Permalink
Browse files

Scoped filters are working now. Time for a small refactor

Signed-off-by: Jimmy Schementi <jschementi@gmail.com>
  • Loading branch information...
1 parent 5213e3a commit d21a54ec06a1d50874f19d5a99e8fad2792c637e @casualjim casualjim committed with Mar 5, 2009
@@ -30,7 +30,7 @@ def around_action(name, options={}, &b)
filter(name, options.merge(:when => :around))
end
- def authorize_action(name, options={}, &b)
+ def authorized_action(name, options={}, &b)
filter(name, options.merge(:when => :authorize), &b)
end
@@ -49,7 +49,8 @@ def after_result(name, options={}, &b)
def filter(name, options={})
@action_filters ||= []
- name = :controller if name.nil?
+ options = name if name.is_a? Class
+ name = :controller if name.nil? || name.is_a?(Class)
@action_filters << { :name => name.to_sym, :options => options }
end
@@ -121,7 +121,7 @@ internal static FilterInfo ToFilterInfo(this IEnumerable filterDescriptions, str
if (description.IsNull()) return;
var key = description[SymbolConstants.Name].ToString();
- if (new string[] { "controller", null, string.Empty, actionName }.DoesNotContain(key)) return; // Note: mind the ! in the beginning
+ if (new string[] { "controller", null, string.Empty, actionName }.DoesNotContain(key)) return;
var filter = converter.Convert(filterDescription as Hash, engine);
if (filter.IsNotNull())
Binary file not shown.
Binary file not shown.
@@ -20,7 +20,7 @@ class HomeController < Controller
before_action :index do |context|
$before_counter ||= 0
$before_counter += 1
- context.request_context.http_context.response.write("Hello world")
+ context.request_context.http_context.response.write("Hello world<br />")
end
filter :index, MyFilter
@@ -6,6 +6,7 @@
include IronRubyMvcWeb::Models::Northwind
require 'MyProductFilter'
+require 'MyControllerFilter'
class ProductsRepository < IronRubyRepository
end
@@ -29,6 +30,7 @@ def return_view(*args)
class ProductsController < Controller
filter :index, MyProductFilter
+ filter MyControllerFilter
def index
repository = ProductsRepository.new
@@ -0,0 +1,11 @@
+class MyControllerFilter < ActionFilter
+
+ def on_action_executing(context)
+ context.http_context.response.write 'My controller filter<br />'
+ end
+
+ def on_action_executed(context)
+ #noop
+ end
+
+end
@@ -1,7 +1,7 @@
class MyFilter < ActionFilter
def on_action_executing(context)
- context.http_context.response.write 'MyFilter'
+ context.http_context.response.write 'My filter<br />'
end
def on_action_executed(context)
@@ -1,7 +1,7 @@
class MyProductFilter < ActionFilter
def on_action_executing(context)
- context.http_context.response.write 'MyFilter'
+ context.http_context.response.write 'My product index filter<br />'
end
def on_action_executed(context)
@@ -122,6 +122,7 @@
<None Include="Controllers\Helpers\BaseController.rb" />
<None Include="Controllers\HomeController.rb" />
<None Include="Controllers\ProductsController.rb" />
+ <None Include="Filters\MyControllerFilter.rb" />
<None Include="Filters\MyFilter.rb" />
<Content Include="Filters\MyProductFilter.rb" />
<None Include="Models\Helpers\model.rb" />
View
@@ -11,3 +11,47 @@ Running IronRubyMvcWeb:
Running Pictures:
1. Start cassini against Pictures
2. ruby Pictures\server\app.rb
+
+
+We now have full support for filters. You can create filters in a number of ways.
+
+class YourController < Controller
+
+ # before_action, after_action, around_action, before_result, after_result, authorized_action, exception_action all work
+ before_action :index do |context|
+ # do some filtering stuff here
+ end
+
+ authorized_action :some_other_action do |context|
+ # do some authorization checking work here
+ end
+
+ filter :index, YourFilter
+ filter :some_other_action, DifferentYourFilter
+
+ # executes for each action
+ filter YourControllerFilter
+
+ def index
+ # index action
+ end
+
+ def some_other_action
+ # index action
+ end
+
+end
+
+You can define the following types of filters:
+ActionFilter, ResultFilter, AuthorizationFilter, ExceptionFilter
+
+class YourFilter < ActionFilter
+
+ def on_action_executing(context)
+ # Do some filter work here
+ end
+
+ def on_action_executed(context)
+ # Do some filter work here
+ end
+end

0 comments on commit d21a54e

Please sign in to comment.