Sha256: 5e5d8a2ab960c20371f1eee58c5ac00de578788acc124d05f89cf43bf9f0ebf9

Contents?: true

Size: 618 Bytes

Versions: 8

Compression:

Stored size: 618 Bytes

Contents

class Memento::Action::Create < Memento::Action::Base
  
  def fetch;end
  
  def undo
    if record.nil?
      build_fake_object
    elsif record_was_changed?
      was_changed
    else
      destroy_record
    end
  end
  
  private
  
  def record_was_changed?
    record.updated_at > record.created_at rescue false
  end
  
  def build_fake_object
    new_object do |object|
      object.id = state.record_id
    end
  end
  
  def was_changed
    record.errors.add(:memento_undo, ActiveSupport::StringInquirer.new("was_changed"))
    record
  end
  
  def destroy_record
    record.destroy
    record
  end
  
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
memento-0.3.7 lib/memento/action/create.rb
memento-0.3.6 lib/memento/action/create.rb
memento-0.3.5 lib/memento/action/create.rb
memento-0.3.4 lib/memento/action/create.rb
memento-0.3.3 lib/memento/action/create.rb
memento-0.3.2 lib/memento/action/create.rb
memento-0.3.1 lib/memento/action/create.rb
memento-0.3.0 lib/memento/action/create.rb