Class: JiraCommand::Config

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

Constant Summary collapse

CONFIG_PATH_CLASS =
Pathname(ENV['HOME'] + '/.jira_command/config.json')

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.check_existObject



22
23
24
# File 'lib/jira_command/config.rb', line 22

def self.check_exist
  FileTest.exists?(CONFIG_PATH_CLASS)
end

Instance Method Details

#clearObject



34
35
36
# File 'lib/jira_command/config.rb', line 34

def clear
  FileUtils.rm(CONFIG_PATH_CLASS)
end

#readObject



12
13
14
15
16
17
18
19
20
# File 'lib/jira_command/config.rb', line 12

def read
  unless FileTest.exists?(CONFIG_PATH_CLASS)
    puts 'please create config file first'
    exit 1
  end

  file = File.read(CONFIG_PATH_CLASS)
  JSON.parse(file, symbolize_names: true)
end

#write(hash_params) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/jira_command/config.rb', line 26

def write(hash_params)
  FileUtils.mkdir_p(CONFIG_PATH_CLASS.dirname) unless Dir.exist?(CONFIG_PATH_CLASS.dirname)

  File.open(CONFIG_PATH_CLASS, 'w') do |f|
    f.puts hash_params.to_json
  end
end