Class: LinkDecisionHelper
- Inherits:
-
Object
- Object
- LinkDecisionHelper
show all
- Defined in:
- lib/link_decision_helper.rb
Defined Under Namespace
Classes: NotOnAllowListError
Constant Summary
collapse
- ALLOWED_TYPES =
[
NAVBAR_LOGGED_IN = :n_logged_in,
NAVBAR_LOGGED_OUT = :n_logged_out
]
- DEFAULT_TITLE =
'Default Title'
- DEFAULT_URL =
'/'
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(title:, url:, type:, display: true, default_type: nil, config: nil, _blank: false) ⇒ LinkDecisionHelper
Returns a new instance of LinkDecisionHelper.
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/link_decision_helper.rb', line 17
def initialize(title:, url:, type:, display: true, default_type: nil, config: nil, _blank: false)
raise NotOnAllowListError, "Unexpected type [#{type}]. Expected #{ALLOWED_TYPES}" unless ALLOWED_TYPES.include?(type)
@config = config
@type = type
@url = url
@title = title
@display = display
@_blank = _blank
if default_type && ALLOWED_TYPES.include?(default_type)
assign_default!
elsif default_type && !ALLOWED_TYPES.include?(default_type)
raise NotOnAllowListError, 'unexpected default value'
end
end
|
Class Method Details
.clear_type!(type:) ⇒ Object
12
13
14
15
|
# File 'lib/link_decision_helper.rb', line 12
def self.clear_type!(type:)
raise "Unexpected type [#{type}]. Expected #{ALLOWED_TYPES}" unless ALLOWED_TYPES.include?(type)
Rails.application.config.public_send("#{type}=", [])
end
|
Instance Method Details
#assign!(index: -1)) ⇒ Object
34
35
36
|
# File 'lib/link_decision_helper.rb', line 34
def assign!(index: -1)
config.public_send(@type).insert(index, self)
end
|
#blank? ⇒ Boolean
46
47
48
|
# File 'lib/link_decision_helper.rb', line 46
def blank?
@_blank
end
|
#display?(current_user) ⇒ Boolean
50
51
52
|
# File 'lib/link_decision_helper.rb', line 50
def display?(current_user)
get_value(@display, current_user)
end
|
#title ⇒ Object
42
43
44
|
# File 'lib/link_decision_helper.rb', line 42
def title
get_value(@title)
end
|
#url ⇒ Object
38
39
40
|
# File 'lib/link_decision_helper.rb', line 38
def url
get_value(@url)
end
|