Class: DataWorks::ParentCreator

Inherits:
Object
  • Object
show all
Defined in:
lib/data_works/parent_creator.rb

Instance Method Summary collapse

Constructor Details

#initialize(works, model_name, model_attrs) ⇒ ParentCreator

Returns a new instance of ParentCreator.



4
5
6
7
8
# File 'lib/data_works/parent_creator.rb', line 4

def initialize(works, model_name, model_attrs)
  @works = works
  @model_name = model_name.to_sym
  @parents = {}
end

Instance Method Details

#create_necessary_parents(parents_we_already_have) ⇒ Object

This returns a hash of the parent models created, so that they can be easily merged into a model attribute hash. For example, if a school parent model was created for a student model, then it would be returned like so:

{ :school => the_school_model }


15
16
17
18
19
20
# File 'lib/data_works/parent_creator.rb', line 15

def create_necessary_parents(parents_we_already_have)
  for missing_necessary_parent in missing_necessary_parents(parents_we_already_have)
    find_or_add(missing_necessary_parent)
  end
  @parents
end