Class: Cyclid::UI::Config

Inherits:
Object
  • Object
show all
Defined in:
app/cyclid_ui/config.rb

Overview

Cyclid UI configuration

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Config

Returns a new instance of Config.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/cyclid_ui/config.rb', line 25

def initialize(path)
  # Try to load the configuration file. If it can't be loaded, we'll
  # fall back to defaults
  begin
    config = YAML.load_file(path)
    manage = config['manage'] || {}
  rescue Errno::ENOENT
    # Cyclid.logger wont exist, yet
    STDERR.puts "Config file #{path} not found: using defaults"
    manage = {}
  end

  @memcached = manage['memcached'] || 'localhost:11211'
  @log = manage['log'] || File.join(%w(/ var log cyclid manage))

  # The api setting is flexible; the URL that the server uses to connect
  # to the API, and the URL that the client uses, can be diferent. This
  # may happen if E.g. the UI & API are running on the same machine but
  # with the ports NAT'd from the outside so that the client sees port
  # 8123 but the local port is 123, or where the API is behind a load
  # balancer and you may wish to avoid the round-trip out and back in.
  #
  # If "api" is a string then it is used for both the server & client URL
  # If "api" is an array then we select the client & server URLs
  # separately
  api = manage['api'] || 'http://localhost:8361'
  if api.is_a? String
    @server_api = URI(api)
    @client_api = URI(api)
  elsif api.is_a? Hash
    @server_api = URI(api['server'])
    @client_api = URI(api['client'])
  end

rescue StandardError => ex
  abort "Failed to load configuration file #{path}: #{ex}"
end

Instance Attribute Details

#client_apiObject (readonly)

Returns the value of attribute client_api.



23
24
25
# File 'app/cyclid_ui/config.rb', line 23

def client_api
  @client_api
end

#logObject (readonly)

Returns the value of attribute log.



23
24
25
# File 'app/cyclid_ui/config.rb', line 23

def log
  @log
end

#memcachedObject (readonly)

Returns the value of attribute memcached.



23
24
25
# File 'app/cyclid_ui/config.rb', line 23

def memcached
  @memcached
end

#server_apiObject (readonly)

Returns the value of attribute server_api.



23
24
25
# File 'app/cyclid_ui/config.rb', line 23

def server_api
  @server_api
end