Skip to content

Commit

Permalink
Autoload issue with ImpressionistController (#2)
Browse files Browse the repository at this point in the history
Instead of depending on autoload to bring in the ImpressionistController
constant, we manually bring it with a call to require and just move that file
to lib.

Prior to this, Rails would emit a warning on startup about needing to use
autoload durning an initializer like this, letting us know that a future
version of Rails will error.

This should hopefully remove that error and still allow these controller mixins
to be available.  Note that Rails 7.1 will eventually be a future blocker here.

PS. This is the recommended approach by Xavier here:
charlotte-ruby#305

Co-authored-by: stefannibrasil <[email protected]>
  • Loading branch information
keegnotrub and stefannibrasil authored Oct 16, 2023
1 parent b02be39 commit 59c8f00
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
47 changes: 23 additions & 24 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ Layout/BlockAlignment:
# Cop supports --auto-correct.
Layout/ClosingParenthesisIndentation:
Exclude:
- "app/controllers/impressionist_controller.rb"
- "lib/impressionist/controllers/impressionist_controller.rb"
- "lib/impressionist/controllers/mongoid/impressionist_controller.rb"

# Offense count: 1
# Cop supports --auto-correct.
Layout/CommentIndentation:
Exclude:
- "app/controllers/impressionist_controller.rb"
- "lib/impressionist/controllers/impressionist_controller.rb"

# Offense count: 6
# Cop supports --auto-correct.
Expand Down Expand Up @@ -92,7 +92,7 @@ Layout/EmptyLineBetweenDefs:
Layout/EmptyLines:
Exclude:
- "Rakefile"
- "app/controllers/impressionist_controller.rb"
- "lib/impressionist/controllers/impressionist_controller.rb"
- "lib/impressionist/counter_cache.rb"
- "lib/impressionist/engine.rb"
- "lib/impressionist/models/mongoid/impressionist/impressionable.rb"
Expand Down Expand Up @@ -122,7 +122,7 @@ Layout/EmptyLinesAroundClassBody:
# Cop supports --auto-correct.
Layout/EmptyLinesAroundMethodBody:
Exclude:
- "app/controllers/impressionist_controller.rb"
- "lib/impressionist/controllers/impressionist_controller.rb"
- "lib/impressionist/counter_cache.rb"
- "lib/impressionist/models/mongoid/impressionist/impressionable.rb"
- "upgrade_migrations/version_0_3_0.rb"
Expand Down Expand Up @@ -208,7 +208,7 @@ Layout/IndentationWidth:
# Configuration parameters: AllowDoxygenCommentStyle, AllowGemfileRubyComment.
Layout/LeadingCommentSpace:
Exclude:
- "app/controllers/impressionist_controller.rb"
- "lib/impressionist/controllers/impressionist_controller.rb"
- "lib/impressionist/bots.rb"

# Offense count: 6
Expand All @@ -227,7 +227,7 @@ Layout/MultilineMethodCallIndentation:
# Cop supports --auto-correct.
Layout/SpaceAfterComma:
Exclude:
- "app/controllers/impressionist_controller.rb"
- "lib/impressionist/controllers/impressionist_controller.rb"
- "app/models/impressionist/bots.rb"
- "lib/impressionist/bots.rb"
- "upgrade_migrations/version_0_3_0.rb"
Expand All @@ -238,15 +238,15 @@ Layout/SpaceAfterComma:
# SupportedStylesInsidePipes: space, no_space
Layout/SpaceAroundBlockParameters:
Exclude:
- "app/controllers/impressionist_controller.rb"
- "lib/impressionist/controllers/impressionist_controller.rb"

# Offense count: 13
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: space, no_space
Layout/SpaceAroundEqualsInParameterDefault:
Exclude:
- "app/controllers/impressionist_controller.rb"
- "lib/impressionist/controllers/impressionist_controller.rb"
- "app/models/impressionist/impressionable.rb"
- "lib/impressionist/controllers/mongoid/impressionist_controller.rb"
- "lib/impressionist/counter_cache.rb"
Expand All @@ -260,7 +260,7 @@ Layout/SpaceAroundEqualsInParameterDefault:
# SupportedStylesForExponentOperator: space, no_space
Layout/SpaceAroundOperators:
Exclude:
- "app/controllers/impressionist_controller.rb"
- "lib/impressionist/controllers/impressionist_controller.rb"
- "lib/impressionist/controllers/mongoid/impressionist_controller.rb"
- "lib/impressionist/counter_cache.rb"
- "lib/impressionist/models/mongo_mapper/impression.rb"
Expand All @@ -272,7 +272,7 @@ Layout/SpaceAroundOperators:
# SupportedStylesForEmptyBraces: space, no_space
Layout/SpaceBeforeBlockBraces:
Exclude:
- "app/controllers/impressionist_controller.rb"
- "lib/impressionist/controllers/impressionist_controller.rb"

# Offense count: 3
# Cop supports --auto-correct.
Expand All @@ -281,7 +281,7 @@ Layout/SpaceBeforeBlockBraces:
# SupportedStylesForEmptyBraces: space, no_space
Layout/SpaceInsideBlockBraces:
Exclude:
- "app/controllers/impressionist_controller.rb"
- "lib/impressionist/controllers/impressionist_controller.rb"

# Offense count: 4
# Cop supports --auto-correct.
Expand All @@ -290,7 +290,7 @@ Layout/SpaceInsideBlockBraces:
# SupportedStylesForEmptyBraces: space, no_space
Layout/SpaceInsideHashLiteralBraces:
Exclude:
- "app/controllers/impressionist_controller.rb"
- "lib/impressionist/controllers/impressionist_controller.rb"
- "lib/impressionist/update_counters.rb"

# Offense count: 3
Expand Down Expand Up @@ -319,7 +319,7 @@ Lint/DuplicateMethods:
# Cop supports --auto-correct.
Lint/RedundantStringCoercion:
Exclude:
- "app/controllers/impressionist_controller.rb"
- "lib/impressionist/controllers/impressionist_controller.rb"

# Offense count: 2
# Cop supports --auto-correct.
Expand Down Expand Up @@ -434,7 +434,7 @@ RSpec/RepeatedExample:
# Include: app/controllers/**/*.rb
Rails/ActionFilter:
Exclude:
- "app/controllers/impressionist_controller.rb"
- "lib/impressionist/controllers/impressionist_controller.rb"

# Offense count: 1
# Cop supports --auto-correct.
Expand All @@ -447,7 +447,7 @@ Rails/ApplicationRecord:
# Configuration parameters: NotNilAndNotEmpty, NotBlank, UnlessBlank.
Rails/Present:
Exclude:
- "app/controllers/impressionist_controller.rb"
- "lib/impressionist/controllers/impressionist_controller.rb"

# Offense count: 1
# Configuration parameters: Include.
Expand Down Expand Up @@ -500,7 +500,7 @@ Style/CommentedKeyword:
# SupportedStyles: assign_to_condition, assign_inside_condition
Style/ConditionalAssignment:
Exclude:
- "app/controllers/impressionist_controller.rb"
- "lib/impressionist/controllers/impressionist_controller.rb"

# Offense count: 24
Style/Documentation:
Expand All @@ -510,7 +510,7 @@ Style/Documentation:
# Cop supports --auto-correct.
Style/EachWithObject:
Exclude:
- "app/controllers/impressionist_controller.rb"
- "lib/impressionist/controllers/impressionist_controller.rb"

# Offense count: 1
# Cop supports --auto-correct.
Expand Down Expand Up @@ -544,7 +544,7 @@ Style/FrozenStringLiteralComment:
# Configuration parameters: MinBodyLength.
Style/GuardClause:
Exclude:
- "app/controllers/impressionist_controller.rb"
- "lib/impressionist/controllers/impressionist_controller.rb"

# Offense count: 136
# Cop supports --auto-correct.
Expand All @@ -557,7 +557,7 @@ Style/HashSyntax:
# Cop supports --auto-correct.
Style/IfUnlessModifier:
Exclude:
- "app/controllers/impressionist_controller.rb"
- "lib/impressionist/controllers/impressionist_controller.rb"
- "app/models/impressionist/impressionable.rb"

# Offense count: 1
Expand Down Expand Up @@ -599,20 +599,20 @@ Style/RedundantBegin:
# Configuration parameters: AllowMultipleReturnValues.
Style/RedundantReturn:
Exclude:
- "app/controllers/impressionist_controller.rb"
- "lib/impressionist/controllers/impressionist_controller.rb"

# Offense count: 4
# Cop supports --auto-correct.
Style/RedundantSelf:
Exclude:
- "app/controllers/impressionist_controller.rb"
- "lib/impressionist/controllers/impressionist_controller.rb"
- "lib/impressionist/counter_cache.rb"

# Offense count: 2
# Cop supports --auto-correct.
Style/RescueModifier:
Exclude:
- "app/controllers/impressionist_controller.rb"
- "lib/impressionist/controllers/impressionist_controller.rb"

# Offense count: 1670
# Cop supports --auto-correct.
Expand All @@ -634,7 +634,7 @@ Style/SymbolArray:
# IgnoredMethods: respond_to, define_method
Style/SymbolProc:
Exclude:
- "app/controllers/impressionist_controller.rb"
- "lib/impressionist/controllers/impressionist_controller.rb"

# Offense count: 1
# Cop supports --auto-correct.
Expand All @@ -657,4 +657,3 @@ Style/WordArray:
# URISchemes: http, https
Layout/LineLength:
Max: 197

2 changes: 1 addition & 1 deletion impressionist.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Gem::Specification.new do |s|

s.add_dependency "friendly_id"
s.add_dependency 'nokogiri', RUBY_VERSION < '2.1.0' ? '~> 1.6.0' : '~> 1'
s.add_dependency 'rails', '>= 3.2.15'
s.add_dependency 'rails', '>= 3.2.15', '< 7.1'

s.add_development_dependency 'bundler', '~> 2.0'
s.add_development_dependency 'capybara'
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions lib/impressionist/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Engine < ::Rails::Engine


initializer 'impressionist.controller' do
require "impressionist/controllers/impressionist_controller"
require "impressionist/controllers/mongoid/impressionist_controller" if orm == :mongoid.to_s

ActiveSupport.on_load(:action_controller) do
Expand Down

0 comments on commit 59c8f00

Please sign in to comment.