Skip to content

Commit 40297b3

Browse files
committed
Add Gemfiles
1 parent c3f70f4 commit 40297b3

18 files changed

+407
-66
lines changed

Gemfile

+13-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
source 'https://rubygems.org'
22

3-
gem 'serve', '1.5.2', git: 'git://github.com/danielstutzman/serve.git'
3+
gem 'activerecord', '~> 4.0', require: 'active_record'
4+
gem 'activerecord-postgresql-adapter'
45

5-
# for Rails form helpers
6-
gem 'actionpack', '~> 4.0.0', require: 'action_view'
6+
gem 'standalone_migrations',
7+
git: 'https://github.com/thinkerbot/standalone-migrations',
8+
branch: 'rails4.0.0', ref: '55767'
79

8-
gem 'rack-piwik', git: 'git://github.com/danielstutzman/rack-piwik.git'
9-
#gem 'rack-piwik', path: '/Users/daniel/dev/rack-piwik'
10+
gem 'sinatra'
11+
gem 'actionpack', require: 'action_view' # for Rails form helpers
12+
gem 'dynamic_form' # for error_messages_for
13+
14+
gem 'rack-flash3', require: 'rack-flash'
15+
gem 'sinatra-footnotes'
16+
gem 'bcrypt-ruby', '~> 3.0.0'
17+
gem 'will_paginate', '~> 3.0.0'

Gemfile.lock

+54-20
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
GIT
2-
remote: git://github.com/danielstutzman/rack-piwik.git
3-
revision: 2c08a1c3695ce642c852f9fbed63485a8e2d18be
2+
remote: https://github.com/thinkerbot/standalone-migrations
3+
revision: 55767bb07fe3bcbcb0e4c111dd9f368380d8e766
4+
ref: 55767
5+
branch: rails4.0.0
46
specs:
5-
rack-piwik (0.0.1)
6-
rack
7-
8-
GIT
9-
remote: git://github.com/danielstutzman/serve.git
10-
revision: c5c15dc574d1dccac73b84eaffe1e70624b37020
11-
specs:
12-
serve (1.5.2)
13-
activesupport (> 3.2.12)
14-
i18n
15-
rack (~> 1.5.2)
16-
rack-test (~> 0.6.2)
17-
tilt (~> 1.3.3)
18-
tzinfo
7+
standalone_migrations (2.1.1)
8+
activerecord (~> 4.0.0)
9+
railties (~> 4.0.0)
10+
rake
1911

2012
GEM
2113
remote: https://rubygems.org/
@@ -26,30 +18,72 @@ GEM
2618
erubis (~> 2.7.0)
2719
rack (~> 1.5.2)
2820
rack-test (~> 0.6.2)
21+
activemodel (4.0.0)
22+
activesupport (= 4.0.0)
23+
builder (~> 3.1.0)
24+
activerecord (4.0.0)
25+
activemodel (= 4.0.0)
26+
activerecord-deprecated_finders (~> 1.0.2)
27+
activesupport (= 4.0.0)
28+
arel (~> 4.0.0)
29+
activerecord-deprecated_finders (1.0.3)
30+
activerecord-postgresql-adapter (0.0.1)
31+
pg
2932
activesupport (4.0.0)
3033
i18n (~> 0.6, >= 0.6.4)
3134
minitest (~> 4.2)
3235
multi_json (~> 1.3)
3336
thread_safe (~> 0.1)
3437
tzinfo (~> 0.3.37)
38+
arel (4.0.0)
3539
atomic (1.1.14)
40+
bcrypt-ruby (3.0.1)
3641
builder (3.1.4)
42+
dynamic_form (1.1.4)
3743
erubis (2.7.0)
3844
i18n (0.6.5)
3945
minitest (4.7.5)
4046
multi_json (1.8.1)
47+
pg (0.17.0)
4148
rack (1.5.2)
49+
rack-flash3 (1.0.5)
50+
rack
51+
rack-protection (1.5.0)
52+
rack
4253
rack-test (0.6.2)
4354
rack (>= 1.0)
55+
railties (4.0.0)
56+
actionpack (= 4.0.0)
57+
activesupport (= 4.0.0)
58+
rake (>= 0.8.7)
59+
thor (>= 0.18.1, < 2.0)
60+
rake (10.1.0)
61+
sinatra (1.4.3)
62+
rack (~> 1.4)
63+
rack-protection (~> 1.4)
64+
tilt (~> 1.3, >= 1.3.4)
65+
sinatra-footnotes (0.1.2)
66+
activesupport
67+
i18n
68+
sinatra
69+
thor (0.18.1)
4470
thread_safe (0.1.3)
4571
atomic
46-
tilt (1.3.7)
72+
tilt (1.4.1)
4773
tzinfo (0.3.37)
74+
will_paginate (3.0.5)
4875

