Module: Kalimba::Persistence Abstract

Extended by:
ActiveSupport::Concern
Defined in:
lib/kalimba/persistence.rb

Overview

This module is abstract.

Backend implementations should override all methods that delegate processing to their parent class (invoking “super”).

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.backendModule

Module of the persistence backend

Returns:

  • (Module)


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

def backend
  self
end

.loggerObject



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

def logger
  @logger ||= defined?(::Rails) && ::Rails.logger
end

.repository(options = {}) ⇒ Any

Create an instance of the backend storage (repository)

Parameters:

  • options (Hash) (defaults to: {})

    backend storage options

Returns:

  • (Any)

    instance of the backend storage

Raises:

  • (NotImplementedError)


16
17
18
# File 'lib/kalimba/persistence.rb', line 16

def repository(options = {})
  raise NotImplementedError
end

Instance Method Details

#destroyBoolean

Remove the resource from the backend storage

Returns:

  • (Boolean)


128
129
130
131
# File 'lib/kalimba/persistence.rb', line 128

def destroy
  @destroyed = true
  freeze
end

#destroyed?Boolean

Check whether the model has been destroyed (remove from the storage)

Returns:

  • (Boolean)


114
115
116
# File 'lib/kalimba/persistence.rb', line 114

def destroyed?
  @destroyed
end

#idObject



92
93
94
# File 'lib/kalimba/persistence.rb', line 92

def id
  subject && subject.fragment
end

#loggerObject



152
153
154
# File 'lib/kalimba/persistence.rb', line 152

def logger
  self.class.logger
end

#new_record?Boolean

Check whether the model has never been persisted

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


99
100
101
# File 'lib/kalimba/persistence.rb', line 99

def new_record?
  raise NotImplementedError
end

#persisted?Boolean

Check whether the model has ever been persisted

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


106
107
108
# File 'lib/kalimba/persistence.rb', line 106

def persisted?
  raise NotImplementedError
end

#reloadself

Retrieve model attributes from the backend storage

Returns:

  • (self)

Raises:

  • (NotImplementedError)


121
122
123
# File 'lib/kalimba/persistence.rb', line 121

def reload
  raise NotImplementedError
end

#save(options = {}) ⇒ Boolean

Persist the model into the backend storage

Returns:

  • (Boolean)

Raises:



146
147
148
149
150
# File 'lib/kalimba/persistence.rb', line 146

def save(options = {})
  @previously_changed = changes
  @changed_attributes.clear
  true
end

#update_attributes(params = {}) ⇒ Boolean

Assign attributes from the given hash and persist the model

Parameters:

  • params (Hash<[Symbol, String] => Any>) (defaults to: {})

Returns:

  • (Boolean)


137
138
139
140
# File 'lib/kalimba/persistence.rb', line 137

def update_attributes(params = {})
  assign_attributes(params)
  save
end