Class: Zm::Client::Base::Object

Inherits:
Object
  • Object
show all
Defined in:
lib/zm/client/base/object.rb

Overview

Abstract Class Provisionning Object

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent) {|_self| ... } ⇒ Object

Returns a new instance of Object.

Yields:

  • (_self)

Yield Parameters:



10
11
12
13
# File 'lib/zm/client/base/object.rb', line 10

def initialize(parent)
  @parent = parent
  yield(self) if block_given?
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



8
9
10
# File 'lib/zm/client/base/object.rb', line 8

def id
  @id
end

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/zm/client/base/object.rb', line 8

def name
  @name
end

#parentObject

Returns the value of attribute parent.



8
9
10
# File 'lib/zm/client/base/object.rb', line 8

def parent
  @parent
end

#tokenObject

Returns the value of attribute token.



8
9
10
# File 'lib/zm/client/base/object.rb', line 8

def token
  @token
end

Instance Method Details

#clone {|obj| ... } ⇒ Object

Yields:

  • (obj)


23
24
25
26
27
28
# File 'lib/zm/client/base/object.rb', line 23

def clone
  obj = super
  obj.remove_instance_variable(:@id)
  yield(obj) if block_given?
  obj
end

#inspectObject



52
53
54
55
# File 'lib/zm/client/base/object.rb', line 52

def inspect
  keys_str = to_h.map { |k, v| "#{k}: #{v}" }.join(', ')
  "#{self.class}:#{format('0x00%x', (object_id << 1))} #{keys_str}"
end

#instance_variables_mapObject



57
58
59
60
61
# File 'lib/zm/client/base/object.rb', line 57

def instance_variables_map
  keys = instance_variables.dup
  keys.delete(:@parent)
  keys.map { |key| [key, instance_variable_get(key)] }
end

#loggerObject



30
31
32
# File 'lib/zm/client/base/object.rb', line 30

def logger
  @parent.logger
end

#recorded?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/zm/client/base/object.rb', line 15

def recorded?
  !@id.nil?
end

#save!Object



19
20
21
# File 'lib/zm/client/base/object.rb', line 19

def save!
  recorded? ? modify! : create!
end

#to_hObject



48
49
50
# File 'lib/zm/client/base/object.rb', line 48

def to_h
  Hash[instance_variables_map]
end

#to_sObject



44
45
46
# File 'lib/zm/client/base/object.rb', line 44

def to_s
  inspect
end

#update_attribute(key, value) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/zm/client/base/object.rb', line 34

def update_attribute(key, value)
  arrow_attr_sym = Utils.arrow_name_sym(key)

  if value.respond_to?(:empty?) && value.empty?
    remove_instance_variable(arrow_attr_sym) if instance_variable_get(arrow_attr_sym)
  else
    instance_variable_set(arrow_attr_sym, value)
  end
end