Class: Joey::Model

Inherits:
Hashie::Dash
  • Object
show all
Defined in:
lib/joey/model.rb

Defined Under Namespace

Classes: KoalaClientRequiredError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}, client = nil) ⇒ Model

Returns a new instance of Model.



8
9
10
11
12
13
# File 'lib/joey/model.rb', line 8

def initialize(hash = {}, client = nil)
  self.client = client
  self.errors = []

  super(hash || {})
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



6
7
8
# File 'lib/joey/model.rb', line 6

def client
  @client
end

#errorsObject

Returns the value of attribute errors.



6
7
8
# File 'lib/joey/model.rb', line 6

def errors
  @errors
end

Class Method Details

.define_properties(*args) ⇒ Object



15
16
17
18
19
# 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 = {}) ⇒ Object

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



76
77
78
# 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 = {}) ⇒ Object



80
81
82
# 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) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
# 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) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# 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) ⇒ Object

end



47
48
49
50
51
52
53
54
55
56
57
58
59
# 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

.recognize?(data) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/joey/model.rb', line 21

def self.recognize?(data)
  true
end