Class: Flatfoot::Tracker
- Inherits:
-
Object
- Object
- Flatfoot::Tracker
- Defined in:
- lib/flatfoot.rb
Constant Summary collapse
- DEFAULT_TARGET =
Dir.glob('app/views/**/*.html.erb').reject{ |file| file.match(/(_mailer)/) }
Instance Attribute Summary collapse
-
#logged_views ⇒ Object
Returns the value of attribute logged_views.
-
#roots ⇒ Object
Returns the value of attribute roots.
-
#store ⇒ Object
Returns the value of attribute store.
-
#target ⇒ Object
Returns the value of attribute target.
Instance Method Summary collapse
-
#initialize(store, options = {}) ⇒ Tracker
constructor
A new instance of Tracker.
- #reset_recordings ⇒ Object
- #track_views(name, start, finish, id, payload) ⇒ Object
- #unused_views ⇒ Object
- #used_views ⇒ Object
Constructor Details
#initialize(store, options = {}) ⇒ Tracker
Returns a new instance of Tracker.
11 12 13 14 15 16 |
# File 'lib/flatfoot.rb', line 11 def initialize(store, = {}) @store = store @target = [:target] || DEFAULT_TARGET @logged_views = [] @roots = .fetch(:roots){ "#{Rails.root.to_s}/" }.split(',') end |
Instance Attribute Details
#logged_views ⇒ Object
Returns the value of attribute logged_views.
9 10 11 |
# File 'lib/flatfoot.rb', line 9 def logged_views @logged_views end |
#roots ⇒ Object
Returns the value of attribute roots.
9 10 11 |
# File 'lib/flatfoot.rb', line 9 def roots @roots end |
#store ⇒ Object
Returns the value of attribute store.
9 10 11 |
# File 'lib/flatfoot.rb', line 9 def store @store end |
#target ⇒ Object
Returns the value of attribute target.
9 10 11 |
# File 'lib/flatfoot.rb', line 9 def target @target end |
Instance Method Details
#reset_recordings ⇒ Object
62 63 64 |
# File 'lib/flatfoot.rb', line 62 def reset_recordings store.del(tracker_key) end |
#track_views(name, start, finish, id, payload) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/flatfoot.rb', line 18 def track_views(name, start, finish, id, payload) begin if file = payload[:identifier] unless logged_views.include?(file) logged_views << file store.sadd(tracker_key, file) end end ### # Annoyingly while you get full path for templates # notifications only pass part of the path for layouts dropping any format info # such as .html.erb or .js.erb # http://edgeguides.rubyonrails.org/active_support_instrumentation.html#render_partial-action_view ### if layout_file = payload[:layout] unless logged_views.include?(layout_file) logged_views << layout_file store.sadd(tracker_key, layout_file) end end rescue Errno::EAGAIN, Timeout::Error #we don't want to raise errors if flatfoot can't reach redis. This is a nice to have not a bring the system down end end |
#unused_views ⇒ Object
55 56 57 58 59 60 |
# File 'lib/flatfoot.rb', line 55 def unused_views recently_used_views = used_views all_views = target.reject{ |view| recently_used_views.include?(view) } # since layouts don't include format we count them used if they match with ANY formats all_views = all_views.reject{ |view| view.match(/\/layouts\//) && recently_used_views.any?{|used_view| view.include?(used_view)} } end |