trailblazer-operation 0.0.6 → 0.0.7

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,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- YzgzYjgyM2I1NjUxYjEyOWIzZGViZDE2NjBkYmQyMTNkYjg5ZWIxOQ==
5
- data.tar.gz: !binary |-
6
- Y2M1MDU0Mzc4MDg0NGVlOGNlYjBkYWE2MTUyZmQyZGQ4ZGMwMjNkNA==
2
+ SHA1:
3
+ metadata.gz: c0ec02e51e1d32a39bfcb2ae86381ada7fa9659a
4
+ data.tar.gz: eaa3b0ae603fa52a37e3f9cd9624a6522cd0d64d
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- MWI0ZmZmYjFmNjhlODZhYjQxOTYwNGRjNDRmM2Q1MGIzOGE3NTZmMjJjZWYw
10
- YTBjZWM3MWNmNjhjN2QzZDY1MjY3Y2QwZGQyM2E0ZmQ5Zjk5ODdjOTc3OWI1
11
- ODhhNWIwYWIyNzQ1M2Q0MGViNWEyYzc4MDA5MGRkMzNjN2FlZGQ=
12
- data.tar.gz: !binary |-
13
- NWQxZWU5YTc0YmY2NzNkNWFmMWFlMDYzYTEwNGM3NjZlZTFkMDU1YmZlZjRm
14
- MDU3YTYxMThiOTY1ZjVkNTlhN2M3NzBiNGYzNWRmOWI3ZmEyMDdlMDU4NDZh
15
- M2ZjOTJmMDY2YjllMjMxMzBjMzdjYzI0MTE1ZjQxODkyYTZlOGI=
6
+ metadata.gz: 7d6bfe1597f701fdbf17a581fe4edd2f52d304d46d0ac53d9d90544e9aa1fc30a522281fc02b4d67cf9ad0f278d89b3994336c58e6377ac306d0727fcbe51736
7
+ data.tar.gz: 4f21e43d502bc7abefa28b1f05261f34d90e2b4f32d72d1d63b5167a84e41637f4965d4fef7320344fc6f461844e9e73dd3db9ecebb57226b6cc2adeb1bee851
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.0.7
2
+
3
+ * Simplify inheritance by basically removing it.
4
+
1
5
  ## 0.0.6
2
6
 
3
7
  * Improvements with the pipe DSL.
data/Gemfile CHANGED
@@ -6,7 +6,6 @@ gemspec
6
6
  gem "multi_json"
7
7
 
8
8
  gem "dry-auto_inject"
9
- gem "dry-matcher"
10
9
 
11
10
  gem "minitest-line"
12
11
  gem "benchmark-ips"
data/Rakefile CHANGED
@@ -11,9 +11,7 @@ Rake::TestTask.new(:test) do |test|
11
11
 
12
12
  if RUBY_VERSION == "1.9.3"
13
13
  test_files = test_files - %w{test/dry_container_test.rb}
14
-
15
14
  end
16
15
 
17
- puts test_files.inspect
18
16
  test.test_files = test_files
19
17
  end
@@ -15,7 +15,7 @@ class Trailblazer::Operation
15
15
  includer.extend DSL # ::|, ::> and friends.
16
16
 
17
17
  includer.initialize_pipetree!
18
- includer.>> New, name: "operation.new", wrap: false
18
+ includer._insert(:>>, New, name: "operation.new", wrap: false)
19
19
  end
20
20
 
21
21
  module ClassMethods
@@ -36,28 +36,35 @@ class Trailblazer::Operation
36
36
  # Dry.RB provides it. It has to be executed with every subclassing.
37
37
  def initialize_pipetree!
38
38
  heritage.record :initialize_pipetree!
39
- self["pipetree"] = ::Pipetree::Flow[]
39
+ self["pipetree"] = ::Pipetree::Flow.new
40
40
  end
41
41
  end
42
42
 
43
43
  module DSL
44
44
  # They all inherit.
45
- def >>(*args); _insert(:>>, *args) end
46
45
  def >(*args); _insert(:>, *args) end
