simple_eav 0.1.0 → 0.2.0
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.
- data/lib/simple_eav.rb +5 -7
- data/lib/version.rb +1 -1
- data/spec/lib/simple_eav_spec.rb +19 -0
- metadata +2 -2
data/lib/simple_eav.rb
CHANGED
@@ -5,9 +5,7 @@ module SimpleEav
|
|
5
5
|
serialize @@column
|
6
6
|
end
|
7
7
|
|
8
|
-
def simple_eav_column
|
9
|
-
@@column if defined? @@column
|
10
|
-
end
|
8
|
+
def simple_eav_column; @@column end
|
11
9
|
end
|
12
10
|
|
13
11
|
def self.included(base)
|
@@ -15,7 +13,7 @@ module SimpleEav
|
|
15
13
|
end
|
16
14
|
|
17
15
|
def simple_eav_column
|
18
|
-
self.class.simple_eav_column
|
16
|
+
self.class.simple_eav_column
|
19
17
|
end
|
20
18
|
|
21
19
|
def actual_columns_of_table
|
@@ -33,8 +31,8 @@ module SimpleEav
|
|
33
31
|
def attributes=(_attributes={})
|
34
32
|
#Iterate over each attribute:
|
35
33
|
# - skip columns that are actually defined in the db
|
36
|
-
# - remove undefined columns to prevent UnknownAttribute::Error from being thrown
|
37
|
-
simple_eav_attrs = read_attribute(
|
34
|
+
# - remove undefined columns to prevent UnknownAttribute::Error from being thrown
|
35
|
+
simple_eav_attrs = read_attribute(simple_eav_column.to_sym) || {}
|
38
36
|
_attributes.each do |column,value|
|
39
37
|
next if actual_columns_of_table.include?(column)
|
40
38
|
simple_eav_attrs[column] = value
|
@@ -50,7 +48,7 @@ module SimpleEav
|
|
50
48
|
|
51
49
|
def method_missing(method, *args, &block)
|
52
50
|
if method.to_s =~ /=$/
|
53
|
-
_attributes =
|
51
|
+
_attributes = read_attribute(simple_eav_column.to_sym) || {}
|
54
52
|
setter = method.to_s.gsub(/=/, '')
|
55
53
|
_attributes[setter.to_sym] = args.shift
|
56
54
|
self.simple_eav_attributes = _attributes
|
data/lib/version.rb
CHANGED
data/spec/lib/simple_eav_spec.rb
CHANGED
@@ -67,6 +67,13 @@ describe SimpleEav do
|
|
67
67
|
person.name.should eql('John')
|
68
68
|
end
|
69
69
|
end
|
70
|
+
|
71
|
+
describe "#method_missing" do
|
72
|
+
it "does not reference the eav_column directly (causes stack overflow error)" do
|
73
|
+
person = Person.new
|
74
|
+
lambda{ person.name = 'John' }.should_not raise_error(SystemStackError)
|
75
|
+
end
|
76
|
+
end
|
70
77
|
|
71
78
|
describe "A missing attribute" do
|
72
79
|
before( :each ) do
|
@@ -83,6 +90,18 @@ describe SimpleEav do
|
|
83
90
|
end
|
84
91
|
end
|
85
92
|
end
|
93
|
+
|
94
|
+
describe "Adding an attribute with existing attributes" do
|
95
|
+
before(:each) do
|
96
|
+
@person = Person.create! :name=>'Jim'
|
97
|
+
end
|
98
|
+
|
99
|
+
it "updates the attributes without removing the old" do
|
100
|
+
@person.update_attributes :cell_number => 911
|
101
|
+
@person.name.should eql('Jim')
|
102
|
+
@person.cell_number.should eql(911)
|
103
|
+
end
|
104
|
+
end
|
86
105
|
|
87
106
|
describe "A custom attribute" do
|
88
107
|
describe "John is a Person" do
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: simple_eav
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.2.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Tim Linquist
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-07-19 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|