Class: Couchbase::DesignDoc

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bucket, doc) ⇒ DesignDoc

Returns a new instance of DesignDoc.



4
5
6
7
8
9
10
11
12
# File 'lib/couchbase/design_doc.rb', line 4

def initialize(bucket, doc)
  @all_views = {}
  @bucket    = bucket
  @name      = doc.name
  @views     = doc.views
  @spatial   = doc.spatial_views
  @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



14
15
16
17
18
19
20
# File 'lib/couchbase/design_doc.rb', line 14

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



38
39
40
# File 'lib/couchbase/design_doc.rb', line 38

def spatial
  @spatial
end

#viewsArray<View>

The list of views defined or empty array

Returns:

Since:

  • 1.2.1



31
32
33
# File 'lib/couchbase/design_doc.rb', line 31

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



47
48
49
# File 'lib/couchbase/design_doc.rb', line 47

def has_views?
  !@views.empty?
end

#inspectObject



51
52
53
54
55
56
57
58
# File 'lib/couchbase/design_doc.rb', line 51

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)


22
23
24
# File 'lib/couchbase/design_doc.rb', line 22

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