Class: Flow::Flowfile

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

Constant Summary collapse

NAMES =

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.



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

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

Instance Attribute Details

#stepsObject (readonly)

Returns the value of attribute steps.



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

def steps
  @steps
end

Class Method Details

.find_fileObject



54
55
56
57
58
59
# File 'lib/flow-lite.rb', line 54

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

.load(code) ⇒ Object

another convenience method - use like Flowfile.load()



69
70
71
72
73
# File 'lib/flow-lite.rb', line 69

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

.load_file(path) ⇒ Object

convenience method - use like Flowfile.load_file()



63
64
65
66
# File 'lib/flow-lite.rb', line 63

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

Instance Method Details

#build_flow_classObject



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

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



77
78
79
80
# File 'lib/flow-lite.rb', line 77

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

#flow_classObject



82
83
84
# File 'lib/flow-lite.rb', line 82

def flow_class
  @flow_class ||= build_flow_class
end

#run(name) ⇒ Object



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

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



107
108
109
# File 'lib/flow-lite.rb', line 107

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