From 72ed24bc70d0ffa16cb57bee627f0c6f325821fe Mon Sep 17 00:00:00 2001 From: "Alistair A. Israel" Date: Fri, 23 Nov 2012 22:48:45 +0800 Subject: [PATCH 1/3] Fix for https://github.com/jeffp/enumerated_attribute/issues/60 --- lib/enumerated_attribute/integrations/active_record.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/enumerated_attribute/integrations/active_record.rb b/lib/enumerated_attribute/integrations/active_record.rb index f4daa6d..04399f4 100644 --- a/lib/enumerated_attribute/integrations/active_record.rb +++ b/lib/enumerated_attribute/integrations/active_record.rb @@ -103,7 +103,7 @@ def new(*args, &block) result end end - unless private_method_defined?(:method_missing_without_enumerated_attribute) + unless method_defined?(:method_missing_without_enumerated_attribute) || private_method_defined?(:method_missing_without_enumerated_attribute) define_chained_method(:method_missing, :enumerated_attribute) do |method_id, *arguments| arguments = arguments.map{|arg| arg.is_a?(Symbol) ? arg.to_s : arg } method_missing_without_enumerated_attribute(method_id, *arguments) From d8435c7e4dc1b1b6d349708a5bd94b0d6b8ec25f Mon Sep 17 00:00:00 2001 From: "Alistair A. Israel" Date: Tue, 27 Nov 2012 12:52:11 +0800 Subject: [PATCH 2/3] Avoid deprecation warnings when used with frameworks such as Devise. --- lib/enumerated_attribute/integrations/active_record.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/enumerated_attribute/integrations/active_record.rb b/lib/enumerated_attribute/integrations/active_record.rb index 04399f4..0f109c2 100644 --- a/lib/enumerated_attribute/integrations/active_record.rb +++ b/lib/enumerated_attribute/integrations/active_record.rb @@ -21,7 +21,15 @@ def validate_enumerated_attribute def write_enumerated_attribute(name, val) name = name.to_s - return write_attribute(name, val) unless self.class.has_enumerated_attribute?(name) + unless self.class.has_enumerated_attribute?(name) + # allow for 'virtual' attributes such as when using Devise (:password, :confirm_password) + setter = "#{name}=".to_sym + if !self.attribute_names.include?(name) && self.methods.include?(setter) + return self.send(setter, val) + else + return write_attribute(name, val) + end + end val = nil if val == '' val_str = val.to_s if val val_sym = val.to_sym if val From 7ae21346d600f1699df2d981cabe467e1879bb61 Mon Sep 17 00:00:00 2001 From: "Alistair A. Israel" Date: Wed, 5 Dec 2012 14:51:38 +0800 Subject: [PATCH 3/3] Added /.project to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 5e4a47c..4eb7cd9 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ vendor lib/tasks/* TODO.rdoc webrat-*.html +/.project