flow-lite 1.0.3 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bec58eb7b17f61cd186fa21cf7b57bf3b93a8ee0
4
- data.tar.gz: b2c6da0f1440e70133c79b4ab2bdac478c08e8a0
3
+ metadata.gz: 48d2755dfa5c6d365387d7a788804dd458d0fedf
4
+ data.tar.gz: '04586b4969ec5b3aa278ba933904c62ea753f765'
5
5
  SHA512:
6
- metadata.gz: 6eb5a662ed0393f8a77df8077a7df4c9da69038529fa53ef235d299298e33724aaf764cb4fd3fcbcf9cf53606f5bd22143a1f98d89758ff7905a22b9dd9559ea
7
- data.tar.gz: d68c1d0439b921ca86a36e850ecb6837b1e3e5dfbfb1cd411c30466d69d30de6909d8315895b69f8d0db9a4fc1d34578bce789d8d1f36a00137384f697116a2b
6
+ metadata.gz: 10c26e5b61781002e063f4695d676d8847e666950b25c6fe451a1d4e396b14c5b85f5892ecd2cbcc1ac35840f3823462edcb95e0ff221acf06021e30a0503db1
7
+ data.tar.gz: b7fdb1a505e1b9eb92dd219e8e86af7813b17874562f1f45ab0b9f18be8f4f3cf1c44a8d2571c56cb8b17912960ff58b82de1f1af379b92c3cb62a1452c456ce
@@ -4,4 +4,6 @@ README.md
4
4
  Rakefile
5
5
  bin/flow
6
6
  lib/flow-lite.rb
7
+ lib/flow-lite/base.rb
8
+ lib/flow-lite/tool.rb
7
9
  lib/flow-lite/version.rb
@@ -20,6 +20,9 @@ require 'optparse'
20
20
  #####################
21
21
  # our own code
22
22
  require 'flow-lite/version' # note: let version always go first
23
+ require 'flow-lite/base'
24
+ require 'flow-lite/tool'
25
+
23
26
 
24
27
 
25
28
 
@@ -42,72 +45,6 @@ class Step
42
45
  end # class Step
43
46
 
44
47
 
45
-
46
- class Base ## base class for flow class (auto)-constructed/build from flowfile
47
- def self.define_step( name_or_names, &block )
48
- names = if name_or_names.is_a?( Array )
49
- name_or_names
50
- else
51
- [name_or_names] ## assume single symbol (name); wrap in array
52
- end
53
- names = names.map {|name| name.to_sym } ## make sure we always use symbols
54
-
55
-
56
- name = names[0]
57
- puts "[flow] adding step >#{name}<..."
58
- define_method( :"step_#{name}", &block )
59
-
60
- alt_names = names[1..-1]
61
- alt_names.each do |alt_name|
62
- puts "[flow] adding alias >#{alt_name}< for >#{name}<..."
63
- alias_method( :"step_#{alt_name}", :"step_#{name}" )
64
- end
65
- end # method self.define_step
66
-
67
-
68
-
69
- ## run step by symbol/name (e.g. step :hello - etc.)
70
- def step( name )
71
- step_name = :"step_#{name}" ## note: make sure we always use symbols
72
- if respond_to?( step_name )
73
- #######
74
- ## check: track (and report) call stack - why? why not?
75
- ## e.g.
76
- ## [flow >(1) first_step)] step >first_step< - starting...
77
- ## [flow >(2) ..first_step > second_step)] step >second_step< - starting...
78
- ## [flow >(3) ....first_step > second_step > third_step)] step >third_step< - starting...
79
- @stack ||= [] ## use a call stack of step names
80
- @stack.push( name )
81
-
82
- puts "[flow >(#{@stack.size}) #{'..'*(@stack.size-1)}#{@stack.join(' > ')})] step >#{name}< - starting..."
83
- start_time = Time.now ## todo: use Timer? t = Timer.start / stop / diff etc. - why? why not?
84
-
85
- __send__( step_name )
86
-
87
- end_time = Time.now
88
- diff_time = end_time - start_time
89
- puts "[flow <(#{@stack.size}) #{'..'*(@stack.size-1)}#{@stack.join(' < ')})] step >#{name}< - done in #{diff_time} sec(s)"
90
- @stack.pop
91
- else
92
- puts "!! ERROR: step definition >#{name}< not found; cannot run/execute - known (defined) steps include:"
93
- pp self.class.step_methods #=> e.g. [:hello, ...]
94
- exit 1
95
- end
96
- end # method step
97
-
98
-
99
- def self.step_methods
100
- names = instance_methods.reduce([]) do |names, name|
101
- names << $1.to_sym if name =~ /^step_(.+)/
102
- names
103
- end
104
- names
105
- end
106
- end # class Base
107
-
108
-
109
-
110
-
111
48
  class Flowfile
