Class: CouchDB::Design::View

Inherits:
Object
  • Object
show all
Defined in:
lib/couchdb/design/view.rb

Overview

The View class acts as a wrapper for the views that are in the CouchDB design document. It also provides methods to generate simple view javascript functions.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(design, name, map = nil, reduce = nil) ⇒ View

Returns a new instance of View.



16
17
18
19
# File 'lib/couchdb/design/view.rb', line 16

def initialize(design, name, map = nil, reduce = nil)
  @design, @name, @map, @reduce = design, name, map, reduce
  @design.views << self
end

Instance Attribute Details

#designObject

Returns the value of attribute design.



11
12
13
# File 'lib/couchdb/design/view.rb', line 11

def design
  @design
end

#mapObject

Returns the value of attribute map.



13
14
15
# File 'lib/couchdb/design/view.rb', line 13

def map
  @map
end

#nameObject

Returns the value of attribute name.



12
13
14
# File 'lib/couchdb/design/view.rb', line 12

def name
  @name
end

#reduceObject

Returns the value of attribute reduce.



14
15
16
# File 'lib/couchdb/design/view.rb', line 14

def reduce
  @reduce
end

Instance Method Details

#collection(options = { }) ⇒ Object



25
26
27
# File 'lib/couchdb/design/view.rb', line 25

def collection(options = { })
  @design ? Collection.new(@design.database, url, options) : nil
end

#to_hashObject



21
22
23
# File 'lib/couchdb/design/view.rb', line 21

def to_hash
  { @name => { "map" => @map, "reduce" => @reduce } }
end

#urlObject



29
30
31
# File 'lib/couchdb/design/view.rb', line 29

def url
  @design ? "#{@design.url}/_view/#{@name}" : nil
end