Class: Rack::Rewrite::ConditionSet
- Inherits:
-
Object
- Object
- Rack::Rewrite::ConditionSet
- Defined in:
- lib/rack_rewrite/condition_set.rb
Instance Attribute Summary collapse
-
#actions ⇒ Object
readonly
Returns the value of attribute actions.
-
#conditions ⇒ Object
readonly
Returns the value of attribute conditions.
-
#parent_set ⇒ Object
readonly
Returns the value of attribute parent_set.
Instance Method Summary collapse
-
#initialize(parent_set, conditions = nil) ⇒ ConditionSet
constructor
A new instance of ConditionSet.
- #satisfied?(env) ⇒ Boolean
Constructor Details
#initialize(parent_set, conditions = nil) ⇒ ConditionSet
Returns a new instance of ConditionSet.
7 8 9 10 11 |
# File 'lib/rack_rewrite/condition_set.rb', line 7 def initialize(parent_set, conditions = nil) @parent_set = parent_set @conditions = conditions @actions = [] end |
Instance Attribute Details
#actions ⇒ Object (readonly)
Returns the value of attribute actions.
5 6 7 |
# File 'lib/rack_rewrite/condition_set.rb', line 5 def actions @actions end |
#conditions ⇒ Object (readonly)
Returns the value of attribute conditions.
5 6 7 |
# File 'lib/rack_rewrite/condition_set.rb', line 5 def conditions @conditions end |
#parent_set ⇒ Object (readonly)
Returns the value of attribute parent_set.
5 6 7 |
# File 'lib/rack_rewrite/condition_set.rb', line 5 def parent_set @parent_set end |
Instance Method Details
#satisfied?(env) ⇒ Boolean
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rack_rewrite/condition_set.rb', line 13 def satisfied?(env) if conditions uri_ok = conditions.key?(:uri) ? conditions[:uri] === env['PATH_INFO'] : true method_ok = conditions.key?(:method) ? conditions[:method] === env['REQUEST_METHOD'].downcase : true host_ok = conditions.key?(:host) ? conditions[:host] === env['HTTP_HOST'] : true port_ok = conditions.key?(:port) ? conditions[:port] === env['SERVER_PORT'].to_i : true scheme_ok = conditions.key?(:scheme) ? conditions[:scheme] === env['rack.url_scheme'] : true if conditions.key?(:params) req = Rack::Request.new(env) params_ok = true conditions[:params].each do |key, test| params_ok = test === req.params[key.to_s] break unless params_ok end else params_ok = true end uri_ok && method_ok && host_ok && port_ok && scheme_ok && params_ok else true end end |