Rails Custom generators - ruby-on-rails-3

Im building a custom generator for my app where I basically want to wrap around the Rails model generator. More specifically, I just want to change the model template being used (I want to add some methods that each model must implement).
Any pointers to the template to override or any other suggestions would be much appreciated.
EDIT:
Just to add, I dont want this to be the default model template, I want to be able to use it only when I use my generator

Some more mucking around and i found the answer. The active record model generator is here

Related

What is the recommended workflow for vue.js + i18n?

I have recently made the jump from developing using the Django framework to vue.js. One thing I am having a hard time wrapping my head around is the workflow for adding translations.
In Django, my workflow felt very intuitive:
Annotate my code with translation hooks.
Pull out the translation hooks into a .po (gettext) file
Translate the messages into the desired locale, i.e. do work in the .po file
Compile the .po file
In the context where all of my work needs to be translated, this workflow was very convenient and fool-proof.
I am excited about the move over to vue.js but I am afraid the difference in translation workflow might be a deal-breaker. Or perhaps, there is something I am missing? Here is my understanding of the vue.js/i18n workflow
Annotate my code with translation hooks. Unlike the Django process, I am using a Translation ID to link messages and translations.
Manually add those translation ids to a JSON file, e.g. en.json
Mirror that json file to that of a different locale, e.g., fr.json
I understand that I can use a tool like BabelEdit to manage the last step. While this seems like a great tool, it is the second step that I am really having a hard time getting my head around. Without a function like the django-admin/gettext makemessages this seems like it would be a tedious and inefficient task.
What am I getting wrong here? I imagine I am not the only one with these needs, so what are the translation workflows that are working for others developing with vue.js?
Thanks in advance.
I believe that you can use https://github.com/pixari/vue-i18n-extract on step 2. I think that BabelEdit can only help if you keep your translations as <i18n> section in your Vue components (in which case you will need https://github.com/intlify/vue-i18n-loader)

Build something similar to sciSpacy, but say for another domain

I want to build a model similar to sciSpacy, but for another domain. How should I go about this?
You'll have to first make sure you have enough training data about your new domain. If you want to have a Named Entity Recognizer, you need texts annotated with named entities. If you want to have a parser, you need texts with dependency annotations. If you want a POS tagger, you need texts annotated with POS tags, etc.
Then you can create a new blank model, add the component(s) to them you need, and start training those:
nlp = spacy.blank("fr")
ner = nlp.create_pipe("ner")
nlp.add_pipe(ner)
ner.add_label("MY_DOMAIN_LABEL")
nlp.begin_training()
nlp.update(texts, annotations, drop=0.2)
This code snippet is not complete, because it really depends on what exactly it is you want to do. You can find more complete snippets in the documentation: https://spacy.io/usage/training
You might also be interested in the command-line utility to train new models, cf https://spacy.io/api/cli#train

ArchUnit to test actual layered architecture

Currently in our project we have layered architecture implemented in following way where Controller, Service, Repository are placed in the same package for each feature, for instance:
feature1:
Feature1Controller
Feature1Service
Feature1Repository
feature2:
Feature2Controller
Feature2Service
Feature2Repository
I've found following example of arch unit test where such classes are placed in dedicated packages https://github.com/TNG/ArchUnit-Examples/blob/master/example-junit5/src/test/java/com/tngtech/archunit/exampletest/junit5/LayeredArchitectureTest.java
Please suggest whether there is possibility to test layered architecture when all layers are in single package
If the file name conventions are followed properly across your project, how about you write custom test cases instead of using layeredArchitecture().
For Example:
classes().that().haveSimpleNameEndingWith("Service")
.should().onlyBeAccessed().byClassesThat().haveSimpleNameEndingWith("Controller")
noClasses().that().haveSimpleNameEndingWith("Service")
.should().accessClassesThat().haveSimpleNameEndingWith("Controller")
I know this question is rather old. But for the record, this has been possible for a while using predicates for the layers, e.g.
layeredArchitecture().consideringAllDependencies()
.layer("Controllers").definedBy(HasName.Predicates.nameEndingWith("Controller"))
.layer("Services").definedBy(HasName.Predicates.nameEndingWith("Service"))
.layer("Repository").definedBy(HasName.Predicates.nameEndingWith("Repository"))
.whereLayer("Controllers").mayNotBeAccessedByAnyLayer()
.whereLayer("Services").mayOnlyBeAccessedByLayers("Controllers")
.whereLayer("Repository").mayOnlyBeAccessedByLayers("Services")
However, I'm not sure how well this works in practice. Because usually you don't just have classes following this naming pattern and that's it. A service might also have some POJO as method parameter type (e.g. MyInput) and that should maybe for example not be used by repositories as well. Also, using forward dependency rules (mayOnlyAccessLayers(..)) this might then cause unwanted violations.

How to use leaflet-extra/leaflet-providers with ngx-leaflet?

How can I use leaflet-extra/leaflet-providers with ngx-leaflet. A simple example would be nice. I installed leaflet, #types/leaflet, ngx-leaflet, leaflet-providers, #types/leaflet-providers, but I cannot figure out how exactly to link ngx-leaflet with tileLayer.providers('ProviderId'). there should be an .addTo(???map???) call. Thanks.
If you need access to the map reference, you can follow the instructions here: https://github.com/Asymmetrik/ngx-leaflet#getting-a-reference-to-the-map
There's also a guide with a bunch of examples of how to integrate Leaflet plugins located here: https://github.com/Asymmetrik/ngx-leaflet-tutorial-plugins
It sounds like with this example, you would use the providers plugin to create layers that you'd add to the layers array you are providing to the leafletLayers input binding or the leafletLayersControl input binding.
You'd just need to create the layers and add them to the appropriate array or object.
If you can provide some more specific example code I can give you more detail.

Workflow for modifying existing crud scaffolded model, views & controllers

I am in the process of learning Yii framework. I have always previously built plugins in wordpress and I have never used a PHP MVC framework before.
Assuming I have designed my database
Used Yiic shell - console to model the db and create crud classes etc.
Modified the controllers and views to my custom requirements.
Now the client requirements change and an extra field is required in the database.
I modify the database to add for example "tel2" field to the customer table.
Do I need to update the model, view and controller manually to incorporate these changes or do I save customisations then get Yiic shell to re-scaffold the model, view & controller, then re-write the customisations manually?
I am sure that I can do either, but is there an easier way / is there a way in which you all work which makes your lives easier?
This was a question on my mind also when I began Yii.
The simple answer to it is you dont have to change everything. The Gii module is a really powerful feature of Yii and after making the CRUD and the model after a DB table, and if you have your own custom functions and methods and then you decide that you need to alter a table and add a new column to it, all you need to do remake the model in gii and it shall show the the modified code in a seperate link tagged as "diff".
Gii only generates the code, it does not overwrite it.
Now all you need to do is open up the "diff" make sure that you do not overwrite the code as there would be an overwrite button as well. After you check out the "diff" code, it shall show the new columns and the new properties highlighted, now all you need to do is copy the requisite changed code into your original code.
This way, you can do as many changes as you want with everything remaining intact.
There is also another method. You can use a base class and extend all your code into another file. This way, all you need to do is change the base model and everything still remains intact.
I think this should have answered your question.
Regards,
You should look at gii as a tool that gets you started quickly. But once you created your models and maybe CRUDs you can usually forget about it. Your project code evolves and - if it's not a very simply project - you will have a lot of manual changes to the auto generated code anyway.
So every time you touch your DB you will update the related files. Often this only involves to add a new attribute rule in rules() in your model, and adding another input field to the form view.