Module: Tire::Model::Persistence::Storage::InstanceMethods

Defined in:
lib/tire/model/persistence/storage.rb

Instance Method Summary collapse

Instance Method Details

#destroyObject



60
61
62
63
64
65
66
# File 'lib/tire/model/persistence/storage.rb', line 60

def destroy
  run_callbacks :destroy do
    @destroyed = true
    update_index
  end
  self.freeze
end

#destroyed?Boolean

Returns:

  • (Boolean)


68
# File 'lib/tire/model/persistence/storage.rb', line 68

def destroyed?   ;  !!@destroyed;       end

#new_record?Boolean

Returns:

  • (Boolean)


70
# File 'lib/tire/model/persistence/storage.rb', line 70

def new_record?  ;  !persisted?;        end

#persisted?Boolean

Returns:

  • (Boolean)


69
# File 'lib/tire/model/persistence/storage.rb', line 69

def persisted?   ;  !!id && !!_version; end

#saveObject



52
53
54
55
56
57
58
# File 'lib/tire/model/persistence/storage.rb', line 52

def save
  return false unless valid?
  run_callbacks :save do
    update_index
  end
  self
end

#update_attribute(name, value) ⇒ Object



26
27
28
29
# File 'lib/tire/model/persistence/storage.rb', line 26

def update_attribute(name, value)
  __update_attributes name => value
  save
end

#update_attributes(attributes = {}) ⇒ Object



31
32
33
34
# File 'lib/tire/model/persistence/storage.rb', line 31

def update_attributes(attributes={})
  __update_attributes attributes
  save
end

#update_indexObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/tire/model/persistence/storage.rb', line 36

def update_index
  run_callbacks :update_elasticsearch_index do
    if destroyed?
      index.remove self
    else
      response  = index.store( self, {:percolate => percolator} )
      self.id     ||= response['_id']
      self._index   = response['_index']
      self._type    = response['_type']
      self._version = response['_version']
      self.gec | update  = response['tire_matches']
      self
    end
  end
end