Class: MimeActor::Callbacks::ClassMethods::ActMatcher
- Inherits:
-
Object
- Object
- MimeActor::Callbacks::ClassMethods::ActMatcher
- Defined in:
- lib/mime_actor/callbacks.rb
Instance Attribute Summary collapse
-
#actions ⇒ Object
readonly
Returns the value of attribute actions.
-
#formats ⇒ Object
readonly
Returns the value of attribute formats.
Instance Method Summary collapse
-
#initialize(actions, formats) ⇒ ActMatcher
constructor
A new instance of ActMatcher.
- #match?(controller) ⇒ Boolean (also: #after, #before, #around)
Constructor Details
#initialize(actions, formats) ⇒ ActMatcher
Returns a new instance of ActMatcher.
48 49 50 51 52 53 54 55 56 |
# File 'lib/mime_actor/callbacks.rb', line 48 def initialize(actions, formats) if RUBY_VERSION < "2.6" @actions = actions ? Array(actions).to_set(&:to_sym) : nil @formats = formats ? Array(formats).to_set(&:to_sym) : nil else @actions = actions&.then { |a| Array(a).to_set(&:to_sym) } @formats = formats&.then { |f| Array(f).to_set(&:to_sym) } end end |
Instance Attribute Details
#actions ⇒ Object (readonly)
Returns the value of attribute actions.
46 47 48 |
# File 'lib/mime_actor/callbacks.rb', line 46 def actions @actions end |
#formats ⇒ Object (readonly)
Returns the value of attribute formats.
46 47 48 |
# File 'lib/mime_actor/callbacks.rb', line 46 def formats @formats end |
Instance Method Details
#match?(controller) ⇒ Boolean Also known as: after, before, around
58 59 60 61 62 63 |
# File 'lib/mime_actor/callbacks.rb', line 58 def match?(controller) matched = true matched &= actions.include?(controller.act_action) if !actions.nil? && controller.respond_to?(:act_action) matched &= formats.include?(controller.act_format) if !formats.nil? && controller.respond_to?(:act_format) matched end |