perry 0.6.1 → 0.6.2

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.
@@ -14,11 +14,11 @@ module Perry::Adapters
14
14
  attr_reader :last_response
15
15
 
16
16
  def read(options)
17
- get_http(options[:relation]).parsed.tap do |result|
18
- unless result.is_a?(Array)
19
- raise Perry::MalformedResponse, "Expected instance of Array got #{result.inspect}"
20
- end
17
+ response = get_http(options[:relation])
18
+ unless response.parsed.is_a?(Array)
19
+ raise Perry::MalformedResponse, "Expected instance of Array got '#{response.raw.inspect}'"
21
20
  end
21
+ response.array_attributes
22
22
  end
23
23
 
24
24
  def write(options)
@@ -49,11 +49,15 @@ module Perry::Persistence
49
49
 
50
50
  def model_attributes
51
51
  # return the inner hash if nested
52
- if parsed_hash.keys.size == 1 && parsed_hash[parsed_hash.keys.first].is_a?(Hash)
53
- parsed_hash[parsed_hash.keys.first]
52
+ extract_attributes(parsed_hash)
53
+ end
54
+
55
+ def array_attributes
56
+ if parsed.is_a?(Array)
57
+ parsed.collect { |item| item.is_a?(Hash) ? extract_attributes(item) : item }
54
58
  else
55
- parsed_hash
56
- end.symbolize_keys
59
+ []
60
+ end
57
61
  end
58
62
 
59
63
  def errors
@@ -62,6 +66,14 @@ module Perry::Persistence
62
66
 
63
67
  protected
64
68
 
69
+ def extract_attributes(hash)
70
+ if hash.keys.size == 1 && hash[hash.keys.first].is_a?(Hash)
71
+ hash[hash.keys.first]
72
+ else
73
+ hash
74
+ end.symbolize_keys
75
+ end
76
+
65
77
  def parsed_hash
66
78
  if parsed.is_a?(Hash)
67
79
  parsed
data/lib/perry/version.rb CHANGED
@@ -3,7 +3,7 @@ module Perry
3
3
 
4
4
  MAJOR = 0
5
5
  MINOR = 6
6
- TINY = 1
6
+ TINY = 2
7
7
 
8
8
  def self.to_s # :nodoc:
9
9
  [MAJOR, MINOR, TINY].join('.')
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: perry
3
3
  version: !ruby/object:Gem::Version
4
- hash: 5
4
+ hash: 3
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 1
10
- version: 0.6.1
9
+ - 2
10
+ version: 0.6.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Travis Petticrew
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-25 00:00:00 Z
18
+ date: 2011-06-13 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: shoulda