trailblazer-operation 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 518732c6417e754d620873510361cd17958defb1
4
- data.tar.gz: a77e4f2314161fb500b15017c79e81e1d53ffb09
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YzgzYjgyM2I1NjUxYjEyOWIzZGViZDE2NjBkYmQyMTNkYjg5ZWIxOQ==
5
+ data.tar.gz: !binary |-
6
+ Y2M1MDU0Mzc4MDg0NGVlOGNlYjBkYWE2MTUyZmQyZGQ4ZGMwMjNkNA==
5
7
  SHA512:
6
- metadata.gz: 0b88e57e5469ab4f41f13954a4c92469f98c661c883c8c1bb1a3f192a32a9f8389e3d941768c867faa9a40d119cf671bca666389a2da704f4957cb7cffcb785d
7
- data.tar.gz: e265e9034e34e802d0364ad3402ab2c5d9f02e1ce5bff8a72a9f78341aa3f1c04abd84625d40cd3abce9d64c54a8455b4a4281809cc2ce5351ac758066c688f1
8
+ metadata.gz: !binary |-
9
+ MWI0ZmZmYjFmNjhlODZhYjQxOTYwNGRjNDRmM2Q1MGIzOGE3NTZmMjJjZWYw
10
+ YTBjZWM3MWNmNjhjN2QzZDY1MjY3Y2QwZGQyM2E0ZmQ5Zjk5ODdjOTc3OWI1
11
+ ODhhNWIwYWIyNzQ1M2Q0MGViNWEyYzc4MDA5MGRkMzNjN2FlZGQ=
12
+ data.tar.gz: !binary |-
13
+ NWQxZWU5YTc0YmY2NzNkNWFmMWFlMDYzYTEwNGM3NjZlZTFkMDU1YmZlZjRm
14
+ MDU3YTYxMThiOTY1ZjVkNTlhN2M3NzBiNGYzNWRmOWI3ZmEyMDdlMDU4NDZh
15
+ M2ZjOTJmMDY2YjllMjMxMzBjMzdjYzI0MTE1ZjQxODkyYTZlOGI=
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.0.6
2
+
3
+ * Improvements with the pipe DSL.
4
+
1
5
  ## 0.0.5
2
6
 
3
7
  * `_insert` provides better API now.
@@ -2,7 +2,6 @@ require "declarative" # FIXME: here?
2
2
  require "trailblazer/operation/skill"
3
3
  require "trailblazer/operation/pipetree"
4
4
  require "trailblazer/operation/generic"
5
- require "trailblazer/operation/macro"
6
5
 
7
6
  module Trailblazer
8
7
  # The Trailblazer-style operation.
@@ -4,7 +4,7 @@ require "trailblazer/operation/result"
4
4
  require "uber/option"
5
5
 
6
6
  class Trailblazer::Operation
7
- New = ->(klass, options) { klass.new(options) } # returns operation instance.
7
+ New = ->(klass, options) { klass.new(options) } # returns operation instance.
8
8
 
9
9
  # Implements the API to populate the operation's pipetree and
10
10
  # `Operation::call` to invoke the latter.
@@ -47,54 +47,100 @@ class Trailblazer::Operation
47
47
  def &(*args); _insert(:&, *args) end
48
48
  def <(*args); _insert(:<, *args) end
49
49
 
50
+ # self.| ->(*) { }, before: "operation.new"
51
+ # self.| :some_method
52
+ def |(cfg, user_options={})
53
+ DSL.import(self, self["pipetree"], cfg, user_options) &&
54
+ heritage.record(:|, cfg, user_options)
55
+ end
56
+
57
+ alias_method :step, :|
58
+ alias_method :consider, :&
59
+ alias_method :failure, :<
60
+ alias_method :success, :>
61
+
50
62
  # :private:
51
- # High-level user step API that allows ->(options) procs.
52
- def _insert(operator, proc, options={})
53
- heritage.record(:_insert, operator, proc, options)
63
+ module Option
64
+ def self.call(proc, &block)
65
+ type = :proc
66
+
67
+ option =
68
+ if proc.is_a? Symbol
69
+ type = :symbol
70
+ ->(input, *_options) { input.send(proc, *_options) }
71
+ elsif proc.is_a? Proc
72
+ # ->(input, options) { proc.(**options) }
73
+ ->(input, *_options) { proc.(*_options) }
74
+ elsif proc.is_a? Uber::Callable
75
+ type = :callable
76
+ ->(input, *_options) { proc.(*_options) }
77
+ end
78
+
79
+ yield type if block_given?
80
+ option
81
+ end
82
+ end
54
83
 
