Class: Unleash::Context
- Inherits:
-
Object
- Object
- Unleash::Context
- Defined in:
- lib/unleash/context.rb
Instance Attribute Summary collapse
-
#app_name ⇒ Object
Returns the value of attribute app_name.
-
#environment ⇒ Object
Returns the value of attribute environment.
-
#properties ⇒ Object
Returns the value of attribute properties.
-
#remote_address ⇒ Object
Returns the value of attribute remote_address.
-
#session_id ⇒ Object
Returns the value of attribute session_id.
-
#user_id ⇒ Object
Returns the value of attribute user_id.
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ Context
constructor
A new instance of Context.
- #to_s ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Context
Returns a new instance of Context.
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/unleash/context.rb', line 6 def initialize(params = {}) raise ArgumentError, "Unleash::Context must be initialized with a hash." unless params.is_a?(Hash) self.app_name = params.values_at('appName', :app_name).compact.first || ( !Unleash.configuration.nil? ? Unleash.configuration.app_name : nil ) self.environment = params.values_at('environment', :environment).compact.first || ( !Unleash.configuration.nil? ? Unleash.configuration.environment : 'default' ) self.user_id = params.values_at('userId', :user_id).compact.first || '' self.session_id = params.values_at('sessionId', :session_id).compact.first || '' self.remote_address = params.values_at('remoteAddress', :remote_address).compact.first || '' properties = params.values_at('properties', :properties).compact.first self.properties = properties.is_a?(Hash) ? properties : {} end |
Instance Attribute Details
#app_name ⇒ Object
Returns the value of attribute app_name.
4 5 6 |
# File 'lib/unleash/context.rb', line 4 def app_name @app_name end |
#environment ⇒ Object
Returns the value of attribute environment.
4 5 6 |
# File 'lib/unleash/context.rb', line 4 def environment @environment end |
#properties ⇒ Object
Returns the value of attribute properties.
4 5 6 |
# File 'lib/unleash/context.rb', line 4 def properties @properties end |
#remote_address ⇒ Object
Returns the value of attribute remote_address.
4 5 6 |
# File 'lib/unleash/context.rb', line 4 def remote_address @remote_address end |
#session_id ⇒ Object
Returns the value of attribute session_id.
4 5 6 |
# File 'lib/unleash/context.rb', line 4 def session_id @session_id end |
#user_id ⇒ Object
Returns the value of attribute user_id.
4 5 6 |
# File 'lib/unleash/context.rb', line 4 def user_id @user_id end |
Instance Method Details
#to_s ⇒ Object
19 20 21 |
# File 'lib/unleash/context.rb', line 19 def to_s "<Context: user_id=#{self.user_id},session_id=#{self.session_id},remote_address=#{self.remote_address},properties=#{self.properties}>" end |