How to dynamically load models inside an installable hook in Sails.js - sails.js

We are thinking of making one of our applications very modular, creating hooks for the different sections.
What would be needed to do for "injecting" a hook/models folder with its own models into the sails instance?
I tried to find if there is a sails-hook-utils or something like that that allows for late model/controller/service injection, on hooks, but found none. I'm about to create a module for it, https://github.com/luislobo/sails-hook-utils, but it would be great if anyone has some head starts on how to do it?

Well, right after digging more, I just found a module that does exactly what I need. I didn't test it yet, but will do it now.
https://github.com/leeroybrun/sails-util-mvcsloader

Related

Spring Cloud Contract: Prefered way to import repeating parts in Contract DSL

When writing a contract for an API i found myself repeating the same things over and over. For example regex validations for complex json object need to be copy pasted.
Thats tedious and not very DRY.
I'm using Kotlin DSL and Maven
I tried to extract the common parts in another file to reuse it. (Kotlin extension functions ftw.)
After trying multiple things to reuse that file I gave up.
The common parts should be as close to the actual contracts as possible. I don't want to export them in another project, and build them seperat, as they are an vital part of the contracts.
I tried it the following ways:
just put the file in the same directory and importing the functions, hoping it would be resolved as it would in java - did not work at all (my expectations were low, was worth a shot)
putting it in another maven module, and add that as dependency to the spring-cloud-contract-maven-plugin. that worked, as long as the dependant module was built and installed in the local maven repo. if no built version was available maven could not resolve it.
experimenting with kotlin script #file:Import() and #file:DependOn to tackle my issue, no luck.
Is there another way, that I missed? Is there a prefered way doing this?
This must be a common issue, right?

Namespacing My Unity Project Scripts

I create tools for the Unity Asset Store and one of my tools is in conflict with other assets people bought from the store which is resulting in unwanted errors. From talking this over with people they said that I should just "namespace TrollBridge{}" EVERY script. Would this be a way of doing it or do I only need to do certain scripts? Even data structure scripts? If it is just certain scripts what exactly am I looking for about these scripts to throw the "namespace TrollBridge {}" on it? I think I understand the whole encapsulation concept with this but maybe I am missing something when it comes to selling tools for other people? Thanks in advance.
Would this be a way of doing it
Yes.
or do I only need to do certain scripts?
Do it for all your scripts.
Even data structure scripts?
Yes, even that. All your classes for this should be in a namespace.
To make this answer short, put all your scripts in a namespace. The reason for this is that you will be distributing this with thousands of people or even hundreds of thousands.
Let's say that someone is using another plugin called Lighting and that plugin has a class called Lighting. Ask yourself what happens when you release your own plugin with a class called Lighting?
I have seen this happen before between two plugins which led to many complains. The publisher had to add namespace to all their script which broke many old projects.
Do it right now so that you won't have this problem in the future. Name your namespace a name you think does not exist in the Asset Store and resonates with the function of your plugin.

How should one handle dependencies among Play sub-projects?

After creating a huge mess of a Play project, I decided that it would probably be a good idea to break it into sub-projects so that the dependencies are, I can compile part of the project, etc.
Unfortunately, I'm discovering that the sub-projects have slight dependencies on the whole project. The coupling is small enough that I'm not ashamed of it, but SBT won't let me declare circular dependencies. (And I think that's a good thing.)
Here's an example. I have a users sub-project that defines several models for dealing with users. There are also basic views that you would probably expect for dealing with users: login, logout, changePassword, updateSettings, etc. The problem is, these all depend on my main template so that they look like the rest of the site. So I need some way to let the users sub-project know what the main template is that it should embed its views in.
As another example, most sites have a "default" page that they send users to when they try to access information they're not authorized to access, or after they logout, etc. The sub-projects need to know what that page is so they can redirect to the default page as needed. But the default page is defined in the main project, which the sub-projects can't depend on.
I started trying to solve this problem by using my Global.onStart method in the main project to "inject" settings into the sub-projects. For example, I created a var to hold the default page, and then set controllers.users.App.defaultPage to the right value when the application started. But then I realized that every sub-project is going to need a few hooks to tell it how it fits into the main project, and trying to manually keep track of all this was just asking for trouble.
Has anyone come up with a good way of dealing with this issue? Should each sub-project have a default Configuration that the main project can modify? Is there a way for each sub-project to declare what configuration it needs, so that the main project failing to provide it would trigger an error? Should I be ashamed at how coupled my code is, and go back to the drawing board?
Thanks!
After more searching, I came across this blog entry. I'm going to give this a shot and see how it works:
http://eng.42go.com/play-framework-dependency-injection-guice/
After using this for a couple of weeks, it's been mostly a success. There are still chicken/egg problems to work out, but I think that's because I hadn't really thought through how much each of my sub-projects depended on others.
There's still no really easy way to access routes from parts of projects you don't depend on, but you probably shouldn't be linking to projects you don't depend on, anyway. I did figure out how to specify a main template and urls/calls for things like my "Not Found", "Permission Required", and "Login" pages so that all sub-projects could access them.

