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

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

Instance Method Summary collapse

Instance Method Details

#destroyObject



64
65
66
67
68
69
70
# File 'lib/tire/model/persistence/storage.rb', line 64

def destroy
  run_callbacks :destroy do
    @destroyed = true
    response = update_index
    ! response.nil?
  end
end

#destroyed?Boolean



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

def destroyed?   ;  !!@destroyed;       end

#new_record?Boolean



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

def new_record?  ;  !persisted?;        end

#persisted?Boolean



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

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

#saveObject



56
57
58
59
60
61
62
# File 'lib/tire/model/persistence/storage.rb', line 56

def save
  return false unless valid?
  run_callbacks :save do
    response = update_index
    !! response['ok']
  end
end

#update_attribute(name, value) ⇒ Object



29
30
31
32
# File 'lib/tire/model/persistence/storage.rb', line 29

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

#update_attributes(attributes = {}) ⇒ Object



34
35
36
37
# File 'lib/tire/model/persistence/storage.rb', line 34

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

#update_indexObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/tire/model/persistence/storage.rb', line 39

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