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
- #with_access(&block) ⇒ Object
Instance Method Details
#controls_access_with(&block) ⇒ Object
33 34 35 |
# File 'lib/sentinel/controller.rb', line 33 def controls_access_with(&block) self.sentinel = block end |
#grants_access_to(*args, &block) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/sentinel/controller.rb', line 46 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
37 38 39 40 |
# File 'lib/sentinel/controller.rb', line 37 def on_denied_with(name = :default, &block) self.access_denied ||= {} self.access_denied[name] = block end |
#with_access(&block) ⇒ Object
42 43 44 |
# File 'lib/sentinel/controller.rb', line 42 def with_access(&block) self.access_granted = block end |