Skip to content

Commit

Permalink
Adding ability to remove operations.
Browse files Browse the repository at this point in the history
  • Loading branch information
jwadhams committed Jun 30, 2017
1 parent 6faf2f3 commit d451391
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "json-logic-js",
"version": "1.1.2",
"version": "1.1.3",
"homepage": "https://github.com/jwadhams/json-logic-js",
"authors": [
"Jeremy Wadhams <[email protected]>"
Expand Down
3 changes: 3 additions & 0 deletions logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,9 @@ http://ricostacruz.com/cheatsheets/umdjs.html
operations[name] = code;
};

jsonLogic.rm_operation = function(name) {
delete operations[name];
};

jsonLogic.rule_like = function(rule, pattern) {
// console.log("Is ". JSON.stringify(rule) . " like " . JSON.stringify(pattern) . "?");
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "json-logic-js",
"version": "1.1.2",
"version": "1.1.3",
"description": "Build complex rules, serialize them as JSON, and execute them in JavaScript",
"main": "logic.js",
"directories": {
Expand Down
13 changes: 13 additions & 0 deletions tests/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,16 @@ QUnit.test( "Expanding functionality with add_operator", function( assert) {
42
);

//Remove operation:
jsonLogic.rm_operation("times");

assert.throws(
function() {
jsonLogic.apply({"times": [2,2]});
},
/Unrecognized operation/
);

// Calling a method that takes an array, but the inside of the array has rules, too
jsonLogic.add_operation("array_times", function(a) {
return a[0]*a[1];
Expand All @@ -183,6 +193,9 @@ QUnit.test( "Expanding functionality with add_operator", function( assert) {
),
42
);



});

QUnit.test( "Expanding functionality with method", function( assert) {
Expand Down

0 comments on commit d451391

Please sign in to comment.