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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b24e44909763b19456f9080d94fb8a74cde3db9a
4
- data.tar.gz: ade097d0da0686cd4397dfb590185dfa1818a69d
3
+ metadata.gz: dc4201ba6cb9b884ee4fefdcd9aacb0c1dd87788
4
+ data.tar.gz: e3c63faa6d018537021f723d131e1a53955cbbb6
5
5
  SHA512:
6
- metadata.gz: 5e99105f1c05100f09690bd3a8d64fa9574557a701515e1cd9e6c10647c56f9d6c04e57ab725abb6c625d0c5018fa498e218c81a01326918f116e2d81f282ea4
7
- data.tar.gz: 986d5e52d67e732e4c4d8d96bbe6ab55e805dcb8d97fa6366e6e5a26e2ff5d35ec226ee553b399e2e0f408dc17e617097a8b491ce05156da8e4a2da2b20856c7
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/chelovekov/model_pack/fork )
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
- default_dup = default.dup rescue default
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}", (default_value.is_a?(Class) ? default_value.new : default_value))
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
@@ -1,6 +1,8 @@
1
1
  module ModelPack
2
2
  module Constructor
3
3
  def initialize(*a)
4
+ attributes = a.pop
5
+ update_attributes(attributes) if attributes
4
6
  update_attributes(a.pop) if a.last.is_a?(Hash)
5
7
  super(*a)
6
8
  end
@@ -1,3 +1,3 @@
1
1
  module ModelPack
2
- VERSION = "0.9.6"
2
+ VERSION = "0.9.7"
3
3
  end
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 = ["che"]
10
- spec.email = ["chelovekov@gmail.com"]
11
- spec.summary = %q{Model Pack – simple model interfaces.}
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"
@@ -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 "should have default nested object" do
293
- class ObjectDefaults
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 :required
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
- object1 = ObjectWithCustomConstructor.new('GET', required: false)
327
- object2 = ObjectWithCustomConstructor.new('POST')
280
+ data = BooleanData.new
328
281
 
329
- expect(object1.req).to eq 'GET'
330
- expect(object1.required).to be false
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.6
4
+ version: 0.9.7
5
5
  platform: ruby
6
6
  authors:
7
- - che
7
+ - inre
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-04 00:00:00.000000000 Z
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
- - chelovekov@gmail.com
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.3
99
+ rubygems_version: 2.4.6
100
100
  signing_key:
101
101
  specification_version: 4
102
- summary: Model Pack – simple model interfaces.
102
+ summary: Model Pack – simple models
103
103
  test_files:
104
104
  - spec/model_pack_spec.rb
105
105
  - spec/spec_helper.rb