Class: FeaturePresenter

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/flipside/feature_presenter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(feature) ⇒ FeaturePresenter

Returns a new instance of FeaturePresenter.



9
10
11
# File 'lib/flipside/feature_presenter.rb', line 9

def initialize(feature)
  @feature = feature
end

Instance Attribute Details

#featureObject (readonly)

Returns the value of attribute feature.



5
6
7
# File 'lib/flipside/feature_presenter.rb', line 5

def feature
  @feature
end

Instance Method Details

#activated_atObject



41
42
43
# File 'lib/flipside/feature_presenter.rb', line 41

def activated_at
  feature.activated_at&.strftime("%Y-%m-%d %H:%M")
end

#activates_soon?(period = 60 * 60 * 24) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
52
53
54
# File 'lib/flipside/feature_presenter.rb', line 49

def activates_soon?(period = 60 * 60 * 24)
  return false if feature.active?
  return false if feature.activated_at.nil?

  feature.activated_at <= Time.now + period
end

#deactivated_atObject



45
46
47
# File 'lib/flipside/feature_presenter.rb', line 45

def deactivated_at
  feature.deactivated_at&.strftime("%Y-%m-%d %H:%M")
end

#deactivates_soon?(period = 60 * 60 * 24) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
59
60
61
# File 'lib/flipside/feature_presenter.rb', line 56

def deactivates_soon?(period = 60 * 60 * 24)
  return false unless feature.active?
  return false if feature.deactivated_at.nil?

  feature.deactivated_at <= Time.now + period
end

#entity_count_strObject



71
72
73
74
75
76
77
78
79
80
# File 'lib/flipside/feature_presenter.rb', line 71

def entity_count_str
  count = feature.entities.count
  if count == 1
    "Enabled for one entity"
  elsif count.positive?
    "Enabled for #{count} entities"
  else
    ""
  end
end

#role_count_strObject



82
83
84
85
86
87
88
89
90
91
# File 'lib/flipside/feature_presenter.rb', line 82

def role_count_str
  count = feature.roles.count
  if count == 1
    "Enabled for one role"
  elsif count.positive?
    "Enabled for #{count} roles"
  else
    ""
  end
end

#statusObject



13
14
15
16
17
18
19
# File 'lib/flipside/feature_presenter.rb', line 13

def status
  if feature.active?
    "active"
  else
    "inactive"
  end
end

#status_colorObject



21
22
23
24
25
26
27
28
29
# File 'lib/flipside/feature_presenter.rb', line 21

def status_color
  if feature.active?
    deactivates_soon? ? "bg-orange-600" : "bg-green-600"
  elsif activates_soon?
    "bg-yellow-600"
  else
    "bg-zinc-600"
  end
end

#status_titleObject



63
64
65
66
67
68
69
# File 'lib/flipside/feature_presenter.rb', line 63

def status_title
  if activates_soon?
    "Activates at: #{activated_at}"
  elsif deactivates_soon?
    "deactivates at: #{deactivated_at}"
  end
end

#switch_colorObject



31
32
33
34
35
36
37
38
39
# File 'lib/flipside/feature_presenter.rb', line 31

def switch_color
  return "bg-blue-700" if feature.enabled

  if (feature.entities.count + feature.roles.count) > 0
    "bg-blue-300"
  else
    "bg-gray-200"
  end
end