kludge 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/kludge/many.rb +13 -8
- data/lib/kludge/one.rb +1 -0
- data/lib/kludge/parts.rb +0 -1
- data/lib/kludge/version.rb +1 -1
- data/spec/kludge/parts_spec.rb +2 -2
- metadata +4 -4
data/lib/kludge/many.rb
CHANGED
@@ -2,6 +2,10 @@ module Kludge
|
|
2
2
|
class Many < Part
|
3
3
|
|
4
4
|
def save
|
5
|
+
if parent
|
6
|
+
parent.value.send("#{name}=", value)
|
7
|
+
end
|
8
|
+
|
5
9
|
value.each(&:save)
|
6
10
|
super
|
7
11
|
end
|
@@ -22,18 +26,19 @@ module Kludge
|
|
22
26
|
end
|
23
27
|
|
24
28
|
def value=(value)
|
25
|
-
@value = value.
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
29
|
+
@value = if value.is_a?(Hash)
|
30
|
+
value.map do |key, value|
|
31
|
+
@name.to_s.classify.constantize.find(value.delete(:id)).tap { |v| v.assign_attributes(value) }
|
32
|
+
end
|
33
|
+
else
|
34
|
+
value.map do |val|
|
35
|
+
if val.is_a?(Hash)
|
30
36
|
@name.to_s.classify.constantize.new(val)
|
37
|
+
else
|
38
|
+
val
|
31
39
|
end
|
32
|
-
else
|
33
|
-
val
|
34
40
|
end
|
35
41
|
end
|
36
42
|
end
|
37
|
-
|
38
43
|
end
|
39
44
|
end
|
data/lib/kludge/one.rb
CHANGED
data/lib/kludge/parts.rb
CHANGED
data/lib/kludge/version.rb
CHANGED
data/spec/kludge/parts_spec.rb
CHANGED
@@ -2,8 +2,8 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Kludge::Parts do
|
4
4
|
let(:parts) { Kludge::Parts.new }
|
5
|
-
let(:trunk_val) { mock :trunk_val, :valid? => true }
|
6
|
-
let(:branch_val) { mock :branch_val, :valid? => true }
|
5
|
+
let(:trunk_val) { mock :trunk_val, :valid? => true, :branch= => true }
|
6
|
+
let(:branch_val) { mock :branch_val, :valid? => true, :leaves= => true }
|
7
7
|
let(:leaves_val) { mock :leaves_val, :valid? => true }
|
8
8
|
let(:trunk) { Kludge::One.new(:trunk, :value => trunk_val) }
|
9
9
|
let(:branch) { Kludge::One.new(:branch, :belongs_to => :trunk, :value => branch_val) }
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kludge
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- hubert
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2013-05-
|
19
|
+
date: 2013-05-29 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: activemodel
|