Class: EasyTags::Options::Callback
- Inherits:
-
Object
- Object
- EasyTags::Options::Callback
- Defined in:
- lib/easy_tags/options/callback.rb
Overview
Represents a single callback item
Constant Summary collapse
- TYPES =
%i[after_add after_remove].freeze
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
- #type ⇒ String readonly
Instance Method Summary collapse
-
#initialize(callback:, type:) ⇒ Callback
constructor
A new instance of Callback.
-
#run(taggable:, tagging:) ⇒ Object
invoke callback for a taggable object for a specific tagging.
Constructor Details
#initialize(callback:, type:) ⇒ Callback
Returns a new instance of Callback.
13 14 15 16 17 18 |
# File 'lib/easy_tags/options/callback.rb', line 13 def initialize(callback:, type:) @callback = callback @type = type raise "unknown callback type - must be one of #{TYPES}" unless TYPES.include?(type) end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
7 8 9 |
# File 'lib/easy_tags/options/callback.rb', line 7 def context @context end |
#type ⇒ String (readonly)
21 22 23 |
# File 'lib/easy_tags/options/callback.rb', line 21 def type @type end |
Instance Method Details
#run(taggable:, tagging:) ⇒ Object
invoke callback for a taggable object for a specific tagging
27 28 29 30 31 32 33 34 |
# File 'lib/easy_tags/options/callback.rb', line 27 def run(taggable:, tagging:) case @callback when Symbol taggable.send(@callback, tagging) when Proc taggable.instance_exec tagging, &@callback end end |