trailblazer-operation 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +8 -0
  3. data/.rubocop_todo.yml +223 -0
  4. data/.travis.yml +6 -7
  5. data/CHANGES.md +2 -14
  6. data/Gemfile +4 -2
  7. data/README.md +13 -2
  8. data/Rakefile +2 -2
  9. data/lib/trailblazer/operation.rb +53 -67
  10. data/lib/trailblazer/operation/class_dependencies.rb +1 -1
  11. data/lib/trailblazer/operation/container.rb +14 -0
  12. data/lib/trailblazer/operation/deprecated_macro.rb +2 -2
  13. data/lib/trailblazer/operation/inspect.rb +17 -27
  14. data/lib/trailblazer/operation/public_call.rb +16 -18
  15. data/lib/trailblazer/operation/railway.rb +2 -3
  16. data/lib/trailblazer/operation/railway/macaroni.rb +2 -2
  17. data/lib/trailblazer/operation/result.rb +14 -1
  18. data/lib/trailblazer/operation/trace.rb +5 -8
  19. data/lib/trailblazer/operation/version.rb +4 -2
  20. data/test/benchmark/skill_resolver_benchmark.rb +8 -9
  21. data/test/call_test.rb +56 -30
  22. data/test/callable_test.rb +147 -147
  23. data/test/class_dependencies_test.rb +6 -7
  24. data/test/docs/doormat_test.rb +13 -12
  25. data/test/docs/macaroni_test.rb +7 -9
  26. data/test/docs/operation_test.rb +69 -4
  27. data/test/docs/wiring_test.rb +98 -53
  28. data/test/dry_container_test.rb +4 -3
  29. data/test/fast_track_test.rb +24 -44
  30. data/test/inheritance_test.rb +13 -12
  31. data/test/inspect_test.rb +6 -7
  32. data/test/introspect_test.rb +6 -6
  33. data/test/operation_test.rb +17 -25
  34. data/test/result_test.rb +4 -4
  35. data/test/ruby-2.0.0/operation_test.rb +9 -9
  36. data/test/ruby-2.0.0/step_test.rb +17 -16
  37. data/test/step_test.rb +47 -42
  38. data/test/test_helper.rb +6 -13
  39. data/test/trace_test.rb +26 -26
  40. data/test/wiring/defaults_test.rb +29 -33
  41. data/trailblazer-operation.gemspec +7 -6
  42. metadata +26 -18
  43. data/lib/trailblazer/operation/heritage.rb +0 -30
  44. data/lib/trailblazer/operation/inject.rb +0 -36
  45. data/lib/trailblazer/operation/railway/fast_track.rb +0 -13
  46. data/lib/trailblazer/operation/railway/normalizer.rb +0 -58
  47. data/lib/trailblazer/operation/railway/task_builder.rb +0 -37
  48. data/test/macro_test.rb +0 -60
  49. data/test/task_wrap_test.rb +0 -97
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d3347429bc2a448f6f41390b5d70aea2076d32235acb78f51563fbcb8f935f8e
4
- data.tar.gz: 68200b340b34a5965cd773921b8282a4eb0f0ad56ae87e1b7ad2585a362cc02a
3
+ metadata.gz: d01fa1d700a2dd5435e8f166189be31b2da6ec460eec204c6aac8b02887c9ad6
4
+ data.tar.gz: a0f41c6afd8f2e85ff86ceab11be439b8ea0ef3340b8e33ada6c34bcf2f5bca6
5
5
  SHA512:
