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

Instance Method Summary collapse

Instance Attribute Details

#filtersObject (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.

Raises:

  • (ArgumentError)


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_filtersObject

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_filtersObject

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