4976
PLATFORMS
5077
ruby
5178

5279
DEPENDENCIES
53-
actionpack (~> 4.0.0)
54-
rack-piwik!
55-
serve (= 1.5.2)!
80+
actionpack
81+
activerecord (~> 4.0)
82+
activerecord-postgresql-adapter
83+
bcrypt-ruby (~> 3.0.0)
84+
dynamic_form
85+
rack-flash3
86+
sinatra
87+
sinatra-footnotes
88+
standalone_migrations!
89+
will_paginate (~> 3.0.0)

Rakefile

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
require 'bundler'
2+
Bundler.require
3+
4+
require 'standalone_migrations'
5+
require 'will_paginate/active_record' if defined? WillPaginate
6+
7+
# Use config/database.yml instead of db/config.yml for db connection config
8+
module StandaloneMigrations
9+
class Configurator
10+
def config
11+
'config/database.yml'
12+
end
13+
end
14+
end
15+
16+
if File.exists?('db')
17+
StandaloneMigrations::Tasks.load_tasks
18+
19+
# Load models from models directory, like Rails (for db:seed task)
20+
Dir['./models/*.rb'].each { |file| require file }
21+
end
22+
23+
desc "Run a Pry session with models from Sinatra app specified by config.ru"
24+
task :console do
25+
require 'rack'
26+
require 'pry'
27+
28+
# load Sinatra app specified in config.ru
29+
app, options = Rack::Builder.parse_file('config.ru')
30+
31+
# 'rake console' is two words; remove first so can specify pry args
32+
ARGV.shift
33+
34+
# like running pry from command line
35+
Pry::CLI.parse_options # like running pry from command line
36+
end
37+
38+
desc "List routes of the Sinatra app specified in config.ru"
39+
task :routes do
40+
require 'rack'
41+
42+
# load Sinatra app specified in config.ru
43+
app, options = Rack::Builder.parse_file('config.ru')
44+
45+
# thanks to cldwalker's tux gem for this code to interpret Sinatra routes
46+
routes = app.routes.inject([]) {|arr, (k,v)|
47+
arr += v.map {|regex,params,*|
48+
path = params.empty? ? regex.inspect :
49+
params.inject(regex.inspect) {|s,e| s.sub(/\([^()]+\)/, ":#{e}") }
50+
[k, (str = path[%r{/\^(.*)\$/}, 1]) ? str.tr('\\', '') : path]
51+
}
52+
}
53+
54+
# still need to pull the regex syntax out
55+
routes = routes.map do |method_and_path|
56+
method, path = method_and_path
57+
path = path.to_s.gsub("\\/", "/").gsub(%r[^/\\A], "").gsub(%r[\\z/$], "")
58+
"#{method} #{path}"
59+
end
60+
61+
# don't show HEAD requests
62+
routes = routes.reject! { |route| route =~ /^HEAD / }
63+
64+
# GET and POST paths should line up at the same column
65+
routes.each { |route| route.gsub! /^GET /, "GET " }
66+
67+
routes.each { |route| puts route }
68+
end
69+
70+
namespace :db do
71+
desc "Show tables' schema and data in db specified by config/database.yml"
72+
task :dump do
73+
require './davinci-sinatra.rb'
74+
ActiveRecord::Base.logger = nil # turn off SQL logging
75+
76+
sql = "select tablename from pg_tables where schemaname = 'public'"
77+
rows = ActiveRecord::Base.connection.execute(sql)
78+
rows.each do |row|
79+
table_name = row['tablename']
80+
puts "#{'_' * 25} #{table_name} table #{'_' * (42 - table_name.size)}"
81+
82+
sql = "select column_name,
83+
case when udt_name = 'varchar'
84+
then concat('varchar(', character_maximum_length, ')')
85+
else data_type end as data_type,
86+
is_nullable
87+
from information_schema.columns
88+
where table_name = '#{table_name}'
89+
and table_schema = 'public'
90+
order by ordinal_position"
91+
rows2 = ActiveRecord::Base.connection.execute(sql)
92+
longest_name_length =
93+
rows2.collect { |row2| row2['column_name'].size }.max + 1
94+
rows2.each_with_index do |row2, i|
95+
puts sprintf("| Type of %-#{longest_name_length}s %s %s",
96+
row2['column_name'] + ':',
97+
row2['data_type'],
98+
row2['is_nullable'] ? '' : 'not null')
99+
end
100+
puts '' # to separate schema from data
101+
102+
sql = "select * from #{table_name};"
103+
rows2 = ActiveRecord::Base.connection.execute(sql)
104+
if rows2.first
105+
keys = rows2.first.keys
106+
longest_key_length = keys.collect { |key| key.size }.max
107+
rows2.each_with_index do |row2, i|
108+
puts '' unless i == 0 # separation between rows
109+
keys.each do |key|
110+
value = row2[key]
111+
value = 'NULL' if value.nil?
112+
puts sprintf("%#{longest_key_length}s: %s", key, value)
113+
end
114+
end
115+
end
116+
end
117+
puts '_' * 75
118+
end
119+
end

