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

Inherits:
Union
  • Object
show all
Includes:
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 =
'Value'.freeze
NAMESPACE =
'types.value'.freeze
LEGACY_ANNOTATIONS =
{
}.freeze
STRUCTURED_ANNOTATIONS =
[
].freeze
THRIFT_FIELD_INDEX_NULL_VALUE =
1
THRIFT_FIELD_INDEX_STRING_VALUE =
2
THRIFT_FIELD_INDEX_BINARY_VALUE =
3
THRIFT_FIELD_INDEX_INTEGER_VALUE =
4
THRIFT_FIELD_INDEX_DOUBLE_VALUE =
5
THRIFT_FIELD_INDEX_BOOL_VALUE =
6
THRIFT_FIELD_INDEX_LIST_VALUE =
7
THRIFT_FIELD_INDEX_MAP_VALUE =
8
THRIFT_FIELD_INDEX_STRUCT_VALUE =
9
THRIFT_FIELD_NULL_VALUE_LEGACY_ANNOTATIONS =
{
}.freeze
THRIFT_FIELD_NULL_VALUE_STRUCTURED_ANNOTATIONS =
[
].freeze
THRIFT_FIELD_STRING_VALUE_LEGACY_ANNOTATIONS =
{
}.freeze
THRIFT_FIELD_STRING_VALUE_STRUCTURED_ANNOTATIONS =
[
].freeze
THRIFT_FIELD_BINARY_VALUE_LEGACY_ANNOTATIONS =
{
}.freeze
THRIFT_FIELD_BINARY_VALUE_STRUCTURED_ANNOTATIONS =
[
].freeze
THRIFT_FIELD_INTEGER_VALUE_LEGACY_ANNOTATIONS =
{
}.freeze
THRIFT_FIELD_INTEGER_VALUE_STRUCTURED_ANNOTATIONS =
[
].freeze
THRIFT_FIELD_DOUBLE_VALUE_LEGACY_ANNOTATIONS =
{
}.freeze
THRIFT_FIELD_DOUBLE_VALUE_STRUCTURED_ANNOTATIONS =
[
].freeze
THRIFT_FIELD_BOOL_VALUE_LEGACY_ANNOTATIONS =
{
}.freeze
THRIFT_FIELD_BOOL_VALUE_STRUCTURED_ANNOTATIONS =
[
].freeze
THRIFT_FIELD_LIST_VALUE_LEGACY_ANNOTATIONS =
{
}.freeze
THRIFT_FIELD_LIST_VALUE_STRUCTURED_ANNOTATIONS =
[
].freeze
THRIFT_FIELD_MAP_VALUE_LEGACY_ANNOTATIONS =
{
}.freeze
THRIFT_FIELD_MAP_VALUE_STRUCTURED_ANNOTATIONS =
[
].freeze
THRIFT_FIELD_STRUCT_VALUE_LEGACY_ANNOTATIONS =
{
}.freeze
THRIFT_FIELD_STRUCT_VALUE_STRUCTURED_ANNOTATIONS =
[
].freeze
FIELDS =
{
  THRIFT_FIELD_INDEX_NULL_VALUE => {type: ::Thrift::Types::STRUCT, name: 'null_value', class: ::Thrift::Types::Value::NullValue, legacy_annotations: THRIFT_FIELD_NULL_VALUE_LEGACY_ANNOTATIONS, structured_annotations: THRIFT_FIELD_NULL_VALUE_STRUCTURED_ANNOTATIONS},
  THRIFT_FIELD_INDEX_STRING_VALUE => {type: ::Thrift::Types::STRING, name: 'string_value', legacy_annotations: THRIFT_FIELD_STRING_VALUE_LEGACY_ANNOTATIONS, structured_annotations: THRIFT_FIELD_STRING_VALUE_STRUCTURED_ANNOTATIONS},
  THRIFT_FIELD_INDEX_BINARY_VALUE => {type: ::Thrift::Types::STRING, name: 'binary_value', binary: true, legacy_annotations: THRIFT_FIELD_BINARY_VALUE_LEGACY_ANNOTATIONS, structured_annotations: THRIFT_FIELD_BINARY_VALUE_STRUCTURED_ANNOTATIONS},
  THRIFT_FIELD_INDEX_INTEGER_VALUE => {type: ::Thrift::Types::I64, name: 'integer_value', legacy_annotations: THRIFT_FIELD_INTEGER_VALUE_LEGACY_ANNOTATIONS, structured_annotations: THRIFT_FIELD_INTEGER_VALUE_STRUCTURED_ANNOTATIONS},
  THRIFT_FIELD_INDEX_DOUBLE_VALUE => {type: ::Thrift::Types::DOUBLE, name: 'double_value', legacy_annotations: THRIFT_FIELD_DOUBLE_VALUE_LEGACY_ANNOTATIONS, structured_annotations: THRIFT_FIELD_DOUBLE_VALUE_STRUCTURED_ANNOTATIONS},
  THRIFT_FIELD_INDEX_BOOL_VALUE => {type: ::Thrift::Types::BOOL, name: 'bool_value', legacy_annotations: THRIFT_FIELD_BOOL_VALUE_LEGACY_ANNOTATIONS, structured_annotations: THRIFT_FIELD_BOOL_VALUE_STRUCTURED_ANNOTATIONS},
  THRIFT_FIELD_INDEX_LIST_VALUE => {type: ::Thrift::Types::STRUCT, name: 'list_value', class: ::Thrift::Types::Value::ListValue, legacy_annotations: THRIFT_FIELD_LIST_VALUE_LEGACY_ANNOTATIONS, structured_annotations: THRIFT_FIELD_LIST_VALUE_STRUCTURED_ANNOTATIONS},
  THRIFT_FIELD_INDEX_MAP_VALUE => {type: ::Thrift::Types::STRUCT, name: 'map_value', class: ::Thrift::Types::Value::MapValue, legacy_annotations: THRIFT_FIELD_MAP_VALUE_LEGACY_ANNOTATIONS, structured_annotations: THRIFT_FIELD_MAP_VALUE_STRUCTURED_ANNOTATIONS},
  THRIFT_FIELD_INDEX_STRUCT_VALUE => {type: ::Thrift::Types::STRUCT, name: 'struct_value', class: ::Thrift::Types::Value::StructValue, legacy_annotations: THRIFT_FIELD_STRUCT_VALUE_LEGACY_ANNOTATIONS, structured_annotations: THRIFT_FIELD_STRUCT_VALUE_STRUCTURED_ANNOTATIONS}
}

