Class: ActiveValidation::Values::Base
- Inherits:
-
Object
- Object
- ActiveValidation::Values::Base
- Defined in:
- lib/active_validation/values/base.rb
Direct Known Subclasses
Constant Summary collapse
- BAD_VALUES =
[nil, true, false].freeze
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
- #as_json ⇒ Object
-
#initialize(value) ⇒ Base
constructor
A new instance of Base.
- #to_s ⇒ Object
- #to_sym ⇒ Object
Constructor Details
#initialize(value) ⇒ Base
Returns a new instance of Base.
10 11 12 13 14 |
# File 'lib/active_validation/values/base.rb', line 10 def initialize(value) raise ArgumentError, "Value of #{self.class} can not be #{value.inspect}" if BAD_VALUES.include? value @value = value.freeze end |
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the value of attribute value.
8 9 10 |
# File 'lib/active_validation/values/base.rb', line 8 def value @value end |
Instance Method Details
#<=>(other) ⇒ Object
16 17 18 19 20 |
# File 'lib/active_validation/values/base.rb', line 16 def <=>(other) raise ArgumentError, "Inconcictent classes #{self.class} and #{other.class}" unless self.class == other.class value <=> other.value end |
#==(other) ⇒ Object
22 23 24 |
# File 'lib/active_validation/values/base.rb', line 22 def ==(other) value == (other.class == self.class ? other.value : other) end |
#as_json ⇒ Object
34 35 36 |
# File 'lib/active_validation/values/base.rb', line 34 def as_json(*) value end |
#to_s ⇒ Object
26 27 28 |
# File 'lib/active_validation/values/base.rb', line 26 def to_s value.to_s end |
#to_sym ⇒ Object
30 31 32 |
# File 'lib/active_validation/values/base.rb', line 30 def to_sym value.to_sym end |