Sha256: 53c650f3a8a36cb416f0d78f0289dfc4da2411dc7f0db780b3b79b605566d0c6

Contents?: true

Size: 1.08 KB

Versions: 15

Compression:

Stored size: 1.08 KB

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
        "function(doc) {
           if(doc.ruby_class && doc.ruby_class == '#{@klass.name}') {
             emit(#{formatted_key(key)}, #{properties_for_map(properties)});
           }
         }"
      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

15 entries across 15 versions & 4 rubygems

Version Path
andrewtimberlake-couch_potato-0.2.8.1 lib/couch_potato/view/properties_view_spec.rb
andrewtimberlake-couch_potato-0.2.8.2 lib/couch_potato/view/properties_view_spec.rb
andrewtimberlake-couch_potato-0.2.8.3 lib/couch_potato/view/properties_view_spec.rb
andrewtimberlake-couch_potato-0.2.8.4 lib/couch_potato/view/properties_view_spec.rb
langalex-couch_potato-0.2.11 lib/couch_potato/view/properties_view_spec.rb
langalex-couch_potato-0.2.12 lib/couch_potato/view/properties_view_spec.rb
langalex-couch_potato-0.2.5 lib/couch_potato/view/properties_view_spec.rb
langalex-couch_potato-0.2.6 lib/couch_potato/view/properties_view_spec.rb
langalex-couch_potato-0.2.7 lib/couch_potato/view/properties_view_spec.rb
langalex-couch_potato-0.2.8 lib/couch_potato/view/properties_view_spec.rb
langalex-couch_potato-0.2.9 lib/couch_potato/view/properties_view_spec.rb
thefool808-couch_potato-0.2.7 lib/couch_potato/view/properties_view_spec.rb
couch_potato-0.2.14 lib/couch_potato/view/properties_view_spec.rb
couch_potato-0.2.13 lib/couch_potato/view/properties_view_spec.rb
couch_potato-0.2.12 lib/couch_potato/view/properties_view_spec.rb