rack-mount 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,13 +7,18 @@ module Rack::Mount
7
7
  super
8
8
 
9
9
  @has_significant_params = @conditions.any? { |method, condition|
10
- condition.required_params.any? || condition.required_defaults.any?
10
+ (condition.respond_to?(:required_params) && condition.required_params.any?) ||
11
+ (condition.respond_to?(:required_defaults) && condition.required_defaults.any?)
11
12
  }
12
13
  end
13
14
 
14
15
  def generation_keys
15
16
  @conditions.inject({}) { |keys, (method, condition)|
16
- keys.merge!(condition.required_defaults)
17
+ if condition.respond_to?(:required_defaults)
18
+ keys.merge!(condition.required_defaults)
19
+ else
20
+ keys
21
+ end
17
22
  }
18
23
  end
19
24
 
@@ -44,10 +44,16 @@ module Rack::Mount
44
44
  conditions = []
45
45
  route.conditions.each do |method, condition|
46
46
  b = []
47
- b << "if m = obj.#{method}.match(#{condition.inspect})"
48
- b << 'matches = m.captures' if route.named_captures[method].any?
49
- b << 'p = nil' if route.named_captures[method].any?
50
- b << route.named_captures[method].map { |k, j| "params[#{k.inspect}] = p if p = matches[#{j}]" }.join('; ')
47
+ if condition.is_a?(Regexp)
48
+ b << "if m = obj.#{method}.match(#{condition.inspect})"
49
+ if (named_captures = route.named_captures[method]) && named_captures.any?
50
+ b << 'matches = m.captures'
51
+ b << 'p = nil'
52
+ b << named_captures.map { |k, j| "params[#{k.inspect}] = p if p = matches[#{j}]" }.join('; ')
53
+ end
54
+ else
55
+ b << "if m = obj.#{method} == route.conditions[:#{method}]"
56
+ end
51
57
  b << 'true'
52
58
  b << 'end'
53
59
  conditions << "(#{b.join('; ')})"
@@ -10,6 +10,7 @@ module Rack::Mount
10
10
 
11
11
  @named_captures = {}
12
12
  @conditions.map { |method, condition|
13
+ next unless condition.respond_to?(:named_captures)
13
14
  @named_captures[method] = condition.named_captures.inject({}) { |named_captures, (k, v)|
14
15
  named_captures[k.to_sym] = v.last - 1
15
16
  named_captures
@@ -22,7 +23,7 @@ module Rack::Mount
22
23
  params = @defaults.dup
23
24
  if @conditions.all? { |method, condition|
24
25
  value = obj.send(method)
25
- if m = value.match(condition)
26
+ if condition.is_a?(Regexp) && (m = value.match(condition))
26
27
  matches = m.captures
27
28
  @named_captures[method].each { |k, i|
28
29
  if v = matches[i]
@@ -30,6 +31,8 @@ module Rack::Mount
30
31
  end
31
32
  }
32
33
  true
34
+ elsif value == condition
35
+ true
33
36
  else
34
37
  false
35
38
  end
@@ -43,11 +43,13 @@ module Rack::Mount
43
43
  next unless method && pattern
44
44
 
45
45
  pattern = Regexp.compile("\\A#{Regexp.escape(pattern)}\\Z") if pattern.is_a?(String)
46
- pattern = Utils.normalize_extended_expression(pattern)
47
46
 
48
- pattern = RegexpWithNamedGroups.new(pattern)
49
- pattern.extend(GeneratableRegexp::InstanceMethods)
50
- pattern.defaults = @defaults
47
+ if pattern.is_a?(Regexp)
48
+ pattern = Utils.normalize_extended_expression(pattern)
49
+ pattern = RegexpWithNamedGroups.new(pattern)
50
+ pattern.extend(GeneratableRegexp::InstanceMethods)
51
+ pattern.defaults = @defaults
52
+ end
51
53
 
52
54
  @conditions[method] = pattern.freeze
53
55
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-mount
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Peek
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-10 00:00:00 -06:00
12
+ date: 2010-01-13 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -71,8 +71,6 @@ files:
71
71
  - LICENSE
72
72
  has_rdoc: true
73
73
  homepage: http://github.com/josh/rack-mount
74
- licenses: []
75
-
76
74
  post_install_message:
77
75
  rdoc_options: []
78
76
 
@@ -93,9 +91,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
91
  requirements: []
94
92
 
95
93
  rubyforge_project:
96
- rubygems_version: 1.3.5
94
+ rubygems_version: 1.3.1
97
95
  signing_key:
98
- specification_version: 3
96
+ specification_version: 2
99
97
  summary: Stackable dynamic tree based Rack router
100
98
  test_files: []
101
99