Module: CouchView::Map

Included in:
Property
Defined in:
lib/couch_view/map.rb,
lib/couch_view/map_property.rb

Defined Under Namespace

Classes: Property

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Instance Attribute Details

- (Object) model

Returns the value of attribute model



3
4
5
# File 'lib/couch_view/map.rb', line 3

def model
  @model
end

Instance Method Details

- (Object) conditions



27
28
29
30
31
32
33
# File 'lib/couch_view/map.rb', line 27

def conditions
  if @model
    "doc['couchrest-type'] == '#{@model}'" 
  else
    "true"
  end
end

- (Map) initialize(model = nil, *properties)

A new instance of Map

Returns:

  • (Map)

    a new instance of Map



5
6
7
8
# File 'lib/couch_view/map.rb', line 5

def initialize(model=nil, *properties)
  @model = model
  @properties = properties.empty? ? ["_id"] : properties 
end

- (Object) map



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/couch_view/map.rb', line 10

def map
  if conditions != "true"
    "
      function(doc){
        if (#{conditions})
          emit(#{key}, null)
      }
    "
  else
    "
      function(doc){
        emit(#{key}, null)
      }
    "
  end
end