Module: Exegesis::Model::InstanceMethods
- Defined in:
- lib/exegesis/model.rb
Instance Method Summary collapse
-
#[](key) ⇒ Object
retrieves the attribte.
-
#[]=(key, value) ⇒ Object
directly sets the attribute, avoiding any writers or lack thereof.
-
#database ⇒ Object
returns the instance’s database, or its parents database if it has a parent.
- #initialize(hash = {}) ⇒ Object
-
#update(hash = {}) ⇒ Object
works like Hash#update on the attributes hash, bypassing any writers.
-
#update_attributes(hash = {}) ⇒ Object
update the attributes in the model using writers.
Instance Method Details
#[](key) ⇒ Object
retrieves the attribte
123 124 125 |
# File 'lib/exegesis/model.rb', line 123 def [] key @attributes[key] end |
#[]=(key, value) ⇒ Object
directly sets the attribute, avoiding any writers or lack thereof.
128 129 130 |
# File 'lib/exegesis/model.rb', line 128 def []= key, value @attributes[key] = value end |
#database ⇒ Object
returns the instance’s database, or its parents database if it has a parent. If neither, returns false. This is overwritten in classes including Exegesis::Document by an attr_accessor.
135 136 137 |
# File 'lib/exegesis/model.rb', line 135 def database parent && parent.database end |
#initialize(hash = {}) ⇒ Object
102 103 104 105 106 |
# File 'lib/exegesis/model.rb', line 102 def initialize hash={} apply_default hash.each {|key, value| @attributes[key.to_s] = value } @attributes['class'] = self.class.name end |
#update(hash = {}) ⇒ Object
works like Hash#update on the attributes hash, bypassing any writers
109 110 111 |
# File 'lib/exegesis/model.rb', line 109 def update hash={} hash.each {|key, value| @attributes[key.to_s] = value } end |
#update_attributes(hash = {}) ⇒ Object
update the attributes in the model using writers. If no writer is defined for a given key it will raise NoMethodError
115 116 117 118 119 120 |
# File 'lib/exegesis/model.rb', line 115 def update_attributes hash={} hash.delete('class') hash.each do |key, value| self.send("#{key}=", value) end end |