aduki 0.0.9 → 0.0.10

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.
@@ -43,6 +43,8 @@ module Aduki
43
43
  value.to_i
44
44
  elsif type && (type <= Float)
45
45
  value.to_f
46
+ elsif type.respond_to? :aduki_find
47
+ type.aduki_find value
46
48
  else
47
49
  type ? type.new(value) : value
48
50
  end
@@ -1,3 +1,3 @@
1
1
  module Aduki
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
@@ -0,0 +1,18 @@
1
+ require "aduki"
2
+ require "spec_helper"
3
+
4
+ describe Aduki::Initializer do
5
+
6
+ it "should assign a value using a custom finder" do
7
+ props = {
8
+ "name" => "Anna Livia",
9
+ "city" => "dublin"
10
+ }
11
+
12
+ contraption = MachineBuilder.new props
13
+
14
+ expect(contraption.name).to eq "Anna Livia"
15
+ expect(contraption.city).to eq CITIES["dublin"]
16
+ expect(contraption.city.name).to eq "Dublin"
17
+ end
18
+ end
@@ -5,6 +5,20 @@ RSpec.configure do |config|
5
5
  config.order = 'random'
6
6
  end
7
7
 
8
+
9
+ CITIES = { }
10
+
11
+ class City < Struct.new(:name)
12
+ def self.aduki_find value
13
+ CITIES[value]
14
+ end
15
+ end
16
+
17
+ CITIES["paris"] = City.new "Paris"
18
+ CITIES["madrid"] = City.new "Madrid"
19
+ CITIES["stockholm"] = City.new "Stockholm"
20
+ CITIES["dublin"] = City.new "Dublin"
21
+
8
22
  class Contraption
9
23
  include Aduki::Initializer
10
24
  attr_accessor :x, :y, :planned, :updated
@@ -19,7 +33,8 @@ end
19
33
 
20
34
  class MachineBuilder
21
35
  include Aduki::Initializer
22
- attr_accessor :name, :email, :phone, :office
36
+ attr_accessor :name, :email, :phone, :office, :city
37
+ aduki :city => City
23
38
  end
24
39
 
25
40
  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.0.9
4
+ version: 0.0.10
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-09 00:00:00.000000000 Z
12
+ date: 2014-02-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -60,6 +60,7 @@ files:
60
60
  - lib/aduki.rb
61
61
  - lib/aduki/version.rb
62
62
  - spec/array_attribute_spec.rb
63
+ - spec/custom_builder_spec.rb
63
64
  - spec/initializer_spec.rb
64
65
  - spec/model.rb
65
66
  - spec/nil_initializer_spec.rb
@@ -94,6 +95,7 @@ specification_version: 3
94
95
  summary: set object attributes recursively from an attributes hash
95
96
  test_files:
96
97
  - spec/array_attribute_spec.rb
98
+ - spec/custom_builder_spec.rb
97
99
  - spec/initializer_spec.rb
98
100
  - spec/model.rb
99
101
  - spec/nil_initializer_spec.rb