Sha256: 838acb2abe695a511416f380b675b2fcfb20479c72985349669d061f06811a8a

Contents?: true

Size: 1.63 KB

Versions: 5

Compression:

Stored size: 1.63 KB

Contents

# versions are managed by the paper_trail gem... providing a history of
# instance-deltas
module ImportableAttachments
  class Version < ActiveRecord::Base
    self.abstract_class = true
    self.table_name = :importable_attachments_versions
    attr_accessible :event, :item_id, :item_type, :object, :object_changes, :whodunnit

    include SmarterDates if ::Configuration.for('smarter_dates').enabled
    include Rails::MarkRequirements if ::Configuration.for('mark_requirements').enabled

    belongs_to :item, polymorphic: true

    # NOTE: to save nested-model forms, new instances must be valid. Therefore,
    #       attachable_id = nil must be valid when attachable is != nil
    #validates :item_id, if: :item_id?, numericality: {only_integer: true, greater_than: 0}
    validates :item_id, alpha_numeric: {punctuation: true}, if: :item_id?

    validates :item_type, alpha_numeric: {punctuation: true}, if: :item_type?

    if ::Configuration.for('versioning').validate_item_type_constants
      validates :item_type, existing_class: true, if: :item_type?
    end

    # :call-seq:
    # object_has? :pattern
    #
    # yields versions in which the object contains a pattern

    scope :object_has?, lambda { |pattern| where('object LIKE ?', "%#{pattern}%") }

    # :call-seq:
    # Klass.in_the_last N
    #
    # yields objects created in the last N (where N is a timestamp)

    scope :in_the_last, lambda { |dt| where('created_at > ?', dt.ago) }

    # :call-seq:
    # yml_to_ruby
    #
    # loads the yaml object into a ruby-hash
    # if this is the 'destroyed' version, then RTFM reify

    def yml_to_ruby
      Psych.load object
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
importable_attachments-0.0.18 app/models/importable_attachments/version.rb
importable_attachments-0.0.17 app/models/importable_attachments/version.rb
importable_attachments-0.0.15 app/models/importable_attachments/version.rb
importable_attachments-0.0.14 app/models/importable_attachments/version.rb
importable_attachments-0.0.13 app/models/importable_attachments/version.rb