112
49
 
113
50
  ## find flowfile path by convention
@@ -176,69 +113,6 @@ class Flowfile
176
113
  flow_class.new.step( name )
177
114
  end
178
115
  end # class Flowfile
179
-
180
-
181
-
182
-
183
- class Tool
184
- def self.main( args=ARGV )
185
- options = {}
186
- OptionParser.new do |parser|
187
- parser.on( '-f FILENAME', '--flowfile FILENAME' ) do |filename|
188
- options[:flowfile] = filename
189
- end
190
-
191
- ## note:
192
- ## you can add many/multiple modules
193
- ## e.g. -r gitti -r mono etc.
194
- parser.on( '-r NAME', '--require NAME') do |name|
195
- options[:requires] ||= []
196
- options[:requires] << name
197
- end
198
- end.parse!( args )
199
-
200
-
201
- ## check for any (dynamic/auto) requires
202
- if options[:requires]
203
- names = options[:requires]
204
- names.each do |name|
205
- ## todo/check: add some error/exception handling here - why? why not?
206
- puts "[flow] auto-require >#{name}<..."
207
- require( name )
208
- end
209
- else ## use/try defaults
210
- config_path = "./config.rb"
211
- if File.exist?( config_path )
212
- puts "[flow] auto-require (default) >#{config_path}<..."
213
- require( config_path )
214
- end
215
- end
216
-
217
-
218
- path = nil
219
- if options[:flowfile]
220
- path = options[:flowfile]
221
- else
222
- path = Flowfile.find_file
223
-
224
- if path.nil?
225
- STDERR.puts "!! ERROR - no flowfile found, sorry - looking for: #{Flowfile::NAMES.join(', ')} in (#{Dir.pwd})"
226
- exit 1
227
- end
228
- end
229
-
230
- puts "[flow] loading >#{path}<..."
231
- flowfile = Flowfile.load_file( path )
232
-
233
-
234
- ## allow multipe steps getting called - why? why not?
235
- ## flow setup clone update etc??
236
- args.each do |arg|
237
- flowfile.run( arg )
238
- end
239
- end # method self.main
240
- end # class Tool
241
-
242
116
  end # module Flow
243
117
 
244
118
 
