Class: Jenkins::Builder::Config
- Inherits:
-
Object
- Object
- Jenkins::Builder::Config
- Defined in:
- lib/jenkins/builder/config.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#file ⇒ Object
Returns the value of attribute file.
-
#service ⇒ Object
Returns the value of attribute service.
Instance Method Summary collapse
- #[](k) ⇒ Object
- #[]=(k, v) ⇒ Object
- #aliases ⇒ Object
- #aliases=(aliases) ⇒ Object
- #branches ⇒ Object
- #branches=(branches) ⇒ Object
- #hooks_of(job) ⇒ Object
- #init ⇒ Object
-
#initialize(service = nil) ⇒ Config
constructor
A new instance of Config.
- #load(file) ⇒ Object
- #password ⇒ Object
- #password=(passwd) ⇒ Object
- #save(config, file) ⇒ Object
- #save! ⇒ Object
- #services ⇒ Object
- #url ⇒ Object
- #url=(url) ⇒ Object
- #username ⇒ Object
- #username=(name) ⇒ Object
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.('~/.jenkins-builder.yaml') if File.exist?(@file) @config = load(@file) else init end end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
7 8 9 |
# File 'lib/jenkins/builder/config.rb', line 7 def config @config end |
#file ⇒ Object
Returns the value of attribute file.
7 8 9 |
# File 'lib/jenkins/builder/config.rb', line 7 def file @file end |
#service ⇒ Object
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 |
#aliases ⇒ Object
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 |
#branches ⇒ Object
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 |
#init ⇒ Object
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 |
#password ⇒ Object
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 |
#services ⇒ Object
29 30 31 |
# File 'lib/jenkins/builder/config.rb', line 29 def services @config['services'].keys end |
#url ⇒ Object
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 |
#username ⇒ Object
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 |