Class: CouchRest::Model::Designs::ViewRow

Inherits:
Hash
  • Object
show all
Defined in:
lib/couchrest/model/designs/view.rb

Overview

A special wrapper class that provides easy access to the key fields in a result row.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Hash

===

Constructor Details

#initialize(hash, model) ⇒ ViewRow

Returns a new instance of ViewRow.



539
540
541
542
# File 'lib/couchrest/model/designs/view.rb', line 539

def initialize(hash, model)
  @model    = model
  replace(hash)
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



538
539
540
# File 'lib/couchrest/model/designs/view.rb', line 538

def model
  @model
end

Instance Method Details

#docObject

Send a request for the linked document either using the “id” field’s value, or the [“value”] used for linked documents.



557
558
559
560
561
# File 'lib/couchrest/model/designs/view.rb', line 557

def doc
  return model.build_from_database(self['doc']) if self['doc']
  doc_id = (value.is_a?(Hash) && value['_id']) ? value['_id'] : self.id
  doc_id ? model.get(doc_id) : nil
end

#idObject



543
544
545
# File 'lib/couchrest/model/designs/view.rb', line 543

def id
  self["id"]
end

#keyObject



546
547
548
# File 'lib/couchrest/model/designs/view.rb', line 546

def key
  self["key"]
end

#raw_docObject



552
553
554
# File 'lib/couchrest/model/designs/view.rb', line 552

def raw_doc
  self['doc']
end

#valueObject



549
550
551
# File 'lib/couchrest/model/designs/view.rb', line 549

def value
  self['value']
end