Module: Octo::FeatureFlag::ClassMethods

Defined in:
lib/octocore-mongo/featureflag.rb

Instance Method Summary collapse

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

Parameters:

  • klass (Module)

    The class or module to be feature flagged

  • state (Boolean)

    The boolean state to set for the class



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

#flagsSet

Get the list of all flags

Returns:

  • (Set)

    A set 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

Parameters:

  • feature (Module)

    The module to be tested

Returns:

  • (Boolean)

    Boolean value specifying if the feature is 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

Parameters:

  • feature (Module)

    The module to be tested

Returns:

  • (Boolean)

    Boolean value specifying the status



68
69
70
# File 'lib/octocore-mongo/featureflag.rb', line 68

def is_not_flagged?(feature)
  !is_flagged?feature
end