Class: Rootage::Sequence

Inherits:
StructX
  • Object
show all
Includes:
CollectionInterface
Defined in:
lib/rootage/core.rb

Overview

Sequence is a series of items.

Direct Known Subclasses

ArgumentDefinition, OptionDefinition, Phase

Instance Attribute Summary

Attributes included from CollectionInterface

#table

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CollectionInterface

#define, #find_item, included

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.

Parameters:

  • process_context_class (Class)

    process context



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.

Parameters:

  • item (Item)

    the action item



286
287
288
# File 'lib/rootage/core.rb', line 286

def append(item)
  list.push(item)
end

#clearObject

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.

Parameters:

  • option (Hash)

    options



305
306
307
# File 'lib/rootage/core.rb', line 305

def configure(option)
  config.merge(option)
end

#copyItem

Copy the object. This is shallow copy, but arrays are cloned.

Returns:

  • (Item)

    copied object



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.

Parameters:

  • exceptions (Array<Class>)

    exception classes that handler should handle, that is assumed StandardError if empty

Yield Parameters:

  • e (Exception)

    raised exception object

  • args (Array)

    arbitrary objects



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.

Parameters:

  • name (Symbol)

    item name

Yield Parameters:

  • item (Item)

    defined postprocess 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.

Parameters:

  • name (Symbol)

    item name

Yield Parameters:

  • item (Item)

    defined preprocess 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.

Parameters:

  • item (Item)

    the action 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.

Parameters:

  • item (Symbol or Item)

    item

Yields:

  • (item)

    the cloned item



356
357
358
359
# File 'lib/rootage/core.rb', line 356

def use(item, &block)
  _item = define(item, &block)
  list << _item
end