Class: Featureflow::ContextBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/featureflow/context_builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ ContextBuilder

Returns a new instance of ContextBuilder.

Raises:

  • (ArgumentError)


3
4
5
6
7
8
# File 'lib/featureflow/context_builder.rb', line 3

def initialize(key)
  raise ArgumentError, 'Parameter key must be a String' unless key.is_a?(String) && !key.empty?
  @context_key = key
  @values = {}
  self
end

Instance Method Details

#buildObject



21
22
23
24
25
26
# File 'lib/featureflow/context_builder.rb', line 21

def build
  {
    key: @context_key,
    values: @values
  }
end

#with_values(hash) ⇒ Object

Raises:

  • (ArgumentError)


10
11
12
13
14
15
16
17
18
19
# File 'lib/featureflow/context_builder.rb', line 10

def with_values(hash)
  raise ArgumentError, 'Parameter hash must be a Hash' unless hash.is_a?(Hash)
  hash = hash.dup
  hash.each do |k, v|
    raise ArgumentError, "Value for #{k} must be a valid 'primitive' JSON datatype" unless valid_value?(v)
    hash[k.to_s] = h.delete(k) unless k.is_a?(String)
  end
  @values = @values.merge(hash)
  self
end