Class: Ledmon::Configurator

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfigurator

Returns a new instance of Configurator.



5
6
7
8
9
10
11
12
# File 'lib/ledmon/configurator.rb', line 5

def initialize
  @config = TTY::Config.new
  config.filename = '.ledmon'
  config.append_path Dir.pwd
  config.env_prefix = 'ledmon'

  config.read if config.exist?
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



3
4
5
# File 'lib/ledmon/configurator.rb', line 3

def config
  @config
end

Class Method Details

.config_value(name, keys: nil, default: nil) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ledmon/configurator.rb', line 14

def self.config_value(name, keys: nil, default: nil)
  keys = Array(keys || name).map(&:to_sym)

  define_method(name) do
    read_value(keys, default:)
  end

  define_method("#{name}=") do |value|
    write_value(keys, value:)
  end
end

Instance Method Details

#http_base_urlObject



35
36
37
38
39
40
41
42
43
44
# File 'lib/ledmon/configurator.rb', line 35

def http_base_url
  port = if http_proto == 'https' && http_port != 443
    ":#{http_port}"
  elsif http_proto == 'http' && http_port != 80
    ":#{http_port}"
  else
    ''
  end
  "#{http_proto}://#{host}#{port}"
end