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.



61
62
63
# File 'lib/joey/model.rb', line 61

def self.find(id, client = nil, args = {})
  client.get_and_map(id, self, args)
end

.has_association(name, klass) ⇒ Object

end



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/joey/model.rb', line 47

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

.recognize?(data) ⇒ Boolean

Returns:

  • (Boolean)


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

def self.recognize?(data)
  true
end