Class: CouchPotato::View::BaseViewSpec

Inherits:
Object
  • Object
show all
Defined in:
lib/couch_potato/view/base_view_spec.rb

Direct Known Subclasses

CustomViewSpec, ModelViewSpec, RawViewSpec

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, view_name, options, view_parameters) ⇒ BaseViewSpec

Returns a new instance of BaseViewSpec.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/couch_potato/view/base_view_spec.rb', line 9

def initialize(klass, view_name, options, view_parameters)
  normalized_view_parameters = normalize_view_parameters view_parameters

  @list_name = normalized_view_parameters.delete(:list) || options[:list]
  @language = options[:language] || Config.default_language

  assert_valid_view_parameters normalized_view_parameters
  assert_sorted_false_not_with_startkey_endkey normalized_view_parameters
  @klass = klass
  @options = options
  @view_name = compute_view_name(view_name,
    options.key?(:digest_view_name) ? options[:digest_view_name] : Config.digest_view_names)
  @design_document = translate_to_design_doc_name(klass.to_s, @view_name, @list_name)
  @list_params = normalized_view_parameters.delete :list_params

  @list_function = klass.lists(@list_name) if @list_name
  @view_parameters = {}
  [:group, :include_docs, :descending, :group_level, :limit].each do |key|
    @view_parameters[key] = options[key] if options.include?(key)
  end
  @view_parameters.merge!(normalized_view_parameters)
  @view_parameters.merge!(@list_params) if @list_params
end

Instance Attribute Details

#design_documentObject (readonly)

Returns the value of attribute design_document.



4
5
6
# File 'lib/couch_potato/view/base_view_spec.rb', line 4

def design_document
  @design_document
end

#languageObject (readonly)

Returns the value of attribute language.



4
5
6
# File 'lib/couch_potato/view/base_view_spec.rb', line 4

def language
  @language
end

#libObject (readonly)

Returns the value of attribute lib.



4
5
6
# File 'lib/couch_potato/view/base_view_spec.rb', line 4

def lib
  @lib
end

#list_functionObject (readonly)

Returns the value of attribute list_function.



4
5
6
# File 'lib/couch_potato/view/base_view_spec.rb', line 4

def list_function
  @list_function
end

#list_nameObject (readonly)

Returns the value of attribute list_name.



4
5
6
# File 'lib/couch_potato/view/base_view_spec.rb', line 4

def list_name
  @list_name
end

#reduce_functionObject (readonly)

Returns the value of attribute reduce_function.



4
5
6
# File 'lib/couch_potato/view/base_view_spec.rb', line 4

def reduce_function
  @reduce_function
end

#view_nameObject (readonly)

Returns the value of attribute view_name.



4
5
6
# File 'lib/couch_potato/view/base_view_spec.rb', line 4

def view_name
  @view_name
end

#view_parametersObject

Returns the value of attribute view_parameters.



5
6
7
# File 'lib/couch_potato/view/base_view_spec.rb', line 5

def view_parameters
  @view_parameters
end

Instance Method Details

#process_results(results) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/couch_potato/view/base_view_spec.rb', line 33

def process_results(results)
  if (filter = options[:results_filter])
    filter.call results
  else
    results
  end
end