Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

persistence #57

Open
dcdieci opened this issue Jul 4, 2016 · 6 comments
Open

persistence #57

dcdieci opened this issue Jul 4, 2016 · 6 comments

Comments

@dcdieci
Copy link

dcdieci commented Jul 4, 2016

Great lib!
Is there any way to persist a rule in a database?

@ulfurinn
Copy link
Owner

ulfurinn commented Jul 4, 2016

It's up to you how you want to do it.

@dcdieci
Copy link
Author

dcdieci commented Jul 4, 2016

I don't quite get it.
For instance how would it be possible to store and load such a rule

`harry = {}
  engine << [harry, "wizard", true]
  engine << [harry, "muggle", true]
  engine << [harry, "potions_grade", 2]
  engine << [harry, "spells_grade", 2]

  advance_grade = engine.rule "advanced to second grade?" do
    forall {
      has :Student, "wizard", true
      has :Student, "muggle", true
      maybe :Student, "potions_grade", :Potions_grade
      maybe :Student, "spells_grade", :Spells_grade
      assert do |token|
        token[:Potions_grade] < 3 && token[:Spells_grade] < 3
      end

      assert do |token|
        token[:Potions_grade] >= 2
      end
      make {
        action { |token|
          p "passed"
        }
      }
    }
  end`

thanks for the swift reply
edit:
e.g. Marshal.dump is not possible due to the used Proc

@ulfurinn
Copy link
Owner

ulfurinn commented Jul 4, 2016

Procs cannot be persisted, of course. They are not marshalable in Ruby.

@ulfurinn
Copy link
Owner

ulfurinn commented Jul 4, 2016

Unless you store the AST and generate code with ruby2ruby or something like that.

@dcdieci
Copy link
Author

dcdieci commented Jul 4, 2016

Procs cannot be persisted, of course. They are not marshalable in Ruby.

exactly.
So I am wondering how I could do it?

@ulfurinn
Copy link
Owner

ulfurinn commented Jul 4, 2016

I don't know. Look into sexpr and such.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants