viva-resource_controller 0.6.5 → 0.6.5.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/resource_controller/helpers/urls.rb +25 -20
- data/lib/urligence.rb +15 -9
- metadata +2 -2
@@ -45,54 +45,59 @@ module ResourceController
|
|
45
45
|
symbol = type.blank? ? nil : type.gsub(/_/, '').to_sym
|
46
46
|
|
47
47
|
define_method("#{type}object_url") do |*alternate_object|
|
48
|
-
smart_url *object_url_options(symbol, alternate_object.first)
|
48
|
+
smart_url *object_url_options(symbol, alternate_object.first).push(extract_params(*alternate_object))
|
49
49
|
end
|
50
50
|
|
51
51
|
define_method("#{type}object_path") do |*alternate_object|
|
52
|
-
smart_path *object_url_options(symbol, alternate_object.first)
|
52
|
+
smart_path *object_url_options(symbol, alternate_object.first).push(extract_params(*alternate_object))
|
53
53
|
end
|
54
54
|
|
55
55
|
define_method("hash_for_#{type}object_url") do |*alternate_object|
|
56
|
-
hash_for_smart_url *object_url_options(symbol, alternate_object.first)
|
56
|
+
hash_for_smart_url *object_url_options(symbol, alternate_object.first).push(extract_params(*alternate_object))
|
57
57
|
end
|
58
58
|
|
59
59
|
define_method("hash_for_#{type}object_path") do |*alternate_object|
|
60
|
-
hash_for_smart_path *object_url_options(symbol, alternate_object.first)
|
60
|
+
hash_for_smart_path *object_url_options(symbol, alternate_object.first).push(extract_params(*alternate_object))
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
-
def new_object_url
|
65
|
-
smart_url *new_object_url_options
|
64
|
+
def new_object_url(*args)
|
65
|
+
smart_url *new_object_url_options.push(extract_params(*args))
|
66
66
|
end
|
67
67
|
|
68
|
-
def new_object_path
|
69
|
-
smart_path *new_object_url_options
|
68
|
+
def new_object_path(*args)
|
69
|
+
smart_path *new_object_url_options.push(extract_params(*args))
|
70
70
|
end
|
71
71
|
|
72
|
-
def hash_for_new_object_url
|
73
|
-
hash_for_smart_url *new_object_url_options
|
72
|
+
def hash_for_new_object_url(*args)
|
73
|
+
hash_for_smart_url *new_object_url_options.push(extract_params(*args))
|
74
74
|
end
|
75
75
|
|
76
|
-
def hash_for_new_object_path
|
77
|
-
hash_for_smart_path *new_object_url_options
|
76
|
+
def hash_for_new_object_path(*args)
|
77
|
+
hash_for_smart_path *new_object_url_options.push(extract_params(*args))
|
78
78
|
end
|
79
79
|
|
80
|
-
def collection_url
|
81
|
-
smart_url *collection_url_options
|
80
|
+
def collection_url(*args)
|
81
|
+
smart_url *collection_url_options.push(extract_params(*args))
|
82
82
|
end
|
83
83
|
|
84
|
-
def collection_path
|
85
|
-
smart_path *collection_url_options
|
84
|
+
def collection_path(*args)
|
85
|
+
smart_path *collection_url_options.push(extract_params(*args))
|
86
86
|
end
|
87
87
|
|
88
|
-
def hash_for_collection_url
|
89
|
-
hash_for_smart_url *collection_url_options
|
88
|
+
def hash_for_collection_url(*args)
|
89
|
+
hash_for_smart_url *collection_url_options.push(extract_params(*args))
|
90
90
|
end
|
91
91
|
|
92
|
-
def hash_for_collection_path
|
93
|
-
hash_for_smart_path *collection_url_options
|
92
|
+
def hash_for_collection_path(*args)
|
93
|
+
hash_for_smart_path *collection_url_options.push(extract_params(*args))
|
94
94
|
end
|
95
95
|
|
96
|
+
def extract_params(*args)
|
97
|
+
params = {}
|
98
|
+
params.merge!(args.last) if args.last.is_a?(Hash)
|
99
|
+
end
|
100
|
+
|
96
101
|
# Used internally to provide the options to smart_url from Urligence.
|
97
102
|
#
|
98
103
|
def collection_url_options
|
data/lib/urligence.rb
CHANGED
@@ -1,23 +1,30 @@
|
|
1
1
|
module Urligence
|
2
2
|
def smart_url(*objects)
|
3
|
-
urligence
|
3
|
+
urligence *attach_params(:nil, :url, *objects)
|
4
4
|
end
|
5
5
|
|
6
6
|
def smart_path(*objects)
|
7
|
-
urligence
|
7
|
+
urligence *attach_params(nil, :path, *objects)
|
8
8
|
end
|
9
9
|
|
10
10
|
def hash_for_smart_url(*objects)
|
11
|
-
urligence
|
11
|
+
urligence *attach_params(:hash_for, :url, *objects)
|
12
12
|
end
|
13
13
|
|
14
14
|
def hash_for_smart_path(*objects)
|
15
|
-
urligence
|
15
|
+
urligence *attach_params(:hash_for, :path, *objects)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Attaches prefix and suffix and appends params
|
19
|
+
def attach_params(prefix, suffix, *objects)
|
20
|
+
params = objects.pop if objects.last.is_a?(Hash)
|
21
|
+
objects.unshift(prefix).push(suffix).push(params)
|
16
22
|
end
|
17
23
|
|
18
24
|
def urligence(*objects)
|
19
|
-
|
20
|
-
|
25
|
+
only_hash = objects.first == :hash_for
|
26
|
+
params = {}
|
27
|
+
params.merge!(objects.pop) if objects.last.is_a?(Hash)
|
21
28
|
|
22
29
|
objects.reject! { |object| object.nil? }
|
23
30
|
|
@@ -31,10 +38,9 @@ module Urligence
|
|
31
38
|
end
|
32
39
|
end
|
33
40
|
|
34
|
-
unless
|
35
|
-
send url_fragments.join("_"), *objects.flatten.select { |obj| !obj.is_a? Symbol }
|
41
|
+
unless only_hash
|
42
|
+
send url_fragments.join("_"), *objects.flatten.select { |obj| !obj.is_a? Symbol }.push(params)
|
36
43
|
else
|
37
|
-
params = {}
|
38
44
|
unparsed_params = objects.select { |obj| !obj.is_a? Symbol }
|
39
45
|
unparsed_params.each_with_index do |obj, i|
|
40
46
|
unless i == (unparsed_params.length-1)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: viva-resource_controller
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.5
|
4
|
+
version: 0.6.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Golick
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-10-01 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|