Class: Xlogin::APIClient::Factory

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/xlogin/apiclient/cli.rb

Instance Method Summary collapse

Constructor Details

#initializeFactory

Returns a new instance of Factory.



14
15
16
# File 'lib/xlogin/apiclient/cli.rb', line 14

def initialize
  @inventory = Hash.new
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, **opts, &block) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/xlogin/apiclient/cli.rb', line 26

def method_missing(method_name, *args, **opts, &block)
  super unless args.size == 2 && Addressable::URI::URIREGEX =~ args[1]

  name = args[0]
  uri  = args[1]
  type = method_name.to_s.downcase
  set_hostinfo(name.to_s, type: type, uri: uri, **opts)
end

Instance Method Details

#get_hostinfo(name) ⇒ Object



22
23
24
# File 'lib/xlogin/apiclient/cli.rb', line 22

def get_hostinfo(name)
  @inventory[name]
end

#set_hostinfo(name, **opts) ⇒ Object



18
19
20
# File 'lib/xlogin/apiclient/cli.rb', line 18

def set_hostinfo(name, **opts)
  @inventory[name] = (get_hostinfo(name) || {name: name}).merge(opts)
end