simple_eav 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,11 +1,14 @@
1
1
  = simple_eav
2
2
 
3
- simple_eav provides a more simple alternative to {acts_as_eav_model}[https://github.com/visfleet/acts_as_eav_model] that works with
3
+ == UPDATE
4
+ Version 1.0.0, is only compatible with >= 3.1. If you are still bound to < 3.1 please use an older version of this gem.
5
+
6
+ simple_eav provides a more simple alternative to {acts_as_eav_model}[https://github.com/visfleet/acts_as_eav_model] that works with
4
7
  ActiveRecord without any monkey patching. This gem is designed to be a replacement for acts_as_eav_model.
5
8
 
6
- Acts_as_eav_model's purpose is to provide a model with any number of custom attributes. This project has the same purpose. The difference being maintaining utmost compatibility with ActiveRecord::Base.
9
+ Acts_as_eav_model's purpose is to provide a model with any number of custom attributes. This project has the same purpose. The difference being maintaining utmost compatibility with ActiveRecord::Base.
7
10
 
8
- Version 0.1.0 makes this library, to my knowledge, fully compatible with acts_as_eav_model. This update introduced the ability to specify custom attributes exactly the same as attributes with an actual column in the database ie:
11
+ This library, to my knowledge, is fully compatible with acts_as_eav_model. This update introduced the ability to specify custom attributes exactly the same as attributes with an actual column in the database ie:
9
12
 
10
13
  Person.create :attribute_with_column=>true, :attribute_without_column=>true
11
14
 
@@ -32,17 +35,11 @@ Version 0.1.0 makes this library, to my knowledge, fully compatible with acts_as
32
35
  person = Person.new
33
36
  person.name = 'Joe'
34
37
  person.name ~> 'Joe'
35
-
38
+
36
39
  person = Person.new :name => 'Joe'
37
40
  person.save!
38
41
  person.name ~> 'Joe'
39
42
 
40
- == Migrating to simple_eav
41
- I have not done this yet but will hopefully be making the transition soon. I'll update the README once that's complete or let me know what you find if you migrate your project first.
42
- At the moment, a migration would be needed that:
43
- - Moves each attribute record to a key => value pair for the simple_eav_column on the model using acts_as_eav_model
44
- - Destroys each attribute record
45
-
46
43
  == Contributing
47
44
 
48
45
  * Fork the project.
data/lib/simple_eav.rb CHANGED
@@ -40,7 +40,7 @@ module SimpleEav
40
40
 
41
41
  def simple_eav_attributes
42
42
  _attributes = self.send(simple_eav_column.to_sym)
43
- _attributes.is_a?(Hash) ? _attributes : {}
43
+ (_attributes.is_a?(Hash) ? _attributes : {}).with_indifferent_access
44
44
  end
45
45
 
46
46
  def simple_eav_attributes=(attributes={})
@@ -51,7 +51,7 @@ module SimpleEav
51
51
  #Iterate over each attribute:
52
52
  # - skip columns that are actually defined in the db
53
53
  # - remove undefined columns to prevent UnknownAttribute::Error from being thrown
54
- simple_eav_attrs = read_attribute(simple_eav_column.to_sym) || {}
54
+ simple_eav_attrs = read_attribute(simple_eav_column.to_sym) || {}.with_indifferent_access
55
55
  _attributes.each do |column,value|
56
56
  next if reserved_attribute?(column.to_sym)
57
57
  simple_eav_attrs[column] = value
@@ -67,7 +67,7 @@ module SimpleEav
67
67
  end
68
68
 
69
69
  def method_missing(method, *args, &block)
70
- _attributes = read_attribute(simple_eav_column.to_sym) || {}
70
+ _attributes = read_attribute(simple_eav_column.to_sym) || {}.with_indifferent_access
71
71
  if method.to_s =~ /=$/
72
72
  setter = method.to_s.gsub(/=/, '')
73
73
  _attributes[setter.to_sym] = args.shift
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module SimpleEav
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -116,6 +116,17 @@ describe SimpleEav do
116
116
  person.reload
117
117
  person.age.to_i.should eql 99
118
118
  end
119
+
120
+ it "sets the person's height with a string for the key" do
121
+ person = Person.create 'height' => "6'1"
122
+ person.height.should == "6'1"
123
+ end
124
+
125
+ it "sets the person's height with a symbol for the key" do
126
+ person = Person.create :height => "6'1"
127
+ person.height.should == "6'1"
128
+ end
129
+
119
130
  it "does not set the age in the simple eav attributes" do
120
131
  person = Person.create(:age=>97, :new_age=>98)
121
132
  person.simple_eav_attributes.should_not have_key :age
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: simple_eav
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.0.0
5
+ version: 1.0.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Tim Linquist
@@ -10,11 +10,10 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-10-17 00:00:00 Z
13
+ date: 2011-11-22 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
17
- prerelease: false
18
17
  requirement: &id001 !ruby/object:Gem::Requirement
19
18
  none: false
20
19
  requirements:
@@ -22,10 +21,10 @@ dependencies:
22
21
  - !ruby/object:Gem::Version
23
22
  version: "3.1"
24
23
  type: :runtime
24
+ prerelease: false
25
25
  version_requirements: *id001
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: ruby-debug19
28
- prerelease: false
29
28
  requirement: &id002 !ruby/object:Gem::Requirement
30
29
  none: false
31
30
  requirements:
@@ -33,10 +32,10 @@ dependencies:
33
32
  - !ruby/object:Gem::Version
34
33
  version: "0"
35
34
  type: :development
35
+ prerelease: false
36
36
  version_requirements: *id002
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: sqlite3
39
- prerelease: false
40
39
  requirement: &id003 !ruby/object:Gem::Requirement
41
40
  none: false
42
41
  requirements:
@@ -44,10 +43,10 @@ dependencies:
44
43
  - !ruby/object:Gem::Version
45
44
  version: 1.3.3
46
45
  type: :development
46
+ prerelease: false
47
47
  version_requirements: *id003
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: rake
50
- prerelease: false
51
50
  requirement: &id004 !ruby/object:Gem::Requirement
52
51
  none: false
53
52
  requirements:
@@ -55,10 +54,10 @@ dependencies:
55
54
  - !ruby/object:Gem::Version
56
55
  version: "0"
57
56
  type: :development
57
+ prerelease: false
58
58
  version_requirements: *id004
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: rspec
61
- prerelease: false
62
61
  requirement: &id005 !ruby/object:Gem::Requirement
63
62
  none: false
64
63
  requirements:
@@ -66,6 +65,7 @@ dependencies:
66
65
  - !ruby/object:Gem::Version
67
66
  version: 2.6.0
68
67
  type: :development
68
+ prerelease: false
69
69
  version_requirements: *id005
70
70
  description: A simple alternative to acts_as_eav_model that works with ActiveRecord without any monkey patching needed. Acts_as_eav_model's gives a model the ability to have any number of custom attributes. This project has the same goal. The difference being maintaining utmost compatability with ActiveRecord::Base.
71
71
  email:
@@ -105,12 +105,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
105
105
  requirements:
106
106
  - - ">="
107
107
  - !ruby/object:Gem::Version
108
+ hash: -1557123848780511245
109
+ segments:
110
+ - 0
108
111
  version: "0"
109
112
  required_rubygems_version: !ruby/object:Gem::Requirement
110
113
  none: false
111
114
  requirements:
112
115
  - - ">="
113
116
  - !ruby/object:Gem::Version
117
+ hash: -1557123848780511245
118
+ segments:
119
+ - 0
114
120
  version: "0"
115
121
  requirements: []
116
122