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_girl/trait.rb

30 lines
593 B
Ruby
Raw Normal View History

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
@block = block
@definition = Definition.new
2011-08-12 14:38:33 -04:00
proxy = FactoryGirl::DefinitionProxy.new(@definition)
proxy.instance_eval(&@block) if block_given?
2011-08-09 20:29:02 -04:00
end
delegate :add_callback, :declare_attribute, :to_create, :define_trait,
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
def ==(other)
name == other.name &&
block == other.block
end
protected
attr_reader :block
2011-08-09 20:29:02 -04:00
end
end