Class: Virtus::Attribute::Boolean
- Inherits:
-
Virtus::Attribute
- Object
- Virtus::Attribute
- Virtus::Attribute::Boolean
- Defined in:
- lib/virtus/attribute/boolean.rb
Overview
Boolean attribute allows true or false values to be set Additionally it adds boolean reader method, like “admin?”
Constant Summary
Constants included from TypeLookup
Instance Attribute Summary
Attributes inherited from Virtus::Attribute
#coercer, #default_value, #options, #primitive, #type
Class Method Summary collapse
- .build_type ⇒ Object private
Instance Method Summary collapse
-
#define_accessor_methods(attribute_set) ⇒ undefined
private
Creates an attribute reader method as a query.
-
#value_coerced?(value) ⇒ Boolean
Returns if the given value is either true or false.
Methods inherited from Virtus::Attribute
build, build_coercer, coerce, #coerce, #coercible?, #finalize, #finalized?, #initialize, #lazy?, merge_options!, #nullify_blank?, #rename, #required?, #strict?
Methods included from TypeLookup
#determine_type, extended, #primitive
Methods included from Options
#accept_options, #accepted_options, #options
Constructor Details
This class inherits a constructor from Virtus::Attribute
Class Method Details
.build_type ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
21 22 23 |
# File 'lib/virtus/attribute/boolean.rb', line 21 def self.build_type(*) Axiom::Types::Boolean end |
Instance Method Details
#define_accessor_methods(attribute_set) ⇒ undefined
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates an attribute reader method as a query
48 49 50 51 |
# File 'lib/virtus/attribute/boolean.rb', line 48 def define_accessor_methods(attribute_set) super attribute_set.define_reader_method(self, "#{name}?", [:reader]) end |
#value_coerced?(value) ⇒ Boolean
Returns if the given value is either true or false
37 38 39 |
# File 'lib/virtus/attribute/boolean.rb', line 37 def value_coerced?(value) value.equal?(true) || value.equal?(false) end |