Class: CouchModel::Row
- Inherits:
-
Object
- Object
- CouchModel::Row
- Defined in:
- lib/couch_model/row.rb
Overview
The Row class acts as a wrapper for a CouchDB view result row.
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(attributes = { }) ⇒ Row
constructor
A new instance of Row.
- #instanciate_model(model_class_name) ⇒ Object
- #model ⇒ Object
Constructor Details
#initialize(attributes = { }) ⇒ Row
Returns a new instance of Row.
13 14 15 |
# File 'lib/couch_model/row.rb', line 13 def initialize(attributes = { }) @id, @key, @value, @document = attributes.values_at "id", "key", "value", "doc" end |
Instance Attribute Details
#document ⇒ Object (readonly)
Returns the value of attribute document.
11 12 13 |
# File 'lib/couch_model/row.rb', line 11 def document @document end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
8 9 10 |
# File 'lib/couch_model/row.rb', line 8 def id @id end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
9 10 11 |
# File 'lib/couch_model/row.rb', line 9 def key @key end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
10 11 12 |
# File 'lib/couch_model/row.rb', line 10 def value @value end |
Instance Method Details
#instanciate_model(model_class_name) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/couch_model/row.rb', line 25 def instanciate_model(model_class_name) model_class = Object.const_get model_class_name model = model_class.new model.instance_variable_set :@attributes, @document model end |
#model ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/couch_model/row.rb', line 17 def model return nil unless @document && @document.has_key?(Configuration::CLASS_KEY) model_class_name = document[Configuration::CLASS_KEY] raise StandardError, "no class defined with name [#{model_class_name}]" unless Object.const_defined?(model_class_name) instanciate_model model_class_name end |