Sha256: d75d8cd0c097a93e20b1cee889cd7cda766240fbe503fb95cab28eaf2b64057d

Contents?: true

Size: 1.42 KB

Versions: 19

Compression:

Stored size: 1.42 KB

Contents

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

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

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

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

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
devcycle-ruby-server-sdk-3.2.0 lib/devcycle-ruby-server-sdk/localbucketing/proto/helpers.rb
devcycle-ruby-server-sdk-3.1.0 lib/devcycle-ruby-server-sdk/localbucketing/proto/helpers.rb
devcycle-ruby-server-sdk-3.0.0 lib/devcycle-ruby-server-sdk/localbucketing/proto/helpers.rb
devcycle-ruby-server-sdk-2.7.1 lib/devcycle-ruby-server-sdk/localbucketing/proto/helpers.rb
devcycle-ruby-server-sdk-2.6.3 lib/devcycle-ruby-server-sdk/localbucketing/proto/helpers.rb
devcycle-ruby-server-sdk-2.6.2 lib/devcycle-ruby-server-sdk/localbucketing/proto/helpers.rb
devcycle-ruby-server-sdk-2.6.1 lib/devcycle-ruby-server-sdk/localbucketing/proto/helpers.rb
devcycle-ruby-server-sdk-2.6.0 lib/devcycle-ruby-server-sdk/localbucketing/proto/helpers.rb
devcycle-ruby-server-sdk-2.5.0 lib/devcycle-ruby-server-sdk/localbucketing/proto/helpers.rb
devcycle-ruby-server-sdk-2.4.1 lib/devcycle-ruby-server-sdk/localbucketing/proto/helpers.rb
devcycle-ruby-server-sdk-2.4.0 lib/devcycle-ruby-server-sdk/localbucketing/proto/helpers.rb
devcycle-ruby-server-sdk-2.3.5 lib/devcycle-ruby-server-sdk/localbucketing/proto/helpers.rb
devcycle-ruby-server-sdk-2.3.4 lib/devcycle-ruby-server-sdk/localbucketing/proto/helpers.rb
devcycle-ruby-server-sdk-2.3.3 lib/devcycle-ruby-server-sdk/localbucketing/proto/helpers.rb
devcycle-ruby-server-sdk-2.3.2 lib/devcycle-ruby-server-sdk/localbucketing/proto/helpers.rb
devcycle-ruby-server-sdk-2.3.1 lib/devcycle-ruby-server-sdk/localbucketing/proto/helpers.rb
devcycle-ruby-server-sdk-2.3.0 lib/devcycle-ruby-server-sdk/localbucketing/proto/helpers.rb
devcycle-ruby-server-sdk-2.2.1 lib/devcycle-ruby-server-sdk/localbucketing/proto/helpers.rb
devcycle-ruby-server-sdk-2.2.0 lib/devcycle-ruby-server-sdk/localbucketing/proto/helpers.rb