Skip to content
This repository has been archived by the owner on Jul 11, 2024. It is now read-only.

Commit

Permalink
fix: multiple file access
Browse files Browse the repository at this point in the history
  • Loading branch information
ralphg6 committed Dec 19, 2023
1 parent 04406a7 commit c5971d4
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 14 deletions.
3 changes: 2 additions & 1 deletion __tests__/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
rules.grl
rules.grl
rules.json
70 changes: 70 additions & 0 deletions __tests__/transpiler/cases/0052 - slice_add_itens/expected.grl
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@

rule DefaultValues salience 10000000 {
when
true
then

result.CreateSlice("tags");

Changed("ctx");
Changed("result");
Retract("DefaultValues");
}


rule RemoteLoaded salience 10000000 {
when
true
then

ctx.RegistryRemoteLoadedWithFrom("gender", "myresolver", "");

Changed("ctx");
Retract("RemoteLoaded");
}

rule RequiredParams salience 10000000 {
when
true
then

ctx.SetRequiredConfigured();
Changed("ctx");
Retract("RequiredParams");
}

rule HasRequiredParamsError salience 9999999 {
when
ctx.Has("requiredParamErrors")
then
Complete();
}

rule feat_tags_0 salience 1001 {
when
ctx.IsReady() && ((ctx.GetString("gender") == "F"))
then
ctx.Put("tags_0", processor.ToMap("{\"client\":\"Woman\"}"));

Retract("feat_tags_0");
}
rule feat_tags_1 salience 1001 {
when
ctx.IsReady() && ((ctx.GetString("gender") == "F"))
then
ctx.Put("tags_1", processor.ToMap("{\"client\":\"Man\"}"));

Retract("feat_tags_1");
}
rule feat_tags salience 1000 {
when
true
then
ctx.AddItems("tags", ctx.GetMap("tags_0"), ctx.GetMap("tags_1"));

result.Put("tags", ctx.GetSlice("tags"));

Changed("result");

Retract("feat_tags");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"name": "gender",
"resolver": "myresolver",
"type": "string"
}
]
23 changes: 13 additions & 10 deletions lib/parser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,27 @@ const parser = async (dir) => {
try {
let rulesPlain;

if (fs.existsSync(dir + "/rules.featws")) {
const rulesFile = dir + "/rules.featws";
const file = fs.readFileSync(rulesFile, "utf8");
rulesPlain = featws.parse(file);
} else if (fs.existsSync(dir + "/rules.json")) {
if (fs.existsSync(dir + "/rules.json")) {
const rulesFile = dir + "/rules.json";
rulesPlain = require(rulesFile);
}
const content = fs.readFileSync(rulesFile, "utf8");
rulesPlain = JSON.parse(content);
} else if (fs.existsSync(dir + "/rules.featws")) {
const rulesFile = dir + "/rules.featws";
const content = fs.readFileSync(rulesFile, "utf8");
rulesPlain = featws.parse(content);
}

if (typeof rulesPlain === "undefined") {
throw new Error("Rules file not founded");
}

const parametersFile = dir + "/parameters.json";
const parameters = require(parametersFile);
const parametersFileContent = fs.readFileSync(parametersFile, "utf8");
const parameters = JSON.parse(parametersFileContent);

const featuresFile = dir + "/features.json";
const features = require(featuresFile);
const featuresFileContent = fs.readFileSync(featuresFile, "utf8");
const features = JSON.parse(featuresFileContent);

const groups = {};
const groupsDir = dir + "/groups/";
Expand Down Expand Up @@ -84,7 +87,7 @@ const parser = async (dir) => {
async function parse(rulesPlain, parameters, features, groups) {
try {
features = setupGroups(groups, rulesPlain, features);

const slices = [];

features = setupSlices(rulesPlain, slices, features);
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "featws-cli",
"version": "0.0.2-rc1",
"version": "0.0.3-rc1",
"description": "A FeatWS CLI to GRL",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit c5971d4

Please sign in to comment.