Class: Aspectory::Introspector
Instance Attribute Summary collapse
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #defined_methods ⇒ Object
- #has_method?(method_id) ⇒ Boolean
-
#initialize(klass, options = {}) ⇒ Introspector
constructor
A new instance of Introspector.
- #observe(method_id, options = {}, &block) ⇒ Object
- #observe_klass! ⇒ Object
- #observing?(method_id) ⇒ Boolean
Constructor Details
#initialize(klass, options = {}) ⇒ Introspector
Returns a new instance of Introspector.
5 6 7 8 |
# File 'lib/aspectory/introspector.rb', line 5 def initialize(klass, ={}) @klass, @options = klass, @observed_methods = { } end |
Instance Attribute Details
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
3 4 5 |
# File 'lib/aspectory/introspector.rb', line 3 def klass @klass end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/aspectory/introspector.rb', line 3 def @options end |
Instance Method Details
#defined_methods ⇒ Object
23 24 25 |
# File 'lib/aspectory/introspector.rb', line 23 def defined_methods (klass.instance_methods - Object.instance_methods).map(&:to_sym) end |
#has_method?(method_id) ⇒ Boolean
27 28 29 |
# File 'lib/aspectory/introspector.rb', line 27 def has_method?(method_id) klass.instance_method(method_id) rescue false end |
#observe(method_id, options = {}, &block) ⇒ Object
10 11 12 13 14 |
# File 'lib/aspectory/introspector.rb', line 10 def observe(method_id, ={}, &block) observe_klass! @observed_methods[method_id] ||= ObservedMethod.new(method_id, ) @observed_methods[method_id].push(block) if block_given? end |
#observe_klass! ⇒ Object
16 17 18 19 20 21 |
# File 'lib/aspectory/introspector.rb', line 16 def observe_klass! @observed ||= begin name = [:meta] ? :singleton_method_added : :method_added install_hook(name) or true end end |
#observing?(method_id) ⇒ Boolean
31 32 33 |
# File 'lib/aspectory/introspector.rb', line 31 def observing?(method_id) not not @observed_methods[method_id] end |