Class: Featureflow::UserBuilder
- Inherits:
-
Object
- Object
- Featureflow::UserBuilder
- Defined in:
- lib/featureflow/user_builder.rb
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(id) ⇒ UserBuilder
constructor
A new instance of UserBuilder.
- #with_attributes(hash) ⇒ Object
Constructor Details
#initialize(id) ⇒ UserBuilder
Returns a new instance of UserBuilder.
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
#build ⇒ Object
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
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 |