Class: Jenkins::Build::Configuration

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/jenkins/build/configuration.rb

Constant Summary collapse

CONFIG =
Pathname('.jenkins-build').freeze
CONFIG_KEYS =
[:server, :project, :api_key, :user]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(folder) ⇒ Configuration

Returns a new instance of Configuration.



23
24
25
26
# File 'lib/jenkins/build/configuration.rb', line 23

def initialize(folder)
  @config = Pathname(CONFIG).expand_path(folder).freeze
  @store = YAML::Store.new(@config)
end

Class Method Details

.currentObject



16
17
18
# File 'lib/jenkins/build/configuration.rb', line 16

def current
  new(Dir.pwd)
end

Instance Method Details

#exists?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/jenkins/build/configuration.rb', line 34

def exists?
  @config.exist?
end

#merge!(opts) ⇒ Object



38
39
40
41
42
# File 'lib/jenkins/build/configuration.rb', line 38

def merge!(opts)
  CONFIG_KEYS.each do |key|
    options[key] = opts[key]
  end
end

#optionsObject



44
45
46
# File 'lib/jenkins/build/configuration.rb', line 44

def options
  @options ||= read
end

#readObject



48
49
50
51
52
53
54
# File 'lib/jenkins/build/configuration.rb', line 48

def read
  @store.transaction(true) do
    @options = CONFIG_KEYS.map do |key|
      [ key, @store[key] ]
    end.to_h
  end
end

#write(options = @options) ⇒ Object



56
57
58
59
60
61
62
# File 'lib/jenkins/build/configuration.rb', line 56

def write(options = @options)
  @store.transaction do
    CONFIG_KEYS.each do |key|
      @store[key] = options.fetch(key)
    end
  end
end