Class: ActionviewPrecompiler::ControllerScanner

Inherits:
Object
  • Object
show all
Defined in:
lib/actionview_precompiler/controller_scanner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller_dir) ⇒ ControllerScanner

Returns a new instance of ControllerScanner.



5
6
7
# File 'lib/actionview_precompiler/controller_scanner.rb', line 5

def initialize(controller_dir)
  @controller_dir = controller_dir
end

Instance Attribute Details

#controller_dirObject (readonly)

Returns the value of attribute controller_dir.



3
4
5
# File 'lib/actionview_precompiler/controller_scanner.rb', line 3

def controller_dir
  @controller_dir
end

Instance Method Details

#template_rendersObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/actionview_precompiler/controller_scanner.rb', line 9

def template_renders
  template_renders = []

  each_controller do |path, fullpath|
    parser = ControllerParser.new(fullpath)

    if path =~ /\A(.*)_controller\.rb\z/
      controller_prefix = $1
    end

    parser.render_calls.each do |render_call|
      virtual_path = render_call.virtual_path

      unless virtual_path.include?("/")
        next unless controller_prefix

        virtual_path = "#{controller_prefix}/#{virtual_path}"
      end

      locals = render_call.locals_keys.map(&:to_s).sort

      template_renders << [virtual_path, locals]
    end
  end

  template_renders.uniq
end