Permalink
Browse files

Refactor ActionMailer to not use hide_actions

  • Loading branch information...
1 parent 4131a2d commit 79bd92b7833d52b74f50259cf8a21f9b05f3e9e3 @drogus drogus committed Aug 3, 2010
View
1 actionmailer/lib/action_mailer.rb
@@ -26,6 +26,7 @@
require 'abstract_controller'
require 'action_view'
+require 'action_dispatch'
# Common Active Support usage in Action Mailer
require 'active_support/core_ext/class'
View
11 actionmailer/lib/action_mailer/base.rb
@@ -5,7 +5,6 @@
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 @@ class Base < AbstractController::Base
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 @@ class Base < AbstractController::Base
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 @@ def insert_part(container, response, charset) #:nodoc:
container.add_part(part)
end
- class_attribute :default_url_options
- self.default_url_options = {}
-
ActiveSupport.run_load_hooks(:action_mailer, self)
end
end
View
46 actionmailer/lib/action_mailer/hide_actions.rb
@@ -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
-
View
1 actionpack/lib/abstract_controller.rb
@@ -24,4 +24,5 @@ module AbstractController
autoload :Translation
autoload :AssetPaths
autoload :ViewPaths
+ autoload :UrlFor
end
View
28 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
View
15 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 @@ def url_options
:_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
View
7 actionpack/lib/action_dispatch/routing/route_set.rb
@@ -337,7 +337,12 @@ class << self
# 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 }

0 comments on commit 79bd92b

Please sign in to comment.