Class: RelaxDB::View
- Inherits:
-
Object
- Object
- RelaxDB::View
- Defined in:
- lib/relaxdb/views.rb
Instance Attribute Summary collapse
-
#view_name ⇒ Object
readonly
Returns the value of attribute view_name.
Instance Method Summary collapse
- #design_doc ⇒ Object
- #exists? ⇒ Boolean
-
#initialize(view_name, map_func, reduce_func = nil) ⇒ View
constructor
A new instance of View.
- #save ⇒ Object
Constructor Details
#initialize(view_name, map_func, reduce_func = nil) ⇒ View
Returns a new instance of View.
90 91 92 93 94 |
# File 'lib/relaxdb/views.rb', line 90 def initialize view_name, map_func, reduce_func = nil @view_name = view_name @map_func = map_func @reduce_func = reduce_func end |
Instance Attribute Details
#view_name ⇒ Object (readonly)
Returns the value of attribute view_name.
88 89 90 |
# File 'lib/relaxdb/views.rb', line 88 def view_name @view_name end |
Instance Method Details
#design_doc ⇒ Object
96 97 98 |
# File 'lib/relaxdb/views.rb', line 96 def design_doc @design_doc ||= DesignDocument.get(RelaxDB.dd) end |
#exists? ⇒ Boolean
107 108 109 110 |
# File 'lib/relaxdb/views.rb', line 107 def exists? dd = design_doc dd.data["views"] && dd.data["views"][@view_name] end |
#save ⇒ Object
100 101 102 103 104 105 |
# File 'lib/relaxdb/views.rb', line 100 def save dd = design_doc dd.add_map_view(@view_name, @map_func) dd.add_reduce_view(@view_name, @reduce_func) if @reduce_func dd.save end |