47
46
  def &(*args); _insert(:&, *args) end
48
47
  def <(*args); _insert(:<, *args) end
49
48
 
50
- # self.| ->(*) { }, before: "operation.new"
51
- # self.| :some_method
52
49
  def |(cfg, user_options={})
53
50
  DSL.import(self, self["pipetree"], cfg, user_options) &&
54
51
  heritage.record(:|, cfg, user_options)
55
52
  end
56
53
 
57
- alias_method :step, :|
54
+ alias_method :step, :|
58
55
  alias_method :consider, :&
59
- alias_method :failure, :<
60
- alias_method :success, :>
56
+ alias_method :failure, :<
57
+ alias_method :success, :>
58
+ alias_method :override, :|
59
+ alias_method :~, :override
60
+
61
+ # :private:
62
+ # High-level user step API that allows ->(options) procs.
63
+ def _insert(operator, proc, options={})
64
+ heritage.record(:_insert, operator, proc, options)
65
+
66
+ DSL.insert(self["pipetree"], operator, proc, options, definer_name: self.name)
67
+ end
61
68
 
62
69
  # :private:
63
70
  module Option
@@ -101,37 +108,16 @@ class Trailblazer::Operation
101
108
  pipe.send(operator, _proc, options) # ex: pipetree.> Validate, after: Model::Build
102
109
  end
103
110
 
111
+ # note: does not calls heritage.record
104
112
  def self.import(operation, pipe, cfg, user_options={})
105
- if cfg.is_a?(Array) # e.g. from Contract::Validate
106
- mod, args, block = cfg
107
-
108
- import = Import.new(pipe, user_options) # API object.
109
-
110
- return mod.import!(operation, import, *args, &block)
111
- end
112
-
113
- insert(pipe, :>, cfg, user_options, {}) # DOEES NOOOT calls heritage.record
114
- end
115
-
116
- Macros = Module.new
117
- def self.macro!(name, constant)
118
- Macros.send :define_method, name do |*args, &block|
119
- [constant, args, block]
120
- end
121
- end
122
-
123
- # :private:
124
- # High-level user step API that allows ->(options) procs.
125
- def _insert(operator, proc, options={})
126
- heritage.record(:_insert, operator, proc, options)
113
+ return insert(pipe, :>, cfg, user_options, {}) unless cfg.is_a?(Array)
127
114
 
128
- DSL.insert(self["pipetree"], operator, proc, options, definer_name: self.name)
129
- end
115
+ # e.g. from Contract::Validate
116
+ mod, args, block = cfg
130
117
 
131
- def ~(cfg)
132
- heritage.record(:~, cfg)
118
+ import = Import.new(pipe, user_options) # API object.
133
119
 
134
- self.|(cfg, inheriting: true) # FIXME: not sure if this is the final API.
120
+ mod.import!(operation, import, *args, &block)
135
121
  end
136
122
 
137
123
  # Try to abstract as much as possible from the imported module. This is for
@@ -140,14 +126,26 @@ class Trailblazer::Operation
140
126
  # low-level (input, options) interface.
141
127
  Import = Struct.new(:pipetree, :user_options) do
142
128
  def call(operator, step, options)
143
- pipetree.send operator, step, options.merge(user_options)
129
+ insert_options = options.merge(user_options)
130
+
131
+ # Inheritance: when the step is already defined in the pipe,
132
+ # simply replace it with the new.
133
+ if name = insert_options[:name]
134
+ insert_options[:replace] = name if pipetree.index(name)
135
+ end
136
+
137
+ pipetree.send operator, step, insert_options
144
138
  end
139
+ end
145
140
 
146
- def inheriting?
147
- user_options[:inheriting]
141
+ Macros = Module.new
142
+ # create a class method on `target`, e.g. Contract::Validate() for step macros.
143
+ def self.macro!(name, constant, target=Macros)
144
+ target.send :define_method, name do |*args, &block|
145
+ [constant, args, block]
148
146
  end
149
147
  end
