Class: Caricature::EventRaiseRecording
- Defined in:
- lib/caricature/clr/method_call_recorder.rb
Overview
A recording that represents an event raise it contains argument variations that can be matched too
Instance Attribute Summary collapse
-
#args ⇒ Object
add args.
-
#count ⇒ Object
gets or sets the amount of times the event was raised.
-
#event_name ⇒ Object
gets or sets the event name.
-
#handler ⇒ Object
gets or sets the block for this event raise.
Instance Method Summary collapse
-
#add_argument_variation(args, block) ⇒ Object
add an argument variation.
-
#find_argument_variations(args) ⇒ Object
finds an argument variation that matches the provided
args. -
#has_argument_variations? ⇒ Boolean
indicates if it has an argument variation.
-
#initialize(event_name, count = 0) ⇒ EventRaiseRecording
constructor
Initializes a new instance of a method call recording every time a method gets called in an isolated object this gets stored in the method call recorder It expects a
method_nameat the very least.
Constructor Details
#initialize(event_name, count = 0) ⇒ EventRaiseRecording
Initializes a new instance of a method call recording every time a method gets called in an isolated object this gets stored in the method call recorder It expects a method_name at the very least.
23 24 25 26 27 |
# File 'lib/caricature/clr/method_call_recorder.rb', line 23 def initialize(event_name, count=0) @event_name = event_name @count = count @variations = [] end |
Instance Attribute Details
#args ⇒ Object
add args
14 15 16 |
# File 'lib/caricature/clr/method_call_recorder.rb', line 14 def args @args end |
#count ⇒ Object
gets or sets the amount of times the event was raised
11 12 13 |
# File 'lib/caricature/clr/method_call_recorder.rb', line 11 def count @count end |
#event_name ⇒ Object
gets or sets the event name
8 9 10 |
# File 'lib/caricature/clr/method_call_recorder.rb', line 8 def event_name @event_name end |
#handler ⇒ Object
gets or sets the block for this event raise
17 18 19 |
# File 'lib/caricature/clr/method_call_recorder.rb', line 17 def handler @handler end |
Instance Method Details
#add_argument_variation(args, block) ⇒ Object
add an argument variation
40 41 42 43 44 45 46 47 |
# File 'lib/caricature/clr/method_call_recorder.rb', line 40 def add_argument_variation(args, block) variation = find_argument_variations args if variation.empty? @variations << ArgumentRecording.new(args, @variations.size+1, block) if variation == [] else variation.first.call_number += 1 end end |
#find_argument_variations(args) ⇒ Object
finds an argument variation that matches the provided args
50 51 52 53 |
# File 'lib/caricature/clr/method_call_recorder.rb', line 50 def find_argument_variations(args) return @variations if args.first.is_a?(Symbol) and args.last == :any @variations.select { |ar| ar.args == args } end |
#has_argument_variations? ⇒ Boolean
indicates if it has an argument variation
35 36 37 |
# File 'lib/caricature/clr/method_call_recorder.rb', line 35 def has_argument_variations? @variations.size > 1 end |