Module: Cequel::Record::Persistence::ClassMethods

Extended by:
Forwardable
Defined in:
lib/cequel/record/persistence.rb

Overview

Class-level functionality for loading and saving records

Since:

  • 0.1.0

Instance Method Summary collapse

Instance Method Details

#create(attributes = {}) {|record| ... } ⇒ Record

Initialize a new record instance, assign attributes, and immediately save it.

Examples:

Create a new record with attribute assignment

Post.create(
  blog_subdomain: 'cassandra',
  permalink: 'cequel',
  title: 'Cequel: The Next Generation'
)

Create a new record with a block

Post.create do |post|
  post.blog = blog
  post.permalink = 'cequel'
  post.title = 'Cequel: The Next Generation'
end

Parameters:

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

    attributes to assign to the new record

Yield Parameters:

  • record (Record)

    record to make modifications before saving

Returns:

Since:

  • 0.1.0



44
45
46
# File 'lib/cequel/record/persistence.rb', line 44

def create(attributes = {}, &block)
  new(attributes, &block).tap { |record| record.save }
end

#hydrate(row) ⇒ Object

Since:

  • 0.1.0



54
55
56
# File 'lib/cequel/record/persistence.rb', line 54

def hydrate(row)
  new_empty(row).__send__(:hydrated!)
end

#tableObject

Since:

  • 0.1.0



49
50
51
# File 'lib/cequel/record/persistence.rb', line 49

def table
  connection[table_name]
end