Module: Octo::FeatureFlag::ClassMethods
- Defined in:
- lib/octocore-mongo/featureflag.rb
Instance Method Summary collapse
-
#featureflag(klass, state) ⇒ Object
Set the featureflag for a module or class to the state.
-
#flags ⇒ Set
Get the list of all flags.
-
#is_flagged?(feature) ⇒ Boolean
Helper method to find if a module is feature flagged or not.
-
#is_not_flagged?(feature) ⇒ Boolean
Returns if the flag is not set.
Instance Method Details
#featureflag(klass, state) ⇒ Object
Set the featureflag for a module or class to the state. If the
featureflag is set to true, it means that the feature is disabled. If
the featureflag is set to false, it means that the feature is enabled.
It also defined a `is_flagged?` method on the module which returns
the state of featureflag
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/octocore-mongo/featureflag.rb', line 26 def featureflag(klass, state) if state unless flags.include?klass flags << klass klass.instance_eval do def is_flagged? true end end end else if flags.include?klass flags.delete(klass) klass.instance_eval do def is_flagged? false end end end end end |
#flags ⇒ Set
Get the list of all flags
51 52 53 |
# File 'lib/octocore-mongo/featureflag.rb', line 51 def flags @flags ||= Set.new([]) end |
#is_flagged?(feature) ⇒ Boolean
Helper method to find if a module is feature flagged or not
60 61 62 |
# File 'lib/octocore-mongo/featureflag.rb', line 60 def is_flagged?(feature) flags.include?feature end |
#is_not_flagged?(feature) ⇒ Boolean
Returns if the flag is not set
68 69 70 |
# File 'lib/octocore-mongo/featureflag.rb', line 68 def is_not_flagged?(feature) !is_flagged?feature end |