84
+ # :public:
85
+ # Wrap the step into a proc that only passes `options` to the step.
86
+ # This is pure convenience for the developer and will be the default
87
+ # API for steps. ATM, we also automatically generate a step `:name`.
88
+ def self.insert(pipe, operator, proc, options={}, kws={}) # TODO: definer_name is a hack for debugging, only.
55
89
  # proc = Uber::Option[proc]
56
90
  _proc =
57
91
  if options[:wrap] == false
58
92
  proc
59
- elsif proc.is_a? Symbol
60
- options[:name] ||= proc
61
- ->(input, _options) { input.send(proc, _options) }
62
- elsif proc.is_a? Proc
63
- options[:name] ||= "#{self.name}:#{proc.source_location.last}" if proc.is_a? Proc
64
- # ->(input, options) { proc.(**options) }
65
- ->(input, _options) { proc.(_options) }
66
- elsif proc.is_a? Uber::Callable
67
- options[:name] ||= proc.class
68
- ->(input, _options) { proc.(_options) }
93
+ else
94
+ Option.(proc) do |type|
95
+ options[:name] ||= proc if type == :symbol
96
+ options[:name] ||= "#{kws[:definer_name]}:#{proc.source_location.last}" if proc.is_a? Proc if type == :proc
97
+ options[:name] ||= proc.class if type == :callable
98
+ end
69
99
  end
70
100
 
71
- self["pipetree"].send(operator, _proc, options) # ex: pipetree.> Validate, after: Model::Build
101
+ pipe.send(operator, _proc, options) # ex: pipetree.> Validate, after: Model::Build
72
102
  end
73
103
 
74
- def ~(cfg)
75
- heritage.record(:~, cfg)
104
+ def self.import(operation, pipe, cfg, user_options={})
105
+ if cfg.is_a?(Array) # e.g. from Contract::Validate
106
+ mod, args, block = cfg
76
107
 
77
- self.|(cfg, inheriting: true) # FIXME: not sure if this is the final API.
78
- end
108
+ import = Import.new(pipe, user_options) # API object.
109
+
110
+ return mod.import!(operation, import, *args, &block)
111
+ end
79
112
 
80
- def |(cfg, user_options={}) # sorry for the magic here, but still playing with the DSL.
81
- if cfg.is_a?(Macro) # e.g. Contract::Validate
82
- import = Import.new(self, user_options)
113
+ insert(pipe, :>, cfg, user_options, {}) # DOEES NOOOT calls heritage.record
114
+ end
83
115
 
84
- return cfg.import!(self, import) &&
85
- heritage.record(:|, cfg, user_options)
116
+ Macros = Module.new
117
+ def self.macro!(name, constant)
118
+ Macros.send :define_method, name do |*args, &block|
119
+ [constant, args, block]
86
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)
87
127
 
88
- self.> cfg, user_options # calls heritage.record
128
+ DSL.insert(self["pipetree"], operator, proc, options, definer_name: self.name)
129
+ end
130
+
131
+ def ~(cfg)
132
+ heritage.record(:~, cfg)
133
+
134
+ self.|(cfg, inheriting: true) # FIXME: not sure if this is the final API.
89
135
  end
90
136
 
91
137
  # Try to abstract as much as possible from the imported module. This is for
92
138
  # forward-compatibility.
93
139
  # Note that Import#call will push the step directly on the pipetree which gives it the
94
140
  # low-level (input, options) interface.
95
- Import = Struct.new(:operation, :user_options) do
141
+ Import = Struct.new(:pipetree, :user_options) do
96
142
  def call(operator, step, options)
97
- operation["pipetree"].send operator, step, options.merge(user_options)
143
+ pipetree.send operator, step, options.merge(user_options)
98
144
  end
99
145
 
100
146
  def inheriting?
@@ -103,4 +149,6 @@ class Trailblazer::Operation
103
149
  end
104
150
  end
105
151
  end
152
+
153
+ extend Pipetree::DSL::Macros
106
154
  end
@@ -1,5 +1,5 @@
1
1
  module Trailblazer
2
2
  class Operation
3
- VERSION = "0.0.5"
3
+ VERSION = "0.0.6"
4
4
  end
5
5
  end
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../../
3
3
  specs:
4
- trailblazer-operation (0.0.3)
4
+ trailblazer-operation (0.0.6)
5
5
  declarative
