Class: MimeActor::Callbacks::ClassMethods::ActMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/mime_actor/callbacks.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#actionsObject (readonly)

Returns the value of attribute actions.



46
47
48
# File 'lib/mime_actor/callbacks.rb', line 46

def actions
  @actions
end

#formatsObject (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

Returns:

  • (Boolean)


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