Module: Cannie::Permissions::ClassMethods

Defined in:
lib/cannie/permissions.rb

Instance Method Summary collapse

Instance Method Details

#allow(action, options = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/cannie/permissions.rb', line 23

def allow(action, options={})
  opts = options.slice(:if, :unless)
  subjects = Array(@controller || options[: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



16
17
18
19
20
21
# File 'lib/cannie/permissions.rb', line 16

def controller(name, &block)
  @controller = name
  instance_exec(&block)
ensure
  @controller = nil
end

#namespace(name, &block) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/cannie/permissions.rb', line 8

def namespace(name, &block)
  orig_scope = @scope
  @scope     = [orig_scope, name].compact.join('/')
  instance_exec(&block)
ensure
  @scope = orig_scope
end

#rulesObject



34
35
36
# File 'lib/cannie/permissions.rb', line 34

def rules
  @rules ||= []
end