trailblazer-rails 2.1.4 → 2.1.5

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.
@@ -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,57 @@
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_v21(operation, *dependencies)
4
+ result = if Rails.application.config.trailblazer.enable_tracing
5
+ _run_operation_v21(operation, :trace, *dependencies).tap { |r| _operation_trace(r) }
6
+ else
7
+ _run_operation_v21(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
+ alias run run_v21 unless method_defined?(:run)
19
+
20
+ private
21
+ # Override to tweak params. Not recommended.
22
+ # Use a deserializer instead.
23
+ def _run_params(params)
24
+ params
25
+ end
26
+
27
+ # This is where we can inject Dry.RB containers and the like via dependencies.
28
+ def _run_runtime_options(ctx = {}, *dependencies)
29
+ [_run_options(ctx), *dependencies]
30
+ end
31
+
32
+ # Override this to inject dependencies such as "current_user"
33
+ # into the runtime options.
34
+ def _run_options(ctx)
35
+ ctx
36
+ end
37
+
38
+ def _run_operation_v21(operation, call_method, *dependencies)
39
+ operation.send(
40
+ call_method,
41
+ { params: _run_params(self.params) }.merge(*_run_runtime_options(*dependencies))
42
+ )
43
+ end
44
+
45
+ def _operation_trace(result)
46
+ puts result.wtf?
47
+ end
48
+
49
+ module Result
50
+ def result
51
+ @_result
52
+ end
53
+ end
54
+
55
+ include Result
56
+ end
57
+ end
@@ -1,30 +1,30 @@
1
- require "rails/railtie"
2
- require "trailblazer/loader"
3
- require "trailblazer/rails/railtie/extend_application_controller"
4
- require "trailblazer/rails/railtie/loader"
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
- config.trailblazer.enable_tracing ||= false
13
-
14
- include Loader
15
- include ExtendApplicationController
16
-
17
- private
18
-
19
- def reloader_class
20
- # Rails 5.0.0.rc1 says:
21
- # DEPRECATION WARNING: to_prepare is deprecated and will be removed from Rails 5.1
22
- # (use ActiveSupport::Reloader.to_prepare instead)
23
- if Gem.loaded_specs['activesupport'].version >= Gem::Version.new('5')
24
- ActiveSupport::Reloader
25
- else
26
- ActionDispatch::Reloader
27
- end
28
- end
29
- end
30
- end
1
+ require "rails/railtie"
2
+ require "trailblazer/loader"
3
+ require "trailblazer/rails/railtie/extend_application_controller"
4
+ require "trailblazer/rails/railtie/loader"
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
+ config.trailblazer.enable_tracing ||= false
13
+
14
+ include Loader
15
+ include ExtendApplicationController
16
+
17
+ private
18
+
19
+ def reloader_class
20
+ # Rails 5.0.0.rc1 says:
21
+ # DEPRECATION WARNING: to_prepare is deprecated and will be removed from Rails 5.1
22
+ # (use ActiveSupport::Reloader.to_prepare instead)
23
+ if Gem.loaded_specs['activesupport'].version >= Gem::Version.new('5')
24
+ ActiveSupport::Reloader
25
+ else
26
+ ActionDispatch::Reloader
27
+ end
28
+ end
29
+ end
30
+ end
@@ -1,28 +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
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
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
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
@@ -1,56 +1,51 @@
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
+ 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
+ load_for(app)
11
+
12
+ engines.each { |engine| load_for(engine) }
13
+ end
14
+
15
+ def self.engines
16
+ ::Rails.application.railties.select { |tie| tie.is_a?(::Rails::Engine) }
17
+ end
18
+
19
+ def self.load_for(app)
20
+ Trailblazer::Loader.new.(prepend: AllModelFiles, root: app.root) { |file| require_dependency(file) }
21
+ end
22
+
23
+ # Prepend model file, before the concept files like operation.rb get loaded.
24
+ ModelFile = lambda do |input, options|
25
+ model = "app/models/#{options[:name]}.rb"
26
+ File.exist?(model) ? [model] + input : input
27
+ end
28
+
29
+ # Load all model files before any TRB files.
30
+ AllModelFiles = lambda do |input, options|
31
+ Dir.glob("#{options[:root]}/app/models/**/*.rb").sort + input
32
+ end
33
+
34
+ # This is to autoload Operation::Dispatch, etc. I'm simply assuming people find this helpful in Rails.
35
+ initializer "trailblazer.library_autoloading" do
36
+ end
37
+
38
+ # thank you, http://stackoverflow.com/a/17573888/465070
39
+ initializer 'trailblazer.install', after: "reform.form_extensions" do |app|
40
+ # the trb autoloading has to be run after initializers have been loaded, so we can tweak inclusion of features in
41
+ # initializers.
42
+ if config.trailblazer.use_loader
43
+ reloader_class.to_prepare do
44
+ Trailblazer::Railtie.load_concepts(app)
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ 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
6
- end
1
+ require "minitest/rails/capybara" # loads Capybara, etc.
2
+
3
+ module Trailblazer::Test
4
+ class Integration < Capybara::Rails::TestCase
5
+ end
6
+ end
@@ -1,5 +1,5 @@
1
- module Trailblazer
2
- module Rails
3
- VERSION = "2.1.4"
4
- end
5
- end
1
+ module Trailblazer
2
+ module Rails
3
+ VERSION = "2.1.5"
4
+ end
5
+ end
@@ -1,27 +1,28 @@
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)/}) }
16
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
17
- spec.require_paths = ["lib"]
18
-
19
- spec.add_dependency "trailblazer", ">= 2.1.0.beta1", "< 2.2.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 "rubocop"
27
- 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)/}) }
16
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_dependency "trailblazer", ">= 2.1.0.beta1", "< 2.2.0"
20
+ spec.add_dependency "trailblazer-loader", ">= 0.1.0"
21
+ spec.add_dependency "reform-rails", ">= 0.1.4", "< 0.2.0"
22
+ spec.add_dependency "activesupport", ">= 5.0.0"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.10"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "minitest"
27
+ spec.add_development_dependency "rubocop"
28
+ end