Module: GitHub::Config

Defined in:
lib/github-api-client/config.rb

Overview

Keeps all the configuration stuff

Constant Summary collapse

Path =

Constant with defined all the paths used in the application

{
  :dir        => ENV['HOME'] + "/.github", 
  :dbfile     => ENV['HOME'] + "/.github/github.db", 
  :migrations => ROOT +  "/db/migrate", 
  :secrets    => ENV['HOME'] + "/.github" + "/secrets.yml"
}
Version =
File.read(
  ROOT + "/VERSION"
)
VERSION =
Version
Secrets =

Secrets array, uses env vars if defined

case
when ENV['GITHUB_USER'] && ENV['GITHUB_TOKEN']
  {
    "login" => ENV['GITHUB_USER'], 
    "token" => ENV['GITHUB_TOKEN']
  }
when `git config --global github.user` && !`git config --global github.token`
  {
    "login" => `git config --global github.user`.strip, 
    "token" => `git config --global github.token`.strip
  } if `git config --global github.user` && !`git config --global github.token`
else
  begin
    # If not env vars, then ~/.github/secrets.yml
    YAML::load_file(GitHub::Config::Path[:secrets])['user']
  rescue Errno::ENOENT
    # Eye candy with rainbow
    puts "You have three ways of defining your user to have authenticated access to your API:\n  \#{\"1.\".color(:cyan)} Put a file in: \#{GitHub::Config::Path[:secrets].color(:blue).bright}\nDefine in yaml:\n  \#{\"user\".color(:yellow).bright}:\n    \#{\"login\".color(:green).bright}: \#{\"your_login\".color(:magenta)}\n    \#{\"token\".color(:blue).bright}: \#{\"your_token\".color(:magenta)}\n  \#{\"2.\".color(:cyan)} Put \#{\"GITHUB_USER\".color(:green).bright} and \#{\"GITHUB_TOKEN\".color(:blue).bright} in your environment, so github-api-client can read it.\n  \#{\"3.\".color(:cyan)} Configure your global git profile as defined here \#{\"http://help.github.com/git-email-settings/\".color(:blue).bright}\n\n  report\n  end\nend\n"
Options =
{
  :verbose => false
}

Class Method Summary collapse

Class Method Details

.resetObject



67
68
69
70
# File 'lib/github-api-client/config.rb', line 67

def self.reset
  File.delete Path[:dbfile]
  setup
end

.setupnil

Sets up the database and migrates it

Returns:

  • (nil)


55
56
57
58
59
60
61
62
63
64
65
# File 'lib/github-api-client/config.rb', line 55

def self.setup
  Dir.mkdir GitHub::Config::Path[:dir] rescue nil
  ActiveRecord::Base.establish_connection(
    :adapter => 'sqlite3', 
    :database => GitHub::Config::Path[:dbfile]
  )
  ActiveRecord::Migrator.migrate(
    GitHub::Config::Path[:migrations], 
    nil
  ) if not File.exists? GitHub::Config::Path[:dbfile]
end