trailblazer-rails 2.1.1 → 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.4.1
1
+ 2.4.4
data/.travis.yml CHANGED
@@ -1,12 +1,16 @@
1
- language: ruby
2
- matrix:
3
- include:
4
- - rvm: 2.4.1
5
- env: TEST_SUITE=rails5.0
6
- gemfile: test/rails5.0/Gemfile
7
-
8
- - rvm: 2.4.1
9
- env: TEST_SUITE=rails5.1
10
- gemfile: test/rails5.1/Gemfile
11
-
12
- script: cd test/$TEST_SUITE && bundle exec rake test
1
+ language: ruby
2
+ matrix:
3
+ include:
4
+ - rvm: 2.4.1
5
+ env: TEST_SUITE=rails5.0
6
+ gemfile: test/rails5.0/Gemfile
7
+
8
+ - rvm: 2.4.1
9
+ env: TEST_SUITE=rails5.1
10
+ gemfile: test/rails5.1/Gemfile
11
+
12
+ - rvm: 2.5.1
13
+ env: TEST_SUITE=rails5.2
14
+ gemfile: test/rails5.2/Gemfile
15
+
16
+ script: cd test/$TEST_SUITE && bundle exec rake test
data/CHANGES.md CHANGED
@@ -1,108 +1,132 @@
1
- # 2.1.1
2
-
3
- * Fixed issue for rails 5.2rc2 when loading model's files
4
- * Rubocop introduced
5
- * Allow enabling tracing when using `run` via `config.trailblazer.enable_tracing = true`
6
-
7
- # 2.1.0
8
-
9
- * Drop deprecated syntax for controller `run`
10
- * Allow disabling of the Trailblazer loader via `config.trailblazer.use_loader = false`
11
-
12
- # 2.0.0
13
-
14
- * Support Trailblazer 2.1.0+
15
- * Drop support for older version of Trailblazer
16
-
17
- # 1.0.5
18
-
19
- * Hook trailblazer application_controller initializer to finisher_hook
20
-
21
- # 1.0.4
22
-
23
- * Make `Railtie::extend_application_controller!` overwriteable via a module.
24
-
25
- # 1.0.3
26
-
27
- * Return the computed application controller constant from `Railtie::extend_application_controller!` to make `compat` code simpler.
28
-
29
- # 1.0.2
30
-
31
- * Allow configuring `ApplicationController` constant via `config.trailblazer.application_controller`.
32
-
33
- # 1.0.1
34
-
35
- * Allow using this gem without `cells,` by loading cells support only when the `cells` gem got detected. Thanks to @promisedlandt.
36
-
37
- # 1.0.0
38
-
39
- * Runs only with >= Trailblazer 2.0.0.
40
- * 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`.
41
- * Added support for explicit `render cell(Artist::Cell::Index, model)`.
42
- * Autoloading got replaced with explicit requires.
43
-
44
- # 0.4.0
45
-
46
- * Better engines support.
47
- * Fix `Responder#errors` by simply removing it and letting `Operation#errors` return the contract errors.
48
-
49
- # 0.3.2
50
-
51
- * Make it work with Rails 3.x, again.
52
-
53
- # 0.3.1
54
-
55
- * Fix loading of `reform-rails`.
56
-
57
- # 0.3.0
58
-
59
- * Require `reform-rails` as a static dependency. This simplifies the user's setup significantly.
60
- * Run the `Railtie` after `reform.form_extensions` and allow reform-rails to do its setup work, then load concepts.
61
-
62
- # 0.2.4
63
-
64
- * Require `trailblazer-loader-0.0.7`.
65
- * Fix sorting, model files are now always required first.
66
- * Manually include `Operation::Controller` in `ApplicationController` for every reload.
67
-
68
- # 0.2.3
69
-
70
- * Bump to `trailblazer-loader` 0.0.4.
71
-
72
- # 0.2.2
73
-
74
- * Remove cells loading code, this happens via trailblazer-loader now.
75
- * We now load the concept's model file if it exists.
76
-
77
- # 0.2.1
78
-
79
- * Require `trailblazer-loader`.
80
-
81
- # 0.2.0
82
-
83
- * Use `trailblazer-loader` for loading operations and associated files, now. Note that `operations.rb` now is `operation.rb` (hence the minor bump).
84
- * The `Operation::Controller` module is not included into `ApplicationController` automatically.
85
- * Added `Trailblazer::Test::Integration`.
86
-
87
- # 0.1.6
88
-
89
- * Fix `Controller#run`, which now returns the operation instance instead of the `Else` object.
90
-
91
- # 0.1.5
92
-
93
- * 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. Thanks to @Scharrels for discussion.
94
- * 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. Thanks @sauy7 for discussion.
95
-
96
- # 0.1.4
97
-
98
- * Treat `:js` requests as non-document, too.
99
- * `Controller#form` now returns the form object and not the operation.
100
- * In `Controller`, `#form`, `#present`, `#run` and `#respond` now all have the same API: `run(constant, options)`. If you want to pass a custom params hash, use `run Comment::Create, params: {..}`.
101
-
102
- # 0.1.3
103
-
104
- * `Operation::contract` works properly with `Operation::ActiveModel` mixed in.
105
-
106
- # 0.1.2
107
-
108
- * First version running with Trailblazer 1.0.0.
1
+ # 2.1.2
2
+
3
+ * `Trailblazer::Rails::Railtie` divided in 2 modules:
4
+ * `Loader` -> require_dependecy `concepts`
5
+ * `ExtendApplicationController` -> include `run` and `render` in controllers
6
+
7
+ # 2.1.1
8
+
9
+ * Fixed issue for rails 5.2rc2 when loading model's files
10
+ * Rubocop introduced
11
+ * Allow enabling tracing when using `run` via `config.trailblazer.enable_tracing = true`
12
+
13
+ # 2.1.0
14
+
15
+ * Drop deprecated syntax for controller `run`
16
+ * Allow disabling of the Trailblazer loader via `config.trailblazer.use_loader = false`
17
+
18
+ # 2.0.0
19
+
20
+ * Support Trailblazer 2.1.0+
21
+ * Drop support for older version of Trailblazer
22
+
23
+ # 1.0.9
24
+
25
+ * `Trailblazer::Rails::Railtie` divided in 2 modules:
26
+ * `Loader` -> require_dependecy `concepts`
27
+ * `ExtendApplicationController` -> include `run` and `render` in controllers
28
+
29
+ # 1.0.8
30
+
31
+ * Fixed Circular dependency detected in rails 5.2
32
+
33
+ # 1.0.7
34
+
35
+ * Fixed typo error in use_loader config flag
36
+
37
+ # 1.0.6 (revoked)
38
+
39
+ * Introduce use_loader config flag
40
+
41
+ # 1.0.5
42
+
43
+ * Hook trailblazer application_controller initializer to finisher_hook
44
+
45
+ # 1.0.4
46
+
47
+ * Make `Railtie::extend_application_controller!` overwriteable via a module.
48
+
49
+ # 1.0.3
50
+
51
+ * Return the computed application controller constant from `Railtie::extend_application_controller!` to make `compat` code simpler.
52
+
53
+ # 1.0.2
54
+
55
+ * Allow configuring `ApplicationController` constant via `config.trailblazer.application_controller`.
56
+
57
+ # 1.0.1
58
+
59
+ * Allow using this gem without `cells,` by loading cells support only when the `cells` gem got detected. Thanks to @promisedlandt.
60
+
61
+ # 1.0.0
62
+
63
+ * Runs only with >= Trailblazer 2.0.0.
64
+ * 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`.
65
+ * Added support for explicit `render cell(Artist::Cell::Index, model)`.
66
+ * Autoloading got replaced with explicit requires.
67
+
68
+ # 0.4.0
69
+
70
+ * Better engines support.
71
+ * Fix `Responder#errors` by simply removing it and letting `Operation#errors` return the contract errors.
72
+
73
+ # 0.3.2
74
+
75
+ * Make it work with Rails 3.x, again.
76
+
77
+ # 0.3.1
78
+
79
+ * Fix loading of `reform-rails`.
80
+
81
+ # 0.3.0
82
+
83
+ * Require `reform-rails` as a static dependency. This simplifies the user's setup significantly.
84
+ * Run the `Railtie` after `reform.form_extensions` and allow reform-rails to do its setup work, then load concepts.
85
+
86
+ # 0.2.4
87
+
88
+ * Require `trailblazer-loader-0.0.7`.
89
+ * Fix sorting, model files are now always required first.
90
+ * Manually include `Operation::Controller` in `ApplicationController` for every reload.
91
+
92
+ # 0.2.3
93
+
94
+ * Bump to `trailblazer-loader` 0.0.4.
95
+
96
+ # 0.2.2
97
+
98
+ * Remove cells loading code, this happens via trailblazer-loader now.
99
+ * We now load the concept's model file if it exists.
100
+
101
+ # 0.2.1
102
+
103
+ * Require `trailblazer-loader`.
104
+
105
+ # 0.2.0
106
+
107
+ * Use `trailblazer-loader` for loading operations and associated files, now. Note that `operations.rb` now is `operation.rb` (hence the minor bump).
108
+ * The `Operation::Controller` module is not included into `ApplicationController` automatically.
109
+ * Added `Trailblazer::Test::Integration`.
110
+
111
+ # 0.1.6
112
+
113
+ * Fix `Controller#run`, which now returns the operation instance instead of the `Else` object.
114
+
115
+ # 0.1.5
116
+
117
+ * 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. Thanks to @Scharrels for discussion.
118
+ * 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. Thanks @sauy7 for discussion.
119
+
120
+ # 0.1.4
121
+
122
+ * Treat `:js` requests as non-document, too.
123
+ * `Controller#form` now returns the form object and not the operation.
124
+ * In `Controller`, `#form`, `#present`, `#run` and `#respond` now all have the same API: `run(constant, options)`. If you want to pass a custom params hash, use `run Comment::Create, params: {..}`.
125
+
126
+ # 0.1.3
127
+
128
+ * `Operation::contract` works properly with `Operation::ActiveModel` mixed in.
129
+
130
+ # 0.1.2
131
+
132
+ * First version running with Trailblazer 1.0.0.
data/LICENSE.txt CHANGED
@@ -1,21 +1,21 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2015-2018 Nick Sutterer
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015-2018 Nick Sutterer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -1,39 +1,39 @@
1
- # Trailblazer::Rails
2
-
3
- *Trailblazer in your Rails controllers.*
4
-
5
- [![Gitter Chat](https://badges.gitter.im/trailblazer/chat.svg)](https://gitter.im/trailblazer/chat)
6
- [![TRB Newsletter](https://img.shields.io/badge/TRB-newsletter-lightgrey.svg)](http://trailblazer.to/newsletter/)
7
- [![Build
8
- Status](https://travis-ci.org/trailblazer/trailblazer-rails.svg)](https://travis-ci.org/trailblazer/trailblazer-rails)
9
- [![Gem Version](https://badge.fury.io/rb/trailblazer-rails.svg)](http://badge.fury.io/rb/trailblazer-rails)
10
-
11
- ## Overview
12
-
13
- `trailblazer-rails` helps you with the following.
14
-
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.
18
-
19
- Please refer to the [full documentation for more](http://trailblazer.to/gems/trailblazer/2.0/rails.html).
20
-
21
- ## Installation
22
-
23
- Add this line to your application's Gemfile:
24
-
25
- ```ruby
26
- gem 'trailblazer-rails'
27
- ```
28
-
29
- Note that the 2.x version only runs with TRB >= 2.1.0.
30
-
31
- ## Setting flags
32
-
33
- * `config.trailblazer.use_loader = false` to disable Trailblazer loader (default TRUE)
34
- * `config.trailblazer.enable_tracing = true` to enable tracing when using `run` (default FALSE)
35
-
36
- ## License
37
-
38
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
39
-
1
+ # Trailblazer::Rails
2
+
3
+ *Trailblazer in your Rails controllers.*
4
+
5
+ [![Gitter Chat](https://badges.gitter.im/trailblazer/chat.svg)](https://gitter.im/trailblazer/chat)
6
+ [![TRB Newsletter](https://img.shields.io/badge/TRB-newsletter-lightgrey.svg)](http://trailblazer.to/newsletter/)
7
+ [![Build
8
+ Status](https://travis-ci.org/trailblazer/trailblazer-rails.svg)](https://travis-ci.org/trailblazer/trailblazer-rails)
9
+ [![Gem Version](https://badge.fury.io/rb/trailblazer-rails.svg)](http://badge.fury.io/rb/trailblazer-rails)
10
+
11
+ ## Overview
12
+
13
+ `trailblazer-rails` helps you with the following.
14
+
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.
18
+
19
+ Please refer to the [full documentation for more](http://trailblazer.to/gems/trailblazer/2.0/rails.html).
20
+
21
+ ## Installation
22
+
23
+ Add this line to your application's Gemfile:
24
+
25
+ ```ruby
26
+ gem 'trailblazer-rails'
27
+ ```
28
+
29
+ Note that the 2.x version only runs with TRB >= 2.1.0.
30
+
31
+ ## Setting flags
32
+
33
+ * `config.trailblazer.use_loader = false` to disable Trailblazer loader (default TRUE)
34
+ * `config.trailblazer.enable_tracing = true` to enable tracing when using `run` (default FALSE)
35
+
36
+ ## License
37
+
38
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
39
+
@@ -1,21 +1,21 @@
1
- module Trailblazer::Rails::Controller::Cell
2
- private
3
-
4
- module Render
5
- def render(cell = nil, options = {}, *, &block)
6
- return super unless cell.kind_of?(::Cell::ViewModel)
7
- render_cell(cell, options)
8
- end
9
-
10
- def render_cell(cell, options)
11
- options = options.reverse_merge(layout: true)
12
-
13
- # render the cell.
14
- content = cell.()
15
-
16
- render({ html: content }.merge(options))
17
- end
18
- end
19
-
20
- include Render
21
- end
1
+ module Trailblazer::Rails::Controller::Cell
2
+ private
3
+
4
+ module Render
5
+ def render(cell = nil, options = {}, *, &block)
6
+ return super unless cell.kind_of?(::Cell::ViewModel)
7
+ render_cell(cell, options)
8
+ end
9
+
10
+ def render_cell(cell, options)
11
+ options = options.reverse_merge(layout: true)
12
+
13
+ # render the cell.
14
+ content = cell.()
15
+
16
+ render({ html: content }.merge(options))
17
+ end
18
+ end
19
+
20
+ include Render
21
+ end
@@ -1,55 +1,55 @@
1
- module Trailblazer::Rails
2
- module Controller
3
- def run(operation, *dependencies)
4
- result = if Rails.application.config.trailblazer.enable_tracing
5
- _run_operation(operation, :trace, *dependencies).tap { |r| _operation_trace(r) }
6
- else
7
- _run_operation(operation, :call, *dependencies)
8
- end
9
-
10
- @model = result[:model]
11
- @form = Trailblazer::Rails::Form.new(result["contract.default"], @model.class)
12
-
13
- yield(result) if result.success? && block_given?
14
-
15
- @_result = result
16
- end
17
-
18
- private
19
- # Override to tweak params. Not recommended.
20
- # Use a deserializer instead.
21
- def _run_params(params)
22
- params
23
- end
24
-
25
- # This is where we can inject Dry.RB containers and the like via dependencies.
26
- def _run_runtime_options(ctx = {}, *dependencies)
27
- [_run_options(ctx), *dependencies]
28
- end
29
-
30
- # Override this to inject dependencies such as "current_user"
31
- # into the runtime options.
32
- def _run_options(ctx)
33
- ctx
34
- end
35
-
36
- def _run_operation(operation, call_method, *dependencies)
37
- operation.send(
38
- call_method,
39
- { params: _run_params(self.params) }.merge(*_run_runtime_options(*dependencies))
40
- )
41
- end
42
-
43
- def _operation_trace(result)
44
- puts result.wtf?
45
- end
46
-
47
- module Result
48
- def result
49
- @_result
50
- end
51
- end
52
-
53
- include Result
54
- end
55
- end
1
+ module Trailblazer::Rails
2
+ module Controller
3
+ def run(operation, *dependencies)
4
+ result = if Rails.application.config.trailblazer.enable_tracing
5
+ _run_operation(operation, :trace, *dependencies).tap { |r| _operation_trace(r) }
6
+ else
7
+ _run_operation(operation, :call, *dependencies)
8
+ end
9
+
10
+ @model = result[:model]
11
+ @form = Trailblazer::Rails::Form.new(result["contract.default"], @model.class)
12
+
13
+ yield(result) if result.success? && block_given?
14
+
15
+ @_result = result
16
+ end
17
+
18
+ private
19
+ # Override to tweak params. Not recommended.
20
+ # Use a deserializer instead.
21
+ def _run_params(params)
22
+ params
23
+ end
24
+
25
+ # This is where we can inject Dry.RB containers and the like via dependencies.
26
+ def _run_runtime_options(ctx = {}, *dependencies)
27
+ [_run_options(ctx), *dependencies]
28
+ end
29
+
30
+ # Override this to inject dependencies such as "current_user"
31
+ # into the runtime options.
32
+ def _run_options(ctx)
33
+ ctx
34
+ end
35
+
36
+ def _run_operation(operation, call_method, *dependencies)
37
+ operation.send(
38
+ call_method,
39
+ { params: _run_params(self.params) }.merge(*_run_runtime_options(*dependencies))
40
+ )
41
+ end
42
+
43
+ def _operation_trace(result)
44
+ puts result.wtf?
45
+ end
46
+
47
+ module Result
48
+ def result
49
+ @_result
50
+ end
51
+ end
52
+
53
+ include Result
54
+ end
55
+ end