class Joey::Model

Attributes

client[RW]
errors[RW]

Public Class Methods

define_properties(*args) click to toggle source
# File lib/joey/model.rb, line 15
def self.define_properties(*args)
  args.each do |arg|
    property arg
  end
end
find(id, client = nil, args = {}) click to toggle source

Get some information of a node in the Graph. Joey::Post.find(‘19440638720_133872233324170’, client, :fields => ‘name,link,description,comments’)

# File lib/joey/model.rb, line 76
def self.find(id, client = nil, args = {})
  client.get_and_map(id, self, args)
end
get_all(ids, client = nil, args = {}) click to toggle source
# File lib/joey/model.rb, line 80
def self.get_all(ids, client = nil, args = {})
  client.get_all_and_map(ids, self, args)
end
has_association(name, klass) click to toggle source
# File lib/joey/model.rb, line 61
def self.has_association(name, klass)
  define_method(name) do
    if (ret = instance_variable_get("@#{name}")).nil?
      ret = client.get_and_map("#{id}/#{name}", klass)
      instance_variable_set("@#{name}", ret)
    end
    return ret
  end
  
  #add_creation_method(name, klass)
end
hash_populating_accessor(method_name, *klass) click to toggle source
# File lib/joey/model.rb, line 25
def self.hash_populating_accessor(method_name, *klass)
  define_method "#{method_name}=" do |hash|
    instance_variable_set("@#{method_name}", client.map_data(hash, klass))
  end

  define_method "#{method_name}" do
    instance_variable_get "@#{method_name}"
  end
  #add_creation_method(method_name,klass)
end
hash_populating_association(method_name, *klass) click to toggle source
TODO: Look out for creation of nodes in the Graph
me = koala_client.me
me.friends_create(args)

def self.add_creation_method(name, klass) define_method “#{name}_create” do |arg| params = arg.nil? ? {} : arg.post_params klass_to_send = arg.nil? ? nil : klass client.post(“#{id}/#{name}”, klass_to_send, params) end end

# File lib/joey/model.rb, line 47
def self.hash_populating_association(method_name, *klass)
  define_method "#{method_name}=" do |hash|
    instance_variable_set("@#{method_name}", client.map_data(hash, klass))
  end

  define_method(method_name) do
    if (ret = instance_variable_get("@#{method_name}")).nil?
      ret = client.get_and_map("#{id}/#{method_name}", klass)
      instance_variable_set("@#{method_name}", ret)
    end
    return ret
  end
end
new(hash = {}, client = nil) click to toggle source
Calls superclass method
# File lib/joey/model.rb, line 8
def initialize(hash = {}, client = nil)
  self.client = client
  self.errors = []

  super(hash || {})
end
recognize?(data) click to toggle source
# File lib/joey/model.rb, line 21
def self.recognize?(data)
  true
end