Class: RelaxDB::View

Inherits:
Object
  • Object
show all
Defined in:
lib/relaxdb/views.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_nameObject (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_docObject



96
97
98
# File 'lib/relaxdb/views.rb', line 96

def design_doc
  @design_doc ||= DesignDocument.get(RelaxDB.dd) 
end

#exists?Boolean

Returns:

  • (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

#saveObject



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