trailblazer-macro 2.1.0.rc12 → 2.1.0.rc13

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,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f5ce55419b3272e247bb23453c3eda1543ad0de9b7308e173fc7532ed0b3c837
4
- data.tar.gz: da8e59a55b392c9220ba8038ce809d52136ee712a4f31489172176a01ef117a5
3
+ metadata.gz: f650f559c9413f94e4ab3b847052cb86f8893f8e76621ca4f871378ba5459fcc
4
+ data.tar.gz: 81cd6d65a460a7e5117591a7512490d031fff59fe3599830013fe846dc56104a
5
5
  SHA512:
6
- metadata.gz: e871c4cf8f7e11af5339a40493b7175919b3c965bc1fbeefa925f41f17d8a89e936fdc39e688725f30115370539c8fcc5cee9f5a3c69f4e411b9a1002ea63a87
7
- data.tar.gz: cd97aa45a6d27af7f4f60e4ab34f80a235a73338188d7e27a48e2a12bcbc693ea1534f4075f95ceaef7918b9f5cebc0e87320bd3f69dd130b5bad814bef080e1
6
+ metadata.gz: '02853f1b5e504e22ab3ff29506b93b9e02db9834894b8ff6c80dcf35467e5ff6e2f549dc604ba1f18e52a549dd4e7d22d4e229fc09b52f2187bd4859b303257d'
7
+ data.tar.gz: b3458af49de52c383ad41108989109174d15dbccdea39d4f6a59fde42eb01b29003883022f6e2785fd0d606be1ef90f32780e77498ddd03aa66fc929bbb3574e
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 2.1.0.rc13
2
+
3
+ * Use symbol keys on `ctx`, only.
4
+
1
5
  # 2.1.0.rc12
2
6
 
3
7
  * Dependency bumps.
@@ -3,9 +3,9 @@ module Trailblazer::Macro
3
3
  task = Trailblazer::Activity::TaskBuilder::Binary(Model.new)
4
4
 
5
5
  injection = Trailblazer::Activity::TaskWrap::Inject::Defaults::Extension(
6
- "model.class" => model_class,
7
- "model.action" => action,
8
- "model.find_by_key" => find_by_key
6
+ :"model.class" => model_class,
7
+ :"model.action" => action,
8
+ :"model.find_by_key" => find_by_key
9
9
  )
10
10
 
11
11
  {task: task, id: "model.build", extensions: [injection]}
@@ -15,19 +15,19 @@ module Trailblazer::Macro
15
15
  def call(options, params:, **)
16
16
  builder = Model::Builder.new
17
17
  options[:model] = model = builder.call(options, params)
18
- options["result.model"] = result = Trailblazer::Operation::Result.new(!model.nil?, {})
18
+ options[:"result.model"] = result = Trailblazer::Operation::Result.new(!model.nil?, {})
19
19
 
20
20
  result.success?
21
21
  end
22
22
 
23
23
  class Builder
24
24
  def call(options, params)
25
- action = options["model.action"] || :new
26
- model_class = options["model.class"]
27
- find_by_key = options["model.find_by_key"] || :id
25
+ action = options[:"model.action"] || :new
26
+ model_class = options[:"model.class"]
27
+ find_by_key = options[:"model.find_by_key"] || :id
28
28
  action = :pass_through unless %i[new find_by].include?(action)
29
29
 
30
- send("#{action}!", model_class, params, options["model.action"], find_by_key)
30
+ send("#{action}!", model_class, params, options[:"model.action"], find_by_key)
31
31
  end
32
32
 
33
33
  def new!(model_class, params, *)
@@ -14,8 +14,8 @@ module Trailblazer::Macro
14
14
  condition = options[@path] # this allows dependency injection.
15
15
  result = condition.([options, flow_options], **circuit_options)
16
16
 
17
- options["policy.#{@name}"] = result["policy"] # assign the policy as a skill.
18
- options["result.policy.#{@name}"] = result
17
+ options[:"policy.#{@name}"] = result[:policy] # assign the policy as a skill.
18
+ options[:"result.policy.#{@name}"] = result
19
19
 
20
20
  # flow control
21
21
  signal = result.success? ? Trailblazer::Activity::Right : Trailblazer::Activity::Left # since we & this, it's only executed OnRight and the return boolean decides the direction, input is passed straight through.
@@ -28,7 +28,7 @@ module Trailblazer::Macro
28
28
  # policy-compatible object at runtime.
29
29
  def self.step(condition, options, &block)
30
30
  name = options[:name]
31
- path = "policy.#{name}.eval"
31
+ path = :"policy.#{name}.eval"
32
32
 
33
33
  task = Eval.new(name: name, path: path)
34
34
 
@@ -27,8 +27,8 @@ module Trailblazer::Macro
27
27
  end
28
28
 
29
29
  def result!(success, policy)
30
- data = {"policy" => policy}
31
- data["message"] = "Breach" if !success # TODO: how to allow messages here?
30
+ data = { policy: policy }
31
+ data[:message] = "Breach" if !success # TODO: how to allow messages here?
32
32
 
33
33
  Trailblazer::Operation::Result.new(success, data)
34
34
  end
@@ -1,7 +1,7 @@
1
1
  module Trailblazer
2
2
  module Version
3
3
  module Macro
4
- VERSION = "2.1.0.rc12".freeze
4
+ VERSION = "2.1.0.rc13".freeze
5
5
  end
6
6
  end
7
7
  end
@@ -10,18 +10,18 @@ class DocsGuardProcTest < Minitest::Spec
10
10
  step :process
11
11
 
12
12
  def process(options, **)
13
- options["x"] = true
13
+ options[:x] = true
14
14
  end
15
15
  #~pipeonly end
16
16
  end
17
17
  #:proc end
18
18
 
19
- it { Create.(pass: false)["x"].must_be_nil }
20
- it { Create.(pass: true)["x"].must_equal true }
19
+ it { Create.(pass: false)[:x].must_be_nil }
20
+ it { Create.(pass: true)[:x].must_equal true }
21
21
 
22
22
  #- result object, guard
23
- it { Create.(pass: true)["result.policy.default"].success?.must_equal true }
24
- it { Create.(pass: false)["result.policy.default"].success?.must_equal false }
23
+ it { Create.(pass: true)[:"result.policy.default"].success?.must_equal true }
24
+ it { Create.(pass: false)[:"result.policy.default"].success?.must_equal false }
25
25
 
26
26
  #---
27
27
  #- Guard inheritance
@@ -74,14 +74,14 @@ class DocsGuardMethodTest < Minitest::Spec
74
74
  step :process
75
75
 
76
76
  def process(options, **)
77
- options["x"] = true
77
+ options[:x] = true
78
78
  end
79
79
  #~pipe-onlyy end
80
80
  end
81
81
  #:method end
82
82
 
83
- it { Create.(pass: false).inspect("x").must_equal %{<Result:false [nil] >} }
84
- it { Create.(pass: true).inspect("x").must_equal %{<Result:true [true] >} }
83
+ it { Create.(pass: false).inspect(:x).must_equal %{<Result:false [nil] >} }
84
+ it { Create.(pass: true).inspect(:x).must_equal %{<Result:true [true] >} }
85
85
  end
86
86
 
87
87
  #---
@@ -94,13 +94,13 @@ class DocsGuardNamedTest < Minitest::Spec
94
94
  end
95
95
  #:name end
96
96
 
97
- it { Create.(:current_user => nil )["result.policy.user"].success?.must_equal false }
98
- it { Create.(:current_user => Module)["result.policy.user"].success?.must_equal true }
97
+ it { Create.(:current_user => nil )[:"result.policy.user"].success?.must_equal false }
98
+ it { Create.(:current_user => Module)[:"result.policy.user"].success?.must_equal true }
99
99
 
