Permalink
Browse files

Attempt to make it more gem like

  • Loading branch information...
1 parent 61700a1 commit 5e1427141089373ac354d02947435bb6091ef48d @markmcspadden markmcspadden committed May 26, 2011
Showing with 332 additions and 271 deletions.
  1. +4 −0 Gemfile
  2. +2 −0 README.textile
  3. +9 −4 Rakefile
  4. +0 −38 d_c_data.rb
  5. +0 −8 d_c_data/account.rb
  6. +0 −7 d_c_data/city.rb
  7. +0 −6 d_c_data/donation.rb
  8. +0 −8 d_c_data/essay.rb
  9. +0 −6 d_c_data/giftcard.rb
  10. +0 −14 d_c_data/project.rb
  11. +0 −8 d_c_data/resource.rb
  12. +0 −9 d_c_data/school.rb
  13. +0 −9 d_c_data/teacher.rb
  14. +24 −0 donors_choose.gemspec
  15. +3 −0 lib/donors_choose.rb
  16. +38 −0 lib/donors_choose/data.rb
  17. +10 −0 lib/donors_choose/data/account.rb
  18. +9 −0 lib/donors_choose/data/city.rb
  19. +10 −0 lib/donors_choose/data/donation.rb
  20. +10 −0 lib/donors_choose/data/essay.rb
  21. +8 −0 lib/donors_choose/data/giftcard.rb
  22. +16 −0 lib/donors_choose/data/project.rb
  23. +10 −0 lib/donors_choose/data/resource.rb
  24. +11 −0 lib/donors_choose/data/school.rb
  25. +11 −0 lib/donors_choose/data/teacher.rb
  26. +3 −0 lib/donors_choose/version.rb
  27. +0 −17 test/d_c_data/account_test.rb
  28. +0 −16 test/d_c_data/donation_test.rb
  29. +0 −17 test/d_c_data/essay_test.rb
  30. +0 −13 test/d_c_data/giftcard_test.rb
  31. +0 −33 test/d_c_data/project_test.rb
  32. +0 −17 test/d_c_data/resource_test.rb
  33. +0 −16 test/d_c_data/school_test.rb
  34. +0 −21 test/d_c_data/teacher_test.rb
  35. +17 −0 test/donors_choose/data/account_test.rb
  36. +2 −2 test/{d_c_data → donors_choose/data}/city_test.rb
  37. +16 −0 test/donors_choose/data/donation_test.rb
  38. +17 −0 test/donors_choose/data/essay_test.rb
  39. +13 −0 test/donors_choose/data/giftcard_test.rb
  40. +33 −0 test/donors_choose/data/project_test.rb
  41. +17 −0 test/donors_choose/data/resource_test.rb
  42. +16 −0 test/donors_choose/data/school_test.rb
  43. +21 −0 test/donors_choose/data/teacher_test.rb
  44. +2 −2 test/test_helper.rb