config.ru

+2-17
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,6 @@ rescue Bundler::BundlerError => e
88
exit e.status_code
99
end
1010

11-
require 'serve'
12-
require 'serve/rack'
13-
require 'action_view' # for Rails form helpers
11+
require './controller.rb'
1412

15-
# The project root directory
16-
root = ::File.dirname(__FILE__)
17-
18-
require 'rack/piwik'
19-
use Rack::Piwik, piwik_url: "http://www.davincicoders2013.info/analytics/"
20-
21-
# Other Rack Middleware
22-
use Rack::ShowStatus # Nice looking 404s and other messages
23-
use Rack::ShowExceptions # Nice looking errors
24-
25-
run Rack::Cascade.new([
26-
Serve::RackAdapter.new(root + '/views'),
27-
Rack::Directory.new(root + '/public')
28-
])
13+
run Sinatra::Application

config/database.yml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
development:
2+
adapter: postgresql
3+
host: localhost
4+
database: "200"
5+
username: postgres
6+
password: postgres
7+
encoding: unicode

controller.rb

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
require './davinci-sinatra.rb'
2+
3+
get "/" do
4+
halt erb(:index)
5+
end

davinci-sinatra.rb

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
require 'active_record'
2+
require 'logger'
3+
require 'sinatra'
4+
require 'yaml'
5+
require 'action_view' # for Rails form helpers
6+
require 'will_paginate/active_record'
7+
require 'sinatra-footnotes'
8+
require 'rack-flash'
9+
require 'dynamic_form'
10+
11+
# Enable sessions -- hardcoded secret to avoid logout on server restart.
12+
use Rack::Session::Cookie,
13+
secret: '524aee674662bbe8a363988a7b4dbcb304f52ae61ef12fc1f3b6a34d8388c71202'
14+
15+
use Rack::Flash, sweep: true
16+
17+
# for Rails form helpers
18+
helpers ActionView::Helpers::FormTagHelper
19+
helpers ActionView::Helpers::FormOptionsHelper
20+
helpers ActionView::Helpers::DynamicForm
21+
22+
# avoid error message that we get from using Rails form helpers with Sinatra
23+
helpers do
24+
def protect_against_forgery?
25+
false
26+
end
27+
end
28+
29+
# Comment this line to turn off Active Record SQL logging
30+
ActiveRecord::Base.logger = Logger.new(STDOUT)
31+
32+
if ENV['DATABASE_URL'] # for Heroku
33+
db = URI.parse(ENV['DATABASE_URL'])
34+
ActiveRecord::Base.establish_connection({
35+
adapter: db.scheme == 'postgres' ? 'postgresql' : db.scheme,
36+
host: db.host,
37+
port: db.port,
38+
username: db.user,
39+
password: db.password,
40+
database: db.path[1..-1],
41+
encoding: 'utf8',
42+
})
43+
elsif Dir.exists?('db') # for local development
44+
config = YAML.load_file('config/database.yml')
45+
ActiveRecord::Base.establish_connection(config['development'])
46+
47+
after { ActiveRecord::Base.connection.close }
48+
# fix ConnectionTimeoutError
49+
end
50+
51+
# Load models from models directory, like Rails
52+
Dir['./models/*.rb'].each { |file| require file }
53+
54+
# Enable use of .html.erb extension
55+
Tilt.register Tilt::ERBTemplate, 'html.erb'
File renamed without changes.

db/schema.rb

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# encoding: UTF-8
2+
# This file is auto-generated from the current state of the database. Instead
3+
# of editing this file, please use the migrations feature of Active Record to
4+
# incrementally modify your database, and then regenerate this schema definition.
5+
#
6+
# Note that this schema.rb definition is the authoritative source for your
7+
# database schema. If you need to create the application database on another
8+
# system, you should be using db:schema:load, not running all the migrations
9+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
10+
# you'll amass, the slower it'll run and the greater likelihood for issues).
11+
#
12+
# It's strongly recommended that you check this file into your version control system.
13+
14+
ActiveRecord::Schema.define(version: 0) do
15+
16+
end

db/seeds.rb

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# This file should contain all the record creation needed to seed the database with its default values.
2+
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
3+
#
4+
# Examples:
5+
#
6+
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
7+
# Mayor.create(name: 'Emanuel', city: cities.first)

models/.gitkeep

Whitespace-only changes.

public/favicon.ico

6.61 KB
Binary file not shown.

0 commit comments

Comments
 (0)