class FactoryGirl::Definition

@api private

Attributes

declarations[R]
defined_traits[R]

Public Class Methods

new(name = nil, base_traits = []) click to toggle source
# File lib/factory_girl/definition.rb, line 6
def initialize(name = nil, base_traits = [])
  @declarations      = DeclarationList.new(name)
  @callbacks         = []
  @defined_traits    = []
  @to_create         = nil
  @base_traits       = base_traits
  @additional_traits = []
  @constructor       = nil
  @attributes        = nil
  @compiled          = false
end

Public Instance Methods

add_callback(callback) click to toggle source
# File lib/factory_girl/definition.rb, line 71
def add_callback(callback)
  @callbacks << callback
end
append_traits(new_traits) click to toggle source
# File lib/factory_girl/definition.rb, line 67
def append_traits(new_traits)
  @additional_traits += new_traits
end
attributes() click to toggle source
# File lib/factory_girl/definition.rb, line 20
def attributes
  @attributes ||= AttributeList.new.tap do |attribute_list|
    attribute_lists = aggregate_from_traits_and_self(:attributes) { declarations.attributes }
    attribute_lists.each do |attributes|
      attribute_list.apply_attributes attributes
    end
  end
end
callbacks() click to toggle source
# File lib/factory_girl/definition.rb, line 41
def callbacks
  aggregate_from_traits_and_self(:callbacks) { @callbacks }
end
compile() click to toggle source
# File lib/factory_girl/definition.rb, line 45
def compile
  unless @compiled
    declarations.attributes

    defined_traits.each do |defined_trait|
      base_traits.each       {|bt| bt.define_trait defined_trait }
      additional_traits.each {|bt| bt.define_trait defined_trait }
    end

    @compiled = true
  end
end
constructor() click to toggle source
# File lib/factory_girl/definition.rb, line 37
def constructor
  aggregate_from_traits_and_self(:constructor) { @constructor }.last
end
define_constructor(&block) click to toggle source
# File lib/factory_girl/definition.rb, line 83
def define_constructor(&block)
  @constructor = block
end
define_trait(trait) click to toggle source
# File lib/factory_girl/definition.rb, line 79
def define_trait(trait)
  @defined_traits << trait
end
inherit_traits(new_traits) click to toggle source
# File lib/factory_girl/definition.rb, line 63
def inherit_traits(new_traits)
  @base_traits += new_traits
end
overridable() click to toggle source
# File lib/factory_girl/definition.rb, line 58
def overridable
  declarations.overridable
  self
end
skip_create() click to toggle source
# File lib/factory_girl/definition.rb, line 75
def skip_create
  @to_create = ->(instance) { }
end
to_create(&block) click to toggle source
# File lib/factory_girl/definition.rb, line 29
def to_create(&block)
  if block_given?
    @to_create = block
  else
    aggregate_from_traits_and_self(:to_create) { @to_create }.last
  end
end