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 =
'2.1.0'
Class Method Summary collapse
-
.disabled?(name, parameters = {}) ⇒ Boolean, true
“EightBall, is the feature named ‘NewFeature’ disabled?”.
-
.enabled?(name, parameters = {}) ⇒ Boolean, false
“EightBall, is the feature named ‘NewFeature’ enabled?”.
- .features ⇒ Array<EightBall::Feature>
- .logger ⇒ Object
- .logger=(logger) ⇒ Object
-
.marshall(marshaller = nil, features = EightBall.features) ⇒ Object
Marshalls the Features.
-
.provider ⇒ EightBall::Providers Provider
Gets the Provider instance EightBall is configured to use.
- .provider=(provider) ⇒ nil
-
.with(name, parameters = {}) ⇒ nil, false
Yields to the given block of code if the Feature is enabled.
Class Method Details
.disabled?(name, parameters = {}) ⇒ Boolean, true
“EightBall, is the feature named ‘NewFeature’ disabled?”
85 86 87 |
# File 'lib/eight_ball.rb', line 85 def self.disabled?(name, parameters = {}) !enabled? name, parameters end |
.enabled?(name, parameters = {}) ⇒ Boolean, false
“EightBall, is the feature named ‘NewFeature’ enabled?”
67 68 69 70 71 72 |
# 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 |
.features ⇒ Array<EightBall::Feature>
50 51 52 53 54 |
# 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 |
.logger ⇒ Object
127 128 129 130 131 |
# File 'lib/eight_ball.rb', line 127 def self.logger @logger ||= Logger.new(STDOUT).tap do |log| log.progname = name end end |
.logger=(logger) ⇒ Object
133 134 135 |
# File 'lib/eight_ball.rb', line 133 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.
119 120 121 122 123 124 125 |
# 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 |
.provider ⇒ EightBall::Providers Provider
Gets the Provider instance EightBall is configured to use
42 43 44 |
# File 'lib/eight_ball.rb', line 42 def self.provider @provider end |
.provider=(provider) ⇒ nil
34 35 36 |
# File 'lib/eight_ball.rb', line 34 def self.provider=(provider) @provider = provider end |
.with(name, parameters = {}) ⇒ nil, false
Yields to the given block of code if the Feature is enabled.
102 103 104 105 106 |
# File 'lib/eight_ball.rb', line 102 def self.with(name, parameters = {}) return false unless block_given? yield if enabled? name, parameters end |