Module: FeatureFlags
- Defined in:
- lib/feature_flags.rb,
lib/feature_flags/engine.rb,
lib/feature_flags/storage.rb,
lib/feature_flags/version.rb,
lib/feature_flags/feature_base.rb,
lib/feature_flags/configuration.rb,
lib/feature_flags/manage_features.rb,
lib/generators/feature_flags/views_generator.rb,
lib/generators/feature_flags/install_generator.rb
Defined Under Namespace
Modules: FeatureBase, Generators
Classes: Configuration, Engine
Constant Summary
collapse
- VERSION =
"0.1.0"
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.configuration ⇒ Object
Returns the value of attribute configuration.
13
14
15
|
# File 'lib/feature_flags/configuration.rb', line 13
def configuration
@configuration
end
|
Class Method Details
.check_features(features, check = false) ⇒ Object
checking dependant features
11
12
13
|
# File 'lib/feature_flags/manage_features.rb', line 11
def self.check_features(features, check = false)
features.map{|feature| get_feature(feature)}.compact.include? check
end
|
16
17
18
19
|
# File 'lib/feature_flags/configuration.rb', line 16
def self.configure
self.configuration ||= Configuration.new
yield(configuration) if block_given?
end
|
.create_and_enable(feature_name) ⇒ Object
15
16
17
18
|
# File 'lib/feature_flags/manage_features.rb', line 15
def self.create_and_enable(feature_name)
feature = Feature.new(:name => feature_name, :status => true)
feature.save ? true : false
end
|
.disable_all ⇒ Object
disables all features in application
46
47
48
49
|
# File 'lib/feature_flags/manage_features.rb', line 46
def self.disable_all
Feature.update_all(:status => false)
Feature.last.update_attributes(:status => false)
end
|
.enable(feature_name) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/feature_flags/manage_features.rb', line 20
def self.enable(feature_name)
feature = Feature.where(:name => feature_name).last
throw_error(feature_name) unless feature.present?
if feature.update_attributes(:status => true)
return true
else
flash[:error] = "#{feature_name} could not be updated"
return false
end
end
|
.enable_all ⇒ Object
enables all features in application
52
53
54
55
|
# File 'lib/feature_flags/manage_features.rb', line 52
def self.enable_all
Feature.update_all(:status => true)
Feature.last.update_attributes(:status => true)
end
|
.enabled?(feature) ⇒ Boolean
2
3
4
|
# File 'lib/feature_flags/manage_features.rb', line 2
def self.enabled?(feature)
feature.is_a?(Array) ? !check_features(feature) : get_feature(feature)
end
|
.enabled_any?(features = []) ⇒ Boolean
6
7
8
|
# File 'lib/feature_flags/manage_features.rb', line 6
def self.enabled_any?(features = [])
check_features(features, true)
end
|
.get_feature(feature_name) ⇒ Object
58
59
60
61
|
# File 'lib/feature_flags/manage_features.rb', line 58
def self.get_feature(feature_name)
all_features = FeatureFlags::FeatureBase.features
all_features.has_key?(feature_name) ? all_features[feature_name] : throw_error(feature_name)
end
|
.set_disabled(feature_name) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/feature_flags/manage_features.rb', line 33
def self.set_disabled(feature_name)
feature = Feature.where(:name => feature_name).last
throw_error(feature_name) unless feature.present?
if feature.update_attributes(:status => false)
return true
else
flash[:error] = "#{feature_name} could not be updated"
return false
end
end
|
.throw_error(feature_name) ⇒ Object
63
64
65
|
# File 'lib/feature_flags/manage_features.rb', line 63
def self.throw_error(feature_name)
raise "#{feature_name} feature not found."
end
|
.update_feature_hash ⇒ Object
67
68
69
|
# File 'lib/feature_flags/manage_features.rb', line 67
def self.update_feature_hash
Feature.new.update_hash
end
|
.update_pstore_value(updated = true) ⇒ Object
storing toggle value inside pstore if in case someone updates from rails console
4
5
6
7
8
9
|
# File 'lib/feature_flags/storage.rb', line 4
def self.update_pstore_value(updated = true)
store = PStore.new('feature_flags')
store.transaction do
store[:updated] = updated
end
end
|