1
0
Fork 0
mirror of https://github.com/thoughtbot/factory_bot.git synced 2022-11-09 11:43:51 -05:00
thoughtbot--factory_bot/lib/factory_bot/trait.rb

34 lines
643 B
Ruby
Raw Normal View History

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