rory 0.3.6 → 0.3.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rory/dispatcher.rb +3 -5
- data/lib/rory/support.rb +7 -0
- data/lib/rory/version.rb +1 -1
- data/spec/application_spec.rb +1 -0
- data/spec/dispatcher_spec.rb +10 -0
- data/spec/fixture_app/config/routes.rb +3 -0
- data/spec/fixture_app/controllers/goose/wombat/rabbits_controller.rb +14 -0
- data/spec/support_spec.rb +32 -0
- metadata +2 -1
data/lib/rory/dispatcher.rb
CHANGED
@@ -52,12 +52,10 @@ module Rory
|
|
52
52
|
def controller_class
|
53
53
|
if route
|
54
54
|
controller_name = Rory::Support.camelize("#{route[:controller]}_controller")
|
55
|
-
|
56
|
-
|
57
|
-
else
|
58
|
-
Object
|
55
|
+
if route[:module]
|
56
|
+
controller_name.prepend "#{Rory::Support.camelize("#{route[:module]}")}/"
|
59
57
|
end
|
60
|
-
|
58
|
+
Rory::Support.constantize(controller_name)
|
61
59
|
end
|
62
60
|
end
|
63
61
|
|
data/lib/rory/support.rb
CHANGED
@@ -9,6 +9,13 @@ module Rory
|
|
9
9
|
string = string.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }.gsub('/', '::')
|
10
10
|
end
|
11
11
|
|
12
|
+
def constantize(string)
|
13
|
+
camelized = camelize(string)
|
14
|
+
camelized.split('::').inject(Object) { |scope, const|
|
15
|
+
scope.const_get(const)
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
12
19
|
def require_all_files_in_directory(path)
|
13
20
|
Dir[Pathname.new(path).join('**', '*.rb')].each do |file|
|
14
21
|
require file
|
data/lib/rory/version.rb
CHANGED
data/spec/application_spec.rb
CHANGED
@@ -77,6 +77,7 @@ describe Rory::Application do
|
|
77
77
|
{ :controller => 'monkeys', :action => nil, :regex => /^foo$/, :methods => [:put] },
|
78
78
|
{ :controller => 'awesome', :action => 'rad', :regex => /^this\/(?<path>[^\/]+)\/is\/(?<very_awesome>[^\/]+)$/},
|
79
79
|
{ :controller => 'lumpies', :action => 'show', :regex => /^lumpies\/(?<lump>[^\/]+)$/, :module => 'goose', :methods => [:get] },
|
80
|
+
{ :controller => 'rabbits', :action => 'chew', :regex => /^rabbits\/(?<chew>[^\/]+)$/, :module => 'goose/wombat', :methods => [:get] },
|
80
81
|
{ :controller => 'root', :action => 'vegetable', :regex => /^$/, :methods => [:get] }
|
81
82
|
].inspect
|
82
83
|
end
|
data/spec/dispatcher_spec.rb
CHANGED
@@ -53,6 +53,16 @@ describe Rory::Dispatcher do
|
|
53
53
|
:in_scoped_controller => true # see Goose::LumpiesController in /spec/fixture_app
|
54
54
|
}
|
55
55
|
end
|
56
|
+
|
57
|
+
it "dispatches properly to a nested scoped controller" do
|
58
|
+
request[:route] = { :controller => 'rabbits', :module => 'goose/wombat' }
|
59
|
+
dispatcher.dispatch.should == {
|
60
|
+
:whatever => :yay,
|
61
|
+
:route => request[:route],
|
62
|
+
:dispatcher => dispatcher,
|
63
|
+
:in_scoped_controller => true # see Goose::Wombat::RabbitsController in /spec/fixture_app
|
64
|
+
}
|
65
|
+
end
|
56
66
|
end
|
57
67
|
|
58
68
|
describe "#route" do
|
@@ -5,5 +5,8 @@ Fixture::Application.set_routes do
|
|
5
5
|
scope :module => 'goose' do
|
6
6
|
match 'lumpies/:lump', :to => 'lumpies#show', :methods => [:get]
|
7
7
|
end
|
8
|
+
scope :module => 'goose/wombat' do
|
9
|
+
match 'rabbits/:chew', :to => 'rabbits#chew', :methods => [:get]
|
10
|
+
end
|
8
11
|
match '/', :to => 'root#vegetable', :methods => [:get]
|
9
12
|
end
|
data/spec/support_spec.rb
CHANGED
@@ -5,6 +5,10 @@ describe Rory::Support do
|
|
5
5
|
it "camelizes given snake-case string" do
|
6
6
|
Rory::Support.camelize('water_under_bridge').should == 'WaterUnderBridge'
|
7
7
|
end
|
8
|
+
|
9
|
+
it "leaves already camel-cased string alone" do
|
10
|
+
Rory::Support.camelize('OliverDrankGasoline').should == 'OliverDrankGasoline'
|
11
|
+
end
|
8
12
|
end
|
9
13
|
|
10
14
|
describe '.require_all_files_in_directory' do
|
@@ -16,4 +20,32 @@ describe Rory::Support do
|
|
16
20
|
Rory::Support.require_all_files_in_directory('spinach')
|
17
21
|
end
|
18
22
|
end
|
23
|
+
|
24
|
+
describe '.constantize' do
|
25
|
+
before(:all) do
|
26
|
+
Object.const_set('OrigamiDeliveryMan', Module.new)
|
27
|
+
OrigamiDeliveryMan.const_set('UnderWhere', Module.new)
|
28
|
+
OrigamiDeliveryMan::UnderWhere.const_set('Skippy', Module.new)
|
29
|
+
end
|
30
|
+
|
31
|
+
after(:all) do
|
32
|
+
Object.send(:remove_const, :OrigamiDeliveryMan)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'returns constant from camelized name' do
|
36
|
+
Rory::Support.constantize('OrigamiDeliveryMan').
|
37
|
+
should == OrigamiDeliveryMan
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'returns constant from snake-case string' do
|
41
|
+
Rory::Support.constantize('origami_delivery_man').
|
42
|
+
should == OrigamiDeliveryMan
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'returns namespaced constant' do
|
46
|
+
Rory::Support.constantize(
|
47
|
+
'origami_delivery_man/under_where/skippy'
|
48
|
+
).should == OrigamiDeliveryMan::UnderWhere::Skippy
|
49
|
+
end
|
50
|
+
end
|
19
51
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -189,6 +189,7 @@ files:
|
|
189
189
|
- spec/fixture_app/config/application.rb
|
190
190
|
- spec/fixture_app/config/routes.rb
|
191
191
|
- spec/fixture_app/controllers/goose/lumpies_controller.rb
|
192
|
+
- spec/fixture_app/controllers/goose/wombat/rabbits_controller.rb
|
192
193
|
- spec/fixture_app/controllers/stub_controller.rb
|
193
194
|
- spec/fixture_app/views/layouts/surround.html.erb
|
194
195
|
- spec/fixture_app/views/test/dynamic.html.erb
|