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

- (Proxy) initialize(klass, database)



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

- (Object) method_missing(m, *args, &block)



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

- (Object) all(opts = {}, &block)

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

- (Object) all_design_doc_versions



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

def all_design_doc_versions
  @klass.all_design_doc_versions(@database)
end

- (Object) cleanup_design_docs!



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

def cleanup_design_docs!
  @klass.cleanup_design_docs!(@database)
end

- (Object) count(opts = {}, &block)



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

- (Object) design_doc

Mixins::DesignDoc



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

def design_doc
  @klass.design_doc
end

- (Object) design_doc_fresh



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

def design_doc_fresh
  @klass.design_doc_fresh
end

- (Object) first(opts = {})



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

- (Object) get(id)



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

- (Boolean) has_view?(view)

Mixins::Views



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

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

- (Object) model_design_doc



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

def model_design_doc
  @klass.model_design_doc(@database)
end

- (Object) new(*args)

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

- (Object) refresh_design_doc



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

def refresh_design_doc
  @klass.refresh_design_doc_on(@database)
end

- (Object) save_design_doc



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

def save_design_doc
  @klass.save_design_doc_on(@database)
end

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



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