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

make sure getters always return Symbols #30

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Changes from 3 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
4 changes: 2 additions & 2 deletions lib/mongoid/enum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ def define_field_accessor(name, field_name, options)

def define_array_field_accessor(name, field_name)
class_eval "def #{name}=(vals) self.write_attribute(:#{field_name}, Array(vals).compact.map(&:to_sym)) end"
class_eval "def #{name}() self.read_attribute(:#{field_name}) end"
class_eval "def #{name}() self.send(:#{field_name}).map{ |i| i.try(:to_sym) } end"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [90/80]

end

def define_string_field_accessor(name, field_name)
class_eval "def #{name}=(val) self.write_attribute(:#{field_name}, val && val.to_sym || nil) end"
class_eval "def #{name}() self.read_attribute(:#{field_name}) end"
class_eval "def #{name}() self.send(:#{field_name}) end"
end

def define_array_accessor(field_name, value)
Expand Down