Ruby Speaks
1 2 system "osascript -e 'say \"the rain in Spain falls mainly on the planes\"'"
DZone Snippets > heavysixer > ruby
13498 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
1 2 system "osascript -e 'say \"the rain in Spain falls mainly on the planes\"'"
1 2 #codename generated from the dictionary 3 REVISION_NUMBER = `svn info`.split("\n")[4][/\d+/].to_i 4 APP_CODENAME = IO.readlines("/usr/share/dict/words")[REVISION_NUMBER] 5
1 2 APP_VERSION = IO.popen("svn info").readlines[4]
1 2 # view 3 <%= form_tag :controller => :posts, :action => create %> 4 <%= text_field("post", "title", "size" => 20) %> 5 <%= text_field("user", "email", "size" => 20) %> 6 <%= end_form_tag %>
1 2 # posts_controller 3 class PostsController < ApplicationController 4 def create 5 @post = Post.create(params[:post]) 6 @user = User.create(params[:user]) 7 @post.users << @user 8 end 9 end
1 2 task :start_fresh => :environment do 3 Rake::Task[:clear_logs].invoke 4 puts 'clearing logs ...done' 5 6 Rake::Task[:recreate_database].invoke 7 puts 'recreate test database ...done' 8 puts 'recreate development database ...done' 9 10 ActiveRecord::Base.establish_connection(:development) 11 Rake::Task[:migrate].invoke 12 puts 'migrate the development database ...done' 13 14 Rake::Task[:load_fixtures_to_development].invoke 15 puts 'load fixtures into development database ...done' 16 17 ActiveRecord::Base.establish_connection(:test) 18 Rake::Task[:prepare_test_database].invoke 19 puts 'clone the development structure to test ...done' 20 end 21 22 desc "Load fixtures data into the test database" 23 task :load_fixtures_to_development => :environment do 24 require 'active_record/fixtures' 25 ActiveRecord::Base.establish_connection(:development) 26 Dir.glob(File.join(RAILS_ROOT, 'test', 'fixtures', '*.{yml,csv}')).each do |fixture_file| 27 Fixtures.create_fixtures('test/fixtures', File.basename(fixture_file, '.*')) 28 end 29 end 30 31 task :recreate_database => :environment do 32 abcs = ActiveRecord::Base.configurations 33 tdb = Array.new 34 tdb << 'test' 35 tdb << 'development' 36 37 for db in tdb 38 case abcs[db]["adapter"] 39 when "mysql" 40 ActiveRecord::Base.establish_connection(db.to_sym) 41 ActiveRecord::Base.connection.recreate_database(abcs[db]["database"]) 42 when "postgresql" 43 ENV['PGHOST'] = abcs[db]["host"] if abcs[db]["host"] 44 ENV['PGPORT'] = abcs[db]["port"].to_s if abcs[db]["port"] 45 ENV['PGPASSWORD'] = abcs[db]["password"].to_s if abcs[db]["password"] 46 enc_option = "-E #{abcs[db]["encoding"]}" if abcs[db]["encoding"] 47 `dropdb -U "#{abcs[db]["username"]}" #{abcs[db]["database"]}` 48 `createdb #{enc_option} -U "#{abcs[db]["username"]}" #{abcs[db]["database"]}` 49 when "sqlite","sqlite3" 50 dbfile = abcs[db]["database"] || abcs[db]["dbfile"] 51 File.delete(dbfile) if File.exist?(dbfile) 52 when "sqlserver" 53 dropfkscript = "#{abcs[db]["host"]}.#{abcs[db]["database"]}.DP1".gsub(/\\/,'-') 54 `osql -E -S #{abcs[db]["host"]} -d #{abcs[db]["database"]} -i db\\#{dropfkscript}` 55 `osql -E -S #{abcs[db]["host"]} -d #{abcs[db]["database"]} -i db\\#{RAILS_ENV}_structure.sql` 56 when "oci" 57 ActiveRecord::Base.establish_connection(db.to_sym) 58 ActiveRecord::Base.connection.structure_drop.split(";\n\n").each do |ddl| 59 ActiveRecord::Base.connection.execute(ddl) 60 end 61 else 62 raise "Task not supported by '#{abcs[db]["adapter"]}'" 63 end 64 end 65 end 66 67 desc "Start Application" 68 task :start do 69 system "ruby script/server" 70 end