Sha256: 04c77c1a7bb4a9d67501811bba3210d1b811b201bb7faef9c526a2e796839ef4

Contents?: true

Size: 757 Bytes

Versions: 1

Compression:

Stored size: 757 Bytes

Contents

module ActiveMetadata::Persistence::Mongoid::History

  def self.included(receiver)
    receiver.send :include, InstanceMethods
  end

  module InstanceMethods

    def save_history
      self.changes.each do |key, value|
        next if ActiveMetadata::CONFIG['history_skip_fields'].include?(key)
        
        label = ActiveMeta.find_or_create_by(:document_id => metadata_id).labels.find_or_create_by(:name => key.to_s)
        label.histories.create!(:value => value[1], :created_at => Time.now.utc)
      end
    end

    def history_for field
      meta = ActiveMeta.find_or_create_by(:document_id => metadata_id)
      
      label = meta.labels.find_or_create_by(:name => field.to_s)
      label.histories.desc(:created_at).to_a
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
active_metadata-0.1.9 lib/active_metadata/persistence/mongoid/history.rb