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

Style cleanup

This commit is contained in:
Joshua Clayton 2012-05-05 00:53:19 -04:00
parent 90f0072f84
commit d8db256664
5 changed files with 25 additions and 32 deletions

View file

@ -5,24 +5,6 @@ module FactoryGirl
class Evaluator
class_attribute :attribute_lists
def self.attribute_list
AttributeList.new.tap do |list|
attribute_lists.each do |attribute_list|
list.apply_attributes attribute_list.to_a
end
end
end
def self.define_attribute(name, &block)
define_method(name) do
if @cached_attributes.key?(name)
@cached_attributes[name]
else
@cached_attributes[name] = instance_exec(&block)
end
end
end
private_instance_methods.each do |method|
undef_method(method) unless method =~ /^__|initialize/
end
@ -66,5 +48,23 @@ module FactoryGirl
def __override_names__
@overrides.keys
end
def self.attribute_list
AttributeList.new.tap do |list|
attribute_lists.each do |attribute_list|
list.apply_attributes attribute_list.to_a
end
end
end
def self.define_attribute(name, &block)
define_method(name) do
if @cached_attributes.key?(name)
@cached_attributes[name]
else
@cached_attributes[name] = instance_exec(&block)
end
end
end
end
end

View file

@ -1,5 +1,4 @@
module FactoryGirl
class << self
# An Array of strings specifying locations that should be searched for
# factory definitions. By default, factory_girl will attempt to require
@ -7,6 +6,7 @@ module FactoryGirl
# existing file will be loaded.
attr_accessor :definition_file_paths
end
self.definition_file_paths = %w(factories test/factories spec/factories)
def self.find_definitions #:nodoc:

View file

@ -12,10 +12,6 @@ module FactoryGirl
end
class DSL
def self.run(block)
new.instance_eval(&block)
end
def factory(name, options = {}, &block)
factory = Factory.new(name, options)
proxy = FactoryGirl::DefinitionProxy.new(factory.definition)
@ -36,18 +32,22 @@ module FactoryGirl
def trait(name, &block)
FactoryGirl.register_trait(Trait.new(name, &block))
end
end
class ModifyDSL
def self.run(block)
new.instance_eval(&block)
end
end
class ModifyDSL
def factory(name, options = {}, &block)
factory = FactoryGirl.factory_by_name(name)
proxy = FactoryGirl::DefinitionProxy.new(factory.definition.overridable)
proxy.instance_eval(&block)
end
def self.run(block)
new.instance_eval(&block)
end
end
end
end

View file

@ -40,7 +40,6 @@ module FactoryGirl
end
module ClassMethods #:nodoc:
def generate(overrides = {}, &block)
ActiveSupport::Deprecation.warn "Model.generate is deprecated; use the FactoryGirl.define syntax instead", caller
instance = FactoryRunner.new(name.underscore, :build, [overrides]).run
@ -62,9 +61,7 @@ module FactoryGirl
yield(instance) if block_given?
instance
end
end
end
end
end

View file

@ -20,13 +20,11 @@ module FactoryGirl
# This syntax was derived from Pete Yandell's machinist.
module Make
module ActiveRecord #:nodoc:
def self.included(base) # :nodoc:
base.extend ClassMethods
end
module ClassMethods #:nodoc:
def make(overrides = {})
ActiveSupport::Deprecation.warn "Model.make is deprecated; use the FactoryGirl.define syntax instead", caller
FactoryRunner.new(name.underscore, :build, [overrides]).run
@ -36,9 +34,7 @@ module FactoryGirl
ActiveSupport::Deprecation.warn "Model.make! is deprecated; use the FactoryGirl.define syntax instead", caller
FactoryRunner.new(name.underscore, :create, [overrides]).run
end
end
end
end
end