Module: Pageflow::FeatureTarget Private

Extended by:
ActiveSupport::Concern
Included in:
Account, Entry
Defined in:
app/models/concerns/pageflow/feature_target.rb

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Constant Summary collapse

STATE_MAPPING =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

{
  true => 'enabled',
  false => 'disabled',
  nil => 'default'
}

Instance Method Summary collapse

Instance Method Details

#enabled_feature_names(config = Pageflow.config_for(self)) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



16
17
18
19
20
# File 'app/models/concerns/pageflow/feature_target.rb', line 16

def enabled_feature_names(config = Pageflow.config_for(self))
  config.features.select { |feature|
    feature_state(feature.name) == true
  }.map(&:name)
end

#feature_state(name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



22
23
24
25
# File 'app/models/concerns/pageflow/feature_target.rb', line 22

def feature_state(name)
  state = own_feature_state(name)
  state == nil ? inherited_feature_state(name) : state
end

#feature_states=(states) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/models/concerns/pageflow/feature_target.rb', line 35

def feature_states=(states)
  boolean_states = states.each_with_object({}) do |(key, value), result|
    if value == true || value == STATE_MAPPING[true]
      result[key] = true
    elsif value == false || value == STATE_MAPPING[false]
      result[key] = false
    elsif value.blank? || value == STATE_MAPPING[nil]
      result[key] = nil
    end
  end

  self.features_configuration = features_configuration
    .merge(boolean_states)
    .reject { |_, value| value.nil? }
end

#features_configurationObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



51
52
53
# File 'app/models/concerns/pageflow/feature_target.rb', line 51

def features_configuration
  self[:features_configuration] || {}
end

#inherited_feature_state(name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



31
32
33
# File 'app/models/concerns/pageflow/feature_target.rb', line 31

def inherited_feature_state(name)
  Pageflow.config.features.enabled_by_default?(name)
end

#own_feature_state(name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



27
28
29
# File 'app/models/concerns/pageflow/feature_target.rb', line 27

def own_feature_state(name)
  features_configuration[name]
end