Module Facebooker::Model
In: lib/facebooker/model.rb

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.

Methods

Classes and Modules

Module Facebooker::Model::ClassMethods
Class Facebooker::Model::UnboundSessionException

Public Class methods

[Source]

# File lib/facebooker/model.rb, line 8
    def self.included(includer)
      includer.extend ClassMethods
      includer.__send__(:attr_writer, :session)
      includer.__send__(:attr_reader, :anonymous_fields)
    end

[Source]

# File lib/facebooker/model.rb, line 110
    def initialize(hash = {})
      populate_from_hash!(hash)
    end

Public Instance methods

This gets populated from FQL queries.

[Source]

# File lib/facebooker/model.rb, line 106
    def anon=(value)
      @anonymous_fields = value
    end

[Source]

# File lib/facebooker/model.rb, line 114
    def populate
      raise NotImplementedError, "#{self.class} included me and should have overriden me"
    end

Set model‘s attributes via Hash. Keys should map directly to the model‘s attribute names.

[Source]

# File lib/facebooker/model.rb, line 124
    def populate_from_hash!(hash)
      unless hash.nil? || hash.empty?
        hash.each do |key, value|
          set_attr_method = "#{key}="
          unless value.nil?
            if respond_to?(set_attr_method)
              self.__send__(set_attr_method, value) 
            else
              Facebooker::Logging.log_info("**Warning**, Attempt to set non-attribute: #{key}",hash)
            end
          end
        end
        @populated = true
      end      
    end

[Source]

# File lib/facebooker/model.rb, line 118
    def populated?
      @populated
    end

Centralized, error-checked place for a model to get the session to which it is bound. Any Facebook API queries require a Session instance.

[Source]

# File lib/facebooker/model.rb, line 100
    def session
      @session || (raise UnboundSessionException, "Must bind this object to a Facebook session before querying")
    end

[Validate]