Top Level Namespace

Defined Under Namespace

Modules: DevCycle, Proto

Instance Method Summary collapse

Instance Method Details

#create_nullable_custom_data(data) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/devcycle-ruby-server-sdk/localbucketing/proto/helpers.rb', line 17

def create_nullable_custom_data(data)
  data_map = {}
  if data.nil? || data.length == 0
    return Proto::NullableCustomData.new(value: data_map, isNull: true)
  end

  data.each do |key, value|
    if value.nil?
      data_map[key] = Proto::CustomDataValue.new(type: Proto::CustomDataType::Null)
    end

    if value.is_a? String
      data_map[key] = Proto::CustomDataValue.new(type: Proto::CustomDataType::Str, stringValue: value)
    elsif value.is_a?(Float) || value.is_a?(Integer)
      data_map[key] = Proto::CustomDataValue.new(type: Proto::CustomDataType::Num, doubleValue: value)
    elsif value.is_a?(TrueClass) || value.is_a?(FalseClass)
      data_map[key] = Proto::CustomDataValue.new(type: Proto::CustomDataType::Bool, boolValue: value)
    end
  end

  Proto::NullableCustomData.new(value: data_map, isNull: false)
end

#create_nullable_double(val) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/devcycle-ruby-server-sdk/localbucketing/proto/helpers.rb', line 9

def create_nullable_double(val)
  if val.nil?
    Proto::NullableDouble.new(value: 0, isNull: true)
  else
    Proto::NullableDouble.new(value: val, isNull: false)
  end
end

#create_nullable_string(val) ⇒ Object



1
2
3
4
5
6
7
# File 'lib/devcycle-ruby-server-sdk/localbucketing/proto/helpers.rb', line 1

def create_nullable_string(val)
  if val.nil? || val.empty?
    Proto::NullableString.new(value: "", isNull: true)
  else
    Proto::NullableString.new(value: val, isNull: false)
  end
end

#get_variable_value(variable_pb) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/devcycle-ruby-server-sdk/localbucketing/proto/helpers.rb', line 40

def get_variable_value(variable_pb)
  case variable_pb.type
  when :Boolean
    variable_pb.boolValue
  when :Number
    variable_pb.doubleValue
  when :String
    variable_pb.stringValue
  when :JSON
    JSON.parse variable_pb.stringValue
  end
end