first commit

This commit is contained in:
Jörg Thalheim 2015-02-03 23:16:12 +01:00
commit cf35af7110
5 changed files with 97 additions and 0 deletions

7
Gemfile Normal file
View File

@ -0,0 +1,7 @@
# A sample Gemfile
source "https://rubygems.org"
gem "sinatra"
gem "sinatra-contrib"
gem "sequel"
gem "sqlite3"

33
Gemfile.lock Normal file
View File

@ -0,0 +1,33 @@
GEM
remote: https://rubygems.org/
specs:
backports (3.6.4)
multi_json (1.10.1)
rack (1.6.0)
rack-protection (1.5.3)
rack
rack-test (0.6.3)
rack (>= 1.0)
sequel (4.18.0)
sinatra (1.4.5)
rack (~> 1.4)
rack-protection (~> 1.4)
tilt (~> 1.3, >= 1.3.4)
sinatra-contrib (1.4.2)
backports (>= 2.0)
multi_json
rack-protection
rack-test
sinatra (~> 1.4.0)
tilt (~> 1.3)
sqlite3 (1.3.10)
tilt (1.4.1)
PLATFORMS
ruby
DEPENDENCIES
sequel
sinatra
sinatra-contrib
sqlite3

15
Rakefile Normal file
View File

@ -0,0 +1,15 @@
namespace :db do
require 'sequel'
Sequel.extension :migration
task :migrate do
m = Sequel::Migrator
db = Sequel.connect(ENV['DATABASE_URL'] || 'sqlite://library.sqlite')
dir = "migrations"
target = ENV['TARGET'] ? ENV['TARGET'].to_i : nil
current = ENV['CURRENT'] ? ENV['CURRENT'].to_i : nil
m.run(db, dir, target: target, current: current)
end
end

33
app.rb Normal file
View File

@ -0,0 +1,33 @@
require "sinatra"
require "sinatra/json"
require "sequel"
NODES = {}
Sequel.connect(ENV["DATABASE_URL"] || "sqlite://meet4eat.db")
class Node < Sequel::Model
def to_json(options={})
{
id: name,
room: room
}.to_json
end
end
get '/nodes' do
json({ nodes: Node.all })
end
put '/nodes/:id' do
node = Node.where(name: params[:id]).first
node ||= Node.new(name: params[:id])
node.room = params[:room] || "default"
node.save
json("")
end
delete '/nodes/:id' do
Node.where(name: params[:id]).delete
json("")
end

9
migrations/1_init_db.rb Normal file
View File

@ -0,0 +1,9 @@
Sequel.migration do
change do
create_table(:nodes) do
primary_key :id
String :room, null: false
String :name, null: false
end
end
end