Class: Virtus::Attribute::Boolean
- Inherits:
-
Object
- Object
- Virtus::Attribute
- Object
- 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
#coercion_method, #default, #name, #options
Instance Method Summary collapse
-
#define_reader_method(mod) ⇒ self
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, #coerce, #define_accessor_methods, #define_writer_method, determine_type, #get, #get!, #initialize, #inspect, merge_options, #public_reader?, #public_writer?, #set, #set!
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
Instance Method Details
#define_reader_method(mod) ⇒ self
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
44 45 46 47 48 |
# File 'lib/virtus/attribute/boolean.rb', line 44 def define_reader_method(mod) super mod.define_reader_method(self, "#{name}?", @reader_visibility) self end |
#value_coerced?(value) ⇒ Boolean
Returns if the given value is either true or false
33 34 35 |
# File 'lib/virtus/attribute/boolean.rb', line 33 def value_coerced?(value) value.equal?(true) or value.equal?(false) end |