aduki 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,5 @@
1
+ require "date"
2
+ require "time"
1
3
  require "aduki/version"
2
4
 
3
5
  module Aduki
@@ -31,6 +33,10 @@ module Aduki
31
33
  type = klass.aduki_type_for_attribute_name setter
32
34
  if type.is_a? Hash
33
35
  to_typed_hash type.values.first, value
36
+ elsif type == Date
37
+ Date.parse value
38
+ elsif type == Time
39
+ Time.parse value
34
40
  else
35
41
  type ? type.new(value) : value
36
42
  end
@@ -1,3 +1,3 @@
1
1
  module Aduki
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -170,7 +170,7 @@ describe Aduki::Initializer do
170
170
  "machines[1].assemblies[0].name" => "second machine, second assembly",
171
171
  "machines[1].assemblies[0].colour" => "turquoise",
172
172
  "machines[1].assemblies[0].size" => "large-ish",
173
- "machines[1].assemblies[1].name" => "second machine, first assembly", # the array index orders items but the position is not respected
173
+ "machines[1].assemblies[1].name" => "second machine, first assembly",
174
174
  "machines[1].assemblies[1].colour" => "purple",
175
175
  "machines[1].assemblies[1].size" => "pretty small",
176
176
  "machines[1].assemblies[2].name" => "second machine, third assembly",
@@ -7,7 +7,8 @@ end
7
7
 
8
8
  class Contraption
9
9
  include Aduki::Initializer
10
- attr_accessor :x, :y
10
+ attr_accessor :x, :y, :planned, :updated
11
+ aduki :planned => Date, :updated => Time
11
12
  end
12
13
 
13
14
  class Assembly
@@ -42,4 +43,3 @@ class Model
42
43
  aduki :machines => Machine
43
44
  aduki :contraptions => Contraption
44
45
  end
45
-
@@ -0,0 +1,39 @@
1
+ require "aduki"
2
+ require "spec_helper"
3
+
4
+ describe Aduki::Initializer do
5
+
6
+ it "should assign a Date attribute" do
7
+ props = {
8
+ "x" => "The X",
9
+ "y" => "The Y",
10
+ "planned" => "1945-01-19",
11
+ }
12
+
13
+ contraption = Contraption.new props
14
+
15
+ expect(contraption.planned).to be_a Date
16
+ expect(contraption.planned.year).to eq 1945
17
+ expect(contraption.planned.month).to eq 1
18
+ expect(contraption.planned.day).to eq 19
19
+ end
20
+
21
+ it "should assign a Time attribute" do
22
+ props = {
23
+ "x" => "The X",
24
+ "y" => "The Y",
25
+ "updated" => "1945-01-19 15:43",
26
+ }
27
+
28
+ contraption = Contraption.new props
29
+
30
+ expect(contraption.updated).to be_a Time
31
+ puts contraption.updated.inspect
32
+ expect(contraption.updated.year).to eq 1945
33
+ expect(contraption.updated.month).to eq 1
34
+ expect(contraption.updated.day).to eq 19
35
+ expect(contraption.updated.hour).to eq 15
36
+ expect(contraption.updated.min).to eq 43
37
+ expect(contraption.updated.sec).to eq 0
38
+ end
39
+ end
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.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-12-31 00:00:00.000000000 Z
12
+ date: 2014-02-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -63,6 +63,7 @@ files:
63
63
  - spec/model.rb
64
64
  - spec/spec_helper.rb
65
65
  - spec/to_aduki_spec.rb
66
+ - spec/to_date_spec.rb
66
67
  homepage: https://github.com/conanite/aduki
67
68
  licenses:
68
69
  - MIT
@@ -93,3 +94,4 @@ test_files:
93
94
  - spec/model.rb
94
95
  - spec/spec_helper.rb
95
96
  - spec/to_aduki_spec.rb
97
+ - spec/to_date_spec.rb