11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/couch_view/couch_view.rb', line 11
def couch_view(name=nil, &block)
view_config = CouchView::Config.new self
view_config.instance_eval &block
view_config.base_view_name name if name
base_view_name = view_config.base_view_name
if view_configs[base_view_name]
view_configs[base_view_name].conditions.each do |condition_name, condition_module|
view_config.conditions_config.send condition_name, condition_module
end
view_configs[base_view_name] = view_config
else
view_configs[base_view_name] = view_config
end
view_config.views.each do |view_name, view|
view_by view_name, :map => view[:map], :reduce => view[:reduce]
end
instance_eval <<-METHODS
def map_#{base_view_name}!
generate_view_proxy_for("#{base_view_name}").get!
end
def map_#{base_view_name}
generate_view_proxy_for "#{base_view_name}"
end
def reduce_#{base_view_name}!
generate_view_proxy_for("#{base_view_name}").reduce(true).get!
end
def reduce_#{base_view_name}
generate_view_proxy_for("#{base_view_name}").reduce(true)
end
METHODS
if view_config.reduce == "_count"
instance_eval <<-METHODS
def count_#{base_view_name}!
generate_count_proxy_for("#{base_view_name}").get!
end
def count_#{base_view_name}
generate_count_proxy_for "#{base_view_name}"
end
METHODS
end
end
|