Class: CouchRest::Mixins::ClassProxy::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/couchrest/mixins/class_proxy.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(klass, database) ⇒ Proxy

Returns a new instance of Proxy.



34
35
36
37
# File 'lib/couchrest/mixins/class_proxy.rb', line 34

def initialize(klass, database)
  @klass = klass
  @database = database
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



47
48
49
50
51
52
53
54
# File 'lib/couchrest/mixins/class_proxy.rb', line 47

def method_missing(m, *args, &block)
  if has_view?(m)
    query = args.shift || {}
    view(m, query, *args, &block)
  else
    super
  end
end

Instance Method Details

#all(opts = {}, &block) ⇒ Object

Mixins::DocumentQueries



58
59
60
61
62
# File 'lib/couchrest/mixins/class_proxy.rb', line 58

def all(opts = {}, &block)
  docs = @klass.all({:database => @database}.merge(opts), &block)
  docs.each { |doc| doc.database = @database if doc.respond_to?(:database) } if docs
  docs
end

#all_design_doc_versionsObject

DEPRICATED



108
109
110
# File 'lib/couchrest/mixins/class_proxy.rb', line 108

def all_design_doc_versions
  @klass.all_design_doc_versions(@database)
end

#count(opts = {}, &block) ⇒ Object



64
65
66
# File 'lib/couchrest/mixins/class_proxy.rb', line 64

def count(opts = {}, &block)
  @klass.all({:database => @database, :raw => true, :limit => 0}.merge(opts), &block)['total_rows']
end

#design_docObject

Mixins::DesignDoc



95
96
97
# File 'lib/couchrest/mixins/class_proxy.rb', line 95

def design_doc
  @klass.design_doc
end

#first(opts = {}) ⇒ Object



68
69
70
71
72
# File 'lib/couchrest/mixins/class_proxy.rb', line 68

def first(opts = {})
  doc = @klass.first({:database => @database}.merge(opts))
  doc.database = @database if doc && doc.respond_to?(:database)
  doc
end

#get(id) ⇒ Object



74
75
76
77
78
# File 'lib/couchrest/mixins/class_proxy.rb', line 74

def get(id)
  doc = @klass.get(id, @database)
  doc.database = @database if doc && doc.respond_to?(:database)
  doc
end

#has_view?(view) ⇒ Boolean

Mixins::Views

Returns:

  • (Boolean)


82
83
84
# File 'lib/couchrest/mixins/class_proxy.rb', line 82

def has_view?(view)
  @klass.has_view?(view)
end

#new(*args) ⇒ Object

ExtendedDocument



41
42
43
44
45
# File 'lib/couchrest/mixins/class_proxy.rb', line 41

def new(*args)
  doc = @klass.new(*args)
  doc.database = @database
  doc
end

#refresh_design_docObject



99
100
101
# File 'lib/couchrest/mixins/class_proxy.rb', line 99

def refresh_design_doc
  @klass.refresh_design_doc(@database)
end

#save_design_docObject



103
104
105
# File 'lib/couchrest/mixins/class_proxy.rb', line 103

def save_design_doc
  @klass.save_design_doc(@database)
end

#stored_design_docObject Also known as: model_design_doc



112
113
114
# File 'lib/couchrest/mixins/class_proxy.rb', line 112

def stored_design_doc
  @klass.stored_design_doc(@database)
end

#view(name, query = {}, &block) ⇒ Object



86
87
88
89
90
# File 'lib/couchrest/mixins/class_proxy.rb', line 86

def view(name, query={}, &block)
  docs = @klass.view(name, {:database => @database}.merge(query), &block)
  docs.each { |doc| doc.database = @database if doc.respond_to?(:database) } if docs
  docs
end