2011-08-09 20:29:02 -04:00
|
|
|
module FactoryGirl
|
2011-08-12 16:16:17 -04:00
|
|
|
class Trait
|
2011-08-09 20:29:02 -04:00
|
|
|
attr_reader :name
|
2011-08-12 14:38:33 -04:00
|
|
|
|
2011-08-09 20:29:02 -04:00
|
|
|
def initialize(name, &block) #:nodoc:
|
|
|
|
@name = name
|
2011-08-12 14:38:33 -04:00
|
|
|
@attribute_list = AttributeList.new
|
|
|
|
|
2011-08-09 20:29:02 -04:00
|
|
|
proxy = FactoryGirl::DefinitionProxy.new(self)
|
|
|
|
proxy.instance_eval(&block) if block_given?
|
|
|
|
end
|
|
|
|
|
2011-09-23 13:14:02 -04:00
|
|
|
def declare_attribute(declaration)
|
|
|
|
@attribute_list.declare_attribute(declaration)
|
|
|
|
declaration
|
2011-08-09 20:29:02 -04:00
|
|
|
end
|
2011-08-12 14:38:33 -04:00
|
|
|
|
2011-08-10 18:19:25 -04:00
|
|
|
def add_callback(name, &block)
|
2011-09-16 16:24:16 -04:00
|
|
|
@attribute_list.add_callback(Callback.new(name, block))
|
2011-08-10 18:19:25 -04:00
|
|
|
end
|
2011-08-12 14:38:33 -04:00
|
|
|
|
|
|
|
def attributes
|
2011-09-23 13:14:02 -04:00
|
|
|
AttributeList.new.tap do |list|
|
|
|
|
@attribute_list.declarations.each do |declaration|
|
|
|
|
declaration.to_attributes.each do |attribute|
|
|
|
|
list.define_attribute(attribute)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
list.apply_attributes @attribute_list
|
|
|
|
end
|
2011-08-12 14:38:33 -04:00
|
|
|
end
|
|
|
|
|
2011-08-10 14:11:53 -04:00
|
|
|
def names
|
|
|
|
[@name]
|
|
|
|
end
|
2011-08-09 20:29:02 -04:00
|
|
|
end
|
|
|
|
end
|