Class: Flow::Flowfile

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

Constant Summary collapse

FLOWFILES =

find flowfile path by convention check for name by convention in this order:

['flowfile',    'Flowfile',
'flowfile.rb', 'Flowfile.rb']

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Flowfile

Returns a new instance of Flowfile.



164
165
166
167
# File 'lib/flow-lite.rb', line 164

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

Instance Attribute Details

#stepsObject (readonly)

Returns the value of attribute steps.



169
170
171
# File 'lib/flow-lite.rb', line 169

def steps
  @steps
end

Class Method Details

.find_fileObject



117
118
119
120
121
122
123
124
# File 'lib/flow-lite.rb', line 117

def self.find_file
  FLOWFILES.each do |name|
    return "./#{name}"   if File.exist?( "./#{name}" )
  end

  STDERR.puts "!! ERROR - no flowfile found, sorry - looking for: #{FLOWFILES.join(', ')} in (#{Dir.pwd})"
  exit 1
end

.load(code) ⇒ Object

another convenience method - use like Flowfile.load()



134
135
136
137
138
# File 'lib/flow-lite.rb', line 134

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

.load_file(path = find_file) ⇒ Object

convenience method - use like Flowfile.load_file()



128
129
130
131
# File 'lib/flow-lite.rb', line 128

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

Instance Method Details

#build_flow_classObject



151
152
153
154
155
156
157
158
159
160
# File 'lib/flow-lite.rb', line 151

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

  steps.each do |step|
    klass.define_step( step.names, &step.block )
  end

  klass
end

#flowObject



142
143
144
145
# File 'lib/flow-lite.rb', line 142

def flow
  ## todo/check: always return a new instance why? why not?

  flow_class.new
end

#flow_classObject



147
148
149
# File 'lib/flow-lite.rb', line 147

def flow_class
  @flow_class ||= build_flow_class
end

#run(name) ⇒ Object



176
177
178
179
# File 'lib/flow-lite.rb', line 176

def run( name )
  ## todo/check: always return/use a new instance why? why not?

  flow_class.new.step( name )
end

#step(name, &block) ⇒ Object

“classic / basic” primitives - step



172
173
174
# File 'lib/flow-lite.rb', line 172

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