Class: GMO::PG::Payload::TypecastableValue
- Inherits:
-
Object
- Object
- GMO::PG::Payload::TypecastableValue
- Defined in:
- lib/gmo-pg/http_resource/payload/typecast.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(value) ⇒ TypecastableValue
constructor
A new instance of TypecastableValue.
- #to_attribute ⇒ Object
- #to_payload ⇒ Object
Constructor Details
#initialize(value) ⇒ TypecastableValue
Returns a new instance of TypecastableValue.
32 33 34 |
# File 'lib/gmo-pg/http_resource/payload/typecast.rb', line 32 def initialize(value) @value = value end |
Instance Attribute Details
#value ⇒ Object
Returns the value of attribute value.
16 17 18 |
# File 'lib/gmo-pg/http_resource/payload/typecast.rb', line 16 def value @value end |
Class Method Details
.from_hash(typecast_option) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/gmo-pg/http_resource/payload/typecast.rb', line 18 def self.from_hash(typecast_option) Class.new(self) do define_method :to_attribute do return super() unless typecast_option[:to_attribute].is_a?(Proc) typecast_option[:to_attribute].call(@value) rescue super() end define_method :to_payload do return super() unless typecast_option[:to_payload].is_a?(Proc) typecast_option[:to_payload].call(@value) rescue super() end end end |
Instance Method Details
#==(other) ⇒ Object
44 45 46 47 |
# File 'lib/gmo-pg/http_resource/payload/typecast.rb', line 44 def ==(other) other_value = other.is_a?(self.class) ? other.to_payload : other to_payload == other_value end |
#to_attribute ⇒ Object
36 37 38 |
# File 'lib/gmo-pg/http_resource/payload/typecast.rb', line 36 def to_attribute @value end |
#to_payload ⇒ Object
40 41 42 |
# File 'lib/gmo-pg/http_resource/payload/typecast.rb', line 40 def to_payload @value.to_s end |