Class: Kabutops::Extensions::CallbackSupport::Manager
- Inherits:
-
Object
- Object
- Kabutops::Extensions::CallbackSupport::Manager
- Defined in:
- lib/kabutops/extensions/callback_support.rb
Instance Attribute Summary collapse
-
#allowed ⇒ Object
readonly
Returns the value of attribute allowed.
-
#map ⇒ Object
readonly
Returns the value of attribute map.
Instance Method Summary collapse
-
#initialize(allowed = nil) ⇒ Manager
constructor
A new instance of Manager.
- #method_missing(name, *args, &block) ⇒ Object
- #notify(name, *args) ⇒ Object
Constructor Details
#initialize(allowed = nil) ⇒ Manager
Returns a new instance of Manager.
13 14 15 16 |
# File 'lib/kabutops/extensions/callback_support.rb', line 13 def initialize allowed=nil @allowed = allowed || [] @map ||= Hashie::Mash.new end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/kabutops/extensions/callback_support.rb', line 18 def method_missing name, *args, &block return super unless block_given? && @allowed.include?(name) @map[name] ||= [] @map[name] << block end |
Instance Attribute Details
#allowed ⇒ Object (readonly)
Returns the value of attribute allowed.
11 12 13 |
# File 'lib/kabutops/extensions/callback_support.rb', line 11 def allowed @allowed end |
#map ⇒ Object (readonly)
Returns the value of attribute map.
11 12 13 |
# File 'lib/kabutops/extensions/callback_support.rb', line 11 def map @map end |
Instance Method Details
#notify(name, *args) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/kabutops/extensions/callback_support.rb', line 25 def notify name, *args return unless @map (@map[name] || []).map do |block| block.call(*args) end end |