module Believer::Persistence::ClassMethods

Public Instance Methods

create(attributes = nil, &block) click to toggle source

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.

@param attributes [Enumerable] the attributes. If this is an array, it is assumed multiple models should be created

# 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