2011-08-09 20:29:02 -04:00
|
|
|
module FactoryGirl
|
2012-05-05 02:31:31 -04:00
|
|
|
# @api private
|
2011-08-12 16:16:17 -04:00
|
|
|
class Trait
|
2012-05-06 16:56:37 -04:00
|
|
|
attr_reader :name, :definition
|
2011-08-12 14:38:33 -04:00
|
|
|
|
2012-05-05 02:31:31 -04:00
|
|
|
def initialize(name, &block)
|
2011-08-09 20:29:02 -04:00
|
|
|
@name = name
|
2011-10-14 15:14:43 -04:00
|
|
|
@block = block
|
2012-05-11 11:43:08 -04:00
|
|
|
@definition = Definition.new(@name)
|
2011-08-12 14:38:33 -04:00
|
|
|
|
2011-10-28 17:01:27 -04:00
|
|
|
proxy = FactoryGirl::DefinitionProxy.new(@definition)
|
2011-10-14 15:14:43 -04:00
|
|
|
proxy.instance_eval(&@block) if block_given?
|
2011-08-09 20:29:02 -04:00
|
|
|
end
|
|
|
|
|
2012-05-11 11:43:08 -04:00
|
|
|
delegate :add_callback, :declare_attribute, :to_create, :define_trait, :constructor,
|
2012-03-09 17:20:38 -05:00
|
|
|
:callbacks, :attributes, to: :@definition
|
2011-08-12 14:38:33 -04:00
|
|
|
|
2011-08-10 14:11:53 -04:00
|
|
|
def names
|
|
|
|
[@name]
|
|
|
|
end
|
2011-10-14 15:14:43 -04:00
|
|
|
|
|
|
|
def ==(other)
|
|
|
|
name == other.name &&
|
|
|
|
block == other.block
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
attr_reader :block
|
2011-08-09 20:29:02 -04:00
|
|
|
end
|
|
|
|
end
|