Class: Denied::Restriction

Inherits:
Object
  • Object
show all
Defined in:
lib/denied/restriction.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Restriction

Returns a new instance of Restriction.



5
6
7
8
9
10
11
# File 'lib/denied/restriction.rb', line 5

def initialize(*args)
  options   = args.extract_options!
  @role     = options[:role]
  @allow_if = options[:allow_if]
  @actions  = args
  actions.empty? and raise ArgumentError, "expected actions to restrict, but got #{actions.inspect}"
end

Instance Attribute Details

#actionsObject

Returns the value of attribute actions.



3
4
5
# File 'lib/denied/restriction.rb', line 3

def actions
  @actions
end

#allow_ifObject

Returns the value of attribute allow_if.



3
4
5
# File 'lib/denied/restriction.rb', line 3

def allow_if
  @allow_if
end

#roleObject

Returns the value of attribute role.



3
4
5
# File 'lib/denied/restriction.rb', line 3

def role
  @role
end

Instance Method Details

#restricts?(action_name) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/denied/restriction.rb', line 13

def restricts?(action_name)
  actions.include?(action_name.to_sym)
end