Class: GithubFlowCli::Config
- Inherits:
-
Object
- Object
- GithubFlowCli::Config
- Defined in:
- lib/github_flow_cli/config.rb
Constant Summary collapse
- CONFIG_DIR =
File.('~/.config')
- CONFIG_FILE =
'hubflow'- KEYS =
%w[username oauth_token branch_issue_map pr_branch_map]
Class Method Summary collapse
- .config_path ⇒ Object
- .link_branch_to_issue(branch_name, issue) ⇒ Object
- .link_pr_to_branch(pr, branch_name) ⇒ Object
- .load ⇒ Object
- .save! ⇒ Object
- .setup ⇒ Object
- .to_h ⇒ Object
- .valid? ⇒ Boolean
Class Method Details
.config_path ⇒ Object
56 57 58 59 |
# File 'lib/github_flow_cli/config.rb', line 56 def config_path FileUtils.mkdir_p(CONFIG_DIR) unless File.directory?(CONFIG_DIR) File.join(CONFIG_DIR, CONFIG_FILE) end |
.link_branch_to_issue(branch_name, issue) ⇒ Object
30 31 32 |
# File 'lib/github_flow_cli/config.rb', line 30 def link_branch_to_issue(branch_name, issue) self.branch_issue_map[branch_name] = issue.number end |
.link_pr_to_branch(pr, branch_name) ⇒ Object
34 35 36 |
# File 'lib/github_flow_cli/config.rb', line 34 def link_pr_to_branch(pr, branch_name) self.pr_branch_map[pr.number] = branch_name end |
.load ⇒ Object
38 39 40 |
# File 'lib/github_flow_cli/config.rb', line 38 def load YAML::load_file(config_path).each { |k, v| send("#{k}=", v) } end |
.save! ⇒ Object
42 43 44 45 46 |
# File 'lib/github_flow_cli/config.rb', line 42 def save! self.branch_issue_map ||= {} self.pr_branch_map ||= {} File.open(config_path, 'w') { |f| f.write(to_h.to_yaml) } end |
.setup ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/github_flow_cli/config.rb', line 15 def setup if File.file?(config_path) load API.use_oauth_token(oauth_token) unless API.valid? puts "WARN: authentication failed, please retry login." File.delete(config_path) exit(1) end else puts "please login first." exit(2) end end |
.to_h ⇒ Object
48 49 50 |
# File 'lib/github_flow_cli/config.rb', line 48 def to_h KEYS.map{ |k| [k, send(k)] }.to_h end |
.valid? ⇒ Boolean
52 53 54 |
# File 'lib/github_flow_cli/config.rb', line 52 def valid? KEYS.all? { |c| send(c) } end |