model_pack 0.9.2 → 0.9.3

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
  SHA1:
3
- metadata.gz: dabb01b01889b40d35d86225715aa392b26c9998
4
- data.tar.gz: 85c4e83fb4e2fc2af86d31f864c0277e04d0db54
3
+ metadata.gz: 7f4637c6e300ad3511f0e8b731d39e0ffc685a75
4
+ data.tar.gz: cb3616c6692f5fe7ae94c2b93039f27c74d0944f
5
5
  SHA512:
6
- metadata.gz: cf57987290bb914c78f5cfa6d62bb00ebc26f2676cace86713feba5d9ef2a2504a8a2803558e4f1811550daadd9b6c461286aeb49d86c185c98e434e934fabb3
7
- data.tar.gz: 7f587c452db113574c71c11612781e0001c1db57f8e0387ade3d3677d3754ce0b10d34a6d57473453d63da0ae82901579af5c12d8326d9ea5f9148162376d98c
6
+ metadata.gz: d2131d2bcef25c5c43ccb98a5b5a2cb63ad1b305c34c9e410a90244f8d73ee52e992249eba1182ac740c61c8f2be38042d2379f36f97108d82a3e3ec1d5734a2
7
+ data.tar.gz: 6df0e38c7e25c9cf49ed31b0c4151b860b399eb587b786fa0509dc0d23882a09313bc62cbbd84ad03c42ac2a6ac6dac9d3d6e307ca3daa1caf0c4e455bd40951
@@ -15,15 +15,17 @@ module ModelPack
15
15
 
16
16
  def attribute_reader(name, default: nil, as: nil, serialize: nil, predicate: nil)
17
17
  default_dup = default.dup rescue default
18
- default_value = default_dup || (as && as.new)
18
+ default_value = default_dup || as
19
19
 
20
20
  define_method name do
21
- instance_variable_defined?("@#{name}") ? instance_variable_get("@#{name}") : instance_variable_set("@#{name}", default_value)
21
+ instance_variable_defined?("@#{name}") ?
22
+ instance_variable_get("@#{name}") : instance_variable_set("@#{name}", (default_value.is_a?(Class) ? default_value.new : default_value))
22
23
  end
23
24
 
24
25
  # define predicate method if required
25
26
  define_method "#{name}?" do
26
- value = (instance_variable_defined?("@#{name}") ? instance_variable_get("@#{name}") : instance_variable_set("@#{name}", default_value))
27
+ value = (instance_variable_defined?("@#{name}") ?
28
+ instance_variable_get("@#{name}") : instance_variable_set("@#{name}", (default_value.is_a?(Class) ? default_value.new : default_value)))
27
29
  predicate.is_a?(Proc) ? predicate.call(value) : !!value # false for nil or false
28
30
  end if predicate
29
31
 
@@ -1,3 +1,3 @@
1
1
  module ModelPack
2
- VERSION = "0.9.2"
2
+ VERSION = "0.9.3"
3
3
  end
@@ -211,7 +211,6 @@ describe ModelPack::ClassMethods do
211
211
  expect(owp.load?).to eq('NO')
212
212
  end
213
213
 
214
-
215
214
  it "should boolean type works well" do
216
215
  class BooleanData
217
216
  include ModelPack::Document
@@ -229,4 +228,18 @@ describe ModelPack::ClassMethods do
229
228
  expect(copy_true_data.serializable_hash[:bit]).to be true
230
229
  expect(copy_false_data.serializable_hash[:bit]).to be false
231
230
  end
231
+
232
+ it "should create unique array for each instance" do
233
+ class ArrayData
234
+ include ModelPack::Document
235
+
236
+ array :data
237
+ end
238
+
239
+ array1 = ArrayData.new
240
+ array1.data << 1
241
+ array2 = ArrayData.new
242
+ expect(array1.data.size).to be 1
243
+ expect(array2.data.size).to be 0
244
+ end
232
245
  end
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: model_pack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - che
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-12 00:00:00.000000000 Z
11
+ date: 2014-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.6'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '10.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: 3.0.0
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 3.0.0
55
55
  description:
@@ -59,7 +59,7 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
- - .gitignore
62
+ - ".gitignore"
63
63
  - Gemfile
64
64
  - LICENSE.txt
65
65
  - README.md
@@ -86,12 +86,12 @@ require_paths:
86
86
  - lib
87
87
  required_ruby_version: !ruby/object:Gem::Requirement
88
88
  requirements:
89
- - - '>='
89
+ - - ">="
90
90
  - !ruby/object:Gem::Version
91
91
  version: 2.0.0
92
92
  required_rubygems_version: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: 2.3.0
97
97
  requirements: []