module Featuring::Flaggable::ClassMethods

Public Class Methods

new(parent) click to toggle source
# File lib/featuring/flaggable.rb, line 111
def initialize(parent)
  @parent = parent
end

Public Instance Methods

feature_flags() click to toggle source

@api private

# File lib/featuring/flaggable.rb, line 116
def feature_flags
  self.class.feature_flags
end
inherited(object) click to toggle source
# File lib/featuring/flaggable.rb, line 126
def inherited(object)
  # Add the feature check methods to the object's internal feature class.
  #
  object.instance_feature_class.internal_feature_checks_module.include instance_feature_class.internal_feature_checks_module

  # Because we added feature check methods above, include again to make them available.
  #
  object.instance_feature_class.include object.instance_feature_class.internal_feature_checks_module

  # Add the feature methods to the object's internal feature class.
  #
  object.instance_feature_class.internal_feature_module.include instance_feature_class.internal_feature_module
end
instance_feature_class() click to toggle source

The internal class where feature flags for the object are defined. An instance of this class is returned when calling ‘object.features`. The object delegates all feature flag definition concerns to this internal class (see the comment above).

# File lib/featuring/flaggable.rb, line 100
def instance_feature_class
  @_instance_feature_class ||= Class.new do
    extend Flaggable

    # The class is `Flaggable`, but *instances* are `Delegatable`. This lets us delegate
    # dynamically to the parent object (the object `features` is called on).
    #
    include Delegatable

    include Serializable

    def initialize(parent)
      @parent = parent
    end

    # @api private
    def feature_flags
      self.class.feature_flags
    end

    private def internal_feature_delegates_to
      @parent
    end
  end
end
internal_feature_delegates_to() click to toggle source
# File lib/featuring/flaggable.rb, line 120
        def internal_feature_delegates_to
  @parent
end