url_mount 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/url_mount.rb +6 -5
- data/test/test_url_mount.rb +1 -10
- data/url_mount.gemspec +1 -1
- metadata +3 -4
data/lib/url_mount.rb
CHANGED
@@ -5,6 +5,7 @@ class UrlMount
|
|
5
5
|
|
6
6
|
attr_accessor :raw_path, :options, :url_mount, :host, :scheme
|
7
7
|
alias_method :defaults, :options
|
8
|
+
alias_method :defaults=, :options=
|
8
9
|
|
9
10
|
def initialize(path, opts = {}, &blk)
|
10
11
|
@raw_path, @options = path, opts
|
@@ -74,14 +75,14 @@ class UrlMount
|
|
74
75
|
nil
|
75
76
|
else
|
76
77
|
raise Ungeneratable, "Missing required variables" if !requirements_met
|
77
|
-
File.join(local_segments.inject([]){|url, segment| str = segment.to_s(opts); url << str if str; url}) =~ /(.*?)\/?$/
|
78
78
|
path = local_segments.inject([]){|url, segment| str = segment.to_s(opts); url << str if str; url}.join
|
79
79
|
match = /(.*?)\/?$/.match(path)
|
80
80
|
result = match[1]
|
81
81
|
path = url_mount.nil? ? result : File.join(url_mount.to_s(opts), result)
|
82
|
-
|
83
|
-
|
84
|
-
|
82
|
+
_host = opts.delete(:host) || host
|
83
|
+
_scheme = opts.delete(:scheme) || scheme
|
84
|
+
if _host || _scheme
|
85
|
+
_scheme ||= "http"
|
85
86
|
raise Ungeneratable, "Missing host when generating absolute url" if _scheme && !_host
|
86
87
|
uri = URI.parse(path)
|
87
88
|
uri.host = _host
|
@@ -171,7 +172,7 @@ class UrlMount
|
|
171
172
|
end
|
172
173
|
|
173
174
|
def to_s(opts = {})
|
174
|
-
item = opts
|
175
|
+
item = opts.delete(name) || @options[name]
|
175
176
|
item.respond_to?(:call) ? item.call : item
|
176
177
|
end
|
177
178
|
end
|
data/test/test_url_mount.rb
CHANGED
@@ -50,7 +50,7 @@ class TestUrlMount < Test::Unit::TestCase
|
|
50
50
|
opts = {:bar => "bar", :other => "other"}
|
51
51
|
u = UrlMount.new("/foo/:bar", :bar => "some_default_bar")
|
52
52
|
u.url(opts)
|
53
|
-
assert_equal( {:
|
53
|
+
assert_equal( {:other => "other"}, opts )
|
54
54
|
end
|
55
55
|
|
56
56
|
should "alias to_s to url" do
|
@@ -148,15 +148,6 @@ class TestUrlMount < Test::Unit::TestCase
|
|
148
148
|
u2.url_mount = u1
|
149
149
|
assert_equal "/root/different/baz/barry", u2.url(:bar => "different")
|
150
150
|
end
|
151
|
-
|
152
|
-
should "not consume params to nested routes" do
|
153
|
-
u1 = UrlMount.new("/root/:bar", :bar => "bar")
|
154
|
-
u2 = UrlMount.new("/baz/:barry", :barry => "barry")
|
155
|
-
u2.url_mount = u1
|
156
|
-
opts = {:bar => "sue", :barry => "wendy"}
|
157
|
-
assert_equal "/root/sue/baz/wendy", u2.url(opts)
|
158
|
-
assert_equal({:bar => "sue", :barry => "wendy"}, opts)
|
159
|
-
end
|
160
151
|
end
|
161
152
|
|
162
153
|
context "host options" do
|
data/url_mount.gemspec
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: url_mount
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 1
|
10
|
+
version: 0.2.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Daniel Neighman
|
@@ -64,7 +64,6 @@ files:
|
|
64
64
|
- README.textile
|
65
65
|
- test/helper.rb
|
66
66
|
- test/test_url_mount.rb
|
67
|
-
- url_mount-0.2.0.gem
|
68
67
|
- url_mount.gemspec
|
69
68
|
has_rdoc: true
|
70
69
|
homepage: http://github.com/hassox/url_mount
|