Module: PriceHubble::EntityConcern::Persistence

Extended by:
ActiveSupport::Concern
Included in:
BaseEntity
Defined in:
lib/pricehubble/entity/concern/persistence.rb

Overview

Map some of the ActiveRecord::Persistence API methods for an entity instance for good compatibility. See: bit.ly/2W1rjfF and bit.ly/2ARRFYB

Instance Method Summary collapse

Instance Method Details

#destroyed?Boolean

Returns true if this object has been destroyed, otherwise returns false.

Returns:

  • (Boolean)

    whenever the entity was destroyed or not



48
49
50
# File 'lib/pricehubble/entity/concern/persistence.rb', line 48

def destroyed?
  @destroyed == true
end

#mark_as_destroyedHausgold::BaseEntity

Mark the entity instance as destroyed.

Returns:

  • (Hausgold::BaseEntity)

    the instance itself for method chaining



39
40
41
42
# File 'lib/pricehubble/entity/concern/persistence.rb', line 39

def mark_as_destroyed
  @destroyed = true
  self
end

#new_record?Boolean

A simple method to query for the state of the entity instance. Returns false whenever the entity is not yet created on the remote application. This is helpful for creating new entities from scratch.

Returns:

  • (Boolean)

    whenever persisted or not



30
31
32
33
34
# File 'lib/pricehubble/entity/concern/persistence.rb', line 30

def new_record?
  return id.nil? if respond_to? :id

  true
end

#persisted?Boolean

A simple method to query for the state of the entity instance. Returns false whenever the entity or the changes of it were not yet persisted on the remote application. This is helpful for creating new entities from scratch or checking for persisted updates.

Returns:

  • (Boolean)

    whenever persisted or not



18
19
20
21
22
23
# File 'lib/pricehubble/entity/concern/persistence.rb', line 18

def persisted?
  return (new_record? ? false : !changed?) \
    if respond_to? :id

  false
end