6
- metadata.gz: 6824c50e6c8f48b587afc1e8a2f08b3b1813379c811f6b1017c6088bdd9836c445839a20cec3ac1407b33290ea5c4a1d3ee47da77854de8bfde7bf24a4230662
7
- data.tar.gz: b0fb9530502238b3bfab54311c93793a4c4f028091ba72a7f9e71a3eb1f760edb077577d2e542d06d6650c392b160f464a44c6f1c7d90d79b9447e468f6935c3
6
+ metadata.gz: c7f95eed76ec2109879d2750636e43d82da24f42af7d58e037538565cd115ff04e9cf2cbeb9d4f2170cb614fb0585d2edbe98ce2a7c94d7d732c8d1ded6e60f8
7
+ data.tar.gz: efd28f9dff2d79bfea21d2438119d8e619410333a904ba50dcccc13d450ae42efd1d71639068bd40168f2283c9c34f1fb9834f8ae56b866d16b2bc0e1b425526
data/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ inherit_from:
2
+ - https://raw.githubusercontent.com/trailblazer/meta/master/rubocop.yml
3
+ - .rubocop_todo.yml
4
+
5
+ Naming/MethodName:
6
+ Exclude:
7
+ - 'lib/trailblazer/operation/inject.rb'
8
+ - 'lib/trailblazer/operation.rb'
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,223 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2019-04-05 17:28:56 +1100 using RuboCop version 0.58.1.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ # Configuration parameters: Include.
11
+ # Include: **/*.gemspec
12
+ Gemspec/RequiredRubyVersion:
13
+ Exclude:
14
+ - 'trailblazer-operation.gemspec'
15
+
16
+ # Offense count: 5
17
+ # Cop supports --auto-correct.
18
+ Layout/CommentIndentation:
19
+ Exclude:
20
+ - 'lib/trailblazer/operation/version.rb'
21
+ - 'test/wiring/defaults_test.rb'
22
+
23
+ # Offense count: 3
24
+ # Cop supports --auto-correct.
25
+ # Configuration parameters: AllowAdjacentOneLineDefs, NumberOfEmptyLines.
26
+ Layout/EmptyLineBetweenDefs:
27
+ Exclude:
28
+ - 'lib/trailblazer/operation.rb'
29
+
30
+ # Offense count: 1
31
+ # Cop supports --auto-correct.
32
+ Layout/EmptyLines:
33
+ Exclude:
34
+ - 'lib/trailblazer/operation.rb'
35
+
36
+ # Offense count: 1
37
+ # Cop supports --auto-correct.
38
+ # Configuration parameters: AllowForAlignment, ForceEqualSignAlignment.
39
+ Layout/ExtraSpacing:
40
+ Exclude:
41
+ - 'lib/trailblazer/operation.rb'
42
+
43
+ # Offense count: 2
44
+ # Cop supports --auto-correct.
45
+ Layout/SpaceBeforeSemicolon:
46
+ Exclude:
47
+ - 'lib/trailblazer/operation.rb'
48
+
49
+ # Offense count: 2
50
+ # Cop supports --auto-correct.
51
+ # Configuration parameters: EnforcedStyle.
52
+ # SupportedStyles: space, no_space
53
+ Layout/SpaceInsideParens:
54
+ Exclude:
55
+ - 'lib/trailblazer/operation.rb'
56
+
57
+ # Offense count: 2
58
+ Lint/ShadowingOuterLocalVariable:
59
+ Exclude:
60
+ - 'lib/trailblazer/operation/deprecated_macro.rb'
61
+ - 'lib/trailblazer/operation/public_call.rb'
62
+
63
+ # Offense count: 1
64
+ # Cop supports --auto-correct.
65
+ # Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments.
66
+ Lint/UnusedBlockArgument:
67
+ Exclude:
68
+ - 'lib/trailblazer/operation/inspect.rb'
69
+
70
+ # Offense count: 2
71
+ Lint/UselessAssignment:
72
+ Exclude:
73
+ - 'lib/trailblazer/operation/public_call.rb'
74
+ - 'lib/trailblazer/operation/trace.rb'
75
+
76
+ # Offense count: 46
77
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
78
+ # URISchemes: http, https
79
+ Metrics/LineLength:
80
+ Max: 255
81
+
82
+ # Offense count: 2
83
+ Naming/ConstantName:
84
+ Exclude:
85
+ - 'lib/trailblazer/operation/inspect.rb'
86
+ - 'lib/trailblazer/operation/version.rb'
87
+
88
+ # Offense count: 1
89
+ # Cop supports --auto-correct.
90
+ Performance/StringReplacement:
91
+ Exclude:
92
+ - 'lib/trailblazer/operation/inspect.rb'
93
+
94
+ # Offense count: 2
95
+ # Cop supports --auto-correct.
96
+ Style/BlockComments:
97
+ Exclude:
98
+ - 'test/docs/wiring_test.rb'
99
+
100
+ # Offense count: 3
101
+ # Cop supports --auto-correct.
102
+ # Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, IgnoredMethods.
103
+ # SupportedStyles: line_count_based, semantic, braces_for_chaining
104
+ # ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object
105
+ # FunctionalMethods: let, let!, subject, watch
106
+ # IgnoredMethods: lambda, proc, it
107
+ Style/BlockDelimiters:
108
+ Exclude:
109
+ - 'lib/trailblazer/operation/inspect.rb'
110
+ - 'test/step_test.rb'
111
+
112
+ # Offense count: 1
113
+ # Cop supports --auto-correct.
114
+ # Configuration parameters: EnforcedStyle.
115
+ # SupportedStyles: braces, no_braces, context_dependent
116
+ Style/BracesAroundHashParameters:
117
+ Exclude:
118
+ - 'lib/trailblazer/operation/public_call.rb'
119
+
120
+ # Offense count: 1
121
+ # Cop supports --auto-correct.
122
+ # Configuration parameters: EnforcedStyle.
123
+ # SupportedStyles: is_a?, kind_of?
124
+ Style/ClassCheck:
125
+ Exclude:
126
+ - 'lib/trailblazer/operation/railway.rb'
127
+
128
+ # Offense count: 2
129
+ Style/CommentedKeyword:
130
+ Exclude:
131
+ - 'lib/trailblazer/operation/railway.rb'
132
+
133
+ # Offense count: 1
134
+ # Cop supports --auto-correct.
135
+ Style/DefWithParentheses:
136
+ Exclude:
137
+ - 'lib/trailblazer/operation.rb'
138
+
139
+ # Offense count: 1
140
+ # Cop supports --auto-correct.
141
+ Style/ExpandPathArguments:
142
+ Exclude:
143
+ - 'trailblazer-operation.gemspec'
144
+
145
+ # Offense count: 3
146
+ # Cop supports --auto-correct.
147
+ # Configuration parameters: EnforcedStyle.
148
+ # SupportedStyles: format, sprintf, percent
149
+ Style/FormatString:
150
+ Exclude:
151
+ - 'lib/trailblazer/operation/inspect.rb'
152
+
153
+ # Offense count: 1
154
+ # Configuration parameters: .
155
+ # SupportedStyles: annotated, template, unannotated
156
+ Style/FormatStringToken:
157
+ EnforcedStyle: unannotated
158
+
159
+ # Offense count: 3
160
+ Style/MethodCalledOnDoEndBlock:
161
+ Exclude:
162
+ - 'lib/trailblazer/operation/inspect.rb'
163
+ - 'test/step_test.rb'
164
+
165
+ # Offense count: 2
166
+ # Cop supports --auto-correct.
167
+ Style/MutableConstant:
168
+ Exclude:
169
+ - 'lib/trailblazer/operation/inspect.rb'
170
+ - 'lib/trailblazer/operation/version.rb'
171
+
172
+ # Offense count: 1
173
+ # Cop supports --auto-correct.
174
+ Style/ParallelAssignment:
175
+ Exclude:
176
+ - 'lib/trailblazer/operation/result.rb'
177
+
178
+ # Offense count: 4
179
+ # Cop supports --auto-correct.
180
+ # Configuration parameters: PreferredDelimiters.
181
+ Style/PercentLiteralDelimiters:
182
+ Exclude:
183
+ - 'Rakefile'
184
+
185
+ # Offense count: 4
186
+ # Cop supports --auto-correct.
187
+ # Configuration parameters: EnforcedStyle.
188
+ # SupportedStyles: only_raise, only_fail, semantic
189
+ Style/SignalException:
190
+ Exclude:
191
+ - 'test/operation_test.rb'
192
+ - 'test/ruby-2.0.0/operation_test.rb'
193
+
194
+ # Offense count: 1
195
+ # Cop supports --auto-correct.
196
+ # Configuration parameters: EnforcedStyle.
197
+ # SupportedStyles: use_perl_names, use_english_names
198
+ Style/SpecialGlobalVars:
199
+ Exclude:
200
+ - 'trailblazer-operation.gemspec'
201
+
202
+ # Offense count: 3
203
+ # Cop supports --auto-correct.
204
+ # Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
205
+ # SupportedStyles: single_quotes, double_quotes
206
+ Style/StringLiterals:
207
+ Exclude:
208
+ - 'Gemfile'
209
+ - 'trailblazer-operation.gemspec'
210
+
211
+ # Offense count: 1
212
+ # Cop supports --auto-correct.
213
+ # Configuration parameters: EnforcedStyleForMultiline.
214
+ # SupportedStylesForMultiline: comma, consistent_comma, no_comma
215
+ Style/TrailingCommaInHashLiteral:
216
+ Exclude:
217
+ - 'lib/trailblazer/operation.rb'
218
+
219
+ # Offense count: 2
220
+ # Cop supports --auto-correct.
221
+ Style/UnneededPercentQ:
222
+ Exclude:
223
+ - 'trailblazer-operation.gemspec'
data/.travis.yml CHANGED
@@ -1,17 +1,16 @@
1
1
  language: ruby
