Class: Gecko::Record::Base

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from LiquidCompatibility

#to_liquid

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

Methods included from Helpers::AssociationHelper

included

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



29
30
31
32
# File 'lib/gecko/record/base.rb', line 29

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)


66
67
68
# File 'lib/gecko/record/base.rb', line 66

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

Instance Method Details

#persisted?Boolean

Whether the record has been persisted

Examples:

variant.persisted? #=> true

Returns:

  • (Boolean)


42
43
44
# File 'lib/gecko/record/base.rb', line 42

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:



54
55
56
# File 'lib/gecko/record/base.rb', line 54

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