Module Her::Model::ORM
In: lib/her/model/orm.rb

This module adds ORM-like capabilities to the model

Methods

Classes and Modules

Module Her::Model::ORM::ClassMethods

Public Instance methods

Initializes attribute to zero if nil and substracts the value passed as by (default is 1). The decrement is performed directly on the underlying attribute, no setter is invoked. Only makes sense for number-based attributes. Returns self.

Wrapper around decrement that saves the resource. Saving is subjected to validation checks. Returns self.

Destroy a resource

@example

  @user = User.find(1)
  @user.destroy
  # Called via DELETE "/users/1"

Return whether the object has been destroyed

Initializes attribute to zero if nil and adds the value passed as by (default is 1). The increment is performed directly on the underlying attribute, no setter is invoked. Only makes sense for number-based attributes. Returns self.

Wrapper around increment that saves the resource. Saving is subjected to validation checks. Returns self.

Uses parsed response to assign attributes and metadata

@private

Return `true` if a resource was not saved yet

new_record?()

Alias for new?

Return `true` if a resource is not `new?`

Refetches the resource

This method finds the resource by its primary key (which could be assigned manually) and modifies the object in-place.

@example

  user = User.find(1)
  # => #<User(users/1) id=1 name="Tobias Fünke">
  user.name = "Oops"
  user.reload # Fetched again via GET "/users/1"
  # => #<User(users/1) id=1 name="Tobias Fünke">

Save a resource and return `false` if the response is not a successful one or if there are errors in the resource. Otherwise, return the newly updated resource

@example Save a resource after fetching it

  @user = User.find(1)
  # Fetched via GET "/users/1"
  @user.fullname = "Tobias Fünke"
  @user.save
  # Called via PUT "/users/1"

@example Save a new resource by creating it

  @user = User.new({ :fullname => "Tobias Fünke" })
  @user.save
  # Called via POST "/users"

Similar to save(), except that ResourceInvalid is raised if the save fails

Assigns to attribute the boolean opposite of attribute?. So if the predicate returns true the attribute will become false. This method toggles directly the underlying value without calling any setter. Returns self.

@example

  user = User.first
  user.admin? # => false
  user.toggle(:admin)
  user.admin? # => true

Wrapper around toggle that saves the resource. Saving is subjected to validation checks. Returns true if the record could be saved.

Update a resource and return it

@example

  @user = User.find(1)
  @user.update_attributes(:name => "Tobias Fünke")
  # Called via PUT "/users/1"

[Validate]