Class: Jsm::Callbacks::Callback
- Inherits:
-
Object
- Object
- Jsm::Callbacks::Callback
- Defined in:
- lib/jsm/callbacks/callback.rb
Overview
the purpose of this class is to store the block that will be used as callback e.g: Jsm::Callbacks::Callback.new(:before) do
put 'me awesome'
end
Constant Summary collapse
- FILTER_TYPES =
[:before, :after]
Instance Attribute Summary collapse
-
#filter_type ⇒ Object
readonly
Returns the value of attribute filter_type.
Instance Method Summary collapse
-
#execute(*obj) ⇒ Object
run callback.
-
#initialize(filter_type, &block) ⇒ Callback
constructor
the allowed filter_type: :before, :after.
Constructor Details
#initialize(filter_type, &block) ⇒ Callback
the allowed filter_type: :before, :after
12 13 14 15 16 17 18 19 |
# File 'lib/jsm/callbacks/callback.rb', line 12 def initialize(filter_type, &block) if FILTER_TYPES.include?(filter_type) @filter_type = filter_type else raise ArgumentError, "invalid type #{filter_type}, allowed: #{FILTER_TYPES.join(', ')}" end @block = block end |
Instance Attribute Details
#filter_type ⇒ Object (readonly)
Returns the value of attribute filter_type.
9 10 11 |
# File 'lib/jsm/callbacks/callback.rb', line 9 def filter_type @filter_type end |
Instance Method Details
#execute(*obj) ⇒ Object
run callback
22 23 24 |
# File 'lib/jsm/callbacks/callback.rb', line 22 def execute(*obj) @block.call(*obj) end |