clomp 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +4 -4
- data/README.md +7 -7
- data/lib/clomp.rb +1 -0
- data/lib/clomp/executor.rb +9 -11
- data/lib/clomp/operation.rb +12 -6
- data/lib/clomp/option.rb +37 -0
- data/lib/clomp/result.rb +7 -3
- data/lib/clomp/track.rb +4 -3
- data/lib/clomp/track_builder.rb +1 -3
- data/lib/clomp/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f83c752440544965f9794dc3c04b609660c862cd
|
4
|
+
data.tar.gz: 117d87a57db19570f5fa50e33c18ea795b987bd5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ea106882c901f0af269df6141d204a11254002a6e121fa46e86649f022ffeefae39c0bc9685e46078ccd309d6ad6e3e8ae67b73f7bb46ca3e4f19fb970d4d6d
|
7
|
+
data.tar.gz: 2bdb4c799cb9693e8b47f823a480fb808563deb631e2caaaaa87def66397d38ef8668d66fb8d25703ec4f2b8ecdb0117303dd6c09517de9f777fd7f83e57ef4e
|
data/Gemfile.lock
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
clomp (0.0
|
4
|
+
clomp (1.0.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
9
|
ast (2.4.0)
|
10
|
-
byebug (
|
10
|
+
byebug (10.0.0)
|
11
11
|
codeclimate-test-reporter (1.0.7)
|
12
12
|
simplecov
|
13
13
|
diff-lcs (1.3)
|
@@ -23,7 +23,7 @@ GEM
|
|
23
23
|
rspec-core (~> 3.7.0)
|
24
24
|
rspec-expectations (~> 3.7.0)
|
25
25
|
rspec-mocks (~> 3.7.0)
|
26
|
-
rspec-core (3.7.
|
26
|
+
rspec-core (3.7.1)
|
27
27
|
rspec-support (~> 3.7.0)
|
28
28
|
rspec-expectations (3.7.0)
|
29
29
|
diff-lcs (>= 1.2.0, < 2.0)
|
@@ -31,7 +31,7 @@ GEM
|
|
31
31
|
rspec-mocks (3.7.0)
|
32
32
|
diff-lcs (>= 1.2.0, < 2.0)
|
33
33
|
rspec-support (~> 3.7.0)
|
34
|
-
rspec-support (3.7.
|
34
|
+
rspec-support (3.7.1)
|
35
35
|
rubocop (0.52.1)
|
36
36
|
parallel (~> 1.10)
|
37
37
|
parser (>= 2.4.0.2, < 3.0)
|
data/README.md
CHANGED
@@ -25,6 +25,13 @@ Build any service with the track! Add as many tracks as you want.
|
|
25
25
|
tracks will be loaded sequentially. You can control success and failure state of any
|
26
26
|
specific step.
|
27
27
|
|
28
|
+
### Example application
|
29
|
+
You may check the following rails project for basic understanding.
|
30
|
+
[Clomp Usage Example](https://github.com/rubyrider/clomp-example)
|
31
|
+
|
32
|
+
Clomp is completely framework independent agnostic framework. You can use it with any ruby frameworks
|
33
|
+
and even with your raw ruby code.
|
34
|
+
|
28
35
|
|
29
36
|
Consider the following class:
|
30
37
|
```ruby
|
@@ -37,13 +44,6 @@ class AnotherOperation < Clomp::Operation
|
|
37
44
|
end
|
38
45
|
|
39
46
|
class SingingOperation < Clomp::Operation
|
40
|
-
# Configure your operation for common tracks,
|
41
|
-
# configuration can be overridden from individual tracks
|
42
|
-
setup do |config|
|
43
|
-
config.fail_fast = true
|
44
|
-
config.optional = true
|
45
|
-
end
|
46
|
-
|
47
47
|
# this block only executes on failure step!
|
48
48
|
# pass options to receive the operation states!
|
49
49
|
add_track :get_lyrics do |options|
|
data/lib/clomp.rb
CHANGED
data/lib/clomp/executor.rb
CHANGED
@@ -9,7 +9,7 @@ module Clomp
|
|
9
9
|
def [](result = {}, options, _self:)
|
10
10
|
result['tracks'].each_with_index do |track, i|
|
11
11
|
|
12
|
-
break if break?(result['tracks'], i)
|
12
|
+
break if break?(result['tracks'].select {|track| track.executed? }, i)
|
13
13
|
|
14
14
|
next if _self.successful? && track.left_track?
|
15
15
|
next if _self.failed? && track.right_track?
|
@@ -23,17 +23,15 @@ module Clomp
|
|
23
23
|
|
24
24
|
_self
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
def break?(tracks, index)
|
28
|
-
track =
|
29
|
-
|
30
|
-
if track.right_track? && track.failure?
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
true if track.track_options[:pass_fast]
|
28
|
+
track = index > 0 && tracks[index -1] || Track.new(name: SecureRandom.hex(5)).tap {|track| track.mark_as_success! && track.executed = true}
|
29
|
+
|
30
|
+
return true if track.right_track? && track.failure? && track.track_options[:fail_fast]
|
31
|
+
|
32
|
+
return true if track.left_track? && track.track_options[:fail_fast]
|
33
|
+
|
34
|
+
!track.track_options[:pass_fast].nil?
|
37
35
|
end
|
38
36
|
end
|
39
37
|
end
|
data/lib/clomp/operation.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Clomp
|
2
2
|
class Operation
|
3
|
-
attr_reader :result, :configs, :output, :executed
|
3
|
+
attr_reader :result, :configs, :output, :executed, :options
|
4
4
|
|
5
5
|
# Constructor for operation object
|
6
6
|
#
|
@@ -8,14 +8,14 @@ module Clomp
|
|
8
8
|
# @param options [Hash] of options to be provided by .[] call/method
|
9
9
|
# @return [self]
|
10
10
|
def initialize(track_builders: [], options: {}, exec: true)
|
11
|
-
@options = {}
|
11
|
+
@options = Clomp::Option[{params: {}}]
|
12
12
|
@options[:params] = options[:params]
|
13
13
|
@options.merge!(options[:immutable_data]) if options[:immutable_data]
|
14
14
|
# Setup result object!
|
15
15
|
@result = Result.new(
|
16
16
|
operation: self,
|
17
17
|
tracks: track_builders || [],
|
18
|
-
options: @options ||
|
18
|
+
options: @options || Option.new
|
19
19
|
)
|
20
20
|
|
21
21
|
@executed = []
|
@@ -23,10 +23,16 @@ module Clomp
|
|
23
23
|
@output = get_status
|
24
24
|
|
25
25
|
exec_steps! if exec
|
26
|
+
|
27
|
+
prepare_options
|
28
|
+
end
|
29
|
+
|
30
|
+
def prepare_options
|
31
|
+
executed_track_list.map {|track| @options.merge!(track.options)}
|
26
32
|
end
|
27
33
|
|
28
34
|
def executed_tracks
|
29
|
-
executed_track_list.collect {|executed_track| [executed_track.name, executed_track.type, executed_track.state
|
35
|
+
executed_track_list.collect {|executed_track| [executed_track.name, executed_track.type, executed_track.state, executed_track.options.keys.join(' || ')] }.join(" --> ")
|
30
36
|
end
|
31
37
|
|
32
38
|
# Execute all the steps! Execute all the tracks!
|
@@ -131,13 +137,13 @@ module Clomp
|
|
131
137
|
end
|
132
138
|
|
133
139
|
def call(mutable_data = {}, immutable_data = {})
|
134
|
-
new(
|
140
|
+
result = new(
|
135
141
|
track_builders: @track_builders,
|
136
142
|
options: {
|
137
143
|
params: mutable_data || {},
|
138
144
|
immutable_data: immutable_data || {}
|
139
145
|
},
|
140
|
-
|
146
|
+
).result
|
141
147
|
end
|
142
148
|
|
143
149
|
alias_method :[], :call
|
data/lib/clomp/option.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
module Clomp
|
2
|
+
class Option < ::Hash
|
3
|
+
alias_method :_get, :[] # preserve the original #[] method
|
4
|
+
protected :_get # make it protected
|
5
|
+
|
6
|
+
def []=(key, value)
|
7
|
+
super(key.to_sym, value)
|
8
|
+
end
|
9
|
+
|
10
|
+
def [](key)
|
11
|
+
super(key.to_sym)
|
12
|
+
end
|
13
|
+
|
14
|
+
def set(key, value)
|
15
|
+
self[key] = value
|
16
|
+
end
|
17
|
+
|
18
|
+
def method_missing(name, *args)
|
19
|
+
name_string = name.to_s
|
20
|
+
if name_string.chomp!('=')
|
21
|
+
self[name_string] = args.first
|
22
|
+
else
|
23
|
+
bangs = name_string.chomp!('!')
|
24
|
+
|
25
|
+
if bangs
|
26
|
+
fetch(name_string.to_sym).presence || raise(KeyError.new("#{name_string} is blank."))
|
27
|
+
else
|
28
|
+
self[name_string]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def respond_to_missing?(name, include_private)
|
34
|
+
true
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/clomp/result.rb
CHANGED
@@ -1,14 +1,18 @@
|
|
1
1
|
module Clomp
|
2
2
|
class Result
|
3
|
-
attr_reader :
|
3
|
+
attr_reader :operation, :state
|
4
4
|
|
5
5
|
def initialize(options: {}, tracks: [], operation: nil)
|
6
6
|
@report = {}
|
7
7
|
@operation = set_prop :operation, operation || Operation.new
|
8
8
|
@tracks = set_prop :tracks, tracks || []
|
9
|
-
@options =
|
9
|
+
@options = Option.new
|
10
10
|
@immutable_data = set_prop :options, options
|
11
|
-
@state = ->(tracks) {tracks.select {|track| track.failure?}.count.zero?}
|
11
|
+
@state = ->(tracks) { tracks.select {|track| track.failure?}.count.zero? }
|
12
|
+
end
|
13
|
+
|
14
|
+
def options=(options = Option.new)
|
15
|
+
@options = options
|
12
16
|
end
|
13
17
|
|
14
18
|
def data
|
data/lib/clomp/track.rb
CHANGED
@@ -2,12 +2,12 @@ module Clomp
|
|
2
2
|
class Track
|
3
3
|
include Clomp::CommonStates
|
4
4
|
|
5
|
-
attr_reader :name, :block, :track_options, :state, :error, :track_from, :left, :right
|
5
|
+
attr_reader :name, :block, :track_options, :state, :error, :track_from, :left, :right, :options
|
6
6
|
attr_accessor :executed
|
7
7
|
|
8
8
|
VALID_TRACK_TYPES = %I(track failed_track finally catch)
|
9
9
|
|
10
|
-
def initialize(name: (raise Errors::NoTrackProvided), track_options: {}, right: true, track_from: nil, &block)
|
10
|
+
def initialize(name: (raise Errors::NoTrackProvided), track_options: {}, right: true, track_from: nil, options: Option.new, &block)
|
11
11
|
@name = name
|
12
12
|
@track_from = track_from
|
13
13
|
@block = block
|
@@ -17,6 +17,7 @@ module Clomp
|
|
17
17
|
@right = right
|
18
18
|
@left = !@right
|
19
19
|
@executed = false
|
20
|
+
@options = options
|
20
21
|
end
|
21
22
|
|
22
23
|
def executed?
|
@@ -40,7 +41,7 @@ module Clomp
|
|
40
41
|
# Track#exec! executes the steps defined in the operation class
|
41
42
|
def exec!(object, options)
|
42
43
|
mark_as_failure! # going to execute! set to failure initially
|
43
|
-
|
44
|
+
@options = options
|
44
45
|
if object.method(name.to_sym).arity > 1
|
45
46
|
mark_as_success! if object.public_send(name.to_sym, options, **options) != false
|
46
47
|
else
|
data/lib/clomp/track_builder.rb
CHANGED
data/lib/clomp/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clomp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Irfan Ahmed
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-02-
|
11
|
+
date: 2018-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -138,6 +138,7 @@ files:
|
|
138
138
|
- lib/clomp/errors.rb
|
139
139
|
- lib/clomp/executor.rb
|
140
140
|
- lib/clomp/operation.rb
|
141
|
+
- lib/clomp/option.rb
|
141
142
|
- lib/clomp/result.rb
|
142
143
|
- lib/clomp/track.rb
|
143
144
|
- lib/clomp/track_builder.rb
|