class Shamu::Features::Context

Captures the environment and request specific context used to match {Toggle} selectors and determine if a feature should be enabled.

Attributes

features_service[R]

Public Class Methods

new( features_service, **attributes ) click to toggle source

@!endgroup Attributes

Calls superclass method Shamu::Attributes::new
# File lib/shamu/features/context.rb, line 43
def initialize( features_service, **attributes )
  @features_service = features_service
  super( **attributes )
end

Public Instance Methods

enabled?( name ) click to toggle source

Check if feature is enabled.

# File lib/shamu/features/context.rb, line 58
def enabled?( name )
  features_service.enabled?( name )
end
env( name ) click to toggle source

Retrieve a value from the host machine's environment. Abstracts over the ENV hash to permit some filtering and to facilitate specs.

@param [String] name of the environment variable. @return [String] the environment variable.

# File lib/shamu/features/context.rb, line 53
def env( name )
  ENV[name]
end
sticky!() click to toggle source

Remember the toggle selection in persistent storage for the user so that they will receive the same result each time.

# File lib/shamu/features/context.rb, line 64
def sticky!
  @sticky = true
  self
end
sticky?() click to toggle source

@return [Boolean] true if the feature election should be remembered

between requests.
# File lib/shamu/features/context.rb, line 71
def sticky?
  @sticky
end