Module: Strelka::App::Filters::ClassMethods
- Defined in:
- lib/strelka/app/filters.rb
Overview
Class methods to add to classes with routing.
Instance Attribute Summary collapse
-
#filters ⇒ Object
readonly
The list of filters.
Instance Method Summary collapse
-
#filter(which = :both, &block) ⇒ Object
Get/set the router class to use for mapping requests to handlers to +newclass.
-
#inherited(subclass) ⇒ Object
Extension callback -- add instance variables to extending objects.
-
#request_filters ⇒ Object
Return filters which should be applied to requests, i.e., those with a
whichof :request or :both. -
#response_filters ⇒ Object
Return filters which should be applied to responses, i.e., those with a
whichof :response or :both.
Instance Attribute Details
#filters ⇒ Object (readonly)
The list of filters
24 25 26 |
# File 'lib/strelka/app/filters.rb', line 24 def filters @filters end |
Instance Method Details
#filter(which = :both, &block) ⇒ Object
Get/set the router class to use for mapping requests to handlers to +newclass.
41 42 43 44 45 46 |
# File 'lib/strelka/app/filters.rb', line 41 def filter( which=:both, &block ) which = which.to_sym raise ArgumentError, "invalid filter stage %p; expected one of: %p" % [ which, self.filters.keys ] if !self.filters.key?( which ) self.filters[ which ] << block end |
#inherited(subclass) ⇒ Object
Extension callback -- add instance variables to extending objects.
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/strelka/app/filters.rb', line 28 def inherited( subclass ) super sub_filters = { :request => self.filters[:request].dup, :response => self.filters[:response].dup, :both => self.filters[:both].dup } subclass.instance_variable_set( :@filters, sub_filters ) end |
#request_filters ⇒ Object
Return filters which should be applied to requests, i.e., those with a which of
:request or :both.
51 52 53 |
# File 'lib/strelka/app/filters.rb', line 51 def request_filters return self.filters[ :request ] + self.filters[ :both ] end |
#response_filters ⇒ Object
Return filters which should be applied to responses, i.e., those with a which of
:response or :both.
58 59 60 |
# File 'lib/strelka/app/filters.rb', line 58 def response_filters return self.filters[ :both ] + self.filters[ :response ] end |