Class: QiitaConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/qiita_org/config.rb

Instance Method Summary collapse

Constructor Details

#initialize(status, option, input) ⇒ QiitaConfig

Returns a new instance of QiitaConfig.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/qiita_org/config.rb', line 6

def initialize(status, option, input)
  @option = option
  @input = input
  if status == "local"
    conf_dir = QiitaBase.new().search_conf_path(Dir.pwd, Dir.home)
    if @option == "set"
      @setup = File.join(Dir.pwd, ".qiita.conf")
    else
      @setup = File.join(conf_dir, ".qiita.conf")
    end
  else
    @setup = File.join(Dir.home, ".qiita.conf")
  end
end

Instance Method Details

#check_or_copy_configObject

check qiita.conf or copy qiita.conf



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/qiita_org/config.rb', line 22

def check_or_copy_config()
  lib = File.expand_path("../../../lib", __FILE__)
  cp_file = File.join(lib, "qiita_org", ".qiita.conf")

  if File.exists?(@setup) # "# {ENV["HOME"]}/.qiita.conf")
    puts @setup.green
    print_config("now", "black")
  else
    FileUtils.cp(cp_file, @setup, verbose: true)
  end
end


43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/qiita_org/config.rb', line 43

def print_config(status, color)
  puts status if status != "now"

  items = JSON.load(File.read(@setup))
  format = JSON.pretty_generate(items)
  File.write(@setup, format)

  conts = File.read(@setup)
  adjust_conts = conts.gsub(/{|}|,/, "{" => "", "}" => "", "," => "")
  puts adjust_conts if color == "black"
  puts adjust_conts.green if color == "green"
  puts adjust_conts.red if color == "red"
end

#runObject



57
58
59
60
61
62
63
# File 'lib/qiita_org/config.rb', line 57

def run()
  if @option == nil || @option == "set"
    check_or_copy_config()
  else
    set_config()
  end
end

#set_configObject



34
35
36
37
38
39
40
41
# File 'lib/qiita_org/config.rb', line 34

def set_config()
  print_config("before", "red")
  items = JSON.load(File.read(@setup))
  items["#{@option}"] = @input.join(" ").strip
  conts = JSON.pretty_generate(items)
  File.write(@setup, conts)
  print_config("after", "green")
end