Module: BeforeFilters
- Defined in:
- lib/before_filters.rb,
lib/before_filters/version.rb
Constant Summary collapse
- VERSION =
"0.0.1"
Instance Method Summary collapse
-
#before_filter(method_name, options = {}) ⇒ Object
DSL method that classes use to add before filters.
-
#filters ⇒ Object
keeps track of all before filters.
-
#method_added(method_name) ⇒ Object
method that is invoked when a new instance method is added to class.
Instance Method Details
#before_filter(method_name, options = {}) ⇒ Object
DSL method that classes use to add before filters
17 18 19 20 21 |
# File 'lib/before_filters.rb', line 17 def before_filter(method_name, = {}) raise StandardError, "List of methods must be a whitelist" unless .has_key?(:only) raise StandardError, "List of methods must be an array" unless [:only].kind_of?(Array) filters[method_name] = [:only] end |
#filters ⇒ Object
keeps track of all before filters
24 25 26 |
# File 'lib/before_filters.rb', line 24 def filters @filters ||= {} end |
#method_added(method_name) ⇒ Object
method that is invoked when a new instance method is added to class
6 7 8 9 10 11 12 13 14 |
# File 'lib/before_filters.rb', line 6 def method_added(method_name) # do not add to filer chain on a method if it already exists on the method return unless self.instance_methods(false).include?(method_name) return if filters.keys.include?(method_name) || filtered_methods.include?(method_name) return unless filters.keys.select { |key| filters[key].include?(instance_method(method_name).name) } add_filters_to(method_name) end |