rest_model 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +3 -27
- data/examples/initialize/embeds_many.rb +2 -1
- data/examples/initialize/embeds_one.rb +2 -1
- data/examples/properties/collections.rb +3 -3
- data/examples/properties/with_if.rb +4 -2
- data/examples/summarization/simple.rb +5 -5
- data/lib/rest_model/key/embeddable/sender.rb +3 -3
- data/lib/rest_model/source/sender.rb +1 -1
- data/lib/rest_model/version.rb +1 -1
- metadata +15 -16
data/README.md
CHANGED
@@ -23,10 +23,10 @@
|
|
23
23
|
property :number
|
24
24
|
property :balance, type: Float
|
25
25
|
property :type, values: {gold: '01', platinum: '02'}
|
26
|
-
|
26
|
+
|
27
27
|
embeds_one :electronic_card
|
28
28
|
embeds_many :transactions
|
29
|
-
|
29
|
+
|
30
30
|
belongs_to :customer
|
31
31
|
has_one :manager
|
32
32
|
has_many :tickets
|
@@ -155,7 +155,7 @@ Just define your `User` class like this:
|
|
155
155
|
|
156
156
|
class Order < RestModel
|
157
157
|
id
|
158
|
-
embeds_many :items,
|
158
|
+
embeds_many :items, class_name: 'order_items'
|
159
159
|
end
|
160
160
|
|
161
161
|
{
|
@@ -209,30 +209,6 @@ Just define your `User` class like this:
|
|
209
209
|
]
|
210
210
|
}
|
211
211
|
|
212
|
-
### embedding relations
|
213
|
-
|
214
|
-
If you want your api to handle `http://app/api/users/19371897318937?include[]=avatar&include[]=guilda`
|
215
|
-
|
216
|
-
user = User.from_source(input, include: [avatar_input, guilda_input]).first
|
217
|
-
|
218
|
-
{
|
219
|
-
id: '19837139879',
|
220
|
-
login: 'jsmith180',
|
221
|
-
avatar: {
|
222
|
-
name: 'K1ll3r',
|
223
|
-
specie: 'WTF'
|
224
|
-
},
|
225
|
-
guilda: {
|
226
|
-
name: 'K1ll3rs'
|
227
|
-
},
|
228
|
-
link: [
|
229
|
-
{
|
230
|
-
rel: 'achievements',
|
231
|
-
href: 'http://app/api/users/19837139879/achievements'
|
232
|
-
}
|
233
|
-
]
|
234
|
-
}
|
235
|
-
|
236
212
|
### [See more examples here](https://github.com/rodrigues/rest_client/tree/master/examples).
|
237
213
|
|
238
214
|
## Installation
|
@@ -5,7 +5,7 @@ class Customer < RestModel
|
|
5
5
|
end
|
6
6
|
|
7
7
|
@customers = Customer.from_source!([{login: "jackiechan2010"},
|
8
|
-
|
9
|
-
|
8
|
+
{login: "brucelee"},
|
9
|
+
{login: "vcr2"}])
|
10
10
|
|
11
|
-
@customers.map
|
11
|
+
@customers.map &method(:inspect_rest_model)
|
@@ -9,13 +9,15 @@ end
|
|
9
9
|
@root_with_description = Customer.from_source!({
|
10
10
|
login: 2000,
|
11
11
|
password: "abc",
|
12
|
-
description: "description"
|
12
|
+
description: "description"
|
13
|
+
}).first
|
13
14
|
|
14
15
|
inspect_rest_model(@root_with_description)
|
15
16
|
|
16
17
|
@root_without_description = Customer.from_source!({
|
17
18
|
login: 2000,
|
18
19
|
password: "abcd",
|
19
|
-
description: "some text II"
|
20
|
+
description: "some text II"
|
21
|
+
}).first
|
20
22
|
|
21
23
|
inspect_rest_model(@root_without_description)
|
@@ -9,11 +9,11 @@ class Customer < RestModel
|
|
9
9
|
end
|
10
10
|
|
11
11
|
input = {
|
12
|
-
"id" =>
|
13
|
-
"login" =>
|
14
|
-
"name" =>
|
15
|
-
"postal_code" =>
|
16
|
-
"email" =>
|
12
|
+
"id" => 138911938,
|
13
|
+
"login" => 'jackiechan2010',
|
14
|
+
"name" => 'jackie chan',
|
15
|
+
"postal_code" => '05492-092',
|
16
|
+
"email" => 'jachan@gmail.com',
|
17
17
|
"secondary_email" => 'jackiepeligroso@yahoo.com'
|
18
18
|
}
|
19
19
|
|
@@ -21,7 +21,7 @@ class RestModel
|
|
21
21
|
: one? ? embeds_one_source(value, options)
|
22
22
|
: embeds_many_source(value, options)
|
23
23
|
else
|
24
|
-
source.merge!(value.to_source(options))
|
24
|
+
source.merge!(value.to_source!(options))
|
25
25
|
end
|
26
26
|
|
27
27
|
source
|
@@ -39,7 +39,7 @@ class RestModel
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def embeds_one_source(value, options)
|
42
|
-
value.to_source(options)
|
42
|
+
value.to_source!(options)
|
43
43
|
end
|
44
44
|
|
45
45
|
def embeds_many_source(value, options)
|
@@ -47,7 +47,7 @@ class RestModel
|
|
47
47
|
|
48
48
|
source = value.each_with_index.map do |item, index|
|
49
49
|
begin
|
50
|
-
item.to_source(options)
|
50
|
+
item.to_source!(options)
|
51
51
|
rescue RestModel::SourceError => e
|
52
52
|
errors[self.name] ||= {}
|
53
53
|
errors[self.name][index] = e.message
|
data/lib/rest_model/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rest_model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,11 +11,11 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2012-04-26 00:00:00.000000000Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activesupport
|
18
|
-
requirement: &
|
18
|
+
requirement: &70119449382520 !ruby/object:Gem::Requirement
|
19
19
|
none: false
|
20
20
|
requirements:
|
21
21
|
- - ~>
|
@@ -23,10 +23,10 @@ dependencies:
|
|
23
23
|
version: '3.0'
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
|
-
version_requirements: *
|
26
|
+
version_requirements: *70119449382520
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: i18n
|
29
|
-
requirement: &
|
29
|
+
requirement: &70119449382020 !ruby/object:Gem::Requirement
|
30
30
|
none: false
|
31
31
|
requirements:
|
32
32
|
- - ! '>='
|
@@ -34,10 +34,10 @@ dependencies:
|
|
34
34
|
version: '0.5'
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
|
-
version_requirements: *
|
37
|
+
version_requirements: *70119449382020
|
38
38
|
- !ruby/object:Gem::Dependency
|
39
39
|
name: rspec
|
40
|
-
requirement: &
|
40
|
+
requirement: &70119449381560 !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
43
|
- - ~>
|
@@ -45,10 +45,10 @@ dependencies:
|
|
45
45
|
version: '2.6'
|
46
46
|
type: :development
|
47
47
|
prerelease: false
|
48
|
-
version_requirements: *
|
48
|
+
version_requirements: *70119449381560
|
49
49
|
- !ruby/object:Gem::Dependency
|
50
50
|
name: guard
|
51
|
-
requirement: &
|
51
|
+
requirement: &70119443530980 !ruby/object:Gem::Requirement
|
52
52
|
none: false
|
53
53
|
requirements:
|
54
54
|
- - ~>
|
@@ -56,10 +56,10 @@ dependencies:
|
|
56
56
|
version: '0.5'
|
57
57
|
type: :development
|
58
58
|
prerelease: false
|
59
|
-
version_requirements: *
|
59
|
+
version_requirements: *70119443530980
|
60
60
|
- !ruby/object:Gem::Dependency
|
61
61
|
name: guard-rspec
|
62
|
-
requirement: &
|
62
|
+
requirement: &70119443530520 !ruby/object:Gem::Requirement
|
63
63
|
none: false
|
64
64
|
requirements:
|
65
65
|
- - ~>
|
@@ -67,10 +67,10 @@ dependencies:
|
|
67
67
|
version: '0.4'
|
68
68
|
type: :development
|
69
69
|
prerelease: false
|
70
|
-
version_requirements: *
|
70
|
+
version_requirements: *70119443530520
|
71
71
|
- !ruby/object:Gem::Dependency
|
72
72
|
name: growl
|
73
|
-
requirement: &
|
73
|
+
requirement: &70119443530060 !ruby/object:Gem::Requirement
|
74
74
|
none: false
|
75
75
|
requirements:
|
76
76
|
- - ~>
|
@@ -78,7 +78,7 @@ dependencies:
|
|
78
78
|
version: '1.0'
|
79
79
|
type: :development
|
80
80
|
prerelease: false
|
81
|
-
version_requirements: *
|
81
|
+
version_requirements: *70119443530060
|
82
82
|
description: ''
|
83
83
|
email:
|
84
84
|
- victorcrodrigues@gmail.com
|
@@ -245,7 +245,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
245
245
|
version: '0'
|
246
246
|
requirements: []
|
247
247
|
rubyforge_project:
|
248
|
-
rubygems_version: 1.8.
|
248
|
+
rubygems_version: 1.8.15
|
249
249
|
signing_key:
|
250
250
|
specification_version: 3
|
251
251
|
summary: ''
|
@@ -288,4 +288,3 @@ test_files:
|
|
288
288
|
- spec/unit/serialization/string_spec.rb
|
289
289
|
- spec/unit/source/path_spec.rb
|
290
290
|
- spec/unit/source/retriever_spec.rb
|
291
|
-
has_rdoc:
|