Class: Thrift::Types::Value::StructValue

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 =
'StructValue'.freeze
NAMESPACE =
'types.value'.freeze
LEGACY_ANNOTATIONS =
{
}.freeze
STRUCTURED_ANNOTATIONS =
[
].freeze
THRIFT_FIELD_INDEX_FIELDS =
1
THRIFT_FIELD_FIELDS_LEGACY_ANNOTATIONS =
{
}.freeze
THRIFT_FIELD_FIELDS_STRUCTURED_ANNOTATIONS =
[
].freeze
FIELDS =
{
  THRIFT_FIELD_INDEX_FIELDS => {type: ::Thrift::Types::MAP, name: 'fields', key: {type: ::Thrift::Types::STRING}, value: {type: ::Thrift::Types::STRUCT, class: ::Thrift::Types::Value::Value}, legacy_annotations: THRIFT_FIELD_FIELDS_LEGACY_ANNOTATIONS, structured_annotations: THRIFT_FIELD_FIELDS_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_object(v) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/thrift/types/value/value.rb', line 49

def from_object(v)
  StructValue.new(
    fields: v.instance_variables.reduce({}) do |acc, k|
      acc.merge(
        k.to_s[1..-1] => Value.from_object(v.instance_variable_get(k))
      )
    end
  )
end

Instance Method Details

#struct_fieldsObject



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

def struct_fields; FIELDS; end

#to_hashObject



42
43
44
45
46
# File 'lib/thrift/types/value/value.rb', line 42

def to_hash
  fields.reduce({}) do |acc, (k, v)|
    acc.merge(k => v.to_object)
  end
end

#validateObject



187
188
189
# File 'lib/thrift/types/value/value_types.rb', line 187

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