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



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



92
93
94
# File 'lib/couchrest/mixins/class_proxy.rb', line 92

def all_design_doc_versions
  @klass.all_design_doc_versions(@database)
end

#cleanup_design_docs!Object



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

def cleanup_design_docs!
  @klass.cleanup_design_docs!(@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



106
107
108
# File 'lib/couchrest/mixins/class_proxy.rb', line 106

def design_doc
  @klass.design_doc
end

#design_doc_freshObject



110
111
112
# File 'lib/couchrest/mixins/class_proxy.rb', line 110

def design_doc_fresh
  @klass.design_doc_fresh
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



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

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

#model_design_docObject



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

def model_design_doc
  @klass.model_design_doc(@database)
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



114
115
116
# File 'lib/couchrest/mixins/class_proxy.rb', line 114

def refresh_design_doc
  @klass.refresh_design_doc_on(@database)
end

#save_design_docObject



118
119
120
# File 'lib/couchrest/mixins/class_proxy.rb', line 118

def save_design_doc
  @klass.save_design_doc_on(@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