Permalink
Browse files

More cleanup around dependencies

  • Loading branch information...
1 parent 5e14271 commit 68646bb2676e61d5764d4c71ddf066aa26869e43 @markmcspadden markmcspadden committed May 26, 2011
Showing with 39 additions and 43 deletions.
  1. +23 −12 README.textile
  2. +0 −7 database.yml.example
  3. +3 −1 lib/donors_choose.rb
  4. +2 −22 lib/donors_choose/data.rb
  5. +11 −1 test/test_helper.rb
View
@@ -2,18 +2,17 @@ h1. donors_choose
This library sprung from the 2011 Hacking Education contest for DonorsChoose.org. (http://www.donorschoose.org/hacking-education)
-The DCData module match up the normalized data provided by DonorsChoose.org to classes that inherit from ActiveRecord::Base.
+The DonorsChoose::Data module match up the normalized data provided by DonorsChoose.org to classes that inherit from ActiveRecord::Base.
*This gem assumes you have loaded the DonorsChoose.org datasets into a PostgreSQL database.*
h2. Usage
<code>
- project = DCData::Project.first
- project.donations
-
- school = DCData::School.last
- school.teachers
+project = DonorsChoose::Data::Project.first
+project.donations
+school = DonorsChoose::Data::School.last
+school.teachers
</code>
@@ -22,19 +21,31 @@ h3. Rails
If you'd like to use it in Rails, just add the following to your Gemfile:
<code>
- gem 'donors_choose'
+gem 'donors_choose'
</code>
h3. Stand alone
If you'd like to use it stand alone, do the following:
-Copy database.yml.example to database.yml and change the credentials to match your setup
+Create a database.yml, very similar to what you'd have in Rails:
+
+bq. adapter: postgresql
+host: localhost
+username: postgres
+password: password
+port: 5432
+database: donors_choose_data
+schema_search_path: public
+
+Then, drop into irb, require the gem, and establish the db connection
<code>
- terminal$ irb
- irb(main):001:0> require 'd_c_data'
- irb(main):001:0> DCData.connect
- irb(main):001:0> DCData::Project.first
+terminal$ irb
+irb(main):001:0> require 'rubygems'
+irb(main):001:0> require 'donors_choose'
+irb(main):001:0> DonorsChoose::Data.connect(YAML.load(File.read('database.yml')))
+irb(main):001:0> DonorsChoose::Data::Project.first
</code>
+
View
@@ -1,7 +0,0 @@
-adapter: postgresql
-host: localhost
-username: postgres
-password: password
-port: 5432
-database: donors_choose_data
-schema_search_path: public
View
@@ -1,3 +1,5 @@
module DonorsChoose
-end
+end
+
+require File.expand_path(File.dirname(__FILE__) + "/donors_choose/data")
View
@@ -1,31 +1,11 @@
require 'active_record'
require 'pg'
-require 'logger'
module DonorsChoose
module Data
-
- def self.setup_log(destination=STDOUT)
- puts "A log of the sql queries will be outputted to: #{destination}"
-
- if destination != STDOUT
- File.delete(destination) if File.exist?(destination)
- end
-
- log = Logger.new destination
- log.level = Logger::DEBUG
- ActiveRecord::Base.logger = log
- end
-
+
# Use this if you're going standalone (aka sans Rails)
- # Probably want to move database.yml.example to database.yml and change the credentials
- def self.connect
- puts "**** SETTING UP Postgresql ****"
-
- setup_log File.expand_path(File.dirname(__FILE__) + "/postgresql.log")
-
- postgres_config = YAML.load(File.read('database.yml'))
-
+ def self.connect(postgres_config = {})
# Connect with db
ActiveRecord::Base.establish_connection(postgres_config)
end
View
@@ -1,5 +1,15 @@
require 'test/unit'
+require 'rubygems'
+
require File.expand_path(File.dirname(__FILE__) + "/../lib/donors_choose/data")
-DonorsChoose::Data.connect
+postgres_config = { :adapter => "postgresql",
+ :host => "localhost",
+ :username => "postgres",
+ :password => "password",
+ :port => 5432,
+ :database => "donors_choose_data",
+ :schema_search_path => "public" }
+
+DonorsChoose::Data.connect postgres_config

0 comments on commit 68646bb

Please sign in to comment.