Class: Recliner::View

Inherits:
Object show all
Defined in:
lib/recliner/views/view.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ View

Returns a new instance of View.



7
8
9
10
11
12
13
14
# File 'lib/recliner/views/view.rb', line 7

def initialize(options={})
  if options[:map]
    @map    = Recliner::ViewFunction::Map.new(options[:map])
    @reduce = Recliner::ViewFunction::Reduce.new(options[:reduce]) if options[:reduce]
  else
    @map, @reduce = Recliner::ViewGenerator.new(options).generate
  end
end

Instance Attribute Details

#mapObject (readonly)

Returns the value of attribute map.



5
6
7
# File 'lib/recliner/views/view.rb', line 5

def map
  @map
end

#reduceObject (readonly)

Returns the value of attribute reduce.



5
6
7
# File 'lib/recliner/views/view.rb', line 5

def reduce
  @reduce
end

Class Method Details

.from_couch(hash) ⇒ Object



16
17
18
# File 'lib/recliner/views/view.rb', line 16

def self.from_couch(hash)
  new(:map => hash['map'], :reduce => hash['reduce'])
end

Instance Method Details

#==(other) ⇒ Object



20
21
22
# File 'lib/recliner/views/view.rb', line 20

def ==(other)
  to_couch == other.to_couch
end

#invoke(database, path, *args) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/recliner/views/view.rb', line 24

def invoke(database, path, *args)
  options, couch_options = split_options!(args.extract_options!)
  
  raw = fetch(database, path, args, couch_options)
  
  if options[:raw]
    raw
  else
    instantiate(raw['rows'])
  end
end