Module: BuiltInData::ClassMethods

Defined in:
lib/built_in_data.rb

Instance Method Summary collapse

Instance Method Details

#load_built_in_data!(hash = nil) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/built_in_data.rb', line 12

def load_built_in_data!(hash = nil)
  objects_hash = prepare_objects_hash(hash)
  Array.new.tap do |updated_objects|

    objects_hash.each do |key, attributes|
      updated_objects << create_or_update!(key, attributes)
    end

    # destroy any built_in objects that have been removed from built_in_data_attributes
    self.built_in.each do |object|
      object.destroy unless objects_hash.has_key?(object.built_in_key)
    end
  end
end