Module: Exegesis::Model::InstanceMethods

Defined in:
lib/exegesis/model.rb

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ Object

retrieves the attribte



106
107
108
# File 'lib/exegesis/model.rb', line 106

def [] key
  @attributes[key]
end

#[]=(key, value) ⇒ Object

directly sets the attribute, avoiding any writers or lack thereof.



111
112
113
# File 'lib/exegesis/model.rb', line 111

def []= key, value
  @attributes[key] = value
end

#databaseObject

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.



118
119
120
# File 'lib/exegesis/model.rb', line 118

def database
  parent && parent.database
end

#initialize(hash = {}) ⇒ Object



86
87
88
89
90
# File 'lib/exegesis/model.rb', line 86

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



93
94
95
# File 'lib/exegesis/model.rb', line 93

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



99
100
101
102
103
# File 'lib/exegesis/model.rb', line 99

def update_attributes hash={}
  hash.each do |key, value| 
    self.send("#{key}=", value)
  end
end