Class: Shamu::Features::Context
- Inherits:
-
Object
- Object
- Shamu::Features::Context
- Includes:
- Attributes
- Defined in:
- lib/shamu/features/context.rb
Overview
Captures the environment and request specific context used to match Toggle selectors and determine if a feature should be enabled.
Attributes collapse
-
#host ⇒ String
The name of the host machine.
-
#roles ⇒ Array<Symbol>
Roles assigned to the current user.
-
#scorpion ⇒ Scorpion
Used to dynamically look up dependencies by Conditions.
-
#time ⇒ Time
The current time.
-
#user_id ⇒ Integer, String
Id of the current user - either an Integer, or a UUID.
Instance Method Summary collapse
-
#enabled?(name) ⇒ Boolean
Check if feature is enabled.
-
#env(name) ⇒ String
Retrieve a value from the host machine's environment.
-
#initialize(features_service, **attributes) ⇒ Context
constructor
A new instance of Context.
-
#sticky! ⇒ Object
Remember the toggle selection in persistent storage for the user so that they will receive the same result each time.
-
#sticky? ⇒ Boolean
True if the feature election should be remembered between requests.
Methods included from Attributes
#[], #as_json, #assign_attributes, association, associations, attribute, #attribute?, attributes, #pretty_print, #set?, #slice, #to_attributes, #to_json
Constructor Details
#initialize(features_service, **attributes) ⇒ Context
Returns a new instance of Context.
43 44 45 46 |
# File 'lib/shamu/features/context.rb', line 43 def initialize( features_service, **attributes ) @features_service = features_service super( **attributes ) end |
Instance Attribute Details
#host ⇒ String
Returns the name of the host machine.
27 28 29 |
# File 'lib/shamu/features/context.rb', line 27 attribute :host do Socket.gethostname end |
#roles ⇒ Array<Symbol>
Returns roles assigned to the current user.
23 |
# File 'lib/shamu/features/context.rb', line 23 attribute :roles |
#scorpion ⇒ Scorpion
Returns used to dynamically look up dependencies by Shamu::Features::Conditions.
38 |
# File 'lib/shamu/features/context.rb', line 38 attribute :scorpion |
#time ⇒ Time
Returns the current time.
17 18 19 |
# File 'lib/shamu/features/context.rb', line 17 attribute :time do Time.zone ? Time.zone.now : Time.now end |
#user_id ⇒ Integer, String
Returns id of the current user - either an Integer, or a UUID.
33 |
# File 'lib/shamu/features/context.rb', line 33 attribute :user_id |
Instance Method Details
#enabled?(name) ⇒ Boolean
Check if feature is enabled.
58 59 60 |
# File 'lib/shamu/features/context.rb', line 58 def enabled?( name ) features_service.enabled?( name ) end |
#env(name) ⇒ String
Retrieve a value from the host machine's environment. Abstracts over the ENV hash to permit some filtering and to facilitate specs.
53 54 55 |
# File 'lib/shamu/features/context.rb', line 53 def env( name ) ENV[name] end |
#sticky! ⇒ Object
Remember the toggle selection in persistent storage for the user so that they will receive the same result each time.
64 65 66 67 |
# File 'lib/shamu/features/context.rb', line 64 def sticky! @sticky = true self end |
#sticky? ⇒ Boolean
Returns true if the feature election should be remembered between requests.
71 72 73 |
# File 'lib/shamu/features/context.rb', line 71 def sticky? @sticky end |