Class: Crowbar::Client::Config

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/crowbar/client/config.rb

Overview

General configuration for the Crowbar CLI

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configHashie::Mash

Define file config

Returns:

  • (Hashie::Mash)

    the file config



82
83
84
# File 'lib/crowbar/client/config.rb', line 82

def config
  @config ||= Hashie::Mash.new
end

#optionsHashie::Mash

Define parameter config

Returns:

  • (Hashie::Mash)

    the parameter config



73
74
75
# File 'lib/crowbar/client/config.rb', line 73

def options
  @options ||= defaults
end

#valuesHashie::Mash

Define merged config

Returns:

  • (Hashie::Mash)

    the merged config



91
92
93
# File 'lib/crowbar/client/config.rb', line 91

def values
  @values ||= Hashie::Mash.new
end

Class Method Details

.configHashie::Mash

Define file config

Returns:

  • (Hashie::Mash)

    the file config

See Also:



358
359
360
# File 'lib/crowbar/client/config.rb', line 358

def config
  instance.config
end

.configure(options) ⇒ Object

Define base configuration

Parameters:

  • options (Hash)

    the base configuration

See Also:



328
329
330
# File 'lib/crowbar/client/config.rb', line 328

def configure(options)
  instance.configure(options)
end

.defaultsHashie::Mash

Define default config

Returns:

  • (Hashie::Mash)

    the default config

See Also:



338
339
340
# File 'lib/crowbar/client/config.rb', line 338

def defaults
  instance.defaults
end

.method_missing(method, *arguments) { ... } ⇒ Object

Magic to catch missing method calls

Parameters:

  • method (Symbol)

    the method that is missing

  • arguments (Array)

    the list of attributes

Yields:



379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
# File 'lib/crowbar/client/config.rb', line 379

def method_missing(method, *arguments, &block)
  case
  when method.to_s.ends_with?("=")
    key = method.to_s.gsub(/=\z/, "")

    if values.key?(key)
      values[key] = arguments.first
    else
      super
    end
  when values.key?(method)
    values[method]
  else
    super
  end
end

.optionsHashie::Mash

Define parameter config

Returns:

  • (Hashie::Mash)

    the parameter config

See Also:



348
349
350
# File 'lib/crowbar/client/config.rb', line 348

def options
  instance.options
end

.respond_to?(method, include_private = false) ⇒ Bool

Magic to catch missing respond_to calls

Parameters:

  • method (Symbol)

    the method that is missing

  • include_private (Bool) (defaults to: false)

    should include private methods

Returns:

  • (Bool)

    the class responds to it or not



403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
# File 'lib/crowbar/client/config.rb', line 403

def respond_to?(method, include_private = false)
  case
  when method.to_s.ends_with?("=")
    key = method.to_s.gsub(/=\z/, "")

    if values.key?(key)
      true
    else
      super
    end
  when values.key?(method)
    true
  else
    super
  end
end

.valuesHashie::Mash

Define merged config

Returns:

  • (Hashie::Mash)

    the merged config

See Also:



368
369
370
# File 'lib/crowbar/client/config.rb', line 368

def values
  instance.values
end

Instance Method Details

#configure(options) ⇒ Object

Define base configuration

Parameters:

  • options (Hash)

    the base configuration



38
39
40
41
42
43
44
45
# File 'lib/crowbar/client/config.rb', line 38

def configure(options)
  self.options = Hashie::Mash.new(
    options
  )

  self.config = parser
  self.values = merge
end

#defaultsHashie::Mash

Define default config

Returns:

  • (Hashie::Mash)

    the default config



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/crowbar/client/config.rb', line 52

def defaults
  @defaults ||= Hashie::Mash.new(
    alias: default_alias,
    username: default_username,
    password: default_password,
    server: default_server,
    verify_ssl: default_verify_ssl,
    timeout: default_timeout,
    anonymous: default_anonymous,
    apiversion: default_apiversion,
    experimental: default_experimental,
    upgrade_versions: default_upgrade_versions,
    debug: default_debug
  )
end