Class: Gecko::Record::Base

Inherits:
Object
  • Object
show all
Extended by:
Helpers::AssociationHelper
Includes:
Helpers::InspectionHelper, Helpers::SerializationHelper, Helpers::ValidationHelper
Defined in:
lib/gecko/record/base.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers::AssociationHelper

belongs_to, has_many

Methods included from Helpers::ValidationHelper

#errors, #valid?

Methods included from Helpers::SerializationHelper

#_serialize, #as_json, #root, #serializable_hash, #serialize_attribute, #writeable?

Methods included from Helpers::InspectionHelper

#inspect

Constructor Details

#initialize(client, attributes = {}) ⇒ undefined

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Overrides the default Virtus functionality to store:

  • The Gecko::Client used to create the object

  • a raw copy of the attributes for the association helpers to read from



27
28
29
30
# File 'lib/gecko/record/base.rb', line 27

def initialize(client, attributes={})
  super(attributes)
  @client   = client
end

Class Method Details

.demodulized_nameString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return the demodulized class name

Examples:

Gecko::Record::Product.demodulized_name #=> "Product"

Returns:

  • (String)


64
65
66
# File 'lib/gecko/record/base.rb', line 64

def self.demodulized_name
  self.name.split('::').last
end

Instance Method Details

#persisted?Boolean

Whether the record has been persisted

Examples:

variant.persisted? #=> true

Returns:

  • (Boolean)


40
41
42
# File 'lib/gecko/record/base.rb', line 40

def persisted?
  !!id
end

#save(opts = {}) ⇒ Gecko::Record::Base

Save a record

Parameters:

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

    the options to save the record with

Options Hash (opts):

  • :idempotency_key (Hash)

    A unique identifier for this action

Returns:



52
53
54
# File 'lib/gecko/record/base.rb', line 52

def save(opts = {})
  @client.adapter_for(self.class.demodulized_name).save(self, opts)
end