class Github::Archive::Connections

Constants

SETTINGS

Public Class Methods

config_mysql(server, user, password, database) click to toggle source
# File lib/github/archive/connections.rb, line 16
def config_mysql(server, user, password, database)
  SETTINGS['GHA']['MYSQL']['SERVER'] = server
  SETTINGS['GHA']['MYSQL']['USERNAME'] = user
  SETTINGS['GHA']['MYSQL']['PASSWORD'] = password
  SETTINGS['GHA']['MYSQL']['DATABASE'] = database
end
config_redis(server, port, password) click to toggle source
# File lib/github/archive/connections.rb, line 36
def config_redis(server, port, password)
  SETTINGS['GHA']['REDIS']['SERVER'] = server
  SETTINGS['GHA']['REDIS']['PORT'] = port
  SETTINGS['GHA']['REDIS']['PASSWORD'] = password
end
connect_mysql() click to toggle source
# File lib/github/archive/connections.rb, line 7
def connect_mysql
  ::ActiveRecord::Base.establish_connection( adapter: 'mysql',
      server: SETTINGS['GHA']['MYSQL']['SERVER'],
      username: SETTINGS['GHA']['MYSQL']['USERNAME'],
      password: SETTINGS['GHA']['MYSQL']['PASSWORD'],
      database: SETTINGS['GHA']['MYSQL']['DATABASE']
  )
end
connect_redis() click to toggle source
# File lib/github/archive/connections.rb, line 23
def connect_redis
  if SETTINGS['GHA']['REDIS']['PASSWORD'].nil?
    ::Resque.redis = Redis.new(:host => SETTINGS['GHA']['REDIS']['SERVER'],
                               :port => SETTINGS['GHA']['REDIS']['PORT'],
                               :thread_safe => true)
  else
    ::Resque.redis = Redis.new(:host => SETTINGS['GHA']['REDIS']['SERVER'],
                               :port => SETTINGS['GHA']['REDIS']['PORT'],
                               :password =>  SETTINGS['GHA']['REDIS']['PASSWORD'],
                               :thread_safe => true)
  end
end
init_settings() click to toggle source
# File lib/github/archive/connections.rb, line 42
def init_settings
  SETTINGS['GHA'] ||= {}
  SETTINGS['GHA']['MYSQL'] ||= {}
  SETTINGS['GHA']['MYSQL']['SERVER'] ||= 'localhost'
  SETTINGS['GHA']['MYSQL']['USERNAME'] ||= 'root'
  SETTINGS['GHA']['MYSQL']['PASSWORD'] ||= nil
  SETTINGS['GHA']['MYSQL']['DATABASE'] ||= 'github_archive'

  SETTINGS['GHA']['REDIS'] ||= {}
  SETTINGS['GHA']['REDIS']['SERVER'] ||= 'localhost'
  SETTINGS['GHA']['REDIS']['PASSWORD'] ||= nil
  SETTINGS['GHA']['REDIS']['PORT'] ||= '6379'
end
read_settings() click to toggle source
# File lib/github/archive/connections.rb, line 56
def read_settings
  if File.exist?(setting_path)
    settings = YAML::load_file setting_path

    config_mysql settings['MYSQL']['SERVER'],
                 settings['MYSQL']['USERNAME'],
                 settings['MYSQL']['PASSWORD'],
                 settings['MYSQL']['DATABASE']

    config_redis settings['REDIS']['SERVER'],
                 settings['REDIS']['PORT'],
                 settings['REDIS']['PASSWORD']
  end
end
write_settings() click to toggle source
# File lib/github/archive/connections.rb, line 71
def write_settings
  File.open(setting_path, "w") do |file|
    file.write SETTINGS['GHA'].to_yaml
  end
end

Private Class Methods

setting_path() click to toggle source
# File lib/github/archive/connections.rb, line 79
def setting_path
  "#{File.expand_path('~')}/.github-archive"
end