Handling multiple template files with playframework in complex application?

I recently found out that Scala is an absolutely interesting programming language.
Since I'm not a real desktop application developer but more a webdeveloper I wanted to try out the play framework and if it works well for my purposes.
So far, I really like it, it seems to be easy to use and the developers really think it through.
BUT
I wanted to create an application with different templates, like an "internal", "external" and "admin" area. I already figured out to try out the "modular application" thing which seems to work good but I can't see any possibility to create something like multiple "template" files..
After a few hours of googling, I thought I should just ask..
Has anybody of you done it yet? Any tips how to organise it the best way?
Thanks a lot!
You can have as many views as required and you can also organize them in packages (under the app.views package) in many levels. All you need is just to learn how to reference required view from the controller.
Take a look to this sample schema.
In other words the most importantis clear and comfortable for you order, which you will be able to work with after 3 years without additional notes.

any way to synchonise between Redmine(or other issue trackers) and a plain text todo list?

I would like to access a Redmine taskbase via a simple text based interface - wondering what the shortest path would be (minimum investment/development).
Right now, this boils down to 2 use cases/phases:
Import a batch of tasks into Redmine from simple, wiki-based, bulletted TODO list, ie. plain text content. This is more of a one-off task, so a quick and dirty solution would be fine.
Later, some smooth two-way synchrosation would be great.. E.g. edit loads of tasks via some friendly plain text (or XML) in an editor, or scripting where I could manipulate all of them with simple text processing; then synchronise with Redmine and commit them back.
Any ideas on the easiest way to achieve these?
I'd prefer an external solution (i.e not touching the server), especially for the one-off import case; something like a neat IDE/editor/client, or a standalone Ruby script (e.g using the RM API).
If an appropriate RM plugin would be available, I would not resist giving it a try (can get root access from our lovely IT support:)..
Current ideas:
Emacs/Org-mode, looks like a great combination of a cool task manager UI and full plain text power. It seems rich enough to capture tags, states as well. This artice looks promising Orgmode and Roundup: Bridging public bugtrackers and local tasklists, although not exactly a perfect match.
org-mode parser in Ruby, could be used in an script with redmine-api access, or - worst case(for me, right now)- in newly developed RM plugin.. This looks like a good start: org-ruby
export RM->XML, process file, import XML->RM... not sure if this is supported?
I guess it's always possible to talk to the DB directly, but I'd prefer to avoid that.
Actually, I'm also interested a similar solution for Bugzilla.
At the simplest level, you could write a RM/Rails plugin that parses an Org-Mode task list, updating corresponding issues in the RM Model.
Equally, you can build a view for Redmine (again as a Rails plugin) to generate an org list of the current (or subset of) issues.
For Bugzilla I think you would be best off using the XML-RPC interface to do your issue comparison/update sync, so you'd have to take a very different approach from Redmine.
If you have any specific questions, please update your question, it's quite broad at the moment.
Update
At the moment, there are a few plugins which will probably help you figure out your solution, for example Nick Boltons xml import and Martin Liu's Redmine CSV Import Plugin but neither of these are going to completely solve the problem for you, just give you some useful starting point.
On the other hand, If you write a script that interacts with Redmine's REST api, you don't need it to be in any specific lanugage, in fact you could do it in Emacs-lisp, if the target users of the script are all Emacs aware, then this might well be the best way to do the job. (it would certainly be the most appealing option to me.)
Maybe this can be useful: https://github.com/fukamachi/redmine-el