Class: ProxmoxAPI::ApiPath

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

Overview

This class is used to collect api path before request

Instance Method Summary collapse

Constructor Details

#initialize(api) ⇒ ApiPath

Returns a new instance of ApiPath.

Parameters:

  • api (ProxmoxAPI)

    ProxmoxAPI object to call when request is executed

Raises:

  • (ArgumentError)


18
19
20
21
22
23
# File 'lib/proxmox_api.rb', line 18

def initialize(api)
  raise ArgumentError, 'Not an instance of ProxmoxAPI' unless api.is_a? ProxmoxAPI

  @api = api
  @path = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



34
35
36
37
38
39
# File 'lib/proxmox_api.rb', line 34

def method_missing(method, *args)
  return @api.__send__(:submit, method, to_s, *args) if REST_METHODS.any? { |rm| /^#{rm}!?$/.match? method }

  @path << method.to_s
  self
end

Instance Method Details

#[](index) ⇒ Object



29
30
31
32
# File 'lib/proxmox_api.rb', line 29

def [](index)
  @path << index.to_s
  self
end

#respond_to_missing?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/proxmox_api.rb', line 41

def respond_to_missing?(*)
  true
end

#to_sObject



25
26
27
# File 'lib/proxmox_api.rb', line 25

def to_s
  @path.join('/')
end