Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for https://github.com/jeffp/enumerated_attribute/issues/60 #61

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ vendor
lib/tasks/*
TODO.rdoc
webrat-*.html
/.project
12 changes: 10 additions & 2 deletions lib/enumerated_attribute/integrations/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -103,7 +111,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)
Expand Down