Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Sowerbutts committed May 22, 2011
0 parents commit 24a710e
Show file tree
Hide file tree
Showing 9 changed files with 185 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Gemfile
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
35 changes: 35 additions & 0 deletions Gemfile.lock
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
33 changes: 33 additions & 0 deletions Rakefile
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 added bin/.town.swp
Binary file not shown.
71 changes: 71 additions & 0 deletions bin/town
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
7 changes: 7 additions & 0 deletions config/database.yml
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 added db/development.sqlite3
Binary file not shown.
16 changes: 16 additions & 0 deletions db/migrate/001_create_clocks.rb
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

15 changes: 15 additions & 0 deletions db/migrate/002_create_people.rb
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

0 comments on commit 24a710e

Please sign in to comment.