aduki 0.2.6 → 0.2.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: b85c60d97a71915e789b12de6530f1bbabb45eb7
4
- data.tar.gz: 77743c74d0d3fc6182941742c22b98ea06a6d906
3
+ metadata.gz: b7dd0b304ba4c822ccea883c49b3436bad96c79b
4
+ data.tar.gz: 66b0f76e294f54bd0b9d5d745fbc15b12ea430e8
5
5
  SHA512:
6
- metadata.gz: 55e9eff182433b8a42591f97ef97f108ddef3f824a5d7b969b26cd2db7ee83288e833aa35b0acc23c9473d841883125c8cb01f6d2b17eae49077d58dca0aacbc
7
- data.tar.gz: f7a1bab6b2cae7502d5e649fce9810d4f8ccff24d8e5cf77c0d9bfebf4c245a209b13b6cfd21a64d6555ba39ca14fb9132ac0a8194e53eb6ff324418cf4e3a3a
6
+ metadata.gz: 2851f920f20bd3fd4f17f76df4e405f7ea6c471cfc966944deedb9f9297abd438cd5ef13ff272689452bee09454523d8d079224ec1ae30af12cdc5e64940cbc5
7
+ data.tar.gz: c09358df15d6efff6a9ab420ca47f0c6870a6d7b159d5f7d6f4dc313dacf738baa4189dc04011d6676203cb750f6ffb643b2b48c85a152b31f036bed0cc2ce9e
@@ -0,0 +1,28 @@
1
+ search:
2
+ - "bin/**/*"
3
+ - "lib/**/*"
4
+ - "spec/**/*"
5
+ - "*.gemspec"
6
+ - ".*.yml"
7
+ - ".git?*"
8
+ - "Gemfile*"
9
+ - README
10
+ ignore:
11
+ - .doc$
12
+ - .ods$
13
+ - .gz$
14
+ - .png$
15
+ - .gif$
16
+ - .zip$
17
+ - .jpg$
18
+ - .xcf$
19
+ - .pdf$
20
+ - /select2/.*.js$
21
+ stats:
22
+ nydp:
23
+ - ".*\\.nydp"
24
+ code:
25
+ - "lib/.*\\.(rb|rake)"
26
+ test:
27
+ - "spec/.*"
28
+ - "test/.*"
@@ -53,11 +53,19 @@ module Aduki
53
53
  case value
54
54
  when Date; value
55
55
  when String; maybe_parse_date(value)
56
+ else
57
+ if value.respond_to?(:to_date)
58
+ value.to_date
59
+ end
56
60
  end
57
61
  elsif type == Time
58
62
  case value
59
63
  when Time; value
60
64
  when String; Time.parse(value)
65
+ else
66
+ if value.respond_to?(:to_time)
67
+ value.to_time
68
+ end
61
69
  end
62
70
  elsif type && (type <= Integer)
63
71
  value.to_i
@@ -133,6 +141,7 @@ module Aduki
133
141
  end
134
142
 
135
143
  def self.apply_attributes object, attrs
144
+ attrs = nil if attrs == ''
136
145
  setters = split_attributes(attrs || { })
137
146
  klass = object.class
138
147
 
@@ -1,3 +1,3 @@
1
1
  module Aduki
2
- VERSION = "0.2.6"
2
+ VERSION = "0.2.7"
3
3
  end
@@ -37,7 +37,7 @@ class Hash
37
37
 
38
38
  def recursively_replace_values &block
39
39
  each_with_object({ }) { |(k, v), result|
40
- result[k] = (v.is_a?(Hash) || v.is_a?(Array)) ? v.recursively_replace_values!(&block) : yield(k, v)
40
+ result[k] = (v.is_a?(Hash) || v.is_a?(Array)) ? v.recursively_replace_values(&block) : yield(k, v)
41
41
  }
42
42
  end
43
43
  end
@@ -2,7 +2,7 @@ require "aduki"
2
2
  require "spec_helper"
3
3
 
4
4
  describe Aduki::Initializer do
