almodovar 0.5.3 → 0.5.4
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/almodovar.rb +15 -8
- metadata +4 -4
data/lib/almodovar.rb
CHANGED
@@ -68,9 +68,14 @@ module Almodovar
|
|
68
68
|
@object_type ||= URI.parse(@url).path.split("/")[-2].singularize
|
69
69
|
end
|
70
70
|
|
71
|
+
def [](key) # for resources with type "document"
|
72
|
+
return super unless xml.at_xpath("/*[@type='document']")
|
73
|
+
Hash.from_xml(xml.to_xml).values.first[key]
|
74
|
+
end
|
75
|
+
|
71
76
|
def method_missing(meth, *args, &blk)
|
72
77
|
document = xml.at_xpath("./*[(name()='#{meth}' or name()='#{attribute_name(meth)}') and @type='document']")
|
73
|
-
return
|
78
|
+
return Resource.from_xml(document.to_xml) if document
|
74
79
|
|
75
80
|
attribute = xml.at_xpath("./*[name()='#{meth}' or name()='#{attribute_name(meth)}']")
|
76
81
|
return node_text(attribute) if attribute
|
@@ -153,19 +158,21 @@ module Almodovar
|
|
153
158
|
@resource_object.send(meth, *args, &blk)
|
154
159
|
end
|
155
160
|
|
156
|
-
def resource_class(meth)
|
157
|
-
@resource_class ||=
|
158
|
-
ResourceCollection
|
159
|
-
else
|
160
|
-
SingleResource
|
161
|
-
end
|
161
|
+
def resource_class(meth, *args)
|
162
|
+
@resource_class ||= collection_call?(meth, *args) ? ResourceCollection : SingleResource
|
162
163
|
end
|
163
164
|
|
164
165
|
def get!
|
165
166
|
klass = xml['type'] == 'array' ? ResourceCollection : SingleResource
|
166
167
|
@resource_object = klass.new(@url, @auth, @xml, @options)
|
167
168
|
end
|
168
|
-
|
169
|
+
|
170
|
+
private
|
171
|
+
|
172
|
+
def collection_call?(meth, *args)
|
173
|
+
(Array.instance_methods + ["create"] - ["delete", "id", "[]"]).include?(meth.to_s) ||
|
174
|
+
(meth.to_s == "[]" && args.size == 1 && args.first.is_a?(Fixnum))
|
175
|
+
end
|
169
176
|
end
|
170
177
|
|
171
178
|
def self.Resource(url, auth, params = {})
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: almodovar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 3
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 5
|
9
|
-
-
|
10
|
-
version: 0.5.
|
9
|
+
- 4
|
10
|
+
version: 0.5.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- BeBanjo S.L.
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-08-
|
18
|
+
date: 2010-08-26 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|