2
2
  before_install:
3
- - gem install bundler
3
+ - gem install bundler -v 1.17.3
4
4
  matrix:
5
5
  include:
6
- # - rvm: 2.0.0
7
- # gemfile: "test/gemfiles/Gemfile.ruby-2.0"
8
- - rvm: 2.1
9
- gemfile: Gemfile
6
+ # - rvm: 2.1.0
7
+ # gemfile: Gemfile
10
8
  - rvm: 2.2.4
11
9
  gemfile: Gemfile
12
10
  - rvm: 2.3.3
13
11
  gemfile: Gemfile
14
12
  - rvm: 2.4.0
15
13
  gemfile: Gemfile
16
- - rvm: jruby-9.1.13.0
17
- env: JRUBY_OPTS="--profile.api"
14
+ - rvm: 2.5.0
15
+ gemfile: Gemfile
16
+ script: bundle exec rake test
data/CHANGES.md CHANGED
@@ -1,18 +1,6 @@
1
- TODO:
2
- * api to add your own task.
1
+ ## 0.5.0
3
2
 
4
- lots of work on the DSL specific parts.
5
- Graph and Sequence to make it easier to wire anything.
6
- macros can now add/modify the wiring, e.g. their end to the our end or the next task.
7
- [ use circuit for actual step_args/initialize process, too? ]
8
- You can now add an unlimited number of "your own" end events, which can then be interpreted on the outside (e.g. Endpoint)
9
- * Introduced the `fast_track: true` option for steps. If you were returning `Railway.fail_fast!` and the like, you now need to declare that option, e.g.
10
-
11
- ```ruby
12
- step :my_validate!, fast_track: true
13
- ```
14
-
15
- params:, rest: ..
3
+ * Minimal API around `Activity::FastTrack` to support the old public call style.
16
4
 
