Module: Sentinel::Controller::ClassMethods
- Defined in:
- lib/sentinel/controller.rb
Instance Method Summary collapse
- #controls_access_with(&block) ⇒ Object
- #grants_access_to(*args, &block) ⇒ Object
- #on_denied_with(name = :default, &block) ⇒ Object
- #sentinel ⇒ Object
- #with_access(&block) ⇒ Object
Instance Method Details
#controls_access_with(&block) ⇒ Object
37 38 39 |
# File 'lib/sentinel/controller.rb', line 37 def controls_access_with(&block) self.sentinel = block end |
#grants_access_to(*args, &block) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/sentinel/controller.rb', line 54 def grants_access_to(*args, &block) = args. block = args.shift if args.first.respond_to?(:call) sentinel_method = args.first denied_handler = .delete(:denies_with) || :default before_filter() do |controller| if block if (block.arity == 1 ? controller.sentinel : controller).instance_eval(&block) controller.instance_eval(&controller.class.access_granted) else controller.instance_eval(&controller.class.access_denied[denied_handler]) end elsif sentinel_method && controller.sentinel && controller.sentinel.send(sentinel_method) controller.instance_eval(&controller.class.access_granted) else controller.instance_eval(&controller.class.access_denied[denied_handler]) end end end |
#on_denied_with(name = :default, &block) ⇒ Object
45 46 47 48 |
# File 'lib/sentinel/controller.rb', line 45 def on_denied_with(name = :default, &block) self.access_denied ||= {} self.access_denied[name] = block end |
#sentinel ⇒ Object
41 42 43 |
# File 'lib/sentinel/controller.rb', line 41 def sentinel read_inheritable_attribute(:sentinel) end |
#with_access(&block) ⇒ Object
50 51 52 |
# File 'lib/sentinel/controller.rb', line 50 def with_access(&block) self.access_granted = block end |