From 79bd92b7833d52b74f50259cf8a21f9b05f3e9e3 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Tue, 3 Aug 2010 19:36:53 +0200 Subject: Refactor ActionMailer to not use hide_actions --- actionmailer/lib/action_mailer.rb | 1 + actionmailer/lib/action_mailer/base.rb | 11 ++---- actionmailer/lib/action_mailer/hide_actions.rb | 46 ---------------------- actionpack/lib/abstract_controller.rb | 1 + actionpack/lib/abstract_controller/url_for.rb | 28 +++++++++++++ actionpack/lib/action_controller/metal/url_for.rb | 15 +------ .../lib/action_dispatch/routing/route_set.rb | 7 +++- 7 files changed, 40 insertions(+), 69 deletions(-) delete mode 100644 actionmailer/lib/action_mailer/hide_actions.rb create mode 100644 actionpack/lib/abstract_controller/url_for.rb diff --git a/actionmailer/lib/action_mailer.rb b/actionmailer/lib/action_mailer.rb index 05ba12197a..706ba74c2d 100644 --- a/actionmailer/lib/action_mailer.rb +++ b/actionmailer/lib/action_mailer.rb @@ -26,6 +26,7 @@ $:.unshift(actionpack_path) if File.directory?(actionpack_path) && !$:.include?( require 'abstract_controller' require 'action_view' +require 'action_dispatch' # Common Active Support usage in Action Mailer require 'active_support/core_ext/class' diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index d1fb446366..f7acb36341 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -5,7 +5,6 @@ require 'active_support/core_ext/array/wrap' require 'active_support/core_ext/object/blank' require 'active_support/core_ext/proc' require 'action_mailer/log_subscriber' -require 'action_mailer/hide_actions' module ActionMailer #:nodoc: # Action Mailer allows you to send email from your application using a mailer model and views. @@ -341,13 +340,13 @@ module ActionMailer #:nodoc: include AbstractController::Helpers include AbstractController::Translation include AbstractController::AssetPaths + include AbstractController::UrlFor cattr_reader :protected_instance_variables @@protected_instance_variables = [] helper ActionMailer::MailHelper include ActionMailer::OldApi - include ActionMailer::HideActions delegate :register_observer, :to => Mail delegate :register_interceptor, :to => Mail @@ -364,9 +363,8 @@ module ActionMailer #:nodoc: class << self def inherited(klass) - klass.with_hiding_actions do - super(klass) - end + super(klass) + klass.class_eval { @action_methods = nil } end def mailer_name @@ -732,9 +730,6 @@ module ActionMailer #:nodoc: container.add_part(part) end - class_attribute :default_url_options - self.default_url_options = {} - ActiveSupport.run_load_hooks(:action_mailer, self) end end diff --git a/actionmailer/lib/action_mailer/hide_actions.rb b/actionmailer/lib/action_mailer/hide_actions.rb deleted file mode 100644 index 876da95c3a..0000000000 --- a/actionmailer/lib/action_mailer/hide_actions.rb +++ /dev/null @@ -1,46 +0,0 @@ -require 'active_support/core_ext/class/attribute' - -module ActionMailer - # ActionController::HideActions adds the ability to prevent public methods on a controller - # to be called as actions. - module HideActions - extend ActiveSupport::Concern - - included do - class_attribute :hidden_actions - self.hidden_actions = Set.new.freeze - end - - private - - module ClassMethods - # Sets all of the actions passed in as hidden actions. - # - # ==== Parameters - # *args<#to_s>:: A list of actions - def hide_action(*args) - self.hidden_actions = hidden_actions.dup.merge(args.map(&:to_s)).freeze - end - - # Run block and add all the new action_methods to hidden_actions. - # This is used in inherited method. - def with_hiding_actions - yield - clear_action_methods! - hide_action(*action_methods) - clear_action_methods! - end - - def clear_action_methods! - @action_methods = nil - end - - # Overrides AbstractController::Base#action_methods to remove any methods - # that are listed as hidden methods. - def action_methods - @action_methods ||= super.reject { |name| hidden_actions.include?(name) } - end - end - end -end - diff --git a/actionpack/lib/abstract_controller.rb b/actionpack/lib/abstract_controller.rb index f8fc79936f..cc5878c88e 100644 --- a/actionpack/lib/abstract_controller.rb +++ b/actionpack/lib/abstract_controller.rb @@ -24,4 +24,5 @@ module AbstractController autoload :Translation autoload :AssetPaths autoload :ViewPaths + autoload :UrlFor end diff --git a/actionpack/lib/abstract_controller/url_for.rb b/actionpack/lib/abstract_controller/url_for.rb new file mode 100644 index 0000000000..2e9de22ecd --- /dev/null +++ b/actionpack/lib/abstract_controller/url_for.rb @@ -0,0 +1,28 @@ +module AbstractController + module UrlFor + extend ActiveSupport::Concern + + include ActionDispatch::Routing::UrlFor + + def _routes + raise "In order to use #url_for, you must include routing helpers explicitly. " \ + "For instance, `include Rails.application.routes.url_helpers" + end + + module ClassMethods + def _routes + nil + end + + def action_methods + @action_methods ||= begin + if _routes + super - _routes.named_routes.helper_names + else + super + end + end + end + end + end +end diff --git a/actionpack/lib/action_controller/metal/url_for.rb b/actionpack/lib/action_controller/metal/url_for.rb index 1e34f21c77..85c6b0a9b5 100644 --- a/actionpack/lib/action_controller/metal/url_for.rb +++ b/actionpack/lib/action_controller/metal/url_for.rb @@ -2,7 +2,7 @@ module ActionController module UrlFor extend ActiveSupport::Concern - include ActionDispatch::Routing::UrlFor + include AbstractController::UrlFor def url_options options = {} @@ -16,18 +16,5 @@ module ActionController :_path_segments => request.symbolized_path_parameters ) end - - def _routes - raise "In order to use #url_for, you must include routing helpers explicitly. " \ - "For instance, `include Rails.application.routes.url_helpers" - end - - module ClassMethods - def action_methods - @action_methods ||= begin - super - _routes.named_routes.helper_names - end - end - end end end diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 6e7e133cc5..219fa37fcb 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -337,7 +337,12 @@ module ActionDispatch # Yes plz - JP included do routes.install_helpers(self) - singleton_class.send(:define_method, :_routes) { @_routes || routes } + singleton_class.send(:define_method, :_routes) { routes } + end + + def initialize(*) + @_routes = nil + super end define_method(:_routes) { @_routes || routes } -- cgit v1.2.3