Permalink
Browse files

Merge pull request #20 from carlosdp/revamp

Update Ruby/Gems and move static file serving to Rack
  • Loading branch information...
Kevin Burke
Kevin Burke committed Aug 2, 2013
2 parents 1dcca96 + 83fde79 commit a69d8e1016aad71292fdac971db9cd174f0fa7d2
Showing with 74 additions and 41 deletions.
  1. +1 −0 Gemfile
  2. +27 −24 Gemfile.lock
  3. +26 −17 app/models/db.rb
  4. +20 −0 config.ru
View
@@ -1,4 +1,5 @@
source 'https://rubygems.org'
+ruby '2.0.0'
gem 'sinatra', '~>1.0'
gem 'yajl-ruby', '~>1.1.0'
View
@@ -1,48 +1,51 @@
GEM
remote: https://rubygems.org/
specs:
- addressable (2.3.2)
+ addressable (2.3.5)
coderay (0.8.357)
- curb (0.7.8)
- faraday (0.8.4)
- multipart-post (~> 1.1)
- faraday_middleware (0.8.8)
+ curb (0.7.18)
+ faraday (0.8.8)
+ multipart-post (~> 1.2.0)
+ faraday_middleware (0.9.0)
faraday (>= 0.7.4, < 0.9)
hashie (1.2.0)
- json (1.7.3)
- mime-types (1.16)
- multi_json (1.3.6)
- multipart-post (1.1.5)
+ json (1.8.0)
+ mime-types (1.23)
+ multi_json (1.7.7)
+ multipart-post (1.2.0)
mustache (0.11.2)
oauth2 (0.5.2)
faraday (~> 0.7)
multi_json (~> 1.0)
- octokit (1.11.0)
+ octokit (1.13.0)
addressable (~> 2.2)
faraday (~> 0.8)
faraday_middleware (~> 0.8)
hashie (~> 1.2)
multi_json (~> 1.3)
- pg (0.14.1)
- rack (1.2.1)
- redis (3.0.2)
- rest-client (1.6.1)
+ pg (0.16.0)
+ rack (1.5.2)
+ rack-protection (1.5.0)
+ rack
+ redis (3.0.4)
+ rest-client (1.6.7)
mime-types (>= 1.16)
- shotgun (0.8)
+ shotgun (0.9)
rack (>= 1.0)
- sinatra (1.1.0)
- rack (~> 1.1)
- tilt (~> 1.1)
- sinatra_auth_github (0.10.0)
+ sinatra (1.4.3)
+ rack (~> 1.4)
+ rack-protection (~> 1.4)
+ tilt (~> 1.3, >= 1.3.4)
+ sinatra_auth_github (0.10.1)
sinatra (~> 1.0)
- warden-github (~> 0.10.0)
- tilt (1.1)
- warden (1.2.1)
+ warden-github (~> 0.10.2)
+ tilt (1.4.1)
+ warden (1.2.3)
rack (>= 1.0)
- warden-github (0.10.0)
+ warden-github (0.10.2)
json (~> 1.5)
oauth2 (~> 0.5.2)
- octokit (~> 1.11.0)
+ octokit (~> 1.13.0)
rest-client (~> 1.6.1)
warden (~> 1.0)
yajl-ruby (~> 1.1)
View
@@ -13,53 +13,62 @@ def self.decode(object)
end
class PostgresDB < AbstractDB
- CONN = PG::Connection::new(
- ENV.fetch("POSTGRES_HOST", "localhost"),
- ENV.fetch("POSTGRES_PORT", 5432),
- :dbname => ENV.fetch("POSTGRES_DATABASE", "hurls"),
- :user => ENV.fetch("POSTGRES_USER", "postgres"),
- :password => ENV.fetch("POSTGRES_PASSWORD", "postgres")
- )
+
+ def self.connection
+ @@connection ||= PG::Connection::new(
+ ENV.fetch("POSTGRES_HOST", "localhost"),
+ ENV.fetch("POSTGRES_PORT", 5432),
+ :dbname => ENV.fetch("POSTGRES_DATABASE", "hurls"),
+ :user => ENV.fetch("POSTGRES_USER", "postgres"),
+ :password => ENV.fetch("POSTGRES_PASSWORD", "postgres")
+ )
+ end
def self.select_query(scope)
- "SELECT content::bytea FROM %s WHERE id = $1 LIMIT 1" % CONN.escape_string(scope.to_s)
+ "SELECT content::bytea FROM %s WHERE id = $1 LIMIT 1" % connection.escape_string(scope.to_s)
end
def self.find(scope, id)
- CONN.exec(select_query(scope), [id], 1) do |result|
+ connection.exec(select_query(scope), [id], 1) do |result|
decode(result.getvalue(0, 0)) if result.num_tuples >= 1
end
end
def self.insert_query(scope)
- "INSERT INTO %s VALUES ($1::varchar, $2::bytea)" % CONN.escape_string(scope.to_s)
+ "INSERT INTO %s VALUES ($1::varchar, $2::bytea)" % connection.escape_string(scope.to_s)
end
def self.save(scope, id, content)
- CONN.exec(insert_query(scope), [id, {:value => encode(content), :format => 1}])
+ connection.exec(insert_query(scope), [id, {:value => encode(content), :format => 1}])
end
def self.count(scope)
- CONN.exec("SELECT COUNT(*) FROM %s" % CONN.escape_string(scope.to_s)) do |result|
+ connection.exec("SELECT COUNT(*) FROM %s" % connection.escape_string(scope.to_s)) do |result|
result.getvalue(0, 0)
end
end
end
class RedisDB < AbstractDB
- uri = URI.parse(ENV.fetch("REDISTOGO_URL", "redis://127.0.0.1:6379"))
- CONNECTION = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
+
+ def self.connection
+ @@uri = URI.parse(ENV.fetch("REDISTOGO_URL", "redis://127.0.0.1:6379"))
+ @@connection ||= Redis.new(
+ :host => @@uri.host,
+ :port => @@uri.port,
+ :password => @@uri.password)
+ end
def self.find(scope, id)
- decode(CONNECTION.get("hurl/#{scope}/#{id}"))
+ decode(connection.get("hurl/#{scope}/#{id}"))
end
def self.save(scope, id, content)
- CONNECTION.set("hurl/#{scope}/#{id}", encode(content))
+ connection.set("hurl/#{scope}/#{id}", encode(content))
end
def self.count(scope)
- CONNECTION.keys("hurl/#{scope}/*").size
+ connection.keys("hurl/#{scope}/*").size
end
end
View
@@ -10,4 +10,24 @@ end
require 'app/app'
+map "/js" do
+ run Rack::Directory.new("./public/js")
+end
+
+map "/css" do
+ run Rack::Directory.new("./public/css")
+end
+
+map "/img" do
+ run Rack::Directory.new("./public/img")
+end
+
+map "/favicon.ico" do
+ run Rack::File.new("./public/favicon.ico")
+end
+
+map "/robots.txt" do
+ run Rack::File.new("./public/robots.txt")
+end
+
run Hurl::App.new

0 comments on commit a69d8e1

Please sign in to comment.