Class: Flow::Flowfile

Inherits:
Object
  • Object
show all
Defined in:
lib/flow-lite.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Flowfile

Returns a new instance of Flowfile.



97
98
99
100
# File 'lib/flow-lite.rb', line 97

def initialize( opts={} )
  @opts  = opts
  @steps = []
end

Instance Attribute Details

#stepsObject (readonly)

Returns the value of attribute steps.



102
103
104
# File 'lib/flow-lite.rb', line 102

def steps
  @steps
end

Class Method Details

.load(code) ⇒ Object

another convenience method - use like Flowfile.load()



71
72
73
74
75
# File 'lib/flow-lite.rb', line 71

def self.load( code )
  flowfile = new
  flowfile.instance_eval( code )
  flowfile
end

.load_file(path = './Flowfile') ⇒ Object

convenience method - use like Flowfile.load_file()



65
66
67
68
# File 'lib/flow-lite.rb', line 65

def self.load_file( path='./Flowfile' )
  code = File.open( path, 'r:utf-8' ) { |f| f.read }
  load( code )
end

Instance Method Details

#build_flow_classObject



84
85
86
87
88
89
90
91
92
93
# File 'lib/flow-lite.rb', line 84

def build_flow_class
  puts "[flow]  building flow class..."
  klass = Class.new( Base )

  steps.each do |step|
    klass.define_step( step )
  end

  klass
end

#flowObject

build flow class



79
80
81
82
# File 'lib/flow-lite.rb', line 79

def flow  ## build flow class
  @flow_class ||= build_flow_class
  @flow_class.new   ## todo/check: always return a new instance why? why not?
end

#run(name) ⇒ Object



110
111
112
113
114
115
116
117
118
119
# File 'lib/flow-lite.rb', line 110

def run( name )
  name = name.to_sym  ## make sure we always use symbols
  if flow.respond_to?( name )
     flow.send( name )
  else
    puts "!! ERROR: step definition >#{name}< not found; cannot run/execute - known steps include:"
    pp @steps
    exit 1
  end
end

#step(name, &block) ⇒ Object

“classic / basic” primitives - step



105
106
107
# File 'lib/flow-lite.rb', line 105

def step( name, &block )
  @steps << Step.new( name, block )
end