Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Now action aliasing is really working

  • Loading branch information...
commit 5cb65c62d4bf0597964d0ddc4e2d8736a855fd2a 1 parent 38a7edd
Ivan Porto Carrero authored March 20, 2009

Showing 26 changed files with 21 additions and 7 deletions. Show diff stats Hide diff stats

  1. 13  IronRubyMvc/Controllers/RubyActionMethodSelector.cs
  2. 2  IronRubyMvc/Controllers/RubyControllerDescriptor.cs
  3. 4  IronRubyMvc/Controllers/controller.rb
  4. 9  IronRubyMvc/Extensions/IEnumerableExtensions.cs
  5. BIN  IronRubyMvcLibrarySpecs/bin/IronRuby.Libraries.dll
  6. BIN  IronRubyMvcLibrarySpecs/bin/IronRuby.Libraries.pdb
  7. BIN  IronRubyMvcLibrarySpecs/bin/IronRuby.dll
  8. BIN  IronRubyMvcLibrarySpecs/bin/IronRuby.pdb
  9. BIN  IronRubyMvcLibrarySpecs/bin/Microsoft.Scripting.Core.dll
  10. BIN  IronRubyMvcLibrarySpecs/bin/Microsoft.Scripting.Core.pdb
  11. BIN  IronRubyMvcLibrarySpecs/bin/Microsoft.Scripting.ExtensionAttribute.dll
  12. BIN  IronRubyMvcLibrarySpecs/bin/Microsoft.Scripting.ExtensionAttribute.pdb
  13. BIN  IronRubyMvcLibrarySpecs/bin/Microsoft.Scripting.dll
  14. BIN  IronRubyMvcLibrarySpecs/bin/Microsoft.Scripting.pdb
  15. BIN  dependencies/IronRuby.Libraries.Yaml.dll
  16. BIN  dependencies/IronRuby.Libraries.Yaml.pdb
  17. BIN  dependencies/IronRuby.Libraries.dll
  18. BIN  dependencies/IronRuby.Libraries.pdb
  19. BIN  dependencies/IronRuby.dll
  20. BIN  dependencies/IronRuby.pdb
  21. BIN  dependencies/Microsoft.Scripting.Core.dll
  22. BIN  dependencies/Microsoft.Scripting.Core.pdb
  23. BIN  dependencies/Microsoft.Scripting.ExtensionAttribute.dll
  24. BIN  dependencies/Microsoft.Scripting.ExtensionAttribute.pdb
  25. BIN  dependencies/Microsoft.Scripting.dll
  26. BIN  dependencies/Microsoft.Scripting.pdb
13  IronRubyMvc/Controllers/RubyActionMethodSelector.cs
@@ -98,7 +98,7 @@ public IEnumerable<string> GetAllActionMethods()
98 98
 
99 99
         private List<string> GetMatchingAliasedMethods(ControllerContext controllerContext, string actionName)
100 100
         {
101  
-            return new List<string>(AliasedMethods.Where(pair => pair.Key == actionName && pair.Value.IsValidForName(controllerContext, actionName)).Map(pair => pair.Key));
  101
+            return new List<string>(AliasedMethods.Where(pair => pair.Value.IsValidForAction(controllerContext, actionName)).Map(pair => pair.Key));
102 102
         }
103 103
 
104 104
         private List<string> RunSelectionFilters(ControllerContext controllerContext, IEnumerable<string> matchingMethods)
@@ -110,12 +110,12 @@ private List<string> RunSelectionFilters(ControllerContext controllerContext, IE
110 110
                        ? new List<string>(matchingMethods)
111 111
                        : new List<string>(
112 112
                            matchingMethods.Where(
113  
-                                methodName => filters.All(filter => filter.Value.IsValidForName(controllerContext, methodName))
  113
+                                methodName => filters.All(filter => filter.Value.IsValid(controllerContext, methodName))
114 114
                            )
115 115
                         );
116 116
         }
117 117
     }
118  
-
  118
+    
119 119
     public class PredicateList : IEnumerable<Func<ControllerContext, string, bool>>
120 120
     {
121 121
         private readonly RubyArray _items;
@@ -139,11 +139,16 @@ private void Add(Proc proc)
139 139
             _predicates.Add(_rubyEngine.ConvertProcToFunc<bool>(proc));
140 140
         }
141 141
 
142  
-        public bool IsValidForName(ControllerContext context, string name)
  142
+        public bool IsValid(ControllerContext context, string name)
143 143
         {
144 144
             return _predicates.All(predicate => predicate(context, name));
145 145
         }
146 146
 
  147
+        public bool IsValidForAction(ControllerContext context, string name)
  148
+        {
  149
+            return _predicates.Any(predicate => predicate(context, name));
  150
+        }
  151