17
5
 
18
6
  ## 0.4.1
data/Gemfile CHANGED
@@ -7,9 +7,11 @@ gem "multi_json"
7
7
 
8
8
  gem "dry-auto_inject"
9
9
 
10
- gem "minitest-line"
11
10
  gem "benchmark-ips"
11
+ gem "minitest-line"
12
12
 
13
13
  # gem "trailblazer-developer", path: "../developer"
14
14
  # gem "trailblazer-developer", git: "https://github.com/trailblazer/trailblazer-developer"
15
- gem "trailblazer-activity", path: "../trailblazer-activity"
15
+ # gem "trailblazer-activity", path: "../trailblazer-activity"
16
+ # gem "trailblazer-activity-dsl-linear", path: "../trailblazer-activity-dsl-linear"
17
+ # gem "trailblazer-activity", github: "trailblazer/trailblazer-activity"
data/README.md CHANGED
@@ -1,6 +1,17 @@
1
- ## Goal
1
+ # Trailblazer-operation
2
2
 
3
- * Make `Operation` an imutable object without having to expose @instance variables. This is now done via the Result object.
3
+ _Trailblazer's Operation implementation._
4
+
5
+ ## Overview
6
+
7
+ An operation is a pattern from the Trailblazer architecture. It implements a public function such as "create user" or "archive blog post". Internally, an operation is simply a generic _activity_ that uses an existing DSL to help you creating the operation's flow.
8
+
9
+ An operation is identical to an activity with two additions.
10
+
11
+ * A public `call` method with a simplified signature `Create.call(params: params, current_user: @user)`
12
+ * It produces a `Result` object with the popular `success?` API.
13
+
14
+ An operation can be used exaclty like an activity, including nesting, tracing, etc.
4
15
 
