Class: Couchbase::DesignDoc
- Defined in:
- lib/couchbase/view_row.rb
Overview
This class encapsulates information about design docs
It is subclass of ViewRow, but also gives access to view creation through method_missing
Constant Summary
Constants included from Constants
Constants::S_CAS, Constants::S_DOC, Constants::S_FLAGS, Constants::S_ID, Constants::S_IS_LAST, Constants::S_KEY, Constants::S_META, Constants::S_VALUE
Instance Attribute Summary collapse
-
#spatial ⇒ Array<View>
The list of spatial views defined or empty array.
-
#views ⇒ Array<View>
The list of views defined or empty array.
Attributes inherited from ViewRow
#data, #doc, #id, #key, #meta, #value
Instance Method Summary collapse
-
#has_views? ⇒ true, false
Check if the document has views defines.
-
#initialize(bucket, data) ⇒ DesignDoc
constructor
Initialize the design doc instance.
- #inspect ⇒ Object
- #method(meth, *args) ⇒ Object
- #method_missing(meth, *args) ⇒ Object
- #respond_to?(meth, *args) ⇒ Boolean
Methods inherited from ViewRow
#[], #[]=, #has_key?, #last?, wrap
Constructor Details
#initialize(bucket, data) ⇒ DesignDoc
Initialize the design doc instance
It takes reference to the bucket, data hash. It will define view methods if the data object looks like design document.
204 205 206 207 208 209 210 211 |
# File 'lib/couchbase/view_row.rb', line 204 def initialize(bucket, data) super @all_views = {} @views = @doc.has_key?('views') ? @doc['views'].keys : [] @spatial = @doc.has_key?('spatial') ? @doc['spatial'].keys : [] @views.each{|name| @all_views[name] = "#{@id}/_view/#{name}"} @spatial.each{|name| @all_views[name] = "#{@id}/_spatial/#{name}"} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args) ⇒ Object
213 214 215 216 217 218 219 |
# File 'lib/couchbase/view_row.rb', line 213 def method_missing(meth, *args) if path = @all_views[meth.to_s] View.new(@bucket, path, *args) else super end end |
Instance Attribute Details
#spatial ⇒ Array<View>
The list of spatial views defined or empty array
249 250 251 |
# File 'lib/couchbase/view_row.rb', line 249 def spatial @spatial end |
#views ⇒ Array<View>
The list of views defined or empty array
242 243 244 |
# File 'lib/couchbase/view_row.rb', line 242 def views @views end |
Instance Method Details
#has_views? ⇒ true, false
Check if the document has views defines
258 259 260 |
# File 'lib/couchbase/view_row.rb', line 258 def has_views? !@views.empty? end |
#inspect ⇒ Object
262 263 264 265 266 267 268 269 |
# File 'lib/couchbase/view_row.rb', line 262 def inspect desc = "#<#{self.class.name}:#{self.object_id}" [:@id, :@views, :@spatial].each do |iv| desc << " #{iv}=#{instance_variable_get(iv).inspect}" end desc << ">" desc end |
#method(meth, *args) ⇒ Object
229 230 231 232 233 234 235 |
# File 'lib/couchbase/view_row.rb', line 229 def method(meth, *args) if path = @all_views[meth.to_s] lambda{|*p| View.new(@bucket, path, *p)} else super end end |
#respond_to?(meth, *args) ⇒ Boolean
221 222 223 224 225 226 227 |
# File 'lib/couchbase/view_row.rb', line 221 def respond_to?(meth, *args) if @all_views[meth.to_s] true else super end end |