Class: RelaxDB::DesignDocument
- Inherits:
-
Object
- Object
- RelaxDB::DesignDocument
- Defined in:
- lib/relaxdb/design_doc.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Class Method Summary collapse
Instance Method Summary collapse
- #add_map_view(view_name, function) ⇒ Object
- #add_reduce_view(view_name, function) ⇒ Object
- #add_validation_func(function) ⇒ Object
- #add_view(view_name, type, function) ⇒ Object
- #destroy! ⇒ Object
-
#initialize(design_doc_name, data) ⇒ DesignDocument
constructor
A new instance of DesignDocument.
- #save ⇒ Object
Constructor Details
#initialize(design_doc_name, data) ⇒ DesignDocument
Returns a new instance of DesignDocument.
7 8 9 10 |
# File 'lib/relaxdb/design_doc.rb', line 7 def initialize(design_doc_name, data) @design_doc_name = design_doc_name @data = data end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
5 6 7 |
# File 'lib/relaxdb/design_doc.rb', line 5 def data @data end |
Class Method Details
.get(design_doc_name) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/relaxdb/design_doc.rb', line 39 def self.get(design_doc_name) begin database = RelaxDB.db resp = database.get("_design/#{design_doc_name}") DesignDocument.new(design_doc_name, JSON.parse(resp.body)) rescue HTTP_404 DesignDocument.new(design_doc_name, {"_id" => "_design/#{design_doc_name}"} ) end end |
Instance Method Details
#add_map_view(view_name, function) ⇒ Object
12 13 14 |
# File 'lib/relaxdb/design_doc.rb', line 12 def add_map_view(view_name, function) add_view(view_name, "map", function) end |
#add_reduce_view(view_name, function) ⇒ Object
16 17 18 |
# File 'lib/relaxdb/design_doc.rb', line 16 def add_reduce_view(view_name, function) add_view(view_name, "reduce", function) end |
#add_validation_func(function) ⇒ Object
20 21 22 23 |
# File 'lib/relaxdb/design_doc.rb', line 20 def add_validation_func(function) @data["validate_doc_update"] = function self end |
#add_view(view_name, type, function) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/relaxdb/design_doc.rb', line 25 def add_view(view_name, type, function) @data["views"] ||= {} @data["views"][view_name] ||= {} @data["views"][view_name][type] = function self end |