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

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

Overview

Abstract Class Provisionning Object

Direct Known Subclasses

AccountObject, AdminObject

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Object.

Yields:

  • (_self)

Yield Parameters:



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

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

Instance Attribute Details

#grantee_typeObject (readonly)

Returns the value of attribute grantee_type.



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

def grantee_type
  @grantee_type
end

#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

#arrow_name(name) ⇒ Object



65
66
67
68
69
# File 'lib/zm/client/base/object.rb', line 65

def arrow_name(name)
  return name if name.to_s.start_with?('@')

  "@#{name}"
end

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

Yields:

  • (obj)


71
72
73
74
75
76
# File 'lib/zm/client/base/object.rb', line 71

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

#concatObject



21
22
23
# File 'lib/zm/client/base/object.rb', line 21

def concat
  instance_variables.map { |variable| instance_variable_get(variable) }
end

#convert_json_string_value(value) ⇒ Object



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

def convert_json_string_value(value)
  return value unless value.is_a?(String)
  return 0 if value == '0'

  c = value.to_i
  c.to_s == value ? c : value
end

#init_from_json(json) ⇒ Object



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

def init_from_json(json)
  @id    = json[:id]
  @name  = json[:name]
end

#instance_variables_array(zcs_attrs) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/zm/client/base/object.rb', line 45

def instance_variables_array(zcs_attrs)
  selected_attrs = zcs_attrs.map { |a| arrow_name(a).to_sym }
  attrs_only_set = instance_variables & selected_attrs

  arr = attrs_only_set.map do |name|
    n = name.to_s[1..-1]
    value = instance_variable_get(name)
    [n, value]
  end

  multi_value = arr.select { |a| a.last.is_a?(Array) }
  arr.reject! { |a| a.last.is_a?(Array) }
  multi_value.each { |a| arr += a.last.map { |v| [a.first, v] } }
  arr
end

#instance_variables_hash(zcs_attrs) ⇒ Object



61
62
63
# File 'lib/zm/client/base/object.rb', line 61

def instance_variables_hash(zcs_attrs)
  Hash[instance_variables_array(zcs_attrs)]
end

#recorded?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/zm/client/base/object.rb', line 37

def recorded?
  !@id.nil?
end

#save!Object



41
42
43
# File 'lib/zm/client/base/object.rb', line 41

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

#to_sObject



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

def to_s
  concat.join(DOUBLEPOINT)
end