aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller
diff options
context:
space:
mode:
authorYehuda Katz <wycats@gmail.com>2009-03-12 13:19:13 -0600
committerYehuda Katz <wycats@gmail.com>2009-03-12 13:19:13 -0600
commita2637e9f1fba92bc0b8dbf461ce9f4f8ffb4cfaa (patch)
tree21207daf4fd7dd7dc77930b934b900b1d1d6e2f0 /actionpack/lib/action_controller
parent67f9b39bd05678881e200ddeed02b2bce9744ac8 (diff)
downloadrails-a2637e9f1fba92bc0b8dbf461ce9f4f8ffb4cfaa.tar.gz
rails-a2637e9f1fba92bc0b8dbf461ce9f4f8ffb4cfaa.tar.bz2
rails-a2637e9f1fba92bc0b8dbf461ce9f4f8ffb4cfaa.zip
Try to build a new AC::Base on top of AbstractController
Diffstat (limited to 'actionpack/lib/action_controller')
-rw-r--r--actionpack/lib/action_controller/new_base.rb5
-rw-r--r--actionpack/lib/action_controller/new_base/base.rb26
-rw-r--r--actionpack/lib/action_controller/new_base/hide_actions.rb28
-rw-r--r--actionpack/lib/action_controller/new_base/url_for.rb40
4 files changed, 99 insertions, 0 deletions
diff --git a/actionpack/lib/action_controller/new_base.rb b/actionpack/lib/action_controller/new_base.rb
new file mode 100644
index 0000000000..2cef221de3
--- /dev/null
+++ b/actionpack/lib/action_controller/new_base.rb
@@ -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 \ No newline at end of file
diff --git a/actionpack/lib/action_controller/new_base/base.rb b/actionpack/lib/action_controller/new_base/base.rb
new file mode 100644
index 0000000000..ebe7c8dda6
--- /dev/null
+++ b/actionpack/lib/action_controller/new_base/base.rb
@@ -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 \ No newline at end of file
diff --git a/actionpack/lib/action_controller/new_base/hide_actions.rb b/actionpack/lib/action_controller/new_base/hide_actions.rb
new file mode 100644
index 0000000000..9847d7b086
--- /dev/null
+++ b/actionpack/lib/action_controller/new_base/hide_actions.rb
@@ -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 \ No newline at end of file
diff --git a/actionpack/lib/action_controller/new_base/url_for.rb b/actionpack/lib/action_controller/new_base/url_for.rb
new file mode 100644
index 0000000000..af5b21012b
--- /dev/null
+++ b/actionpack/lib/action_controller/new_base/url_for.rb
@@ -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 \ No newline at end of file