Module: Exegesis::Model::InstanceMethods

Defined in:
lib/exegesis/model.rb

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ Object

retrieves the attribte



89
90
91
# File 'lib/exegesis/model.rb', line 89

def [] key
  @attributes[key]
end

#[]=(key, value) ⇒ Object

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



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

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.



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

def database
  parent && parent.database
end

#initialize(hash = {}) ⇒ Object



69
70
71
72
73
# File 'lib/exegesis/model.rb', line 69

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



76
77
78
# File 'lib/exegesis/model.rb', line 76

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



82
83
84
85
86
# File 'lib/exegesis/model.rb', line 82

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