module ActsAsFootprintable::Footprinter
Public Class Methods
Source
# File lib/acts_as_footprintable/footprinter.rb, line 5 def self.included(base) base.class_eval do has_many :footprints, class_name: 'ActsAsFootprintable::Footprint', as: :footprinter, dependent: :destroy do def footprintable includes(:footprintable).map(&:footprintable) end end end end
Public Instance Methods
Source
# File lib/acts_as_footprintable/footprinter.rb, line 24 def access_histories(limit = nil) get_access_history_records(footprints, limit) end
Source
# File lib/acts_as_footprintable/footprinter.rb, line 20 def access_histories_for(klass, limit = nil) get_access_history_records(footprints.for_type(klass), limit) end
Source
# File lib/acts_as_footprintable/footprinter.rb, line 8 def footprintable includes(:footprintable).map(&:footprintable) end
Source
# File lib/acts_as_footprintable/footprinter.rb, line 15 def leave_footprints(footprintable) footprint = ActsAsFootprintable::Footprint.new(footprintable: footprintable, footprinter: self) footprint.save end
Private Instance Methods
Source
# File lib/acts_as_footprintable/footprinter.rb, line 30 def get_access_history_records(target, limit = nil) footprints.where(id: recent_footprint_ids(target, limit)).order('created_at DESC') end
Source
# File lib/acts_as_footprintable/footprinter.rb, line 38 def recent_footprint_ids(target, limit = nil) records = footprints.where(<<~SQL) ( #{table_name}.footprintable_id, #{table_name}.footprintable_type, #{table_name}.created_at ) IN (#{recent_footprints_by(target).to_sql}) SQL records = records.order('footprints.created_at desc') records = records.limit(limit) unless limit.nil? records.ids end
Source
# File lib/acts_as_footprintable/footprinter.rb, line 51 def recent_footprints_by(target) target.group( "#{table_name}.footprintable_id", "#{table_name}.footprintable_type" ).select( "#{table_name}.footprintable_id", "#{table_name}.footprintable_type", "MAX(#{table_name}.created_at) AS created_at" ) end
Source
# File lib/acts_as_footprintable/footprinter.rb, line 34 def table_name ActsAsFootprintable::Footprint.table_name end