Module: Kangaroo::Model::Persistence::ClassMethods

Defined in:
lib/kangaroo/model/persistence.rb

Instance Method Summary collapse

Instance Method Details

#create(attributes = {}) ⇒ Object

Initialize a record and immediately save it

Parameters:

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

Returns:

  • saved record



94
95
96
97
98
# File 'lib/kangaroo/model/persistence.rb', line 94

def create attributes = {}
  new(attributes).tap do |new_record|
    new_record.save
  end
end

#find(id) ⇒ Object

Retrieve a record by id

Parameters:

  • id (Number)

Returns:

  • record

Raises:

  • RecordNotFound



105
106
107
108
109
# File 'lib/kangaroo/model/persistence.rb', line 105

def find id
  Array === id ?
  find_every(ids) :
  find_single(id)
end