@@ -0,0 +1,89 @@
1
+
2
+ module Flow
3
+
4
+ class Base ## base class for flow class (auto)-constructed/build from flowfile
5
+ def self.define_step( name_or_names, &block )
6
+ names = if name_or_names.is_a?( Array )
7
+ name_or_names
8
+ else
9
+ [name_or_names] ## assume single symbol (name); wrap in array
10
+ end
11
+ names = names.map {|name| name.to_sym } ## make sure we always use symbols
12
+
13
+
14
+ name = names[0]
15
+ puts "[flow] adding step >#{name}<..."
16
+ define_method( :"step_#{name}", &block )
17
+
18
+ alt_names = names[1..-1]
19
+ alt_names.each do |alt_name|
20
+ puts "[flow] adding alias >#{alt_name}< for >#{name}<..."
21
+ alias_method( :"step_#{alt_name}", :"step_#{name}" )
22
+ end
23
+ end # method self.define_step
24
+
25
+
26
+
27
+
28
+ TRUE_VALUES = [
29
+ 'true', 't',
30
+ 'yes', 'y',
31
+ 'on',
32
+ '1',
33
+ ]
34
+
35
+ ### include / check for ruby debug flag too - why? why not?
36
+ def debug?
37
+ value = ENV['DEBUG']
38
+ if value && TRUE_VALUES.include?( value.downcase )
39
+ true
40
+ else
41
+ false
42
+ end
43
+ end
44
+
45
+
46
+
47
+ ## run step by symbol/name (e.g. step :hello - etc.)
48
+ ##
49
+ ## todo/check: allow (re)entrant calls to step (step calling step etc.) - why? why not?
50
+ def step( name )
51
+ step_name = :"step_#{name}" ## note: make sure we always use symbols
52
+ if respond_to?( step_name )
53
+ #######
54
+ ## check: track (and report) call stack - why? why not?
55
+ ## e.g.
56
+ ## [flow >(1) first_step)] step >first_step< - starting...
57
+ ## [flow >(2) ..first_step > second_step)] step >second_step< - starting...
58
+ ## [flow >(3) ....first_step > second_step > third_step)] step >third_step< - starting...
59
+ @stack ||= [] ## use a call stack of step names
60
+ @stack.push( name )
61
+
62
+ puts "[flow >(#{@stack.size}) #{'..'*(@stack.size-1)}#{@stack.join(' > ')})] step >#{name}< - starting..."
63
+ start_time = Time.now ## todo: use Timer? t = Timer.start / stop / diff etc. - why? why not?
64
+
65
+ __send__( step_name )
66
+
67
+ end_time = Time.now
68
+ diff_time = end_time - start_time
69
+ puts "[flow <(#{@stack.size}) #{'..'*(@stack.size-1)}#{@stack.join(' < ')})] step >#{name}< - done in #{diff_time} sec(s)"
70
+ @stack.pop
71
+ else
72
+ puts "!! ERROR: step definition >#{name}< not found; cannot run/execute - known (defined) steps include:"
73
+ pp self.class.step_methods #=> e.g. [:hello, ...]
74
+ exit 1
75
+ end
76
+ end # method step
77
+
78
+
79
+ def self.step_methods
80
+ names = instance_methods.reduce([]) do |names, name|
81
+ names << $1.to_sym if name =~ /^step_(.+)/
82
+ names
83
+ end
84
+ names
85
+ end
86
+ end # class Base
87
+
88
+
89
+ end # module Flow
@@ -0,0 +1,130 @@
1
+ module Flow
2
+
3
+ class Tool
4
+ def self.main( args=ARGV )
5
+ options = {}
6
+ OptionParser.new do |parser|
7
+ parser.on( '-f FILE', '--file FILE', '--flowfile FILE',
8
+ 'Read FILE as a flowfile.'
9
+ ) do |file|
10
+ options[:flowfile] = file
11
+ end
12
+
13
+ ## note:
14
+ ## you can add many/multiple modules
15
+ ## e.g. -r gitti -r mono etc.
16
+ parser.on( '-r NAME', '--require NAME') do |name|
17
+ options[:requires] ||= []
18
+ options[:requires] << name
19
+ end
20
+
21
+ parser.on( '-d', '--debug') do |debug|
22
+ options[:debug] = debug
23
+ ## note: for no auto-set env here - why? why not
24
+ ENV['DEBUG']='1' ## use t or true or such - why? why not?
25
+ puts "[flow] setting >DEBUG< env variable to >#{1}<"
26
+ end
27
+
28
+ ## todo/check/reserve: add -e/--env(iornmanet) e.g. dev/test/prod(uction) etc.
29
+ ## plus (convenience) shortcuts e.g. --dev, --prod(uction), --test
30
+ end.parse!( args )
31
+
32
+
33
+ ## check for any (dynamic/auto) requires
34
+ if options[:requires]
35
+ names = options[:requires]
36
+ names.each do |name|
37
+ ## todo/check: add some error/exception handling here - why? why not?
38
+ puts "[flow] auto-require >#{name}<..."
39
+ require( name )
40
+ end
41
+ else ## use/try defaults
42
+ config_path = "./config.rb"
43
+ if File.exist?( config_path )
44
+ puts "[flow] auto-require (default) >#{config_path}<..."
45
+ require( config_path )
46
+ end
47
+ end
48
+
49
+
50
+ path = nil
51
+ if options[:flowfile]
52
+ path = options[:flowfile]
53
+ else
54
+ path = Flowfile.find_file
55
+
56
+ if path.nil?
57
+ STDERR.puts "!! ERROR - no flowfile found, sorry - looking for: #{Flowfile::NAMES.join(', ')} in (#{Dir.pwd})"
58
+ exit 1
59
+ end
60
+ end
61
+
62
+
63
+ ### split args into vars and steps
64
+ vars = []
65
+ args = args.select do |arg|
66
+ ## note: mark freestanding = as fatal error (empty var)
67
+ if arg == '='
68
+ STDERR.puts "!! ERROR - empty var (=) in args; sorry - make sure there are NO spaces before ="
69
+ exit 1
70
+ elsif arg =~ /^[A-Za-z][A-Za-z0-9_]*=/
71
+ vars << arg
72
+ false ## filter -- do NOT include
73
+ else
74
+ true
75
+ end
76
+ end
77
+
78
+ if args.size > 0
79
+ puts "[flow] #{args.size} arg(s):"
80
+ pp args
81
+ end
82
+
83
+ if vars.size > 0
84
+ puts "[flow] #{vars.size} var(s):"
85
+ pp vars
86
+
87
+ ## auto-add vars to ENV
88
+ ## note: if the value is empty e.g. DEBUG= or such
89
+ ## the variable gets deleted / undefined / unset!!
90
+ vars.each do |var|
91
+ pos = var.index('=') ## split on first =
92
+ name = var[0..(pos-1)]
93
+ value = var[(pos+1)..-1]
94
+ # print "[flow] splitting "
95
+ # print "%-24s " % ">#{var}<"
96
+ # print "=> name: "
97
+ # print "%-18s " % ">#{name}<,"
98
+ # print "value: >#{value}< (#{value.class.name})"
99
+ # print "\n"
100
+
101
+ if value.empty? ## note: variable gets deleted / undefined / unset
102
+ puts "[flow] UNSET >#{name}< env variable"
103
+ ENV[ name ] = nil
104
+ else
105
+ puts "[flow] set >#{name}< env variable to >#{value}<"
106
+ ENV[ name ] = value
107
+ end
108
+ end
109
+ end
110
+
111
+
112
+
113
+ puts "[flow] loading >#{path}<..."
114
+ flowfile = Flowfile.load_file( path )
115
+
116
+
117
+
118
+ ## allow multipe steps getting called - why? why not?
119
+ ## flow setup clone update etc. - yes, yes
120
+ ## follow make model and allow variables with FOO= or bar= too
121
+ ## note: mark freestanding = as fatal error (empty var)
122
+
123
+ args.each do |arg|
124
+ flowfile.run( arg )
125
+ end
126
+ end # method self.main
127
+ end # class Tool
128
+
129
+
130
+ end # module Flow
@@ -1,8 +1,8 @@
1
1
  module FlowLite
2
2
 
3
3
  MAJOR = 1 ## todo: namespace inside version or something - why? why not??
4
- MINOR = 0
5
- PATCH = 3
4
+ MINOR = 1
5
+ PATCH = 0
6
6
  VERSION = [MAJOR,MINOR,PATCH].join('.')
7
7
 
8
8
  def self.version
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flow-lite
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-03 00:00:00.000000000 Z
11
+ date: 2020-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rdoc
@@ -61,6 +61,8 @@ files:
61
61
  - Rakefile
62
62
  - bin/flow
63
63
  - lib/flow-lite.rb
64
+ - lib/flow-lite/base.rb
65
+ - lib/flow-lite/tool.rb
64
66
  - lib/flow-lite/version.rb
65
67
  homepage: https://github.com/rubycoco/flow
66
68
  licenses: