Sha256: 94e4cdf0f025afa79ef97fc50fd7a3eea12b8ae00197fff12c6a83dd5ce48bae

Contents?: true

Size: 1.07 KB

Versions: 10

Compression:

Stored size: 1.07 KB

Contents

class Revision::Auditor < Revision

  attr_reader :versionable
  def initialize(versionable)
    @versionable = versionable
  end

  def changes_original?
    return true if versionable.marked_for_destruction?
    return true if changes_at_least_one_attribute?
    return true if changes_at_least_one_nested_association?
    return false
  end

  private
  def changes_at_least_one_attribute?
    versionable_attributes.each do |attr|
      attr = AttributeEncapsulator.new(attr)
      return true if versionable_changed_attributes.include?(attr.key)
    end
    return false
  end

  def changes_at_least_one_nested_association?
    versionable_nested_associations.each do |association|
      return true if association_changed?(association)
    end
    return false
  end

  def association_changed?(association)
    versionable.public_send(association).each do |child|
      return true if child_changed?(child)
    end
    return false
  end

  def child_changed?(child)
    child.new_record? || child.marked_for_destruction? ||
      Revision::Auditor.new(child).changes_original?
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
controlled_versioning-0.12.0 lib/controlled_versioning/revision/auditor.rb
controlled_versioning-0.11.0 lib/controlled_versioning/revision/auditor.rb
controlled_versioning-0.10.0 lib/controlled_versioning/revision/auditor.rb
controlled_versioning-0.9.2 lib/controlled_versioning/revision/auditor.rb
controlled_versioning-0.9.1 lib/controlled_versioning/revision/auditor.rb
controlled_versioning-0.9.0 lib/controlled_versioning/revision/auditor.rb
controlled_versioning-0.8.0 lib/controlled_versioning/revision/auditor.rb
controlled_versioning-0.7.2 lib/controlled_versioning/revision/auditor.rb
controlled_versioning-0.6.3 lib/controlled_versioning/revision/auditor.rb
controlled_versioning-0.6.2 lib/controlled_versioning/revision/auditor.rb