Class: Fabricators::Definitions
- Inherits:
-
Object
- Object
- Fabricators::Definitions
- Includes:
- Callbacks
- Defined in:
- lib/fabricators/definitions.rb
Instance Method Summary collapse
- #fabricator(name, options = {}, &block) ⇒ Object
- #find(name, type) ⇒ Object
- #generator(name, first = 0, options = {}, &block) ⇒ Object
-
#initialize ⇒ Definitions
constructor
A new instance of Definitions.
- #reset! ⇒ Object
Methods included from Callbacks
Constructor Details
#initialize ⇒ Definitions
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, ={}, &block) fabricator = Fabricator.new(name, , &block) iterate_names name, 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, ={}, &block) generator = Generator.new(first, &block) iterate_names name, 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 |