Class: CouchDB::Design::View
- Inherits:
-
Object
- Object
- CouchDB::Design::View
- 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
-
#design ⇒ Object
Returns the value of attribute design.
-
#map ⇒ Object
Returns the value of attribute map.
-
#name ⇒ Object
Returns the value of attribute name.
-
#reduce ⇒ Object
Returns the value of attribute reduce.
Instance Method Summary collapse
- #collection(options = { }) ⇒ Object
-
#initialize(design, name, map = nil, reduce = nil) ⇒ View
constructor
A new instance of View.
- #to_hash ⇒ Object
- #url ⇒ Object
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
#design ⇒ Object
Returns the value of attribute design.
11 12 13 |
# File 'lib/couchdb/design/view.rb', line 11 def design @design end |
#map ⇒ Object
Returns the value of attribute map.
13 14 15 |
# File 'lib/couchdb/design/view.rb', line 13 def map @map end |
#name ⇒ Object
Returns the value of attribute name.
12 13 14 |
# File 'lib/couchdb/design/view.rb', line 12 def name @name end |
#reduce ⇒ Object
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( = { }) @design ? Collection.new(@design.database, url, ) : nil end |
#to_hash ⇒ Object
21 22 23 |
# File 'lib/couchdb/design/view.rb', line 21 def to_hash { @name => { "map" => @map, "reduce" => @reduce } } end |
#url ⇒ Object
29 30 31 |
# File 'lib/couchdb/design/view.rb', line 29 def url @design ? "#{@design.url}/_view/#{@name}" : nil end |