Class: Ixtlan::Guard::ActionController::Filter
- Inherits:
-
Object
- Object
- Ixtlan::Guard::ActionController::Filter
- Defined in:
- lib/ixtlan/guard/guard_rails.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
Instance Method Summary collapse
- #allowed?(action) ⇒ Boolean
-
#initialize(method, options, &block) ⇒ Filter
constructor
A new instance of Filter.
- #proc(base, reference = nil) ⇒ Object
Constructor Details
#initialize(method, options, &block) ⇒ Filter
Returns a new instance of Filter.
12 13 14 15 16 17 18 19 20 |
# File 'lib/ixtlan/guard/guard_rails.rb', line 12 def initialize(method, , &block) @only = [:only] @except = [:except] || [] @reference = [:reference] @reference = @reference.to_sym if @reference @block = block @method = method.to_sym if method raise "illegal arguments: either block or method name #{method}" if block && method end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
11 12 13 |
# File 'lib/ixtlan/guard/guard_rails.rb', line 11 def block @block end |
Instance Method Details
#allowed?(action) ⇒ Boolean
60 61 62 63 64 |
# File 'lib/ixtlan/guard/guard_rails.rb', line 60 def allowed?(action) action = action.to_sym (@only && @only.member?(action)) || ((@only.nil? || @only.empty?) && ! @except.member?(action)) end |
#proc(base, reference = nil) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/ixtlan/guard/guard_rails.rb', line 22 def proc(base, reference = nil) if @block if reference Proc.new do |groups| @block.call(groups, reference) end elsif @reference Proc.new do |groups| @block.call(groups, base.send(@reference)) end else @block end else if base.respond_to?(@method) || base.private_methods.include?(@method.to_s) || base.private_methods.include?(@method.to_sym) if reference Proc.new do |groups| base.send(@method, groups, reference) end elsif @reference Proc.new do |groups| base.send(@method, groups, base.send(@reference)) end else base.method(@method) end else if @reference Proc.new do |groups| base.class.send(@method, groups, base.send(@reference)) end else base.class.method(@method) end end end end |