model_pack 0.9.6 → 0.9.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/model_pack/class_methods.rb +2 -3
- data/lib/model_pack/constructor.rb +2 -0
- data/lib/model_pack/version.rb +1 -1
- data/model_pack.gemspec +3 -3
- data/spec/model_pack_spec.rb +7 -56
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc4201ba6cb9b884ee4fefdcd9aacb0c1dd87788
|
4
|
+
data.tar.gz: e3c63faa6d018537021f723d131e1a53955cbbb6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 08f774a99e8ae7a4bde8587d737dc1ed60fc17d55f2af435dcdcd9d35b56004c579d004158417dc9c5ad11d666c3a41a2448de7950fa12f3ea00b2766df9319a
|
7
|
+
data.tar.gz: bb1db9adae93f9b6db89739515933698721da24f5685767a26f4afbb0748ebfe771f9cad88d6eaedbd63a62f7aa415b46b02389c4f1b317b32bed78763e37aee
|
data/README.md
CHANGED
@@ -124,7 +124,7 @@ puts unsecure_hash
|
|
124
124
|
|
125
125
|
## Contributing
|
126
126
|
|
127
|
-
1. Fork it ( https://github.com/
|
127
|
+
1. Fork it ( https://github.com/inre/model_pack/fork )
|
128
128
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
129
129
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
130
130
|
4. Push to the branch (`git push origin my-new-feature`)
|
@@ -14,12 +14,11 @@ module ModelPack
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def attribute_reader(name, default: nil, as: nil, serialize: nil, predicate: nil)
|
17
|
-
|
18
|
-
default_value = default_dup || as
|
17
|
+
default_value = default.dup rescue default
|
19
18
|
|
20
19
|
define_method name do
|
21
20
|
instance_variable_defined?("@#{name}") ?
|
22
|
-
instance_variable_get("@#{name}") : instance_variable_set("@#{name}", (
|
21
|
+
instance_variable_get("@#{name}") : instance_variable_set("@#{name}", (as ? as.new : default_value))
|
23
22
|
end
|
24
23
|
|
25
24
|
# define predicate method if required
|
data/lib/model_pack/version.rb
CHANGED
data/model_pack.gemspec
CHANGED
@@ -6,9 +6,9 @@ require 'model_pack/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "model_pack"
|
8
8
|
spec.version = ModelPack::VERSION
|
9
|
-
spec.authors = ["
|
10
|
-
spec.email = ["
|
11
|
-
spec.summary = %q{Model Pack – simple
|
9
|
+
spec.authors = ["inre"]
|
10
|
+
spec.email = ["inre.strom@gmail.com"]
|
11
|
+
spec.summary = %q{Model Pack – simple models}
|
12
12
|
#spec.description = %q{TODO: Write a longer description. Optional.}
|
13
13
|
spec.homepage = ""
|
14
14
|
spec.license = "MIT"
|
data/spec/model_pack_spec.rb
CHANGED
@@ -237,26 +237,6 @@ describe ModelPack::ClassMethods do
|
|
237
237
|
expect(owp.load?).to eq('NO')
|
238
238
|
end
|
239
239
|
|
240
|
-
it "should have predicate for nested object" do
|
241
|
-
class TargetObject
|
242
|
-
end
|
243
|
-
|
244
|
-
class ObjectWithPredicateObject
|
245
|
-
include ModelPack::Document
|
246
|
-
|
247
|
-
object :target, class_name: TargetObject, predicate: true
|
248
|
-
end
|
249
|
-
|
250
|
-
object1 = ObjectWithPredicateObject.new(
|
251
|
-
target: TargetObject.new
|
252
|
-
)
|
253
|
-
|
254
|
-
object2 = ObjectWithPredicateObject.new()
|
255
|
-
|
256
|
-
expect(object1.target?).to be true
|
257
|
-
expect(object2.target?).to be false
|
258
|
-
end
|
259
|
-
|
260
240
|
it "should boolean type works well" do
|
261
241
|
class BooleanData
|
262
242
|
include ModelPack::Document
|
@@ -289,46 +269,17 @@ describe ModelPack::ClassMethods do
|
|
289
269
|
expect(array2.data.size).to be 0
|
290
270
|
end
|
291
271
|
|
292
|
-
it "
|
293
|
-
class
|
294
|
-
include ModelPack::Document
|
295
|
-
|
296
|
-
attribute :alpha, default: [1,2,3]
|
297
|
-
attribute :beta, default: {a: true}
|
298
|
-
end
|
299
|
-
|
300
|
-
class ObjectWithDefaults
|
301
|
-
include ModelPack::Document
|
302
|
-
|
303
|
-
object :defaults, class_name: ObjectDefaults, default: ObjectDefaults
|
304
|
-
end
|
305
|
-
|
306
|
-
object = ObjectWithDefaults.new
|
307
|
-
|
308
|
-
expect(object.defaults).to be_a(ObjectDefaults)
|
309
|
-
expect(object.defaults.alpha).to contain_exactly(1,2,3)
|
310
|
-
expect(object.defaults.beta).to include(a: true)
|
311
|
-
end
|
312
|
-
|
313
|
-
it "should have constructor with custom params" do
|
314
|
-
class ObjectWithCustomConstructor
|
272
|
+
it "supports boolean as default" do
|
273
|
+
class BooleanData
|
315
274
|
include ModelPack::Document
|
316
275
|
|
317
|
-
attribute :
|
318
|
-
|
319
|
-
attr_accessor :req
|
320
|
-
|
321
|
-
def initialize(req)
|
322
|
-
@req = req
|
323
|
-
end
|
276
|
+
attribute :always_false, default: false
|
277
|
+
attribute :always_true, default: true
|
324
278
|
end
|
325
279
|
|
326
|
-
|
327
|
-
object2 = ObjectWithCustomConstructor.new('POST')
|
280
|
+
data = BooleanData.new
|
328
281
|
|
329
|
-
expect(
|
330
|
-
expect(
|
331
|
-
expect(object2.req).to eq 'POST'
|
332
|
-
expect(object2.required).to be nil
|
282
|
+
expect(data.always_false).to be false
|
283
|
+
expect(data.always_true).to be true
|
333
284
|
end
|
334
285
|
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.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- inre
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: 3.0.0
|
55
55
|
description:
|
56
56
|
email:
|
57
|
-
-
|
57
|
+
- inre.strom@gmail.com
|
58
58
|
executables: []
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
@@ -96,10 +96,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
96
|
version: 2.3.0
|
97
97
|
requirements: []
|
98
98
|
rubyforge_project:
|
99
|
-
rubygems_version: 2.4.
|
99
|
+
rubygems_version: 2.4.6
|
100
100
|
signing_key:
|
101
101
|
specification_version: 4
|
102
|
-
summary: Model Pack – simple
|
102
|
+
summary: Model Pack – simple models
|
103
103
|
test_files:
|
104
104
|
- spec/model_pack_spec.rb
|
105
105
|
- spec/spec_helper.rb
|