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(option, input) ⇒ QiitaConfig
constructor
A new instance of QiitaConfig.
- #print_config(status, color) ⇒ Object
- #run ⇒ Object
- #set_config ⇒ Object
Constructor Details
#initialize(option, input) ⇒ QiitaConfig
Returns a new instance of QiitaConfig.
6 7 8 9 10 |
# File 'lib/qiita_org/config.rb', line 6 def initialize(option, input) @option = option @input = input @setup = "#{ENV["HOME"]}/.qiita.conf" end |
Instance Method Details
#check_or_copy_config ⇒ Object
check qiita.conf or copy qiita.conf
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/qiita_org/config.rb', line 13 def check_or_copy_config() lib = File.("../../../lib", __FILE__) cp_file = File.join(lib, "qiita_org", ".qiita.conf") if File.exists?("#{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
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/qiita_org/config.rb', line 34 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
48 49 50 51 52 53 54 |
# File 'lib/qiita_org/config.rb', line 48 def run() if @option == nil check_or_copy_config() else set_config() end end |
#set_config ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/qiita_org/config.rb', line 25 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 |