Class: BootyCall::ObservedMethod
- Inherits:
-
Object
- Object
- BootyCall::ObservedMethod
- Defined in:
- lib/booty_call/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/booty_call/observed_method.rb', line 5 def initialize(method_id, ={}) @method_id = method_id @callbacks = [] @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/booty_call/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/booty_call/observed_method.rb', line 12 def match(sym) return unless case method_id when Symbol then valid? when Regexp then valid? and method_id.try(:match, sym.to_s) else ; nil end @callbacks.each { |fn| fn.call(sym) } @count += 1 end |
#push(*args) ⇒ Object
26 27 28 29 |
# File 'lib/booty_call/observed_method.rb', line 26 def push(*args) @callbacks += args @callbacks.tap.compact!.uniq! end |
#valid? ⇒ Boolean
22 23 24 |
# File 'lib/booty_call/observed_method.rb', line 22 def valid? @times.to_s.match(/^(inf|any|all|every)/) or @count < @times end |