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



46
47
48
# File 'lib/cequel/record/persistence.rb', line 46

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

#hydrate(row) ⇒ Cequel::Record

populated with the attributes from ‘row`

Parameters:

  • row (Hash)

    attributes from the database with which the new instance should be populated.

Returns:

Since:

  • 0.1.0



62
63
64
# File 'lib/cequel/record/persistence.rb', line 62

def hydrate(row)
  new_empty.hydrate(row)
end

#tableObject

Since:

  • 0.1.0



51
52
53
# File 'lib/cequel/record/persistence.rb', line 51

def table
  connection[table_name]
end