trailblazer-rails 1.0.8 → 1.0.9

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
- SHA1:
3
- metadata.gz: 66dbc1fe3c52c21795bc3b3949640b2c1c465b1d
4
- data.tar.gz: 8b51f29ecabbca7d6e042605112cabd3a3ee6b63
2
+ SHA256:
3
+ metadata.gz: 75dc8012bc26b4744c1e9d9bbbac1a9c48bb2dfbb2a2fcc3666cb90dbf5bb98c
4
+ data.tar.gz: 448a1646c41e7b061a75466201fd2dfc39a792952ef57c71d744854bafe7b894
5
5
  SHA512:
6
- metadata.gz: 374f48690b7b07795dec2fc4fd70c27e227065989958d2e38f9f56c6fdbe42bba8256738b4968359d97ed4ea6dab5c603da5c83159ce97c823224ebe0543def3
7
- data.tar.gz: 327ae6147626bf5e3a03f8735487cd34a48235788266c21589a195a1238b920bf1be14dcf13c141ab9a5ff3d54db05bf33deda06c8d212e4a59aa2629ea4d172
6
+ metadata.gz: 4d6b74c528958964c57ec7a01d071f46800ac6788419be2c968901132a3acd7a7baac93df43d86913bca100072b213280761b94c0733deaf414649ced759d827
7
+ data.tar.gz: f2cc72a1e83d51bdb5045fb5cfd4a6fde0b9fb6b7e9312b2eb96bcc3058aa815a475d10958828b5291a8e252d1e3ee9ac30dcb72d49d2ac0aa6d7fb347e55a62
data/.gitignore CHANGED
@@ -1,11 +1,12 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
- test/**/*.log
11
- test/**/db/*.sqlite3
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ test/**/*.log
11
+ test/**/db/*.sqlite3
12
+ test/**/Gemfile.lock
data/.travis.yml CHANGED
@@ -1,10 +1,17 @@
1
- language: ruby
2
- matrix:
3
- include:
4
- - rvm: 2.3.1
5
- env: TEST_SUITE=rails4.2
6
- gemfile: test/rails4.2/Gemfile
7
- # - rvm: 2.1.9
8
- # env: TEST_SUITE=rails3.2
9
- # gemfile: test/rails3.2/Gemfile
10
- script: cd test/$TEST_SUITE && bundle exec rake test
1
+ language: ruby
2
+ matrix:
3
+ include:
4
+ - rvm: 2.3.1
5
+ env: TEST_SUITE=rails4.2
6
+ gemfile: test/rails4.2/Gemfile
7
+ - rvm: 2.4.1
8
+ env: TEST_SUITE=rails5.0
9
+ gemfile: test/rails5.0/Gemfile
10
+ - rvm: 2.4.1
11
+ env: TEST_SUITE=rails5.1
12
+ gemfile: test/rails5.1/Gemfile
13
+ - rvm: 2.5.1
14
+ env: TEST_SUITE=rails5.2
15
+ gemfile: test/rails5.2/Gemfile
16
+
17
+ script: cd test/$TEST_SUITE && bundle install && bundle exec rake test
data/CHANGES.md CHANGED
@@ -1,104 +1,111 @@
1
- # 1.0.8
2
-
3
- * Fixed Circular dependency detected in rails 5.2
4
-
5
- # 1.0.7
6
-
7
- * Fixed typo error in use_loader config flag
8
-
9
- # 1.0.6 (revoked)
10
-
11
- * Introduce use_loader config flag
12
-
13
- # 1.0.5
14
-
15
- * Hook trailblazer application_controller initializer to finisher_hook
16
-
17
- # 1.0.4
18
-
19
- * Make `Railtie::extend_application_controller!` overwriteable via a module.
20
-
21
- # 1.0.3
22
-
23
- * Return the computed application controller constant from `Railtie::extend_application_controller!` to make `compat` code simpler.
24
-
25
- # 1.0.2
26
-
27
- * Allow configuring `ApplicationController` constant via `config.trailblazer.application_controller`.
28
-
29
- # 1.0.1
30
-
31
- * Allow using this gem without `cells,` by loading cells support only when the `cells` gem got detected. Thanks to @promisedlandt.
32
-
33
- # 1.0.0
34
-
35
- * Runs only with >= Trailblazer 2.0.0.
36
- * 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`.
37
- * Added support for explicit `render cell(Artist::Cell::Index, model)`.
38
- * Autoloading got replaced with explicit requires.
39
-
40
- # 0.4.0
41
-
42
- * Better engines support.
43
- * Fix `Responder#errors` by simply removing it and letting `Operation#errors` return the contract errors.
44
-
45
- # 0.3.2
46
-
47
- * Make it work with Rails 3.x, again.
48
-
49
- # 0.3.1
50
-
51
- * Fix loading of `reform-rails`.
52
-
53
- # 0.3.0
54
-
55
- * Require `reform-rails` as a static dependency. This simplifies the user's setup significantly.
56
- * Run the `Railtie` after `reform.form_extensions` and allow reform-rails to do its setup work, then load concepts.
57
-
58
- # 0.2.4
59
-
60
- * Require `trailblazer-loader-0.0.7`.
61
- * Fix sorting, model files are now always required first.
62
- * Manually include `Operation::Controller` in `ApplicationController` for every reload.
63
-
64
- # 0.2.3
65
-
66
- * Bump to `trailblazer-loader` 0.0.4.
67
-
68
- # 0.2.2
69
-
70
- * Remove cells loading code, this happens via trailblazer-loader now.
71
- * We now load the concept's model file if it exists.
72
-
73
- # 0.2.1
74
-
75
- * Require `trailblazer-loader`.
76
-
77
- # 0.2.0
78
-
79
- * Use `trailblazer-loader` for loading operations and associated files, now. Note that `operations.rb` now is `operation.rb` (hence the minor bump).
80
- * The `Operation::Controller` module is not included into `ApplicationController` automatically.
81
- * Added `Trailblazer::Test::Integration`.
82
-
83
- # 0.1.6
84
-
85
- * Fix `Controller#run`, which now returns the operation instance instead of the `Else` object.
86
-
87
- # 0.1.5
88
-
89
- * 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.
90
- * 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.
91
-
92
- # 0.1.4
93
-
94
- * Treat `:js` requests as non-document, too.
95
- * `Controller#form` now returns the form object and not the operation.
96
- * 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: {..}`.
97
-
98
- # 0.1.3
99
-
100
- * `Operation::contract` works properly with `Operation::ActiveModel` mixed in.
101
-
102
- # 0.1.2
103
-
104
- * First version running with Trailblazer 1.0.0.
1
+ # 1.0.9
2
+
3
+ * `Trailblazer::Rails::Railtie` divided in 2 modules:
4
+ * `Loader` -> require_dependecy `concepts`
5
+ * `ExtendApplicationController` -> include `run` and `render` in controllers
6
+ * Remove Gemfile.lock in the test folders to make travis CI to work
7
+
8
+ # 1.0.8
9
+
10
+ * Fixed Circular dependency detected in rails 5.2
11
+
12
+ # 1.0.7
13
+
14
+ * Fixed typo error in use_loader config flag
15
+
16
+ # 1.0.6 (revoked)
17
+
18
+ * Introduce use_loader config flag
19
+
20
+ # 1.0.5
21
+
22
+ * Hook trailblazer application_controller initializer to finisher_hook
23
+
24
+ # 1.0.4
25
+
26
+ * Make `Railtie::extend_application_controller!` overwriteable via a module.
27
+
28
+ # 1.0.3
29
+
30
+ * Return the computed application controller constant from `Railtie::extend_application_controller!` to make `compat` code simpler.
31
+
32
+ # 1.0.2
33
+
34
+ * Allow configuring `ApplicationController` constant via `config.trailblazer.application_controller`.
35
+
36
+ # 1.0.1
37
+
38
+ * Allow using this gem without `cells,` by loading cells support only when the `cells` gem got detected. Thanks to @promisedlandt.
39
+
40
+ # 1.0.0
41
+
42
+ * Runs only with >= Trailblazer 2.0.0.
43
+ * 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`.
44
+ * Added support for explicit `render cell(Artist::Cell::Index, model)`.
45
+ * Autoloading got replaced with explicit requires.
46
+
47
+ # 0.4.0
48
+
49
+ * Better engines support.
50
+ * Fix `Responder#errors` by simply removing it and letting `Operation#errors` return the contract errors.
51
+
52
+ # 0.3.2
53
+
54
+ * Make it work with Rails 3.x, again.
55
+
56
+ # 0.3.1
57
+
58
+ * Fix loading of `reform-rails`.
59
+
60
+ # 0.3.0
61
+
62
+ * Require `reform-rails` as a static dependency. This simplifies the user's setup significantly.
63
+ * Run the `Railtie` after `reform.form_extensions` and allow reform-rails to do its setup work, then load concepts.
64
+
65
+ # 0.2.4
66
+
67
+ * Require `trailblazer-loader-0.0.7`.
68
+ * Fix sorting, model files are now always required first.
69
+ * Manually include `Operation::Controller` in `ApplicationController` for every reload.
70
+
71
+ # 0.2.3
72
+
73
+ * Bump to `trailblazer-loader` 0.0.4.
74
+
75
+ # 0.2.2
76
+
77
+ * Remove cells loading code, this happens via trailblazer-loader now.
78
+ * We now load the concept's model file if it exists.
79
+
80
+ # 0.2.1
81
+
82
+ * Require `trailblazer-loader`.
83
+
84
+ # 0.2.0
85
+
86
+ * Use `trailblazer-loader` for loading operations and associated files, now. Note that `operations.rb` now is `operation.rb` (hence the minor bump).
87
+ * The `Operation::Controller` module is not included into `ApplicationController` automatically.
88
+ * Added `Trailblazer::Test::Integration`.
89
+
90
+ # 0.1.6
91
+
92
+ * Fix `Controller#run`, which now returns the operation instance instead of the `Else` object.
93
+
94
+ # 0.1.5
95
+
96
+ * 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.
97
+ * 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.
98
+
99
+ # 0.1.4
100
+
101
+ * Treat `:js` requests as non-document, too.
102
+ * `Controller#form` now returns the form object and not the operation.
103
+ * 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: {..}`.
104
+
105
+ # 0.1.3
106
+
107
+ * `Operation::contract` works properly with `Operation::ActiveModel` mixed in.
108
+
109
+ # 0.1.2
110
+
111
+ * 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 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 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,34 +1,34 @@
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/cells)
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 1.x version only runs with TRB >= 2.0.0.
30
-
31
- ## License
32
-
33
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
34
-
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/cells)
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 1.x version only runs with TRB >= 2.0.0.
30
+
31
+ ## License
32
+
33
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
34
+
@@ -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,43 +1,43 @@
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 Result
36
- def result
37
- @_result
38
- end
39
- end
40
-
41
- include Result
42
- end
43
- end
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 Result
36
+ def result
37
+ @_result
38
+ end
39
+ end
40
+
41
+ include Result
42
+ end
43
+ end
@@ -1,90 +1,29 @@
1
- require "rails/railtie"
2
- require "trailblazer/loader"
3
-
4
- module Trailblazer
5
- class Railtie < ::Rails::Railtie
6
- config.trailblazer = ActiveSupport::OrderedOptions.new
7
- ## Accept also an Array of controllers
8
- config.trailblazer.application_controller ||= 'ActionController::Base'
9
- config.trailblazer.use_loader ||= true
10
-
11
- def self.load_concepts(app)
12
- # Loader.new.(insert: [ModelFile, before: Loader::AddConceptFiles]) { |file| require_dependency("#{app.root}/#{file}") }
13
- load_for(app)
14
-
15
- engines.each { |engine| load_for(engine) }
16
- end
17
-
18
- def self.engines
19
- if Gem::Version.new(::Rails.version) >= Gem::Version.new("4.1")
20
- ::Rails.application.railties.find_all { |tie| tie.is_a?(::Rails::Engine) }
21
- else
22
- ::Rails.application.railties.engines
23
- end
24
- end
25
-
26
- def self.load_for(app)
27
- Loader.new.(prepend: AllModelFiles, root: app.root) { |file| require_dependency(file) }
28
- end
29
-
30
- # This is to autoload Operation::Dispatch, etc. I'm simply assuming people find this helpful in Rails.
31
- initializer "trailblazer.library_autoloading" do
32
- end
33
-
34
- # thank you, http://stackoverflow.com/a/17573888/465070
35
- initializer 'trailblazer.install', after: "reform.form_extensions" do |app|
36
- # the trb autoloading has to be run after initializers have been loaded, so we can tweak inclusion of features in
37
- # initializers.
38
- if config.trailblazer.use_loader
39
- reloader_class.to_prepare do
40
- Trailblazer::Railtie.load_concepts(app)
41
- end
42
- end
43
- end
44
-
45
- initializer "trailblazer.application_controller", before: "finisher_hook" do |app|
46
- reloader_class.to_prepare do
47
- ActiveSupport.on_load(:action_controller) do |app|
48
- Trailblazer::Railtie.extend_application_controller!(app)
49
- end
50
- end
51
- end
52
-
53
- # Prepend model file, before the concept files like operation.rb get loaded.
54
- ModelFile = ->(input, options) do
55
- model = "app/models/#{options[:name]}.rb"
56
- File.exist?(model) ? [model]+input : input
57
- end
58
-
59
- # Load all model files before any TRB files.
60
- AllModelFiles = ->(input, options) do
61
- Dir.glob("#{options[:root]}/app/models/**/*.rb").sort + input
62
- end
63
-
64
- private
65
-
66
- def reloader_class
67
- # Rails 5.0.0.rc1 says:
68
- # DEPRECATION WARNING: to_prepare is deprecated and will be removed from Rails 5.1
69
- # (use ActiveSupport::Reloader.to_prepare instead)
70
- if Gem.loaded_specs['activesupport'].version >= Gem::Version.new('5')
71
- ActiveSupport::Reloader
72
- else
73
- ActionDispatch::Reloader
74
- end
75
- end
76
-
77
- module ExtendApplicationController
78
- def extend_application_controller!(app)
79
- controllers = Array(::Rails.application.config.trailblazer.application_controller).map{ |x| x.to_s }
80
- if controllers.include? app.to_s
81
- app.send :include, Trailblazer::Rails::Controller
82
- app.send :include, Trailblazer::Rails::Controller::Cell if defined?(::Cell)
83
- end
84
- app
85
- end
86
- end
87
-
88
- extend ExtendApplicationController
89
- end
90
- end
1
+ require "rails/railtie"
2
+ require "trailblazer/loader"
3
+ require "trailblazer/rails/railtie/loader"
4
+ require "trailblazer/rails/railtie/extend_application_controller"
5
+
6
+ module Trailblazer
7
+ class Railtie < ::Rails::Railtie
8
+ config.trailblazer = ActiveSupport::OrderedOptions.new
9
+ ## Accept also an Array of controllers
10
+ config.trailblazer.application_controller ||= 'ActionController::Base'
11
+ config.trailblazer.use_loader ||= true
12
+
13
+ include Loader
14
+ include ExtendApplicationController
15
+
16
+ private
17
+
18
+ def reloader_class
19
+ # Rails 5.0.0.rc1 says:
20
+ # DEPRECATION WARNING: to_prepare is deprecated and will be removed from Rails 5.1
21
+ # (use ActiveSupport::Reloader.to_prepare instead)
22
+ if Gem.loaded_specs['activesupport'].version >= Gem::Version.new('5')
23
+ ActiveSupport::Reloader
24
+ else
25
+ ActionDispatch::Reloader
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,28 @@
1
+ require 'active_support/concern'
2
+
3
+ module Trailblazer
4
+ class Railtie < ::Rails::Railtie
5
+ module ExtendApplicationController
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ initializer "trailblazer.application_controller", before: "finisher_hook" do |app|
10
+ reloader_class.to_prepare do
11
+ ActiveSupport.on_load(:action_controller) do |app|
12
+ Trailblazer::Railtie.extend_application_controller!(app)
13
+ end
14
+ end
15
+ end
16
+
17
+ def extend_application_controller!(app)
18
+ controllers = Array(::Rails.application.config.trailblazer.application_controller).map{ |x| x.to_s }
19
+ if controllers.include? app.to_s
20
+ app.send :include, Trailblazer::Rails::Controller
21
+ app.send :include, Trailblazer::Rails::Controller::Cell if defined?(::Cell)
22
+ end
23
+ app
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,56 @@
1
+ require 'active_support/concern'
2
+
3
+ module Trailblazer
4
+ class Railtie < ::Rails::Railtie
5
+ module Loader
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ def self.load_concepts(app)
10
+ # Loader.new.(insert: [ModelFile, before: Loader::AddConceptFiles]) { |file| require_dependency("#{app.root}/#{file}") }
11
+ load_for(app)
12
+
13
+ engines.each { |engine| load_for(engine) }
14
+ end
15
+
16
+ def self.engines
17
+ if Gem::Version.new(::Rails.version) >= Gem::Version.new("4.1")
18
+ ::Rails.application.railties.find_all { |tie| tie.is_a?(::Rails::Engine) }
19
+ else
20
+ ::Rails.application.railties.engines
21
+ end
22
+ end
23
+
24
+ def self.load_for(app)
25
+ Trailblazer::Loader.new.(prepend: AllModelFiles, root: app.root) { |file| require_dependency(file) }
26
+ end
27
+
28
+ # Prepend model file, before the concept files like operation.rb get loaded.
29
+ ModelFile = ->(input, options) do
30
+ model = "app/models/#{options[:name]}.rb"
31
+ File.exist?(model) ? [model]+input : input
32
+ end
33
+
34
+ # Load all model files before any TRB files.
35
+ AllModelFiles = ->(input, options) do
36
+ Dir.glob("#{options[:root]}/app/models/**/*.rb").sort + input
37
+ end
38
+
39
+ # This is to autoload Operation::Dispatch, etc. I'm simply assuming people find this helpful in Rails.
40
+ initializer "trailblazer.library_autoloading" do
41
+ end
42
+
43
+ # thank you, http://stackoverflow.com/a/17573888/465070
44
+ initializer 'trailblazer.install', after: "reform.form_extensions" do |app|
45
+ # the trb autoloading has to be run after initializers have been loaded, so we can tweak inclusion of features in
46
+ # initializers.
47
+ if config.trailblazer.use_loader
48
+ reloader_class.to_prepare do
49
+ Trailblazer::Railtie.load_concepts(app)
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -1,6 +1,6 @@
1
- require "minitest/rails/capybara" # loads Capybara, etc.
2
-
3
- module Trailblazer::Test
4
- class Integration < Capybara::Rails::TestCase
5
- end
1
+ require "minitest/rails/capybara" # loads Capybara, etc.
2
+
3
+ module Trailblazer::Test
4
+ class Integration < Capybara::Rails::TestCase
5
+ end
6
6
  end
@@ -1,5 +1,5 @@
1
- module Trailblazer
2
- module Rails
3
- VERSION = "1.0.8"
4
- end
5
- end
1
+ module Trailblazer
2
+ module Rails
3
+ VERSION = "1.0.9"
4
+ end
5
+ end
Binary file
@@ -1,31 +1,31 @@
1
- lib = File.expand_path('../lib', __FILE__)
2
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require 'trailblazer/rails/version'
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = "trailblazer-rails"
7
- spec.version = Trailblazer::Rails::VERSION
8
- spec.authors = ["Nick Sutterer"]
9
- spec.email = ["apotonick@gmail.com"]
10
-
11
- spec.summary = %q{Convenient Rails support for Trailblazer.}
12
- spec.homepage = "http://trailblazer.to/gems/trailblazer/2.0/rails.html"
13
- spec.license = "MIT"
14
-
15
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
17
- spec.require_paths = ["lib"]
18
-
19
- spec.add_dependency "trailblazer", "~> 2.0.0"
20
- spec.add_dependency "trailblazer-loader", ">= 0.1.0"
21
- spec.add_dependency "reform-rails", ">= 0.1.4", "< 0.2.0"
22
-
23
- spec.add_development_dependency "bundler", "~> 1.10"
24
- spec.add_development_dependency "rake", "~> 10.0"
25
- spec.add_development_dependency "minitest"
26
- spec.add_development_dependency "actionpack", '>= 3.0.0' # Rails is optional.
27
- spec.add_development_dependency "sqlite3"
28
- # spec.add_development_dependency "responders"
29
-
30
- spec.add_development_dependency "multi_json"
31
- end
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'trailblazer/rails/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "trailblazer-rails"
7
+ spec.version = Trailblazer::Rails::VERSION
8
+ spec.authors = ["Nick Sutterer"]
9
+ spec.email = ["apotonick@gmail.com"]
10
+
11
+ spec.summary = %q{Convenient Rails support for Trailblazer.}
12
+ spec.homepage = "http://trailblazer.to/gems/trailblazer/2.0/rails.html"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_dependency "trailblazer", "~> 2.0.0"
20
+ spec.add_dependency "trailblazer-loader", ">= 0.1.0"
21
+ spec.add_dependency "reform-rails", ">= 0.1.4", "< 0.2.0"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.10"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "minitest"
26
+ spec.add_development_dependency "actionpack", '>= 3.0.0' # Rails is optional.
27
+ spec.add_development_dependency "sqlite3"
28
+ # spec.add_development_dependency "responders"
29
+
30
+ spec.add_development_dependency "multi_json"
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: 1.0.8
4
+ version: 1.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sutterer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-16 00:00:00.000000000 Z
11
+ date: 2018-06-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: trailblazer
@@ -163,8 +163,11 @@ files:
163
163
  - lib/trailblazer/rails/controller.rb
164
164
  - lib/trailblazer/rails/form.rb
165
165
  - lib/trailblazer/rails/railtie.rb
166
+ - lib/trailblazer/rails/railtie/extend_application_controller.rb
167
+ - lib/trailblazer/rails/railtie/loader.rb
166
168
  - lib/trailblazer/rails/test/integration.rb
167
169
  - lib/trailblazer/rails/version.rb
170
+ - trailblazer-rails-2.1.4.gem
168
171
  - trailblazer-rails.gemspec
169
172
  homepage: http://trailblazer.to/gems/trailblazer/2.0/rails.html
170
173
  licenses:
@@ -186,7 +189,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
186
189
  version: '0'
187
190
  requirements: []
188
191
  rubyforge_project:
189
- rubygems_version: 2.6.14
192
+ rubygems_version: 2.7.3
190
193
  signing_key:
191
194
  specification_version: 4
192
195
  summary: Convenient Rails support for Trailblazer.