fluke/devops-service/db/mongo/connectors/helpers/show_command.rb
2015-02-12 13:01:05 +03:00

26 lines
694 B
Ruby

require 'lib/string_helper'
module Connectors
module Helpers
module ShowCommand
# when included, this module adds method #show and alias for it.
# Alias name depends on base class name.
# We need this alias to forward methods from MongoConnector to resources connectors.
def self.included(base)
method_name = StringHelper.underscore_class(base).to_sym
alias_method method_name, :show
end
def show(id, options={})
query = {'_id' => id}.merge(options)
bson = collection.find(query).to_a.first
raise RecordNotFound.new("'#{id}' not found") unless bson
model_from_bson(bson)
end
end
end
end