Class: Traver::ObjectCreator

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/traver/object_creator.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(factory_name, params, factory_definer, sequencer, cache = {}, nesting = 1) ⇒ ObjectCreator

Returns a new instance of ObjectCreator.



23
24
25
26
27
28
29
30
# File 'lib/traver/object_creator.rb', line 23

def initialize(factory_name, params, factory_definer, sequencer, cache = {}, nesting = 1)
  @factory_name    = factory_name
  @params          = params
  @factory_definer = factory_definer
  @sequencer       = sequencer
  @cache           = cache
  @nesting         = nesting
end

Instance Attribute Details

#after_createObject

Returns the value of attribute after_create.



10
11
12
# File 'lib/traver/object_creator.rb', line 10

def after_create
  @after_create
end

#cacheObject (readonly)

Returns the value of attribute cache.



7
8
9
# File 'lib/traver/object_creator.rb', line 7

def cache
  @cache
end

#factory_definerObject (readonly)

Returns the value of attribute factory_definer.



7
8
9
# File 'lib/traver/object_creator.rb', line 7

def factory_definer
  @factory_definer
end

#factory_nameObject (readonly)

Returns the value of attribute factory_name.



7
8
9
# File 'lib/traver/object_creator.rb', line 7

def factory_name
  @factory_name
end

#nestingObject (readonly)

Returns the value of attribute nesting.



7
8
9
# File 'lib/traver/object_creator.rb', line 7

def nesting
  @nesting
end

#objectObject (readonly)

Returns the value of attribute object.



8
9
10
# File 'lib/traver/object_creator.rb', line 8

def object
  @object
end

#paramsObject (readonly)

Returns the value of attribute params.



7
8
9
# File 'lib/traver/object_creator.rb', line 7

def params
  @params
end

#sequencerObject (readonly)

Returns the value of attribute sequencer.



7
8
9
# File 'lib/traver/object_creator.rb', line 7

def sequencer
  @sequencer
end

Class Method Details

.create_object(factory_name, params, factory_definer, sequencer, cache = {}, nesting = 1) ⇒ Object



16
17
18
19
20
21
# File 'lib/traver/object_creator.rb', line 16

def self.create_object(factory_name, params, factory_definer, sequencer, cache = {}, nesting = 1)
  creator = new(factory_name, params, factory_definer, sequencer, cache, nesting)
  creator.create_object
  
  creator.object
end

Instance Method Details

#create_objectObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/traver/object_creator.rb', line 32

def create_object
  obtain_factory
  
  if obtain_object_from_cache?
    obtain_object_from_cache
  else
    # puts "#{'-' * nesting} #{factory_name}<br/>"
    
    change_ref_to_be_empty_hash
    merge_factory_params
    merge_default_params
    instantiate_object
    set_nested_objects
    set_attributes
    persist_object
    cache_object
    set_has_one_objects
    set_nested_collections
    call_after_create_hook
  end
end