Module: CouchRest::Model::Designs::ClassMethods

Defined in:
lib/couchrest/model/designs.rb

Instance Method Summary collapse

Instance Method Details

#default_per_pageObject

The models number of documents to return by default when performing pagination. Returns 25 unless explicitly overridden via paginates_per



63
64
65
# File 'lib/couchrest/model/designs.rb', line 63

def default_per_page
  @_default_per_page || 25
end

#design(prefix = nil, &block) ⇒ Object

Add views and other design document features to the current model.



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/couchrest/model/designs.rb', line 27

def design(prefix = nil, &block)

  # Store ourselves a copy of this design spec incase any other model inherits.
  (@_design_blocks ||= [ ]) << {:args => [prefix], :block => block}

  mapper = DesignMapper.new(self, prefix)
  mapper.instance_eval(&block) if block_given?

  # Create an 'all' view if no prefix and one has not been defined already
  mapper.view(:all) if prefix.nil? and !mapper.design_doc.has_view?(:all)
end

#design_docsObject



67
68
69
# File 'lib/couchrest/model/designs.rb', line 67

def design_docs
  @_design_docs ||= []
end

#inherited(model) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/couchrest/model/designs.rb', line 39

def inherited(model)
  super

  # Go through our design blocks and re-implement them in the child.
  unless @_design_blocks.nil?
    @_design_blocks.each do |row|
      model.design(*row[:args], &row[:block])
    end
  end
end

#paginates_per(val) ⇒ Object

Override the default page pagination value:

class Person < CouchRest::Model::Base
  paginates_per 10
end


56
57
58
# File 'lib/couchrest/model/designs.rb', line 56

def paginates_per(val)
  @_default_per_page = val
end