-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
panda, tiger, eagle #13
base: master
Are you sure you want to change the base?
Changes from all commits
a68a493
f079d8d
974c5bd
c335508
5dd5166
b7d93bf
08f4de3
89b66c2
1fed194
63b24d7
bdb8776
4438eb0
cbbf8ce
1f5112d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,5 @@ doc/ | |
|
||
config/database.yml | ||
TODO | ||
.env | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
source 'http://rubygems.org' | ||
|
||
source "https://rubygems.org" | ||
ruby "2.1.0" | ||
gem 'rake' | ||
gem 'activesupport' | ||
gem 'activerecord' | ||
gem 'sinatra' | ||
gem 'sinatra-contrib' | ||
gem 'sinatra-activerecord' | ||
gem 'pg' | ||
gem 'puma' | ||
gem 'foreman' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,71 @@ | ||
GEM | ||
remote: http://rubygems.org/ | ||
remote: https://rubygems.org/ | ||
specs: | ||
activesupport (3.2.3) | ||
i18n (~> 0.6) | ||
multi_json (~> 1.0) | ||
backports (2.5.3) | ||
eventmachine (0.12.10) | ||
i18n (0.6.0) | ||
multi_json (1.3.5) | ||
rack (1.4.1) | ||
rack-protection (1.2.0) | ||
activemodel (4.0.2) | ||
activesupport (= 4.0.2) | ||
builder (~> 3.1.0) | ||
activerecord (4.0.2) | ||
activemodel (= 4.0.2) | ||
activerecord-deprecated_finders (~> 1.0.2) | ||
activesupport (= 4.0.2) | ||
arel (~> 4.0.0) | ||
activerecord-deprecated_finders (1.0.3) | ||
activesupport (4.0.2) | ||
i18n (~> 0.6, >= 0.6.4) | ||
minitest (~> 4.2) | ||
multi_json (~> 1.3) | ||
thread_safe (~> 0.1) | ||
tzinfo (~> 0.3.37) | ||
arel (4.0.1) | ||
atomic (1.1.14) | ||
backports (3.4.0) | ||
builder (3.1.4) | ||
dotenv (0.9.0) | ||
foreman (0.63.0) | ||
dotenv (>= 0.7) | ||
thor (>= 0.13.6) | ||
i18n (0.6.9) | ||
minitest (4.7.5) | ||
multi_json (1.8.4) | ||
pg (0.17.1) | ||
puma (2.7.1) | ||
rack (>= 1.1, < 2.0) | ||
rack (1.5.2) | ||
rack-protection (1.5.2) | ||
rack | ||
rack-test (0.6.1) | ||
rack-test (0.6.2) | ||
rack (>= 1.0) | ||
rake (0.9.2.2) | ||
sinatra (1.3.2) | ||
rack (~> 1.3, >= 1.3.6) | ||
rack-protection (~> 1.2) | ||
tilt (~> 1.3, >= 1.3.3) | ||
sinatra-contrib (1.3.1) | ||
rake (10.1.1) | ||
sinatra (1.4.4) | ||
rack (~> 1.4) | ||
rack-protection (~> 1.4) | ||
tilt (~> 1.3, >= 1.3.4) | ||
sinatra-activerecord (1.2.4) | ||
activerecord (>= 3.0) | ||
sinatra (~> 1.0) | ||
sinatra-contrib (1.4.2) | ||
backports (>= 2.0) | ||
eventmachine | ||
multi_json | ||
rack-protection | ||
rack-test | ||
sinatra (~> 1.3.0) | ||
sinatra (~> 1.4.0) | ||
tilt (~> 1.3) | ||
tilt (1.3.3) | ||
thor (0.18.1) | ||
thread_safe (0.1.3) | ||
atomic | ||
tilt (1.4.1) | ||
tzinfo (0.3.38) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
activerecord | ||
activesupport | ||
foreman | ||
pg | ||
puma | ||
rake | ||
sinatra | ||
sinatra-activerecord | ||
sinatra-contrib |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require './theweb' | ||
require 'sinatra/activerecord/rake' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
host: 'localhost' | ||
adapter: 'postgresql' | ||
database: 'episode5' | ||
username: albinosquirrelclimb | ||
encoding: 'utf8' | ||
pool: 5 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class CreatesPage < ActiveRecord::Migration | ||
def change | ||
create_table :pages do |t| | ||
t.text :content | ||
t.text :preview | ||
t.integer :option_ids, array: true, default: [] | ||
t.boolean :starting_point, default: false | ||
t.boolean :conclusion, default: false | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# This file is auto-generated from the current state of the database. Instead | ||
# of editing this file, please use the migrations feature of Active Record to | ||
# incrementally modify your database, and then regenerate this schema definition. | ||
# | ||
# Note that this schema.rb definition is the authoritative source for your | ||
# database schema. If you need to create the application database on another | ||
# system, you should be using db:schema:load, not running all the migrations | ||
# from scratch. The latter is a flawed and unsustainable approach (the more migrations | ||
# you'll amass, the slower it'll run and the greater likelihood for issues). | ||
# | ||
# It's strongly recommended that you check this file into your version control system. | ||
|
||
ActiveRecord::Schema.define(version: 1) do | ||
|
||
# These are extensions that must be enabled in order to support this database | ||
enable_extension "plpgsql" | ||
|
||
create_table "pages", force: true do |t| | ||
t.text "content" | ||
t.text "preview" | ||
t.integer "option_ids", default: [], array: true | ||
t.boolean "starting_point", default: false | ||
t.boolean "conclusion", default: false | ||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#options | ||
#fourth tier | ||
fourthTier_option1 = Page.create(conclusion: true, content: "You have tea with the monkey. Mmmm Earl Grey. You win!", preview: "Sir") | ||
|
||
fourthTier_option2 = Page.create(conclusion: true, content: "The monkey does not appreciate you calling him that. He throws his poo at you. You sulk home in disgrace.", preview: "Ma'am") | ||
|
||
#third tier | ||
thirdTier_option1 = Page.create(option_ids: [fourthTier_option1.id, fourthTier_option2.id], content: "How should you address the monkey?", preview: "Really? A monkey?" ) | ||
#second tier | ||
#path1 | ||
secondTier_option1 = Page.create(conclusion: true, content: "The duck gets mad and eats you. That was a terrible Quack", preview: "You quack at the duck.") | ||
|
||
secondTier_option2 = Page.create(option_ids: [thirdTier_option1.id], content: "Surprise! A monkey jumps in front of you!", preview: "You pat the duck.") | ||
|
||
#path2 | ||
secondTier_option3 = Page.create(conclusion: true, content: "Why would you pass up loot? You fall in the water. Eaten by sharks!? bummer!", preview: "Keep walking down the road toward the dock, ignoring the chest.") | ||
|
||
secondTier_option4 = Page.create(option_ids: [thirdTier_option1.id], content: "Surprise! A monkey jumps in front of you!", preview: "Bang open the chest with the hammer.") | ||
|
||
#firstTier | ||
#path1 | ||
firstTier_option1 = Page.create(option_ids: [secondTier_option1.id, secondTier_option2.id], content: "You see a duck", preview: "Walk into the forest") | ||
|
||
#path2 | ||
firstTier_option2 = Page.create(option_ids: [secondTier_option3.id, secondTier_option4.id], content: "You see a giant chest with a hammer beside it.", preview: "Walk down the road to the dock") | ||
|
||
#starting_page | ||
Page.create(starting_point: true, option_ids: [firstTier_option1.id, firstTier_option2.id], content: "You wake up on a road. It's foggy and dampy. In your bag is 30 gold pieces and a bacon sandwich. Which do you choose?") | ||
|
||
|
||
|
||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require 'pg' | ||
require 'active_record' | ||
require 'yaml' | ||
|
||
|
||
@connection_details = YAML::load(File.open('config/database.yml')) | ||
|
||
# # Setup out connection details | ||
ActiveRecord::Base.establish_connection(@connection_details.merge({'database'=> 'postgres', 'schema_search_path'=> 'public'})) | ||
# # # create the 'tv' database | ||
ActiveRecord::Base.connection.drop_database (connection_details.fetch('database')) rescue nil | ||
ActiveRecord::Base.connection.create_database(connection_details.fetch('database')) rescue nil | ||
# # # connect to it | ||
ActiveRecord::Base.connection_pool.with_connection do | ||
ActiveRecord::Base.establish_connection(@connection_details) | ||
end | ||
|
||
# # # Migrate all the things | ||
ActiveRecord::Migrator.migrate("db/migrate/") | ||
ActiveRecord::Base.connection.close | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
configure :development do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this file amazed me. I learned something today! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I struggled with the way we setup the connection to postgres in development and having that work on heroku. I spent a decently long time googling around to find a implementation file that would switch connection techniques depending on the environment. Here's the like that guided me to the solution http://mherman.org/blog/2013/06/08/designing-with-class-sinatra-plus-postgresql-plus-heroku/#.Uu-7AfldU1I There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another way COULD be to always connect via the connection string in ENV. |
||
require_relative 'db/setup' | ||
|
||
end | ||
|
||
configure :production do | ||
db = URI.parse(ENV['DATABASE_URL'] || 'postgres://localhost/mydb') | ||
|
||
ActiveRecord::Base.connection_pool.with_connection do | ||
ActiveRecord::Base.establish_connection( | ||
:adapter => db.scheme == 'postgres' ? 'postgresql' : db.scheme, | ||
:host => db.host, | ||
:username => db.user, | ||
:password => db.password, | ||
:database => db.path[1..-1], | ||
:encoding => 'utf8' | ||
) | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class Book | ||
|
||
attr_reader :current_page | ||
|
||
def initialize(starting_page) | ||
@current_page = starting_page | ||
end | ||
|
||
def input(input_string) | ||
if input_string.chomp == "A" | ||
@current_page = Page.find(current_page.option_ids.first) | ||
elsif input_string.chomp == "B" | ||
@current_page = Page.find(current_page.option_ids.last) | ||
end | ||
end | ||
|
||
def complete_game? | ||
current_page.conclusion? | ||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class Page < ActiveRecord::Base | ||
|
||
def self.starting_point | ||
Page.where(starting_point: true).first | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nicely done with the array in postgres. A++