Class: WhatsupGithub::Config

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/whatsup_github/config_reader.rb

Overview

Creates readable objects from confirurarion files

Constant Summary collapse

@@filename =
''

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



20
21
22
23
# File 'lib/whatsup_github/config_reader.rb', line 20

def initialize
  @file = @@filename
  @config = {}
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



10
11
12
# File 'lib/whatsup_github/config_reader.rb', line 10

def config
  @config
end

Class Method Details

.filename=(filename) ⇒ Object



16
17
18
# File 'lib/whatsup_github/config_reader.rb', line 16

def self.filename=(filename)
  @@filename = filename
end

Instance Method Details

#base_branchObject



40
41
42
# File 'lib/whatsup_github/config_reader.rb', line 40

def base_branch
  read['base_branch']
end

#enterpriseObject



74
75
76
# File 'lib/whatsup_github/config_reader.rb', line 74

def enterprise
  read['enterprise']
end

#labelsObject



48
49
50
# File 'lib/whatsup_github/config_reader.rb', line 48

def labels
  required_labels + optional_labels
end

#magic_wordObject



70
71
72
# File 'lib/whatsup_github/config_reader.rb', line 70

def magic_word
  read['magic_word']
end

#membershipObject



66
67
68
# File 'lib/whatsup_github/config_reader.rb', line 66

def membership
  read['membership']
end

#optional_labelsObject



59
60
61
62
63
64
# File 'lib/whatsup_github/config_reader.rb', line 59

def optional_labels
  res = read.dig 'labels', 'optional'
  return [] unless res

  res
end

#output_formatObject



44
45
46
# File 'lib/whatsup_github/config_reader.rb', line 44

def output_format
  read['output_format']
end

#readObject



25
26
27
28
29
30
31
32
33
34
# File 'lib/whatsup_github/config_reader.rb', line 25

def read
  unless File.exist?(@file)
    dist_file = File.expand_path("../template/#{@file}", __dir__)
    FileUtils.cp dist_file, @file
  end
  @config = YAML.load_file @file
  return {} unless @config

  @config
end

#reposObject



36
37
38
# File 'lib/whatsup_github/config_reader.rb', line 36

def repos
  read['repos']
end

#required_labelsObject



52
53
54
55
56
57
# File 'lib/whatsup_github/config_reader.rb', line 52

def required_labels
  res = read.dig 'labels', 'required'
  return [] unless res

  res
end