sawyer 0.5.5 → 0.6.0
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 +4 -4
- data/lib/sawyer.rb +1 -1
- data/lib/sawyer/resource.rb +7 -0
- data/test/resource_test.rb +19 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80567e1f99aebed1ceebd9a780b762ccec70f131
|
4
|
+
data.tar.gz: 5d655e43363373e8c43a3ec736b51273509e0576
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23547dec9018b054060a2580548b5c0b0df4bc9564dd7191d4d60ff11263464aa77ca83ea432dc4c8185ded9a5b4837e253d7b23518de093925b6cfd3d5bb17d
|
7
|
+
data.tar.gz: 83341503aa9ece0200d92a8b75e028f7cfff4c93ca66ea852857d58b0f2312f4da5df5353910c0323cbf1b6a8fbebd78fde7356bf34200f80b95a1c3ab1c4e6b
|
data/lib/sawyer.rb
CHANGED
data/lib/sawyer/resource.rb
CHANGED
@@ -5,6 +5,7 @@ module Sawyer
|
|
5
5
|
attr_reader :attrs
|
6
6
|
alias to_hash attrs
|
7
7
|
alias to_h attrs
|
8
|
+
include Enumerable
|
8
9
|
|
9
10
|
# Initializes a Resource with the given data.
|
10
11
|
#
|
@@ -120,6 +121,10 @@ module Sawyer
|
|
120
121
|
to_attrs.respond_to?(:pretty_inspect) ? to_attrs.pretty_inspect : to_attrs.inspect
|
121
122
|
end
|
122
123
|
|
124
|
+
def each(&block)
|
125
|
+
@attrs.each(&block)
|
126
|
+
end
|
127
|
+
|
123
128
|
# private
|
124
129
|
def to_yaml_properties
|
125
130
|
[:@attrs, :@_fields, :@_rels]
|
@@ -130,6 +135,8 @@ module Sawyer
|
|
130
135
|
hash.keys.each do |k|
|
131
136
|
if hash[k].is_a?(Sawyer::Resource)
|
132
137
|
hash[k] = hash[k].to_attrs
|
138
|
+
elsif hash[k].is_a?(Array) && hash[k].all?{|el| el.is_a?(Sawyer::Resource)}
|
139
|
+
hash[k] = hash[k].collect{|el| el.to_attrs}
|
133
140
|
end
|
134
141
|
end
|
135
142
|
hash
|
data/test/resource_test.rb
CHANGED
@@ -128,6 +128,12 @@ module Sawyer
|
|
128
128
|
assert_equal hash, res.to_h
|
129
129
|
end
|
130
130
|
|
131
|
+
def test_to_attrs_for_sawyer_resource_arrays
|
132
|
+
res = Resource.new @agent, :a => 1, :b => [Resource.new(@agent, :a => 2)]
|
133
|
+
hash = {:a => 1, :b => [{:a => 2}]}
|
134
|
+
assert_equal hash, res.to_attrs
|
135
|
+
end
|
136
|
+
|
131
137
|
def test_handle_hash_notation_with_string_key
|
132
138
|
res = Resource.new @agent, :a => 1
|
133
139
|
assert_equal 1, res['a']
|
@@ -176,5 +182,18 @@ module Sawyer
|
|
176
182
|
resource = Resource.new @agent, :a => 1
|
177
183
|
assert_equal "{:a=>1}\n", resource.inspect
|
178
184
|
end
|
185
|
+
|
186
|
+
def test_each
|
187
|
+
resource = Resource.new @agent, { :a => 1, :b => 2 }
|
188
|
+
output = []
|
189
|
+
resource.each { |k,v| output << [k,v] }
|
190
|
+
assert_equal [[:a, 1], [:b, 2]], output
|
191
|
+
end
|
192
|
+
|
193
|
+
def test_enumerable
|
194
|
+
resource = Resource.new @agent, { :a => 1, :b => 2 }
|
195
|
+
enum = resource.map
|
196
|
+
assert_equal Enumerator, enum.class
|
197
|
+
end
|
179
198
|
end
|
180
199
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sawyer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rick Olson
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-12-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|