Skip to content

Commit

Permalink
Add some docs on to_prolog
Browse files Browse the repository at this point in the history
  • Loading branch information
gilbert committed Apr 10, 2020
1 parent 6fd97b0 commit a6bd0a5
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,37 @@ end

This will mutate your database. If you want to "fork" your database instead, you can call `db.clone`, which will return a new instance with all stored data. Cloning like this is optimized to copy as little as possible.

### `to_prolog`

If you're loading rules from a database, you might be generating predicates like this:

```rb
rules = Ruleset.find_by(org: ...).rules
db = RubyProlog.new do
rules['permissions'].map do |role, perm|
permission[role, perm].fact
end
end
```

However, if something doesn't work, how do find out why?

This is where `#to_prolog` comes in handy. Just run it on your instance:

```rb
puts db.to_prolog
```

and you'll get something that looks like this:

```text
permission('admin', 'invite').
permission('admin', 'ban').
permission('membe', 'create_post').
```

Then you can do a quick copy/paste into an environment like [Tau Prolog's sandbox](http://tau-prolog.org/sandbox/) or [SWISH](https://swish.swi-prolog.org) and run some queries.

Examples
----

Expand Down

0 comments on commit a6bd0a5

Please sign in to comment.