Class: Unleash::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/unleash/context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Context

Returns a new instance of Context.

Raises:

  • (ArgumentError)


5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/unleash/context.rb', line 5

def initialize(params = {})
  raise ArgumentError, "Unleash::Context must be initialized with a hash." unless params.is_a?(Hash)

  self.app_name    = value_for('appName', params, Unleash&.configuration&.app_name)
  self.environment = value_for('environment', params, Unleash&.configuration&.environment || 'default')
  self.user_id     = value_for('userId', params)
  self.session_id  = value_for('sessionId', params)
  self.remote_address = value_for('remoteAddress', params)

  properties = value_for('properties', params)
  self.properties = properties.is_a?(Hash) ? properties : {}
end

Instance Attribute Details

#app_nameObject

Returns the value of attribute app_name.



3
4
5
# File 'lib/unleash/context.rb', line 3

def app_name
  @app_name
end

#environmentObject

Returns the value of attribute environment.



3
4
5
# File 'lib/unleash/context.rb', line 3

def environment
  @environment
end

#propertiesObject

Returns the value of attribute properties.



3
4
5
# File 'lib/unleash/context.rb', line 3

def properties
  @properties
end

#remote_addressObject

Returns the value of attribute remote_address.



3
4
5
# File 'lib/unleash/context.rb', line 3

def remote_address
  @remote_address
end

#session_idObject

Returns the value of attribute session_id.



3
4
5
# File 'lib/unleash/context.rb', line 3

def session_id
  @session_id
end

#user_idObject

Returns the value of attribute user_id.



3
4
5
# File 'lib/unleash/context.rb', line 3

def user_id
  @user_id
end

Instance Method Details

#to_sObject



18
19
20
# File 'lib/unleash/context.rb', line 18

def to_s
  "<Context: user_id=#{self.user_id},session_id=#{self.session_id},remote_address=#{self.remote_address},properties=#{self.properties}>"
end