pakada 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +4 -1
- data/Rakefile +1 -6
- data/lib/pakada/module.rb +8 -1
- data/lib/pakada/version.rb +1 -1
- data/lib/pakada.rb +10 -6
- data/spec/module_spec.rb +14 -18
- data/spec/pakada_spec.rb +12 -8
- data/spec/spec_helper.rb +0 -3
- metadata +16 -16
data/Gemfile
CHANGED
data/Rakefile
CHANGED
data/lib/pakada/module.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require "pathname"
|
2
|
+
|
1
3
|
class Pakada
|
2
4
|
module Module
|
3
5
|
@descendants = []
|
@@ -23,6 +25,8 @@ class Pakada
|
|
23
25
|
# use Kernel.caller instead of self.caller so Mocha doesn't explode...
|
24
26
|
file = Kernel.caller[0].split(":")[0]
|
25
27
|
klass.instance_variable_set :@path, detect_path(file)
|
28
|
+
else
|
29
|
+
klass.instance_variable_set :@path, Pathname.new(klass.path)
|
26
30
|
end
|
27
31
|
|
28
32
|
unless klass.dependencies
|
@@ -42,8 +46,10 @@ class Pakada
|
|
42
46
|
end
|
43
47
|
|
44
48
|
def detect_path(file)
|
49
|
+
file = String(file)
|
45
50
|
filepath = nil
|
46
51
|
filepath = file if file =~ /^\// && File.exists?(file)
|
52
|
+
|
47
53
|
$LOAD_PATH.each do |dir|
|
48
54
|
x = File.join dir, file
|
49
55
|
if File.exists? x
|
@@ -56,7 +62,8 @@ class Pakada
|
|
56
62
|
segments = File.dirname(filepath).split("/").reverse
|
57
63
|
pos = segments.find_index("lib") || -1
|
58
64
|
|
59
|
-
segments[(pos + 1)..-1].reverse.join
|
65
|
+
path = segments[(pos + 1)..-1].reverse.join("/")
|
66
|
+
Pathname.new File.expand_path(path)
|
60
67
|
end
|
61
68
|
end
|
62
69
|
|
data/lib/pakada/version.rb
CHANGED
data/lib/pakada.rb
CHANGED
@@ -40,14 +40,18 @@ class Pakada
|
|
40
40
|
def self.boot
|
41
41
|
instance(:default) {|ins| ins.urls = ["/"] } if instances.empty?
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
43
|
+
if instances.keys.length > 1
|
44
|
+
@urlmap = Rack::URLMap.new instances.values.inject({}) {|map, ins|
|
45
|
+
ins.urls.each {|url|
|
46
|
+
map[url] = proc {|env|
|
47
|
+
instance(ins.name) { ins.call env }
|
48
|
+
}
|
47
49
|
}
|
50
|
+
map
|
48
51
|
}
|
49
|
-
|
50
|
-
|
52
|
+
else
|
53
|
+
@urlmap = instances.values[0]
|
54
|
+
end
|
51
55
|
|
52
56
|
instances.values.each {|ins|
|
53
57
|
instance(ins.name) { ins.boot }
|
data/spec/module_spec.rb
CHANGED
@@ -24,14 +24,14 @@ describe Pakada::Module do
|
|
24
24
|
it "loops through the load path to find a matching path" do
|
25
25
|
m = Pakada::Module
|
26
26
|
|
27
|
-
path = "/my/path"
|
28
|
-
FileUtils.mkdir_p path
|
29
|
-
FileUtils.touch path
|
30
|
-
$LOAD_PATH << path
|
27
|
+
path = Pathname.new("/my/path")
|
28
|
+
FileUtils.mkdir_p path.join("lib")
|
29
|
+
FileUtils.touch path.join("lib/some_module.rb")
|
30
|
+
$LOAD_PATH << path.join("lib")
|
31
31
|
|
32
32
|
m.detect_path("some_module.rb").should == path
|
33
|
-
m.detect_path(path
|
34
|
-
$LOAD_PATH.delete path
|
33
|
+
m.detect_path(path.join("lib/some_module.rb")).should == path
|
34
|
+
$LOAD_PATH.delete path.join("lib")
|
35
35
|
|
36
36
|
m.detect_path("config.ru").should be_nil
|
37
37
|
end
|
@@ -86,23 +86,19 @@ describe Pakada::Module do
|
|
86
86
|
end
|
87
87
|
|
88
88
|
it "tries to determine the module's path" do
|
89
|
-
path = "/my/path"
|
90
|
-
file = path
|
89
|
+
path = Pathname.new("/my/path")
|
90
|
+
file = path.join("lib/some_module.rb")
|
91
91
|
|
92
|
-
Kernel.should_receive(:
|
93
|
-
|
94
|
-
|
95
|
-
alias caller mock_caller
|
96
|
-
end
|
92
|
+
Kernel.should_receive(:caller).once {
|
93
|
+
[file.to_s + ":1: in `something'"]
|
94
|
+
}
|
97
95
|
|
98
|
-
Pakada::Module.should_receive(:detect_path).with(file).once { path }
|
96
|
+
Pakada::Module.should_receive(:detect_path).with(file.to_s).once { path }
|
99
97
|
klass = Class.new do
|
100
98
|
@pakada_name = :some_module
|
101
99
|
include Pakada::Module
|
102
100
|
end
|
103
101
|
klass.path.should == path
|
104
|
-
|
105
|
-
Kernel.instance_eval { alias caller orig_caller }
|
106
102
|
end
|
107
103
|
|
108
104
|
it "respects an already set path" do
|
@@ -112,7 +108,7 @@ describe Pakada::Module do
|
|
112
108
|
@path = "/my/path"
|
113
109
|
include Pakada::Module
|
114
110
|
end
|
115
|
-
klass.path.should == "/my/path"
|
111
|
+
klass.path.should == Pathname.new("/my/path")
|
116
112
|
end
|
117
113
|
|
118
114
|
it "adds the module to the list of descendants" do
|
@@ -159,7 +155,7 @@ describe "SomeModule" do
|
|
159
155
|
|
160
156
|
describe ".path" do
|
161
157
|
it "contains the module's base path" do
|
162
|
-
@klass.path.should == "/opt/pakada"
|
158
|
+
@klass.path.should == Pathname.new("/opt/pakada")
|
163
159
|
end
|
164
160
|
|
165
161
|
it "is read-only" do
|
data/spec/pakada_spec.rb
CHANGED
@@ -98,6 +98,12 @@ describe Pakada do
|
|
98
98
|
Pakada.boot
|
99
99
|
end
|
100
100
|
|
101
|
+
it "doesn't create a URLMap if there's only one instance" do
|
102
|
+
Pakada.instances.delete :bar
|
103
|
+
Rack::URLMap.should_not_receive :new
|
104
|
+
Pakada.boot
|
105
|
+
end
|
106
|
+
|
101
107
|
it "calls #boot on each instance" do
|
102
108
|
foo.should_receive :boot
|
103
109
|
bar.should_receive :boot
|
@@ -108,15 +114,10 @@ describe Pakada do
|
|
108
114
|
|
109
115
|
it "creates a default instance if there are no others" do
|
110
116
|
Pakada.instances.clear
|
111
|
-
|
112
|
-
Rack::URLMap.should_receive(:new) {|map|
|
113
|
-
default.should_receive(:call) {
|
114
|
-
Pakada.instance.should == default
|
115
|
-
}
|
116
|
-
map["/"].call({})
|
117
|
-
}
|
118
|
-
|
119
117
|
Pakada.boot
|
118
|
+
|
119
|
+
Pakada.instances[:default].should equal(default)
|
120
|
+
default.urls.should == ["/"]
|
120
121
|
end
|
121
122
|
end
|
122
123
|
|
@@ -127,6 +128,9 @@ describe Pakada do
|
|
127
128
|
|
128
129
|
before do
|
129
130
|
Rack::URLMap.stub :new => urlmap
|
131
|
+
|
132
|
+
Pakada.instance(:foo) {}
|
133
|
+
Pakada.instance(:bar) {}
|
130
134
|
Pakada.boot
|
131
135
|
end
|
132
136
|
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pakada
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-08-
|
12
|
+
date: 2011-08-14 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
16
|
-
requirement: &
|
16
|
+
requirement: &70444740 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70444740
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: hooked
|
27
|
-
requirement: &
|
27
|
+
requirement: &70444530 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70444530
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &70444320 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70444320
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: fakefs
|
49
|
-
requirement: &
|
49
|
+
requirement: &70444110 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70444110
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: fakefs-require
|
60
|
-
requirement: &
|
60
|
+
requirement: &70443900 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70443900
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: yard
|
71
|
-
requirement: &
|
71
|
+
requirement: &70443690 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70443690
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: rdiscount
|
82
|
-
requirement: &
|
82
|
+
requirement: &70504120 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,7 +87,7 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70504120
|
91
91
|
description:
|
92
92
|
email:
|
93
93
|
- lars.gierth@gmail.com
|