Class: Aspectory::ObservedMethod
- Defined in:
- lib/aspectory/observed_method.rb
Instance Attribute Summary collapse
-
#method_id ⇒ Object
readonly
Returns the value of attribute method_id.
Instance Method Summary collapse
-
#initialize(method_id, options = {}) ⇒ ObservedMethod
constructor
A new instance of ObservedMethod.
- #match(sym) ⇒ Object
- #push(*args) ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(method_id, options = {}) ⇒ ObservedMethod
Returns a new instance of ObservedMethod.
5 6 7 8 9 10 |
# File 'lib/aspectory/observed_method.rb', line 5 def initialize(method_id, ={}) @method_id = method_id @handlers = [] @count = 0 @times = [:times] || 1 end |
Instance Attribute Details
#method_id ⇒ Object (readonly)
Returns the value of attribute method_id.
3 4 5 |
# File 'lib/aspectory/observed_method.rb', line 3 def method_id @method_id end |
Instance Method Details
#match(sym) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/aspectory/observed_method.rb', line 12 def match(sym) return unless case method_id when Symbol then valid? and method_id === sym when Regexp then valid? and method_id.try(:match, sym.to_s) else ; nil end @handlers.each { |fn| fn[sym] } @count += 1 end |
#push(*args) ⇒ Object
31 32 33 34 |
# File 'lib/aspectory/observed_method.rb', line 31 def push(*args) @handlers += args @handlers.tap.compact!.uniq! end |
#valid? ⇒ Boolean
22 23 24 25 26 27 28 29 |
# File 'lib/aspectory/observed_method.rb', line 22 def valid? if @times.to_s.match(/^(inf|any|all|every)/) def self.valid?; true end true # memoizing the result else @count < @times end end |