Module: Ashikawa::AR::Persistence

Extended by:
ActiveSupport::Concern
Included in:
Model
Defined in:
lib/ashikawa-ar/persistence.rb

Overview

Provides Persistence functionality for your model

Instance Method Summary collapse

Instance Method Details

#deleteself

Delete the record from the database

Examples:

Get the updated version from the database

sam.delete

Returns:

  • (self)

Raises:



56
# File 'lib/ashikawa-ar/persistence.rb', line 56

def delete;end

#deleted?Boolean

Check, if the object has been deleted

Examples:

Check, if sam is deleted

sam.deleted?

Returns:

  • (Boolean)


106
# File 'lib/ashikawa-ar/persistence.rb', line 106

def deleted?;end

#new_record?Boolean

Check, if the object is a new record

Examples:

Check, if sam is a new record

sam.new_record?

Returns:

  • (Boolean)


114
# File 'lib/ashikawa-ar/persistence.rb', line 114

def new_record?;end

#persisted?Boolean

Check, if the object has been persisted

Examples:

Check, if sam is persisted

sam.persisted?

Returns:

  • (Boolean)


98
# File 'lib/ashikawa-ar/persistence.rb', line 98

def persisted?;end

#reloadself

Reload the record from the database

Examples:

Get the updated version from the database

sam.reload

Returns:

  • (self)

Raises:



47
# File 'lib/ashikawa-ar/persistence.rb', line 47

def reload;end

#saveself, false

Save the document to the database returning false if invalid

Examples:

Save the document to the database

sam = Person.new name: "Sam Lowry"
sam.save

Returns:

  • (self, false)

    Returns false if not saved



19
# File 'lib/ashikawa-ar/persistence.rb', line 19

def save;end

#save!self

Save the document to the database throwing an exception if invalid

Examples:

Save the document to the database

sam = Person.new name: "Sam Lowry"
sam.save!

Returns:

  • (self)

Raises:



29
# File 'lib/ashikawa-ar/persistence.rb', line 29

def save!;end

#save_without_validationself

Save the document to the database even if it is invalid

Examples:

Save the document to the database

sam = Person.new name: "Sam Lowry"
sam.save_without_validation

Returns:

  • (self)

    Returns false if not saved



38
# File 'lib/ashikawa-ar/persistence.rb', line 38

def save_without_validation;end

#update_attribute(key, value) ⇒ self

Update a single attribute and write to the database

Examples:

Update the age

sam.update_attribute "age", 39

Parameters:

  • key (String)

    Name of the attribute

  • value (Object)

    Value of the attribute

Returns:

  • (self)

Raises:



67
# File 'lib/ashikawa-ar/persistence.rb', line 67

def update_attribute(key, value);end

#update_attributes(attributes) ⇒ self, false

Updates multiple attributes and write to the database returning false if they are invalid

Examples:

Update the age and favorite color

sam.update_attributes age: 39, favorite_color: "Green"

Parameters:

  • attributes (Hash)

Returns:

  • (self, false)

Raises:



78
# File 'lib/ashikawa-ar/persistence.rb', line 78

def update_attributes(attributes);end

#update_attributes!(attributes) ⇒ self

Updates multiple attributes and write to the database throwing an exception if they are invalid

Examples:

Update the age and favorite color

sam.update_attributes! age: 39, favorite_color: "Green"

Parameters:

  • attributes (Hash)

Returns:

  • (self)

Raises:



90
# File 'lib/ashikawa-ar/persistence.rb', line 90

def update_attributes!(attributes);end