Class: DsfrAccessibleSkipLinks::SkipLinksImplementedChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/dsfr_accessible_skip_links/skip_links_implemented_checker.rb

Defined Under Namespace

Classes: SkipLinksNotDefinedError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller_name:, action_name:, has_skip_links: false) ⇒ SkipLinksImplementedChecker



7
8
9
10
11
# File 'lib/dsfr_accessible_skip_links/skip_links_implemented_checker.rb', line 7

def initialize(controller_name:, action_name:, has_skip_links: false)
  @controller_name = controller_name
  @action_name = action_name
  @has_skip_links = has_skip_links
end

Instance Attribute Details

#action_nameObject (readonly)

Returns the value of attribute action_name.



5
6
7
# File 'lib/dsfr_accessible_skip_links/skip_links_implemented_checker.rb', line 5

def action_name
  @action_name
end

#controller_nameObject (readonly)

Returns the value of attribute controller_name.



5
6
7
# File 'lib/dsfr_accessible_skip_links/skip_links_implemented_checker.rb', line 5

def controller_name
  @controller_name
end

Returns the value of attribute has_skip_links.



5
6
7
# File 'lib/dsfr_accessible_skip_links/skip_links_implemented_checker.rb', line 5

def has_skip_links
  @has_skip_links
end

Instance Method Details

#perform!Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/dsfr_accessible_skip_links/skip_links_implemented_checker.rb', line 13

def perform!
  return true if has_skip_links
  return true if whitelisted?

  current_route = "#{controller_name}##{action_name}"
  raise SkipLinksNotDefinedError,
        "No skip links defined for this page (#{current_route}). " \
        "Use content_for(:skip_links) to define skip links or " \
        "define them in a view-specific helper."
end