Class: Nestor::Machine
- Inherits:
-
Object
- Object
- Nestor::Machine
- Defined in:
- lib/nestor/machine.rb
Overview
Implements the state machine that is at the heart of Nestor.
Usage
In the Watchr script, use @mapper to access an instance of this class.
The available events you may call are:
ready!
-
Machine instances start in the
booting
state. Once the boot is complete, callready
to indicate you are ready to process events. The default rails template calls #ready whentest/test_helper.rb
is loaded. changed!
-
Tells the Machine a file changed. The Watchr script and mapper are responsible for assigning meaning to the file. The default Watchr script knows how to map model, controller and view files to given tests, and the script thus only tells the Machine about test files. Nothing prevents another implementation from providing the actual implementation files and letting the mapper decide later what to do about those.
run_successful!
-
Tells the Machine that the last build was successful. This does not necessarily indicate a a completely green build: only that the last run was successful, given the focused files.
run_failed!
-
Tells the Machine there were one or more test failures or errors. Again, this doesn’t mean the whole build failed: only the last couple of files had something that caused a failure.
run!
-
Tells the machine to tell the
#mapper
to run the tests, given the current state of affairs. This might be running all tests, or a subset if the Machine is currently focusing on some items. A separate event is required by the Machine to allow coalescing multiple change events together.
Instance Attribute Summary collapse
-
#changed_file ⇒ Object
The last changed file.
-
#focused_files ⇒ Object
readonly
The list of files we are focusing on, as received by #changed!.
-
#focuses ⇒ Object
readonly
The list of failing tests or examples being focused on right now.
-
#mapper ⇒ Object
readonly
The Machine actually delegates running the tests to another object, and this is it’s reference.
-
#options ⇒ Object
readonly
The options as passed to #new.
Instance Method Summary collapse
-
#changed!(file) ⇒ Object
Notifies the Machine that a file changed.
-
#initialize(mapper, options = {}) ⇒ Machine
constructor
mapper
is required, and must implement a couple of methods. -
#log(*args) ⇒ Object
Delegate to @mapper.
Constructor Details
#initialize(mapper, options = {}) ⇒ Machine
mapper
is required, and must implement a couple of methods. See Nestor::Mappers for the required calls.
54 55 56 57 58 59 60 61 62 |
# File 'lib/nestor/machine.rb', line 54 def initialize(mapper, ={}) @options = super() # Have to specify no-args, or else it'll raise an ArgumentError @mapper = mapper @focused_files, @focuses = [], [] log_state_change end |
Instance Attribute Details
#changed_file ⇒ Object
The last changed file. Set by #changed!
45 46 47 |
# File 'lib/nestor/machine.rb', line 45 def changed_file @changed_file end |
#focused_files ⇒ Object (readonly)
The list of files we are focusing on, as received by #changed!
42 43 44 |
# File 'lib/nestor/machine.rb', line 42 def focused_files @focused_files end |
#focuses ⇒ Object (readonly)
The list of failing tests or examples being focused on right now
48 49 50 |
# File 'lib/nestor/machine.rb', line 48 def focuses @focuses end |
#mapper ⇒ Object (readonly)
The Machine actually delegates running the tests to another object, and this is it’s reference.
39 40 41 |
# File 'lib/nestor/machine.rb', line 39 def mapper @mapper end |
#options ⇒ Object (readonly)
The options as passed to #new.
51 52 53 |
# File 'lib/nestor/machine.rb', line 51 def @options end |
Instance Method Details
#changed!(file) ⇒ Object
Notifies the Machine that a file changed. This might trigger a state change and schedule a build.
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/nestor/machine.rb', line 113 def changed!(file) mapped_files = mapper.map(file) case mapped_files when [] # Run all tests unfocus! when nil # Reset reset! else mapped_files.each do |mapped_file| mapper.log "#{file} => #{mapped_file}" self.changed_file = mapped_file file_changed! end end end |