module Spare::Execution::ClassMethods

Public Instance Methods

call(attributes = nil)
Alias for: execute
call!(attributes = nil)
Alias for: execute!
execute(attributes = nil) click to toggle source

Build an object (or multiple objects) and executes, if validations pass. The resulting object is returned whether the object was executed successfully to the database or not.

The attributes parameter can be either a Hash or an Array of Hashes. These Hashes describe the attributes on the objects that are to be created.

# File lib/spare/execution.rb, line 9
def execute(attributes = nil)
  if attributes.is_a?(Array)
    attributes.map { |attr| excute(attr) }
  else
    object = new(attributes)
    object.execute
    object
  end
end
Also aliased as: call
execute!(attributes = nil) click to toggle source

Build an object (or multiple objects) and executes, if validations pass. Raises a RecordInvalid error if validations fail, unlike Base#create.

The attributes parameter can be either a Hash or an Array of Hashes. These describe which attributes to be created on the object, or multiple objects when given an Array of Hashes.

# File lib/spare/execution.rb, line 27
def execute!(attributes = nil)
  if attributes.is_a?(Array)
    attributes.collect { |attr| create!(attr) }
  else
    object = new(attributes)
    object.execute!
    object
  end
end
Also aliased as: call!