Module: ActiveData::Model::Persistence::ClassMethods

Defined in:
lib/active_data/model/persistence.rb

Instance Method Summary collapse

Instance Method Details

#instantiate(data) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/active_data/model/persistence.rb', line 7

def instantiate(data)
  data = data.stringify_keys
  instance = allocate

  instance.instance_variable_set(:@initial_attributes, data.slice(*attribute_names))
  instance.send(:mark_persisted!)

  instance
end

#instantiate_collection(data) ⇒ Object



17
18
19
20
21
# File 'lib/active_data/model/persistence.rb', line 17

def instantiate_collection(data)
  collection = Array.wrap(data).map { |attrs| instantiate attrs }
  collection = scope(collection, true) if respond_to?(:scope)
  collection
end