joshbuddy-usher 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 4
2
+ :patch: 5
3
3
  :major: 0
4
4
  :minor: 3
@@ -9,8 +9,9 @@ class Usher
9
9
  RequestMethods = [:method, :host, :port, :scheme]
10
10
  Request = Struct.new(:path, *RequestMethods)
11
11
 
12
- def initialize
12
+ def initialize(&blk)
13
13
  @routes = Usher.new(:request_methods => RequestMethods)
14
+ instance_eval(&blk) if blk
14
15
  end
15
16
 
16
17
  def add(path, options = {})
@@ -6,14 +6,14 @@ class Usher
6
6
  autoload :MerbInterface, 'interface/merb_interface'
7
7
  autoload :RackInterface, 'interface/rack_interface'
8
8
 
9
- def self.for(type)
9
+ def self.for(type, &blk)
10
10
  case type
11
11
  when :rails2
12
- Rails2Interface.new
12
+ Rails2Interface.new(&blk)
13
13
  when :merb
14
- MerbInterface.new
14
+ MerbInterface.new(&blk)
15
15
  when :rack
16
- RackInterface.new
16
+ RackInterface.new(&blk)
17
17
  end
18
18
  end
19
19
 
data/lib/usher/node.rb CHANGED
@@ -100,7 +100,11 @@ class Usher
100
100
  params.last.last << part unless part.is_a?(Symbol)
101
101
  find(request, path, params)
102
102
  when :':'
103
+ var = next_part.value
103
104
  params << [next_part.value.name, part]
105
+ until (path.first == var.look_ahead) || path.empty?
106
+ params.last.last << path.shift.to_s
107
+ end
104
108
  next_part.find(request, path, params)
105
109
  end
106
110
  end
@@ -2,6 +2,7 @@ class Usher
2
2
  class Route
3
3
  class Variable
4
4
  attr_reader :type, :name, :validator, :transformer
5
+ attr_accessor :look_ahead
5
6
 
6
7
  def initialize(type, name, opts = {})
7
8
  @type = type
@@ -73,7 +73,24 @@ class Usher
73
73
  current_group << part
74
74
  end
75
75
  end unless !path || path.empty?
76
- calc_paths(parts)
76
+ paths = calc_paths(parts)
77
+ paths.each do |path|
78
+ last_delimiter = nil
79
+ last_variable = nil
80
+ path.each do |part|
81
+ case part
82
+ when Symbol
83
+ last_delimiter = part
84
+ when Usher::Route::Variable
85
+ if last_variable
86
+ last_variable.look_ahead = last_delimiter || @delimiters.first.to_sym
87
+ end
88
+ last_variable = part
89
+ end
90
+ end
91
+ last_variable.look_ahead = last_delimiter || @delimiters.first.to_sym if last_variable
92
+ end
93
+ paths
77
94
  end
78
95
 
79
96
  private
@@ -102,6 +102,11 @@ describe "Usher route recognition" do
102
102
  route_set.recognize(build_request({:method => 'get', :path => '/!asd,qwe/hjk$qwe/09AZaz$-_+!*\'', :domain => 'admin.host.com'})).params.rassoc('09AZaz$-_+!*\'').first.should == :id
103
103
  end
104
104
 
105
+ it "shouldn't care about non-primary delimiters in the path" do
106
+ route = route_set.add_route('/testing/:id/testing2/:id2/:id3')
107
+ route_set.recognize(build_request({:method => 'get', :path => '/testing/asd.qwe/testing2/poi.zxc/oiu.asd'})).params.should == [[:id, 'asd.qwe'], [:id2, 'poi.zxc'], [:id3, 'oiu.asd']]
108
+ end
109
+
105
110
  it "should use a transformer (symbol) on incoming variables" do
106
111
  route_set.add_route('/:controller/:action/:id', :transformers => {:id => :to_i})
107
112
  route_set.recognize(build_request({:method => 'get', :path => '/products/show/123asd', :domain => 'admin.host.com'})).params.rassoc(123).first.should == :id
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: joshbuddy-usher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Hull
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-07 00:00:00 -07:00
12
+ date: 2009-04-10 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency