Permalink
Browse files

Added the default selectors (acceptvers and nonaction)

  • Loading branch information...
1 parent 5cb65c6 commit f6b1122eb7688b8fb5b114adafe490eb41863ecb @casualjim casualjim committed Mar 20, 2009
@@ -8,30 +8,57 @@
namespace System.Web.Mvc.IronRuby.Controllers
{
+ /// <summary>
+ /// The descriptor for a Ruby enabled Controller
+ /// </summary>
public class RubyControllerDescriptor : ControllerDescriptor
{
private readonly IRubyEngine _engine;
private readonly RubyActionMethodSelector _selector;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="RubyControllerDescriptor"/> class.
+ /// </summary>
+ /// <param name="rubyClass">The ruby class.</param>
+ /// <param name="engine">The engine.</param>
public RubyControllerDescriptor(RubyClass rubyClass, IRubyEngine engine)
{
_engine = engine;
RubyControllerClass = rubyClass;
_selector = new RubyActionMethodSelector(engine, rubyClass);
}
+ /// <summary>
+ /// Gets the name of the controller.
+ /// </summary>
+ /// <value>The name of the controller.</value>
public override string ControllerName
{
get { return RubyControllerClass.Name; }
}
+ /// <summary>
+ /// Gets the type of the controller.
+ /// </summary>
+ /// <value>The type of the controller.</value>
public override Type ControllerType
{
get { return typeof (RubyController); }
}
+ /// <summary>
+ /// Gets or sets the class ruby controller.
+ /// </summary>
+ /// <value>The ruby controller class.</value>
public RubyClass RubyControllerClass { get; private set; }
+ /// <summary>
+ /// Finds the action.
+ /// </summary>
+ /// <param name="controllerContext">The controller context.</param>
+ /// <param name="actionName">The name of the action.</param>
+ /// <returns>The information about the action.</returns>
public override ActionDescriptor FindAction(ControllerContext controllerContext, string actionName)
{
controllerContext.EnsureArgumentNotNull("controllerContext");
@@ -41,6 +68,12 @@ public override ActionDescriptor FindAction(ControllerContext controllerContext,
return selectedName.IsNotNullOrBlank() ? new RubyActionDescriptor(selectedName, this, _engine ) : null;
}
+ /// <summary>
+ /// Gets the canonical actions.
+ /// </summary>
+ /// <returns>
+ /// A list of action descriptors for the controller.
+ /// </returns>
public override ActionDescriptor[] GetCanonicalActions()
{
return _selector.GetAllActionMethods().Map(method => new RubyActionDescriptor(method, this, _engine)).ToArray();
@@ -154,7 +154,7 @@ module ClassMethods
def method_selector(name, selector)
key = name.to_s.to_sym
name_selectors[key] ||= []
- name_selectors[key] << selector
+ name_selectors[key] << selector unless selector.nil?
name_selectors[key].uniq!
name_selectors[key]
end
@@ -166,13 +166,18 @@ def alias_action(name, act_name)
name_selector(name, fn)
end
- def name_selector(name, selector=nil, &b)
+ def name_selector(name, selector)
key = name.to_s.to_sym
name_selectors[key] ||= []
- name_selectors[key] << (selector||b)
+ name_selectors[key] << selector if block_given?
name_selectors[key].uniq!
name_selectors[key]
end
+
+ def non_action(name)
+ fn = lambda { |context, action_name| return false }
+ method_selector name, fn
+ end
def name_selectors
@name_selectors ||= {}
@@ -189,8 +194,28 @@ def method_selectors
def self.included(base)
base.extend(ClassMethods)
end
+
+ module AcceptVerbs
+
+ module ClassMethods
+
+ def accept_verbs(name, *verbs)
+ fn = lambda { |context, name|
+ return verbs.include?(context.http_context.request.http_method.to_s.downcase.to_sym)
+ }
+ method_selector(name, fn)
+ end
+
+ end
+
+ def self.included(base)
+ base.extend(ClassMethods)
+ end
+ end
end
+
+
end
#module Controllers
@@ -200,6 +225,7 @@ class Controller < System::Web::Mvc::IronRuby::Controllers::RubyController
include Controllers::Filters
include Controllers::Selectors
+ include Controllers::Selectors::AcceptVerbs
def fill_view_data
instance_variables.each { |varname| view_data.add(varname[1..-1], instance_variable_get(varname.to_sym)) }
@@ -21,6 +21,8 @@ class HomeController < Controller
filter :index, MyFilter
alias_action :my_method, :index_again
+ non_action :my_helper_method
+ accept_verbs :only_post, :post
def index
view(nil, 'layout', HomeModel.new)
@@ -30,6 +32,14 @@ def my_method
view('index', 'layout', HomeModel.new)
end
+ def my_helper_method
+ view('index', 'layout', HomeModel.new)
+ end
+
+ def only_post
+ view('index', 'layout', HomeModel.new)
+ end
+
def raise_error
raise "This is supposed to happen"
end

0 comments on commit f6b1122

Please sign in to comment.