View
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in donors_choose.gemspec
+gemspec
View
@@ -18,13 +18,15 @@ h2. Usage
h3. Rails
+
If you'd like to use it in Rails, just add the following to your Gemfile:
<code>
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
View
@@ -1,11 +1,16 @@
+# Bundler tasks
+require 'bundler'
+Bundler::GemHelper.install_tasks
+
+# Test tasks
require 'rake'
require 'rake/testtask'
-task :default => [:test_units]
-
desc "Run basic tests"
Rake::TestTask.new("test_units") { |t|
- t.pattern = 'test/*/*_test.rb'
+ t.pattern = 'test/*/*/*_test.rb'
t.verbose = true
t.warning = true
-}
+}
+
+task :default => [:test_units]
View
@@ -1,38 +0,0 @@
-require 'rubygems'
-require 'active_record'
-
-# Setup logging with ActiveRecord
-require 'logger'
-def 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
-
-module DCData
-
- # 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")
-
- require 'pg'
- postgres_config = YAML.load(File.read('database.yml'))
-
- # Connect with db
- ActiveRecord::Base.establish_connection(postgres_config)
- end
-
-end
-
-Dir.glob("#{File.dirname __FILE__}/d_c_data/*.rb").each do |f|
- require f
-end
View
@@ -1,8 +0,0 @@
-module DCData
- class Account < ActiveRecord::Base
- set_table_name :normalized_account
- set_primary_key :_acctid
-
- belongs_to :city, :foreign_key => :cityid
- end
-end
View
@@ -1,7 +0,0 @@
-module DCData
- class City < ActiveRecord::Base
- set_table_name :normalized_city
-
- has_many :accounts, :foreign_key => :cityid
- end
-end
View
@@ -1,6 +0,0 @@
-class Donation < ActiveRecord::Base
- set_table_name :normalized_donation
- set_primary_key :_donationid
-
- belongs_to :project, :foreign_key => :_projectid
-end
View
@@ -1,8 +0,0 @@
-module DCData
- class Essay < ActiveRecord::Base
- set_table_name :normalized_essay
- set_primary_key :_projectid
-
- belongs_to :project, :foreign_key => :_projectid
- end
-end
View
@@ -1,6 +0,0 @@
-module DCData
- class Giftcard < ActiveRecord::Base
- set_table_name :normalized_giftcard
- set_primary_key :_giftcardid
- end
-end
View
@@ -1,14 +0,0 @@
-module DCData
- class Project < ActiveRecord::Base
- set_table_name :normalized_project
- set_primary_key :_projectid
-
- belongs_to :school, :foreign_key => :_schoolid
- belongs_to :teacher, :foreign_key => :_teacher_acctid
-
- has_one :essay, :foreign_key => :_projectid
-
- has_many :donations, :foreign_key => :_projectid
- has_many :resources, :foreign_key => :_projectid
- end
-end
View
@@ -1,8 +0,0 @@
-module DCData
- class Resource < ActiveRecord::Base
- set_table_name :normalized_resource
- set_primary_key :_resourceid
-
- belongs_to :project, :foreign_key => :_projectid
- end
-end
View
@@ -1,9 +0,0 @@
-module DCData
- class School < ActiveRecord::Base
- set_table_name :normalized_school
- set_primary_key :_schoolid
-
- has_many :projects, :foreign_key => :_schoolid
- has_many :teachers, :through => :projects
- end
-end
View
@@ -1,9 +0,0 @@
-module DCData
- class Teacher < ActiveRecord::Base
- set_table_name :normalized_teacher
- set_primary_key :_teacher_acctid
-
- has_many :projects, :foreign_key => :_teacher_acctid
- has_many :schools, :through => :projects
- end
-end
View
@@ -0,0 +1,24 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "donors_choose/version"
+
+Gem::Specification.new do |s|
+ s.name = "donors_choose"
+ s.version = DonorsChoose::VERSION
+ s.platform = Gem::Platform::RUBY
+ s.authors = ["Mark McSpadden"]
+ s.email = [""]
+ s.homepage = ""
+ s.summary = %q{Libaries to assist with mining and utilizing donorschoose.org}
+ s.description = %q{}
+
+ s.rubyforge_project = "donors_choose"
+
+ s.add_dependency 'activerecord', '> 3.0'
+ s.add_dependency 'pg'
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+end
View
@@ -0,0 +1,3 @@
+module DonorsChoose
+
+end
View
@@ -0,0 +1,38 @@
+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'))
+
+ # Connect with db
+ ActiveRecord::Base.establish_connection(postgres_config)
+ end
+
+ Dir.glob("#{File.dirname __FILE__}/data/*.rb").each do |f|
+ require f
+ end
+ end
+end
+
@@ -0,0 +1,10 @@
+module DonorsChoose
+ module Data
+ class Account < ActiveRecord::Base
+ set_table_name :normalized_account
+ set_primary_key :_acctid
+
+ belongs_to :city, :foreign_key => :cityid
+ end
+ end
+end
@@ -0,0 +1,9 @@
+module DonorsChoose
+ module Data
+ class City < ActiveRecord::Base
+ set_table_name :normalized_city
+
+ has_many :accounts, :foreign_key => :cityid
+ end
+ end
+end
@@ -0,0 +1,10 @@
+module DonorsChoose
+ module Data
+ class Donation < ActiveRecord::Base
+ set_table_name :normalized_donation
+ set_primary_key :_donationid
+
+ belongs_to :project, :foreign_key => :_projectid
+ end
+ end
+end
@@ -0,0 +1,10 @@
+module DonorsChoose
+ module Data
+ class Essay < ActiveRecord::Base
+ set_table_name :normalized_essay
+ set_primary_key :_projectid
+
+ belongs_to :project, :foreign_key => :_projectid
+ end
+ end
+end
@@ -0,0 +1,8 @@
+module DonorsChoose
+ module Data
+ class Giftcard < ActiveRecord::Base
+ set_table_name :normalized_giftcard
+ set_primary_key :_giftcardid
+ end
+ end
+end
@@ -0,0 +1,16 @@
+module DonorsChoose
+ module Data
+ class Project < ActiveRecord::Base
+ set_table_name :normalized_project
+ set_primary_key :_projectid
+
+ belongs_to :school, :foreign_key => :_schoolid
+ belongs_to :teacher, :foreign_key => :_teacher_acctid
+
+ has_one :essay, :foreign_key => :_projectid
+
+ has_many :donations, :foreign_key => :_projectid
+ has_many :resources, :foreign_key => :_projectid
+ end
+ end
+end
@@ -0,0 +1,10 @@
+module DonorsChoose
+ module Data
+ class Resource < ActiveRecord::Base
+ set_table_name :normalized_resource
+ set_primary_key :_resourceid
+
+ belongs_to :project, :foreign_key => :_projectid
+ end
+ end
+end
@@ -0,0 +1,11 @@
+module DonorsChoose
+ module Data
+ class School < ActiveRecord::Base
+ set_table_name :normalized_school
+ set_primary_key :_schoolid
+
+ has_many :projects, :foreign_key => :_schoolid
+ has_many :teachers, :through => :projects
+ end
+ end
+end
@@ -0,0 +1,11 @@
+module DonorsChoose
+ module Data
+ class Teacher < ActiveRecord::Base
+ set_table_name :normalized_teacher
+ set_primary_key :_teacher_acctid
+
+ has_many :projects, :foreign_key => :_teacher_acctid
+ has_many :schools, :through => :projects
+ end
+ end
+end
@@ -0,0 +1,3 @@
+module DonorsChoose
+ VERSION = "0.0.1"
+end
@@ -1,17 +0,0 @@
-require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
-
-class AccountTest < Test::Unit::TestCase
-
- def setup
- @account = DCData::Account.first
- end
-
- def test_account_setup
- assert_equal "6e1d31eea9f0495d5bcfd0ab9b0b4ac3", @account._acctid
- end
-
- def test_city_setup
- assert_equal 15003, @account.city.id
- end
-
-end
Oops, something went wrong.

0 comments on commit 5e14271

Please sign in to comment.