public
Description: my random ruby scripts
Homepage:
Clone URL: git://github.com/kastner/ruby-junk.git
Click here to lend your support to: ruby-junk and make a donation at www.pledgie.com !
ruby-junk / ar_play_for_so.rb
100755 51 lines (41 sloc) 1.122 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env ruby
%w|rubygems active_record irb|.each {|lib| require lib}
ActiveSupport::Inflector.inflections.singular("toyota", "toyota")
 
class Car < ActiveRecord::Base
end
 
class CarWheelMap < ActiveRecord::Base
end
 
%w|ford buick toyota|.each do |car_type|
eval <<-CLASS
class #{car_type.classify}Wheels < ActiveRecord::Base
set_table_name "wheels_for_#{car_type.pluralize}"
CLASS
end
 
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Base.establish_connection(
:adapter => "sqlite3",
:database => ":memory:"
)
 
ActiveRecord::Schema.define do
create_table :cars do |t|
t.string :name
end
 
create_table :car_to_wheel_table_map, :id => false do |t|
t.integer :car_id
t.string :wheel_table
end
%w|ford buick toyta|.each do |car_type|
create_table "wheels_for_#{car_type.pluralize}" do
t.integer :car_id
t.string :color
end
end
end
 
 
10.times do |i|
start = i * 10 + 1
group = Group.create(:name => "#{start} to #{start+9}")
10.times do |i|
    group.numbers << Number.create(:number => i + start)
  end
end
 
IRB.start if __FILE__ == $0