Class: DataMapper::Adapters::YamlAdapter

Inherits:
AbstractAdapter show all
Defined in:
lib/dm-core/adapters/yaml_adapter.rb

Instance Attribute Summary

Attributes inherited from AbstractAdapter

#field_naming_convention, #name, #options, #resource_naming_convention

Instance Method Summary collapse

Methods included from Equalizer

#equalize

Instance Method Details

#create(resources) ⇒ Object

TODO: document

API:

  • semipublic



9
10
11
12
13
14
15
16
# File 'lib/dm-core/adapters/yaml_adapter.rb', line 9

def create(resources)
  update_records(resources.first.model) do |records|
    resources.each do |resource|
      initialize_serial(resource, records.size.succ)
      records << resource.attributes(:field)
    end
  end
end

#delete(collection) ⇒ Object

TODO: document

API:

  • semipublic



37
38
39
40
41
42
43
# File 'lib/dm-core/adapters/yaml_adapter.rb', line 37

def delete(collection)
  update_records(collection.model) do |records|
    records_to_delete = collection.query.filter_records(records.dup)
    records.replace(records - records_to_delete)
    records_to_delete.size
  end
end

#read(query) ⇒ Object

TODO: document

API:

  • semipublic



20
21
22
# File 'lib/dm-core/adapters/yaml_adapter.rb', line 20

def read(query)
  query.filter_records(records_for(query.model).dup)
end

#update(attributes, collection) ⇒ Object

TODO: document

API:

  • semipublic



26
27
28
29
30
31
32
33
# File 'lib/dm-core/adapters/yaml_adapter.rb', line 26

def update(attributes, collection)
  attributes = attributes_as_fields(attributes)

  update_records(collection.model) do |records|
    records_to_update = collection.query.filter_records(records.dup)
    records_to_update.each { |resource| resource.update(attributes) }.size
  end
end