clomp 0.0.6 → 0.0.7

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: 157180a93184acd687b9a7f477c3fa802e25e97d
4
- data.tar.gz: 4764196bd4c58fa24a080c64acadc4c39551bdce
3
+ metadata.gz: 8fcc8ef3538d403411b6830fdff8f3ac9182e92e
4
+ data.tar.gz: a4053d2ae44b83d05db2b1edf47c6349a24e2328
5
5
  SHA512:
6
- metadata.gz: e36e6fec60c1f24f8875594e42c3c378f8168f5189aedc9ea57a42e0dc09ade21d28ddfd62a31833d48424650047f752848684a68a3bb6269e0c38c20189643d
7
- data.tar.gz: ca9b011b066f366ed6af520f5581052f5d3873eadbc084d3168e268a64c5127bf33de8bc2d425942a67eb504cd7d08b5b8d6a881fee0a6371a1db8642403fd5d
6
+ metadata.gz: 1614abe9d9fcd6ebba4597538ac9dd69176a9422ff664c7738f298c74438ec78cced76958a99df7b728e4d6001a86da4e76a7f1dbd01abba6fb5fd46204ac705
7
+ data.tar.gz: 336ca614bb77901c93546adbfcc48c94f5b21c46ad5af68fd3177406bc3837b0b4330e844fb5d3329a26b8d6b20b46c80a59e4e98d252bee9163ae969b45f34d
data/.byebug_history CHANGED
@@ -1,12 +1,7 @@
1
1
  c
2
- Callable[result, track, options, _self]
3
- track.name
4
- track.track_from
2
+ x
3
+ z
5
4
  c
6
- track.track_from
7
- Callable[result, track, options, _self]
8
- track
9
- _self
10
- track.name
11
- track_name
12
- _callable_object
5
+ failure?
6
+ n
7
+ User.new
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- clomp (0.0.5)
4
+ clomp (0.0.6)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -85,6 +85,16 @@ end
85
85
  @result.failure? # => false