Constants included from Struct_Union

Struct_Union::CONTAINER_TYPES

Class Method Summary collapse

Instance Method Summary collapse

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

Methods inherited from Union

#<=>, #==, #eql?, field_accessor, generate_accessors, #get_set_field, #get_value, #hash, #initialize, #inspect, qmark_isset_method, #read, #write

Constructor Details

This class inherits a constructor from Thrift::Union

Class Method Details

.binary_value(val) ⇒ Object



216
217
218
# File 'lib/thrift/types/value/value_types.rb', line 216

def binary_value(val)
  Value.new(:binary_value, val)
end

.bool_value(val) ⇒ Object



228
229
230
# File 'lib/thrift/types/value/value_types.rb', line 228

def bool_value(val)
  Value.new(:bool_value, val)
end

.double_value(val) ⇒ Object



224
225
226
# File 'lib/thrift/types/value/value_types.rb', line 224

def double_value(val)
  Value.new(:double_value, val)
end

.from_object(v) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/thrift/types/value/value.rb', line 84

def from_object(v)
  case v
  when NilClass
    Value.new(null_value: NullValue.new)
  when Symbol
    Value.new(string_value: v.to_s)
  when String
    if v.encoding.eql?(Encoding::UTF_8) && v.valid_encoding?
      Value.new(string_value: v)
    else
      Value.new(binary_value: v)
    end
  when Integer
    Value.new(integer_value: v)
  when Float
    Value.new(double_value: v)
  when TrueClass, FalseClass
    Value.new(bool_value: v)
  when Array
    Value.new(list_value: ListValue.from_array(v))
  when Hash
    Value.new(map_value: MapValue.from_hash(v))
  else
    Value.new(struct_value: StructValue.from_object(v))
  end
end

.integer_value(val) ⇒ Object



220
221
222
# File 'lib/thrift/types/value/value_types.rb', line 220

def integer_value(val)
  Value.new(:integer_value, val)
end

.list_value(val) ⇒ Object



232
233
234
# File 'lib/thrift/types/value/value_types.rb', line 232

def list_value(val)
  Value.new(:list_value, val)
end

.map_value(val) ⇒ Object



236
237
238
# File 'lib/thrift/types/value/value_types.rb', line 236

def map_value(val)
  Value.new(:map_value, val)
end

.null_value(val) ⇒ Object



208
209
210
# File 'lib/thrift/types/value/value_types.rb', line 208

def null_value(val)
  Value.new(:null_value, val)
end

.string_value(val) ⇒ Object



212
213
214
# File 'lib/thrift/types/value/value_types.rb', line 212

def string_value(val)
  Value.new(:string_value, val)
end

.struct_value(val) ⇒ Object



240
241
242
# File 'lib/thrift/types/value/value_types.rb', line 240

def struct_value(val)
  Value.new(:struct_value, val)
end

Instance Method Details

#struct_fieldsObject



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

def struct_fields; FIELDS; end

#to_objectObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/thrift/types/value/value.rb', line 68

def to_object
  case get_value.class
  when NullValue
     nil
  when ListValue
    list_value.to_array
  when MapValue
    map_value.to_hash
  when StructValue
    struct_value.to_hash
  else
    get_value
  end
end

#validateObject

Raises:

  • (StandardError)


323
324
325
# File 'lib/thrift/types/value/value_types.rb', line 323

def validate
  raise(StandardError, 'Union fields are not set.') if get_set_field.nil? || get_value.nil?
end