Module: Cannie::Permissions::ClassMethods
- Defined in:
- lib/cannie/permissions.rb
Instance Method Summary collapse
- #allow(action, options = {}) ⇒ Object
- #controller(name, &block) ⇒ Object
- #namespace(name, &block) ⇒ Object
- #rules ⇒ Object
Instance Method Details
#allow(action, options = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/cannie/permissions.rb', line 25 def allow(action, ={}) opts = .slice(:if, :unless) subjects = Array(@controller || [:on]).map { |v| subject(v) } Array(action).each do |action_name| subjects.each do |subj| rules << Rule.new(action_name, subj, opts) end end end |
#controller(name, &block) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/cannie/permissions.rb', line 18 def controller(name, &block) @controller = name instance_exec(&block) ensure @controller = nil end |
#namespace(name, &block) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/cannie/permissions.rb', line 10 def namespace(name, &block) orig_scope = @scope @scope = [orig_scope, name].compact.join('/') instance_exec(&block) ensure @scope = orig_scope end |
#rules ⇒ Object
36 37 38 |
# File 'lib/cannie/permissions.rb', line 36 def rules @rules ||= [] end |