simplify_api 0.1.3 → 0.1.4

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
2
  SHA256:
3
- metadata.gz: 10ee721abac5c00b5a8a832164ea083368e7092535b7238f2d22f37e05fdd109
4
- data.tar.gz: 186733c3df4495ac3c3e3abb7eab1af2e5aaf01c0f0be5e455de49086f4ae00c
3
+ metadata.gz: 3d5c993f71e29fbaa2e17f68e43de75d08c4a13b42bb05e0b7b52f3a076de633
4
+ data.tar.gz: a6e03c193ac868b30165c4319c2c1a587531baf45c39b970c7b0011a4b1d0978
5
5
  SHA512:
6
- metadata.gz: 052a2bbf129a7d62c65c3bea2dc9c1bf081208ca62111be3e6cb7674a231b99105ac65d23b51369765f9f2fd7fd53c838acd78bf5ba3b86ca0d59e287cf25e4a
7
- data.tar.gz: aa6195bbc6e131f1408024c9fd247f62cca8e8aff327006fd7de30b24f26abc0eae048cc8f6e40deec921daaa300d0a03b9e17731fd1c97d1591b5a294cd8dc8
6
+ metadata.gz: 513ca3a6d2e76ec876a0ed9983476d6f8c04cefa11f640c5e5ec6699ba1dc58f9a09c4b5e328689c6f6d049948d34d3d28abb022fd96284c854a94530e808775
7
+ data.tar.gz: 7891192f811ad08bc06619e5e27d8eb0ad9ea65aac4dc7bf0d623e33d0fedbdaa9984631f2239a27aaab885959da2ad6d03c8c860bb4511f98b665d1ffe7286b
@@ -23,7 +23,7 @@ module SimplifyApi
23
23
 
24
24
  attributes[attr] = {
25
25
  name: attr.to_s,
26
- type: type.class == Class ? type : (type.class == Array ? Array : Object),
26
+ type: { Class => type, Array => Array }[type.class] || Object,
27
27
  params: args
28
28
  }
29
29
  attributes[attr]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SimplifyApi
4
- VERSION = '0.1.3'
4
+ VERSION = '0.1.4'
5
5
  end
@@ -92,8 +92,6 @@ describe SimplifyApi do
92
92
  "English",
93
93
  "German" ]
94
94
  }))
95
-
96
- puts "JSON: #{json_value}"
97
95
  subject = Test.new(json_value)
98
96
 
99
97
  expect(subject.name).to eq "John Doe"
@@ -102,4 +100,38 @@ describe SimplifyApi do
102
100
  expect(subject.languages).to have(2).languages
103
101
  end
104
102
  end
103
+
104
+ describe "with nested classes" do
105
+ before(:all) do
106
+ class Location
107
+ include SimplifyApi
108
+ attribute :title, String, mandatory: true
109
+ attribute :address, String
110
+ attribute :city, String
111
+ end
112
+
113
+ class User
114
+ include SimplifyApi
115
+ attribute :name, String, mandatory: true
116
+ attribute :locations, [Location]
117
+ end
118
+ end
119
+
120
+ it "should instatiate nested classes from JSON" do
121
+ json_value = JSON.parse(%q({
122
+ "name": "John Doe",
123
+ "locations": [
124
+ { "title": "Home", "address": "Elm Street", "city": "New York" },
125
+ { "title": "Office", "address": "White House Street", "city": "Washington DC" }
126
+ ]
127
+ }))
128
+ subject = User.new(json_value)
129
+
130
+ expect(subject.name).to eq "John Doe"
131
+ expect(subject.locations).to have(2).locations
132
+ expect(subject.locations[0].class).to be Location
133
+ expect(subject.locations[0].title).to eq "Home"
134
+ expect(subject.locations[1].title).to eq "Office"
135
+ end
136
+ end
105
137
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simplify_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rodrigo Garcia Couto