aduki 0.1.1 → 0.1.2

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: b2083ed7af6b80549df900d66e0cb35155771108
4
- data.tar.gz: 35b6925901470ff78de0eaedc036a14c4fcb2af3
3
+ metadata.gz: 269ae6607c034416e171d45d6452c4fba0e5bf84
4
+ data.tar.gz: bcd5234c6bf73552897059acb43633df077ce4bb
5
5
  SHA512:
6
- metadata.gz: 885a4d4e4a2430322027ef36ca3881852fbcd25cb8d0ea57b880ecc09e773110365609ca16c47013a8743ee713b26275de58b63874a1ca0eeecf824de2a1afd0
7
- data.tar.gz: bfd53ddbae29f3705a6e958b90b3e8d3e59bb17d87a111695f0d7767da14c8951f03d2a5cb89806865d84f6634898fa1f33d139e0ee847359c38c53c6bb9ef8d
6
+ metadata.gz: 30966ec2c14406a5a3d91e7c3943119997c0285f90bf7f4de39166d65801374de6674a6c8278bf39b7710f35d52e720d7257817b8fbc7b542c9bc7c87248d9c0
7
+ data.tar.gz: cbd2ae5d83392f9b1c6ed3e8158d10b46aff04685ad67ae06cacb137c3e44155e473177d05c00b36de9d7be08a0deac1e3eb7cab045bf647d1220b456f52f887
@@ -146,11 +146,12 @@ module Aduki
146
146
  end
147
147
  end
148
148
 
149
- def aduki_initialize name, klass
150
- aduki name => klass
149
+ def aduki_initialize name, initial_klass, type=:notset
150
+ type = (type == :notset) ? initial_klass : type
151
+ aduki(name => type) if type
151
152
  initializer_name = :"aduki_initialize_#{name}"
152
153
  define_method initializer_name do
153
- send :"#{name}=", klass.new
154
+ send :"#{name}=", initial_klass.new
154
155
  end
155
156
  @@initializers[self] ||= []
156
157
  @@initializers[self] << initializer_name
@@ -1,3 +1,3 @@
1
1
  module Aduki
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -206,7 +206,10 @@ describe Aduki::Initializer do
206
206
  props = {
207
207
  "name" => "Brackish Water",
208
208
  "gadget.name" => "The Loud Gadget",
209
- "gadget.speaker.ohms" => "29"
209
+ "gadget.speaker.ohms" => "29",
210
+ "gadget.speaker.dates[1]" => "2015-03-12",
211
+ "gadget.speaker.dates[2]" => "2015-06-08",
212
+ "gadget.speaker.dates[3]" => "2015-06-21",
210
213
  }
211
214
 
212
215
  model = Model.new props
@@ -215,5 +218,37 @@ describe Aduki::Initializer do
215
218
  model.gadget.name.should == "The Loud Gadget"
216
219
  model.gadget.speaker.should be_a Speaker
217
220
  model.gadget.speaker.ohms.should == "29"
221
+
222
+ expect(model.gadget.speaker.dates).to eq [ Date.parse("2015-03-12"), Date.parse("2015-06-08"), Date.parse("2015-06-21") ]
223
+ end
224
+
225
+ it "should handle pre-initialized arrays without a given array type" do
226
+ props = {
227
+ "name" => "Brackish Water",
228
+ "gadget.name" => "The Loud Gadget",
229
+ "gadget.speaker.ohms" => "29",
230
+ "gadget.speaker.dimensions[1]" => "12",
231
+ "gadget.speaker.dimensions[2]" => "8",
232
+ "gadget.speaker.dimensions[3]" => "21",
233
+ }
234
+
235
+ model = Model.new props
236
+
237
+ expect(model.gadget.speaker.dimensions).to eq [ "12", "8", "21" ]
238
+ end
239
+
240
+ it "should handle pre-initialized arrays with a previously-set array type" do
241
+ props = {
242
+ "name" => "Brackish Water",
243
+ "gadget.name" => "The Loud Gadget",
244
+ "gadget.speaker.ohms" => "29",
245
+ "gadget.speaker.threads[1]" => "12.4",
246
+ "gadget.speaker.threads[2]" => "8.16",
247
+ "gadget.speaker.threads[3]" => "21.42",
248
+ }
249
+
250
+ model = Model.new props
251
+
252
+ expect(model.gadget.speaker.threads).to eq [ 12.4, 8.16, 21.42 ]
218
253
  end
219
254
  end
@@ -6,7 +6,10 @@ describe Aduki::Initializer do
6
6
  props = {
7
7
  "name" => "Brackish Water",
8
8
  "gadget.name" => "The Loud Gadget",
9
- "gadget.speaker.ohms" => "29"
9
+ "gadget.speaker.ohms" => "29",
10
+ "gadget.speaker.dates[1]" => "2014-03-12",
11
+ "gadget.speaker.dates[2]" => "2014-06-08",
12
+ "gadget.speaker.dates[3]" => "2014-06-21",
10
13
  }
11
14
 
12
15
  model = Model.new props
@@ -16,11 +19,15 @@ describe Aduki::Initializer do
16
19
  expect(model.gadget.price). to eq nil
17
20
  expect(model.gadget.speaker.ohms). to eq "29"
18
21
  expect(model.gadget.speaker.diameter).to eq nil
22
+ expect(model.gadget.speaker.dates).to eq [ Date.parse("2014-03-12"), Date.parse("2014-06-08"), Date.parse("2014-06-21") ]
19
23
 
20
24
  more_props = {
21
25
  "name" => "Smelly Brackish Water",
22
26
  "gadget.price" => "42",
23
- "gadget.speaker.diameter" => "large"
27
+ "gadget.speaker.diameter" => "large",
28
+ "gadget.speaker.dates[1]" => "2015-06-21",
29
+ "gadget.speaker.dates[2]" => "2015-03-12",
30
+ "gadget.speaker.dates[3]" => "2015-06-08",
24
31
  }
25
32
 
26
33
  Aduki.apply_attributes model, more_props
@@ -30,6 +37,7 @@ describe Aduki::Initializer do
30
37
  expect(model.gadget.price). to eq "42"
31
38
  expect(model.gadget.speaker.ohms). to eq "29"
32
39
  expect(model.gadget.speaker.diameter).to eq "large"
40
+ expect(model.gadget.speaker.dates).to eq [ Date.parse("2014-03-12"), Date.parse("2014-06-08"), Date.parse("2014-06-21"), Date.parse("2015-06-21"), Date.parse("2015-03-12"), Date.parse("2015-06-08") ]
33
41
  end
34
42
 
35
43
  it "does not die when reader accessor is absent" do
@@ -40,7 +40,11 @@ end
40
40
 
41
41
  class Speaker
42
42
  include Aduki::Initializer
43
- attr_accessor :ohms, :diameter
43
+ attr_accessor :ohms, :diameter, :dimensions
44
+ aduki threads: Float
45
+ aduki_initialize :dates, Array, Date
46
+ aduki_initialize :dimensions, Array, nil
47
+ aduki_initialize :threads, Array, nil
44
48
  end
45
49
 
46
50
  class Gadget
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aduki
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Conan Dalton