Class: Jenkins::Builder::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/jenkins/builder/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service = nil) ⇒ Config

Returns a new instance of Config.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/jenkins/builder/config.rb', line 9

def initialize(service = nil)

  @service = service
  @file = File.expand_path('~/.jenkins-builder.yaml')

  if File.exist?(@file)
    @config = load(@file)
  else
    init
  end
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



7
8
9
# File 'lib/jenkins/builder/config.rb', line 7

def config
  @config
end

#fileObject

Returns the value of attribute file.



7
8
9
# File 'lib/jenkins/builder/config.rb', line 7

def file
  @file
end

#serviceObject

Returns the value of attribute service.



7
8
9
# File 'lib/jenkins/builder/config.rb', line 7

def service
  @service
end

Instance Method Details

#[](k) ⇒ Object



21
22
23
# File 'lib/jenkins/builder/config.rb', line 21

def [](k)
  @config[k]
end

#[]=(k, v) ⇒ Object



25
26
27
# File 'lib/jenkins/builder/config.rb', line 25

def []=(k, v)
  @config[k] = v
end

#aliasesObject



49
50
51
# File 'lib/jenkins/builder/config.rb', line 49

def aliases
  @config['aliases']
end

#aliases=(aliases) ⇒ Object



53
54
55
# File 'lib/jenkins/builder/config.rb', line 53

def aliases=(aliases)
  @config['aliases'] = aliases
end

#branchesObject



65
66
67
# File 'lib/jenkins/builder/config.rb', line 65

def branches
  @config['branches']
end

#branches=(branches) ⇒ Object



69
70
71
# File 'lib/jenkins/builder/config.rb', line 69

def branches=(branches)
  @config['branches'] = branches
end

#hooks_of(job) ⇒ Object



73
74
75
76
77
# File 'lib/jenkins/builder/config.rb', line 73

def hooks_of(job)
  hooks = @config['services'][@service]['hooks'] && @config['services'][@service]['hooks'][job]
  hooks = [hooks] if hooks.is_a?(String)
  hooks
end

#initObject



79
80
81
82
# File 'lib/jenkins/builder/config.rb', line 79

def init
  @config = {}
  save(@config, @file)
end

#load(file) ⇒ Object



84
85
86
# File 'lib/jenkins/builder/config.rb', line 84

def load(file)
  YAML.load(File.read(file)) || {}
end

#passwordObject



41
42
43
# File 'lib/jenkins/builder/config.rb', line 41

def password
  @config['services'][@service]['password']
end

#password=(passwd) ⇒ Object



45
46
47
# File 'lib/jenkins/builder/config.rb', line 45

def password=(passwd)
  @config['services'][@service]['password'] = passwd
end

#save(config, file) ⇒ Object



88
89
90
91
92
93
94
# File 'lib/jenkins/builder/config.rb', line 88

def save(config, file)
  File.open(file, 'w') do |f|
    unless @config.empty?
      f.write(YAML.dump(config))
    end
  end
end

#save!Object



96
97
98
# File 'lib/jenkins/builder/config.rb', line 96

def save!
  save(@config, @file)
end

#servicesObject



29
30
31
# File 'lib/jenkins/builder/config.rb', line 29

def services
  @config['services'].keys
end

#urlObject



57
58
59
# File 'lib/jenkins/builder/config.rb', line 57

def url
  @service && @config['services'][@service]['url']
end

#url=(url) ⇒ Object



61
62
63
# File 'lib/jenkins/builder/config.rb', line 61

def url=(url)
  @config['services'][@service]['url'] = url
end

#usernameObject



33
34
35
# File 'lib/jenkins/builder/config.rb', line 33

def username
  @config['services'][@service]['username']
end

#username=(name) ⇒ Object



37
38
39
# File 'lib/jenkins/builder/config.rb', line 37

def username=(name)
  @config['services'][@service]['username'] = name
end