Module: FeatureFlags::Features
- Defined in:
- lib/featureflags/features.rb
Instance Attribute Summary collapse
-
#flags ⇒ Object
Returns the value of attribute flags.
Class Method Summary collapse
- .all_defaults ⇒ Object
- .all_enabled?(*names) ⇒ Boolean
- .any_enabled?(*names) ⇒ Boolean
- .enabled?(name) ⇒ Boolean
-
.enabled_by_default ⇒ Object
return all features which are enabled by default i.e.
- .env_ize(name) ⇒ Object
-
.flag(name) ⇒ Object
Could be useful to use this directly for variants / AB testing, etc e.g.
- .init!(flags = nil) ⇒ Object
Instance Attribute Details
#flags ⇒ Object
Returns the value of attribute flags.
3 4 5 |
# File 'lib/featureflags/features.rb', line 3 def flags @flags end |
Class Method Details
.all_defaults ⇒ Object
20 21 22 |
# File 'lib/featureflags/features.rb', line 20 def self.all_defaults @flags || {} end |
.all_enabled?(*names) ⇒ Boolean
34 35 36 |
# File 'lib/featureflags/features.rb', line 34 def self.all_enabled?(*names) names.flatten.all?{ |name| enabled?(name) } end |
.any_enabled?(*names) ⇒ Boolean
30 31 32 |
# File 'lib/featureflags/features.rb', line 30 def self.any_enabled?(*names) names.flatten.any?{ |name| enabled?(name) } end |
.enabled?(name) ⇒ Boolean
9 10 11 |
# File 'lib/featureflags/features.rb', line 9 def self.enabled?(name) !!flag(name) end |
.enabled_by_default ⇒ Object
return all features which are enabled by default i.e. not-false, regardless of environment variables
26 27 28 |
# File 'lib/featureflags/features.rb', line 26 def self.enabled_by_default @flags.select{|k,v| v}.keys end |
.env_ize(name) ⇒ Object
38 39 40 |
# File 'lib/featureflags/features.rb', line 38 def self.env_ize(name) name.to_s.upcase.gsub(/[^A-Z0-9_]+/, '_') end |
.flag(name) ⇒ Object
Could be useful to use this directly for variants / AB testing, etc e.g. FeatureFlags::Features.flag(‘homepage.splash_form’)
16 17 18 |
# File 'lib/featureflags/features.rb', line 16 def self.flag(name) ENV[env_ize(name)] || @flags[name.to_sym] end |
.init!(flags = nil) ⇒ Object
5 6 7 |
# File 'lib/featureflags/features.rb', line 5 def self.init!(flags=nil) @flags = load_flags!(flags) end |