trailblazer-rails 0.4.0 → 1.0.0.beta1
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 +4 -4
- data/.travis.yml +4 -2
- data/CHANGES.md +7 -0
- data/README.md +14 -10
- data/lib/trailblazer/rails/controller.rb +53 -0
- data/lib/trailblazer/rails/form.rb +21 -0
- data/lib/trailblazer/rails/railtie.rb +2 -3
- data/lib/trailblazer/rails/version.rb +1 -1
- data/lib/trailblazer/rails.rb +4 -20
- data/trailblazer-rails.gemspec +4 -7
- metadata +21 -67
- data/lib/trailblazer/operation/controller/active_record.rb +0 -21
- data/lib/trailblazer/operation/model/active_model.rb +0 -11
- data/lib/trailblazer/operation/worker.rb +0 -112
- data/lib/trailblazer/rails/autoloading.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0705212033400543b790af175283c948227fbc0e
|
4
|
+
data.tar.gz: 1c0381c7660afca45e739a77311a5b802d9748d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 017696e9e891c948c1e0352e615b14e0f722985633eb663f5d5f8528efa0ee608c64bf15d31b967416696c926c036585e8741072523895d9759b14c682c66b0c
|
7
|
+
data.tar.gz: 49849e9760b72347be4bdb3837577d3a354d4ffa2249d5c9d9b9a31b2678d1efa333cae64a0ac45ec033c2967d624d10a515cb99410e82797704711c4a84aed2
|
data/.travis.yml
CHANGED
data/CHANGES.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
# 1.0.0
|
2
|
+
|
3
|
+
* Runs only with >= Trailblazer 2.0.0.
|
4
|
+
* Removed `Controller#form`, `#present` and `#respond`. The latter is now [replaced with `Endpoint`](https://github.com/trailblazer/trailblazer-endpoint/). The only operation trigger is `Controller#run`.
|
5
|
+
* Added support for explicit `render cell(Artist::Cell::Index, model)`.
|
6
|
+
* Autoloading got replaced with explicit requires.
|
7
|
+
|
1
8
|
# 0.4.0
|
2
9
|
|
3
10
|
* Better engines support.
|
data/README.md
CHANGED
@@ -1,20 +1,22 @@
|
|
1
1
|
# Trailblazer::Rails
|
2
2
|
|
3
|
-
|
3
|
+
*Trailblazer in your Rails controllers.*
|
4
4
|
|
5
|
+
[](https://gitter.im/trailblazer/chat)
|
6
|
+
[](http://trailblazer.to/newsletter/)
|
7
|
+
[](https://travis-ci.org/trailblazer/trailblazer-rails)
|
9
|
+
[](http://badge.fury.io/rb/cells)
|
5
10
|
|
6
|
-
|
11
|
+
## Overview
|
7
12
|
|
8
|
-
|
13
|
+
`trailblazer-rails` helps you with the following.
|
9
14
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
## Planned
|
14
|
-
|
15
|
-
* Adds autoloading, etc.
|
16
|
-
* Automatic rendering of a controller cell instead of primitive view.
|
15
|
+
* Running operations in your controller actions.
|
16
|
+
* Minimalistic integration tests ("smoke tests") to test controller/operation wiring.
|
17
|
+
* Rendering cells instead of an ActionView in a controller action.
|
17
18
|
|
19
|
+
Please refer to the [full documentation for more](http://trailblazer.to/gems/trailblazer/rails.html).
|
18
20
|
|
19
21
|
## Installation
|
20
22
|
|
@@ -24,6 +26,8 @@ Add this line to your application's Gemfile:
|
|
24
26
|
gem 'trailblazer-rails'
|
25
27
|
```
|
26
28
|
|
29
|
+
Note that the 1.x version only runs with TRB >= 2.0.0.
|
30
|
+
|
27
31
|
## License
|
28
32
|
|
29
33
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Trailblazer::Rails
|
2
|
+
module Controller
|
3
|
+
def run(operation, params=self.params, *dependencies)
|
4
|
+
result = operation.(
|
5
|
+
_run_params(params),
|
6
|
+
*_run_runtime_options(*dependencies)
|
7
|
+
)
|
8
|
+
|
9
|
+
@form = Trailblazer::Rails::Form.new(result["contract.default"], result["model"].class)
|
10
|
+
@model = result["model"]
|
11
|
+
|
12
|
+
yield(result) if result.success? && block_given?
|
13
|
+
|
14
|
+
@_result = result
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
# Override to tweak params. Not recommended.
|
19
|
+
# Use a deserializer instead.
|
20
|
+
def _run_params(params)
|
21
|
+
params
|
22
|
+
end
|
23
|
+
|
24
|
+
# This is where we can inject Dry.RB containers and the like via dependencies.
|
25
|
+
def _run_runtime_options(options={}, *dependencies)
|
26
|
+
[_run_options(options), *dependencies]
|
27
|
+
end
|
28
|
+
|
29
|
+
# Override this to inject dependencies such as "current_user"
|
30
|
+
# into the runtime options.
|
31
|
+
def _run_options(options)
|
32
|
+
options
|
33
|
+
end
|
34
|
+
|
35
|
+
module Render
|
36
|
+
def render(cell=nil, options={}, *, &block)
|
37
|
+
return super unless cell.kind_of?(::Cell::ViewModel)
|
38
|
+
render_cell(cell, options)
|
39
|
+
end
|
40
|
+
|
41
|
+
def render_cell(cell, options)
|
42
|
+
options = options.reverse_merge(layout: true)
|
43
|
+
|
44
|
+
# render the cell.
|
45
|
+
content = cell.()
|
46
|
+
|
47
|
+
render( { html: content }.merge(options) )
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
include Render
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Trailblazer
|
2
|
+
class Rails::Form < SimpleDelegator
|
3
|
+
def initialize(delegated, model_class)
|
4
|
+
super(delegated)
|
5
|
+
@model_class = model_class
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.name
|
9
|
+
# for whatever reason, validations climb up the inheritance tree and require _every_ class to have a name (4.1).
|
10
|
+
"Reform::Form"
|
11
|
+
end
|
12
|
+
|
13
|
+
def model_name
|
14
|
+
::ActiveModel::Name.new(self, nil, @model_class.to_s.camelize)
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_model
|
18
|
+
self
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -18,7 +18,6 @@ module Trailblazer
|
|
18
18
|
|
19
19
|
# This is to autoload Operation::Dispatch, etc. I'm simply assuming people find this helpful in Rails.
|
20
20
|
initializer "trailblazer.library_autoloading" do
|
21
|
-
require "trailblazer/autoloading"
|
22
21
|
end
|
23
22
|
|
24
23
|
# thank you, http://stackoverflow.com/a/17573888/465070
|
@@ -35,8 +34,8 @@ module Trailblazer
|
|
35
34
|
# end
|
36
35
|
|
37
36
|
initializer "trailblazer.application_controller" do
|
38
|
-
|
39
|
-
include Trailblazer::
|
37
|
+
reloader_class.to_prepare do
|
38
|
+
ApplicationController.send :include, Trailblazer::Rails::Controller
|
40
39
|
end
|
41
40
|
end
|
42
41
|
|
data/lib/trailblazer/rails.rb
CHANGED
@@ -2,28 +2,12 @@ require "trailblazer/rails/version"
|
|
2
2
|
|
3
3
|
module Trailblazer
|
4
4
|
module Rails
|
5
|
-
# Your code goes here...
|
6
5
|
end
|
7
6
|
end
|
8
7
|
|
9
8
|
require "reform/rails"
|
10
|
-
require "trailblazer/rails/railtie"
|
11
|
-
|
12
|
-
require "trailblazer/operation"
|
13
|
-
# TODO: remove that once i18n, validations etc in Reform/AM are sorted.
|
14
|
-
Trailblazer::Operation.contract_class.class_eval do
|
15
|
-
def self.name
|
16
|
-
# for whatever reason, validations climb up the inheritance tree and require _every_ class to have a name (4.1).
|
17
|
-
"Reform::Form"
|
18
|
-
end
|
19
|
-
end
|
20
9
|
|
21
|
-
|
22
|
-
require "trailblazer/
|
23
|
-
require "trailblazer/
|
24
|
-
|
25
|
-
include Trailblazer::Operation::Model::ActiveModel # ::contract.
|
26
|
-
end
|
27
|
-
|
28
|
-
require "trailblazer/autoloading"
|
29
|
-
require "trailblazer/rails/autoloading"
|
10
|
+
require "trailblazer/rails/controller"
|
11
|
+
require "trailblazer/rails/form"
|
12
|
+
require "trailblazer/rails/railtie"
|
13
|
+
require "trailblazer"
|
data/trailblazer-rails.gemspec
CHANGED
@@ -9,26 +9,23 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.email = ["apotonick@gmail.com"]
|
10
10
|
|
11
11
|
spec.summary = %q{Convenient Rails support for Trailblazer.}
|
12
|
-
spec.homepage = "http://trailblazer.to"
|
12
|
+
spec.homepage = "http://trailblazer.to/gems/trailblazer/rails"
|
13
13
|
spec.license = "MIT"
|
14
14
|
|
15
15
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
16
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
17
17
|
spec.require_paths = ["lib"]
|
18
18
|
|
19
|
-
spec.add_dependency "trailblazer", ">=
|
19
|
+
spec.add_dependency "trailblazer", ">= 2.0.0.beta1", "< 2.1.0"
|
20
20
|
spec.add_dependency "trailblazer-loader", ">= 0.1.0"
|
21
|
-
spec.add_dependency "reform-rails", ">= 0.1.4"
|
21
|
+
spec.add_dependency "reform-rails", ">= 0.1.4", "< 0.2.0"
|
22
22
|
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.10"
|
24
24
|
spec.add_development_dependency "rake", "~> 10.0"
|
25
25
|
spec.add_development_dependency "minitest"
|
26
|
-
spec.add_development_dependency "rails"
|
27
26
|
spec.add_development_dependency "actionpack", '>= 3.0.0' # Rails is optional.
|
28
27
|
spec.add_development_dependency "sqlite3"
|
29
|
-
spec.add_development_dependency "responders"
|
30
|
-
spec.add_development_dependency "database_cleaner"
|
31
|
-
spec.add_development_dependency "sidekiq", ">= 3.1.0"
|
28
|
+
# spec.add_development_dependency "responders"
|
32
29
|
|
33
30
|
spec.add_development_dependency "multi_json"
|
34
31
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trailblazer-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0.beta1
|
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
|
+
date: 2016-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: trailblazer
|
@@ -16,14 +16,20 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.0.0.beta1
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 2.1.0
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
27
|
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
29
|
+
version: 2.0.0.beta1
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.1.0
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: trailblazer-loader
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -45,6 +51,9 @@ dependencies:
|
|
45
51
|
- - ">="
|
46
52
|
- !ruby/object:Gem::Version
|
47
53
|
version: 0.1.4
|
54
|
+
- - "<"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 0.2.0
|
48
57
|
type: :runtime
|
49
58
|
prerelease: false
|
50
59
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -52,6 +61,9 @@ dependencies:
|
|
52
61
|
- - ">="
|
53
62
|
- !ruby/object:Gem::Version
|
54
63
|
version: 0.1.4
|
64
|
+
- - "<"
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 0.2.0
|
55
67
|
- !ruby/object:Gem::Dependency
|
56
68
|
name: bundler
|
57
69
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,20 +106,6 @@ dependencies:
|
|
94
106
|
- - ">="
|
95
107
|
- !ruby/object:Gem::Version
|
96
108
|
version: '0'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: rails
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - ">="
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - ">="
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
111
109
|
- !ruby/object:Gem::Dependency
|
112
110
|
name: actionpack
|
113
111
|
requirement: !ruby/object:Gem::Requirement
|
@@ -136,48 +134,6 @@ dependencies:
|
|
136
134
|
- - ">="
|
137
135
|
- !ruby/object:Gem::Version
|
138
136
|
version: '0'
|
139
|
-
- !ruby/object:Gem::Dependency
|
140
|
-
name: responders
|
141
|
-
requirement: !ruby/object:Gem::Requirement
|
142
|
-
requirements:
|
143
|
-
- - ">="
|
144
|
-
- !ruby/object:Gem::Version
|
145
|
-
version: '0'
|
146
|
-
type: :development
|
147
|
-
prerelease: false
|
148
|
-
version_requirements: !ruby/object:Gem::Requirement
|
149
|
-
requirements:
|
150
|
-
- - ">="
|
151
|
-
- !ruby/object:Gem::Version
|
152
|
-
version: '0'
|
153
|
-
- !ruby/object:Gem::Dependency
|
154
|
-
name: database_cleaner
|
155
|
-
requirement: !ruby/object:Gem::Requirement
|
156
|
-
requirements:
|
157
|
-
- - ">="
|
158
|
-
- !ruby/object:Gem::Version
|
159
|
-
version: '0'
|
160
|
-
type: :development
|
161
|
-
prerelease: false
|
162
|
-
version_requirements: !ruby/object:Gem::Requirement
|
163
|
-
requirements:
|
164
|
-
- - ">="
|
165
|
-
- !ruby/object:Gem::Version
|
166
|
-
version: '0'
|
167
|
-
- !ruby/object:Gem::Dependency
|
168
|
-
name: sidekiq
|
169
|
-
requirement: !ruby/object:Gem::Requirement
|
170
|
-
requirements:
|
171
|
-
- - ">="
|
172
|
-
- !ruby/object:Gem::Version
|
173
|
-
version: 3.1.0
|
174
|
-
type: :development
|
175
|
-
prerelease: false
|
176
|
-
version_requirements: !ruby/object:Gem::Requirement
|
177
|
-
requirements:
|
178
|
-
- - ">="
|
179
|
-
- !ruby/object:Gem::Version
|
180
|
-
version: 3.1.0
|
181
137
|
- !ruby/object:Gem::Dependency
|
182
138
|
name: multi_json
|
183
139
|
requirement: !ruby/object:Gem::Requirement
|
@@ -206,17 +162,15 @@ files:
|
|
206
162
|
- LICENSE.txt
|
207
163
|
- README.md
|
208
164
|
- Rakefile
|
209
|
-
- lib/trailblazer/operation/controller/active_record.rb
|
210
|
-
- lib/trailblazer/operation/model/active_model.rb
|
211
165
|
- lib/trailblazer/operation/responder.rb
|
212
|
-
- lib/trailblazer/operation/worker.rb
|
213
166
|
- lib/trailblazer/rails.rb
|
214
|
-
- lib/trailblazer/rails/
|
167
|
+
- lib/trailblazer/rails/controller.rb
|
168
|
+
- lib/trailblazer/rails/form.rb
|
215
169
|
- lib/trailblazer/rails/railtie.rb
|
216
170
|
- lib/trailblazer/rails/test/integration.rb
|
217
171
|
- lib/trailblazer/rails/version.rb
|
218
172
|
- trailblazer-rails.gemspec
|
219
|
-
homepage: http://trailblazer.to
|
173
|
+
homepage: http://trailblazer.to/gems/trailblazer/rails
|
220
174
|
licenses:
|
221
175
|
- MIT
|
222
176
|
metadata: {}
|
@@ -231,9 +185,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
231
185
|
version: '0'
|
232
186
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
233
187
|
requirements:
|
234
|
-
- - "
|
188
|
+
- - ">"
|
235
189
|
- !ruby/object:Gem::Version
|
236
|
-
version:
|
190
|
+
version: 1.3.1
|
237
191
|
requirements: []
|
238
192
|
rubyforge_project:
|
239
193
|
rubygems_version: 2.6.3
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# Assigns an additional instance variable for +@model+ named after the model's table name (e.g. @comment).
|
2
|
-
#
|
3
|
-
# THIS MODULE IS DEPRECATED!
|
4
|
-
#
|
5
|
-
# Please don't use this module. Instead, use @model in your controller or pass the
|
6
|
-
# operation instance to a cell to present it.
|
7
|
-
module Trailblazer::Operation::Controller::ActiveRecord
|
8
|
-
private
|
9
|
-
def setup_operation_instance_variables!(operation, options)
|
10
|
-
super
|
11
|
-
instance_variable_set(:"@#{operation_model_name}", @model)
|
12
|
-
end
|
13
|
-
|
14
|
-
def operation_model_name
|
15
|
-
# set the right variable name if collection
|
16
|
-
if @operation.is_a?(Trailblazer::Operation::Collection)
|
17
|
-
return @model.model.table_name.split(".").last
|
18
|
-
end
|
19
|
-
@model.class.table_name.split(".").last.singularize
|
20
|
-
end
|
21
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
module Trailblazer
|
2
|
-
module Operation::Model
|
3
|
-
# Automatically set model_name on operation's contract.
|
4
|
-
module ActiveModel
|
5
|
-
def contract(*, &block)
|
6
|
-
super
|
7
|
-
contract_class.model(model_class) # this assumes that Form::ActiveModel is mixed in.
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
@@ -1,112 +0,0 @@
|
|
1
|
-
require 'sidekiq/worker'
|
2
|
-
require 'active_support/core_ext/hash/indifferent_access'
|
3
|
-
|
4
|
-
#setup in initialize: when Op.run() with Worker, the policy will be run "delayed" and not with the actual permission set. this will result in many crashing sidekiq workers.
|
5
|
-
|
6
|
-
class Trailblazer::Operation
|
7
|
-
# only kicks in when Operation::run, #run will still do it real-time
|
8
|
-
# Works with Reform 2, only.
|
9
|
-
module Worker
|
10
|
-
def self.included(base)
|
11
|
-
base.send(:include, Sidekiq::Worker)
|
12
|
-
base.extend(ClassMethods)
|
13
|
-
end
|
14
|
-
|
15
|
-
module ClassMethods
|
16
|
-
def run(params)
|
17
|
-
if background?
|
18
|
-
return perform_async(serializable(params))
|
19
|
-
end
|
20
|
-
|
21
|
-
super(params)
|
22
|
-
end
|
23
|
-
|
24
|
-
def new(*args)
|
25
|
-
return super if args.any?
|
26
|
-
# sidekiq behavior: (not a big fan of this)
|
27
|
-
self
|
28
|
-
end
|
29
|
-
|
30
|
-
def perform(params) # called by Sidekiq.
|
31
|
-
build_operation(params).perform
|
32
|
-
end
|
33
|
-
|
34
|
-
def jid=(jid)
|
35
|
-
puts "@@@@@ #{jid.inspect}"
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
def perform_async(*args)
|
40
|
-
client_push('class' => self, 'args' => args) # calls class.new.perform(params)
|
41
|
-
end
|
42
|
-
|
43
|
-
def background? # TODO: make configurable.
|
44
|
-
true
|
45
|
-
# if Rails.env == "production" or Rails.env == "staging"
|
46
|
-
end
|
47
|
-
|
48
|
-
def serializable(params)
|
49
|
-
params # this is where we convert file uloads into Trailblazer::UploadedFile, etc. soon.
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
|
54
|
-
def perform#(params)
|
55
|
-
# the serialized params hash from Sidekiq contains a Op::UploadedFile hash.
|
56
|
-
|
57
|
-
# the following code is basically what happens in a controller.
|
58
|
-
# this is a bug in Rails, it doesn't work without requiring as/hash/ina
|
59
|
-
# params = ActiveSupport::HashWithIndifferentAccess.new_from_hash_copying_default(params) # TODO: this might make it ultra-slow as Reform converts it back to strings.
|
60
|
-
params = @params.with_indifferent_access
|
61
|
-
@params = deserializable(params)
|
62
|
-
run
|
63
|
-
end
|
64
|
-
|
65
|
-
private
|
66
|
-
def deserializable(params)
|
67
|
-
params # this is where we convert file uloads into Trailblazer::UploadedFile, etc. soon.
|
68
|
-
end
|
69
|
-
|
70
|
-
|
71
|
-
# Overrides ::serializable and #deserializable and handles file properties from the Contract schema.
|
72
|
-
module FileMarshaller
|
73
|
-
# NOTE: this is WIP and the implementation will be more understandable and performant soon.
|
74
|
-
def self.included(base)
|
75
|
-
base.extend ClassMethods
|
76
|
-
end
|
77
|
-
|
78
|
-
|
79
|
-
private
|
80
|
-
module ClassMethods
|
81
|
-
def file_marshaller_representer
|
82
|
-
@file_marshaller_representer ||= contract_class.schema(include: [Representable::Hash]).apply do |dfn|
|
83
|
-
dfn.merge!(
|
84
|
-
getter: lambda { |*| self[dfn.name.to_sym] },
|
85
|
-
setter: lambda { |fragment, *| self[dfn.name.to_s] = fragment }
|
86
|
-
) # FIXME: allow both sym and str.
|
87
|
-
|
88
|
-
dfn.merge!(class: Hash) and next if dfn[:form] or dfn[:twin] # nested properties need a class for deserialization.
|
89
|
-
next unless dfn[:file]
|
90
|
-
|
91
|
-
# TODO: where do we set /tmp/uploads?
|
92
|
-
dfn.merge!(
|
93
|
-
serialize: lambda { |file, *| Trailblazer::Operation::UploadedFile.new(file, tmp_dir: "/tmp/uploads").to_hash },
|
94
|
-
deserialize: lambda { |object, hash, *| Trailblazer::Operation::UploadedFile.from_hash(hash) },
|
95
|
-
class: Hash
|
96
|
-
)
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
def serializable(params)
|
101
|
-
file_marshaller_representer.new(params).to_hash
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
# todo: do with_indifferent_access in #deserialize and call super here.
|
106
|
-
def deserializable(hash)
|
107
|
-
# self.class.file_marshaller_representer.new({}).extend(Representable::Debug).from_hash(hash)
|
108
|
-
self.class.file_marshaller_representer.new({}.with_indifferent_access).from_hash(hash)
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|