module Muve::Store

Muve::Store takes care of resource persistence and retrieval. Use stores as adaptors to connect your implementation of Muve to whichever datastore you please.

Adaptors or Stores only take of the interaction with the datastore but leave the model's housekeeping up the respective model. Make sure to conform to the expected return formats for the different adaptor methods.

Take a look at Muve::Store::Mongo to find an implementation of a store adaptor.

Public Instance Methods

count(resource, details={}) click to toggle source

counts the resources matching the details, if any. Returns a integer that represents the amount of matching entities found.

# File lib/muve/store.rb, line 91
def count(resource, details={})
  raise IncompleteImplementation, "implement a count handler for #{self}"
end
create(resource, details) click to toggle source

creates a resource containing the specified details in the repository. Returns the id of the created object on success, raises an error otherwise

# File lib/muve/store.rb, line 46
def create(resource, details)
  raise IncompleteImplementation, "implement a create handler for #{self}"
end
delete(resource, id, details=nil) click to toggle source

removes a resource matching the optional id and details from the repository. A successful removal operation should returns true while any other value is considered an error.

# File lib/muve/store.rb, line 54
def delete(resource, id, details=nil)
  raise IncompleteImplementation, "implement a delete handler for #{self}"
end
Also aliased as: destroy, remove
destroy(resource, id, details=nil)
Alias for: delete
fetch(resource, id, details={}) click to toggle source

collect a single resource from the repository that matches the given id and details. Upon the successful retrieval of a resource the id of the resource is presented under the key id while other attributes of the resource bear arbitrary names.

{ id: 12, name: 'Spock', organization: 'The Enterprise' }
# File lib/muve/store.rb, line 69
def fetch(resource, id, details={})
  raise IncompleteImplementation, "implement a fetch handler for #{self}"
end
find(resource, details) click to toggle source

find resources from its repository that match the given id and details Returns an Enumerator that returns a hash with the key id containing the primary key for the respective resource.

def find(resource, details)
  details = {} unless details.kind_of? Hash
  Enumerator.new do |item|
    fetched_result_from_datastore.each do |data|
      item << format_data(data) # format_data composes the required hash
    end
  end
end
# File lib/muve/store.rb, line 85
def find(resource, details)
  raise IncompleteImplementation, "implement a find handler for #{self}"
end
formatter() click to toggle source
# File lib/muve/store.rb, line 105
def formatter
  raise IncompleteImplementation, "specify a formatter"
end
get(resource, id=nil, details=nil) click to toggle source

gets data from the given container matching the provided details

Given a Place resource the following calls may be acceptable

  • +Adaptor.get(Place, 1232) # find one resource where id = 1232+

  • +Adaptor.get(Place, nil, { city: 'NYC', rating: 5 })+ # find more

# File lib/muve/store.rb, line 34
def get(resource, id=nil, details=nil)
  raise InvalidQuery unless (id || details)

  if details
    find(resource, details)
  else
    fetch(resource, id, {})
  end
end
index_hash(index_values) click to toggle source

composes the id hash for the used store. Some in some cases the index is the id or _id field, while in other cases the index field may be different. The store should take care of index naming.

# File lib/muve/store.rb, line 101
def index_hash(index_values)
  raise IncompleteImplementation, "implement the index_hash handler for #{self}"
end
remove(resource, id, details=nil)
Alias for: delete
update(resource, id, details) click to toggle source

update a resource with the identified by id with the given details

# File lib/muve/store.rb, line 59
def update(resource, id, details)
  raise IncompleteImplementation, "implement a update handler for #{self}"
end