Class: Rootage::Sequence
- Inherits:
-
StructX
- Object
- StructX
- Rootage::Sequence
- Includes:
- CollectionInterface
- Defined in:
- lib/rootage/core.rb
Overview
Sequence
is a series of items.
Direct Known Subclasses
Instance Attribute Summary
Attributes included from CollectionInterface
Class Method Summary collapse
-
.set_process_context_class(klass) ⇒ void
Set a process context.
Instance Method Summary collapse
-
#append(item) ⇒ void
(also: #<<)
Append the item.
-
#clear ⇒ Object
Clear list.
-
#configure(option) ⇒ void
Configure the sequence option.
-
#copy ⇒ Item
Copy the object.
-
#exception(*exceptions) {|e, args| ... } ⇒ Object
Define an exception handler.
- #execute(scenario, &block) ⇒ Object
-
#get_process_context_class(scenario) ⇒ Object
Return the context class.
-
#post(name) {|item| ... } ⇒ Object
Define a post-action item.
-
#pre(name) {|item| ... } ⇒ Object
Define a pre-action item.
-
#preppend(item) ⇒ void
Preppend the item.
-
#use(item) {|item| ... } ⇒ Object
Use the item.
Methods included from CollectionInterface
Class Method Details
.set_process_context_class(klass) ⇒ void
This method returns an undefined value.
Set a process context. This context is used as default context for items.
243 244 245 |
# File 'lib/rootage/core.rb', line 243 def set_process_context_class(klass) @process_context_class = klass end |
Instance Method Details
#append(item) ⇒ void Also known as: <<
This method returns an undefined value.
Append the item.
286 287 288 |
# File 'lib/rootage/core.rb', line 286 def append(item) list.push(item) end |
#clear ⇒ Object
Clear list.
271 272 273 |
# File 'lib/rootage/core.rb', line 271 def clear list.clear end |
#configure(option) ⇒ void
This method returns an undefined value.
Configure the sequence option.
305 306 307 |
# File 'lib/rootage/core.rb', line 305 def configure(option) config.merge(option) end |
#copy ⇒ Item
Copy the object. This is shallow copy, but arrays are cloned.
262 263 264 265 266 267 268 |
# File 'lib/rootage/core.rb', line 262 def copy self.class.new.tap do |obj| self.each_pair do |key, val| obj.set(key => (val.is_a?(Array) or val.is_a?(Hash)) ? val.clone : val) end end end |
#exception(*exceptions) {|e, args| ... } ⇒ Object
Define an exception handler.
343 344 345 346 347 348 |
# File 'lib/rootage/core.rb', line 343 def exception(*exceptions, &block) if exceptions.empty? exceptions = [StandardError] end self.exception_handlers << ExceptionHandler.new(exceptions, block) end |
#execute(scenario, &block) ⇒ Object
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 |
# File 'lib/rootage/core.rb', line 361 def execute(scenario, &block) catch(:rootage_sequence_quit) do execute_pre(scenario, &block) execute_main(scenario, &block) execute_post(scenario, &block) end rescue Exception => e catch(:rootage_item_stop) do if exception_handlers.find do |handler| catch(:rootage_process_failure) do handler.try_to_handle(get_process_context_class(scenario).new(scenario), e, args) end end else raise end end end |
#get_process_context_class(scenario) ⇒ Object
Return the context class. If this object has no context class, return class's context.
277 278 279 |
# File 'lib/rootage/core.rb', line 277 def get_process_context_class(scenario) self.process_context_class || self.class.instance_variable_get(:@process_context_class) || scenario.process_context_class end |
#post(name) {|item| ... } ⇒ Object
Define a post-action item.
328 329 330 331 332 333 |
# File 'lib/rootage/core.rb', line 328 def post(name, &block) self.posts << item_class.new.tap do |item| item.name = name block.call(item) end end |
#pre(name) {|item| ... } ⇒ Object
Define a pre-action item.
315 316 317 318 319 320 |
# File 'lib/rootage/core.rb', line 315 def pre(name, &block) self.pres << item_class.new.tap do |item| item.name = name block.call(item) end end |
#preppend(item) ⇒ void
This method returns an undefined value.
Preppend the item.
296 297 298 |
# File 'lib/rootage/core.rb', line 296 def preppend(item) list.unshift(item) end |
#use(item) {|item| ... } ⇒ Object
Use the item. This defines an item and pushs it to the sequence.
356 357 358 359 |
# File 'lib/rootage/core.rb', line 356 def use(item, &block) _item = define(item, &block) list << _item end |