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/submit.rb,
lib/atcoder_greedy/command/destroy.rb,
lib/atcoder_greedy/command/template.rb

Defined Under Namespace

Classes: Command

Constant Summary collapse

VERSION =
'0.5.0'

Class Method Summary collapse

Class Method Details

.configObject



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

def self.config
  yml_path = get_config_path + '/settings.yml'
  yml_file = YAML.load_file(yml_path)
  if yml_file
    @config = yml_file
  else
    File.open(yml_path, 'w') { |f| YAML.dump(@config, f) }
  end
end

.configure(opts = {}) ⇒ Object

Configure through hash



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

def self.configure(opts = {})
  self.config
  opts.each do |k, v|
    if v.is_a?(Hash)
      v.each do |ck, cv|
        @config[k.to_sym][ck.to_sym] = cv if @valid_languages.include?(ck.to_s)
      end
    else
      @config[k.to_sym] = v if @valid_config_keys.include? k.to_sym
    end
  end
  self.save_config
end

.get_config_pathObject



43
44
45
46
47
48
49
50
# File 'lib/atcoder_greedy.rb', line 43

def self.get_config_path
  config_path = Dir.home + '/.atcoder_greedy'
  if Dir.exists?(config_path)
    config_path
  else
    raise "Can't find config directory. please init by command: 'atcoder_greedy config'.'"
  end
end

.save_configObject



62
63
64
65
66
67
68
69
# File 'lib/atcoder_greedy.rb', line 62

def self.save_config
  yml_path = get_config_path + '/settings.yml'
  if File.exists?(yml_path)
    File.open(yml_path, 'w') { |f| YAML.dump(@config, f) }
  else
    raise "Can't find #{yml_path}. please set configure."
  end
end