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 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.map do |val|
26
- if val.kind_of?(Hash)
27
- if val[:id].present?
28
- @name.to_s.classify.constantize.find(val.delete(:id)).tap { |v| v.assign_attributes(val) }
29
- else
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
@@ -2,6 +2,7 @@ module Kludge
2
2
  class One < Part
3
3
 
4
4
  def save
5
+ parent.value.send("#{name}=", value) if parent
5
6
  value.save
6
7
  super
7
8
  end
data/lib/kludge/parts.rb CHANGED
@@ -57,4 +57,3 @@ module Kludge
57
57
  end
58
58
  end
59
59
  end
60
-
@@ -1,3 +1,3 @@
1
1
  module Kludge
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -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: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
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-14 00:00:00 Z
19
+ date: 2013-05-29 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: activemodel