Module: Featuring::Flaggable::ClassMethods

Extended by:
Forwardable
Defined in:
lib/featuring/flaggable.rb

Instance Method Summary collapse

Instance Method Details

#inherited(object) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
137
138
# 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_classObject

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).



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# 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