module Elastictastic::Persistence

Public Instance Methods

destroy(options = {}, &block) click to toggle source
# File lib/elastictastic/persistence.rb, line 7
def destroy(options = {}, &block)
  if persisted?
    Elastictastic.persister.destroy(self, &block)
  else
    raise OperationNotAllowed, "Cannot destroy transient document: #{inspect}"
  end
end
pending_destroy!() click to toggle source
# File lib/elastictastic/persistence.rb, line 44
def pending_destroy!
  @_pending_destroy = true
end
pending_destroy?() click to toggle source
# File lib/elastictastic/persistence.rb, line 27
def pending_destroy?
  !!@_pending_destroy
end
pending_save!() click to toggle source
# File lib/elastictastic/persistence.rb, line 40
def pending_save!
  @_pending_save = true
end
pending_save?() click to toggle source
# File lib/elastictastic/persistence.rb, line 23
def pending_save?
  !!@_pending_save
end
persisted!() click to toggle source
# File lib/elastictastic/persistence.rb, line 31
def persisted!
  @_persisted = true
  @_pending_save = false
end
persisted?() click to toggle source
# File lib/elastictastic/persistence.rb, line 15
def persisted?
  !!@_persisted
end
save(options = {}, &block) click to toggle source
# File lib/elastictastic/persistence.rb, line 3
def save(options = {}, &block)
  persisted? ? update(options, &block) : create(options, &block)
end
transient!() click to toggle source
# File lib/elastictastic/persistence.rb, line 36
def transient!
  @_persisted = @_pending_destroy = false
end
transient?() click to toggle source
# File lib/elastictastic/persistence.rb, line 19
def transient?
  !persisted?
end

Protected Instance Methods

create(options = {}, &block) click to toggle source
# File lib/elastictastic/persistence.rb, line 50
def create(options = {}, &block)
  Elastictastic.persister.create(self, &block)
end
update(options = {}, &block) click to toggle source
# File lib/elastictastic/persistence.rb, line 54
def update(options = {}, &block)
  Elastictastic.persister.update(self, &block)
end

Private Instance Methods

assert_transient!() click to toggle source
# File lib/elastictastic/persistence.rb, line 60
def assert_transient!
  if persisted?
    raise IllegalModificationError,
      "Cannot modify identity attribute after model has been saved."
  end
end