Class: Featureflow::UserBuilder

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

Instance Method Summary collapse

Constructor Details

#initialize(id) ⇒ UserBuilder

Returns a new instance of UserBuilder.

Raises:

  • (ArgumentError)


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

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

Instance Method Details

#buildObject



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

def build
  {
    id: @user_id,
    attributes: @attributes
  }
end

#with_attributes(hash) ⇒ Object

Raises:

  • (ArgumentError)


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

def with_attributes(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
  @attributes = @attributes.merge(hash)
  self
end