Permalink
Browse files

More Factory reorganization and cleanup

  • Loading branch information...
1 parent 7f42abe commit 115378350bdd3ec03bd696a08d4f68252bf56b81 @joshuaclayton joshuaclayton committed Oct 7, 2011
Showing with 22 additions and 25 deletions.
  1. +9 −0 lib/factory_girl.rb
  2. +13 −25 lib/factory_girl/factory.rb
View
@@ -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
@@ -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
@@ -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

0 comments on commit 1153783

Please sign in to comment.