-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Peter Sowerbutts
committed
May 22, 2011
0 parents
commit 24a710e
Showing
9 changed files
with
185 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
source "http://rubygems.org" | ||
|
||
gem "activerecord" | ||
gem "sqlite3" | ||
|
||
group :test do | ||
gem "rspec" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
GEM | ||
remote: http://rubygems.org/ | ||
specs: | ||
activemodel (3.0.7) | ||
activesupport (= 3.0.7) | ||
builder (~> 2.1.2) | ||
i18n (~> 0.5.0) | ||
activerecord (3.0.7) | ||
activemodel (= 3.0.7) | ||
activesupport (= 3.0.7) | ||
arel (~> 2.0.2) | ||
tzinfo (~> 0.3.23) | ||
activesupport (3.0.7) | ||
arel (2.0.10) | ||
builder (2.1.2) | ||
diff-lcs (1.1.2) | ||
i18n (0.5.0) | ||
rspec (2.6.0) | ||
rspec-core (~> 2.6.0) | ||
rspec-expectations (~> 2.6.0) | ||
rspec-mocks (~> 2.6.0) | ||
rspec-core (2.6.3) | ||
rspec-expectations (2.6.0) | ||
diff-lcs (~> 1.1.2) | ||
rspec-mocks (2.6.0) | ||
sqlite3 (1.3.3) | ||
tzinfo (0.3.27) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
activerecord | ||
rspec | ||
sqlite3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#require 'bundler' | ||
#Bundler.setup | ||
#Bundler::GemHelper.install_tasks | ||
|
||
require 'active_record' | ||
require 'yaml' | ||
|
||
|
||
task :default => [:gem] | ||
#[:clean, :test, :gem] | ||
|
||
task :clean do | ||
# rm_rf "pkg" | ||
end | ||
|
||
task :test do | ||
Spec::Rake::SpecTask.new('spec') do |t| | ||
t.spec_files = FileList['spec/**/*.rb'] | ||
end | ||
end | ||
|
||
task :gem => :build | ||
|
||
desc "Migrate the database through scripts in db/migrate. Target specific version with VERSION=x" | ||
task :migrate => :environment do | ||
ActiveRecord::Migrator.migrate('db/migrate', ENV["VERSION"] ? ENV["VERSION"].to_i : nil ) | ||
end | ||
|
||
task :environment do | ||
ActiveRecord::Base.establish_connection(YAML::load(File.open('config/database.yml'))['development']) | ||
# ActiveRecord::Base.logger = Logger.new(File.open('database.log', 'a')) | ||
end | ||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#!/usr/bin/env ruby | ||
$LOAD_PATH.push File.join(File.dirname(__FILE__), "../lib") | ||
require 'town' | ||
|
||
require 'active_record' | ||
require 'yaml' | ||
|
||
class Test | ||
def puts(string) | ||
# Create a insert SQL statement | ||
print string | ||
end | ||
end | ||
test = Test.new | ||
test.puts "test" | ||
|
||
dbconfig = YAML::load(File.open('config/database.yml')) | ||
ActiveRecord::Base.establish_connection(dbconfig['development']) | ||
|
||
|
||
class Person < ActiveRecord::Base | ||
|
||
end | ||
|
||
class Clock < ActiveRecord::Base | ||
|
||
def update(values) | ||
values.each do |value| | ||
self.update_attribute(value[0],value[1]) | ||
end | ||
end | ||
|
||
end | ||
|
||
runner = Town::Runner.new(STDOUT, :output_format => "yaml") | ||
|
||
Person.delete_all | ||
runner.people.each do |person| | ||
yaml = YAML.load person.to_yaml | ||
Person.create(yaml['values']) | ||
end | ||
puts "People: #{Person.count}\n" | ||
puts "#{Clock.count}\n" | ||
#runner = Town::Runner.new(Test.new, :output_format => "yaml") | ||
|
||
yaml = YAML.load runner.clock.to_yaml | ||
Clock.delete_all | ||
clock = Clock.create yaml['values'] | ||
|
||
@action_generator = Town::ActionGenerator.new | ||
|
||
while true do | ||
runner.clock.tick | ||
yaml = YAML.load runner.clock.to_yaml | ||
puts yaml.inspect | ||
Clock.delete_all | ||
values = yaml['values'] | ||
Clock.create values | ||
puts "#{Clock.count}\n" | ||
@action_generator.time = runner.clock.time | ||
runner.people.each do |person| | ||
person.current_action = @action_generator.next_action(person) | ||
Person.delete_all | ||
yaml = YAML.load person.to_yaml | ||
Person.create(yaml['values']) | ||
puts yaml.inspect | ||
end | ||
sleep 1 | ||
end | ||
|
||
#runner.start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
development: | ||
adapter: postgresql | ||
database: town_development | ||
username: pete | ||
password: password | ||
pool: 5 | ||
timeout: 5000 |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class CreateClocks < ActiveRecord::Migration | ||
def self.up | ||
create_table :clocks do |t| | ||
t.integer :minute, :null => false | ||
t.integer :hour, :null => false | ||
t.integer :day, :null => false | ||
t.integer :month, :null => false | ||
t.integer :year, :null => false | ||
end | ||
end | ||
|
||
def self.down | ||
drop_table :clocks | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class CreatePeople < ActiveRecord::Migration | ||
def self.up | ||
create_table :people do |t| | ||
t.string :first_name, :null => false | ||
t.string :family_name, :null => false | ||
t.string :date_of_birth, :null => false | ||
t.string :current_action, :null => false | ||
end | ||
end | ||
|
||
def self.down | ||
drop_table :people | ||
end | ||
end | ||
|