trailblazer 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +5 -0
- data/Gemfile +4 -3
- data/lib/trailblazer/endpoint.rb +17 -7
- data/lib/trailblazer/operation/controller.rb +7 -7
- data/lib/trailblazer/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c3291fbc4f467b44c4246b36472b29cc46b998b
|
4
|
+
data.tar.gz: e6a7c046f95d199a88375748a18d2be9fd9b6612
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35ce9c252a11a60218d947f67db6b7de446ad4f1866480b18348604eb03ef9b6014ebb6747573b843ce76f794bb6f2c641c5eab1e92d73efeada8edeb531b95f
|
7
|
+
data.tar.gz: 7b94323221011e3f1233f44375420f39cc17a87401a410490aaca7aae0f4bbfd3fddce695e3edaac344b0f64919100a0649cc7c3e42229f9879fdb807f6a4b74
|
data/CHANGES.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
# 1.0.2
|
2
|
+
|
3
|
+
* Treat all requests as `params` requests unless the operation has a representer mixed in. If you don't want that, you can override using `is_document: false`. This appears to be the smoothest solution for all.
|
4
|
+
* In `Controller#form`, the options argument is now passed into `form.prepopulate!(options)`. This allows to use arbitrary options and the `options[:params]` for prepopulation.
|
5
|
+
|
1
6
|
# 1.0.1
|
2
7
|
|
3
8
|
* Treat `:js` requests as non-document, too.
|
data/Gemfile
CHANGED
@@ -3,10 +3,11 @@ source 'https://rubygems.org'
|
|
3
3
|
# Specify your gem's dependencies in trailblazer.gemspec
|
4
4
|
gemspec
|
5
5
|
|
6
|
-
|
6
|
+
gem "representable", path: "../representable"
|
7
7
|
# gem "disposable", path: "../disposable"
|
8
8
|
gem "virtus"
|
9
9
|
# gem "reform", github: "apotonick/reform"
|
10
|
-
gem "reform", "~> 2.0.0"
|
11
|
-
|
10
|
+
# gem "reform", "~> 2.0.0"
|
11
|
+
gem "reform", path: "../reform"
|
12
|
+
gem "roar", path: "../roar"
|
12
13
|
gem "multi_json"
|
data/lib/trailblazer/endpoint.rb
CHANGED
@@ -1,25 +1,35 @@
|
|
1
1
|
module Trailblazer
|
2
2
|
# Encapsulates HTTP-specific logic needed before running an operation.
|
3
|
-
# Right now, all this does is #document_body!
|
3
|
+
# Right now, all this does is #document_body! which figures out whether or not to pass the request body
|
4
|
+
# into params, so the operation can use a representer to deserialize the original document.
|
4
5
|
# To be used in Lotus, Roda, Rails, etc.
|
5
6
|
class Endpoint
|
6
7
|
def initialize(operation_class, params, request, options)
|
7
8
|
@operation_class = operation_class
|
8
|
-
@params
|
9
|
-
@request
|
10
|
-
@is_document
|
9
|
+
@params = params
|
10
|
+
@request = request
|
11
|
+
@is_document = document_request_for?(options)
|
11
12
|
end
|
12
13
|
|
13
14
|
def call
|
14
|
-
document_body! if
|
15
|
+
document_body! if @is_document
|
15
16
|
yield @params# Create.run(params)
|
16
17
|
end
|
17
18
|
|
18
19
|
private
|
19
20
|
attr_reader :params, :operation_class, :request
|
20
21
|
|
21
|
-
|
22
|
-
|
22
|
+
# this is a really weak test but will make sure the document_body behavior is only enabled
|
23
|
+
# for people who know what they're doing. also, this won't work if you use a polymorphic dispatch,
|
24
|
+
# e.g. `run Comment::Create` where the builder will instantiate Create::JSON which has Representer
|
25
|
+
# included.
|
26
|
+
def document_request_for?(options)
|
27
|
+
puts "``#{options.inspect}"
|
28
|
+
return options[:is_document] if options.has_key?(:is_document)
|
29
|
+
|
30
|
+
result= operation_class < Operation::Representer # TODO: this doesn't work with polymorphic dispatch.
|
31
|
+
puts "@@ss@@@ #{result.inspect}"
|
32
|
+
result
|
23
33
|
end
|
24
34
|
|
25
35
|
def document_body!
|
@@ -2,9 +2,11 @@ require "trailblazer/endpoint"
|
|
2
2
|
|
3
3
|
module Trailblazer::Operation::Controller
|
4
4
|
private
|
5
|
-
def form(
|
6
|
-
|
7
|
-
|
5
|
+
def form(operation_class, options={})
|
6
|
+
options[:___dont_deprecate] = 1 # TODO: remove in 1.1.
|
7
|
+
|
8
|
+
operation!(operation_class, options).tap do |op|
|
9
|
+
op.contract.prepopulate!(options) # equals to @form.prepopulate!
|
8
10
|
end.contract
|
9
11
|
end
|
10
12
|
|
@@ -31,6 +33,7 @@ private
|
|
31
33
|
# The block passed to #respond is always run, regardless of the validity result.
|
32
34
|
def respond(operation_class, options={}, &block)
|
33
35
|
options[:___dont_deprecate] = 1 # TODO: remove in 1.1.
|
36
|
+
|
34
37
|
res, op = operation_for!(operation_class, options) { |params| operation_class.run(params) }
|
35
38
|
namespace = options.delete(:namespace) || []
|
36
39
|
|
@@ -49,11 +52,8 @@ private
|
|
49
52
|
|
50
53
|
# Normalizes parameters and invokes the operation (including its builders).
|
51
54
|
def operation_for!(operation_class, options, &block)
|
52
|
-
options = deprecate_positional_params_argument!(options)
|
55
|
+
options = deprecate_positional_params_argument!(options) # TODO: remove in 1.1.
|
53
56
|
|
54
|
-
# Per default, only treat :html and js as non-document.
|
55
|
-
default_options = {is_document: ![:html, :js].include?(request.format.to_sym)}
|
56
|
-
options = default_options.merge(options)
|
57
57
|
params = options.delete(:params) || self.params # TODO: test params: parameter properly in all 4 methods.
|
58
58
|
|
59
59
|
process_params!(params)
|
data/lib/trailblazer/version.rb
CHANGED
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: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Sutterer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: uber
|