Split rules across files #58

Closed
w1nk opened this Issue Aug 28, 2013 · 3 comments

Comments

Projects
None yet
2 participants
@w1nk

w1nk commented Aug 28, 2013

Is there a way to load multiple files of rules into a single flow?

@ghost ghost assigned doug-martin Aug 28, 2013

@w1nk w1nk closed this Aug 30, 2013

doug-martin added a commit to doug-martin/nools that referenced this issue Aug 30, 2013

v0.1.10
* Added ability to `import` other nools files to create composible rules files [#58](noolsjs#58)
* When using `global` to require other files you can now require other files relative to the nools file
@doug-martin

This comment has been minimized.

Show comment
Hide comment
@doug-martin

doug-martin Aug 30, 2013

Contributor

I see that you issued pull request #59 to address this issue however I also came up with the following solution which allows for nested imports and prevents duplicate declarations etc. The syntax looks like the following.

//defines.nools
define Count{
    constructor: function(){
        this.called = 0;
    }
}
//orRule.nools
import("./defines.nools");
rule orRule {
    when {
        or(
            s : String s == 'hello',
            s : String s == 'world'
        );
        count : Count;
    }
    then {
        count.called++;
        count.s = s;
    }
}
//notRule.nools
import("./defines.nools");
rule notRule {
    when {
        not(s : String s == 'hello');
        count : Count
    }
    then {
        count.called++;
    }
}
//import
import("./orRules.nools");
import("./notRules.nools");

In the above example the import will prevent the same rules file from being imported twice so in this case orRule.nools and notRule.nools could be run by itself or combined as in the third example. I think this solution is more robust leads to the rules files being more self contained.

Let me know what you think.

-Doug

P.S. Im finishing up the tests and should have this merged in soon. If you still feel that allowing for an array of files to specified and concated together I am open for discussion.

Contributor

doug-martin commented Aug 30, 2013

I see that you issued pull request #59 to address this issue however I also came up with the following solution which allows for nested imports and prevents duplicate declarations etc. The syntax looks like the following.

//defines.nools
define Count{
    constructor: function(){
        this.called = 0;
    }
}
//orRule.nools
import("./defines.nools");
rule orRule {
    when {
        or(
            s : String s == 'hello',
            s : String s == 'world'
        );
        count : Count;
    }
    then {
        count.called++;
        count.s = s;
    }
}
//notRule.nools
import("./defines.nools");
rule notRule {
    when {
        not(s : String s == 'hello');
        count : Count
    }
    then {
        count.called++;
    }
}
//import
import("./orRules.nools");
import("./notRules.nools");

In the above example the import will prevent the same rules file from being imported twice so in this case orRule.nools and notRule.nools could be run by itself or combined as in the third example. I think this solution is more robust leads to the rules files being more self contained.

Let me know what you think.

-Doug

P.S. Im finishing up the tests and should have this merged in soon. If you still feel that allowing for an array of files to specified and concated together I am open for discussion.

@doug-martin doug-martin reopened this Aug 30, 2013

doug-martin added a commit to doug-martin/nools that referenced this issue Aug 30, 2013

v0.1.10
* Added ability to `import` other nools files to create composible rules files [#58](noolsjs#58)
* When using `global` to require other files you can now require other files relative to the nools file

doug-martin added a commit to doug-martin/nools that referenced this issue Aug 30, 2013

v0.1.10
* Added ability to `import` other nools files to create composible rules files [#58](noolsjs#58)
* When using `global` to require other files you can now require other files relative to the nools file

@doug-martin doug-martin referenced this issue Aug 30, 2013

Merged

v0.1.10 #63

@w1nk

This comment has been minimized.

Show comment
Hide comment
@w1nk

w1nk Aug 30, 2013

Just to make sure I understand, you're adding nools.import which with accept a filename and prevent duplicates, and most importantly each file is being loaded into the same flow? If yes, you've sold me :)

w1nk commented Aug 30, 2013

Just to make sure I understand, you're adding nools.import which with accept a filename and prevent duplicates, and most importantly each file is being loaded into the same flow? If yes, you've sold me :)

doug-martin added a commit to doug-martin/nools that referenced this issue Aug 30, 2013

v0.1.10
* Added ability to `import` other nools files to create composible rules files [#58](noolsjs#58)
* When using `global` to require other files you can now require other files relative to the nools file

doug-martin added a commit to doug-martin/nools that referenced this issue Sep 4, 2013

v0.1.10
* Added ability to `import` other nools files to create composible rules files [#58](noolsjs#58)
* When using `global` to require other files you can now require other files relative to the nools file
* Added uglify-js as a dependency instead of devDependency #71
* Fixed issue #61 where transpile would not properly escape `"` character.
* Fixed issue #66 and #67 where regular expression matching was too greedy.
* Fixed issue #62 where constraints with a `"` character would produce invalid javascript when `transpiling`.
* Fixed issue #69 where rules names with a `'` character in a rule would produce invalid javascript when `transpiling`.
@doug-martin

This comment has been minimized.

Show comment
Hide comment
@doug-martin

doug-martin Sep 4, 2013

Contributor

Yes the import functionality addresses all of those...let me know what you think

Contributor

doug-martin commented Sep 4, 2013

Yes the import functionality addresses all of those...let me know what you think

@doug-martin doug-martin closed this Sep 4, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment