trailblazer 2.0.6 → 2.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,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 856c86ffb4c7cc3adfe5bf1f6a18b121a2e8869b
4
- data.tar.gz: 1a79e03ac9dd720d86c7b5d13973316a1e71010b
3
+ metadata.gz: bf6240c4f189a477366736fe061c493f08c6949b
4
+ data.tar.gz: 68b716f9d99c124fc6d86f1e471c21478d25c0ae
5
5
  SHA512:
6
- metadata.gz: 95d7f47adc5eef009673170e5b423d0ce141884b35501cd6dafc7ef8194ff20e4e4d1ceb1859519961e6f1f983408fe053aede58fba3a6d23588dc2b0ef952bf
7
- data.tar.gz: c0b9b10bf8fd45e1f55c41bbdd85b9f706f54831fc224915a9b37272e17047911e41c5ccfc220ccf4eed76bbc6ab62c424cb14ca079a5c86e90628dc93b85eaf
6
+ metadata.gz: 3ea12ffe486f4f9c50ac9a839cd3b6429a36c7e6be2c6dd889244f025d7dbe4b21b50b45f56378b77fdddba1c819cdaf81b204d32aed90ce606b846ba561aac8
7
+ data.tar.gz: 0cbc2fc6e6f3e3e38019cf3181373803fc0828a12799bd6239705f77786eafacc9d339e1c48f3939876aa93473a5a49ce1a5f50b2651d50f5a5489f9b59d0b8b
data/CHANGES.md CHANGED
@@ -1,3 +1,14 @@
1
+ # 2.0.7
2
+
3
+ * Allow to use any method with the Model macro, e.g.
4
+
5
+ ```ruby
6
+ step Model( Comment, :[] )
7
+ ```
8
+
9
+ will now invoke `Comment[ params[:id] ]`, which makes using Sequel a breeze.
10
+
11
+
1
12
  # 2.0.6
2
13
 
3
14
  * Fix what we broke in 2.0.5, where `Wrap` would always use the current operation subclass and not the empty `Trailblazer::Operation`. Thanks to @mensfeld.
data/Gemfile CHANGED
@@ -9,7 +9,7 @@ gemspec
9
9
  gem "reform-rails"
10
10
  gem "activesupport", "~> 4.2.0"
11
11
 
12
- # gem "roar", github: "apotonick/roar"
12
+ gem "roar", github: "apotonick/roar"
13
13
  # gem "reform", "~> 2.0.0"
14
14
  gem "reform"#, path: "../reform"
15
15
  # gem "roar", path: "../roar"
data/README.md CHANGED
@@ -264,7 +264,7 @@ end
264
264
 
265
265
  The operation can then parse incoming JSON documents in `validate` and render a document via `to_json`.
266
266
 
267
- [Learn more.](http://trailblazer.to/gems/operation/representer.html)
267
+ [Learn more.](http://trailblazer.to/gems/operation/2.0/representer.html)
268
268
 
269
269
  ## Tests
270
270
 
@@ -26,22 +26,29 @@ class Trailblazer::Operation
26
26
  action = options["model.action"] || :new
27
27
  model_class = options["model.class"]
28
28
 
29
- send("#{action}!", model_class, params)
29
+ action = :pass_through unless [:new, :find_by, :find].include?(action)
30
+
31
+ send("#{action}!", model_class, params, options["model.action"])
30
32
  end
31
33
 
32
- def new!(model_class, params)
34
+ def new!(model_class, params, *)
33
35
  model_class.new
34
36
  end
35
37
 
36
- def find!(model_class, params)
38
+ def find!(model_class, params, *)
37
39
  model_class.find(params[:id])
38
40
  end
39
41
 
40
42
  # Doesn't throw an exception and will return false to divert to Left.
41
- def find_by!(model_class, params)
43
+ def find_by!(model_class, params, *)
42
44
  model_class.find_by(id: params[:id])
43
45
  end
44
46
 
47
+ # Call any method on the model class and pass :id.
48
+ def pass_through!(model_class, params, action)
49
+ model_class.send(action, params[:id])
50
+ end
51
+
45
52
  private
46
53
  def deprecate_update!(options) # TODO: remove in 2.1.
47
54
  return unless options["model.action"] == :update
@@ -1,3 +1,3 @@
1
1
  module Trailblazer
2
- VERSION = "2.0.6"
2
+ VERSION = "2.0.7"
3
3
  end
@@ -5,6 +5,10 @@ class DocsModelTest < Minitest::Spec
5
5
  def self.find_by(id:nil)
6
6
  id.nil? ? nil : new(id)
7
7
  end
8
+
9
+ def self.[](id)
10
+ id.nil? ? nil : new(id+99)
11
+ end
8
12
  end
9
13
 
10
14
  #:op
@@ -46,7 +50,26 @@ class DocsModelTest < Minitest::Spec
46
50
  result.success? #=> false
47
51
  #:update-fail end
48
52
 
49
- result["model"].must_equal nil
53
+ result["model"].must_be_nil
50
54
  result.success?.must_equal false
51
55
  end
56
+
57
+ #:show
58
+ class Show < Trailblazer::Operation
59
+ step Model( Song, :[] )
60
+ # ..
61
+ end
62
+ #:show end
63
+
64
+ it do
65
+ result = Show.({ id: 1 })
66
+
67
+ #:show-ok
68
+ result = Show.({ id: 1 })
69
+ result["model"] #=> #<struct Song id=1, title="Roxanne">
70
+ #:show-ok end
71
+
72
+ result.success?.must_equal true
73
+ result["model"].inspect.must_equal %{#<struct DocsModelTest::Song id=100, title=nil>}
74
+ end
52
75
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trailblazer
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.6
4
+ version: 2.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: 2017-05-02 00:00:00.000000000 Z
11
+ date: 2017-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: trailblazer-operation
@@ -243,7 +243,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
243
243
  version: '0'
244
244
  requirements: []
245
245
  rubyforge_project:
246
- rubygems_version: 2.5.2
246
+ rubygems_version: 2.6.8
247
247
  signing_key:
248
248
  specification_version: 4
249
249
  summary: A high-level architecture for Ruby and Rails.