Class: Github::Archive::Connections
- Inherits:
-
Object
- Object
- Github::Archive::Connections
- Defined in:
- lib/github/archive/connections.rb
Constant Summary collapse
- SETTINGS =
{}
Class Method Summary collapse
- .config_mysql(server, user, password, database) ⇒ Object
- .config_redis(server, port, password) ⇒ Object
- .connect_mysql ⇒ Object
- .connect_redis ⇒ Object
- .init_settings ⇒ Object
- .read_settings ⇒ Object
- .write_settings ⇒ Object
Class Method Details
.config_mysql(server, user, password, database) ⇒ Object
16 17 18 19 20 21 |
# 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) ⇒ Object
36 37 38 39 40 |
# 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 ⇒ Object
7 8 9 10 11 12 13 14 |
# 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 ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# 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 ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# 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 ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# 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 ⇒ Object
71 72 73 74 75 |
# 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 |