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

#modelObject

Returns the value of attribute model.



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

def model
  @model
end

Instance Method Details

#conditionsObject



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

#initialize(model = nil, *properties) ⇒ Object



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

#mapObject



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