Class: Super::Navigation

Inherits:
Object
  • Object
show all
Defined in:
lib/super/navigation.rb

Defined Under Namespace

Classes: Builder, Menu, RouteFormatterButReallySearcher

Instance Method Summary collapse

Constructor Details

#initializeNavigation

Returns a new instance of Navigation.



5
6
7
8
9
10
11
# File 'lib/super/navigation.rb', line 5

def initialize
  @builder = Builder.new
  @definition = yield @builder
  if !@definition.is_a?(Array)
    @definition = [@definition]
  end
end

Instance Method Details

#definitionObject



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/super/navigation.rb', line 13

def definition
  return @defs if instance_variable_defined?(:@defs)

  searcher = RouteFormatterButReallySearcher.new
  inspector = ActionDispatch::Routing::RoutesInspector.new(Rails.application.routes.routes)
  inspector.format(searcher)
  all_matches = searcher.matches
  unused_matches = all_matches.each_with_object({}) { |match, hash| hash[match] = true }

  defs = expand_proc_syntax_sugar(@definition)
  defs = validate_and_determine_explicit_links(defs, unused_matches)
  @defs = expand_directives(defs, all_matches, unused_matches.keys)
end