Module: AtcoderGreedy

Defined in:
lib/atcoder_greedy.rb,
lib/atcoder_greedy/command.rb,
lib/atcoder_greedy/version.rb,
lib/atcoder_greedy/command/test.rb,
lib/atcoder_greedy/command/config.rb,
lib/atcoder_greedy/command/create.rb,
lib/atcoder_greedy/command/destroy.rb

Defined Under Namespace

Classes: Command

Constant Summary collapse

VERSION =
'0.3.1'

Class Method Summary collapse

Class Method Details

.configObject



49
50
51
52
53
# File 'lib/atcoder_greedy.rb', line 49

def self.config
  yml_path = get_config_path + '/settings.yml'
  configure_with(yml_path)
  @config
end

.configure(opts = {}) ⇒ Object

Configure through hash



21
22
23
# File 'lib/atcoder_greedy.rb', line 21

def self.configure(opts = {})
  opts.each { |k, v| @config[k.to_sym] = v if @valid_config_keys.include? k.to_sym }
end

.configure_with(path_to_yaml_file) ⇒ Object

Configure through yaml file



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/atcoder_greedy.rb', line 26

def self.configure_with(path_to_yaml_file)
  begin
    config = YAML::load(IO.read(path_to_yaml_file))
  rescue Errno::ENOENT
    puts "YAML configuration file couldn't be found. Using defaults."; return
  rescue Psych::SyntaxError
    puts "YAML configuration file contains invalid syntax. Using defaults."; return
  end

  configure(config)
end

.get_config_pathObject



38
39
40
41
42
43
44
45
46
47
# File 'lib/atcoder_greedy.rb', line 38

def self.get_config_path
  config_path = Dir.home + '/.atcoder_greedy'
  if Dir.exists?(config_path)
    # use user settings
    config_path
  else
    # use default settings
    File.join(File.dirname(__dir__), '/lib/atcoder_greedy')
  end
end

.save_configObject



55
56
57
58
59
60
# File 'lib/atcoder_greedy.rb', line 55

def self.save_config
  yml_path = get_config_path + '/settings.yml'
  f = File.open(yml_path, 'w')
  f.print(@config.to_yaml)
  f.close
end