Parent

Files

DataMapper::Adapters::YamlAdapter

Public Class Methods

new(name, options = {}) click to toggle source

@api semipublic

# File lib/dm-yaml-adapter/adapter.rb, line 53
def initialize(name, options = {})
  super
  (@path = Pathname(@options[:path]).freeze).mkpath
end

Public Instance Methods

attributes_as_fields(attributes) click to toggle source

@api semipublic

# File lib/dm-yaml-adapter/adapter.rb, line 42
def attributes_as_fields(attributes)
  pairs = attributes.map do |property, value|
    dumped = value.kind_of?(Module) ? value.name : property.dump(value)
    [ property.field, dumped ]
  end
  Hash[pairs]
end
create(resources) click to toggle source

@api semipublic

# File lib/dm-yaml-adapter/adapter.rb, line 8
def create(resources)
  update_records(resources.first.model) do |records|
    resources.each do |resource|
      initialize_serial(resource, records.size.succ)
      records << attributes_as_fields(resource.attributes(nil))
    end
  end
end
delete(collection) click to toggle source

@api semipublic

# File lib/dm-yaml-adapter/adapter.rb, line 33
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) click to toggle source

@api semipublic

# File lib/dm-yaml-adapter/adapter.rb, line 18
def read(query)
  query.filter_records(records_for(query.model).dup)
end
update(attributes, collection) click to toggle source

@api semipublic

# File lib/dm-yaml-adapter/adapter.rb, line 23
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 { |record| record.update(attributes) }.size
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.