Class: CouchView::Count::Proxy

Inherits:
Proxy
  • Object
show all
Defined in:
lib/couch_view/count_proxy.rb

Instance Attribute Summary

Attributes inherited from Proxy

#_map, #_model, #_query_options

Instance Method Summary collapse

Methods inherited from Proxy

#_options, #initialize, #method_missing

Constructor Details

This class inherits a constructor from CouchView::Proxy

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class CouchView::Proxy

Instance Method Details

#each(&block) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/couch_view/count_proxy.rb', line 4

def each(&block)
  raise "You can't call 'each' on a count proxy that doesn't set 'group' to 'true'." unless _options[:group]
  results = self.get!['rows']
  results.each do |row|
    block.call row['key'], row['value']
  end
end

#get!Object



12
13
14
15
16
17
18
19
# File 'lib/couch_view/count_proxy.rb', line 12

def get!
  if _options[:group]
    super
  else
    result = super['rows'].first
    result ? result['value'] : 0
  end
end