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
