Module: Engrel::Mixin::InstanceMethods

Defined in:
lib/engrel/mixin.rb

Instance Method Summary collapse

Instance Method Details

#instantiate_object!(key) ⇒ Object

Make sure we can make an object before we go trying to save the “association”.



23
24
25
26
27
28
29
30
31
# File 'lib/engrel/mixin.rb', line 23

def instantiate_object!(key)
  key = key.to_sym
  id_key, type_key = "#{key}_id".to_sym, "#{key}_type".to_sym
  return true if !self[key].blank? && !(self[key][:id].blank? rescue true)
  class_name = self[type_key] || (self.send(key).class.to_s rescue "Page")
  raise "Could not determine class name for #{key} (#{self.to_s})" if class_name.blank?
  newid = self[id_key] || (self[key][:id] rescue nil)
  class_name.constantize.spec(newid) rescue raise("Unable to instantiate #{class_name} object with ID #{newid || '[unavailable]'}")
end

#set_fetcher!(newfetcher = nil) ⇒ Object

This is very specific to Facebook–it stores a reference to the object through whose access token the intermediate object was initially fetched.



14
15
16
17
18
19
20
# File 'lib/engrel/mixin.rb', line 14

def set_fetcher!(newfetcher = nil)
  write_attribute(:fetcher_id, newfetcher[:id])
  write_attribute(:fetcher_type, newfetcher.class.to_s)
  save(:validate => false)
  reload
  fetcher
end