Module: MimeActor::Scene::ClassMethods
- Defined in:
- lib/mime_actor/scene.rb
Instance Method Summary collapse
-
#act_on_action(*actions, format:, with: nil, &block) ⇒ Object
Register ‘action` + `format` definitions.
Instance Method Details
#act_on_action(*actions, format:, with: nil, &block) ⇒ Object
Register ‘action` + `format` definitions.
For each unique ‘action` being registered, a corresponding `action` method will be defined.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/mime_actor/scene.rb', line 87 def act_on_action(*actions, format:, with: nil, &block) raise ArgumentError, "format is required" if format.nil? raise ArgumentError, "provide either with: or a block" if !with.nil? && block_given? validate!(:actions, actions) validate!(:format_or_formats, format) validate!(:callable, with) unless with.nil? with = block if block_given? actions.each do |action| acting_scenes[action] ||= {} Array(format).each do |action_format| acting_scenes[action][action_format] = with end end ActiveSupport.version >= "7.2" ? generate_action_methods(actions) : eval_action_methods(actions) end |