Class: CIJoe::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/cijoe/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/cijoe/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/cijoe/config.rb', line 13

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

Class Method Details

.method_missing(command, *args) ⇒ Object



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

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

Instance Method Details

#config_stringObject



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

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

#to_sObject



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/cijoe/config.rb', line 17

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
    raise "Error calling git config, is a recent version of git installed? Command: #{git_command.inspect}, Error: #{result.inspect}, Status: #{process_status.inspect}"
  end
end