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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f2618bcea766e5192fadaa575315a4ad04170654
4
- data.tar.gz: fe623b65e42ac232f9bc0ec45a723b5fa5da70e2
3
+ metadata.gz: 1c3291fbc4f467b44c4246b36472b29cc46b998b
4
+ data.tar.gz: e6a7c046f95d199a88375748a18d2be9fd9b6612
5
5
  SHA512:
6
- metadata.gz: befbbee9f37e868da73002c26ce09b91f609ee0e1ded07ffc976dc56cd4440cfa23609911939394c48427d7e9a69bcf28839404a2fb411584d6215b11f79f8c2
7
- data.tar.gz: e132220e955dc8b0338584b3fc1055d9abacd2100308277829cbf51bfa6b0ecb5bf2a605c7759bb9a36a191ac9985fe514c4a581ede512cd003a74728928c6e6
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
- # gem "representable", path: "../representable"
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
- # gem "reform", path: "../reform"
10
+ # gem "reform", "~> 2.0.0"
11
+ gem "reform", path: "../reform"
12
+ gem "roar", path: "../roar"
12
13
  gem "multi_json"
@@ -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 = params
9
- @request = request
10
- @is_document = options[: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 document_request?
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
- def document_request?
22
- @is_document
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(*args)
6
- operation!(*args).tap do |op|
7
- op.contract.prepopulate! # equals to @form.prepopulate!
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)
@@ -1,3 +1,3 @@
1
1
  module Trailblazer
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  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: 1.0.1
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-02 00:00:00.000000000 Z
11
+ date: 2015-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: uber