Class: Predicates::Enumerated
Overview
A basic pattern where the values are enumerated.
Options
-
:options - a complete collection of values that the attribute may contain
Example
field_is_enumerated :options => ['allowed_value_one', 'allowed_value_two']
Direct Known Subclasses
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Attributes inherited from Base
#full_message, #or_empty, #validate_if, #validate_on
Instance Method Summary collapse
- #error_message ⇒ Object
-
#initialize(attr, options = {}) ⇒ Enumerated
constructor
A new instance of Enumerated.
- #validate(value, record) ⇒ Object
Methods inherited from Base
#allow_empty?, #error, #error_binds, #normalize, #to_human
Constructor Details
#initialize(attr, options = {}) ⇒ Enumerated
Returns a new instance of Enumerated.
11 12 13 14 |
# File 'lib/predicates/enumerated.rb', line 11 def initialize(attr, = {}) [:or_empty] ||= false super(attr, ) end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
9 10 11 |
# File 'lib/predicates/enumerated.rb', line 9 def @options end |
Instance Method Details
#error_message ⇒ Object
16 17 18 |
# File 'lib/predicates/enumerated.rb', line 16 def @error_message || :inclusion end |
#validate(value, record) ⇒ Object
20 21 22 |
# File 'lib/predicates/enumerated.rb', line 20 def validate(value, record) self..include? value end |