abstract class Avram::Factory

Defined in:

avram/factory.cr

Constant Summary

SEQUENCES = {} of String => Int32

Class Method Summary

Macro Summary

Instance Method Summary

Instance methods inherited from class Object

blank_for_validates_required? : Bool blank_for_validates_required?

Class Method Detail

def self.build_attributes(&) #

[View source]
def self.build_attributes #

[View source]
def self.create #

[View source]
def self.create(&) #

[View source]
def self.create_pair #

Returns an array with 2 instances of the model from the Factory.

Usage:

tags = TagFactory.create_pair
typeof(tags) # => Array(Tag)
tags.size    # => 2

[View source]
def self.create_pair(&) #

Similar to .create_pair, but accepts a block which yields the factory instance.

Both factories receive the same argument values.

Usage:

TagFactory.create_pair do |factory|
  # set both factories name to "test"
  factory.name("test")
end

[View source]

Macro Detail

macro setup_attribute_shortcuts(operation) #

[View source]
macro setup_attributes(operation) #

[View source]
macro setup_callbacks(model_name) #

[View source]

Instance Method Detail

def create #

[View source]
def operation #

[View source]
def sequence(value : String) : String #

Returns a value with a number to use for unique values.

Usage:

class UserFactory < Avram::Factory
  def initialize
    username sequence("username")            # => username-1, username-2, etc.
    email "#{sequence("email")}@example.com" # => [email protected], [email protected], etc.
  end
end

[View source]