Module: Believer::Persistence::ClassMethods

Defined in:
lib/believer/persistence.rb

Instance Method Summary collapse

Instance Method Details

#create(attributes = nil, &block) ⇒ Object

Creates 1 or more new instances, and persists them to the database. An optional block can be provided which is called for each created model.



13
14
15
16
17
18
19
20
21
# File 'lib/believer/persistence.rb', line 13

def create(attributes = nil, &block)
  if attributes.is_a?(Array)
    attributes.collect { |attr| create(attr, &block) }
  else
    object = new(attributes, &block)
    object.save
    object
  end
end