Module: Elastictastic::Persistence

Defined in:
lib/elastictastic/persistence.rb

Instance Method Summary collapse

Instance Method Details

#destroy(options = {}, &block) ⇒ Object



7
8
9
10
11
12
13
# 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!Object



44
45
46
# File 'lib/elastictastic/persistence.rb', line 44

def pending_destroy!
  @_pending_destroy = true
end

#pending_destroy?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/elastictastic/persistence.rb', line 27

def pending_destroy?
  !!@_pending_destroy
end

#pending_save!Object



40
41
42
# File 'lib/elastictastic/persistence.rb', line 40

def pending_save!
  @_pending_save = true
end

#pending_save?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/elastictastic/persistence.rb', line 23

def pending_save?
  !!@_pending_save
end

#persisted!Object



31
32
33
34
# File 'lib/elastictastic/persistence.rb', line 31

def persisted!
  @_persisted = true
  @_pending_save = false
end

#persisted?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/elastictastic/persistence.rb', line 15

def persisted?
  !!@_persisted
end

#save(options = {}, &block) ⇒ Object



3
4
5
# File 'lib/elastictastic/persistence.rb', line 3

def save(options = {}, &block)
  persisted? ? update(options, &block) : create(options, &block)
end

#transient!Object



36
37
38
# File 'lib/elastictastic/persistence.rb', line 36

def transient!
  @_persisted = @_pending_destroy = false
end

#transient?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/elastictastic/persistence.rb', line 19

def transient?
  !persisted?
end