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.



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

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

Instance Attribute Details

#stepsObject (readonly)

Returns the value of attribute steps.



151
152
153
# File 'lib/flow-lite.rb', line 151

def steps
  @steps
end

Class Method Details

.find_fileObject



99
100
101
102
103
104
105
106
# File 'lib/flow-lite.rb', line 99

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()



116
117
118
119
120
# File 'lib/flow-lite.rb', line 116

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()



110
111
112
113
# File 'lib/flow-lite.rb', line 110

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



133
134
135
136
137
138
139
140
141
142
# File 'lib/flow-lite.rb', line 133

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



124
125
126
127
# File 'lib/flow-lite.rb', line 124

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

#flow_classObject



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

def flow_class
  @flow_class ||= build_flow_class
end

#run(name) ⇒ Object



158
159
160
161
# File 'lib/flow-lite.rb', line 158

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



154
155
156
# File 'lib/flow-lite.rb', line 154

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