trailblazer-rails 1.0.11 → 2.0.0

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
- SHA256:
3
- metadata.gz: 6083dd3a2a300df874af17e718c2111bea4f1c6bd01b875e43682a72ac6e464e
4
- data.tar.gz: b21728f595c427bbc915a7bd8750329aeb1422d520b18ad0b68d3eef5dc36356
2
+ SHA1:
3
+ metadata.gz: 7bf10b78c1fcf973a62ffa500b0008dfe73f1cc2
4
+ data.tar.gz: f729f62ecac32f615119f651109a2e6de4cf0bc0
5
5
  SHA512:
6
- metadata.gz: 783a271a63667912a00f31df9bc7eb6f423e5a1e282219d2c27abb6d3ff3a622d6f04b41cca7b3a3fb26dedc07ea5b8844d9efdb1e9b54c6ed8ed105dd33b825
7
- data.tar.gz: 501bc8046e61c384ad38a6590df27a9f876d2e9d066bfe5e02e66c6ca2349984c83d03ba782640a0bc806b23fba893d32511ad1e2f6a0593e3c1cc47c9bd0321
6
+ metadata.gz: a467dce46aa9e21f6824ba09db844ad0363bfa0f47dbd31e2988275401b5d5f763f2c05be5d8cc8a79bdd693d9579a64833b9ff2b9deb14010dde882c86c80e3
7
+ data.tar.gz: 0ee7f00cce0d332f93166e4613c6cfa869b3f10b2837fe7ee6d8eb1be09255d468c68da2dfcf71379c3ac1f93d2a49474c8f2ea6f3226e0302334caa413bb663
data/.gitignore CHANGED
@@ -8,5 +8,4 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  test/**/*.log
11
- test/**/db/*.sqlite3
12
- test/**/Gemfile.lock
11
+ *.iml
@@ -0,0 +1 @@
1
+ 2.4.1
@@ -1,12 +1,6 @@
1
- sudo: false
2
1
  language: ruby
3
- cache: bundler
4
2
  matrix:
5
3
  include:
6
- - rvm: 2.4.1
7
- env: TEST_SUITE=rails4.2
8
- gemfile: test/rails4.2/Gemfile
9
-
10
4
  - rvm: 2.4.1
11
5
  env: TEST_SUITE=rails5.0
12
6
  gemfile: test/rails5.0/Gemfile
@@ -15,8 +9,4 @@ matrix:
15
9
  env: TEST_SUITE=rails5.1
16
10
  gemfile: test/rails5.1/Gemfile
17
11
 
18
- - rvm: 2.5.1
19
- env: TEST_SUITE=rails5.2
20
- gemfile: test/rails5.2/Gemfile
21
-
22
- script: cd test/$TEST_SUITE && bundle install && bundle exec rake test
12
+ script: cd test/$TEST_SUITE && bundle exec rake test
data/CHANGES.md CHANGED
@@ -1,30 +1,7 @@
1
- # 1.0.11
1
+ # 2.0.0
2
2
 
3
- * Bug: Deprecation warning for use_loader always called (fixed)
4
-
5
- # 1.0.10
6
-
7
- * Reintroduced railtie dependency 4.x +
8
- * Config flag use_loader renamed with enable_loader
9
-
10
- # 1.0.9
11
-
12
- * `Trailblazer::Rails::Railtie` divided in 2 modules:
13
- * `Loader` -> require_dependecy `concepts`
14
- * `ExtendApplicationController` -> include `run` and `render` in controllers
15
- * Remove Gemfile.lock in the test folders to make travis CI to work
16
-
17
- # 1.0.8
18
-
19
- * Fixed Circular dependency detected in rails 5.2
20
-
21
- # 1.0.7
22
-
23
- * Fixed typo error in use_loader config flag
24
-
25
- # 1.0.6 (revoked)
26
-
27
- * Introduce use_loader config flag
3
+ * Support Trailblazer 2.1.0+
4
+ * Drop support for older version of Trailblazer
28
5
 
29
6
  # 1.0.5
