aduki 0.0.7 → 0.0.8

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.
data/lib/aduki.rb CHANGED
@@ -37,6 +37,10 @@ module Aduki
37
37
  Date.parse value
38
38
  elsif type == Time
39
39
  Time.parse value
40
+ elsif type && (type <= Integer)
41
+ value.to_i
42
+ elsif type && (type <= Float)
43
+ value.to_f
40
44
  else
41
45
  type ? type.new(value) : value
42
46
  end
@@ -99,7 +103,7 @@ module Aduki
99
103
  end
100
104
 
101
105
  module Initializer
102
- def initialize attrs
106
+ def initialize attrs={ }
103
107
  Aduki.apply_attributes self, attrs
104
108
  end
105
109
 
data/lib/aduki/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Aduki
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -0,0 +1,14 @@
1
+ require "aduki"
2
+ require "spec_helper"
3
+
4
+ describe Aduki::Initializer do
5
+
6
+ it "should silently accept nil initializer parameter" do
7
+ contraption = Assembly.new
8
+
9
+ expect(contraption.name ).to be_nil
10
+ expect(contraption.colour).to be_nil
11
+ expect(contraption.height).to be_nil
12
+ expect(contraption.weight).to be_nil
13
+ end
14
+ end
@@ -0,0 +1,17 @@
1
+ require "aduki"
2
+ require "spec_helper"
3
+
4
+ describe Aduki::Initializer do
5
+
6
+ it "should assign an integer attribute" do
7
+ props = {
8
+ "height" => "123",
9
+ "weight" => "12.345"
10
+ }
11
+
12
+ contraption = Assembly.new props
13
+
14
+ expect(contraption.height).to eq 123
15
+ expect(contraption.weight).to eq 12.345
16
+ end
17
+ end
data/spec/spec_helper.rb CHANGED
@@ -13,7 +13,8 @@ end
13
13
 
14
14
  class Assembly
15
15
  include Aduki::Initializer
16
- attr_accessor :name, :colour, :size
16
+ attr_accessor :name, :colour, :size, :height, :weight
17
+ aduki :height => Integer, :weight => Float
17
18
  end
18
19
 
19
20
  class MachineBuilder
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.7
4
+ version: 0.0.8
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: 2014-02-07 00:00:00.000000000 Z
12
+ date: 2014-02-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -61,6 +61,8 @@ files:
61
61
  - lib/aduki/version.rb
62
62
  - spec/initializer_spec.rb
63
63
  - spec/model.rb
64
+ - spec/nil_initializer_spec.rb
65
+ - spec/number_attribute_spec.rb
64
66
  - spec/spec_helper.rb
65
67
  - spec/to_aduki_spec.rb
66
68
  - spec/to_date_spec.rb
@@ -92,6 +94,8 @@ summary: set object attributes recursively from an attributes hash
92
94
  test_files:
93
95
  - spec/initializer_spec.rb
94
96
  - spec/model.rb
97
+ - spec/nil_initializer_spec.rb
98
+ - spec/number_attribute_spec.rb
95
99
  - spec/spec_helper.rb
96
100
  - spec/to_aduki_spec.rb
97
101
  - spec/to_date_spec.rb