Class: Jirify::Config

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

Constant Summary collapse

CONFIG_FOLDER =
"#{Dir.home}/.jirify".freeze
CONFIG_FILE =
"#{CONFIG_FOLDER}/.jirify".freeze

Class Method Summary collapse

Class Method Details

.always_verboseObject



72
73
74
# File 'lib/jirify/config.rb', line 72

def always_verbose
  options['verbose']
end

.atlassian_urlObject



76
77
78
# File 'lib/jirify/config.rb', line 76

def atlassian_url
  options['site']
end

.client_optionsObject



127
128
129
130
131
132
133
134
135
# File 'lib/jirify/config.rb', line 127

def client_options
  {
    username:     options['username'],
    password:     options['token'],
    site:         atlassian_url,
    context_path: '',
    auth_type:    :basic
  }
end

.config_fileObject



15
16
17
18
# File 'lib/jirify/config.rb', line 15

def config_file
  initialize! unless initialized?
  @config_file ||= CONFIG_FILE
end

.config_folderObject



10
11
12
13
# File 'lib/jirify/config.rb', line 10

def config_folder
  initialize! unless initialized?
  @config_folder ||= CONFIG_FOLDER
end

.copy_bash_completion!Object



30
31
32
# File 'lib/jirify/config.rb', line 30

def copy_bash_completion!
  FileUtils.cp "#{File.expand_path('..', File.dirname(__dir__))}/jirify.bash_completion.sh", CONFIG_FOLDER
end

.initialize!Object



24
25
26
27
28
# File 'lib/jirify/config.rb', line 24

def initialize!
  FileUtils.mkdir_p CONFIG_FOLDER
  FileUtils.touch CONFIG_FILE
  copy_bash_completion!
end

.initialized?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/jirify/config.rb', line 20

def initialized?
  File.directory?(CONFIG_FOLDER) && File.exist?(CONFIG_FILE)
end

.issue_browse_urlObject



88
89
90
# File 'lib/jirify/config.rb', line 88

def issue_browse_url
  "#{atlassian_url}/browse/"
end

.optionsObject



63
64
65
66
67
68
69
70
# File 'lib/jirify/config.rb', line 63

def options
  unless initialized?
    puts ColorizedString['ERROR: You must initialize Jirify first!'].white.on_red.bold
    exit(0)
  end

  @options ||= YAML.load_file(config_file)['options']
end

.projectsObject



84
85
86
# File 'lib/jirify/config.rb', line 84

def projects
  options['projects']
end

.projects=(value) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/jirify/config.rb', line 41

def projects=(value)
  unless initialized?
    puts ColorizedString['ERROR: You must initialize Jirify first!'].white.on_red.bold
    exit(0)
  end

  config = YAML.load_file(config_file)
  config['options']['projects'] = value
  write(config)
end

.statusesObject



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/jirify/config.rb', line 92

def statuses
  default = {
    'blocked'     => 'Blocked',
    'todo'        => 'To Do',
    'in_progress' => 'In Progress',
    'in_review'   => 'In Review',
    'done'        => 'Closed'
  }

  if initialized?
    options['statuses'] || default
  else
    default
  end
end

.transitionsObject



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/jirify/config.rb', line 108

def transitions
  default = {
    'block'        => 'Blocked',
    'unblock'      => 'Unblock',
    'start'        => 'Start Progress',
    'stop'         => 'Stop Progress',
    'start_review' => 'Code Review',
    'stop_review'  => 'Back to In Progress',
    'close'        => 'Close',
    'reopen'       => 'Reopen'
  }

  if initialized?
    options['transitions'] || default
  else
    default
  end
end

.usernameObject



80
81
82
# File 'lib/jirify/config.rb', line 80

def username
  options['username']
end

.verbose=(value) ⇒ Object



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

def verbose=(value)
  unless initialized?
    puts ColorizedString['ERROR: You must initialize Jirify first!'].white.on_red.bold
    exit(0)
  end

  config = YAML.load_file(config_file)
  config['options']['verbose'] = value
  write(config)
end

.write(config) ⇒ Object



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

def write(config)
  puts 'Writing config:'
  puts config.to_yaml

  File.write(config_file, config.to_yaml)
end