Class: Restrict::Restriction
- Inherits:
-
Object
- Object
- Restrict::Restriction
- Defined in:
- lib/restrict/restriction.rb
Instance Attribute Summary collapse
-
#actions ⇒ Object
Returns the value of attribute actions.
-
#on ⇒ Object
Returns the value of attribute on.
-
#options ⇒ Object
Returns the value of attribute options.
-
#unless ⇒ Object
Returns the value of attribute unless.
Instance Method Summary collapse
- #applies_to?(action) ⇒ Boolean
-
#initialize(*args) ⇒ Restriction
constructor
A new instance of Restriction.
- #validate(controller) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Restriction
Returns a new instance of Restriction.
5 6 7 8 9 10 |
# File 'lib/restrict/restriction.rb', line 5 def initialize(*args) @options = args. @unless = @options[:unless] @on = @options[:on] || [:of] || [:object] @actions = args end |
Instance Attribute Details
#actions ⇒ Object
Returns the value of attribute actions.
3 4 5 |
# File 'lib/restrict/restriction.rb', line 3 def actions @actions end |
#on ⇒ Object
Returns the value of attribute on.
3 4 5 |
# File 'lib/restrict/restriction.rb', line 3 def on @on end |
#options ⇒ Object
Returns the value of attribute options.
3 4 5 |
# File 'lib/restrict/restriction.rb', line 3 def @options end |
#unless ⇒ Object
Returns the value of attribute unless.
3 4 5 |
# File 'lib/restrict/restriction.rb', line 3 def unless @unless end |
Instance Method Details
#applies_to?(action) ⇒ Boolean
12 13 14 |
# File 'lib/restrict/restriction.rb', line 12 def applies_to?(action) applies_to_action?(action) || applies_to_all_actions? end |
#validate(controller) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/restrict/restriction.rb', line 16 def validate(controller) @unless or return unless_args = [] if @on object = controller.__send__(on) unless_args << object or raise Restrict::AccessDenied, reason: 'object given was #{object.inspect}' end unless controller.__send__(@unless, *unless_args) raise Restrict::AccessDenied, reason: self end end |