150
- end
148
+ end # DSL
151
149
  end
152
150
 
153
151
  extend Pipetree::DSL::Macros
@@ -1,5 +1,5 @@
1
1
  module Trailblazer
2
2
  class Operation
3
- VERSION = "0.0.6"
3
+ VERSION = "0.0.7"
4
4
  end
5
5
  end
@@ -2,4 +2,3 @@ source 'https://rubygems.org'
2
2
  gemspec path: "../../"
3
3
 
4
4
  gem "dry-auto_inject"
5
- gem "dry-matcher"
@@ -11,28 +11,32 @@ class PipetreeTest < Minitest::Spec
11
11
  # ::|
12
12
  # without options
13
13
  class Create < Trailblazer::Operation
14
- self.| [Validate]
14
+ step [Validate]
15
15
  end
16
16
 
17
17
  it { Create["pipetree"].inspect.must_equal %{[>validate,>>operation.new]} }
18
18
 
19
19
  # without any options or []
20
20
  # class New < Trailblazer::Operation
21
- # self.| Validate
21
+ # step Validate
22
22
  # end
23
23
 
24
24
  # it { New["pipetree"].inspect.must_equal %{[>validate,>>operation.new]} }
25
25
 
26
26
  # with options
27
27
  class Update < Trailblazer::Operation
28
- self.| [Validate], after: "operation.new"
28
+ step [Validate], after: "operation.new"
29
29
  end
30
30
 
31
31
  it { Update["pipetree"].inspect.must_equal %{[>>operation.new,>validate]} }
32
32
 
33
- # with :symbol
33
+ #---
34
+ # ::step
35
+
36
+ #-
37
+ #- with :symbol
34
38
  class Delete < Trailblazer::Operation
35
- self.| :call!
39
+ step :call!
36
40
 
37
41
  def call!(options)
38
42
  self["x"] = options["params"]
@@ -41,9 +45,15 @@ class PipetreeTest < Minitest::Spec
41
45
 
42
46
  it { Delete.("yo")["x"].must_equal "yo" }
43
47
 
48
+ #- inheritance
49
+ class Remove < Delete
50
+ end
51
+
52
+ it { Remove.("yo")["x"].must_equal "yo" }
53
+
44
54
  # proc arguments
45
55
  class Forward < Trailblazer::Operation
46
- self.| ->(input, options) { puts "@@@@@ #{input.inspect}"; puts "@@@@@ #{options.inspect}" }
56
+ step ->(input, options) { puts "@@@@@ #{input.inspect}"; puts "@@@@@ #{options.inspect}" }
47
57
  end
48
58
 
49
59
  it { skip; Forward.({ id: 1 }) }
@@ -66,7 +76,7 @@ class PipetreeTest < Minitest::Spec
66
76
  end
67
77
 
68
78
  it { Right.( id: 1 ).slice(">", "method_name!", "callable").must_equal [1, 1, 1] }
69
- it { Right["pipetree"].inspect.must_equal %{[>>operation.new,>PipetreeTest::Right:56,>method_name!,>PipetreeTest::Right::MyCallable]} }
79
+ it { Right["pipetree"].inspect.must_equal %{[>>operation.new,>PipetreeTest::Right:66,>method_name!,>PipetreeTest::Right::MyCallable]} }
70
80
 
71
81
  #---
72
82
  # inheritance
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_dependency "uber", ">= 0.1.0", "< 0.2.0"
22
22
  spec.add_dependency "declarative"
23
- spec.add_dependency "pipetree", ">= 0.0.4", "< 0.1.0"
23
+ spec.add_dependency "pipetree", ">= 0.0.5", "< 0.1.0"
24
24
 
25
25
  spec.add_development_dependency "bundler"
26
26
  spec.add_development_dependency "rake"
metadata CHANGED
@@ -1,109 +1,109 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trailblazer-operation
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
  - Nick Sutterer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-07 00:00:00.000000000 Z
11
+ date: 2016-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: uber
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 0.1.0
20
- - - <
20
+ - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: 0.2.0
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - ! '>='
27
+ - - ">="
28
28
  - !ruby/object:Gem::Version