30
7
 
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015 Nick Sutterer
3
+ Copyright (c) 2015-2018 Nick Sutterer
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
  [![TRB Newsletter](https://img.shields.io/badge/TRB-newsletter-lightgrey.svg)](http://trailblazer.to/newsletter/)
7
7
  [![Build
8
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)
9
+ [![Gem Version](https://badge.fury.io/rb/trailblazer-rails.svg)](http://badge.fury.io/rb/trailblazer-rails)
10
10
 
11
11
  ## Overview
12
12
 
@@ -26,7 +26,7 @@ Add this line to your application's Gemfile:
26
26
  gem 'trailblazer-rails'
27
27
  ```
28
28
 
29
- Note that the 1.x version only runs with TRB >= 2.0.0.
29
+ Note that the 2.x version only runs with TRB >= 2.1.0.
30
30
 
31
31
  ## License
32
32
 
data/Rakefile CHANGED
@@ -7,4 +7,4 @@ Rake::TestTask.new(:test) do |t|
7
7
  t.test_files = FileList['test/**/*_test.rb']
8
8
  end
9
9
 
10
- task default: :test
10
+ task :default => :test
@@ -1,10 +1,9 @@
1
1
  module Trailblazer::Rails::Controller::Cell
2
- private # rubocop:disable Lint/UselessAccessModifier
2
+ private
3
3
 
4
4
  module Render
5
- def render(cell = nil, options = {}, *, &block)
6
- return super unless cell.kind_of?(::Cell::ViewModel) # rubocop:disable Style/ClassCheck
7
-
5
+ def render(cell=nil, options={}, *, &block)
6
+ return super unless cell.kind_of?(::Cell::ViewModel)
8
7
  render_cell(cell, options)
9
8
  end
10
9
 
@@ -14,7 +13,7 @@ module Trailblazer::Rails::Controller::Cell
14
13
  # render the cell.
15
14
  content = cell.()
16
15
 
17
- render({html: content}.merge(options))
16
+ render( { html: content }.merge(options) )
18
17
  end
19
18
  end
20
19
 
@@ -1,20 +1,17 @@
1
1
  module Trailblazer::Rails
2
2
  module Controller
3
- def run(operation, params = self.params, *dependencies)
4
- result = operation.(
5
- _run_params(params),
6
- *_run_runtime_options(*dependencies)
7
- )
3
+ def run(operation, params=self.params, *dependencies)
4
+ result = operation.({params: _run_params(params) }.merge(*_run_runtime_options(*dependencies)))
8
5
 
9
- _assign_trb_ivars(result)
6
+ @model = result[:model]
7
+ @form = Trailblazer::Rails::Form.new( result[ "contract.default" ], @model.class )
10
8
 
11
9
  yield(result) if result.success? && block_given?
12
10
 
13
11
  @_result = result
14
12
  end
15
13
 
16
- private
17
-
14
+ private
18
15
  # Override to tweak params. Not recommended.
19
16
  # Use a deserializer instead.
20
17
  def _run_params(params)
@@ -22,7 +19,7 @@ module Trailblazer::Rails
22
19
  end
23
20
 
24
21
  # This is where we can inject Dry.RB containers and the like via dependencies.
25
- def _run_runtime_options(options = {}, *dependencies)
22
+ def _run_runtime_options(options={}, *dependencies)
26
23
  [_run_options(options), *dependencies]
27
24
  end
28
25
 
@@ -32,15 +29,6 @@ module Trailblazer::Rails
32
29
  options
33
30
  end
34
31
 
35
- def _assign_trb_ivars(result)
36
- @model = result["model"]
37
- @form = _wrap_with_trb_form(result["contract.default"], @model.class)
38
- end
39
-
40
- def _wrap_with_trb_form(form, model)
41
- Trailblazer::Rails::Form.new(form, model)
42
- end
43
-
44
32
  module Result
45
33
  def result
46
34
  @_result
@@ -1,17 +1,65 @@
1
1
  require "rails/railtie"
2
2
  require "trailblazer/loader"
3
- require "trailblazer/rails/railtie/loader"
4
- require "trailblazer/rails/railtie/extend_application_controller"
5
3
 
6
4
  module Trailblazer
7
5
  class Railtie < ::Rails::Railtie
8
6
  config.trailblazer = ActiveSupport::OrderedOptions.new
9
7
  ## Accept also an Array of controllers
10
- config.trailblazer.application_controller ||= "ActionController::Base"
11
- config.trailblazer.enable_loader ||= true
8
+ config.trailblazer.application_controller ||= 'ActionController::Base'
9
+ config.trailblazer.use_loader ||= true
12
10
 
13
- include Loader
14
- include ExtendApplicationController
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") + input
62
+ end
15
63
 
16
64
  private
17
65
 
@@ -19,11 +67,24 @@ module Trailblazer
19
67
  # Rails 5.0.0.rc1 says:
20
68
  # DEPRECATION WARNING: to_prepare is deprecated and will be removed from Rails 5.1
21
69
  # (use ActiveSupport::Reloader.to_prepare instead)
22
- if Gem.loaded_specs["activesupport"].version >= Gem::Version.new("5")
70
+ if Gem.loaded_specs['activesupport'].version >= Gem::Version.new('5')
23
71
  ActiveSupport::Reloader
24
72
  else
25
73
  ActionDispatch::Reloader
26
74
  end
27
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
28
89
  end
29
90
  end
@@ -3,4 +3,4 @@ require "minitest/rails/capybara" # loads Capybara, etc.
3
3
  module Trailblazer::Test
4
4
  class Integration < Capybara::Rails::TestCase
5
5
  end
6
- end
6
+ end
@@ -1,5 +1,5 @@
1
1
  module Trailblazer
2
2
  module Rails
3
- VERSION = "1.0.11".freeze
3
+ VERSION = "2.0.0"
4
4
  end
5
5
  end
@@ -1,4 +1,4 @@
1
- lib = File.expand_path('lib', __dir__)
1
+ lib = File.expand_path('../lib', __FILE__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
  require 'trailblazer/rails/version'
4
4
 
@@ -8,20 +8,20 @@ Gem::Specification.new do |spec|
8
8
  spec.authors = ["Nick Sutterer"]
9
9
  spec.email = ["apotonick@gmail.com"]
10
10
 
11
- spec.summary = "Convenient Rails support for Trailblazer."
11
+ spec.summary = %q{Convenient Rails support for Trailblazer.}
12
12
  spec.homepage = "http://trailblazer.to/gems/trailblazer/2.0/rails.html"
13
13
  spec.license = "MIT"
14
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) }
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
17
  spec.require_paths = ["lib"]
18
18
 
19
- spec.add_dependency "railties", '>= 4.0.0'
20
- spec.add_dependency "trailblazer", "~> 2.0.0"
19
+ spec.add_dependency "trailblazer", ">= 2.1.0.beta1", "< 2.2.0"
21
20
  spec.add_dependency "trailblazer-loader", ">= 0.1.0"
21
+ spec.add_dependency "reform-rails", ">= 0.1.4", "< 0.2.0"
22
22
 
23
23
  spec.add_development_dependency "bundler", "~> 1.10"
24
- spec.add_development_dependency "minitest"
25
24
  spec.add_development_dependency "rake", "~> 10.0"
26
- spec.add_development_dependency "rubocop"
25
+ spec.add_development_dependency "minitest"
26
+
27
27
  end
metadata CHANGED
@@ -1,57 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trailblazer-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.11
4
+ version: 2.0.0
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-11-21 00:00:00.000000000 Z
11
+ date: 2018-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: railties
14
+ name: trailblazer
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 4.0.0
19
+ version: 2.1.0.beta1
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: 2.2.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: 4.0.0
29
+ version: 2.1.0.beta1
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: 2.2.0
27
33
  - !ruby/object:Gem::Dependency
28
- name: trailblazer
34
+ name: trailblazer-loader
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
- - - "~>"
37
+ - - ">="
32
38
  - !ruby/object:Gem::Version
33
- version: 2.0.0
39
+ version: 0.1.0
34
40
  type: :runtime
35
41
  prerelease: false
36
42
  version_requirements: !ruby/object:Gem::Requirement
37
43
  requirements:
38
- - - "~>"
44
+ - - ">="
39
45
  - !ruby/object:Gem::Version
40
- version: 2.0.0
46
+ version: 0.1.0
41
47
  - !ruby/object:Gem::Dependency
42
- name: trailblazer-loader
48
+ name: reform-rails
43
49
  requirement: !ruby/object:Gem::Requirement
44
50
  requirements:
45
51
  - - ">="
46
52
  - !ruby/object:Gem::Version
47
- version: 0.1.0
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
51
60
  requirements:
52
61
  - - ">="
53
62
  - !ruby/object:Gem::Version
54
- version: 0.1.0
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
@@ -66,20 +78,6 @@ dependencies:
66
78
  - - "~>"
67
79
  - !ruby/object:Gem::Version
68
80
  version: '1.10'
69
- - !ruby/object:Gem::Dependency
70
- name: minitest
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
81
  - !ruby/object:Gem::Dependency
84
82
  name: rake
85
83
  requirement: !ruby/object:Gem::Requirement
@@ -95,7 +93,7 @@ dependencies:
95
93
  - !ruby/object:Gem::Version
96
94
  version: '10.0'
97
95
  - !ruby/object:Gem::Dependency
98
- name: rubocop
96
+ name: minitest
99
97
  requirement: !ruby/object:Gem::Requirement
100
98
  requirements:
101
99
  - - ">="
@@ -116,8 +114,7 @@ extensions: []
116
114
  extra_rdoc_files: []
117
115
  files:
118
116
  - ".gitignore"
119
- - ".rubocop-https---raw-githubusercontent-com-trailblazer-meta-master-rubocop-yml"
120
- - ".rubocop.yml"
117
+ - ".ruby-version"
121
118
  - ".travis.yml"
122
119
  - CHANGES.md
123
120
  - Gemfile
@@ -131,8 +128,6 @@ files:
131
128
  - lib/trailblazer/rails/controller.rb
132
129
  - lib/trailblazer/rails/form.rb
133
130
  - lib/trailblazer/rails/railtie.rb
134
- - lib/trailblazer/rails/railtie/extend_application_controller.rb
135
- - lib/trailblazer/rails/railtie/loader.rb
136
131
  - lib/trailblazer/rails/test/integration.rb
137
132
  - lib/trailblazer/rails/version.rb
138
133
  - trailblazer-rails.gemspec
@@ -156,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
151
  version: '0'
157
152
  requirements: []
158
153
  rubyforge_project:
159
- rubygems_version: 2.7.7
154
+ rubygems_version: 2.6.11
160
155
  signing_key:
161
156
  specification_version: 4
162
157
  summary: Convenient Rails support for Trailblazer.
@@ -1,114 +0,0 @@
1
- AllCops:
2
- TargetRubyVersion: 2.5.0
3
- DisplayCopNames: true
4
- Layout/CaseIndentation:
5
- IndentOneStep: true
6
- Layout/FirstArrayElementLineBreak:
7
- Enabled: true
8
- Layout/FirstHashElementLineBreak:
9
- Enabled: true
10
- Layout/FirstMethodArgumentLineBreak:
11
- Enabled: true
12
- Layout/FirstMethodParameterLineBreak:
13
- Enabled: true
14
- Layout/MultilineAssignmentLayout:
15
- Enabled: true
16
- EnforcedStyle: same_line
17
- Layout/SpaceInsideHashLiteralBraces:
18
- EnforcedStyle: no_space
19
- Metrics/LineLength:
20
- Max: 130
21
- Metrics/ParameterLists:
22
- Max: 5
23
- Naming/VariableNumber:
24
- EnforcedStyle: snake_case
25
- Style/AndOr:
26
- EnforcedStyle: conditionals
27
- Style/AutoResourceCleanup:
28
- Enabled: true
29
- Style/CollectionMethods:
30
- Enabled: true
31
- Style/Documentation:
32
- Enabled: false
33
- Style/EmptyLiteral:
34
- Enabled: false
35
- Style/EmptyMethod:
36
- EnforcedStyle: expanded
37
- Style/FormatStringToken:
38
- EnforcedStyle: template
39
- Style/ImplicitRuntimeError:
40
- Enabled: true
41
- Style/MethodCalledOnDoEndBlock:
42
- Enabled: true
43
- Style/MethodDefParentheses:
44
- EnforcedStyle: require_parentheses
45
- Style/MissingElse:
46
- Enabled: true
47
- EnforcedStyle: case
48
- Style/NumericLiterals:
49
- Enabled: false
50
- Style/OptionHash:
51
- Enabled: true
52
- Style/PercentLiteralDelimiters:
53
- PreferredDelimiters:
54
- "%w": "[]"
55
- "%W": "[]"
56
- "%i": "[]"
57
- "%I": "[]"
58
- "%r": "()"
59
- Style/ReturnNil:
60
- Enabled: true
61
- Style/SafeNavigation:
62
- Enabled: false
63
- Style/Send:
64
- Enabled: true
65
- Style/SignalException:
66
- EnforcedStyle: semantic
67
- Style/StringLiterals:
68
- EnforcedStyle: double_quotes
69
- Style/StringLiteralsInInterpolation:
70
- EnforcedStyle: double_quotes
71
- Style/StringMethods:
72
- Enabled: true
73
- Style/SymbolArray:
74
- Enabled: true
75
- # this allows in rspec to have expect { } with multiple lines
76
- Style/BlockDelimiters:
77
- EnforcedStyle: braces_for_chaining
78
- Layout/EndOfLine:
79
- Enabled: false
80
- # don't need these checks in test folders
81
- Metrics/ModuleLength:
82
- Exclude:
83
- - "spec/**/*"
84
- - "test/**/*"
85
- Metrics/BlockLength:
86
- Exclude:
87
- - "spec/**/*"
88
- - "test/**/*"
89
- - "*.gemspec" # definitely not in the gemspec
90
- Metrics/MethodLength:
91
- Max: 20
92
- Lint/UnreachableCode:
93
- Description: 'Unreachable code.'
94
- Enabled: false
95
- Lint/Void:
96
- Enabled: false
97
- Layout/AlignHash:
98
- EnforcedLastArgumentHashStyle: ignore_implicit
99
- Metrics/AbcSize:
100
- Max: 25
101
- Style/LambdaCall:
102
- Enabled: false
103
- # This to fix lots of failure in trailblazer-operation tests
104
- Style/Semicolon:
105
- Enabled: false
106
- Naming/UncommunicativeMethodParamName:
107
- Enabled: false
108
- Style/ClassAndModuleChildren:
109
- Enabled: false
110
- Layout/LeadingCommentSpace:
111
- Exclude:
112
- - 'test/docs/**/*'
113
- Layout/AlignHash:
114
- EnforcedHashRocketStyle: table
@@ -1,11 +0,0 @@
1
- inherit_from:
2
- - https://raw.githubusercontent.com/trailblazer/meta/master/rubocop.yml
3
-
4
- Style/ClassAndModuleChildren:
5
- Enabled: false
6
-
7
- Style/StringLiterals:
8
- Enabled: false
9
-
10
- Style/Send:
11
- Enabled: false
@@ -1,28 +0,0 @@
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(&: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,63 +0,0 @@
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 # rubocop:disable Metrics/BlockLength
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.select { |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 = lambda do |input, options|
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 = lambda do |input, options|
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
-
48
- # TODO: remove me in v1.1.0
49
- if config.trailblazer.use_loader.to_s.present?
50
- warn "DEPRECATION WARNING [trailblazer-rails]: please use config.trailblazer.enable_loader" \
51
- " to enable/disable the loader, config.trailblazer.use_loader will be removed from version 1.1.0"
52
- end
53
-
54
- if config.trailblazer.enable_loader || config.trailblazer.use_loader
55
- reloader_class.to_prepare do
56
- Trailblazer::Railtie.load_concepts(app)
57
- end
58
- end
59
- end
60
- end
61
- end
62
- end
63
- end