Class: Qapi::Model

Inherits:
Object
  • Object
show all
Defined in:
lib/qapi/model.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection, attrs = {}) ⇒ Model

Returns a new instance of Model.



16
17
18
19
20
21
# File 'lib/qapi/model.rb', line 16

def initialize(connection, attrs = {})
  @connection = connection
  self.class.attrs.each do |attr|
    self.send("#{attr}=", attrs[attr])
  end
end

Class Attribute Details

.attrsObject

Returns the value of attribute attrs.



7
8
9
# File 'lib/qapi/model.rb', line 7

def attrs
  @attrs
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



4
5
6
# File 'lib/qapi/model.rb', line 4

def connection
  @connection
end

Class Method Details

.attribute(name) ⇒ Object



10
11
12
13
14
# File 'lib/qapi/model.rb', line 10

def self.attribute(name)
  self.send(:attr_accessor, name)
  self.attrs ||= []
  self.attrs << name.to_s
end

Instance Method Details

#inspectObject



23
24
25
26
27
# File 'lib/qapi/model.rb', line 23

def inspect
  "<" + self.class.attrs.map do |attr|
    "#{attr}: #{send(attr)}"
  end.join(", ") + ">"
end