Module: EightBall

Defined in:
lib/eight_ball.rb,
lib/eight_ball/feature.rb,
lib/eight_ball/version.rb,
lib/eight_ball/configuration_error.rb

Overview

For all your feature querying needs.

Defined Under Namespace

Modules: Conditions, Marshallers, Providers Classes: ConfigurationError, Feature

Constant Summary collapse

VERSION =
'3.3.2'

Class Method Summary collapse

Class Method Details

.disabled?(name, parameters = {}) ⇒ Boolean, true

"EightBall, is the feature named 'NewFeature' disabled?"

Examples:

EightBall.disabled? 'feature1', account_id: 1

Parameters:

  • name (String)

    The name of the Feature.

  • parameters (Hash) (defaults to: {})

    The parameters the Conditions of this Feature are concerned with.

Returns:

  • (Boolean)

    whether or not the Feature is disabled.

  • (true)

    if Feature does not exist.



87
88
89
# File 'lib/eight_ball.rb', line 87

def self.disabled?(name, parameters = {})
  !enabled? name, parameters
end

.enabled?(name, parameters = {}) ⇒ Boolean, false

"EightBall, is the feature named 'NewFeature' enabled?"

Examples:

EightBall.enabled? 'feature1', account_id: 1

Parameters:

  • name (String)

    The name of the Feature.

  • parameters (Hash) (defaults to: {})

    The parameters the Conditions of this Feature are concerned with.

Returns:

  • (Boolean)

    whether or not the Feature is enabled.

  • (false)

    if Feature does not exist.



69
70
71
72
73
74
# File 'lib/eight_ball.rb', line 69

def self.enabled?(name, parameters = {})
  feature = provider.features.find { |f| f.name == name }
  return false unless feature

  feature.enabled? parameters
end

.featuresArray<EightBall::Feature>

Serves as a shortcut to access the Features available on the configured Provider



52
53
54
55
56
# File 'lib/eight_ball.rb', line 52

def self.features
  raise EightBall::ConfigurationError, 'No Provider has been configured; there can be no features. Please see "EightBall.provider="' unless provider

  provider.features
end

.loggerObject



129
130
131
132
133
# File 'lib/eight_ball.rb', line 129

def self.logger
  @logger ||= Logger.new(STDOUT).tap do |log|
    log.progname = name
  end
end

.logger=(logger) ⇒ Object



135
136
137
# File 'lib/eight_ball.rb', line 135

def self.logger=(logger)
  @logger = logger
end

.marshall(marshaller = nil, features = EightBall.features) ⇒ Object

Marshalls the Features. This can be useful for converting the data to, e.g., a JSON file.

If a Marshaller is provided, use it.

If no Marshaller is provided, uses the same Marshaller that the Provider is configured with.

If the Provider does not expose a Marshaller, this will default to the JSON Marshaller.



121
122
123
124
125
126
127
# File 'lib/eight_ball.rb', line 121

def self.marshall(marshaller = nil, features = EightBall.features)
  marshaller ||=
    (provider.respond_to?(:marshaller) && provider.marshaller) ||
    EightBall::Marshallers::Json.new

  marshaller.marshall features
end

.providerEightBall::Providers Provider

Gets the Provider instance EightBall is configured to use

Returns:



44
45
46
# File 'lib/eight_ball.rb', line 44

def self.provider
  @provider
end

.provider=(provider) ⇒ nil

Sets the Provider instance EightBall will use to obtain your list of Features.

Examples:

EightBall.provider = EightBall::Providers::Http.new 'http://www.rewind.io'

Returns:

  • (nil)


36
37
38
# File 'lib/eight_ball.rb', line 36

def self.provider=(provider)
  @provider = provider
end

.with(name, parameters = {}) ⇒ nil, false

Yields to the given block of code if the Feature is enabled.

Examples:

EightBall.with 'feature1', account_id: 1 do
  puts 'Feature is enabled!'
end

Parameters:

  • name (String)

    The name of the Feature.

  • parameters (Hash) (defaults to: {})

    The parameters the Conditions of this Feature are concerned with.

Returns:

  • (nil)

    if block is yielded to

  • (false)

    if no block is given



104
105
106
107
108
# File 'lib/eight_ball.rb', line 104

def self.with(name, parameters = {})
  return false unless block_given?

  yield if enabled? name, parameters
end