Class: Fabricators::Definitions

Inherits:
Object
  • Object
show all
Includes:
Callbacks
Defined in:
lib/fabricators/definitions.rb

Instance Method Summary collapse

Methods included from Callbacks

#callbacks

Constructor Details

#initializeDefinitions

Returns a new instance of Definitions.



5
6
7
# File 'lib/fabricators/definitions.rb', line 5

def initialize
  reset!
end

Instance Method Details

#fabricator(name, options = {}, &block) ⇒ Object



15
16
17
18
19
20
# File 'lib/fabricators/definitions.rb', line 15

def fabricator(name, options={}, &block)
  fabricator = Fabricator.new(name, options, &block)
  iterate_names name, options do |name|
    @fabricators[name] = fabricator
  end
end

#find(name, type) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/fabricators/definitions.rb', line 29

def find(name, type)
  case type
  when :fabricator
    @fabricators[name]
  when :generator
    @generators[name]
  end.tap do |definition|
    raise "Definition #{name} of type #{type} not found" unless definition
  end
end

#generator(name, first = 0, options = {}, &block) ⇒ Object



22
23
24
25
26
27
# File 'lib/fabricators/definitions.rb', line 22

def generator(name, first=0, options={}, &block)
  generator = Generator.new(first, &block)
  iterate_names name, options do |name|
    @generators[name] = generator
  end
end

#reset!Object



9
10
11
12
13
# File 'lib/fabricators/definitions.rb', line 9

def reset!
  @fabricators = {}
  @generators = {}
  @callbacks = {}
end