module Connectors
  module Helpers
    module ListCommand

      # when included, this module adds method #list 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)
        alias_method base.to_s.underscore_class.pluralize, :list
      end

      # query options is needed, for example, for fields limiting
      def list(query={}, query_options={})
        collection.find(query, query_options).to_a.map {|bson| model_from_bson(bson)}
      end

    end
  end
end
