Permalink
Browse files

Now action aliasing is really working

  • Loading branch information...
casualjim committed Mar 20, 2009
1 parent 38a7edd commit 5cb65c62d4bf0597964d0ddc4e2d8736a855fd2a
@@ -98,7 +98,7 @@ public IEnumerable<string> GetAllActionMethods()
private List<string> GetMatchingAliasedMethods(ControllerContext controllerContext, string actionName)
{
- return new List<string>(AliasedMethods.Where(pair => pair.Key == actionName && pair.Value.IsValidForName(controllerContext, actionName)).Map(pair => pair.Key));
+ return new List<string>(AliasedMethods.Where(pair => pair.Value.IsValidForAction(controllerContext, actionName)).Map(pair => pair.Key));
}
private List<string> RunSelectionFilters(ControllerContext controllerContext, IEnumerable<string> matchingMethods)
@@ -110,12 +110,12 @@ private List<string> RunSelectionFilters(ControllerContext controllerContext, IE
? new List<string>(matchingMethods)
: new List<string>(
matchingMethods.Where(
- methodName => filters.All(filter => filter.Value.IsValidForName(controllerContext, methodName))
+ methodName => filters.All(filter => filter.Value.IsValid(controllerContext, methodName))
)
);
}
}
-
+
public class PredicateList : IEnumerable<Func<ControllerContext, string, bool>>
{
private readonly RubyArray _items;
@@ -139,11 +139,16 @@ private void Add(Proc proc)
_predicates.Add(_rubyEngine.ConvertProcToFunc<bool>(proc));
}
- public bool IsValidForName(ControllerContext context, string name)
+ public bool IsValid(ControllerContext context, string name)
{
return _predicates.All(predicate => predicate(context, name));
}
+ public bool IsValidForAction(ControllerContext context, string name)
+ {
+ return _predicates.Any(predicate => predicate(context, name));
+ }
+
#region Implementation of IEnumerable
/// <summary>
@@ -38,7 +38,7 @@ public override ActionDescriptor FindAction(ControllerContext controllerContext,
actionName.EnsureArgumentNotNull("actionName");
var selectedName = _selector.FindActionMethod(controllerContext, actionName);
- return selectedName.IsNotNullOrBlank() ? new RubyActionDescriptor(actionName, this, _engine ) : null;
+ return selectedName.IsNotNullOrBlank() ? new RubyActionDescriptor(selectedName, this, _engine ) : null;
}
public override ActionDescriptor[] GetCanonicalActions()
@@ -117,7 +117,7 @@ def around_result(name, method_name=nil, options={}, &b)
filter(name, RubyProcResultFilter.new(options[:before], options[:after]))
end
- def filter(name, options=nil)
+ def filter(name, options=nil)
@action_filters ||= {}
klass = nil
klass = name.new if name.is_a? Class
@@ -161,7 +161,7 @@ def method_selector(name, selector)
def alias_action(name, act_name)
fn = Proc.new do |controller_context, action_name|
- !!/#{action_name.to_s}/i.match(act_name.to_s)
+ !!/^#{action_name.to_s}$/i.match(act_name.to_s)
end
name_selector(name, fn)
end
@@ -135,6 +135,15 @@ public static bool All<TSource>(this IEnumerable<TSource> collection, Predicate<
return true;
}
+ public static bool Any<TSource>(this IEnumerable<TSource> collection, Predicate<TSource> predicate)
+ {
+ foreach (var source in collection)
+ {
+ if(predicate(source)) return true;
+ }
+ return false;
+ }
+
public static IEnumerable Where(this IEnumerable collection, Predicate<object> predicate)
{
foreach (var source in collection)
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 5cb65c6

Please sign in to comment.