Class: Pandoru::ClientBuilders::FileBasedClientBuilder

Inherits:
APIClientBuilder show all
Defined in:
lib/pandoru/client_builder.rb

Overview

Abstract File Based Client Builder Provides base functionality for client builders that load their settings from files.

Constant Summary collapse

DEFAULT_CONFIG_FILE =
""

Constants inherited from APIClientBuilder

APIClientBuilder::DEFAULT_CLIENT_CLASS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from APIClientBuilder

#build_from_settings_hash

Constructor Details

#initialize(path: nil, authenticate: true, **kwargs) ⇒ FileBasedClientBuilder

Returns a new instance of FileBasedClientBuilder.



181
182
183
184
185
# File 'lib/pandoru/client_builder.rb', line 181

def initialize(path: nil, authenticate: true, **kwargs)
  super(**kwargs)
  @path = path
  @authenticate = authenticate
end

Instance Attribute Details

#authenticateObject (readonly)

Returns the value of attribute authenticate.



179
180
181
# File 'lib/pandoru/client_builder.rb', line 179

def authenticate
  @authenticate
end

#pathObject

Returns the value of attribute path.



179
180
181
# File 'lib/pandoru/client_builder.rb', line 179

def path
  @path
end

Instance Method Details

#buildObject



200
201
202
203
204
205
206
207
208
# File 'lib/pandoru/client_builder.rb', line 200

def build
  client = build_from_settings_hash(config)
  
  if authenticate && config["USERNAME"] && config["PASSWORD"]
    client.(config["USERNAME"], config["PASSWORD"])
  end
  
  client
end

#configObject



192
193
194
# File 'lib/pandoru/client_builder.rb', line 192

def config
  @config ||= parse_config
end

#parse_configObject

Raises:

  • (NotImplementedError)


196
197
198
# File 'lib/pandoru/client_builder.rb', line 196

def parse_config
  raise NotImplementedError, "Subclasses must implement parse_config"
end