Class: Thrift::Types::Value::MapValue

Inherits:
Object
  • Object
show all
Includes:
Struct, Struct_Union
Defined in:
lib/thrift/types/value/value.rb,
lib/thrift/types/value/value_types.rb,
lib/thrift/types/value/value_types.rb

Constant Summary collapse

NAME =
'MapValue'.freeze
NAMESPACE =
'types.value'.freeze
LEGACY_ANNOTATIONS =
{
}.freeze
STRUCTURED_ANNOTATIONS =
[
].freeze
THRIFT_FIELD_INDEX_ENTRIES =
1
THRIFT_FIELD_ENTRIES_LEGACY_ANNOTATIONS =
{
}.freeze
THRIFT_FIELD_ENTRIES_STRUCTURED_ANNOTATIONS =
[
].freeze
FIELDS =
{
  THRIFT_FIELD_INDEX_ENTRIES => {type: ::Thrift::Types::LIST, name: 'entries', element: {type: ::Thrift::Types::STRUCT, class: ::Thrift::Types::Value::MapEntry}, legacy_annotations: THRIFT_FIELD_ENTRIES_LEGACY_ANNOTATIONS, structured_annotations: THRIFT_FIELD_ENTRIES_STRUCTURED_ANNOTATIONS}
}

Constants included from Struct_Union

Struct_Union::CONTAINER_TYPES

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Struct

#<=>, #==, #differences, #eql?, field_accessor, #fields_with_default_values, generate_accessors, #hash, #initialize, #inspect, qmark_isset_method, #read, #write

Methods included from Struct_Union

#each_field, #field_info, #inspect_collection, #inspect_field, #is_container?, #name_to_id, #read_field, #sorted_field_ids, #write_container, #write_data

Class Method Details

.from_hash(v) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/thrift/types/value/value.rb', line 26

def from_hash(v)
  MapValue.new(
    entries: v.reduce([]) do |acc, (k, vv)|
      acc +  [
        MapEntry.new(
          key:   Value.from_object(k),
          value: Value.from_object(vv)
        )
      ]
    end
  )
end

Instance Method Details

#struct_fieldsObject



151
# File 'lib/thrift/types/value/value_types.rb', line 151

def struct_fields; FIELDS; end

#to_hashObject



19
20
21
22
23
# File 'lib/thrift/types/value/value.rb', line 19

def to_hash
  entries.reduce({}) do |acc, e|
    acc.merge(e.key.to_object => e.value.to_object)
  end
end

#validateObject



153
154
155
# File 'lib/thrift/types/value/value_types.rb', line 153

def validate
  raise ::Thrift::ProtocolException.new(::Thrift::ProtocolException::UNKNOWN, 'Required field entries is unset!') unless @entries
end