Module: Elastictastic::Persistence

Defined in:
lib/elastictastic/persistence.rb

Instance Method Summary collapse

Instance Method Details

#destroy ⇒ Object



7
8
9
10
11
12
13
# File 'lib/elastictastic/persistence.rb', line 7

def destroy
  if persisted?
    Elastictastic.persister.destroy(self)
  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 ⇒ Object



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

def save
  persisted? ? update : create
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