Class: Gitnesse::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/gitnesse/configuration.rb

Defined Under Namespace

Classes: MultipleConfigFileError, NoConfigFileError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



12
13
14
15
16
17
# File 'lib/gitnesse/configuration.rb', line 12

def initialize
  @branch = 'master'
  @target_directory = File.join(Dir.pwd, 'features')
  @annotate_results = false
  @info = nil
end

Instance Attribute Details

#annotate_resultsObject

Returns the value of attribute annotate_results.



6
7
8
# File 'lib/gitnesse/configuration.rb', line 6

def annotate_results
  @annotate_results
end

#branchObject

Returns the value of attribute branch.



4
5
6
# File 'lib/gitnesse/configuration.rb', line 4

def branch
  @branch
end

#infoObject

Returns the value of attribute info.



7
8
9
# File 'lib/gitnesse/configuration.rb', line 7

def info
  @info
end

#repository_urlObject

Returns the value of attribute repository_url.



3
4
5
# File 'lib/gitnesse/configuration.rb', line 3

def repository_url
  @repository_url
end

#target_directoryObject

Returns the value of attribute target_directory.



5
6
7
# File 'lib/gitnesse/configuration.rb', line 5

def target_directory
  @target_directory
end

Class Method Details

.load_using_searchObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/gitnesse/configuration.rb', line 28

def self.load_using_search
  load(ENV['GITNESSE_CONFIG']) and return if ENV['GITNESSE_CONFIG']

  possible_config_files = Dir.glob(File.join("**", "gitnesse.rb"))

  files_with_config = possible_config_files.select do |file_name|
    if FileUtils.compare_file(__FILE__, file_name)
      false
    elsif File.fnmatch("vendor/**/*.rb", file_name)
      false
    else
      file_content = File.read(file_name)
      file_content.match("Gitnesse.configure")
    end
  end

  case files_with_config.length
    when 0
      raise NoConfigFileError, "Can't find a gitnesse.rb file with Gitnesse configuration."
    when 1
      load(File.absolute_path(files_with_config.first))
    else
      raise MultipleConfigFileError, "Several config files found: #{files_with_config.join(", ")}"
  end
end

Instance Method Details

#to_hashObject

Public: Returns the current Gitnesse configuration as a Hash

Returns a hash containing the current Gitnesse configuration



22
23
24
25
26
# File 'lib/gitnesse/configuration.rb', line 22

def to_hash
  { 'repository_url'   => @repository_url,
    'branch'           => @branch,
    'target_directory' => @target_directory }
end