Module: FakerMaker

Extended by:
Base, Configurable
Defined in:
lib/faker_maker.rb,
lib/faker_maker/base.rb,
lib/faker_maker/naming.rb,
lib/faker_maker/factory.rb,
lib/faker_maker/version.rb,
lib/faker_maker/attribute.rb,
lib/faker_maker/auditable.rb,
lib/faker_maker/naming/json.rb,
lib/faker_maker/configuration.rb,
lib/faker_maker/lifecycle_hooks.rb,
lib/faker_maker/definition_proxy.rb,
lib/faker_maker/naming/json_capitalized.rb

Overview

FakerMaker module for generating Fakes

Defined Under Namespace

Modules: Auditable, Base, Configurable, LifecycleHooks, Naming Classes: Attribute, ChaosConflictingAttributeError, Configuration, DefinitionProxy, Error, Factory, NoSuchAttributeError, NoSuchAttributeNamingStrategy, NoSuchFactoryError

Constant Summary collapse

OMIT =

Token value for marking attributes as omittable from generated JSON. Usage in factory definitions: ‘omit: FakerMaker::OMIT`

'__OMIT__'.freeze
VERSION =
'5.0.0'

Class Method Summary collapse

Methods included from Base

factory

Methods included from Configurable

configuration, configuration=, configure

Class Method Details

.[](name) ⇒ Object

Raises:



53
54
55
56
57
58
# File 'lib/faker_maker.rb', line 53

def []( name )
  factory = find_factory(name)
  raise NoSuchFactoryError, "No such factory '#{name}'" unless factory

  factory
end

.build(name) ⇒ Object



49
50
51
# File 'lib/faker_maker.rb', line 49

def build( name )
  find_factory( name ).build
end

.factoriesObject



45
46
47
# File 'lib/faker_maker.rb', line 45

def factories
  @factories ||= {}
end

.find_factory(name) ⇒ Object



60
61
62
# File 'lib/faker_maker.rb', line 60

def find_factory( name )
  factories[name]
end

.register_factory(factory) ⇒ Object



39
40
41
42
43
# File 'lib/faker_maker.rb', line 39

def register_factory( factory )
  warn "Factory '#{factory.name}' already registered" if factories[factory.name]
  factory.assemble
  factories[factory.name] = factory
end

.shut!(name) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/faker_maker.rb', line 64

def shut!( name )
  factory = find_factory( name )
  return unless factory

  factories[name] = nil
  FakerMaker::Factory.send( :remove_const, factory.class_name )
end

.shut_all!Object



72
73
74
# File 'lib/faker_maker.rb', line 72

def shut_all!
  factories.each_key { |f| shut!( f ) }
end