Module: LaunchDarkly::Impl::Context
- Defined in:
- lib/ldclient-rb/impl/context.rb
Overview
Constant Summary collapse
- ERR_KIND_NON_STRING =
'context kind must be a string'
- ERR_KIND_CANNOT_BE_KIND =
'"kind" is not a valid context kind'
- ERR_KIND_CANNOT_BE_MULTI =
'"multi" is not a valid context kind'
- ERR_KIND_INVALID_CHARS =
'context kind contains disallowed characters'
- ERR_KEY_NON_STRING =
'context key must be a string'
- ERR_KEY_EMPTY =
'context key must not be empty'
- ERR_NAME_NON_STRING =
'context name must be a string'
- ERR_ANONYMOUS_NON_BOOLEAN =
'context anonymous must be a boolean'
Class Method Summary collapse
- .canonicalize_key_for_kind(kind, key) ⇒ String
-
.make_context(context) ⇒ LDContext
We allow consumers of this SDK to provide us with either a Hash or an instance of an LDContext.
-
.validate_anonymous(anonymous, allow_nil) ⇒ String?
Returns an error message if anonymous is invalid; nil otherwise.
-
.validate_key(key) ⇒ String?
Returns an error message if the key is invalid; nil otherwise.
-
.validate_kind(kind) ⇒ String?
Returns an error message if the kind is invalid; nil otherwise.
-
.validate_name(name) ⇒ String?
Returns an error message if the name is invalid; nil otherwise.
Class Method Details
.canonicalize_key_for_kind(kind, key) ⇒ String
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
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.
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?
Returns an error message if anonymous is invalid; nil otherwise.
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?
Returns an error message if the key is invalid; nil otherwise.
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?
Returns an error message if the kind is invalid; nil otherwise.
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?
Returns an error message if the name is invalid; nil otherwise.
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 |