scripts/console.rb in composite_primary_keys-1.0.8 vs scripts/console.rb in composite_primary_keys-1.0.10
- old
+ new
@@ -1,25 +1,48 @@
-# FIXME:
-# I haven't figured out how to setup an irb console yet.
-# So, from the root, run:
-# irb -f -r scripts/console
+#!/usr/bin/env ruby
-PROJECT_ROOT = '.' #File.join(File.dirname(__FILE__), '..')
+#
+# if run as script, load the file as library while starting irb
+#
+if __FILE__ == $0
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
+ ENV['ADAPTER'] = ARGV[0]
+ exec "#{irb} -f -r #{$0} --simple-prompt"
+end
-adapter = 'mysql'
-$:.unshift 'lib'
+#
+# check if the given adapter is supported (default: mysql)
+#
+adapters = %w[mysql sqlite oracle oracle_enhanced postgresql ibm_db]
+adapter = ENV['ADAPTER'] || 'mysql'
+unless adapters.include? adapter
+ puts "Usage: #{__FILE__} <adapter>"
+ puts ''
+ puts 'Adapters: '
+ puts adapters.map{ |adapter| " #{adapter}" }.join("\n")
+ exit 1
+end
-require "local/database_connections"
+#
+# load all necessary libraries
+#
+require 'rubygems'
+require 'local/database_connections'
+
+$LOAD_PATH.unshift 'lib'
+
begin
- require "local/paths"
- $:.unshift "#{ENV['EDGE_RAILS_DIR']}/activerecord/lib" if ENV['EDGE_RAILS_DIR']
- $:.unshift "#{ENV['EDGE_RAILS_DIR']}/activesupport/lib" if ENV['EDGE_RAILS_DIR']
+ require 'local/paths'
+ $LOAD_PATH.unshift "#{ENV['EDGE_RAILS_DIR']}/activerecord/lib" if ENV['EDGE_RAILS_DIR']
+ $LOAD_PATH.unshift "#{ENV['EDGE_RAILS_DIR']}/activesupport/lib" if ENV['EDGE_RAILS_DIR']
rescue
end
require 'active_support'
require 'active_record'
require "test/connections/native_#{adapter}/connection"
require 'composite_primary_keys'
+PROJECT_ROOT = File.join(File.dirname(__FILE__), '..')
Dir[File.join(PROJECT_ROOT,'test/fixtures/*.rb')].each { |model| require model }
+