module GHRH::Config

Constants

API_URL
CACHE_DIR
CACHE_FILE
DEFAULT_HOST
HOST
USER_AGENT

Public Class Methods

fetch_hooks() click to toggle source
# File lib/ghrh/config.rb, line 41
def self.fetch_hooks
  resp = GHRH::Client.get("/hooks", :headers => {"User-Agent" => USER_AGENT})
  hooks_h = {}
  resp.each do |hook|
    hooks_h[hook['name']]=hook
  end
  File.open(CACHE_FILE, 'w').write(hooks_h.to_json)
  puts "Wrote hooks cache to #{CACHE_FILE}"
end
get(setting, default=nil) click to toggle source
# File lib/ghrh/config.rb, line 8
def self.get(setting, default=nil)
  # Check environment first, if setting is x.y env is X_Y
  value = ENV[setting.upcase.gsub('.', '_')] || ""

  # Check local git config
  value = %x{git config --local #{setting} 2>/dev/null}.strip if value.empty?

  # Check global git config
  value = %x{git config --global #{setting} 2>/dev/null}.strip if value.empty?

  # Return default if all above failed to return anything
  value = default if value.empty?

  value
end
hooks() click to toggle source
# File lib/ghrh/config.rb, line 51
def self.hooks
  if not File.directory? CACHE_DIR
    Dir.mkdir CACHE_DIR
  end

  if not File.exists? CACHE_FILE
    puts "No hooks cache found fetching"
    fetch_hooks
  end
  JSON.load File.read CACHE_FILE
end
scope() click to toggle source
# File lib/ghrh/config.rb, line 4
def self.scope
  File.exists?(File.join(Dir.pwd,'.git/config')) == true ? "local" : "global"
end
set(setting, value, config_scope=scope) click to toggle source
# File lib/ghrh/config.rb, line 36
def self.set(setting, value, config_scope=scope)
  # Set config setting, if user specified scope use that, else detect
  %x{git config --#{config_scope} #{setting} #{value}}
end
token() click to toggle source
# File lib/ghrh/config.rb, line 24
def self.token
  get('ghrh.token')
end