Class: TypeAdapter
- Inherits:
-
Object
- Object
- TypeAdapter
- Defined in:
- lib/type_adapter.rb
Instance Attribute Summary collapse
-
#adapted ⇒ Object
Returns the value of attribute adapted.
Instance Method Summary collapse
- #field_values ⇒ Object
-
#initialize(metadata, values) ⇒ TypeAdapter
constructor
A new instance of TypeAdapter.
Constructor Details
#initialize(metadata, values) ⇒ TypeAdapter
Returns a new instance of TypeAdapter.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/type_adapter.rb', line 4 def initialize(, values) case [:type] when ::Thrift::Types::STRUCT fields = adapt([:class]::FIELDS.values, values) self.adapted = [:class].new(fields) when ::Thrift::Types::LIST self.adapted = values.map { |v| adapt_field([:element], v) } when ::Thrift::Types::MAP self.adapted = Hash[*values.map { |v| [ adapt_field([:key], v), adapt_field([:value], v) ] }] else self.adapted = values end end |
Instance Attribute Details
#adapted ⇒ Object
Returns the value of attribute adapted.
2 3 4 |
# File 'lib/type_adapter.rb', line 2 def adapted @adapted end |
Instance Method Details
#field_values ⇒ Object
28 29 30 |
# File 'lib/type_adapter.rb', line 28 def field_values self.adapted.struct_fields.values.collect { |f| self.adapted.send(f[:name]) } end |