6
6
  pipetree (>= 0.0.4, < 0.1.0)
7
7
  uber (>= 0.1.0, < 0.2.0)
@@ -2,8 +2,6 @@ require "test_helper"
2
2
 
3
3
  class PipetreeTest < Minitest::Spec
4
4
  module Validate
5
- extend Trailblazer::Operation::Macro
6
-
7
5
  def self.import!(operation, pipe)
8
6
  pipe.(:>, ->{ snippet }, name: "validate", before: "operation.new")
9
7
  end
@@ -13,21 +11,21 @@ class PipetreeTest < Minitest::Spec
13
11
  # ::|
14
12
  # without options
15
13
  class Create < Trailblazer::Operation
16
- self.| Validate[]
14
+ self.| [Validate]
17
15
  end
18
16
 
19
17
  it { Create["pipetree"].inspect.must_equal %{[>validate,>>operation.new]} }
20
18
 
21
19
  # without any options or []
22
- class New < Trailblazer::Operation
23
- self.| Validate
24
- end
20
+ # class New < Trailblazer::Operation
21
+ # self.| Validate
22
+ # end
25
23
 
26
- it { New["pipetree"].inspect.must_equal %{[>validate,>>operation.new]} }
24
+ # it { New["pipetree"].inspect.must_equal %{[>validate,>>operation.new]} }
27
25
 
28
26
  # with options
29
27
  class Update < Trailblazer::Operation
30
- self.| Validate, after: "operation.new"
28
+ self.| [Validate], after: "operation.new"
31
29
  end
32
30
 
33
31
  it { Update["pipetree"].inspect.must_equal %{[>>operation.new,>validate]} }
@@ -68,7 +66,7 @@ class PipetreeTest < Minitest::Spec
68
66
  end
69
67
 
70
68
  it { Right.( id: 1 ).slice(">", "method_name!", "callable").must_equal [1, 1, 1] }
71
- it { Right["pipetree"].inspect.must_equal %{[>>operation.new,>PipetreeTest::Right:58,>method_name!,>PipetreeTest::Right::MyCallable]} }
69
+ it { Right["pipetree"].inspect.must_equal %{[>>operation.new,>PipetreeTest::Right:56,>method_name!,>PipetreeTest::Right::MyCallable]} }
72
70
 
73
71
  #---
74
72
  # inheritance
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.5
4
+ version: 0.0.6
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-11-30 00:00:00.000000000 Z
11
+ date: 2016-12-07 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
53
  version: 0.0.4
54
- - - "<"
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
63
  version: 0.0.4
64
- - - "<"
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,15 +113,14 @@ 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
121
121
  - Rakefile
122
122
  - lib/trailblazer/operation.rb
123
123
  - lib/trailblazer/operation/generic.rb
124
- - lib/trailblazer/operation/macro.rb
125
124
  - lib/trailblazer/operation/pipetree.rb
126
125
  - lib/trailblazer/operation/result.rb
127
126
  - lib/trailblazer/operation/skill.rb
@@ -151,17 +150,17 @@ require_paths:
151
150
  - lib
152
151
  required_ruby_version: !ruby/object:Gem::Requirement
153
152
  requirements:
154
- - - ">="
153
+ - - ! '>='
155
154
  - !ruby/object:Gem::Version
156
155
  version: 1.9.3
157
156
  required_rubygems_version: !ruby/object:Gem::Requirement
158
157
  requirements:
159
- - - ">="
158
+ - - ! '>='
160
159
  - !ruby/object:Gem::Version
161
160
  version: '0'
162
161
  requirements: []
163
162
  rubyforge_project:
164
- rubygems_version: 2.6.3
163
+ rubygems_version: 2.4.8
165
164
  signing_key:
166
165
  specification_version: 4
167
166
  summary: Trailblazer's operation object with dependency management and pipetree flow.
@@ -1,17 +0,0 @@
1
- class Trailblazer::Operation
2
- module Macro
3
- Configuration = Struct.new(:mod, :args, :block) do
4
- include Macro # mark it, so that ::| thinks this is a step module.
5
-
6
- def import!(operation, import)
7
- mod.import!(operation, import, *args)
8
- end
9
- end
10
-
11
- def [](*args, &block)
12
- # When called like Builder["builder.crud"], create a proxy
13
- # object and Pipeline::| calls #import! on it.
14
- Configuration.new(self, args, block)
15
- end
16
- end
17
- end