Sha256: a65f0af1ff068ac3f165e4cea418f08a61de0830194a8d7bbd027dcca6a0dcd6

Contents?: true

Size: 1.09 KB

Versions: 2

Compression:

Stored size: 1.09 KB

Contents

module ArchivalRecordCore
  module ArchivalRecordActiveRecordMethods

    def self.included(base)
      super
      base.extend ARClassMethods
      base.send :include, ARInstanceMethods
    end

    module ARClassMethods

      def archival?
        included_modules.include?(ArchivalRecordCore::ArchivalRecord::InstanceMethods)
      end

    end

    module ARInstanceMethods

      def archival?
        self.class.archival?
      end

    end

    module ARRelationMethods

      def archive_all!
        error_message = "The #{klass} must implement 'act_on_archivals' in order to call `archive_all!`"
        raise(NotImplementedError, error_message) unless archival?

        head_archive_number = Digest::MD5.hexdigest("#{klass}#{Time.now.utc.to_i}")
        each { |record| record.archive!(head_archive_number) }.tap { reset }
      end

      def unarchive_all!
        error_message = "The #{klass} must implement 'act_on_archivals' in order to call `unarchive_all!`"
        raise(NotImplementedError, error_message) unless archival?

        each(&:unarchive!).tap { reset }
      end

    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
archival_record-3.0.1 lib/archival_record_core/archival_record_active_record_methods.rb
archival_record-3.0.0 lib/archival_record_core/archival_record_active_record_methods.rb