Module: Fabrial

Extended by:
Create, Fabricate
Defined in:
lib/fabrial.rb,
lib/fabrial/errors.rb,
lib/fabrial/version.rb

Defined Under Namespace

Modules: Fabricate Classes: CreationError, Error, UnknownClassError

Constant Summary collapse

VERSION =
'0.3.0'

Instance Attribute Summary

Attributes included from Create

#defaults

Class Method Summary collapse

Methods included from Fabricate

add_default_return, extract_child_records, fabricate

Methods included from Create

create

Class Method Details

.before_create(&block) ⇒ Object



27
28
29
# File 'lib/fabrial.rb', line 27

def self.before_create(&block)
  @before_create = block
end

.before_fabricate(&block) ⇒ Object



14
15
16
# File 'lib/fabrial.rb', line 14

def self.before_fabricate(&block)
  @before_fabricate = block
end

.resetObject



35
36
37
38
# File 'lib/fabrial.rb', line 35

def self.reset
  @before_fabricate = nil
  @before_create = nil
end

.run_before_create(klass, data, ancesstors, children) ⇒ Object



31
32
33
# File 'lib/fabrial.rb', line 31

def self.run_before_create(klass, data, ancesstors, children)
  @before_create&.call klass, data, ancesstors, children
end

.run_before_fabricate(objects) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/fabrial.rb', line 18

def self.run_before_fabricate(objects)
  if @before_fabricate
    @before_fabricate&.call objects
  else
    objects
  end
end