Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Attempt to make it more gem like

  • Loading branch information...
commit 5e1427141089373ac354d02947435bb6091ef48d 1 parent 61700a1
@markmcspadden markmcspadden authored
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
4 Gemfile
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in donors_choose.gemspec
+gemspec
View
2  README.textile
@@ -18,6 +18,7 @@ h2. Usage
h3. Rails
+
If you'd like to use it in Rails, just add the following to your Gemfile:
<code>
@@ -25,6 +26,7 @@ If you'd like to use it in Rails, just add the following to your Gemfile:
</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
13 Rakefile
@@ -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
38 d_c_data.rb
@@ -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
8 d_c_data/account.rb
@@ -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
7 d_c_data/city.rb
@@ -1,7 +0,0 @@
-module DCData
- class City < ActiveRecord::Base
- set_table_name :normalized_city
-
- has_many :accounts, :foreign_key => :cityid
- end
-end
View
6 d_c_data/donation.rb
@@ -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
8 d_c_data/essay.rb
@@ -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
6 d_c_data/giftcard.rb
@@ -1,6 +0,0 @@
-module DCData
- class Giftcard < ActiveRecord::Base
- set_table_name :normalized_giftcard
- set_primary_key :_giftcardid
- end
-end
View
14 d_c_data/project.rb
@@ -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
8 d_c_data/resource.rb
@@ -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
9 d_c_data/school.rb
@@ -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
9 d_c_data/teacher.rb
@@ -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
24 donors_choose.gemspec
@@ -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
3  lib/donors_choose.rb
@@ -0,0 +1,3 @@
+module DonorsChoose
+
+end
View
38 lib/donors_choose/data.rb
@@ -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
+
View
10 lib/donors_choose/data/account.rb
@@ -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
View
9 lib/donors_choose/data/city.rb
@@ -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
View
10 lib/donors_choose/data/donation.rb
@@ -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
View
10 lib/donors_choose/data/essay.rb
@@ -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
View
8 lib/donors_choose/data/giftcard.rb
@@ -0,0 +1,8 @@
+module DonorsChoose
+ module Data
+ class Giftcard < ActiveRecord::Base
+ set_table_name :normalized_giftcard
+ set_primary_key :_giftcardid
+ end
+ end
+end
View
16 lib/donors_choose/data/project.rb
@@ -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
View
10 lib/donors_choose/data/resource.rb
@@ -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
View
11 lib/donors_choose/data/school.rb
@@ -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
View
11 lib/donors_choose/data/teacher.rb
@@ -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
View
3  lib/donors_choose/version.rb
@@ -0,0 +1,3 @@
+module DonorsChoose
+ VERSION = "0.0.1"
+end
View
17 test/d_c_data/account_test.rb
@@ -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
View
16 test/d_c_data/donation_test.rb
@@ -1,16 +0,0 @@
-require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
-
-class DonationTest < Test::Unit::TestCase
-
- def setup
- @donation = DCData::Donation.first
- end
-
- def test_donation_setup
- assert_equal "798b59bfda2a7dd69a1a02f6bb007969", @donation._donationid
- end
-
- def test_project_setup
- assert_equal "364c61a92927942f7241ecdc1dcc1c04", @donation.project._projectid
- end
-end
View
17 test/d_c_data/essay_test.rb
@@ -1,17 +0,0 @@
-require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
-
-class EssayTest < Test::Unit::TestCase
-
- def setup
- @essay = DCData::Essay.first
- end
-
- def test_essay_setup
- assert_equal "2a68c0296a73dcb868b5d35145935462", @essay._projectid
- end
-
- def test_project_setup
- assert_equal "2a68c0296a73dcb868b5d35145935462", @essay.project._projectid
- end
-
-end
View
13 test/d_c_data/giftcard_test.rb
@@ -1,13 +0,0 @@
-require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
-
-class GiftcardTest < Test::Unit::TestCase
-
- def setup
- @giftcard = DCData::Giftcard.first
- end
-
- def test_giftcard_setup
- assert_equal "7c2fa2b7b826c6a75a4ec1519f937537", @giftcard._giftcardid
- end
-
-end
View
33 test/d_c_data/project_test.rb
@@ -1,33 +0,0 @@
-require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
-
-class ProjectTest < Test::Unit::TestCase
-
- def setup
- @project = DCData::Project.first
- end
-
- def test_project_setup
- assert_equal "b1ee1388beb00573ef0ab81e2b7243c4", @project._projectid
- end
-
- def test_donation_setup
- assert_equal "8a88748e91884b5f03bbaa5f4fcfd036", @project.donations.first._donationid
- end
-
- def test_essay_setup
- assert_equal "b1ee1388beb00573ef0ab81e2b7243c4", @project.essay._projectid
- end
-
- def test_teacher_setup
- assert_equal "590154bc5343aae1f958b043139b3d62", @project.teacher._teacher_acctid
- end
-
- def test_resources_setup
- assert_equal "590154bc5343aae1f958b043139b3d62", @project.resources.first._resourceid
- end
-
- def test_school_setup
- assert_equal "df2afbda9d169825b454772337b797c8", @project.school._schoolid
- end
-
-end
View
17 test/d_c_data/resource_test.rb
@@ -1,17 +0,0 @@
-require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
-
-class ResourceTest < Test::Unit::TestCase
-
- def setup
- @resource = DCData::Resource.first
- end
-
- def test_resource_setup
- assert_equal "d44b79386ab2353c9409736c3994e83f", @resource._resourceid
- end
-
- def test_project_setup
- assert_equal "2a68c0296a73dcb868b5d35145935462", @resource.project._projectid
- end
-
-end
View
16 test/d_c_data/school_test.rb
@@ -1,16 +0,0 @@
-require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
-
-class SchoolTest < Test::Unit::TestCase
-
- def setup
- @school = DCData::School.first
- end
-
- def test_school_setup
- assert_equal "4effb11a762d152b107678ab4744063b", @school._schoolid
- end
-
- def test_project_setup
- assert_equal "6eb774f01d75b29a3c1971040d9d1b5a", @school.projects.first._projectid
- end
-end
View
21 test/d_c_data/teacher_test.rb
@@ -1,21 +0,0 @@
-require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
-
-class TeacherTest < Test::Unit::TestCase
-
- def setup
- @teacher = DCData::Teacher.first
- end
-
- def test_teacher_setup
- assert_equal "d04fe28078bb087996351d7a6d0c20d1", @teacher._teacher_acctid
- end
-
- def test_projects_setup
- assert_equal "f9065c14b96ae492fb62924acb115521", @teacher.projects.first._projectid
- end
-
- def test_schools_setup
- assert_equal "39ddbff0638271cd2eb7793af1c91237", @teacher.schools.first._schoolid
- end
-
-end
View
17 test/donors_choose/data/account_test.rb
@@ -0,0 +1,17 @@
+require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
+
+class AccountTest < Test::Unit::TestCase
+
+ def setup
+ @account = DonorsChoose::Data::Account.order(:_acctid).first
+ end
+
+ def test_account_setup
+ assert_equal "00008481214e948f070337066f875fb2", @account._acctid
+ end
+
+ def test_city_setup
+ assert_equal 4474, @account.city.id
+ end
+
+end
View
4 test/d_c_data/city_test.rb → test/donors_choose/data/city_test.rb
@@ -1,9 +1,9 @@
-require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
+require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
class CityTest < Test::Unit::TestCase
def setup
- @city = DCData::City.first
+ @city = DonorsChoose::Data::City.first
end
def test_city_setup
View
16 test/donors_choose/data/donation_test.rb
@@ -0,0 +1,16 @@
+require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
+
+class DonationTest < Test::Unit::TestCase
+
+ def setup
+ @donation = DonorsChoose::Data::Donation.order(:_donationid).first
+ end
+
+ def test_donation_setup
+ assert_equal "0000023f507999464aa2b78875b7e5d6", @donation._donationid
+ end
+
+ def test_project_setup
+ assert_equal "69bf3a609bb4673818e0eebd004ea504", @donation.project._projectid
+ end
+end
View
17 test/donors_choose/data/essay_test.rb
@@ -0,0 +1,17 @@
+require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
+
+class EssayTest < Test::Unit::TestCase
+
+ def setup
+ @essay = DonorsChoose::Data::Essay.order(:_projectid).first
+ end
+
+ def test_essay_setup
+ assert_equal "0000023f507999464aa2b78875b7e5d6", @essay._projectid
+ end
+
+ def test_project_setup
+ assert_equal "0000023f507999464aa2b78875b7e5d6", @essay.project._projectid
+ end
+
+end
View
13 test/donors_choose/data/giftcard_test.rb
@@ -0,0 +1,13 @@
+require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
+
+class GiftcardTest < Test::Unit::TestCase
+
+ def setup
+ @giftcard = DonorsChoose::Data::Giftcard.order(:_giftcardid).first
+ end
+
+ def test_giftcard_setup
+ assert_equal "000238b44c187c254752736e53ee46f2", @giftcard._giftcardid
+ end
+
+end
View
33 test/donors_choose/data/project_test.rb
@@ -0,0 +1,33 @@
+require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
+
+class ProjectTest < Test::Unit::TestCase
+
+ def setup
+ @project = DonorsChoose::Data::Project.order(:_projectid).first
+ end
+
+ def test_project_setup
+ assert_equal "0000023f507999464aa2b78875b7e5d6", @project._projectid
+ end
+
+ def test_donation_setup
+ assert_equal "ee519de971e6ec8961f5efa06c6ed191", @project.donations.first._donationid
+ end
+
+ def test_essay_setup
+ assert_equal "0000023f507999464aa2b78875b7e5d6", @project.essay._projectid
+ end
+
+ def test_teacher_setup
+ assert_equal "5ac258059d9c4fc4db5c1a92b7204db0", @project.teacher._teacher_acctid
+ end
+
+ def test_resources_setup
+ assert_equal "179328a86f77fd5516d122f371c41d32", @project.resources.first._resourceid
+ end
+
+ def test_school_setup
+ assert_equal "c8eafeea02033a1cacd629b410668d55", @project.school._schoolid
+ end
+
+end
View
17 test/donors_choose/data/resource_test.rb
@@ -0,0 +1,17 @@
+require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
+
+class ResourceTest < Test::Unit::TestCase
+
+ def setup
+ @resource = DonorsChoose::Data::Resource.order(:_resourceid).first
+ end
+
+ def test_resource_setup
+ assert_equal "00000170fe6288e0bc4d136e7d9b5ff2", @resource._resourceid
+ end
+
+ def test_project_setup
+ assert_equal "401699836249c08c7a686b33e243b826", @resource.project._projectid
+ end
+
+end
View
16 test/donors_choose/data/school_test.rb
@@ -0,0 +1,16 @@
+require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
+
+class SchoolTest < Test::Unit::TestCase
+
+ def setup
+ @school = DonorsChoose::Data::School.order(:_schoolid).first
+ end
+
+ def test_school_setup
+ assert_equal "00064eac8b3d1f6dea8a07559922ed58", @school._schoolid
+ end
+
+ def test_project_setup
+ assert_equal "2934f1c8ae5069a41fe601dcf57601be", @school.projects.first._projectid
+ end
+end
View
21 test/donors_choose/data/teacher_test.rb
@@ -0,0 +1,21 @@
+require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
+
+class TeacherTest < Test::Unit::TestCase
+
+ def setup
+ @teacher = DonorsChoose::Data::Teacher.order(:_teacher_acctid).first
+ end
+
+ def test_teacher_setup
+ assert_equal "0000fc70ad0a307d08f88a484dd99cb4", @teacher._teacher_acctid
+ end
+
+ def test_projects_setup
+ assert_equal "dde9ff3a749c46a5d6d6be4f37b0dba6", @teacher.projects.first._projectid
+ end
+
+ def test_schools_setup
+ assert_equal "3a379fd45cb12c92c3c4283e97421111", @teacher.schools.first._schoolid
+ end
+
+end
View
4 test/test_helper.rb
@@ -1,5 +1,5 @@
require 'test/unit'
-require File.expand_path(File.dirname(__FILE__) + "/../d_c_data")
+require File.expand_path(File.dirname(__FILE__) + "/../lib/donors_choose/data")
-DCData.connect
+DonorsChoose::Data.connect
Please sign in to comment.
Something went wrong with that request. Please try again.