5
16
  ## Copyright
6
17
 
data/Rakefile CHANGED
@@ -1,8 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rake/testtask"
3
3
 
4
- task :default => [:test]
5
-
6
4
  Rake::TestTask.new(:test) do |test|
7
5
  test.libs << "test"
8
6
  test.verbose = true
@@ -19,3 +17,5 @@ Rake::TestTask.new(:test) do |test|
19
17
 
20
18
  test.test_files = test_files
21
19
  end
20
+
21
+ task :default => %i[test]
@@ -1,91 +1,77 @@
1
- require "forwardable"
2
-
3
- # trailblazer-context
4
1
  require "trailblazer/option"
5
2
  require "trailblazer/context"
6
3
  require "trailblazer/container_chain"
7
4
 
8
5
  require "trailblazer/activity"
9
- require "trailblazer/activity/dsl/magnetic"
10
-
11
-
12
- require "trailblazer/operation/callable"
13
-
14
- require "trailblazer/operation/heritage"
15
- require "trailblazer/operation/public_call" # TODO: Remove in 3.0.
16
- require "trailblazer/operation/class_dependencies"
17
- require "trailblazer/operation/deprecated_macro" # TODO: remove in 2.2.
18
- require "trailblazer/operation/result"
19
- require "trailblazer/operation/railway"
20
-
21
- require "trailblazer/operation/railway/fast_track"
22
- require "trailblazer/operation/railway/normalizer"
23
- require "trailblazer/operation/trace"
6
+ require "trailblazer/activity/dsl/linear"
24
7
 
25
- require "trailblazer/operation/railway/macaroni"
26
8
 
27
9
  module Trailblazer
28
- # The Trailblazer-style operation.
29
- # Note that you don't have to use our "opinionated" version with result object, skills, etc.
30
- class Operation
31
-
32
- module FastTrackActivity
33
- builder_options = {
34
- track_end: Railway::End::Success.new(semantic: :success),
35
- failure_end: Railway::End::Failure.new(semantic: :failure),
36
- pass_fast_end: Railway::End::PassFast.new(semantic: :pass_fast),
37
- fail_fast_end: Railway::End::FailFast.new(semantic: :fail_fast),
38
- }
39
-
40
- extend Activity::FastTrack( pipeline: Railway::Normalizer::Pipeline, builder_options: builder_options )
41
- end
42
-
43
- extend Skill::Accessors # ::[] and ::[]= # TODO: fade out this usage.
44
-
45
- def self.inherited(subclass)
46
- super
47
- subclass.initialize!
48
- heritage.(subclass)
49
- end
50
-
51
- def self.initialize!
52
- @activity = FastTrackActivity.clone
10
+ # DISCUSS: I don't know where else to put this. It's not part of the {Activity} concept
11
+ class Activity
12
+ class Railway
13
+ module End
14
+ # @private
15
+ class Success < Activity::End; end
16
+ class Failure < Activity::End; end
17
+
18
+ class FailFast < Failure; end
19
+ class PassFast < Success; end
20
+ end
53
21
  end
