flow-lite 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4af502cc9764efd28671cbd3e4e498c0cc9dbd87
4
- data.tar.gz: af96b08715862f411dfb3cdc7a2b87bc8ac4c8e6
3
+ metadata.gz: fd6dc6a4982583a8267aea617e5d7852321b7a00
4
+ data.tar.gz: 5e050df47d5f1d52881c2666f1bb732f39cb4981
5
5
  SHA512:
6
- metadata.gz: c2edc964d13234f76c67c52989e4ff9e664164a61ba185f472d6f24a6300d1ee87cdc8ec30eb40a88258fd9beb63e133f95e852249b7f0d5b624e17430a86b31
7
- data.tar.gz: 90a4af15059474729db047b8ad658c36cfacbcdfd0db1802ec29423d22893806eea0a9beeb371364a05f848ffbf8b82aa15333b32fbf3cfe630d8a73287e7eee
6
+ metadata.gz: 7778366b484f614248c91c33d9aa3e01377c6861408277e5f9e49391e0b5640edcc3dee685c7ed415484bc0a3f2f9c3a2aff852bbbba777b9087e7e49e8803c0
7
+ data.tar.gz: 1b0d6f6148183a97326edcf11c1a0b7b140573b0d758d157c5c06d43947c4e2ca26831c24973f5f56688b06fae421188e44648a94bcde84c81ba27ebd7d10319
data/README.md CHANGED
@@ -12,7 +12,155 @@ flow-lite gem - (yet) another (lite) workflow engine; let's you define your work
12
12
 
13
13
  ## Usage
14
14
 
15
- To be done
15
+
16
+ Define the workflow steps in a Flowfile. Example:
17
+
18
+
19
+ ``` ruby
20
+ step :first_step do
21
+ puts "first_step"
22
+ second_step # note: you can call other steps like methods
23
+ end
24
+
25
+ step :second_step do
26
+ puts "second_step"
27
+ third_step
28
+ end
29
+
30
+ step :third_step do
31
+ puts "third_step"
32
+ end
33
+ ```
34
+
35
+ And than use the `flow` command line tool to run a step.
36
+ Example:
37
+
38
+ ```
39
+ $ flow first_step
40
+ ```
41
+
42
+ Note: By default the `flow` command line tool reads in the `Flowfile`. Use `-f/--flowfile` option to use a different file.
43
+
44
+
45
+ That's it for now.
46
+
47
+
48
+
49
+ ## Backstage Internals / Inside Flowfiles
50
+
51
+
52
+ If you read in a `Flowfile` the flow machinery
53
+ builds a new (regular) class derived from `Flow::Base`
54
+ and every step becomes a (regular) method. Example:
55
+
56
+ ``` ruby
57
+ require 'flow-lite'
58
+
59
+ flowfile = Flow::Flowfile.load( <<TXT )
60
+ step :hello do
61
+ puts "Hello, world!"
62
+ end
63
+
64
+ step :hola do
65
+ puts "¡Hola, mundo!"
66
+ end
67
+ TXT
68
+
69
+ flow = flowfile.flow # (auto-)builds a flow class (see Note 1)
70
+ # and constructs/returns an instance
71
+ flow.hello #=> "Hello, world!"
72
+ flow.hola #=> "¡Hola, mundo!"
73
+
74
+ # or use ruby's (regular) message/metaprogramming machinery
75
+ flow.send( :hello ) #=> "Hello, world!"
76
+ flow.send( :hola ) #=> "¡Hola, mundo!"
77
+ # or try
78
+ flow.class.instance_methods.grep( /^step_/ ) #=> [:step_hello, :step_hola]
79
+ # ...
80
+ ```
81
+
82
+ Note 1: The Flowfile "source / configuration":
83
+
84
+ ``` ruby
85
+ step :hello do
86
+ puts "Hello, world!"
87
+ end
88
+
89
+ step :hola do
90
+ puts "¡Hola, mundo!"
91
+ end
92
+ ```
93
+
94
+ gets used to (auto-) build (via metaprogramming) a flow class like:
95
+
96
+ ``` ruby
97
+ class Greeter < Flow::Base
98
+ def hello
99
+ puts "Hello, world!"
100
+ end
101
+ alias_method :step_hello, :hello
102
+
103
+ def hola
104
+ puts "¡Hola, mundo!"
105
+ end
106
+ alias_method :step_hola, :hola
107
+ end
108
+ ```
109
+
110
+
111
+
112
+ **Tips & Tricks**
113
+
114
+ Auto-include pre-build / pre-defined steps. Use a (regular) Module e.g.:
115
+
116
+ ``` ruby
117
+ module GitHubActions
118
+ def setup
119
+ # setup ssh
120
+ ssh_key = ENV['SSH_KEY']
121
+ ssh_path = File.expand_path( '~/.ssh' )
122
+
123
+ FileUtils.mkdir_p( ssh_path ) # make sure path exists
124
+ File.open( "#{ssh_path}/id_rsa", 'w' ) { |f| f.write( ssh_key ) }
125
+ File.chmod( 0600, "#{ssh_path}/id_rsa" )
126
+
127
+ # setup git
128
+ user_name = ENV['GITHUB_NAME'] || 'you'
129
+ user_email = ENV['GITHUB_EMAIL'] || 'you@example.com'
130
+
131
+ Git.config( 'user.name', user_name, global: true )
132
+ Git.config( 'user.email', user_email, global: true )
133
+
134
+ # ...
135
+ end
136
+ # optional - for auto-discovery add a step alias
137
+ alias_method :step_setup, :setup
138
+ end
139
+ ```
140
+
141
+ and than use (regular) include e.g.:
142
+
143
+ ``` ruby
144
+ class Flow::Base
145
+ include GitHubActions
146
+ end
147
+ ```
148
+
149
+ Now all your flows can (re)use `setup` or any other methods you define.
150
+
151
+
152
+
153
+
154
+
155
+ ## Installation
156
+
157
+ Use
158
+
159
+ gem install flow-lite
160
+
161
+ or add to your Gemfile
162
+
163
+ gem 'flow-lite'
16
164
 
