json-logic-ruby
json-logic-ruby copied to clipboard
Functional differences between this and original JS port
I've noticed that the operations in this port work entirely different then they do in the original JS port. Specifically here: https://github.com/bhgames/json-logic-ruby/blob/97b4b5d6d2bfdf00d450c428e43022113b3e4a3c/lib/json_logic/operation.rb#L117
JSONLogic is defined to accept the elements in an array as the argument to an operation. However, your operations accept an array and the original data object.
With all the testing I've done so far, it seems like everything officially supported in the JS port works the same in this Ruby port. Ex)
rule = {+: [1, 2]}
data = {}
JSONLogic.apply(rule, data) # 3
The result of this will be 3
in both ports ✅
However, if you were to define something like this in ruby:
rule = {+: [{var: 'data'}]}
data = {data: [1,2]}
JSONLogic.apply(rule, data) # 3
and in JS
rule = {"+": [{"var": "data"}]}
data = {"data": [1,2]}
jsonLogic.apply(rule, data) # 1
You end up with 3
in Ruby and 1
in JS. ❌
Ultimately this leads to inconsistencies when trying to develop cross-platform.
Ok, thanks for letting me know! Feel free to submit a PR to fix this, I'd love to have it in. I'm pretty busy these days, so I don't get to dropin as often.
Could I suggest using https://github.com/rails/execjs on the server? That way you use the same JS port front and back end.