fluke/devops-service/db/mongo/connectors/helpers/show_command.rb
2016-01-19 18:10:51 +03:00

24 lines
656 B
Ruby

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 = base.to_s.underscore_class.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