Module: Ginatra

Defined in:
lib/ginatra.rb,
lib/ginatra/repo.rb,
lib/ginatra/config.rb,
lib/ginatra/errors.rb,
lib/ginatra/logger.rb,
lib/ginatra/helpers.rb,
lib/ginatra/version.rb,
lib/ginatra/repo_list.rb,
lib/ginatra/repo_stats.rb

Defined Under Namespace

Modules: Helpers, Logger Classes: App, Error, InvalidRef, Repo, RepoList, RepoNotFound, RepoStats

Constant Summary collapse

VERSION =
"4.1.0"
RELEASE_NAME =
"Baku"

Class Method Summary collapse

Class Method Details

.configObject



5
6
7
# File 'lib/ginatra/config.rb', line 5

def self.config
  @config ||= OpenStruct.new load_config
end

.load_configHash

Loads the configuration and merges it with custom configuration if necessary.

Returns:

  • (Hash)

    config a hash of the configuration options



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ginatra/config.rb', line 13

def self.load_config
  current_path        = File.expand_path(File.dirname(__FILE__))
  custom_config_file  = File.expand_path("~/.ginatra/config.yml")
  default_config_file = File.expand_path("#{current_path}/../../config.yml")

  # Our own file should be there and we don't need to check its syntax
  abort 'ginatra config file #{default_config_file} is missing.' unless File.exists?(default_config_file)
  final_config = YAML.load_file(default_config_file)

  # User config file may not exist or be broken
  if File.exists?(custom_config_file)
    begin
      custom_config = YAML.load_file(custom_config_file)
    rescue Psych::SyntaxError => ex
      puts "Cannot parse your config file #{ex.message}."
      custom_config = {}
    end
    final_config.merge!(custom_config)
  else
    puts "User config file #{custom_config_file} absent. Will only see repos in #{final_config["git_dirs"].join(", ")}."
  end

  final_config
end