Skip to content
Browse files

add up urls, make app work for newer activesupport, add /reservations…

… list url
  • Loading branch information...
1 parent 7ef9857 commit 7d06b3beaef41b1fbef8ef324b58eabc50c04071 @tongueroo tongueroo committed Jun 2, 2013
View
3 .gitignore
@@ -2,8 +2,9 @@
.DS_Store
*.gem
*.log
+config/redis.yml
config/database.yml
config/deploy.rb
log
pkg
-tmp
+tmp
View
4 Gemfile
@@ -9,4 +9,6 @@ gem "haml", "= 3.1.2"
gem "lilypad", "= 0.3.1"
gem "redis", "= 2.2.2"
gem "sinatra", "= 1.2.6"
-gem "yajl-ruby", "= 1.0.0"
+gem "activesupport"
+gem "yajl-ruby", "= 1.0.0"
+gem "unicorn"
View
13 Gemfile.lock
@@ -1,31 +1,44 @@
GEM
remote: http://rubygems.org/
specs:
+ activesupport (3.2.13)
+ i18n (= 0.6.1)
+ multi_json (~> 1.0)
builder (3.0.0)
haml (3.1.2)
+ i18n (0.6.1)
+ kgio (2.8.0)
lilypad (0.3.1)
builder (>= 2.1.2)
require (= 0.2.6)
+ multi_json (1.7.3)
rack (1.3.4)
rack-test (0.6.1)
rack (>= 1.0)
+ raindrops (0.11.0)
redis (2.2.2)
require (0.2.6)
rspec (1.3.2)
sinatra (1.2.6)
rack (~> 1.1)
tilt (>= 1.2.2, < 2.0)
tilt (1.3.3)
+ unicorn (4.6.2)
+ kgio (~> 2.6)
+ rack
+ raindrops (~> 0.7)
yajl-ruby (1.0.0)
PLATFORMS
ruby
DEPENDENCIES
+ activesupport
haml (= 3.1.2)
lilypad (= 0.3.1)
rack-test (= 0.6.1)
redis (= 2.2.2)
rspec (~> 1.0)
sinatra (= 1.2.6)
+ unicorn
yajl-ruby (= 1.0.0)
View
1 Procfile
@@ -0,0 +1 @@
+app: bundle exec unicorn -p $PORT
View
4 config/redis.example.yml
@@ -1,8 +1,8 @@
development:
- platform:
+ maitre_d:
host: localhost
port: 6379
production:
- platform:
+ maitre_d:
host: localhost
port: 6379
View
2 lib/application/redis.rb
@@ -1,4 +1,5 @@
require 'redis'
+require 'yaml'
def redis
$redis ||= (
@@ -21,6 +22,7 @@ def redis
)
end
)
+ puts "yo2"
end
redis
View
6 lib/maitre_d/controller/pulse.rb
@@ -1,6 +0,0 @@
-Application.class_eval do
-
- get '/pulse' do
- "#{self.class.environment} OK"
- end
-end
View
5 lib/maitre_d/controller/reservations.rb
@@ -16,6 +16,11 @@
Reservation.find(params).to_response
end
+ get '/reservations' do
+ reservations = Reservation.all.collect {|r| r.attributes}
+ Yajl::Encoder.encode(reservations)
+ end
+
get '/reservations/destroy' do
reservation = Reservation.find(params)
reservation.destroy
View
14 lib/maitre_d/controller/up.rb
@@ -0,0 +1,14 @@
+Application.class_eval do
+
+ get '/up' do
+ "#{self.class.environment} OK"
+ end
+
+ get '/up/elb' do
+ "#{self.class.environment} OK"
+ end
+
+ get '/up/sms' do
+ "#{self.class.environment} OK"
+ end
+end
View
20 lib/maitre_d/model/reservation.rb
@@ -4,6 +4,8 @@ class Reservation
attr_reader :attributes
+ @@namespace = "maitre_d"
+
def initialize(attributes={})
@attributes = attributes
end
@@ -30,9 +32,16 @@ def expire_at
Time.at(Time.now.to_i + attributes[:seconds].to_i)
end
+ def symbolize_keys(hash)
+ hash.inject({}) do |options, (key, value)|
+ options[(key.to_sym rescue key) || key] = value
+ options
+ end
+ end
+
def get
if val = $redis.get(key)
- val = Yajl::Parser.parse(val).symbolize_keys
+ val = symbolize_keys(Yajl::Parser.parse(val))
else
val = {}
end
@@ -42,7 +51,7 @@ def get
def key
raise "environment option not present" unless attributes[:environment]
- "maitre_d:#{attributes[:environment]}"
+ "#{@@namespace}:#{attributes[:environment]}"
end
def self.find(attributes)
@@ -51,6 +60,13 @@ def self.find(attributes)
res
end
+ def self.all
+ $redis.keys("#{@@namespace}:*").map do |key|
+ m = key.match(/maitre_d\:(.*)\:?/)
+ find(:environment => m[1]) if m and m[1]
+ end.compact
+ end
+
def to_response
if exists?
Yajl::Encoder.encode(value.merge(:status => 'reserved'))

0 comments on commit 7d06b3b

Please sign in to comment.
Something went wrong with that request. Please try again.