Class: Couchbase::DesignDoc

Inherits:
ViewRow
  • Object
show all
Defined in:
lib/couchbase/design_doc.rb

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

Attributes inherited from ViewRow

#data, #doc, #id, #key, #meta, #value

Instance Method Summary collapse

Methods inherited from ViewRow

#[], #[]=, #has_key?, #last?, wrap

Constructor Details

#initialize(bucket, doc) ⇒ DesignDoc

Returns a new instance of DesignDoc.



25
26
27
28
29
30
31
32
33
34
# File 'lib/couchbase/design_doc.rb', line 25

def initialize(bucket, doc)
  @all_views = {}
  @bucket    = bucket
  @name      = doc.name
  @views     = doc.views
  @spatial   = doc.spatial_views
  @doc       = {}
  @views.each   { |view| @all_views[view.name] = "#{@name}/_view/#{view.name}" }
  @spatial.each { |view| @all_views[view.name] = "#{@name}/_spatial/#{view.name}" }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/couchbase/design_doc.rb', line 36

def method_missing(meth, *args)
  if path = @all_views[meth.to_s]
    View.new(@bucket, path, *args)
  else
    super
  end
end

Instance Attribute Details

#spatialArray<View>

The list of spatial views defined or empty array

Returns:

Since:

  • 1.2.1



60
61
62
# File 'lib/couchbase/design_doc.rb', line 60

def spatial
  @spatial
end

#viewsArray<View>

The list of views defined or empty array

Returns:

Since:

  • 1.2.1



53
54
55
# File 'lib/couchbase/design_doc.rb', line 53

def views
  @views
end

Instance Method Details

#has_views?true, false

Check if the document has views defines

Returns:

  • (true, false)

    true if the document have views

See Also:

Since:

  • 1.2.1



69
70
71
# File 'lib/couchbase/design_doc.rb', line 69

def has_views?
  !@views.empty?
end

#inspectObject



73
74
75
76
77
78
79
80
# File 'lib/couchbase/design_doc.rb', line 73

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

#respond_to_missing?(meth, *args) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/couchbase/design_doc.rb', line 44

def respond_to_missing?(meth, *args)
  @all_views[meth.to_s] || super
end