Class: Flipflop::FeaturesController::FeaturesPresenter

Inherits:
Object
  • Object
show all
Defined in:
app/controllers/flipflop/features_controller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(feature_set) ⇒ FeaturesPresenter

Returns a new instance of FeaturesPresenter.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/flipflop/features_controller.rb', line 21

def initialize(feature_set)
  @cache = {}
  @feature_set = feature_set

  @strategies = @feature_set.strategies.reject(&:hidden?)
  @grouped_features = @feature_set.features.group_by(&:group)

  app_class = Rails.application.class
  application_name = app_class.respond_to?(:module_parent_name) ?
    app_class.module_parent_name :
    app_class.parent_name

  @application_name = application_name.underscore.titleize
end

Instance Attribute Details

#application_nameObject (readonly)

Returns the value of attribute application_name.



19
20
21
# File 'app/controllers/flipflop/features_controller.rb', line 19

def application_name
  @application_name
end

#grouped_featuresObject (readonly)

Returns the value of attribute grouped_features.



19
20
21
# File 'app/controllers/flipflop/features_controller.rb', line 19

def grouped_features
  @grouped_features
end

#strategiesObject (readonly)

Returns the value of attribute strategies.



19
20
21
# File 'app/controllers/flipflop/features_controller.rb', line 19

def strategies
  @strategies
end

Instance Method Details

#grouped?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'app/controllers/flipflop/features_controller.rb', line 36

def grouped?
  grouped_features.keys != [nil]
end

#status(feature) ⇒ Object



40
41
42
43
44
# File 'app/controllers/flipflop/features_controller.rb', line 40

def status(feature)
  cache(nil, feature) do
    status_to_sym(@feature_set.enabled?(feature.key))
  end
end

#strategy_status(strategy, feature) ⇒ Object



46
47
48
49
50
# File 'app/controllers/flipflop/features_controller.rb', line 46

def strategy_status(strategy, feature)
  cache(strategy, feature) do
    status_to_sym(strategy.enabled?(feature.key))
  end
end

#switch_url(strategy, feature) ⇒ Object



52
53
54
# File 'app/controllers/flipflop/features_controller.rb', line 52

def switch_url(strategy, feature)
  feature_strategy_path(feature.key, strategy.key)
end