+
147 152
         #region Implementation of IEnumerable
148 153
 
149 154
         /// <summary>
2  IronRubyMvc/Controllers/RubyControllerDescriptor.cs
@@ -38,7 +38,7 @@ public override ActionDescriptor FindAction(ControllerContext controllerContext,
38 38
             actionName.EnsureArgumentNotNull("actionName");
39 39
 
40 40
             var selectedName = _selector.FindActionMethod(controllerContext, actionName);
41  
-            return selectedName.IsNotNullOrBlank() ?  new RubyActionDescriptor(actionName, this, _engine ) : null;
  41
+            return selectedName.IsNotNullOrBlank() ?  new RubyActionDescriptor(selectedName, this, _engine ) : null;
42 42
         }
43 43
 
44 44
         public override ActionDescriptor[] GetCanonicalActions()
4  IronRubyMvc/Controllers/controller.rb
@@ -117,7 +117,7 @@ def around_result(name, method_name=nil, options={}, &b)
117 117
           filter(name, RubyProcResultFilter.new(options[:before], options[:after])) 
118 118
         end
119 119
  
120  
-	 	    def filter(name, options=nil)
  120
+	 	def filter(name, options=nil)
121 121
           @action_filters ||= {}
122 122
           klass = nil
123 123
           klass = name.new if name.is_a? Class
@@ -161,7 +161,7 @@ def method_selector(name, selector)
161 161
         
162 162
         def alias_action(name, act_name)
163 163
           fn = Proc.new do |controller_context, action_name|
164  
-            !!/#{action_name.to_s}/i.match(act_name.to_s)
  164
+            !!/^#{action_name.to_s}$/i.match(act_name.to_s)
165 165
           end
166 166
           name_selector(name, fn)
167 167
         end
9  IronRubyMvc/Extensions/IEnumerableExtensions.cs
@@ -135,6 +135,15 @@ public static bool All<TSource>(this IEnumerable<TSource> collection, Predicate<
135 135
             return true;
136 136
         }
137 137
 
  138
+        public static bool Any<TSource>(this IEnumerable<TSource> collection, Predicate<TSource> predicate)
  139
+        {
  140
+            foreach (var source in collection)
  141
+            {
  142
+                if(predicate(source)) return true;
  143
+            }
  144
+            return false;
  145
+        }
  146
+
138 147
         public static IEnumerable Where(this IEnumerable collection, Predicate<object> predicate)
139 148
         {
140 149
             foreach (var source in collection)
BIN  IronRubyMvcLibrarySpecs/bin/IronRuby.Libraries.dll
Binary file not shown
BIN  IronRubyMvcLibrarySpecs/bin/IronRuby.Libraries.pdb
Binary file not shown
BIN  IronRubyMvcLibrarySpecs/bin/IronRuby.dll
Binary file not shown
BIN  IronRubyMvcLibrarySpecs/bin/IronRuby.pdb
Binary file not shown
BIN  IronRubyMvcLibrarySpecs/bin/Microsoft.Scripting.Core.dll
Binary file not shown
BIN  IronRubyMvcLibrarySpecs/bin/Microsoft.Scripting.Core.pdb
Binary file not shown
BIN  IronRubyMvcLibrarySpecs/bin/Microsoft.Scripting.ExtensionAttribute.dll
Binary file not shown
BIN  IronRubyMvcLibrarySpecs/bin/Microsoft.Scripting.ExtensionAttribute.pdb
Binary file not shown
BIN  IronRubyMvcLibrarySpecs/bin/Microsoft.Scripting.dll
Binary file not shown
BIN  IronRubyMvcLibrarySpecs/bin/Microsoft.Scripting.pdb
Binary file not shown
BIN  dependencies/IronRuby.Libraries.Yaml.dll
Binary file not shown
BIN  dependencies/IronRuby.Libraries.Yaml.pdb
Binary file not shown
BIN  dependencies/IronRuby.Libraries.dll
Binary file not shown
BIN  dependencies/IronRuby.Libraries.pdb
Binary file not shown
BIN  dependencies/IronRuby.dll
Binary file not shown
BIN  dependencies/IronRuby.pdb
Binary file not shown
BIN  dependencies/Microsoft.Scripting.Core.dll
Binary file not shown
BIN  dependencies/Microsoft.Scripting.Core.pdb
Binary file not shown
BIN  dependencies/Microsoft.Scripting.ExtensionAttribute.dll
Binary file not shown
BIN  dependencies/Microsoft.Scripting.ExtensionAttribute.pdb
Binary file not shown
BIN  dependencies/Microsoft.Scripting.dll
Binary file not shown
BIN  dependencies/Microsoft.Scripting.pdb
Binary file not shown

0 notes on commit 5cb65c6

Please sign in to comment.
Something went wrong with that request. Please try again.