17
165
 
18
166
 
@@ -40,7 +40,20 @@ end # class Step
40
40
 
41
41
 
42
42
  class Base ## base class for flow class (auto)-constructed/build from flowfile
43
- end
43
+ def self.define_step( step )
44
+ name = step.names[0]
45
+ puts " adding step >#{name}<..."
46
+ define_method( name, &step.block )
47
+ alias_method( :"step_#{name}", name ) ## (auto-)add step_<name> alias
48
+
49
+ alt_names = step.names[1..-1]
50
+ alt_names.each do |alt_name|
51
+ puts " adding alias >#{alt_name}< for >#{name}<..."
52
+ alias_method( alt_name, name )
53
+ end
54
+ end
55
+ end # class Base
56
+
44
57
 
45
58
 
46
59
  class Flowfile
@@ -66,20 +79,12 @@ class Flowfile
66
79
 
67
80
  def build_flow_class
68
81
  puts " building flow class..."
69
- flowfile = self
70
- klass = Class.new( Base ) do
71
- flowfile.steps.each_with_index do |step,i|
72
- name = step.names[0]
73
- puts " adding step #{i+1}/#{flowfile.steps.size} >#{name}<..."
74
- define_method( name, &step.block )
75
-
76
- alt_names = step.names[1..-1]
77
- alt_names.each do |alt_name|
78
- puts " adding alias >#{alt_name}< for >#{name}<..."
79
- alias_method( alt_name, name )
80
- end
81
- end
82
+ klass = Class.new( Base )
83
+
84
+ steps.each do |step|
85
+ klass.define_step( step )
82
86
  end
87
+
83
88
  klass
84
89
  end
85
90
 
@@ -1,8 +1,8 @@
1
1
  module FlowLite
2
2
 
3
3
  MAJOR = 0 ## todo: namespace inside version or something - why? why not??
4
- MINOR = 0
5
- PATCH = 1
4
+ MINOR = 1
5
+ PATCH = 0
6
6
  VERSION = [MAJOR,MINOR,PATCH].join('.')
7
7
 
8
8
  def self.version
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flow-lite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer