Class: QiitaConfig
- Inherits:
-
Object
- Object
- QiitaConfig
- Defined in:
- lib/qiita_org/config.rb
Instance Method Summary collapse
-
#check_or_copy_config ⇒ Object
check qiita.conf or copy qiita.conf.
-
#initialize(status, option, input) ⇒ QiitaConfig
constructor
A new instance of QiitaConfig.
- #print_config(status, color) ⇒ Object
- #run ⇒ Object
- #set_config ⇒ Object
Constructor Details
#initialize(status, option, input) ⇒ QiitaConfig
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/qiita_org/config.rb', line 6 def initialize(status, option, input) @option = option @input = input if status == "local" search = SearchConfPath.new(Dir.pwd, Dir.home) conf_dir = search.search_conf_path() 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_config ⇒ Object
check qiita.conf or copy qiita.conf
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/qiita_org/config.rb', line 23 def check_or_copy_config() lib = File.("../../../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 |
#print_config(status, color) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/qiita_org/config.rb', line 44 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 |
#run ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/qiita_org/config.rb', line 58 def run() if @option == nil || @option == "set" check_or_copy_config() else set_config() end end |
#set_config ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/qiita_org/config.rb', line 35 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 |