From f4b8d9d896fb2338b2be2bf2e9630e9862c5dabe Mon Sep 17 00:00:00 2001 From: drammopo Date: Wed, 9 Apr 2014 23:03:49 +0200 Subject: [PATCH 1/2] Added Tiger level features --- Gemfile | 1 + Gemfile.lock | 12 ++++++++++++ adventure.rb | 13 +++++-------- config/database.yml.sample | 6 ------ db/migrate/001_creates_page.rb | 16 ++++++++-------- db/seed.rb | 10 ++++++++++ models/book.rb | 2 +- rakefile.rb | 1 + spec/spec_helper.rb | 6 +++--- 9 files changed, 41 insertions(+), 26 deletions(-) delete mode 100644 config/database.yml.sample diff --git a/Gemfile b/Gemfile index 5ac1d52..7f073f4 100644 --- a/Gemfile +++ b/Gemfile @@ -4,4 +4,5 @@ gem 'rake' gem 'rspec' gem 'activesupport' gem 'activerecord' +gem "sinatra-activerecord" gem 'pg' diff --git a/Gemfile.lock b/Gemfile.lock index 0facad0..90288c9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -18,6 +18,9 @@ GEM i18n (0.6.0) multi_json (1.3.4) pg (0.13.2) + rack (1.5.2) + rack-protection (1.5.3) + rack rake (0.9.2.2) rspec (2.10.0) rspec-core (~> 2.10.0) @@ -27,6 +30,14 @@ GEM rspec-expectations (2.10.0) diff-lcs (~> 1.1.3) rspec-mocks (2.10.1) + sinatra (1.3.2) + rack (~> 1.3, >= 1.3.6) + rack-protection (~> 1.2) + tilt (~> 1.3, >= 1.3.3) + sinatra-activerecord (1.7.0) + activerecord (>= 3.0) + sinatra (~> 1.0) + tilt (1.4.1) tzinfo (0.3.33) PLATFORMS @@ -38,3 +49,4 @@ DEPENDENCIES pg rake rspec + sinatra-activerecord diff --git a/adventure.rb b/adventure.rb index d65f616..3aacd15 100644 --- a/adventure.rb +++ b/adventure.rb @@ -4,12 +4,9 @@ require_relative 'db/setup' require_relative 'models/page' require_relative 'models/book' +require_relative "db/seed" -page = Page.create(starting_point: true, 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?") -Page.create(conclusion: true, parent_id: page.id, content: "Go into the forest") -Page.create(conclusion: true, parent_id: page.id, content: "Walk down the road") - -book = Book.new(page) +book = Book.new(Page.starting_point) until book.complete_game? do puts book.current_page.content @@ -17,7 +14,7 @@ puts " - [#{book.current_page.options.first.content}]" puts " - [#{book.current_page.options.last.content}]" puts "What do you want to do? Enter A or B" - + book.input( gets ) end @@ -30,6 +27,6 @@ puts "------------------------------------------" -puts book.current_page.content +puts book.current_page.content -puts "hope you won!" +puts "Hope you won!" diff --git a/config/database.yml.sample b/config/database.yml.sample deleted file mode 100644 index 2e5c2a9..0000000 --- a/config/database.yml.sample +++ /dev/null @@ -1,6 +0,0 @@ -host: 'localhost' -adapter: 'postgresql' -database: 'episode5' -username: XXXXXXX -encoding: 'utf8' -pool: 5 diff --git a/db/migrate/001_creates_page.rb b/db/migrate/001_creates_page.rb index 8a293c0..7aa12b3 100644 --- a/db/migrate/001_creates_page.rb +++ b/db/migrate/001_creates_page.rb @@ -1,10 +1,10 @@ class CreatesPage < ActiveRecord::Migration - def change - create_table :pages do |t| - t.text :content - t.integer :parent_id - t.boolean :starting_point, default: false - t.boolean :conclusion, default: false - end - end + def change + create_table :pages do |t| + t.text :content + t.integer :parent_id + t.boolean :starting_point, default: false + t.boolean :conclusion, default: false + end + end end diff --git a/db/seed.rb b/db/seed.rb index 1abe902..da737e6 100644 --- a/db/seed.rb +++ b/db/seed.rb @@ -1 +1,11 @@ # Cleaning Out +Page.delete_all + +start = Page.create(starting_point: true, 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?") +forest = Page.create(conclusion: false, parent_id: start.id, content: "Go into the forest") +road = Page.create(conclusion: false, parent_id: start.id, content: "Walk down the road") + +campfire = Page.create(conclusion: false, parent_id: forest.id, content: "Approach the campfire") +sandwich = Page.create(conclusion: false, parent_id: forest.id, content: "Sit down to eat your sandwich") +Page.create(conclusion: true, parent_id: campfire.id, content: "You're a winner. Get 30 gold pieces!") +Page.create(conclusion: true, parent_id: sandwich.id, content: "Eaten by sharks!? bummer!") diff --git a/models/book.rb b/models/book.rb index 5eb6f53..3c14935 100644 --- a/models/book.rb +++ b/models/book.rb @@ -7,7 +7,7 @@ def initialize(starting_page) end def input(input_string) - if input_string.chomp == "A" + if input_string.chomp == "A" @current_page = current_page.options.first elsif input_string.chomp == "B" @current_page = current_page.options.last diff --git a/rakefile.rb b/rakefile.rb index a547a71..2406bcc 100644 --- a/rakefile.rb +++ b/rakefile.rb @@ -2,6 +2,7 @@ require "bundler/setup" require 'rspec/core/rake_task' +require 'active_record' desc 'Default: run specs.' task :default => :spec diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index bdb95b8..a17e8e1 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,5 @@ -require "rspec" +require 'rspec' require 'bundler/setup' require_relative '../db/setup' -require_relative "../models/page" -require_relative "../models/book" +require_relative '../models/page' +require_relative '../models/book' From 30a0d1cdeb959d8107812237dfc15ddc8e63766c Mon Sep 17 00:00:00 2001 From: drammopo Date: Thu, 10 Apr 2014 00:32:23 -0700 Subject: [PATCH 2/2] Removed unused gem sinatra-activerecord --- Gemfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Gemfile b/Gemfile index 7f073f4..5ac1d52 100644 --- a/Gemfile +++ b/Gemfile @@ -4,5 +4,4 @@ gem 'rake' gem 'rspec' gem 'activesupport' gem 'activerecord' -gem "sinatra-activerecord" gem 'pg'