almodovar 1.5.2 → 1.5.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f0f8ff4c7ab0601687b70e10972f57e056f59010
4
- data.tar.gz: ba87147194a45b40a76dee36bb775c976905e4b0
3
+ metadata.gz: b0070e4a31dadf08f8c1c4419f1cf9adaae3cfb3
4
+ data.tar.gz: e7749dc727492f4362a89d9f7e8f374c336b4a28
5
5
  SHA512:
6
- metadata.gz: ec95efa37a20b829750b2d5392520fb06e90d5bcb9f9a0a3011b873af77bca3de72921338bd25b3cdb633c69fa96fbaf9344b73d9ecb80e59220ed7644b9e042
7
- data.tar.gz: bbae4a872613753d8f84c2d228020b5d166bd37df13fda422beec9eddbbf2b6de05f1ad86219e6ef97a46dc8378e0464cb13e12346adc32df91c8ed874eec847
6
+ metadata.gz: 2d368d1b28e8e011828ccaf01fa735facb74f012323b799c3b24c74baee7b6278606bc3689678b353c732b62d556a43ae1c8b2862eb517190c5019de61f1ed04
7
+ data.tar.gz: d8306c513cd1a59226374c935b2a34e4d0df44ca556082fe01963cb683ad7f7be6f257447d4678f3710b9d5d89846f42208e91ec802e5766e04cbdeff33694df
@@ -1,17 +1,17 @@
1
1
  module Almodovar
2
2
  class SingleResource
3
3
  include HttpAccessor
4
-
4
+
5
5
  undef_method :id if instance_methods.include?("id")
6
6
  undef_method :type if instance_methods.include?("type")
7
-
7
+
8
8
  def initialize(url, auth, xml = nil, options = {})
9
9
  @url = url
10
10
  @auth = auth
11
11
  @xml = xml
12
12
  @options = options
13
13
  end
14
-
14
+
15
15
  def update(attrs = {})
16
16
  raise ArgumentError.new("You must specify one only root element which is the type of resource (e.g. `:project => { :name => 'Wadus' }` instead of just `:name => 'Wadus'`)") if attrs.size > 1
17
17
  root, body = attrs.first
@@ -19,48 +19,61 @@ module Almodovar
19
19
  check_errors(response, @url)
20
20
  @xml = Nokogiri::XML.parse(response.body).root
21
21
  end
22
-
22
+
23
23
  def delete
24
24
  check_errors(http.delete(@url), @url)
25
25
  end
26
-
26
+
27
27
  def url
28
28
  @url ||= xml.at_xpath("./link[@rel='self']").try(:[], "href")
29
29
  end
30
-
30
+
31
+ def to_hash
32
+ xml_without_type = xml.dup.tap do |xml|
33
+ xml.delete("type")
34
+ end
35
+
36
+ if xml_without_type.content.strip.empty?
37
+ {}
38
+ else
39
+ xml_hash = Hash.from_xml(xml_without_type.to_s)
40
+ xml_hash[xml_without_type.name]
41
+ end
42
+ end
43
+
31
44
  delegate :to_xml, :to => :xml
32
45
  alias_method :inspect, :to_xml
33
-
46
+
34
47
  def [](key) # for resources with type "document"
35
48
  return super unless xml.at_xpath("/*[@type='document']")
36
49
  Hash.from_xml(xml.to_xml).values.first[key]
37
50
  end
38
-
51
+
39
52
  def respond_to?(meth, include_all=false)
40
53
  super || (node(meth) != nil) || (link(meth) != nil)
41
54
  end
42
-
55
+
43
56
  private
44
-
57
+
45
58
  def method_missing(meth, *args, &blk)
46
59
  if node = node(meth)
47
60
  return node['type'] == 'document' ? Resource.from_xml(node.to_xml) : node_text(node)
48
61
  end
49
-
62
+
50
63
  link = link(meth)
51
64
  return Resource.new(link["href"], @auth, link.at_xpath("./*"), *args) if link
52
-
65
+
53
66
  super
54
67
  end
55
-
68
+
56
69
  def node(name)
57
70
  xml.at_xpath("./*[name()='#{name}' or name()='#{attribute_name(name)}']")
58
71
  end
59
-
72
+
60
73
  def link(name)
61
74
  xml.at_xpath("./link[@rel='#{name}' or @rel='#{attribute_name(name)}']")
62
75
  end
63
-
76
+
64
77
  def node_text(node)
65
78
  case node['type']
66
79
  when "integer"
@@ -75,10 +88,10 @@ module Almodovar
75
88
  node.text
76
89
  end
77
90
  end
78
-
91
+
79
92
  def attribute_name(attribute)
80
93
  attribute.to_s.gsub('_', '-')
81
94
  end
82
-
95
+
83
96
  end
84
- end
97
+ end
@@ -1,3 +1,3 @@
1
1
  module Almodovar
2
- VERSION = '1.5.2'
2
+ VERSION = '1.5.3'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: almodovar
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.2
4
+ version: 1.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - BeBanjo S.L.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-07 00:00:00.000000000 Z
11
+ date: 2016-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: builder
@@ -134,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
134
  version: '0'
135
135
  requirements: []
136
136
  rubyforge_project:
137
- rubygems_version: 2.5.1
137
+ rubygems_version: 2.4.5
138
138
  signing_key:
139
139
  specification_version: 4
140
140
  summary: BeBanjo API client