Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use module#prepend when available. #813

Merged
merged 1 commit into from
Mar 18, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions lib/wicked_pdf/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,16 @@
class WickedPdf
if defined?(Rails.env)

if Rails::VERSION::MAJOR >= 5
if Rails::VERSION::MAJOR >= 4
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only difference between the Rails 4 and 5+ paths was :include vs prepend, so they were consolidated, and feature detection is now being used to determine whether to use :prepend or :include.


class WickedRailtie < Rails::Railtie
initializer 'wicked_pdf.register' do |_app|
ActionController::Base.send :prepend, PdfHelper
ActionView::Base.send :include, WickedPdfHelper::Assets
end
end

elsif Rails::VERSION::MAJOR == 4

class WickedRailtie < Rails::Railtie
initializer 'wicked_pdf.register' do |_app|
ActionController::Base.send :include, PdfHelper
if ActionController::Base.respond_to?(:prepend) &&
Object.method(:new).respond_to?(:super_method)
ActionController::Base.send :prepend, PdfHelper
else
ActionController::Base.send :include, PdfHelper
end
ActionView::Base.send :include, WickedPdfHelper::Assets
end
end
Expand Down