Class: Menu::Config

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

Overview

MenuConfig handlers

Instance Method Summary collapse

Methods inherited from Base

#initialize, #run_default, #run_selected_command

Constructor Details

This class inherits a constructor from Menu::Base

Instance Method Details

#create_input_mapObject



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

def create_input_map
  {
    url: menu[:url],
    shift_start: menu[:shift_start],
    shift_end: menu[:shift_end],
    list: menu[:list]
  }
end

#create_procs_mapObject



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

def create_procs_map
  {
    url: proc { set_url },
    shift_start: proc { set_shift_start },
    shift_end: proc { set_shift_end },
    list: proc { run_list }
  }
end

rubocop:enable Metrics/AbcSize



79
80
81
82
83
# File 'lib/menu/config.rb', line 79

def print_config_value(value)
  puts "#{value[:key]}=#{value[:value].call}"
rescue LogworkException::ConfigurationValueNotFound
  puts "#{value[:key]}=[not-set]"
end

#run_listObject

rubocop:disable Metrics/AbcSize



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/menu/config.rb', line 66

def run_list
  values = [
    { key: :url, value: proc { Configuration::ConfigurationManager.instance.jira_server_url } },
    { key: :shift_start, value: proc { ShiftConfiguration.new.shift_start } },
    { key: :shift_end, value: proc { ShiftConfiguration.new.shift_end } },
    { key: :username, value: proc { CredentialsConfiguration.new..username } },
    { key: :password, value: proc { CredentialsConfiguration.new..password.nil? ? nil : "****" } }
  ]

  values.each { |v| print_config_value(v) }
end

#set_shift_endObject

Set shift end time.



58
59
60
61
62
# File 'lib/menu/config.rb', line 58

def set_shift_end
  ShiftConfiguration.new.update_shift_end(menu[:shift_end])
rescue LogworkException::InvalidTime
  Utilities.log("Invalid end time format.", { type: :error })
end

#set_shift_startObject

Set shift start time.



51
52
53
54
55
# File 'lib/menu/config.rb', line 51

def set_shift_start
  ShiftConfiguration.new.update_shift_start(menu[:shift_start])
rescue LogworkException::InvalidTime
  Utilities.log("Invalid starttime format.", { type: :error })
end

#set_urlObject

Set JIRA URL.



44
45
46
47
48
# File 'lib/menu/config.rb', line 44

def set_url
  Configuraiton::ConfigurationManager.instance.update_jira_server_url(menu[:url])
rescue LogworkException::InvalidURL
  Utilities.log("Invalid JIRA server URL.", { type: :error })
end