aduki 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/aduki.rb +3 -7
- data/lib/aduki/version.rb +1 -1
- data/spec/attr_finder_spec.rb +7 -0
- data/spec/spec_helper.rb +5 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0681494a2a4133047eb70952bec208ddf1e737e4
|
4
|
+
data.tar.gz: 76eef24aa7d051a67faae78e7651c879655272fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb88d8aacc43c875b8f62ddc2cad6dae344adec9c7586afaa93805690d7d13dd3a5508bc8244ecf1a4476a92ccaf0aa16651fb4ef6c1de91f522cfe292f7442f
|
7
|
+
data.tar.gz: 8f8515478e5beda599113476a6d6d9e51cfd0ff3e6702d1a24db916291dbfab5e36b8ad3076d788190c99c4b76ba9cb83a233a966395357f551cfa1d84da55cd
|
data/lib/aduki.rb
CHANGED
@@ -89,13 +89,9 @@ module Aduki
|
|
89
89
|
def self.apply_array_attribute klass, object, getter, value
|
90
90
|
setter_method = "#{getter}=".to_sym
|
91
91
|
return unless object.respond_to? setter_method
|
92
|
-
|
93
|
-
array = object.send getter
|
94
|
-
if array == nil
|
95
|
-
array = []
|
96
|
-
object.send(setter_method, array)
|
97
|
-
end
|
92
|
+
array = object.send(getter) || []
|
98
93
|
array << to_value(klass, getter, value)
|
94
|
+
object.send(setter_method, array)
|
99
95
|
end
|
100
96
|
|
101
97
|
def self.apply_new_single_attribute klass, object, setter, value
|
@@ -177,7 +173,7 @@ module Aduki
|
|
177
173
|
end
|
178
174
|
|
179
175
|
def attr_many_finder finder, id, name, options={ }
|
180
|
-
class_eval Aduki::AttrFinder.one2many_attr_finder_text(finder, id, name, options
|
176
|
+
class_eval Aduki::AttrFinder.one2many_attr_finder_text(finder, id, name, options)
|
181
177
|
end
|
182
178
|
end
|
183
179
|
|
data/lib/aduki/version.rb
CHANGED
data/spec/attr_finder_spec.rb
CHANGED
@@ -9,6 +9,9 @@ describe Aduki::AttrFinder do
|
|
9
9
|
"gift_names[0]" => "dinner",
|
10
10
|
"gift_names[1]" => "whiskey",
|
11
11
|
"gift_names[2]" => "cigars",
|
12
|
+
"spk_ohms[0]" => 101,
|
13
|
+
"spk_ohms[1]" => 104,
|
14
|
+
"spk_ohms[2]" => 98,
|
12
15
|
}
|
13
16
|
|
14
17
|
politician = Politician.new props
|
@@ -17,6 +20,10 @@ describe Aduki::AttrFinder do
|
|
17
20
|
expect(politician.city).to eq City::CITIES["dublin"]
|
18
21
|
expect(politician.city.name).to eq "dublin"
|
19
22
|
expect(politician.gifts).to eq [Gift.lookup("dinner"), Gift.lookup("whiskey"), Gift.lookup("cigars")]
|
23
|
+
|
24
|
+
expect(politician.spks) .to be_a Array
|
25
|
+
expect(politician.spks.map(&:class).uniq).to eq [Speaker]
|
26
|
+
expect(politician.spks.map(&:ohms)) .to eq [101, 104, 98]
|
20
27
|
end
|
21
28
|
|
22
29
|
it "does not override a value with unknown identifier" do
|
data/spec/spec_helper.rb
CHANGED
@@ -45,6 +45,7 @@ class Politician
|
|
45
45
|
attr_accessor :name
|
46
46
|
attr_finder :aduki_find, :name, :city
|
47
47
|
attr_many_finder :lookup, :name, :gifts
|
48
|
+
attr_many_finder :make?, :ohms, :spks, :class_name => "Speaker"
|
48
49
|
end
|
49
50
|
|
50
51
|
class Contraption
|
@@ -73,6 +74,10 @@ class Speaker
|
|
73
74
|
aduki_initialize :dates, Array, Date
|
74
75
|
aduki_initialize :dimensions, Array, nil
|
75
76
|
aduki_initialize :threads, Array, nil
|
77
|
+
|
78
|
+
def self.make? ohms
|
79
|
+
ohms.is_a?(Integer) ? Speaker.new(ohms: ohms) : ohms.map { |o| make? o }
|
80
|
+
end
|
76
81
|
end
|
77
82
|
|
78
83
|
class Gadget
|