Class: GitlabBitbarLibConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/bitbar_gitlab/gitlab_bitbar_lib_config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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.expand_path(launch_file))
  @exe_file = File.expand_path(launch_file)
  @config_file= File.expand_path('~/.bitbar_gitlab_cnf.yml')
  load_config if exists?
end

Instance Attribute Details

#exe_dirObject (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_fileObject (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

#deleteObject



21
22
23
# File 'lib/bitbar_gitlab/gitlab_bitbar_lib_config.rb', line 21

def delete
  File.delete @config_file
end

#exists?Boolean

Returns:

  • (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_configObject



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_warningObject



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_configObject



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

Returns:

  • (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_existsObject



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