Skip to content

Commit

Permalink
More Factory reorganization and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaclayton committed Oct 7, 2011
1 parent 7f42abe commit 1153783
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
9 changes: 9 additions & 0 deletions lib/factory_girl.rb
Expand Up @@ -34,6 +34,15 @@
end

module FactoryGirl
# Raised when a factory is defined that attempts to instantiate itself.
class AssociationDefinitionError < RuntimeError; end

# Raised when a callback is defined that has an invalid name
class InvalidCallbackNameError < RuntimeError; end

# Raised when a factory is defined with the same name as a previously-defined factory.
class DuplicateDefinitionError < RuntimeError; end

def self.factories
@factories ||= Registry.new
end
Expand Down
38 changes: 13 additions & 25 deletions lib/factory_girl/factory.rb
Expand Up @@ -2,34 +2,9 @@
require "active_support/inflector"

module FactoryGirl
# Raised when a factory is defined that attempts to instantiate itself.
class AssociationDefinitionError < RuntimeError
end

# Raised when a callback is defined that has an invalid name
class InvalidCallbackNameError < RuntimeError
end

# Raised when a factory is defined with the same name as a previously-defined factory.
class DuplicateDefinitionError < RuntimeError
end

class Factory
attr_reader :name #:nodoc:

def factory_name
puts "WARNING: factory.factory_name is deprecated. Use factory.name instead."
name
end

def build_class #:nodoc:
@build_class ||= class_name.to_s.camelize.constantize
end

def default_strategy #:nodoc:
@default_strategy || (parent && parent.default_strategy) || :create
end

def initialize(name, options = {}) #:nodoc:
assert_valid_options(options)
@name = name.to_s.underscore.to_sym
Expand All @@ -44,6 +19,19 @@ def initialize(name, options = {}) #:nodoc:
@compiled = false
end

def factory_name
puts "WARNING: factory.factory_name is deprecated. Use factory.name instead."
name
end

def build_class #:nodoc:
@build_class ||= class_name.to_s.camelize.constantize
end

def default_strategy #:nodoc:
@default_strategy || (parent && parent.default_strategy) || :create
end

def allow_overrides
@compiled = false
@attribute_list.overridable
Expand Down

0 comments on commit 1153783

Please sign in to comment.