model_pack 0.9.10 → 0.9.11
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/model_pack/attribute_methods.rb +3 -1
- data/lib/model_pack/version.rb +1 -1
- data/spec/model_pack_spec.rb +36 -14
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a7f884f06e518d29fc6644b38ad37813b3c15e3
|
4
|
+
data.tar.gz: c845a60e80628ad55ef0a2e8775a366808238f61
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c897776daee8e42b74e9b2264702fc58d843e166f4fdd344bafb52bc511c96ecf71d793b51b15b77a23cd1e0f9a2825ab9ae88930c8eab53392f1497e7d9b27
|
7
|
+
data.tar.gz: fdaeb38967e99dd6849d6acefbb776a5e506072f3ffbfd7677767c4f49c78d52b2ecf58fc7dcb4984257ee82e2d87b694de6a0f27d279e7de0b58d83fb9ccbf7
|
@@ -11,7 +11,9 @@ module ModelPack
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def attribute_names
|
14
|
-
|
14
|
+
names = instance_variable_defined?(:@attribute_names) ?
|
15
|
+
instance_variable_get(:@attribute_names) :
|
16
|
+
instance_variable_set(:@attribute_names, superclass.respond_to?(:attribute_names) ? superclass.attribute_names.clone : Array.new)
|
15
17
|
end
|
16
18
|
end
|
17
19
|
|
data/lib/model_pack/version.rb
CHANGED
data/spec/model_pack_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe ModelPack::ClassMethods do
|
4
4
|
|
5
|
-
it "should create model with
|
5
|
+
it "should create model with defaults" do
|
6
6
|
class Point
|
7
7
|
include ModelPack::Document
|
8
8
|
|
@@ -16,14 +16,14 @@ describe ModelPack::ClassMethods do
|
|
16
16
|
expect(point.attributes).to include({x: 0, y: 0})
|
17
17
|
end
|
18
18
|
|
19
|
-
it "should create model
|
19
|
+
it "should create filled model" do
|
20
20
|
point = Point.new(x: 3, y: 5)
|
21
21
|
expect(point.x).to be(3)
|
22
22
|
expect(point.y).to be(5)
|
23
23
|
expect(point.attributes).to include({x: 3, y: 5})
|
24
24
|
end
|
25
25
|
|
26
|
-
it "should
|
26
|
+
it "should change attributes" do
|
27
27
|
point = Point.new(x: 4, y: 6)
|
28
28
|
point.update_attributes(x:3, y:2)
|
29
29
|
expect(point.x).to be(3)
|
@@ -89,7 +89,7 @@ describe ModelPack::ClassMethods do
|
|
89
89
|
expect(json[:points][2]).to include({x: 5, y:5})
|
90
90
|
end
|
91
91
|
|
92
|
-
it "should each attribute
|
92
|
+
it "should use each attribute like writer" do
|
93
93
|
class SecureData
|
94
94
|
include ModelPack::Document
|
95
95
|
|
@@ -121,7 +121,7 @@ describe ModelPack::ClassMethods do
|
|
121
121
|
expect(unsecure_hash).to include(always_string: "55")
|
122
122
|
end
|
123
123
|
|
124
|
-
it "should
|
124
|
+
it "should not allow method with name `method`" do
|
125
125
|
expect {
|
126
126
|
class Request
|
127
127
|
include ModelPack::Document
|
@@ -131,7 +131,7 @@ describe ModelPack::ClassMethods do
|
|
131
131
|
}.to raise_error
|
132
132
|
end
|
133
133
|
|
134
|
-
it "should serialize and
|
134
|
+
it "should serialize and upload model" do
|
135
135
|
polygon = Polygon.new(points: [{x: 3, y: 3}, {x:2, y:1}, {x:4, y:2}])
|
136
136
|
polygon_copy = Polygon.new(polygon.serializable_hash) # or as_json
|
137
137
|
expect(polygon_copy.points).to be_a(Array)
|
@@ -140,7 +140,7 @@ describe ModelPack::ClassMethods do
|
|
140
140
|
end
|
141
141
|
end
|
142
142
|
|
143
|
-
it "should
|
143
|
+
it "should copy model" do
|
144
144
|
polygon = Polygon.new(points: [{x: 3, y: 3}, {x:2, y:1}, {x:4, y:2}])
|
145
145
|
polygon_copy = polygon.copy
|
146
146
|
polygon.points.each_with_index do |point, index|
|
@@ -148,7 +148,7 @@ describe ModelPack::ClassMethods do
|
|
148
148
|
end
|
149
149
|
end
|
150
150
|
|
151
|
-
it "should
|
151
|
+
it "should have nary field" do
|
152
152
|
class Options
|
153
153
|
include ModelPack::Document
|
154
154
|
|
@@ -209,7 +209,7 @@ describe ModelPack::ClassMethods do
|
|
209
209
|
expect(buffer.position).to be(11)
|
210
210
|
end
|
211
211
|
|
212
|
-
it "should have
|
212
|
+
it "should have predicate method" do
|
213
213
|
class OptionsWithPredicate
|
214
214
|
include ModelPack::Document
|
215
215
|
|
@@ -237,7 +237,7 @@ describe ModelPack::ClassMethods do
|
|
237
237
|
expect(owp.load?).to eq('NO')
|
238
238
|
end
|
239
239
|
|
240
|
-
it "should boolean type
|
240
|
+
it "should boolean type to work too" do
|
241
241
|
class BooleanData
|
242
242
|
include ModelPack::Document
|
243
243
|
|
@@ -255,7 +255,7 @@ describe ModelPack::ClassMethods do
|
|
255
255
|
expect(copy_false_data.serializable_hash[:bit]).to be false
|
256
256
|
end
|
257
257
|
|
258
|
-
it "should create unique array for each instance" do
|
258
|
+
it "should create unique array for each of instance" do
|
259
259
|
class ArrayData
|
260
260
|
include ModelPack::Document
|
261
261
|
|
@@ -263,13 +263,13 @@ describe ModelPack::ClassMethods do
|
|
263
263
|
end
|
264
264
|
|
265
265
|
array1 = ArrayData.new
|
266
|
-
array1.data
|
266
|
+
array1.data § 1
|
267
267
|
array2 = ArrayData.new
|
268
268
|
expect(array1.data.size).to be 1
|
269
269
|
expect(array2.data.size).to be 0
|
270
270
|
end
|
271
271
|
|
272
|
-
it "supports boolean as default" do
|
272
|
+
it "supports boolean as default values" do
|
273
273
|
class BooleanData
|
274
274
|
include ModelPack::Document
|
275
275
|
|
@@ -285,7 +285,7 @@ describe ModelPack::ClassMethods do
|
|
285
285
|
expect(data.dynamic_default).to be 6
|
286
286
|
end
|
287
287
|
|
288
|
-
it "
|
288
|
+
it "has a class in the model" do
|
289
289
|
class NestedObject
|
290
290
|
include ModelPack::Document
|
291
291
|
attribute :a, default: 5
|
@@ -294,9 +294,31 @@ describe ModelPack::ClassMethods do
|
|
294
294
|
class ParentObject
|
295
295
|
include ModelPack::Document
|
296
296
|
object :nested, class_name: NestedObject, as: NestedObject
|
297
|
+
attribute :b, default: 1
|
297
298
|
end
|
298
299
|
|
299
300
|
parent = ParentObject.new
|
300
301
|
expect(parent.nested.a).to be 5
|
301
302
|
end
|
303
|
+
|
304
|
+
it "inherits another document" do
|
305
|
+
class BaseDocument
|
306
|
+
include ModelPack::Document
|
307
|
+
attribute :param, default: 'val'
|
308
|
+
end
|
309
|
+
|
310
|
+
class CustomDocument < BaseDocument
|
311
|
+
include ModelPack::Document
|
312
|
+
attribute :first, default: 'foo'
|
313
|
+
end
|
314
|
+
|
315
|
+
class AnotherDocument < BaseDocument
|
316
|
+
include ModelPack::Document
|
317
|
+
attribute :second, default: 'bar'
|
318
|
+
end
|
319
|
+
|
320
|
+
expect(BaseDocument.new.attributes).to eq(param: 'val');
|
321
|
+
expect(CustomDocument.new.attributes).to eq(param: 'val', first: 'foo');
|
322
|
+
expect(AnotherDocument.new.attributes).to eq(param: 'val', second: 'bar');
|
323
|
+
end
|
302
324
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: model_pack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- inre
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -96,10 +96,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
96
|
version: 2.3.0
|
97
97
|
requirements: []
|
98
98
|
rubyforge_project:
|
99
|
-
rubygems_version: 2.
|
99
|
+
rubygems_version: 2.5.1
|
100
100
|
signing_key:
|
101
101
|
specification_version: 4
|
102
102
|
summary: Model Pack – simple models
|
103
103
|
test_files:
|
104
104
|
- spec/model_pack_spec.rb
|
105
105
|
- spec/spec_helper.rb
|
106
|
+
has_rdoc:
|