86
86
  ```
87
87
 
88
+ Trace the steps:
89
+ ```ruby
90
+ @result = SingingOperation[singer_name: 'Base Baba']
91
+ @result.executed_tracks
92
+ "first_track:track:success --> track_from_another_operation:track:success --> call_something:track:success"
93
+
94
+ @result.to_s
95
+ "Clomp::Result > Successful: first_track:track:success --> track_from_another_operation:track:success --> call_something:track:success"
96
+ ```
97
+
88
98
  ## Configuration
89
99
  You can set custom step name(s), custom fail, pass flow configuration globally and operation wise!
90
100
 
data/_config.yml ADDED
@@ -0,0 +1 @@
1
+ theme: jekyll-theme-cayman
@@ -3,19 +3,27 @@ require 'pp'
3
3
  module Clomp
4
4
  class Executor
5
5
  class << self
6
- def [](result = {}, options, _self: )
6
+ # _self = operation
7
+ #
8
+ def [](result = {}, options, _self:)
7
9
  result['tracks'].each do |track|
8
10
  next unless track.track?
9
11
 
10
12
  _callable_object = Callable[track, options, _self]
11
-
13
+
12
14
  raise Errors::TrackNotDefined, "Please define the track in your operation/service: #{track.name} in #{_callable_object.class}" unless _callable_object.respond_to?(track.name)
13
-
15
+
14
16
  _track = track.exec!(_callable_object, options)
15
-
16
- break if _track.failure?
17
+
18
+ _self.executed << _track
19
+
20
+ # Considering pass first on success state
21
+ break if _track.success? && ((options[:pass_fast]) || Configuration.setup.pass_fast)
22
+
23
+ # Consider both local or global configuration
24
+ break if _track.failure? && ((options[:fail_fast]) || Configuration.setup.fail_fast)
17
25
  end
18
-
26
+
19
27
  _self
20
28
  end
21
29
  end
@@ -1,6 +1,6 @@
1
1
  module Clomp
2
2
  class Operation
3
- attr_reader :result, :configs
3
+ attr_reader :result, :configs, :output, :executed
4
4
 
5
5
  # Constructor for operation object
6
6
  #
@@ -8,19 +8,27 @@ 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 = options
11
+ @options = {}
12
+ @options[:params] = options[:params]
13
+ @options.merge!(options[:immutable_data]) if options[:immutable_data]
12
14
  # Setup result object!
13
15
  @result = Result.new(
14
16
  operation: self,
15
17
  tracks: track_builders || [],
16
- options: options || {}
18
+ options: @options || {}
17
19
  )
18
20
 
19
- @configs = self.class.setup_configuration
21
+ @executed = []
22
+ @configs = self.class.setup_configuration
23
+ @output = get_status
20
24
 
21
25
  exec_steps! if exec
22
26
  end
23
27
 
28
+ def executed_tracks
29
+ @executed.collect {|executed_track| [executed_track.name, executed_track.type, executed_track.state].join(":") }.join(" --> ")
30
+ end
31
+
24
32
  # Execute all the steps! Execute all the tracks!
25
33
  def exec_steps!
26
34
  Executor[result, @options, _self: self]
@@ -30,6 +38,19 @@ module Clomp
30
38
  @result['tracks'].collect {|track| track.name if track.success?}.compact
31
39
  end
32
40
 
41
+ # collect track status
42
+ def get_status
43
+ @result['tracks'].collect {|track| track.name if track.failure?}.compact.count.zero? ? 'Success' : 'Failure'
44
+ end
45
+
46
+ def failed
47
+ get_status == 'Failure'
48
+ end
49
+
50
+ def successful
51
+ get_status == 'Success'
52
+ end
53
+
33
54
  # Name of the steps defined in the operation class
34
55
  def steps
35
56
  @result['tracks'].collect {|track| track.name}
@@ -62,12 +83,12 @@ module Clomp
62
83
  # Share track from other operation
63
84
  def share(track_name, from:, track_options: {}, &block)
64
85
  @track_builders ||= []
65
-
86
+
66
87
  _callable_class = from && from.kind_of?(String) ? Object.const_get(from) : from
67
88
 
68
89
  raise UnknownOperation, 'Please provide a valid operation to share the steps for' unless _callable_class
69
90
 
70
- @track_builders << build_track(track_name, track_options, :track, track_for: _callable_class , &block)
91
+ @track_builders << build_track(track_name, track_options, :track, track_for: _callable_class, &block)
71
92
  end
72
93
 
73
94
  # get track name and options!
@@ -90,7 +111,7 @@ module Clomp
90
111
  # get the track name for the failure case!
91
112
  def failure(track_name, track_options: {}, &block)
92
113
  @track_builders ||= []
93
-
114
+
94
115
  @track_builders << build_track(track_name, track_options, :failed_track, track_for: nil, &block)
95
116
  end
96
117
 
@@ -105,7 +126,7 @@ module Clomp
105
126
  new(
106
127
  track_builders: @track_builders,
107
128
  options: {
108
- params: mutable_data || {},
129
+ params: mutable_data || {},
109
130
  immutable_data: immutable_data || {}
110
131
  },
111
132
  ).result
data/lib/clomp/result.rb CHANGED
@@ -27,6 +27,14 @@ module Clomp
27
27
  @state.(self[:tracks]) === false
28
28
  end
29
29
 
30
+ def state_statement
31
+ success? ? 'Successful' : 'Failure'
32
+ end
33
+
34
+ def to_s
35
+ "#{self.class.name} > #{state_statement}: #{executed_tracks}"
36
+ end
37
+
30
38
  def method_missing(method, *args)
31
39
  if @operation.respond_to?(method)
32
40
  @operation.send(method, *args)
data/lib/clomp/track.rb CHANGED
@@ -2,7 +2,7 @@ module Clomp
2
2
  class Track
3
3
  include Clomp::CommonStates
4
4
 
5
- attr_reader :name, :block, :track_options, :state, :error, :track_from
5
+ attr_reader :name, :block, :track_options, :state, :error, :track_from, :type
6
6
 
7
7
  VALID_TRACK_TYPES = %I(track failed_track finally catch)
8
8
 
@@ -28,10 +28,6 @@ module Clomp
28
28
  end
29
29
  end
30
30
 
31
- def track?
32
- @type == :track
33
- end
34
-
35
31
  # Track#exec! executes the steps defined in the operation class
36
32
  def exec!(object, options)
37
33
  mark_as_failure! # going to execute! set to failure initially
@@ -48,6 +44,8 @@ module Clomp
48
44
 
49
45
  rescue => e
50
46
  @error = e.message
47
+
48
+ mark_as_failure!
51
49
 
52
50
  self
53
51
  end
data/lib/clomp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Clomp
2
- VERSION = '0.0.6'
2
+ VERSION = '0.0.7'
3
3
  end
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: 0.0.6
4
+ version: 0.0.7
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-01-14 00:00:00.000000000 Z
11
+ date: 2018-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -85,6 +85,7 @@ files:
85
85
  - LICENSE.txt
86
86
  - README.md
87
87
  - Rakefile
88
+ - _config.yml
88
89
  - bin/console
89
90
  - bin/setup
90
91
  - clomp.gemspec