Skip to content

Commit

Permalink
fixes for 0.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Preston Lee committed Feb 9, 2009
1 parent cdcf859 commit 2a78a5a
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 3 deletions.
4 changes: 3 additions & 1 deletion History.txt
@@ -1,5 +1,7 @@
== 0.0.3 / 2009-02-??
== 0.0.3 / 2009-02-09

* Renaming files due to RubyForge stupidity.
* Adding usage examples.

== 0.0.2 / 2009-02-04

Expand Down
1 change: 1 addition & 0 deletions Rakefile
Expand Up @@ -6,4 +6,5 @@ Echoe.new("ruby-prolog") do |p|
# p.docs_host = "uncapitalizer.com:~/www/files/doc/"
# p.runtime_dependencies = ["string_tools >=1.4.0"]
p.version = '0.0.3'
p.email = "preston.lee@openrain.com"
end
74 changes: 72 additions & 2 deletions examples/acls.rb
Expand Up @@ -2,6 +2,76 @@
require 'ruby-prolog'

c = RubyProlog::Core.new
c.instance_eval {
c.instance_eval do

# Let's put together an issue tracking system for Microsoft.

# We'll start by declaring a few projects...
project_status['me', 'live'].fact
project_status['xp', 'live'].fact
project_status['vista', 'live'].fact
project_status['7', 'in_progress'].fact


# Now we'll create a custom ACL system...
role_can['user', 'create'].fact
role_can['user', 'read'].fact

role_can['qa', 'create'].fact
role_can['qa', 'read'].fact
role_can['qa', 'update'].fact

role_can['admin', 'create'].fact
role_can['admin', 'read'].fact
role_can['admin', 'update'].fact
role_can['admin', 'delete'].fact


# Let's put people on different projects
assigned['alice', 'me', 'user'].fact
assigned['bob', 'me', 'qa'].fact
assigned['charlie', 'me', 'qa'].fact

assigned['alice', 'xp', 'user'].fact
assigned['bob', 'xp', 'user'].fact
assigned['charlie', 'xp', 'admin'].fact

assigned['alice', 'vista', 'qa'].fact
assigned['bob', 'vista', 'admin'].fact
assigned['charlie', 'vista', 'admin'].fact

assigned['alice', '7', 'user'].fact
assigned['bob', '7', 'qa'].fact
assigned['charlie', '7', 'qa'].fact
assigned['dale', '7', 'admin'].fact


# can_read_on_project[:U, :P] <<= [assigned[:U, :P, :R], role_can[:R, 'read']]
can_on_project[:U, :X, :P] <<= [assigned[:U, :P, :R], role_can[:R, :X]]
is_role_on_multiple_projects[:U, :R] <<= [assigned[:U, :X, :R], assigned[:U, :Y, :R], noteq[:X, :Y]]
# , noteq[:P1, :P2]

puts 'Who does QA?'
p query(assigned[:U, :P, 'qa'])

puts "Who can access the 'vista' project?"
p query(can_on_project[:U, 'read', 'vista'])

puts "Does Alice have delete privileges on Vista?"
puts query(can_on_project['alice', 'delete', 'vista']).empty? ? "Yes" : "No"

puts "Does Bob have delete privileges on Vista?"
puts query(can_on_project['bob', 'delete', 'vista']).empty? ? "Yes" : "No"

puts "Who is an admin on multiple projects?"
# p query(is_role_on_multiple_projects[:U, 'admin'])

s = Array.new
query(is_role_on_multiple_projects[:U, 'admin']).each do |r|
s |= [r[0].args[0]] # Put each result into the array, if not already present.
end
s.each do |n| puts n end # Print all unique results!

}


end

0 comments on commit 2a78a5a

Please sign in to comment.