module EightBall
For all your feature querying needs.
Constants
- VERSION
Public Class Methods
“EightBall, is the feature named 'NewFeature' disabled?”
@return whether or not the {EightBall::Feature} is disabled. @return [true] if {EightBall::Feature} does not exist.
@param name [String] The name of the {EightBall::Feature}. @param parameters [Hash] The parameters the {EightBall::Conditions} of this
{EightBall::Feature} are concerned with.
@example
EightBall.disabled? 'feature1', account_id: 1
# File lib/eight_ball.rb, line 85 def self.disabled?(name, parameters = {}) !enabled? name, parameters end
“EightBall, is the feature named 'NewFeature' enabled?”
@return whether or not the {EightBall::Feature} is enabled. @return [false] if {EightBall::Feature} does not exist.
@param name [String] The name of the {EightBall::Feature}. @param parameters [Hash] The parameters the {EightBall::Conditions} of this
{EightBall::Feature} are concerned with.
@example
EightBall.enabled? 'feature1', account_id: 1
# File lib/eight_ball.rb, line 67 def self.enabled?(name, parameters = {}) feature = provider.features.find { |f| f.name == name } return false unless feature feature.enabled? parameters end
Serves as a shortcut to access the {EightBall::Feature Features} available on the configured {EightBall::Providers Provider}
@return [Array<EightBall::Feature>]
# File lib/eight_ball.rb, line 50 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
# File lib/eight_ball.rb, line 127 def self.logger @logger ||= Logger.new(STDOUT).tap do |log| log.progname = name end end
# File lib/eight_ball.rb, line 133 def self.logger=(logger) @logger = logger end
Marshalls the {EightBall::Feature Features}. This can be useful for converting the data to, e.g., a JSON file.
If a {EightBall::Marshallers Marshaller} is provided, use it.
If no {EightBall::Marshallers Marshaller} is provided, uses the same Marshaller that the Provider is configured with.
If the {EightBall::Providers Provider} does not expose a {EightBall::Marshallers Marshaller}, this will default to the {EightBall::Marshallers::Json JSON Marshaller}.
# File lib/eight_ball.rb, line 119 def self.marshall(marshaller = nil, features = EightBall.features) marshaller ||= (provider.respond_to?(:marshaller) && provider.marshaller) || EightBall::Marshallers::Json.new marshaller.marshall features end
Gets the {EightBall::Providers Provider} instance EightBall
is configured to use
@return {EightBall::Providers Provider}
# File lib/eight_ball.rb, line 42 def self.provider @provider end
Sets the {EightBall::Providers Provider} instance EightBall
will use to obtain your list of {EightBall::Feature Features}.
@return [nil]
@example
EightBall.provider = EightBall::Providers::Http.new 'http://www.rewind.io'
# File lib/eight_ball.rb, line 34 def self.provider=(provider) @provider = provider end
Yields to the given block of code if the {EightBall::Feature} is enabled.
@return [nil] if block is yielded to @return [false] if no block is given
@param name [String] The name of the {EightBall::Feature}. @param parameters [Hash] The parameters the {EightBall::Conditions} of this
{EightBall::Feature} are concerned with.
@example
EightBall.with 'feature1', account_id: 1 do puts 'Feature is enabled!' end
# File lib/eight_ball.rb, line 102 def self.with(name, parameters = {}) return false unless block_given? yield if enabled? name, parameters end