Class: Rack::TicketOffice::UrlFilter
- Inherits:
-
Object
- Object
- Rack::TicketOffice::UrlFilter
- Defined in:
- lib/rack/ticket-office/url_filter.rb
Instance Attribute Summary collapse
-
#allowed_queries ⇒ Object
readonly
Returns the value of attribute allowed_queries.
-
#path_info ⇒ Object
readonly
Returns the value of attribute path_info.
-
#request_methods ⇒ Object
readonly
Returns the value of attribute request_methods.
-
#required_queries ⇒ Object
readonly
Returns the value of attribute required_queries.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(request_spec) ⇒ UrlFilter
constructor
A new instance of UrlFilter.
- #marshal_dump ⇒ Object
- #marshal_load(variables) ⇒ Object
- #match(env) ⇒ Object
Constructor Details
#initialize(request_spec) ⇒ UrlFilter
Returns a new instance of UrlFilter.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/rack/ticket-office/url_filter.rb', line 9 def initialize(request_spec) begin request_spec.assert_valid_keys(:request_methods, :path, :required_queries, :allowed_queries) request_spec[:request_methods].assert_valid_elements(:get, :post, :put, :delete, :head, :options, :all) "Fred".match(request_spec[:path]) rescue raise ArgumentError end @request_methods = request_spec[:request_methods] @request_methods = [:get, :post, :put, :delete, :head, :options] if request_spec[:request_methods].include?(:all) @path_info = request_spec[:path] @required_queries = request_spec[:required_queries] || {} @allowed_queries = request_spec[:allowed_queries] || [] end |
Instance Attribute Details
#allowed_queries ⇒ Object (readonly)
Returns the value of attribute allowed_queries.
7 8 9 |
# File 'lib/rack/ticket-office/url_filter.rb', line 7 def allowed_queries @allowed_queries end |
#path_info ⇒ Object (readonly)
Returns the value of attribute path_info.
7 8 9 |
# File 'lib/rack/ticket-office/url_filter.rb', line 7 def path_info @path_info end |
#request_methods ⇒ Object (readonly)
Returns the value of attribute request_methods.
7 8 9 |
# File 'lib/rack/ticket-office/url_filter.rb', line 7 def request_methods @request_methods end |
#required_queries ⇒ Object (readonly)
Returns the value of attribute required_queries.
7 8 9 |
# File 'lib/rack/ticket-office/url_filter.rb', line 7 def required_queries @required_queries end |
Instance Method Details
#==(other) ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/rack/ticket-office/url_filter.rb', line 54 def ==(other) return (self.class == other.class) && (self.request_methods == other.request_methods) && (self.path_info == other.path_info) && (self.required_queries == other.required_queries) && (self.allowed_queries == other.allowed_queries) true end |
#marshal_dump ⇒ Object
43 44 45 |
# File 'lib/rack/ticket-office/url_filter.rb', line 43 def marshal_dump [ @request_methods, @path_info, @required_queries, @allowed_queries ] end |
#marshal_load(variables) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/rack/ticket-office/url_filter.rb', line 47 def marshal_load(variables) @request_methods = variables[0] @path_info = variables[1] @required_queries = variables[2] @allowed_queries = variables[3] end |
#match(env) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rack/ticket-office/url_filter.rb', line 25 def match(env) req = Rack::Request.new(env) return false unless @request_methods.include?(req.request_method.downcase.to_sym) path_match = req.path_info.match(@path_info) return false unless path_match and path_match[0].eql?(req.path_info) @required_queries.each do |key, value| return false unless req.GET[key] == value end req.GET.each_key do |key| return false unless @required_queries.has_key?(key) or @allowed_queries.include?(key) end true end |