Module: Spacer::Model
Overview
helper methods primarily supporting the management of Ruby objects which are populatable via Hashes.
Since most Facebook API calls accept and return hashes of data (as XML), the Model module allows us to
directly populate a model's attributes given a Hash with matching key names.
Defined Under Namespace
Modules: ClassMethods
Classes: UnboundSessionException
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.included(includer) ⇒ Object
30
31
32
|
# File 'lib/spacer/model.rb', line 30
def self.included(includer)
includer.extend ClassMethods
end
|
Instance Method Details
#initialize(hash = {}) ⇒ Object
102
103
104
|
# File 'lib/spacer/model.rb', line 102
def initialize(hash = {})
populate_from_hash!(hash)
end
|
#populate ⇒ Object
106
107
108
|
# File 'lib/spacer/model.rb', line 106
def populate
raise NotImplementedError, "#{self.class} included me and should have overriden me"
end
|
#populate_from_hash!(hash) ⇒ Object
Set model's attributes via Hash. Keys should map directly to the model's attribute names.
116
117
118
119
120
121
122
123
|
# File 'lib/spacer/model.rb', line 116
def populate_from_hash!(hash)
unless hash.empty?
hash.each do |key, value|
self.__send__("#{key}=", value)
end
@populated = true
end
end
|
#populated? ⇒ Boolean
110
111
112
|
# File 'lib/spacer/model.rb', line 110
def populated?
!@populated.nil?
end
|