Module: EightBall

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

Overview

For all your feature querying needs.

Defined Under Namespace

Modules: Conditions, Parsers, Providers Classes: Feature

Constant Summary collapse

VERSION =
'1.0.0'

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.



65
66
67
# File 'lib/eight_ball.rb', line 65

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.



47
48
49
50
51
52
# File 'lib/eight_ball.rb', line 47

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

  feature.enabled? parameters
end

.loggerObject



88
89
90
91
92
# File 'lib/eight_ball.rb', line 88

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

.logger=(logger) ⇒ Object



94
95
96
# File 'lib/eight_ball.rb', line 94

def self.logger=(logger)
  @logger = logger
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)


32
33
34
# File 'lib/eight_ball.rb', line 32

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 Feature is disabled



82
83
84
85
86
# File 'lib/eight_ball.rb', line 82

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

  yield if enabled? name, parameters
end