class WRKFLO::Step

Attributes

name[RW]
project[RW]
raw_config[RW]

Public Class Methods

add_alias(name) click to toggle source

Add an alias for this class to the step map. Used by subclasses to register their definitions

# File lib/wrkflo/step.rb, line 12
def add_alias name
  @@step_map[name.to_sym] = self
end
create(name='', config={}) click to toggle source

Create a new instance of a Step based on the step map entry. If none exists, a generic Step is created.

# File lib/wrkflo/step.rb, line 18
def create name='', config={}, project=nil
  @@step_map[name.to_sym].new(name, config, project) || Step.new(name, config, project)
end
new(name, raw_config, project=nil) click to toggle source
# File lib/wrkflo/step.rb, line 27
def initialize name, raw_config, project=nil
  # The name for this step
  @name = name
  # The options that define this step
  @raw_config = raw_config
  # The project to which this step belongs
  @project = project
  # Generate the finalized step configuration
  apply_configuration(@raw_config)
  # Always validate the new configuration unless specifically told not to.
  ensure_valid_configuration
  # Run step-specific initialization
  init
end

Public Instance Methods

init() click to toggle source

Work done immediately after initializing this step

# File lib/wrkflo/step.rb, line 55
def init;   end
log(message) click to toggle source

A pass through to this step's project's log. If this step has no project, a simple puts call is used instead.

# File lib/wrkflo/step.rb, line 44
def log message
  @project ? @project.log(message) : puts(message)
end
run() click to toggle source

The code to run when running this step normally

# File lib/wrkflo/step.rb, line 59
def run
  log "Nothing to do."
end
setup() click to toggle source

Common work done before running and unrunning.

# File lib/wrkflo/step.rb, line 57
def setup;  end
unrun() click to toggle source

The code to run when running this step backwards

# File lib/wrkflo/step.rb, line 63
def unrun
  log "Nothing to do."
end

Protected Instance Methods

on(platform) { |yn| ... } click to toggle source

Return true if being run on the given platform. If a block is given, run the block only if being run on the given platform and return the result.

# File lib/wrkflo/step.rb, line 72
def on platform
  return OS.send("#{platform}?").tap{ |yn| yield yn if block_given? }
end

Private Instance Methods

ensure_valid_configuration() click to toggle source
# File lib/wrkflo/step.rb, line 79
def ensure_valid_configuration
  validate_configuration do |prop, value, reason|
    prop_name = "`#{@name}.#{prop.name}`"
    case reason
    when :required
      Notifier.error_out("required property #{prop_name} not provided for `#{@project.name}`.", type: "ConfigurationError")
    when :type
      Notifier.error_out(
        "property #{prop_name} for `#{@project.name}` does not match expected type.",
        "expected: #{prop.type_as_string}",
        "got:      #{prop.value_type_as_string(value)}")
    else
      Notifier.error_out("Unknown error", type: "ConfigurationError")
    end
  end
end