54
22
 
55
-
56
- extend Activity::Interface
57
-
58
- module Process
59
- def to_h
60
- @activity.to_h.merge( activity: @activity )
23
+ module Operation
24
+ def self.OptionsForState()
25
+ {
26
+ end_task: Activity::Railway::End::Success.new(semantic: :success),
27
+ failure_end: Activity::Railway::End::Failure.new(semantic: :failure),
28
+ fail_fast_end: Activity::Railway::End::FailFast.new(semantic: :fail_fast),
29
+ pass_fast_end: Activity::Railway::End::PassFast.new(semantic: :pass_fast),
30
+ }
61
31
  end
62
32
  end
33
+ end
63
34
 
64
- extend Process # make ::call etc. class methods on Operation.
35
+ def self.Operation(options)
36
+ Class.new(Activity::FastTrack( Activity::Operation.OptionsForState.merge(options) )) do
37
+ extend Operation::PublicCall
38
+ end
39
+ end
65
40
 
66
- extend Heritage::Accessor
41
+ # The Trailblazer-style operation.
42
+ # Note that you don't have to use our "opinionated" version with result object, skills, etc.
43
+ class Operation < Activity::FastTrack(Activity::Operation.OptionsForState)
44
+ # extend Skill::Accessors # ::[] and ::[]= # TODO: fade out this usage.
67
45
 
68
46
  class << self
69
- extend Forwardable # TODO: test those helpers
70
- def_delegators :@activity, :Path, :Output, :End, :Track
71
- def_delegators :@activity, :outputs
72
-
73
- def step(task, options={}, &block); add_task!(:step, task, options, &block) end
74
- def pass(task, options={}, &block); add_task!(:pass, task, options, &block) end
75
- def fail(task, options={}, &block); add_task!(:fail, task, options, &block) end
76
-
77
- alias_method :success, :pass
78
- alias_method :failure, :fail
79
-
80
- def add_task!(name, task, options, &block)
81
- heritage.record(name, task, options, &block)
82
- @activity.send(name, task, options, &block)
83
- end
47
+ alias_method :strategy_call, :call
84
48
  end
85
49
 
50
+ require "trailblazer/operation/public_call" # TODO: Remove in 3.0.
86
51
  extend PublicCall # ::call(params, { current_user: .. })
52
+
53
+ require "trailblazer/operation/trace"
87
54
  extend Trace # ::trace
55
+
56
+ module Railway
57
+ def self.fail! ; Activity::Left end
58
+ def self.pass! ; Activity::Right end
59
+ def self.fail_fast!; Activity::FastTrack::FailFast end
60
+ def self.pass_fast!; Activity::FastTrack::PassFast end
61
+ end
88
62
  end
89
63
  end
90
64
 
91
65
  require "trailblazer/operation/inspect"
66
+
67
+ require "trailblazer/operation/class_dependencies"
68
+ require "trailblazer/operation/deprecated_macro" # TODO: remove in 2.2.
69
+
70
+ require "trailblazer/operation/result"
71
+ require "trailblazer/operation/railway"
72
+
73
+ require "trailblazer/operation/trace"
74
+
75
+ require "trailblazer/operation/railway/macaroni"
76
+
77
+ require "trailblazer/operation/container"