dagger 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 400789f6c3710c704d0336c5c68d287124d439e0
4
- data.tar.gz: 87b3fab878972ef9acfab1d63b8f23e50ce78ddc
2
+ SHA256:
3
+ metadata.gz: 4bfc1ae0c456b34133f1193441ade9ec29aff0a12c8cd3d5789431095e0b9460
4
+ data.tar.gz: 4793e4ca427ee9ed39dd93b0b3eb0055023a3fcbacb2e168e1e1dc91c56ae988
5
5
  SHA512:
6
- metadata.gz: a665605c3ff2136a18b780b8bd641d652ebe6252359285a11f051de485fd8e289f065c335f1706ace41552a7dda5b79e5de068e4e360e7d7cb41ea7c652e6f38
7
- data.tar.gz: f61b5b2517b2c52a325d631c121a8a8d203fd74fc2716a154ebffa3d09f93373962047b699faa34db70119e38ad07d894187bdfb9cec593b695afca16130fc17
6
+ metadata.gz: dd762ea62c7d7a5a10d8c953900c7875aefa4e4b8c983b8b198bdbbf9083d218b8b8aad156d89ae30a457be3f7e0cd51f4dbb0d35ff92bb7ef6032d28e98a302
7
+ data.tar.gz: 980873071693904349794ca12d5b22ad791ba52ac658ce8225da61fc94faaa4e8a4529c30fbb6cd6be3945d6a83cc31fb4bb5288f957f8d8a309646712b592be
@@ -1,6 +1,14 @@
1
1
  require 'ox'
2
2
 
3
3
  XMLNode = Struct.new(:name, :text, :attributes, :children) do
4
+
5
+ alias_method :to_s, :text
6
+ alias_method :value, :text
7
+
8
+ def to_hash
9
+ self # for backwards compat
10
+ end
11
+
4
12
  # this lets us traverse an parsed object like this:
5
13
  # doc[:child][:grandchild].value
6
14
  def [](key)
@@ -8,6 +16,22 @@ XMLNode = Struct.new(:name, :text, :attributes, :children) do
8
16
  found.empty? ? nil : found.size == 1 ? found.first : found
9
17
  end
10
18
 
19
+ def dig(*paths)
20
+ list = Array(paths).flatten
21
+ res = list.reduce([self]) do |parents, key|
22
+
23
+ if parents
24
+ found = parents.map do |parent|
25
+ parent.children.select { |node| node.name.to_s == key.to_s }
26
+ end.flatten
27
+
28
+ found.any? ? found : nil
29
+ end
30
+ end
31
+
32
+ res.nil? || res.empty? ? nil : res.size == 1 ? res.first : res
33
+ end
34
+
11
35
  # returns first matching node
12
36
  def first(key)
13
37
  if found = self[key]
@@ -23,7 +23,9 @@ class Parsers
23
23
  alias_method :application_x_javascript, :application_json
24
24
 
25
25
  def text_xml(body)
26
- Ox.parse(body)
26
+ if res = Ox.parse(body)
27
+ res.to_hash
28
+ end
27
29
  rescue Ox::ParseError
28
30
  nil
29
31
  end
@@ -1,7 +1,7 @@
1
1
  module Dagger
2
2
  MAJOR = 1
3
- MINOR = 0
4
- PATCH = 2
3
+ MINOR = 1
4
+ PATCH = 0
5
5
 
6
6
  VERSION = [MAJOR, MINOR, PATCH].join('.')
7
7
  end
@@ -94,18 +94,23 @@ describe 'Parsers' do
94
94
 
95
95
  describe 'valid data' do
96
96
  before do
97
- allow(fake_resp).to receive(:body).and_return('<xml><foo>123</foo></xml>')
97
+ allow(fake_resp).to receive(:body).and_return('<xml><foo>123</foo><bar><test>456</test></bar></xml>')
98
98
  end
99
99
 
100
- it 'returns nil' do
100
+ it 'returns XMLNode obj' do
101
101
  res = send_request.data
102
- expect(res).to be_a(Ox::Element)
103
- expect(res.foo).to be_a(Ox::Element)
104
- expect(res.foo.text).to eql('123')
102
+ expect(res).to be_a(XMLNode)
103
+ expect(res.to_hash).to eql(res)
104
+ expect(res['foo']).to be_a(XMLNode)
105
+ expect(res['foo'].text).to eql('123')
106
+
107
+ # test dig behaviour
108
+ expect(res.dig('xxx', 'test', '111')).to be(nil)
109
+ expect(res.dig('bar', 'test')).to be_a(XMLNode)
110
+ expect(res.dig('bar', 'test').to_s).to eql('456')
105
111
  end
106
112
  end
107
113
 
108
-
109
114
  describe 'XMLNode extension' do
110
115
 
111
116
  xml = %(
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dagger
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomás Pollak
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-02 00:00:00.000000000 Z
11
+ date: 2018-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -135,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
135
  version: 1.3.6
136
136
  requirements: []
137
137
  rubyforge_project: dagger
138
- rubygems_version: 2.5.1
138
+ rubygems_version: 2.7.3
139
139
  signing_key:
140
140
  specification_version: 4
141
141
  summary: Simplified Net::HTTP wrapper.