Class: CIQuantum::Config

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command, project_path = nil, parent = nil) ⇒ Config

Returns a new instance of Config.



7
8
9
10
11
# File 'lib/ciquantum/config.rb', line 7

def initialize(command, project_path = nil, parent = nil)
  @command  = command
  @parent   = parent
  @project_path = project_path || File.join(File.dirname(__FILE__), '../../')
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(command, *args) ⇒ Object



13
14
15
# File 'lib/ciquantum/config.rb', line 13

def method_missing(command, *args)
  self[command]
end

Class Method Details

.method_missing(command, *args) ⇒ Object



3
4
5
# File 'lib/ciquantum/config.rb', line 3

def self.method_missing(command, *args)
  new(command, *args)
end

Instance Method Details

#[](command) ⇒ Object



17
18
19
# File 'lib/ciquantum/config.rb', line 17

def [](command)
  Config.new(command, @project_path, self)
end

#config_stringObject



34
35
36
# File 'lib/ciquantum/config.rb', line 34

def config_string
  @parent ? "#{@parent.config_string}.#{@command}" : @command
end

#set(value) ⇒ Object



38
39
40
41
42
43
# File 'lib/ciquantum/config.rb', line 38

def set value
  git_command = "cd #{@project_path} && git config --replace-all #{config_string} #{value.to_s}"
  puts "Executing command: #{git_command}"
  `#{git_command} 2>&1`
  successful_command? $?
end

#to_sObject



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ciquantum/config.rb', line 21

def to_s
  git_command = "cd #{@project_path} && git config #{config_string}"
  result = `#{git_command} 2>&1`.chomp
  process_status = $?

  if successful_command?(process_status) || config_command_with_empty_value?(result,process_status)
    return result
  else
    return ""
  end
end