100
100
  it {
101
101
  #:name-result
102
102
  result = Create.(:current_user => true)
103
- result["result.policy.user"].success? #=> true
103
+ result[:"result.policy.user"].success? #=> true
104
104
  #:name-result end
105
105
  }
106
106
  end
@@ -123,7 +123,7 @@ class DocsGuardInjectionTest < Minitest::Spec
123
123
  Create.(
124
124
  {},
125
125
  :current_user => Module,
126
- "policy.default.eval" => Trailblazer::Operation::Policy::Guard.build(->(options, **) { false })
126
+ :"policy.default.eval" => Trailblazer::Operation::Policy::Guard.build(->(options, **) { false })
127
127
  )
128
128
  #:di-call end
129
129
  result.inspect("").must_equal %{<Result:false [nil] >} }
@@ -36,11 +36,11 @@ class DocsPunditProcTest < Minitest::Spec
36
36
  it do
37
37
  #:pundit-result
38
38
  result = Create.(params: {}, current_user: Module)
39
- result["result.policy.default"].success? #=> true
40
- result["result.policy.default"]["policy"] #=> #<MyPolicy ...>
39
+ result[:"result.policy.default"].success? #=> true
40
+ result[:"result.policy.default"][:policy] #=> #<MyPolicy ...>
41
41
  #:pundit-result end
42
- result["result.policy.default"].success?.must_equal true
43
- result["result.policy.default"]["policy"].is_a?(MyPolicy).must_equal true
42
+ result[:"result.policy.default"].success?.must_equal true
43
+ result[:"result.policy.default"][:policy].is_a?(MyPolicy).must_equal true
44
44
  end
45
45
 
46
46
  #---
@@ -82,7 +82,7 @@ class DocsPunditProcTest < Minitest::Spec
82
82
  #:di-call
83
83
  Create.(params: {},
84
84
  current_user: Module,
85
- "policy.default.eval" => Trailblazer::Operation::Policy::Pundit.build(AnotherPolicy, :create?)
85
+ :"policy.default.eval" => Trailblazer::Operation::Policy::Pundit.build(AnotherPolicy, :create?)
86
86
  )
87
87
  #:di-call end
88
88
  result.inspect("").must_equal %{<Result:true [nil] >} }
@@ -104,9 +104,9 @@ class PunditWithNameTest < Minitest::Spec
104
104
  it {
105
105
  #:name-call
106
106
  result = Create.(params: {}, current_user: Module)
107
- result["result.policy.after_model"].success? #=> true
107
+ result[:"result.policy.after_model"].success? #=> true
108
108
  #:name-call end
109
- result["result.policy.after_model"].success?.must_equal true }
109
+ result[:"result.policy.after_model"].success?.must_equal true }
110
110
  end
111
111
 
112
112
  #---
@@ -48,7 +48,7 @@ class ModelTest < Minitest::Spec
48
48
  step Trailblazer::Operation::Model Song, :find_by
49
49
  step :process
50
50
 
51
- def process(options, **); options["x"] = true end
51
+ def process(options, **); options[:x] = true end
52
52
  end
53
53
 
54
54
  # :find_by, exceptionless.
@@ -57,36 +57,36 @@ class ModelTest < Minitest::Spec
57
57
  step Trailblazer::Operation::Model( Song, :find_by, :title )
58
58
  step :process
59
59
 
60
- def process(options, **); options["x"] = true end
60
+ def process(options, **); options[:x] = true end
61
61
  end
62
62
 
63
63
  # can't find model.
64
64
  #- result object, model
65
65
  it do
66
- Find.(params: {id: nil})["result.model"].failure?.must_equal true
67
- Find.(params: {id: nil})["x"].must_be_nil
66
+ Find.(params: {id: nil})[:"result.model"].failure?.must_equal true
67
+ Find.(params: {id: nil})[:"x"].must_be_nil
68
68
  Find.(params: {id: nil}).failure?.must_equal true
69
69
  end
70
70
 
71
71
  #- result object, model
72
72
  it do
