Class: ReeEnum::Value
- Inherits:
-
Object
- Object
- ReeEnum::Value
- Defined in:
- lib/ree_lib/packages/ree_dao/package/ree_dao.rb,
lib/ree_lib/packages/ree_enum/package/ree_enum/value.rb
Overview
ReeEnum::Value#sql_literal is used to properly serialize enum values for database queries
Instance Attribute Summary collapse
-
#enum_class ⇒ Object
readonly
Returns the value of attribute enum_class.
-
#enum_name ⇒ Object
readonly
Returns the value of attribute enum_name.
-
#mapped_value ⇒ Object
readonly
Returns the value of attribute mapped_value.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #==(compare) ⇒ Object
- #as_json(*args) ⇒ Object
-
#initialize(enum_class, enum_name, value, mapped_value, method) ⇒ Value
constructor
A new instance of Value.
- #inspect ⇒ Object
- #sql_literal ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(enum_class, enum_name, value, mapped_value, method) ⇒ Value
Returns a new instance of Value.
7 8 9 10 11 12 13 |
# File 'lib/ree_lib/packages/ree_enum/package/ree_enum/value.rb', line 7 def initialize(enum_class, enum_name, value, mapped_value, method) @enum_class = enum_class @enum_name = enum_name @value = value @method = method @mapped_value = mapped_value end |
Instance Attribute Details
#enum_class ⇒ Object (readonly)
Returns the value of attribute enum_class.
4 5 6 |
# File 'lib/ree_lib/packages/ree_enum/package/ree_enum/value.rb', line 4 def enum_class @enum_class end |
#enum_name ⇒ Object (readonly)
Returns the value of attribute enum_name.
4 5 6 |
# File 'lib/ree_lib/packages/ree_enum/package/ree_enum/value.rb', line 4 def enum_name @enum_name end |
#mapped_value ⇒ Object (readonly)
Returns the value of attribute mapped_value.
4 5 6 |
# File 'lib/ree_lib/packages/ree_enum/package/ree_enum/value.rb', line 4 def mapped_value @mapped_value end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
4 5 6 |
# File 'lib/ree_lib/packages/ree_enum/package/ree_enum/value.rb', line 4 def method @method end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
4 5 6 |
# File 'lib/ree_lib/packages/ree_enum/package/ree_enum/value.rb', line 4 def value @value end |
Instance Method Details
#==(compare) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/ree_lib/packages/ree_enum/package/ree_enum/value.rb', line 24 def ==(compare) if compare.is_a?(self.class) value == compare.value elsif compare.is_a?(Symbol) && value.is_a?(String) value.to_sym == compare else value == compare || mapped_value == compare end end |
#as_json(*args) ⇒ Object
19 20 21 |
# File 'lib/ree_lib/packages/ree_enum/package/ree_enum/value.rb', line 19 def as_json(*args) value end |
#inspect ⇒ Object
34 35 36 |
# File 'lib/ree_lib/packages/ree_enum/package/ree_enum/value.rb', line 34 def inspect "#{enum_class.name}##{value}" end |
#sql_literal ⇒ Object
33 34 35 |
# File 'lib/ree_lib/packages/ree_dao/package/ree_dao.rb', line 33 def sql_literal(*) mapped_value.to_s end |
#to_s ⇒ Object
15 16 17 |
# File 'lib/ree_lib/packages/ree_enum/package/ree_enum/value.rb', line 15 def to_s value.to_s end |