Updated readme, added :validate option. Version bumped to 0.1.1
This commit is contained in:
parent
38dd9d4edf
commit
01298e44ee
@ -5,7 +5,7 @@ Status](https://travis-ci.org/thetron/mongoid-enum.png)](https://travis-ci.org/t
|
|||||||
|
|
||||||
Heavily inspired by [DHH's
|
Heavily inspired by [DHH's
|
||||||
ActiveRecord::Enum](https://github.com/rails/rails/commit/db41eb8a6ea88b854bf5cd11070ea4245e1639c5), this little library is
|
ActiveRecord::Enum](https://github.com/rails/rails/commit/db41eb8a6ea88b854bf5cd11070ea4245e1639c5), this little library is
|
||||||
just there to help you cut down the cruft in your models and make the
|
there to help you cut down the cruft in your models and make the
|
||||||
world a happier place at the same time.
|
world a happier place at the same time.
|
||||||
|
|
||||||
A single line will get you fields, accessors, validations and scopes,
|
A single line will get you fields, accessors, validations and scopes,
|
||||||
@ -141,7 +141,7 @@ your field are always from your list of options. If you need more
|
|||||||
complex validations, or you just want to throw caution to the wind, you
|
complex validations, or you just want to throw caution to the wind, you
|
||||||
can turn them off:
|
can turn them off:
|
||||||
|
|
||||||
enum :status => [:up, :down], :validation => false
|
enum :status => [:up, :down], :validate => false
|
||||||
|
|
||||||
|
|
||||||
# Issues and Feature Requests
|
# Issues and Feature Requests
|
||||||
|
@ -11,6 +11,7 @@ module Mongoid
|
|||||||
multiple = options[:multiple] || false
|
multiple = options[:multiple] || false
|
||||||
default = options[:default].nil? && values.first || options[:default]
|
default = options[:default].nil? && values.first || options[:default]
|
||||||
required = options[:required].nil? || options[:required]
|
required = options[:required].nil? || options[:required]
|
||||||
|
validate = options[:validate].nil? || options[:validate]
|
||||||
|
|
||||||
const_set const_name, values
|
const_set const_name, values
|
||||||
|
|
||||||
@ -18,9 +19,9 @@ module Mongoid
|
|||||||
field field_name, :type => type, :default => default
|
field field_name, :type => type, :default => default
|
||||||
alias_attribute name, field_name
|
alias_attribute name, field_name
|
||||||
|
|
||||||
if multiple
|
if multiple && validate
|
||||||
validates field_name, :'mongoid/enum/validators/multiple' => { :in => values, :allow_nil => !required }
|
validates field_name, :'mongoid/enum/validators/multiple' => { :in => values, :allow_nil => !required }
|
||||||
else
|
elsif validate
|
||||||
validates field_name, :inclusion => {:in => values}, :allow_nil => !required
|
validates field_name, :inclusion => {:in => values}, :allow_nil => !required
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
module Mongoid
|
module Mongoid
|
||||||
module Enum
|
module Enum
|
||||||
VERSION = "0.1.0"
|
VERSION = "0.1.1"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user