73
- Find.(params: {id: 9})["result.model"].success?.must_equal true
74
- Find.(params: {id: 9})["x"].must_equal true
73
+ Find.(params: {id: 9})[:"result.model"].success?.must_equal true
74
+ Find.(params: {id: 9})[:"x"].must_equal true
75
75
  Find.(params: {id: 9})[:model].inspect.must_equal %{#<struct ModelTest::Song id=9, title=nil>}
76
76
  end
77
77
 
78
78
  # can't find model by title.
79
79
  #- result object, model
80
80
  it do
81
- FindByKey.(params: {title: nil})["result.model"].failure?.must_equal true
82
- FindByKey.(params: {title: nil})["x"].must_be_nil
81
+ FindByKey.(params: {title: nil})[:"result.model"].failure?.must_equal true
82
+ FindByKey.(params: {title: nil})[:"x"].must_be_nil
83
83
  FindByKey.(params: {title: nil}).failure?.must_equal true
84
84
  end
85
85
 
86
86
  #- result object, model by title
87
87
  it do
88
- FindByKey.(params: {title: "Test"})["result.model"].success?.must_equal true
89
- FindByKey.(params: {title: "Test"})["x"].must_equal true
88
+ FindByKey.(params: {title: "Test"})[:"result.model"].success?.must_equal true
89
+ FindByKey.(params: {title: "Test"})[:"x"].must_equal true
90
90
  FindByKey.(params: {title: "Test"})[:model].inspect.must_equal %{#<struct ModelTest::Song id=2, title="Test">}
91
91
  end
92
92
  end
@@ -20,36 +20,36 @@ class PolicyTest < Minitest::Spec
20
20
  step :process
21
21
 
22
22
  def process(options, **)
23
- options["process"] = true
23
+ options[:process] = true
24
24
  end
25
25
  end
26
26
 
27
27
  # successful.
28
28
  it do
29
29
  result = Create.(params: {}, current_user: Module)
30
- result["process"].must_equal true
30
+ result[:process].must_equal true
31
31
  #- result object, policy
32
- result["result.policy.default"].success?.must_equal true
33
- result["result.policy.default"]["message"].must_be_nil
32
+ result[:"result.policy.default"].success?.must_equal true
33
+ result[:"result.policy.default"][:message].must_be_nil
34
34
  # result[:valid].must_be_nil
35
- result["policy.default"].inspect.must_equal %{<Auth: user:Module, model:nil>}
35
+ result[:"policy.default"].inspect.must_equal %{<Auth: user:Module, model:nil>}
36
36
  end
37
37
  # breach.
38
38
  it do
39
39
  result = Create.(params: {}, current_user: nil)
40
- result["process"].must_be_nil
40
+ result[:process].must_be_nil
41
41
  #- result object, policy
42
- result["result.policy.default"].success?.must_equal false
43
- result["result.policy.default"]["message"].must_equal "Breach"
42
+ result[:"result.policy.default"].success?.must_equal false
43
+ result[:"result.policy.default"][:message].must_equal "Breach"
44
44
  end
45
45
  # inject different policy.Condition it { Create.(params: {}, current_user: Object, "policy.default.eval" => Trailblazer::Operation::Policy::Pundit::Condition.new(Auth, :user_object?))["process"].must_equal true }
46
- it { Create.(params: {}, current_user: Module, "policy.default.eval" => Trailblazer::Operation::Policy::Pundit::Condition.new(Auth, :user_object?))["process"].must_be_nil }
46
+ it { Create.(params: {}, current_user: Module, :"policy.default.eval" => Trailblazer::Operation::Policy::Pundit::Condition.new(Auth, :user_object?))[:process].must_be_nil }
47
47
 
48
48
 
49
49
  #---
50
50
  # inheritance, adding Model
51
51
  class Show < Create
52
- step Model( Song, :new ), before: "policy.default.eval"
52
+ step Model( Song, :new ), before: :"policy.default.eval"
53
53
  end
54
54
 
55
55
  it { Trailblazer::Developer.railway(Show).must_equal %{[>model.build,>policy.default.eval,>process]} }
@@ -57,7 +57,7 @@ class PolicyTest < Minitest::Spec
57
57
  # invalid because user AND model.
58
58
  it do
59
59
  result = Show.(params: {}, current_user: Module)
60
- result["process"].must_be_nil
60
+ result[:process].must_be_nil
61
61
  result[:model].inspect.must_equal %{#<struct PolicyTest::Song id=nil>}
62
62
  # result["policy"].inspect.must_equal %{#<struct PolicyTest::Song id=nil>}
63
63
  end
@@ -65,10 +65,10 @@ class PolicyTest < Minitest::Spec
65
65
  # valid because new policy.
66
66
  it do
67
67
  # puts Show["pipetree"].inspect
68
- result = Show.(params: {}, current_user: Module, "policy.default.eval" => Trailblazer::Operation::Policy::Pundit::Condition.new(Auth, :user_and_model?))
69
- result["process"].must_equal true
68
+ result = Show.(params: {}, current_user: Module, :"policy.default.eval" => Trailblazer::Operation::Policy::Pundit::Condition.new(Auth, :user_and_model?))
69
+ result[:process].must_equal true
70
70
  result[:model].inspect.must_equal %{#<struct PolicyTest::Song id=nil>}
71
- result["policy.default"].inspect.must_equal %{<Auth: user:Module, model:#<struct PolicyTest::Song id=nil>>}
71
+ result[:"policy.default"].inspect.must_equal %{<Auth: user:Module, model:#<struct PolicyTest::Song id=nil>>}
72
72
  end
73
73
 
74
74
  ##--
@@ -79,27 +79,27 @@ class PolicyTest < Minitest::Spec
79
79
  step :process
80
80
 
81
81
  def process(options, **)
82
- options["process"] = true
82
+ options[:process] = true
83
83
  end
84
84
  end
85
85
 
86
86
  # successful.
87
87
  it do
88
88
  result = Edit.(params: { id: 1 }, current_user: Module)
89
- result["process"].must_equal true
89
+ result[:process].must_equal true
90
90
  result[:model].inspect.must_equal %{#<struct PolicyTest::Song id=1>}
91
- result["result.policy.default"].success?.must_equal true
92
- result["result.policy.default"]["message"].must_be_nil
91
+ result[:"result.policy.default"].success?.must_equal true
92
+ result[:"result.policy.default"][:message].must_be_nil
93
93
  # result[:valid].must_be_nil
94
- result["policy.default"].inspect.must_equal %{<Auth: user:Module, model:#<struct PolicyTest::Song id=1>>}
94
+ result[:"policy.default"].inspect.must_equal %{<Auth: user:Module, model:#<struct PolicyTest::Song id=1>>}
95
95
  end
96
96
 
97
97
  # breach.
98
98
  it do
99
99
  result = Edit.(params: { id: 4 }, current_user: nil)
100
100
  result[:model].inspect.must_equal %{#<struct PolicyTest::Song id=4>}
101
- result["process"].must_be_nil
102
- result["result.policy.default"].success?.must_equal false
103
- result["result.policy.default"]["message"].must_equal "Breach"
101
+ result[:process].must_be_nil
102
+ result[:"result.policy.default"].success?.must_equal false
103
+ result[:"result.policy.default"][:message].must_equal "Breach"
104
104
  end
105
105
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trailblazer-macro
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0.rc12
4
+ version: 2.1.0.rc13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sutterer
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-07-19 00:00:00.000000000 Z
12
+ date: 2019-07-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -188,7 +188,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
188
188
  version: 1.3.1
189
189
  requirements: []
190
190
  rubyforge_project:
191
- rubygems_version: 2.7.3
191
+ rubygems_version: 2.7.6
192
192
  signing_key:
193
193
  specification_version: 4
194
194
  summary: 'Macros for Trailblazer''s operation: Policy, Wrap, Rescue and more.'