Module: FactoryGirl

Extended by:
Syntax::Default
Defined in:
lib/factory_girl.rb,
lib/factory_girl/proxy.rb,
lib/factory_girl/syntax.rb,
lib/factory_girl/aliases.rb,
lib/factory_girl/factory.rb,
lib/factory_girl/version.rb,
lib/factory_girl/registry.rb,
lib/factory_girl/sequence.rb,
lib/factory_girl/attribute.rb,
lib/factory_girl/proxy/stub.rb,
lib/factory_girl/proxy/build.rb,
lib/factory_girl/syntax/make.rb,
lib/factory_girl/syntax/sham.rb,
lib/factory_girl/proxy/create.rb,
lib/factory_girl/syntax/default.rb,
lib/factory_girl/syntax/methods.rb,
lib/factory_girl/syntax/vintage.rb,
lib/factory_girl/syntax/generate.rb,
lib/factory_girl/attribute/static.rb,
lib/factory_girl/definition_proxy.rb,
lib/factory_girl/find_definitions.rb,
lib/factory_girl/syntax/blueprint.rb,
lib/factory_girl/attribute/dynamic.rb,
lib/factory_girl/attribute/callback.rb,
lib/factory_girl/attribute/implicit.rb,
lib/factory_girl/attribute/sequence.rb,
lib/factory_girl/proxy/attributes_for.rb,
lib/factory_girl/attribute/association.rb

Defined Under Namespace

Modules: Syntax Classes: AssociationDefinitionError, Attribute, AttributeDefinitionError, DefinitionProxy, DuplicateDefinitionError, Factory, InvalidCallbackNameError, Proxy, Registry, Sequence, SequenceAbuseError

Constant Summary collapse

VERSION =
"2.0.1"

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from Syntax::Default

define

Methods included from Syntax::Methods

#attributes_for, #build, #build_list, #build_stubbed, #create, #create_list, #generate

Class Attribute Details

.aliasesObject

:nodoc:



4
5
6
# File 'lib/factory_girl/aliases.rb', line 4

def aliases
  @aliases
end

.definition_file_pathsObject

An Array of strings specifying locations that should be searched for factory definitions. By default, factory_girl will attempt to require “factories,” “test/factories,” and “spec/factories.” Only the first existing file will be loaded.



8
9
10
# File 'lib/factory_girl/find_definitions.rb', line 8

def definition_file_paths
  @definition_file_paths
end

Class Method Details

.aliases_for(attribute) ⇒ Object

:nodoc:



11
12
13
14
15
16
17
18
19
20
# File 'lib/factory_girl/aliases.rb', line 11

def self.aliases_for(attribute) #:nodoc:
  aliases.collect do |params|
    pattern, replace = *params
    if pattern.match(attribute.to_s)
      attribute.to_s.sub(pattern, replace).to_sym
    else
      nil
    end
  end.compact << attribute
end

.factoriesObject



30
31
32
# File 'lib/factory_girl.rb', line 30

def self.factories
  @factories ||= Registry.new
end

.factory_by_name(name) ⇒ Object



38
39
40
# File 'lib/factory_girl.rb', line 38

def self.factory_by_name(name)
  factories.find(name)
end

.find_definitionsObject

:nodoc:



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/factory_girl/find_definitions.rb', line 12

def self.find_definitions #:nodoc:
  definition_file_paths.each do |path|
    path = File.expand_path(path)

    require("#{path}.rb") if File.exists?("#{path}.rb")

    if File.directory? path
      Dir[File.join(path, '**', '*.rb')].sort.each do |file|
        require file
      end
    end
  end
end

.register_factory(factory) ⇒ Object



34
35
36
# File 'lib/factory_girl.rb', line 34

def self.register_factory(factory)
  factories.add(factory)
end

.register_sequence(sequence) ⇒ Object



46
47
48
# File 'lib/factory_girl.rb', line 46

def self.register_sequence(sequence)
  sequences.add(sequence)
end

.sequence_by_name(name) ⇒ Object



50
51
52
# File 'lib/factory_girl.rb', line 50

def self.sequence_by_name(name)
  sequences.find(name)
end

.sequencesObject



42
43
44
# File 'lib/factory_girl.rb', line 42

def self.sequences
  @sequences ||= Registry.new
end