Class: Restfulie::Client::Mikyung::RestProcessModel
- Inherits:
-
Object
- Object
- Restfulie::Client::Mikyung::RestProcessModel
- Defined in:
- lib/restfulie/client/mikyung/rest_process_model.rb
Overview
Provides a DSL to build your process in a human readable way.
Example: When there is a machine And already installed Then reboot
Before creating your DSL you should provide your method content:
When /there (are|is an|is a|is) (.*)/ do |resource, regex|
resource.keys.first==regex[2]
end
When “already installed” do |resource|
@installed
end
Then “reboot” do |resource|
resource.machine.boot.post! :boot => {:reason => "Installed #{@software[:name]}"}
end
Constant Summary collapse
- @@at =
""
- @@follow =
false
- @@accept =
"application/atom+xml"
- @@current_dir =
""
Class Method Summary collapse
- .accept(type) ⇒ Object
- .at(uri) ⇒ Object
- .current_dir(dir) ⇒ Object
- .follow(bool) ⇒ Object
- .get_restfulie ⇒ Object
Instance Method Summary collapse
-
#And(concat) ⇒ Object
Adds a constraint to the current scenario.
-
#But(concat) ⇒ Object
Adds a negative constraint to the current scenario.
-
#completed?(resource) ⇒ Boolean
you need to override this method to provide a completion criteria.
-
#conditions ⇒ Object
the list of conditions.
-
#method_missing(sym, *args) ⇒ Object
concatenates anything to a current expression.
-
#next_step(resource, mikyung) ⇒ Object
Goes through every scenario and finds which one fits the current server steady state.
-
#scenario ⇒ Object
load scenario definition from ‘scenarios/.scenario’ otherwise you can simply override this method with a module.
-
#steps ⇒ Object
load step definitions from the ‘steps/.rb’ otherwise you can simply override this method with a module.
-
#Then(concat, &block) ⇒ Object
Creates a result rule.
-
#then_rules ⇒ Object
the list of results.
-
#When(concat, &block) ⇒ Object
creates a When rule or block.
-
#when_rules ⇒ Object
the list of conditional rules.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args) ⇒ Object
concatenates anything to a current expression
67 68 69 |
# File 'lib/restfulie/client/mikyung/rest_process_model.rb', line 67 def method_missing(sym, *args) Restfulie::Client::Mikyung::Concatenator.new(sym.to_s, *args) end |
Class Method Details
.accept(type) ⇒ Object
51 52 53 |
# File 'lib/restfulie/client/mikyung/rest_process_model.rb', line 51 def self.accept(type) @@accept = type end |
.at(uri) ⇒ Object
43 44 45 |
# File 'lib/restfulie/client/mikyung/rest_process_model.rb', line 43 def self.at(uri) @@at = uri end |
.current_dir(dir) ⇒ Object
55 56 57 |
# File 'lib/restfulie/client/mikyung/rest_process_model.rb', line 55 def self.current_dir(dir) @@current_dir = dir end |
.follow(bool) ⇒ Object
47 48 49 |
# File 'lib/restfulie/client/mikyung/rest_process_model.rb', line 47 def self.follow(bool) @@follow = bool end |
Instance Method Details
#And(concat) ⇒ Object
Adds a constraint to the current scenario
107 108 109 |
# File 'lib/restfulie/client/mikyung/rest_process_model.rb', line 107 def And(concat) @condition.and when_factory(concat) end |
#But(concat) ⇒ Object
Adds a negative constraint to the current scenario
112 113 114 |
# File 'lib/restfulie/client/mikyung/rest_process_model.rb', line 112 def But(concat) @condition.but when_factory(concat) end |
#completed?(resource) ⇒ Boolean
you need to override this method to provide a completion criteria. Will raise an error otherwise
171 172 173 |
# File 'lib/restfulie/client/mikyung/rest_process_model.rb', line 171 def completed?(resource) raise CompletionCriteriaMissingError.new end |
#conditions ⇒ Object
the list of conditions
77 78 79 |
# File 'lib/restfulie/client/mikyung/rest_process_model.rb', line 77 def conditions @conditions ||= [] end |
#next_step(resource, mikyung) ⇒ Object
Goes through every scenario and finds which one fits the current server steady state. Picks this step and executes the business rule attached to it.
132 133 134 135 136 137 138 139 |
# File 'lib/restfulie/client/mikyung/rest_process_model.rb', line 132 def next_step(resource, mikyung) conditions.each do |c| if c.should_run_for(resource, self) return c.execute(resource, self, mikyung) end end nil end |
#scenario ⇒ Object
load scenario definition from ‘scenarios/.scenario’ otherwise you can simply override this method with a module
157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/restfulie/client/mikyung/rest_process_model.rb', line 157 def scenario unless @scenarios_loaded scenario_file = File.("./scenarios/#{self.class.name.underscore}.scenario", @@current_dir) if File.exists?(scenario_file) self.instance_eval File.read(scenario_file), __FILE__, __LINE__ + 1 else raise ScenarioFileNotFoundError.new("File #{scenario_file} not found") end @scenarios_loaded = true end end |
#steps ⇒ Object
load step definitions from the ‘steps/.rb’ otherwise you can simply override this method with a module
143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/restfulie/client/mikyung/rest_process_model.rb', line 143 def steps unless @steps_loaded step_file = File.("./steps/#{self.class.name.underscore}.rb", @@current_dir) if File.exists?(step_file) self.instance_eval File.read(step_file), __FILE__, __LINE__ + 1 else raise StepsFileNotFoundError.new("File #{step_file} not found") end @steps_loaded = true end end |
#Then(concat, &block) ⇒ Object
Creates a result rule
example: Then “reboot” do |resource|
resource.machine.boot.post! :boot => {:reason => "Installed #{@software[:name]}"}
end
122 123 124 125 126 127 128 |
# File 'lib/restfulie/client/mikyung/rest_process_model.rb', line 122 def Then(concat, &block) if concat.respond_to? :content @condition.results_on Restfulie::Client::Mikyung::ThenCondition.new(concat.content) else then_rules << [concat, block] end end |
#then_rules ⇒ Object
the list of results
72 73 74 |
# File 'lib/restfulie/client/mikyung/rest_process_model.rb', line 72 def then_rules @then_rules ||= [] end |
#When(concat, &block) ⇒ Object
creates a When rule or block
When blocks should return true or false whether the current resource matches what you expect: When /there (are|is an|is a|is) (.*)/ do |resource, regex|
resource.keys.first==regex[2]
end
When rules will group conditions and rules together: When there is a machine And already installed Then reboot
97 98 99 100 101 102 103 104 |
# File 'lib/restfulie/client/mikyung/rest_process_model.rb', line 97 def When(concat, &block) if concat.respond_to? :content @condition = when_factory(concat) conditions << @condition else when_rules << [concat, block] end end |
#when_rules ⇒ Object
the list of conditional rules
82 83 84 |
# File 'lib/restfulie/client/mikyung/rest_process_model.rb', line 82 def when_rules @when_rules ||= [] end |