vexile 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/vexile/version.rb +1 -1
- data/lib/vexile.rb +8 -4
- data/spec/main_spec.rb +17 -0
- metadata +2 -2
data/lib/vexile/version.rb
CHANGED
data/lib/vexile.rb
CHANGED
@@ -13,10 +13,12 @@ module Vexile
|
|
13
13
|
end
|
14
14
|
|
15
15
|
class VexileProxy < Proxy
|
16
|
+
attr_reader :__source__
|
16
17
|
def __setobj__ value
|
17
18
|
klass = @options[:owner_class].vexile_const_lookup(@options[:class_name])
|
18
19
|
raise "#{@options[:class_name]} is not a vexile class" unless klass
|
19
20
|
@target = klass.new
|
21
|
+
@__source__ = value
|
20
22
|
load_params value
|
21
23
|
end
|
22
24
|
end
|
@@ -30,10 +32,12 @@ module Vexile
|
|
30
32
|
Vexile.klasses << self
|
31
33
|
include ActiveModel::Validations
|
32
34
|
|
33
|
-
def load_params
|
34
|
-
|
35
|
-
|
36
|
-
self.
|
35
|
+
def load_params hsh
|
36
|
+
if hsh.kind_of? Hash
|
37
|
+
hsh.each do |key, value|
|
38
|
+
if self.respond_to? "#{key}="
|
39
|
+
self.__send__("#{key}=", value)
|
40
|
+
end
|
37
41
|
end
|
38
42
|
end
|
39
43
|
end
|
data/spec/main_spec.rb
CHANGED
@@ -19,6 +19,7 @@ describe Vexile do
|
|
19
19
|
attr_accessor :p5, :p6
|
20
20
|
validates :bs, :size => {:min => 1, :max => 2}, :recursive => true
|
21
21
|
has_many :bs
|
22
|
+
has_one :a
|
22
23
|
end
|
23
24
|
|
24
25
|
class Test
|
@@ -78,4 +79,20 @@ describe Vexile do
|
|
78
79
|
end.to_not raise_error
|
79
80
|
t.c.class.should == Namespaced::C
|
80
81
|
end
|
82
|
+
|
83
|
+
it "should save original loaded part" do
|
84
|
+
t = Test.new
|
85
|
+
t.c = {:p5 => 1, :p6 => 2, :bs => [{:p3 => "test1", :p4 => "test2"}]}
|
86
|
+
t.c.__source__.should == {:p5 => 1, :p6 => 2, :bs => [{:p3 => "test1", :p4 => "test2"}]}
|
87
|
+
t.c.bs.first.__source__.should == {:p3 => "test1", :p4 => "test2"}
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should not raise NoMethodError while non-hash object loaded (just not initialize attribs)" do
|
91
|
+
t = Test.new
|
92
|
+
expect{ t.c = "test" }.to_not raise_error
|
93
|
+
expect{ t.valid? }.to_not raise_error
|
94
|
+
expect{ t.c = {:p5 => 1, :p6 => 2, :a => "test"} }.to_not raise_error
|
95
|
+
t.c.__source__.should == {:p5 => 1, :p6 => 2, :a => "test"}
|
96
|
+
t.c.a.__source__.should == "test"
|
97
|
+
end
|
81
98
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vexile
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
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: 2013-01-
|
12
|
+
date: 2013-01-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|