29
29
  version: 0.1.0
30
- - - <
30
+ - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: 0.2.0
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: declarative
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - ! '>='
37
+ - - ">="
38
38
  - !ruby/object:Gem::Version
39
39
  version: '0'
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
- - - ! '>='
44
+ - - ">="
45
45
  - !ruby/object:Gem::Version
46
46
  version: '0'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: pipetree
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - ! '>='
51
+ - - ">="
52
52
  - !ruby/object:Gem::Version
53
- version: 0.0.4
54
- - - <
53
+ version: 0.0.5
54
+ - - "<"
55
55
  - !ruby/object:Gem::Version
56
56
  version: 0.1.0
57
57
  type: :runtime
58
58
  prerelease: false
59
59
  version_requirements: !ruby/object:Gem::Requirement
60
60
  requirements:
61
- - - ! '>='
61
+ - - ">="
62
62
  - !ruby/object:Gem::Version
63
- version: 0.0.4
64
- - - <
63
+ version: 0.0.5
64
+ - - "<"
65
65
  - !ruby/object:Gem::Version
66
66
  version: 0.1.0
67
67
  - !ruby/object:Gem::Dependency
68
68
  name: bundler
69
69
  requirement: !ruby/object:Gem::Requirement
70
70
  requirements:
71
- - - ! '>='
71
+ - - ">="
72
72
  - !ruby/object:Gem::Version
73
73
  version: '0'
74
74
  type: :development
75
75
  prerelease: false
76
76
  version_requirements: !ruby/object:Gem::Requirement
77
77
  requirements:
78
- - - ! '>='
78
+ - - ">="
79
79
  - !ruby/object:Gem::Version
80
80
  version: '0'
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: rake
83
83
  requirement: !ruby/object:Gem::Requirement
84
84
  requirements:
85
- - - ! '>='
85
+ - - ">="
86
86
  - !ruby/object:Gem::Version
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
90
  version_requirements: !ruby/object:Gem::Requirement
91
91
  requirements:
92
- - - ! '>='
92
+ - - ">="
93
93
  - !ruby/object:Gem::Version
94
94
  version: '0'
95
95
  - !ruby/object:Gem::Dependency
96
96
  name: minitest
97
97
  requirement: !ruby/object:Gem::Requirement
98
98
  requirements:
99
- - - ! '>='
99
+ - - ">="
100
100
  - !ruby/object:Gem::Version
101
101
  version: '0'
102
102
  type: :development
103
103
  prerelease: false
104
104
  version_requirements: !ruby/object:Gem::Requirement
105
105
  requirements:
106
- - - ! '>='
106
+ - - ">="
107
107
  - !ruby/object:Gem::Version
108
108
  version: '0'
109
109
  description: Trailblazer's operation object.
@@ -113,8 +113,8 @@ executables: []
113
113
  extensions: []
114
114
  extra_rdoc_files: []
115
115
  files:
116
- - .gitignore
117
- - .travis.yml
116
+ - ".gitignore"
117
+ - ".travis.yml"
118
118
  - CHANGES.md
119
119
  - Gemfile
120
120
  - README.md
@@ -150,17 +150,17 @@ require_paths:
150
150
  - lib
151
151
  required_ruby_version: !ruby/object:Gem::Requirement
152
152
  requirements:
153
- - - ! '>='
153
+ - - ">="
154
154
  - !ruby/object:Gem::Version
155
155
  version: 1.9.3
156
156
  required_rubygems_version: !ruby/object:Gem::Requirement
157
157
  requirements:
158
- - - ! '>='
158
+ - - ">="
159
159
  - !ruby/object:Gem::Version
160
160
  version: '0'
161
161
  requirements: []
162
162
  rubyforge_project:
163
- rubygems_version: 2.4.8
163
+ rubygems_version: 2.6.3
164
164
  signing_key:
165
165
  specification_version: 4
166
166
  summary: Trailblazer's operation object with dependency management and pipetree flow.