Module: LaunchDarkly::Impl::Context Private

Defined in:
lib/ldclient-rb/impl/context.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Since:

  • 5.5.0

Constant Summary collapse

ERR_KIND_NON_STRING =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Since:

  • 5.5.0

'context kind must be a string'
ERR_KIND_CANNOT_BE_KIND =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Since:

  • 5.5.0

'"kind" is not a valid context kind'
ERR_KIND_CANNOT_BE_MULTI =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Since:

  • 5.5.0

'"multi" is not a valid context kind'
ERR_KIND_INVALID_CHARS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Since:

  • 5.5.0

'context kind contains disallowed characters'
ERR_KEY_NON_STRING =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Since:

  • 5.5.0

'context key must be a string'
ERR_KEY_EMPTY =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Since:

  • 5.5.0

'context key must not be empty'
ERR_NAME_NON_STRING =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Since:

  • 5.5.0

'context name must be a string'
ERR_ANONYMOUS_NON_BOOLEAN =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Since:

  • 5.5.0

'context anonymous must be a boolean'

Class Method Summary collapse

Class Method Details

.canonicalize_key_for_kind(kind, key) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • kind (String)
  • key (String)

Returns:

  • (String)

Since:

  • 5.5.0



86
87
88
89
90
91
92
93
# File 'lib/ldclient-rb/impl/context.rb', line 86

def self.canonicalize_key_for_kind(kind, key)
  # When building a FullyQualifiedKey, ':' and '%' are percent-escaped;
  # we do not use a full URL-encoding function because implementations of
  # this are inconsistent across platforms.
  encoded = key.gsub("%", "%25").gsub(":", "%3A")

  "#{kind}:#{encoded}"
end

.make_context(context) ⇒ LDContext

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

We allow consumers of this SDK to provide us with either a Hash or an instance of an LDContext. This is convenient for them but not as much for us. To make the conversion slightly more convenient for us, we have created this method.

Parameters:

Returns:

Since:

  • 5.5.0



27
28
29
30
31
# File 'lib/ldclient-rb/impl/context.rb', line 27

def self.make_context(context)
  return context if context.is_a?(LDContext)

  LDContext.create(context)
end

.validate_anonymous(anonymous, allow_nil) ⇒ String?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns an error message if anonymous is invalid; nil otherwise.

Parameters:

  • anonymous (any)
  • allow_nil (Boolean)

Returns:

  • (String, nil)

Since:

  • 5.5.0



74
75
76
77
78
79
# File 'lib/ldclient-rb/impl/context.rb', line 74

def self.validate_anonymous(anonymous, allow_nil)
  return nil if anonymous.nil? && allow_nil
  return nil if [true, false].include? anonymous

  ERR_ANONYMOUS_NON_BOOLEAN
end

.validate_key(key) ⇒ String?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns an error message if the key is invalid; nil otherwise.

Parameters:

  • key (any)

Returns:

  • (String, nil)

Since:

  • 5.5.0



52
53
54
55
# File 'lib/ldclient-rb/impl/context.rb', line 52

def self.validate_key(key)
  return ERR_KEY_NON_STRING unless key.is_a?(String)
  ERR_KEY_EMPTY if key == ""
end

.validate_kind(kind) ⇒ String?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns an error message if the kind is invalid; nil otherwise.

Parameters:

  • kind (any)

Returns:

  • (String, nil)

Since:

  • 5.5.0



39
40
41
42
43
44
# File 'lib/ldclient-rb/impl/context.rb', line 39

def self.validate_kind(kind)
  return ERR_KIND_NON_STRING unless kind.is_a?(String)
  return ERR_KIND_CANNOT_BE_KIND if kind == "kind"
  return ERR_KIND_CANNOT_BE_MULTI if kind == "multi"
  ERR_KIND_INVALID_CHARS unless kind.match?(/^[\w.-]+$/)
end

.validate_name(name) ⇒ String?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns an error message if the name is invalid; nil otherwise.

Parameters:

  • name (any)

Returns:

  • (String, nil)

Since:

  • 5.5.0



63
64
65
# File 'lib/ldclient-rb/impl/context.rb', line 63

def self.validate_name(name)
  ERR_NAME_NON_STRING unless name.nil? || name.is_a?(String)
end