Permalink
Browse files

Try to build a new AC::Base on top of AbstractController

  • Loading branch information...
1 parent 67f9b39 commit a2637e9f1fba92bc0b8dbf461ce9f4f8ffb4cfaa @wycats wycats committed Mar 12, 2009
@@ -0,0 +1,5 @@
+module ActionController
+ autoload :AbstractBase, "action_controller/new_base/base"
+ autoload :HideActions, "action_controller/new_base/hide_actions"
+ autoload :UrlFor, "action_controller/new_base/url_for"
+end
@@ -0,0 +1,26 @@
+module ActionController
+ class AbstractBase < AbstractController::Base
+ attr_internal :request, :response, :params
+
+ def self.controller_name
+ @controller_name ||= controller_path.split("/").last
+ end
+
+ def controller_name() self.class.controller_name end
+
+ def self.controller_path
+ @controller_path ||= self.name.sub(/Controller$/, '').underscore
+ end
+
+ def controller_path() self.class.controller_path end
+
+ def self.action_methods
+ @action_names ||= Set.new(self.public_instance_methods - self::CORE_METHODS)
+ end
+
+ def self.action_names() action_methods end
+
+ def action_methods() self.class.action_names end
+ def action_names() action_methods end
+ end
+end
@@ -0,0 +1,28 @@
+module ActionController
+ module HideActions
+ def self.included(klass)
+ klass.class_eval do
+ extend ClassMethods
+ extlib_inheritable_accessor :hidden_actions
+ self.hidden_actions ||= Set.new
+ end
+ end
+
+ def action_methods() self.class.action_names end
+ def action_names() action_methods end
+
+ module ClassMethods
+ def hide_action(*args)
+ args.each do |arg|
+ self.hidden_actions << arg.to_s
+ end
+ end
+
+ def action_methods
+ @action_names ||= Set.new(super.reject {|name| self.hidden_actions.include?(name.to_s)})
+ end
+
+ def self.action_names() action_methods end
+ end
+ end
+end
@@ -0,0 +1,40 @@
+module ActionController
+ module UrlFor
+ def initialize_current_url
+ @url = UrlRewriter.new(request, params.clone)
+ end
+
+ # Overwrite to implement a number of default options that all url_for-based methods will use. The default options should come in
+ # the form of a hash, just like the one you would use for url_for directly. Example:
+ #
+ # def default_url_options(options)
+ # { :project => @project.active? ? @project.url_name : "unknown" }
+ # end
+ #
+ # As you can infer from the example, this is mostly useful for situations where you want to centralize dynamic decisions about the
+ # urls as they stem from the business domain. Please note that any individual url_for call can always override the defaults set
+ # by this method.
+ def default_url_options(options = nil)
+ end
+
+ def rewrite_options(options) #:nodoc:
+ if defaults = default_url_options(options)
+ defaults.merge(options)
+ else
+ options
+ end
+ end
+
+ def url_for(options = {})
+ options ||= {}
+ case options
+ when String
+ options
+ when Hash
+ @url.rewrite(rewrite_options(options))
+ else
+ polymorphic_url(options)
+ end
+ end
+ end
+end
Oops, something went wrong.

0 comments on commit a2637e9

Please sign in to comment.