This repository has been archived by the owner on Nov 10, 2017. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added a couple of comments regarding dependent gems. added initial sq…
…lite3 address book
- Loading branch information
1 parent
d1136a3
commit f2e90a5
Showing
4 changed files
with
40 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require 'singleton' | ||
require 'thread' | ||
require 'sqlite3' # gem install sqlite3-ruby | ||
|
||
class AddressBook | ||
include Singleton | ||
|
||
def initialize | ||
@mutex = Mutex.new | ||
end | ||
|
||
def configure(config) | ||
@db = SQLite3::Database.new(config['database']) | ||
@query = config['finder_sql'] | ||
end | ||
|
||
# this method should return an array of hosts which this request is qualified to connect to. | ||
# which is determined based on the contents of the data passed | ||
def lookup_addresses(data) | ||
# TODO: make this use real parameters from the data payload | ||
# Example: | ||
# req_host = data['host'] | ||
# @db.execute(@query, req_host) | ||
servers = [] | ||
@mutex.synchronize { | ||
@db.execute(@query) do |row| | ||
servers << {:host => row[0], :port => row[1]} | ||
end | ||
} | ||
return servers if servers.any? | ||
return nil | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters