Class: LifxDash::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/lifx_dash/configuration.rb

Constant Summary collapse

CONFIG_FILE_NAME =
".lifx_dash.rc.yml"
OPTION_PROMPTS =
{
  "iface"       => "Network interface identifier e.g. en0 (choose from ifconfig -l)",
  "token"       => "LIFX API token (get a free personal token at cloud.lifx.com)",
  "mac-address" => "Dash button MAC address (use lifx_dash snoop to find it)",
  "selector"    => "LIFX bulb selector e.g. all or a LIFX bulb ID",
  "log-file"    => "Log file location (when running as a daemon)"
}

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ Object


15
16
17
# File 'lib/lifx_dash/configuration.rb', line 15

def [](key)
  config_options[key]
end

#configureObject


29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/lifx_dash/configuration.rb', line 29

def configure
  puts "Configuring lifx_dash ...\n\n"
  user_options = ask_for_options

  if user_options.values.all?(&:nil?)
    puts "\nNo options set, configuration is unchanged"
  else
    File.open(config_file, "w") do |file|
      YAML::dump(user_options, file)
    end
    puts "\nConfiguration saved to #{config_file}"
  end
end

#showObject


19
20
21
22
23
24
25
26
27
# File 'lib/lifx_dash/configuration.rb', line 19

def show
  if File.exist?(config_file)
    puts "Configuration file at #{config_file} ...\n\n"
    puts File.read(config_file)
    puts "\nChange these options with `lifx_dash config`"
  else
    puts "No configuration file exists at #{config_file}"
  end
end