Sha256: a3183a87a1642516e85e9daf8e4ce95e177d32f00f6df691ea1f855266914ce7

Contents?: true

Size: 801 Bytes

Versions: 10

Compression:

Stored size: 801 Bytes

Contents

module AbAdmin
  module Concerns
    module HasTracking
      extend ActiveSupport::Concern

      included do
        has_many :tracks, as: :trackable
        class_attribute :tracking_enabled
        self.tracking_enabled = true
      end

      def track(options={})
        return unless tracking_enabled?
        options[:trackable] ||= self
        options[:owner] ||= user if respond_to?(:user)
        options[:user] ||= updater if respond_to?(:updater)
        options[:key] = [self.class.model_name.plural, options[:key]].compact.join('.')
        tracks.build(options)
      end

      def track!(*args)
        track(*args).save!
      end

      module ClassMethods
        def tracking_enabled?
          tracking_enabled && Track.tracking_enabled
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
ab_admin-0.11.0 lib/ab_admin/concerns/has_tracking.rb
ab_admin-0.10.0 lib/ab_admin/concerns/has_tracking.rb
ab_admin-0.9.0 lib/ab_admin/concerns/has_tracking.rb
ab_admin-0.8.3 lib/ab_admin/concerns/has_tracking.rb
ab_admin-0.8.2 lib/ab_admin/concerns/has_tracking.rb
ab_admin-0.8.1 lib/ab_admin/concerns/has_tracking.rb
ab_admin-0.8.0 lib/ab_admin/concerns/has_tracking.rb
ab_admin-0.7.0 lib/ab_admin/concerns/has_tracking.rb
ab_admin-0.6.1 lib/ab_admin/concerns/has_tracking.rb
ab_admin-0.6.0 lib/ab_admin/concerns/has_tracking.rb