5
- it "should assign an integer attribute of an object nested in an array attribute" do
5
+ it "assigns an integer attribute of an object nested in an array attribute" do
6
6
  props = {
7
7
  "name" => "Foo",
8
8
  "assemblies" => [{ "name" => "A0", "height" => "10" }, { "name" => "A1", "height" => "20" }, { "name" => "A2", "height" => "30" }, ],
@@ -3,7 +3,7 @@ require "spec_helper"
3
3
 
4
4
  describe Aduki::Initializer do
5
5
 
6
- it "should assign a value using a custom finder" do
6
+ it "assigns a value using a custom finder" do
7
7
  props = {
8
8
  "name" => "Anna Livia",
9
9
  "city" => "dublin"
@@ -4,7 +4,7 @@ describe Hash do
4
4
  before { Aduki.install_monkey_patches }
5
5
 
6
6
  describe 'recursively_delete_keys!' do
7
- it "should delete the specified keys from itself and all nested hashes, even sub-nested in arrays" do
7
+ it "deletes the specified keys from itself and all nested hashes, even sub-nested in arrays" do
8
8
  h = {
9
9
  site_id: "foo",
10
10
  "site_id" => :bar,
@@ -22,7 +22,7 @@ describe Hash do
22
22
 
23
23
  h.recursively_delete_keys! :site_id, "site_id"
24
24
 
25
- h.should == {
25
+ expect(h).to eq({
26
26
  things: {
27
27
  2 => [ { a: 12, b: 53 },
28
28
  { a: 13, b: 54 },
@@ -31,12 +31,12 @@ describe Hash do
31
31
  toto: :titi
32
32
  },
33
33
  others: [ { name: "Walter" } ]
34
- }
34
+ })
35
35
  end
36
36
  end
37
37
 
38
38
  describe 'recursively_stringify_keys!' do
39
- it "should change all keys to strings" do
39
+ it "changes all keys to strings" do
40
40
  h = {
41
41
  foo: "bar",
42
42
  12 => 13,
@@ -85,90 +85,90 @@ describe Aduki::Initializer do
85
85
  "countries[4]" => "Spain",
86
86
  }
87
87
 
88
- it "should set a bunch of properties from a hash of property paths" do
88
+ it "sets a bunch of properties from a hash of property paths" do
89
89
  props = PROPS
90
90
 
91
91
  model = Model.new props
92
92
 
93
- model.name.should == "Willy"
94
- model.email.should == "willy@wonka.softify.com"
95
- model.item.should == "HXB5H"
96
- model.thing.should == "0"
97
- model.gadget.name.should == "My Big Gadget"
98
- model.gadget.price.should == "21"
99
- model.gadget.supplier.should == "Apple, Inc."
100
- model.gadget.speaker.should be_a Speaker
101
- model.gadget.speaker.ohms.should == nil
102
- model.machines[0].name.should == "The First Machine"
103
- model.machines[0].weight.should == "88"
104
- model.machines[0].speed.should == "142"
105
- model.machines[0].builder.name.should == "The First Machine Builder"
106
- model.machines[0].builder.email.should == "wibble@bump"
107
- model.machines[0].builder.phone.should == "4099"
108
- model.machines[0].builder.office.should == "2nd floor room 12"
109
- model.machines[0].assemblies[0].name.should == "first machine, first assembly"
110
- model.machines[0].assemblies[0].colour.should == "red"
111
- model.machines[0].assemblies[0].size.should == "pretty large"
112
- model.machines[0].assemblies[1].name.should == "first machine, second assembly"
113
- model.machines[0].assemblies[1].colour.should == "green"
114
- model.machines[0].assemblies[1].size.should == "sort of medium"
115
- model.machines[0].assemblies[2].name.should == "first machine, third assembly"
116
- model.machines[0].assemblies[2].colour.should == "blue"
117
- model.machines[0].assemblies[2].size.should == "miniscule"
118
- model.machines[0].dimensions[0].should == "2346.56"
119
- model.machines[0].dimensions[1].should == "6456.64"
120
- model.machines[0].dimensions[2].should == "3859.39"
121
- model.machines[0].dimensions[3].should == "2365.68"
122
- model.machines[0].team.should == { "lead" => "Shakespeare", "code" => "Chaucer", "design" => "Jobs"}
123
- model.machines[0].helpers["jim"].should be_a MachineBuilder
124
- model.machines[0].helpers["jim"].name.should == "Jim Appleby"
125
- model.machines[0].helpers["jim"].email.should == "Jim.Appleby@example.com"
126
- model.machines[0].helpers["jim"].phone.should == "123 456 789"
127
- model.machines[0].helpers["jim"].office.should == "Elephant & Castle"
128
- model.machines[0].helpers["ben"].should be_a MachineBuilder
129
- model.machines[0].helpers["ben"].name.should == "Ben Barnes"
130
- model.machines[0].helpers["ben"].email.should == "Ben.Barnes@example.com"
131
- model.machines[0].helpers["ben"].phone.should == "123 456 790"
132
- model.machines[0].helpers["ben"].office.should == "Cockney"
133
- model.machines[0].helpers["pat"].should be_a MachineBuilder
134
- model.machines[0].helpers["pat"].name.should == "Patrick O'Brien"
135
- model.machines[0].helpers["pat"].email.should == "Patrick.O.Brien@example.com"
136
- model.machines[0].helpers["pat"].phone.should == "123 456 791"
137
- model.machines[0].helpers["pat"].office.should == "Hammersmith"
138
- model.machines[1].name.should == "The Second Machine"
139
- model.machines[1].weight.should == "34"
140
- model.machines[1].speed.should == "289"
141
- model.machines[1].builder.name.should == "The Second Machine Builder"
142
- model.machines[1].builder.email.should == "waggie@bump"
143
- model.machines[1].builder.phone.should == "4101"
144
- model.machines[1].builder.office.should == "3rd floor room 23"
145
- model.machines[1].assemblies[0].name.should == "second machine, second assembly"
146
- model.machines[1].assemblies[0].colour.should == "turquoise"
147
- model.machines[1].assemblies[0].size.should == "large-ish"
148
- model.machines[1].assemblies[1].name.should == "second machine, first assembly"
149
- model.machines[1].assemblies[1].colour.should == "purple"
150
- model.machines[1].assemblies[1].size.should == "pretty small"
151
- model.machines[1].assemblies[2].name.should == "second machine, third assembly"
152
- model.machines[1].assemblies[2].colour.should == "magenta"
153
- model.machines[1].assemblies[2].size.should == "gigantic"
154
- model.machines[1].dimensions[0].should == "1985.85"
155
- model.machines[1].dimensions[1].should == "7234.92"
156
- model.machines[1].dimensions[2].should == "9725.52"
157
- model.machines[1].dimensions[3].should == "3579.79"
158
- model.machines[1].team.should == { "lead" => "Joyce", "code" => "O'Brien", "design" => "Moore", "muffins" => "MacNamara"}
159
- model.contraptions[0].x.should == "19"
160
- model.contraptions[0].y.should == "0.003"
161
- model.contraptions[1].x.should == "12"
162
- model.contraptions[1].y.should == "0.0012"
163
- model.contraptions[2].x.should == "24"
164
- model.contraptions[2].y.should == "0.00063"
165
- model.contraptions[3].x.should == "16"
166
- model.contraptions[3].y.should == "0.00091"
167
- model.countries[0].should == "France"
168
- model.countries[1].should == "Sweden"
169
- model.countries[2].should == "Germany"
170
- model.countries[3].should == "Ireland"
171
- model.countries[4].should == "Spain"
93
+ expect(model.name).to eq "Willy"
94
+ expect(model.email).to eq "willy@wonka.softify.com"
95
+ expect(model.item).to eq "HXB5H"
96
+ expect(model.thing).to eq "0"
97
+ expect(model.gadget.name).to eq "My Big Gadget"
98
+ expect(model.gadget.price).to eq "21"
99
+ expect(model.gadget.supplier).to eq "Apple, Inc."
100
+ expect(model.gadget.speaker).to be_a Speaker
101
+ expect(model.gadget.speaker.ohms).to eq nil
102
+ expect(model.machines[0].name).to eq "The First Machine"
103
+ expect(model.machines[0].weight).to eq "88"
104
+ expect(model.machines[0].speed).to eq "142"
105
+ expect(model.machines[0].builder.name).to eq "The First Machine Builder"
106
+ expect(model.machines[0].builder.email).to eq "wibble@bump"
107
+ expect(model.machines[0].builder.phone).to eq "4099"
108
+ expect(model.machines[0].builder.office).to eq "2nd floor room 12"
109
+ expect(model.machines[0].assemblies[0].name).to eq "first machine, first assembly"
110
+ expect(model.machines[0].assemblies[0].colour).to eq "red"
111
+ expect(model.machines[0].assemblies[0].size).to eq "pretty large"
112
+ expect(model.machines[0].assemblies[1].name).to eq "first machine, second assembly"
113
+ expect(model.machines[0].assemblies[1].colour).to eq "green"
114
+ expect(model.machines[0].assemblies[1].size).to eq "sort of medium"
115
+ expect(model.machines[0].assemblies[2].name).to eq "first machine, third assembly"
116
+ expect(model.machines[0].assemblies[2].colour).to eq "blue"
117
+ expect(model.machines[0].assemblies[2].size).to eq "miniscule"
118
+ expect(model.machines[0].dimensions[0]).to eq "2346.56"
119
+ expect(model.machines[0].dimensions[1]).to eq "6456.64"
120
+ expect(model.machines[0].dimensions[2]).to eq "3859.39"
121
+ expect(model.machines[0].dimensions[3]).to eq "2365.68"
122
+ expect(model.machines[0].team).to eq({ "lead" => "Shakespeare", "code" => "Chaucer", "design" => "Jobs"})
123
+ expect(model.machines[0].helpers["jim"]).to be_a MachineBuilder
124
+ expect(model.machines[0].helpers["jim"].name).to eq "Jim Appleby"
125
+ expect(model.machines[0].helpers["jim"].email).to eq "Jim.Appleby@example.com"
126
+ expect(model.machines[0].helpers["jim"].phone).to eq "123 456 789"
127
+ expect(model.machines[0].helpers["jim"].office).to eq "Elephant & Castle"
128
+ expect(model.machines[0].helpers["ben"]).to be_a MachineBuilder
129
+ expect(model.machines[0].helpers["ben"].name).to eq "Ben Barnes"
130
+ expect(model.machines[0].helpers["ben"].email).to eq "Ben.Barnes@example.com"
131
+ expect(model.machines[0].helpers["ben"].phone).to eq "123 456 790"
132
+ expect(model.machines[0].helpers["ben"].office).to eq "Cockney"
133
+ expect(model.machines[0].helpers["pat"]).to be_a MachineBuilder
134
+ expect(model.machines[0].helpers["pat"].name).to eq "Patrick O'Brien"
135
+ expect(model.machines[0].helpers["pat"].email).to eq "Patrick.O.Brien@example.com"
136
+ expect(model.machines[0].helpers["pat"].phone).to eq "123 456 791"
137
+ expect(model.machines[0].helpers["pat"].office).to eq "Hammersmith"
138
+ expect(model.machines[1].name).to eq "The Second Machine"
139
+ expect(model.machines[1].weight).to eq "34"
140
+ expect(model.machines[1].speed).to eq "289"
141
+ expect(model.machines[1].builder.name).to eq "The Second Machine Builder"
142
+ expect(model.machines[1].builder.email).to eq "waggie@bump"
143
+ expect(model.machines[1].builder.phone).to eq "4101"
144
+ expect(model.machines[1].builder.office).to eq "3rd floor room 23"
145
+ expect(model.machines[1].assemblies[0].name).to eq "second machine, second assembly"
146
+ expect(model.machines[1].assemblies[0].colour).to eq "turquoise"
147
+ expect(model.machines[1].assemblies[0].size).to eq "large-ish"
148
+ expect(model.machines[1].assemblies[1].name).to eq "second machine, first assembly"
149
+ expect(model.machines[1].assemblies[1].colour).to eq "purple"
150
+ expect(model.machines[1].assemblies[1].size).to eq "pretty small"
151
+ expect(model.machines[1].assemblies[2].name).to eq "second machine, third assembly"
152
+ expect(model.machines[1].assemblies[2].colour).to eq "magenta"
153
+ expect(model.machines[1].assemblies[2].size).to eq "gigantic"
154
+ expect(model.machines[1].dimensions[0]).to eq "1985.85"
155
+ expect(model.machines[1].dimensions[1]).to eq "7234.92"
156
+ expect(model.machines[1].dimensions[2]).to eq "9725.52"
157
+ expect(model.machines[1].dimensions[3]).to eq "3579.79"
158
+ expect(model.machines[1].team).to eq({ "lead" => "Joyce", "code" => "O'Brien", "design" => "Moore", "muffins" => "MacNamara"})
159
+ expect(model.contraptions[0].x).to eq "19"
160
+ expect(model.contraptions[0].y).to eq "0.003"
161
+ expect(model.contraptions[1].x).to eq "12"
162
+ expect(model.contraptions[1].y).to eq "0.0012"
163
+ expect(model.contraptions[2].x).to eq "24"
164
+ expect(model.contraptions[2].y).to eq "0.00063"
165
+ expect(model.contraptions[3].x).to eq "16"
166
+ expect(model.contraptions[3].y).to eq "0.00091"
167
+ expect(model.countries[0]).to eq "France"
168
+ expect(model.countries[1]).to eq "Sweden"
169
+ expect(model.countries[2]).to eq "Germany"
170
+ expect(model.countries[3]).to eq "Ireland"
171
+ expect(model.countries[4]).to eq "Spain"
172
172
 
173
173
  sensibly_indexed_props = props.merge({
174
174
  "machines[1].assemblies[0].name" => "second machine, second assembly",
@@ -199,10 +199,10 @@ describe Aduki::Initializer do
199
199
 
200
200
  silly_keys.each { |k| sensibly_indexed_props.delete k }
201
201
 
202
- Aduki.to_aduki(model).should == sensibly_indexed_props
202
+ expect(Aduki.to_aduki(model)).to eq sensibly_indexed_props
203
203
  end
204
204
 
205
- it "should initialize attributes of pre-initialized nested objects" do
205
+ it "initializes attributes of pre-initialized nested objects" do
206
206
  props = {
207
207
  "name" => "Brackish Water",
208
208
  "gadget.name" => "The Loud Gadget",
@@ -214,15 +214,15 @@ describe Aduki::Initializer do
214
214
 
215
215
  model = Model.new props
216
216
 
217
- model.name.should == "Brackish Water"
218
- model.gadget.name.should == "The Loud Gadget"
219
- model.gadget.speaker.should be_a Speaker
220
- model.gadget.speaker.ohms.should == "29"
217
+ expect(model.name).to eq "Brackish Water"
218
+ expect(model.gadget.name).to eq "The Loud Gadget"
219
+ expect(model.gadget.speaker).to be_a Speaker
220
+ expect(model.gadget.speaker.ohms).to eq "29"
221
221
 
222
222
  expect(model.gadget.speaker.dates).to eq [ Date.parse("2015-03-12"), Date.parse("2015-06-08"), Date.parse("2015-06-21") ]
223
223
  end
224
224
 
225
- it "should handle pre-initialized arrays without a given array type" do
225
+ it "handles pre-initialized arrays without a given array type" do
226
226
  props = {
227
227
  "name" => "Brackish Water",
228
228
  "gadget.name" => "The Loud Gadget",
@@ -237,7 +237,7 @@ describe Aduki::Initializer do
237
237
  expect(model.gadget.speaker.dimensions).to eq [ "12", "8", "21" ]
238
238
  end
239
239
 
240
- it "should handle pre-initialized arrays with a previously-set array type" do
240
+ it "handles pre-initialized arrays with a previously-set array type" do
241
241
  props = {
242
242
  "name" => "Brackish Water",
243
243
  "gadget.name" => "The Loud Gadget",
@@ -252,7 +252,7 @@ describe Aduki::Initializer do
252
252
  expect(model.gadget.speaker.threads).to eq [ 12.4, 8.16, 21.42 ]
253
253
  end
254
254
 
255
- it "should handle pre-initialized hashes" do
255
+ it "handles pre-initialized hashes" do
256
256
  props = {
257
257
  "name" => "Brackish Water",
258
258
  "gadget.name" => "The Loud Gadget",
@@ -266,7 +266,7 @@ describe Aduki::Initializer do
266
266
  expect(model.gadget.variables).to eq({ "x"=> "29", "y" => "12.4", "z" => "8.16"})
267
267
  end
268
268
 
269
- it "should handle pre-initialized hashes with more complex subkeys" do
269
+ it "handles pre-initialized hashes with more complex subkeys" do
270
270
  props = {
271
271
  "name" => "Brackish Water",
272
272
  "gadget.name" => "The Loud Gadget",
@@ -2,7 +2,7 @@ require "aduki"
2
2
  require "spec_helper"
3
3
 
4
4
  describe Aduki::Initializer do
5
- it "should initialize attributes of pre-initialized nested objects" do
5
+ it "initializes attributes of pre-initialized nested objects" do
6
6
  props = {
7
7
  "name" => "Brackish Water",
8
8
  "gadget.name" => "The Loud Gadget",
@@ -3,7 +3,7 @@ require "spec_helper"
3
3
 
4
4
  describe Aduki::Initializer do
5
5
 
6
- it "should silently accept nil initializer parameter" do
6
+ it "silently accepts nil initializer parameter" do
7
7
  contraption = Assembly.new
8
8
 
9
9
  expect(contraption.name ).to be_nil
@@ -11,4 +11,13 @@ describe Aduki::Initializer do
11
11
  expect(contraption.height).to be_nil
12
12
  expect(contraption.weight).to be_nil
13
13
  end
14
+
15
+ it "silently accepts empty-string initializer parameter" do
16
+ contraption = Assembly.new ""
17
+
18
+ expect(contraption.name ).to be_nil
19
+ expect(contraption.colour).to be_nil
20
+ expect(contraption.height).to be_nil
21
+ expect(contraption.weight).to be_nil
22
+ end
14
23
  end
@@ -3,7 +3,7 @@ require "spec_helper"
3
3
 
4
4
  describe Aduki::Initializer do
5
5
 
6
- it "should assign an integer attribute" do
6
+ it "assigns an integer attribute" do
7
7
  props = {
8
8
  "height" => "123",
9
9
  "weight" => "12.345"
@@ -1,11 +1,11 @@
1
+ require 'aduki'
1
2
 
2
3
  RSpec.configure do |config|
3
- config.treat_symbols_as_metadata_keys_with_true_values = true
4
+ # config.treat_symbols_as_metadata_keys_with_true_values = true
4
5
  config.run_all_when_everything_filtered = true
5
6
  config.order = 'random'
6
7
  end
7
8
 
8
-
9
9
  class City < Struct.new(:name)
10
10
  CITIES = { }
11
11
  def self.aduki_find value
@@ -2,23 +2,23 @@ require "aduki"
2
2
  require "spec_helper"
3
3
 
4
4
  describe Aduki do
5
- it "should return a plain hash structure" do
5
+ it "returns a plain hash structure" do
6
6
  hsh = { "foo" => "bar" }
7
7
  props = Aduki.to_aduki hsh
8
- props.should == { "foo" => "bar" }
8
+ expect(props).to eq({ "foo" => "bar" })
9
9
  end
10
10
 
11
11
  it "should flatten nested keys" do
12
12
  hsh = { "foo" => "bar", "bing" => { "boo" => "wogga", "tingle" => "wimp" } }
13
13
  props = Aduki.to_aduki hsh
14
- props.should == {
14
+ expect(props).to eq({
15
15
  "foo" => "bar",
16
16
  "bing.boo" => "wogga",
17
17
  "bing.tingle" => "wimp"
18
- }
18
+ })
19
19
  end
20
20
 
21
- it "should flatten deeply nested keys" do
21
+ it "flattens deeply nested keys" do
22
22
  hsh = {
23
23
  "foo" => "bar",
24
24
  "bing" => {
@@ -29,16 +29,16 @@ describe Aduki do
29
29
  "scorn" => "shart"
30
30
  }} }
31
31
  props = Aduki.to_aduki hsh
32
- props.should == {
32
+ expect(props).to eq({
33
33
  "foo" => "bar",
34
34
  "bing.boo" => "wogga",
35
35
  "bing.tingle" => "wimp",
36
36
  "bing.harpoon.shonk" => "twaddle",
37
37
  "bing.harpoon.scorn" => "shart",
38
- }
38
+ })
39
39
  end
40
40
 
41
- it "should flatten array keys also " do
41
+ it "flattens array keys also " do
42
42
  hsh = {
43
43
  "foo" => "bar",
44
44
  "bing" => {
@@ -50,7 +50,7 @@ describe Aduki do
50
50
  "shart" ]
51
51
  } }
52
52
  props = Aduki.to_aduki hsh
53
- props.should == {
53
+ expect(props).to eq({
54
54
  "foo" => "bar",
55
55
  "bing.boo" => "wogga",
56
56
  "bing.tingle" => "wimp",
@@ -58,10 +58,10 @@ describe Aduki do
58
58
  "bing.harpoon[1]" => "twaddle",
59
59
  "bing.harpoon[2]" => "scorn",
60
60
  "bing.harpoon[3]" => "shart",
61
- }
61
+ })
62
62
  end
63
63
 
64
- it "should flatten nested arrays " do
64
+ it "flattens nested arrays " do
65
65
  hsh = {
66
66
  "foo" => "bar",
67
67
  "bing" => {
@@ -73,7 +73,7 @@ describe Aduki do
73
73
  { :wing => :tip, :tail => :fin } ]
74
74
  } }
75
75
  props = Aduki.to_aduki hsh
76
- props.should == {
76
+ expect(props).to eq({
77
77
  "foo" => "bar",
78
78
  "bing.boo" => "wogga",
79
79
  "bing.tingle" => "wimp",
@@ -84,10 +84,10 @@ describe Aduki do
84
84
  "bing.harpoon[2][2]" => "gamma",
85
85
  "bing.harpoon[3].wing" => :tip,
86
86
  "bing.harpoon[3].tail" => :fin,
87
- }
87
+ })
88
88
  end
89
89
 
90
- it "should flatten aduki objects " do
90
+ it "flattens aduki objects " do
91
91
  hsh = {
92
92
  "foo" => "bar",
93
93
  "bing" => {
@@ -99,7 +99,7 @@ describe Aduki do
99
99
  { :wing => :tip, :tail => :fin } ]
100
100
  } }
101
101
  props = Aduki.to_aduki hsh
102
- props.should == {
102
+ expect(props).to eq({
103
103
  "foo" => "bar",
104
104
  "bing.boo" => "wogga",
105
105
  "bing.tingle" => "wimp",
@@ -110,6 +110,6 @@ describe Aduki do
110
110
  "bing.harpoon[2][2]" => "gamma",
111
111
  "bing.harpoon[3].wing" => :tip,
112
112
  "bing.harpoon[3].tail" => :fin,
113
- }
113
+ })
114
114
  end
115
115
  end
@@ -3,7 +3,13 @@ require "spec_helper"
3
3
 
4
4
  describe Aduki::Initializer do
5
5
 
6
- it "should assign a Date attribute" do
6
+ class SomeTimeAgo < Aduki::Initializable
7
+ attr_accessor :days
8
+ def to_date ; Date.today - days ; end
9
+ def to_time ; Time.now - (days * 86400) ; end
10
+ end
11
+
12
+ it "assigns a Date attribute" do
7
13
  props = {
8
14
  "x" => "The X",
9
15
  "y" => "The Y",
@@ -18,7 +24,15 @@ describe Aduki::Initializer do
18
24
  expect(contraption.planned.day).to eq 19
19
25
  end
20
26
 
21
- it "should assign a Time attribute" do
27
+ it "assigns a Date attribute from something like a Date (ActiveSupport::TimeWithZone, DateTime, Time)" do
28
+ contraption = Contraption.new "planned" => SomeTimeAgo.new(days: 36)
29
+ expect(contraption.planned).to eq(Date.today - 36)
30
+
31
+ contraption = Contraption.new "planned" => (Time.now - (86400 * 64))
32
+ expect(contraption.planned).to eq(Date.today - 64)
33
+ end
34
+
35
+ it "assigns a Time attribute" do
22
36
  props = {
23
37
  "x" => "The X",
24
38
  "y" => "The Y",
@@ -35,4 +49,15 @@ describe Aduki::Initializer do
35
49
  expect(contraption.updated.min).to eq 43
36
50
  expect(contraption.updated.sec).to eq 0
37
51
  end
52
+
53
+ it "assigns a Time attribute from something like a Time" do
54
+ contraption = Contraption.new updated: SomeTimeAgo.new(days: 72.5)
55
+ expect(contraption.updated).to be_a Time
56
+ expected = (Time.now - 72.5 * 86400)
57
+ expect(contraption.updated.to_i).to eq(expected.to_i)
58
+
59
+ contraption = Contraption.new updated: (Date.today - 88)
60
+ expect(contraption.updated).to be_a Time
61
+ expect(contraption.updated).to eq((Date.today - 88).to_time)
62
+ end
38
63
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aduki
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Conan Dalton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-12 00:00:00.000000000 Z
11
+ date: 2019-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -47,6 +47,7 @@ extra_rdoc_files: []
47
47
  files:
48
48
  - ".gitignore"
49
49
  - ".rspec"
50
+ - ".zeiger.yml"
50
51
  - Gemfile
51
52
  - LICENSE.txt
52
53
  - README.md
@@ -94,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
95
  version: '0'
95
96
  requirements: []
96
97
  rubyforge_project:
97
- rubygems_version: 2.2.2
98
+ rubygems_version: 2.5.2.3
98
99
  signing_key:
99
100
  specification_version: 4
100
101
  summary: set object attributes recursively from an attributes hash