simple_eav 0.2.0 → 0.3.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 +11 -10
- data/lib/version.rb +1 -1
- data/spec/lib/simple_eav_spec.rb +4 -0
- metadata +3 -5
data/lib/simple_eav.rb
CHANGED
@@ -13,29 +13,30 @@ module SimpleEav
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def simple_eav_column
|
16
|
-
self.class.simple_eav_column
|
16
|
+
self.class.simple_eav_column
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
def actual_columns_of_table
|
20
20
|
self.class.columns.map{|col| col.name.to_sym }
|
21
21
|
end
|
22
22
|
|
23
23
|
def simple_eav_attributes
|
24
|
-
self.send(simple_eav_column.to_sym)
|
24
|
+
_attributes = self.send(simple_eav_column.to_sym)
|
25
|
+
_attributes.is_a?(Hash) ? _attributes : {}
|
25
26
|
end
|
26
27
|
|
27
28
|
def simple_eav_attributes=(attributes={})
|
28
29
|
self.send("#{simple_eav_column}=", attributes)
|
29
30
|
end
|
30
|
-
|
31
|
+
|
31
32
|
def attributes=(_attributes={})
|
32
33
|
#Iterate over each attribute:
|
33
34
|
# - skip columns that are actually defined in the db
|
34
|
-
# - remove undefined columns to prevent UnknownAttribute::Error from being thrown
|
35
|
+
# - remove undefined columns to prevent UnknownAttribute::Error from being thrown
|
35
36
|
simple_eav_attrs = read_attribute(simple_eav_column.to_sym) || {}
|
36
37
|
_attributes.each do |column,value|
|
37
38
|
next if actual_columns_of_table.include?(column)
|
38
|
-
simple_eav_attrs[column] = value
|
39
|
+
simple_eav_attrs[column] = value
|
39
40
|
_attributes.delete(column)
|
40
41
|
end
|
41
42
|
self.simple_eav_attributes = simple_eav_attrs
|
@@ -47,13 +48,13 @@ module SimpleEav
|
|
47
48
|
end
|
48
49
|
|
49
50
|
def method_missing(method, *args, &block)
|
51
|
+
_attributes = read_attribute(simple_eav_column.to_sym) || {}
|
50
52
|
if method.to_s =~ /=$/
|
51
|
-
_attributes = read_attribute(simple_eav_column.to_sym) || {}
|
52
53
|
setter = method.to_s.gsub(/=/, '')
|
53
54
|
_attributes[setter.to_sym] = args.shift
|
54
|
-
self.simple_eav_attributes = _attributes
|
55
|
-
elsif
|
56
|
-
|
55
|
+
return self.simple_eav_attributes = _attributes
|
56
|
+
elsif _attributes.has_key?(method.to_sym)
|
57
|
+
return _attributes[method.to_sym]
|
57
58
|
else
|
58
59
|
super(method, *args, &block)
|
59
60
|
end
|
data/lib/version.rb
CHANGED
data/spec/lib/simple_eav_spec.rb
CHANGED
@@ -13,6 +13,10 @@ describe SimpleEav do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
describe "Expected ActiveRecord behavior" do
|
16
|
+
it "handles an empty string of attributes" do
|
17
|
+
person = Person.create(:simple_attributes=>'')
|
18
|
+
person.should_not be_new_record
|
19
|
+
end
|
16
20
|
describe "given a hash of undefined attributes" do
|
17
21
|
it "creates a person with a name" do
|
18
22
|
person = Person.create(:name=>'Joseph')
|
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.3.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Tim Linquist
|
@@ -10,8 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-07-
|
14
|
-
default_executable:
|
13
|
+
date: 2011-07-30 00:00:00 Z
|
15
14
|
dependencies:
|
16
15
|
- !ruby/object:Gem::Dependency
|
17
16
|
name: activerecord
|
@@ -80,7 +79,6 @@ files:
|
|
80
79
|
- spec/lib/simple_eav_spec.rb
|
81
80
|
- spec/spec_helper.rb
|
82
81
|
- spec/support/person.rb
|
83
|
-
has_rdoc: true
|
84
82
|
homepage: http://github.com/timo3377/simple_eav
|
85
83
|
licenses: []
|
86
84
|
|
@@ -104,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
102
|
requirements: []
|
105
103
|
|
106
104
|
rubyforge_project:
|
107
|
-
rubygems_version: 1.
|
105
|
+
rubygems_version: 1.8.3
|
108
106
|
signing_key:
|
109
107
|
specification_version: 3
|
110
108
|
summary: A simple alternative to acts_as_eav_model.
|