Sha256: 7e4ef73177f5089292cce3f7b66e09c1c4439eecc21ece3fde9e0216a2fdf9d1

Contents?: true

Size: 1005 Bytes

Versions: 10

Compression:

Stored size: 1005 Bytes

Contents

module CouchPotato
  module View
    # A view to return model instances with only some properties poulated by searching its properties, e.g. for very large documents where you are only interested in some of their data
    #
    # example:
    #   view :my_view, :key => :name, :properties => [:name, :author], :type => :properties
    class PropertiesViewSpec < ModelViewSpec
      def map_function
        map_body do
          "emit(#{formatted_key(key)}, #{properties_for_map(properties)});"
        end
      end
      
      def process_results(results)
        results['rows'].map do |row|
          klass.json_create row['value'].merge(:_id => row['id'])
        end
      end
      
      def view_parameters
        {:include_docs => false}.merge(super)
      end
      
      private
      
      def properties
        options[:properties]
      end
      
      def properties_for_map(properties)
        '{' + properties.map{|p| "#{p}: doc.#{p}"}.join(', ') + '}'
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
couch_potato-0.2.28 lib/couch_potato/view/properties_view_spec.rb
couch_potato-0.2.27 lib/couch_potato/view/properties_view_spec.rb
couch_potato-0.2.26 lib/couch_potato/view/properties_view_spec.rb
couch_potato-0.2.25 lib/couch_potato/view/properties_view_spec.rb
couch_potato-0.2.24 lib/couch_potato/view/properties_view_spec.rb
couch_potato-0.2.23 lib/couch_potato/view/properties_view_spec.rb
couch_potato-0.2.22 lib/couch_potato/view/properties_view_spec.rb
couch_potato-0.2.21 lib/couch_potato/view/properties_view_spec.rb
couch_potato-0.2.20 lib/couch_potato/view/properties_view_spec.rb
couch_potato-0.2.19 lib/couch_potato/view/properties_view_spec.rb