Module: FeatureToggle

Extended by:
Syntax
Defined in:
lib/feature_toggle.rb,
lib/feature_toggle/engine.rb,
lib/feature_toggle/syntax.rb,
lib/feature_toggle/version.rb,
lib/feature_toggle/syntax/state.rb,
lib/feature_toggle/syntax/shared.rb,
app/models/feature_toggle/feature.rb,
lib/feature_toggle/syntax/feature.rb,
app/helpers/feature_toggle/features_helper.rb,
app/helpers/feature_toggle/application_helper.rb,
app/controllers/feature_toggle/features_controller.rb,
app/controllers/feature_toggle/application_controller.rb

Defined Under Namespace

Modules: ApplicationHelper, FeaturesHelper, Syntax Classes: ApplicationController, Engine, Feature, FeaturesController

Constant Summary collapse

VERSION =
"1.0.0"

Class Method Summary collapse

Methods included from Syntax

define

Class Method Details

.configurationObject



20
21
22
# File 'lib/feature_toggle.rb', line 20

def self.configuration
  @config ||= OpenStruct.new
end

.featuresObject



16
17
18
# File 'lib/feature_toggle.rb', line 16

def self.features
  @features ||= []
end

.on?(feature, state_context) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
27
28
29
30
# File 'lib/feature_toggle.rb', line 24

def self.on?(feature, state_context)
  enable_state_names = Feature.where(feature: feature, enable: true).pluck(:state)
  enable_states = states.select {|state| enable_state_names.include?(state.name.to_s) }
  enable_states.any? do |state|
    state_context.instance_eval &state.value
  end
end

.setup {|configuration| ... } ⇒ Object

Yields:



8
9
10
# File 'lib/feature_toggle.rb', line 8

def self.setup(&block)
  yield configuration
end

.statesObject



12
13
14
# File 'lib/feature_toggle.rb', line 12

def self.states
  @states ||= []
end