Class: GitlabBitbarLibConfig
- Inherits:
-
Object
- Object
- GitlabBitbarLibConfig
- Defined in:
- lib/bitbar_gitlab/gitlab_bitbar_lib_config.rb
Instance Attribute Summary collapse
-
#exe_dir ⇒ Object
readonly
Returns the value of attribute exe_dir.
-
#exe_file ⇒ Object
readonly
Returns the value of attribute exe_file.
Instance Method Summary collapse
- #delete ⇒ Object
- #exists? ⇒ Boolean
- #get_key(sym) ⇒ Object
-
#initialize(launch_file) ⇒ GitlabBitbarLibConfig
constructor
A new instance of GitlabBitbarLibConfig.
- #key_is_set(key) ⇒ Object
- #load_config ⇒ Object
- #missing_warning ⇒ Object
- #save_config ⇒ Object
- #save_init(init_conf) ⇒ Object
- #set_key(sym, val) ⇒ Object
- #toggle_on?(key) ⇒ Boolean
- #try_exe_dir_exists ⇒ Object
Constructor Details
#initialize(launch_file) ⇒ GitlabBitbarLibConfig
Returns a new instance of GitlabBitbarLibConfig.
6 7 8 9 10 11 |
# File 'lib/bitbar_gitlab/gitlab_bitbar_lib_config.rb', line 6 def initialize launch_file @exe_dir = File.dirname(File.(launch_file)) @exe_file = File.(launch_file) @config_file= File.('~/.bitbar_gitlab_cnf.yml') load_config if exists? end |
Instance Attribute Details
#exe_dir ⇒ Object (readonly)
Returns the value of attribute exe_dir.
4 5 6 |
# File 'lib/bitbar_gitlab/gitlab_bitbar_lib_config.rb', line 4 def exe_dir @exe_dir end |
#exe_file ⇒ Object (readonly)
Returns the value of attribute exe_file.
3 4 5 |
# File 'lib/bitbar_gitlab/gitlab_bitbar_lib_config.rb', line 3 def exe_file @exe_file end |
Instance Method Details
#delete ⇒ Object
21 22 23 |
# File 'lib/bitbar_gitlab/gitlab_bitbar_lib_config.rb', line 21 def delete File.delete @config_file end |
#exists? ⇒ Boolean
17 18 19 |
# File 'lib/bitbar_gitlab/gitlab_bitbar_lib_config.rb', line 17 def exists? true if File.exists? @config_file end |
#get_key(sym) ⇒ Object
35 36 37 |
# File 'lib/bitbar_gitlab/gitlab_bitbar_lib_config.rb', line 35 def get_key sym @config[sym.to_s.upcase] if @config.key?(sym.to_s.upcase) end |
#key_is_set(key) ⇒ Object
52 53 54 55 56 |
# File 'lib/bitbar_gitlab/gitlab_bitbar_lib_config.rb', line 52 def key_is_set key if get_key(key) and get_key(key) != 0 true end end |
#load_config ⇒ Object
25 26 27 |
# File 'lib/bitbar_gitlab/gitlab_bitbar_lib_config.rb', line 25 def load_config @config = YAML.load_file(@config_file) end |
#missing_warning ⇒ Object
58 59 60 61 62 63 |
# File 'lib/bitbar_gitlab/gitlab_bitbar_lib_config.rb', line 58 def missing_warning puts "WARNING, could not execute BITBAR_GITLAB" puts puts "make sure '~/.bitbar_gitlab_cnf.yml' exists." puts "You might want to run 'gitlab-bitbar-plugin.rb install'" end |
#save_config ⇒ Object
29 30 31 32 33 |
# File 'lib/bitbar_gitlab/gitlab_bitbar_lib_config.rb', line 29 def save_config File.open(@config_file, 'w') do |f| f.write(@config.to_yaml) end end |
#save_init(init_conf) ⇒ Object
13 14 15 |
# File 'lib/bitbar_gitlab/gitlab_bitbar_lib_config.rb', line 13 def save_init init_conf File.open(@config_file, 'w') { |file| file.write(init_conf.to_yaml) } end |
#set_key(sym, val) ⇒ Object
39 40 41 42 |
# File 'lib/bitbar_gitlab/gitlab_bitbar_lib_config.rb', line 39 def set_key sym, val @config[sym.to_s.upcase] = val save_config end |
#toggle_on?(key) ⇒ Boolean
44 45 46 47 48 49 50 |
# File 'lib/bitbar_gitlab/gitlab_bitbar_lib_config.rb', line 44 def toggle_on? key if @config['TOGGLE_'+key.to_s.upcase] and @config['TOGGLE_'+key.to_s.upcase] !=0 true else false end end |
#try_exe_dir_exists ⇒ Object
65 66 67 68 69 |
# File 'lib/bitbar_gitlab/gitlab_bitbar_lib_config.rb', line 65 def try_exe_dir_exists unless get_key :exe_util_dir set_key :exe_util_dir, @exe_dir end end |