Sha256: 9f7e3fa59894ddf5dfc1d58cf5a42b8586251ddf1b7bfda74651a6b0bfe01a75

Contents?: true

Size: 724 Bytes

Versions: 12

Compression:

Stored size: 724 Bytes

Contents

module CouchPotato
  module View
    module ViewParameters
      module_function

      def normalize_view_parameters(params)
        hash = wrap_in_hash params
        remove_nil_stale(replace_range_key(hash))
      end

      def remove_nil_stale(params)
        params.reject{|name, value| name.to_s == 'stale' && value.nil?}
      end

      def wrap_in_hash(params)
        if params.is_a?(Hash)
          params
        else
          {:key => params}
        end
      end

      def replace_range_key(params)
        if((key = params[:key]).is_a?(Range))
          params.delete :key
          params[:startkey] = key.first
          params[:endkey] = key.last
        end
        params
      end

    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
couch_potato-1.18.0 lib/couch_potato/view/view_parameters.rb
couch_potato-1.17.0 lib/couch_potato/view/view_parameters.rb
couch_potato-1.16.0 lib/couch_potato/view/view_parameters.rb
couch_potato-1.15.0 lib/couch_potato/view/view_parameters.rb
couch_potato-1.14.0 lib/couch_potato/view/view_parameters.rb
couch_potato-1.13.0 lib/couch_potato/view/view_parameters.rb
couch_potato-1.12.1 lib/couch_potato/view/view_parameters.rb
couch_potato-1.12.0 lib/couch_potato/view/view_parameters.rb
couch_potato-1.11.0 lib/couch_potato/view/view_parameters.rb
couch_potato-1.10.1 lib/couch_potato/view/view_parameters.rb
couch_potato-1.10.0 lib/couch_potato/view/view_parameters.rb
couch_potato-1.9.0 lib/couch_potato/view/view_parameters.rb