Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #36 from fringd/fix-warnings-in-3-1-1

fix deprecation warnings with 3.1.1
  • Loading branch information...
commit 84d78eb9f51f50cf9d746021c3d1933ba8f4258c 2 parents 3d827b0 + ab39bf4
@turadg turadg authored
Showing with 21 additions and 17 deletions.
  1. +2 −2 README.rdoc
  2. +19 −15 lib/enumerated_attribute/integrations/active_record.rb
View
4 README.rdoc
@@ -557,9 +557,9 @@ ActiveRecord's write_attribute and read_attribute methods do not support symbols
== Testing
-The plugin uses RSpec and Webrat for testing. Make sure you have the RSpec gem installed:
+The plugin uses jeweler, RSpec, and Webrat for testing. Make sure you have these gems installed:
- gem install rspec webrat
+ gem install rspec webrat jeweler
To test the plugin for regular ruby objects, run:
View
34 lib/enumerated_attribute/integrations/active_record.rb
@@ -18,7 +18,7 @@ def validate_enumerated_attribute
end
end
end
-
+
def write_enumerated_attribute(name, val)
name = name.to_s
return write_attribute(name, val) unless self.class.has_enumerated_attribute?(name)
@@ -29,7 +29,7 @@ def write_enumerated_attribute(name, val)
write_attribute(name, val_str)
val_sym
end
-
+
def read_enumerated_attribute(name)
name = name.to_s
#if not enumerated - let active record handle it
@@ -42,17 +42,21 @@ def read_enumerated_attribute(name)
val = val.to_sym if !!val
val
end
-
+
def attributes=(attrs, guard_protected_attributes=true)
return if attrs.nil?
- #check the attributes then turn them over
+ #check the attributes then turn them over
attrs.each do |k, v|
attrs[k] = v.to_s if self.class.has_enumerated_attribute?(k)
end
-
- super
+
+ if guard_protected_attributes
+ super(attrs) #prevents deprecation warnings for rails 3.1.1
+ else
+ super(attrs, guard_protected_attributes)
+ end
end
-
+
def attributes
atts = super
atts.each do |k,v|
@@ -62,23 +66,23 @@ def attributes
end
atts
end
-
+
def [](attr_name); read_enumerated_attribute(attr_name); end
def []=(attr_name, value); write_enumerated_attribute(attr_name, value); end
-
+
private
-
+
def attribute=(attr_name, value); write_enumerated_attribute(attr_name, value); end
-
+
module ClassMethods
private
-
+
def construct_attributes_from_arguments(attribute_names, arguments)
attributes = {}
attribute_names.each_with_index{|name, idx| attributes[name] = has_enumerated_attribute?(name) ? arguments[idx].to_s : arguments[idx]}
attributes
end
-
+
def instantiate(record)
object = super(record)
self.enumerated_attributes.each do |k,v|
@@ -88,7 +92,7 @@ def instantiate(record)
end
object
end
-
+
def define_enumerated_attribute_new_method
class_eval do
class << self
@@ -113,6 +117,6 @@ def new(*args, &block)
end
end
end
- end
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.