Class: ReeEnum::Value

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_classObject (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_nameObject (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_valueObject (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

#methodObject (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

#valueObject (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

#inspectObject



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_literalObject



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_sObject



15
16
17
# File 'lib/ree_lib/packages/ree_enum/package/ree_enum/value.rb', line 15

def to_s
  value.to_s
end