Class: RailsIdle::Collector::Views

Inherits:
Base
  • Object
show all
Defined in:
lib/rails-idle/collector/views.rb

Instance Method Summary collapse

Methods inherited from Base

#push, #storage

Instance Method Details

#collectObject



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/rails-idle/collector/views.rb', line 4

def collect
  view_paths.each do |path|
    views = Dir[path + '/**/*.*']
    views.each do |view|
      view = modify_prefix(view)
      next unless view
      if view =~ extensions_regexp
        _collect view
      end
    end
  end
end

#subscribeObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rails-idle/collector/views.rb', line 17

def subscribe
  %w{render_template render_partial render_collection}.each do |event|
    ActiveSupport::Notifications.subscribe("#{event}.action_view") do |name, started, finished, unique_id, payload|
      orig_prefix = ''
      view = modify_prefix payload[:identifier], orig_prefix
      next unless view
      execution_time = finished.to_f - started.to_f 
      push(view, execution_time)
      if payload[:layout] && view =~ /\.\w+\.\w+$/
        # just_view = extract_view  payload[:identifier], view
        # prefix = payload[:identifier].gsub(just_view, '')
        extension = view.match(/\.\w+\.\w+$/)[0]
        layout = orig_prefix + '/' + payload[:layout] + extension
        layout = modify_prefix layout
        push(layout, execution_time) if layout
      end
    end
  end
end