-
Notifications
You must be signed in to change notification settings - Fork 166
make sure getters always return Symbols #30
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
base: master
Are you sure you want to change the base?
Changes from all commits
bec99d6
12ed93e
de50b88
0db167f
cfb12c3
4368a48
d2f3b9f
5f1dc6a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,12 @@ | ||
script: "bundle exec rspec spec" | ||
|
||
sudo: false | ||
language: ruby | ||
|
||
rvm: | ||
- 1.9.3 | ||
- 2.0.0 | ||
- 2.1.0 | ||
- 2.1.1 | ||
- 2.1.2 | ||
- jruby-19mode | ||
|
||
services: | ||
- mongodb |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ def enum(name, values, options = {}) | |
|
||
create_field field_name, options | ||
|
||
create_validations field_name, values, options | ||
create_validations name, field_name, options | ||
define_value_scopes_and_accessors field_name, values, options | ||
define_field_accessor name, field_name, options | ||
end | ||
|
@@ -40,12 +40,11 @@ def create_field(field_name, options) | |
field field_name, :type => type, :default => options[:default] | ||
end | ||
|
||
def create_validations(field_name, values, options) | ||
def create_validations(name, field_name, options) | ||
if options[:multiple] && options[:validate] | ||
validates field_name, :'mongoid/enum/validators/multiple' => { :in => values.map(&:to_sym), :allow_nil => !options[:required] } | ||
#FIXME: Shouldn't this be `elsif options[:validate]` ??? | ||
elsif validate | ||
validates field_name, :inclusion => {:in => values.map(&:to_sym)}, :allow_nil => !options[:required] | ||
validates field_name, :'mongoid/enum/validators/multiple' => { :in => self.const_get(name.to_s.upcase), :allow_nil => !options[:required] } | ||
elsif options[:validate] | ||
validates field_name, :inclusion => {:in => self.const_get(name.to_s.upcase)}, :allow_nil => !options[:required] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. [122/80] |
||
end | ||
end | ||
|
||
|
@@ -71,12 +70,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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [149/80]
Use the new Ruby 1.9 hash syntax.
Redundant
self
detected.