Sha256: b003181be6354e00113aa320621a0c8acaad8741a938a7cf58364feedc7d0509

Contents?: true

Size: 1.07 KB

Versions: 93

Compression:

Stored size: 1.07 KB

Contents

require 'tenon/has_history/attr_serializer.rb'
require 'tenon/has_history/item_reverter.rb'

module Tenon
  module HasHistory
    def self.included(mod)
      mod.extend(ClassMethods)
      mod.include(InstanceMethods)
    end

    module ClassMethods
      def has_history(except: [], only: [], includes: [])
        send(:has_many, :versions, class_name: 'Tenon::ItemVersion', as: :item)
        default_except = [:id]
        @has_history_except = (except + default_except).uniq
        @has_history_only = only
        @has_history_includes = includes
      end
    end

    module InstanceMethods
      def has_history_except
        self.class.instance_variable_get('@has_history_except')
      end

      def has_history_only
        self.class.instance_variable_get('@has_history_only')
      end

      def has_history_includes
        self.class.instance_variable_get('@has_history_includes')
      end

      def revert(item_version)
        Tenon::HasHistory::ItemReverter.revert(self, item_version)
      end
    end
  end
end

ActiveRecord::Base.send(:include, Tenon::HasHistory)

Version data entries

93 entries across 93 versions & 1 rubygems

Version Path
tenon-1.1.8 lib/tenon/has_history.rb
tenon-1.1.7 lib/tenon/has_history.rb
tenon-1.1.6 lib/tenon/has_history.rb
tenon-2.1.0 lib/tenon/has_history.rb
tenon-2.0.8 lib/tenon/has_history.rb
tenon-2.0.7 lib/tenon/has_history.rb
tenon-2.0.6 lib/tenon/has_history.rb
tenon-2.0.5 lib/tenon/has_history.rb
tenon-2.0.4 lib/tenon/has_history.rb
tenon-2.0.3 lib/tenon/has_history.rb
tenon-2.0.2 lib/tenon/has_history.rb
tenon-2.0.1 lib/tenon/has_history.rb
tenon-2.0.0 lib/tenon/has_history.rb
tenon-1.1.5 lib/tenon/has_history.rb
tenon-1.1.4 lib/tenon/has_history.rb
tenon-1.1.3 lib/tenon/has_history.rb
tenon-1.1.2 lib/tenon/has_history.rb
tenon-1.1.1 lib/tenon/has_history.rb
tenon-1.0.76 lib/tenon/has_history.rb
tenon-1.0.75 lib/tenon/has_history.rb