Permalink
Browse files

Initial check-in of denormalizes as app.

  • Loading branch information...
0 parents commit e8955c6b9caa8671fd4981c2fc230047003450f0 @duncanbeevers committed May 9, 2008
Showing with 8,431 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +18 −0 README
  3. +10 −0 Rakefile
  4. +10 −0 app/controllers/application.rb
  5. +3 −0 app/helpers/application_helper.rb
  6. +3 −0 app/models/user.rb
  7. +6 −0 app/models/user_score.rb
  8. +6 −0 app/models/user_zip_code.rb
  9. +109 −0 config/boot.rb
  10. +19 −0 config/database.yml
  11. +59 −0 config/environment.rb
  12. +18 −0 config/environments/development.rb
  13. +19 −0 config/environments/production.rb
  14. +22 −0 config/environments/test.rb
  15. +10 −0 config/initializers/inflections.rb
  16. +5 −0 config/initializers/mime_types.rb
  17. +35 −0 config/routes.rb
  18. +14 −0 db/migrate/001_create_users.rb
  19. +13 −0 db/migrate/002_create_user_scores.rb
  20. +13 −0 db/migrate/003_create_user_zip_codes.rb
  21. +36 −0 db/schema.rb
  22. +2 −0 doc/README_FOR_APP
  23. +56 −0 lib/core_extensions/activerecord/denormalizes.rb
  24. +40 −0 public/.htaccess
  25. +30 −0 public/404.html
  26. +30 −0 public/422.html
  27. +30 −0 public/500.html
  28. +10 −0 public/dispatch.cgi
  29. +24 −0 public/dispatch.fcgi
  30. +10 −0 public/dispatch.rb
  31. 0 public/favicon.ico
  32. BIN public/images/rails.png
  33. +277 −0 public/index.html
  34. +2 −0 public/javascripts/application.js
  35. +963 −0 public/javascripts/controls.js
  36. +972 −0 public/javascripts/dragdrop.js
  37. +1,120 −0 public/javascripts/effects.js
  38. +4,225 −0 public/javascripts/prototype.js
  39. +5 −0 public/robots.txt
  40. +3 −0 script/about
  41. +3 −0 script/console
  42. +3 −0 script/destroy
  43. +3 −0 script/generate
  44. +3 −0 script/performance/benchmarker
  45. +3 −0 script/performance/profiler
  46. +3 −0 script/performance/request
  47. +3 −0 script/plugin
  48. +3 −0 script/process/inspector
  49. +3 −0 script/process/reaper
  50. +3 −0 script/process/spawner
  51. +3 −0 script/runner
  52. +3 −0 script/server
  53. +7 −0 test/fixtures/user_scores.yml
  54. +7 −0 test/fixtures/user_zip_codes.yml
  55. +7 −0 test/fixtures/users.yml
  56. +38 −0 test/test_helper.rb
  57. +73 −0 test/unit/denormalizes_test.rb
  58. +8 −0 test/unit/user_score_test.rb
  59. +8 −0 test/unit/user_test.rb
  60. +8 −0 test/unit/user_zip_code_test.rb
  61. +10 −0 vendor/plugins/named_scope_for/init.rb
  62. +1 −0 vendor/rails
@@ -0,0 +1 @@
+log/*
18 README
@@ -0,0 +1,18 @@
+Denormalizes provides a clean syntax for specifying observation
+and denormalization rules between ActiveRecord models.
+
+ class UserScore < ActiveRecord::Base
+ belongs_to :user
+ named_scope_for :user_id
+
+ denormalizes :score, :from => :user
+ end
+
+There are a number of common-sense conventions in use here.
+First, the denormalization model must have reflection onto the
+observed model in the form of a has_one or belongs_to.
+
+Second, denormalized values can only be activerecord attributes
+of the observed model, (must be columns in the database) and
+the observer model's columns must match those of the observed
+model.
@@ -0,0 +1,10 @@
+# Add your own tasks in files placed in lib/tasks ending in .rake,
+# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
+
+require(File.join(File.dirname(__FILE__), 'config', 'boot'))
+
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+require 'tasks/rails'
@@ -0,0 +1,10 @@
+# Filters added to this controller apply to all controllers in the application.
+# Likewise, all the methods added will be available for all controllers.
+
+class ApplicationController < ActionController::Base
+ helper :all # include all helpers, all the time
+
+ # See ActionController::RequestForgeryProtection for details
+ # Uncomment the :secret if you're not using the cookie session store
+ protect_from_forgery # :secret => '16a3f140e8ff628c2fb6535f579c3c59'
+end
@@ -0,0 +1,3 @@
+# Methods added to this helper will be available to all templates in the application.
+module ApplicationHelper
+end
@@ -0,0 +1,3 @@
+class User < ActiveRecord::Base
+
+end
@@ -0,0 +1,6 @@
+class UserScore < ActiveRecord::Base
+ belongs_to :user
+ named_scope_for :user_id
+
+ denormalizes :score, :from => :user
+end
@@ -0,0 +1,6 @@
+class UserZipCode < ActiveRecord::Base
+ belongs_to :user
+ named_scope_for :user_id
+
+ denormalizes :zip_code, :from => :user
+end
@@ -0,0 +1,109 @@
+# Don't change this file!
+# Configure your app in config/environment.rb and config/environments/*.rb
+
+RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
+
+module Rails
+ class << self
+ def boot!
+ unless booted?
+ preinitialize
+ pick_boot.run
+ end
+ end
+
+ def booted?
+ defined? Rails::Initializer
+ end
+
+ def pick_boot
+ (vendor_rails? ? VendorBoot : GemBoot).new
+ end
+
+ def vendor_rails?
+ File.exist?("#{RAILS_ROOT}/vendor/rails")
+ end
+
+ # FIXME : Ruby 1.9
+ def preinitialize
+ load(preinitializer_path) if File.exists?(preinitializer_path)
+ end
+
+ def preinitializer_path
+ "#{RAILS_ROOT}/config/preinitializer.rb"
+ end
+ end
+
+ class Boot
+ def run
+ load_initializer
+ Rails::Initializer.run(:set_load_path)
+ end
+ end
+
+ class VendorBoot < Boot
+ def load_initializer
+ require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
+ end
+ end
+
+ class GemBoot < Boot
+ def load_initializer
+ self.class.load_rubygems
+ load_rails_gem
+ require 'initializer'
+ end
+
+ def load_rails_gem
+ if version = self.class.gem_version
+ gem 'rails', version
+ else
+ gem 'rails'
+ end
+ rescue Gem::LoadError => load_error
+ $stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
+ exit 1
+ end
+
+ class << self
+ def rubygems_version
+ Gem::RubyGemsVersion if defined? Gem::RubyGemsVersion
+ end
+
+ def gem_version
+ if defined? RAILS_GEM_VERSION
+ RAILS_GEM_VERSION
+ elsif ENV.include?('RAILS_GEM_VERSION')
+ ENV['RAILS_GEM_VERSION']
+ else
+ parse_gem_version(read_environment_rb)
+ end
+ end
+
+ def load_rubygems
+ require 'rubygems'
+
+ unless rubygems_version >= '0.9.4'
+ $stderr.puts %(Rails requires RubyGems >= 0.9.4 (you have #{rubygems_version}). Please `gem update --system` and try again.)
+ exit 1
+ end
+
+ rescue LoadError
+ $stderr.puts %(Rails requires RubyGems >= 0.9.4. Please install RubyGems and try again: http://rubygems.rubyforge.org)
+ exit 1
+ end
+
+ def parse_gem_version(text)
+ $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
+ end
+
+ private
+ def read_environment_rb
+ File.read("#{RAILS_ROOT}/config/environment.rb")
+ end
+ end
+ end
+end
+
+# All that for this:
+Rails.boot!
@@ -0,0 +1,19 @@
+# SQLite version 3.x
+# gem install sqlite3-ruby (not necessary on OS X Leopard)
+development:
+ adapter: sqlite3
+ database: db/development.sqlite3
+ timeout: 5000
+
+# Warning: The database defined as 'test' will be erased and
+# re-generated from your development database when you run 'rake'.
+# Do not set this db to the same as development or production.
+test:
+ adapter: sqlite3
+ database: db/test.sqlite3
+ timeout: 5000
+
+production:
+ adapter: sqlite3
+ database: db/production.sqlite3
+ timeout: 5000
@@ -0,0 +1,59 @@
+# Be sure to restart your server when you modify this file
+
+# Uncomment below to force Rails into production mode when
+# you don't control web/app server and can't set it the proper way
+# ENV['RAILS_ENV'] ||= 'production'
+
+# Specifies gem version of Rails to use when vendor/rails is not present
+RAILS_GEM_VERSION = '2.0.2' unless defined? RAILS_GEM_VERSION
+
+# Bootstrap the Rails environment, frameworks, and default configuration
+require File.join(File.dirname(__FILE__), 'boot')
+
+Rails::Initializer.run do |config|
+ # Settings in config/environments/* take precedence over those specified here.
+ # Application configuration should go into files in config/initializers
+ # -- all .rb files in that directory are automatically loaded.
+ # See Rails::Configuration for more options.
+
+ # Skip frameworks you're not going to use (only works if using vendor/rails).
+ # To use Rails without a database, you must remove the Active Record framework
+ # config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
+
+ # Only load the plugins named here, in the order given. By default, all plugins
+ # in vendor/plugins are loaded in alphabetical order.
+ # :all can be used as a placeholder for all plugins not explicitly named
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
+
+ # Add additional load paths for your own custom dirs
+ # config.load_paths += %W( #{RAILS_ROOT}/extras )
+
+ # Force all environments to use the same logger level
+ # (by default production uses :info, the others :debug)
+ # config.log_level = :debug
+
+ # Your secret key for verifying cookie session data integrity.
+ # If you change this key, all old sessions will become invalid!
+ # Make sure the secret is at least 30 characters and all random,
+ # no regular words or you'll be exposed to dictionary attacks.
+ config.action_controller.session = {
+ :session_key => '_denormalizes_session',
+ :secret => '3ef283c29a88daa04cb9163a6e5c1885434d537102e60e078bd80076b387d546c755a376f739bed6872112323ae3c6f6f7636207eceb994d18cf7d3788d12b69'
+ }
+
+ # Use the database for sessions instead of the cookie-based default,
+ # which shouldn't be used to store highly confidential information
+ # (create the session table with 'rake db:sessions:create')
+ # config.action_controller.session_store = :active_record_store
+
+ # Use SQL instead of Active Record's schema dumper when creating the test database.
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
+ # like if you have constraints or database-specific column types
+ # config.active_record.schema_format = :sql
+
+ # Activate observers that should always be running
+ # config.active_record.observers = :cacher, :garbage_collector
+
+ # Make Active Record use UTC-base instead of local time
+ # config.active_record.default_timezone = :utc
+end
@@ -0,0 +1,18 @@
+# Settings specified here will take precedence over those in config/environment.rb
+
+# In the development environment your application's code is reloaded on
+# every request. This slows down response time but is perfect for development
+# since you don't have to restart the webserver when you make code changes.
+config.cache_classes = false
+
+# Log error messages when you accidentally call methods on nil.
+config.whiny_nils = true
+
+# Show full error reports and disable caching
+config.action_controller.consider_all_requests_local = true
+config.action_view.debug_rjs = true
+config.action_controller.perform_caching = false
+config.action_view.cache_template_extensions = false
+
+# Don't care if the mailer can't send
+config.action_mailer.raise_delivery_errors = false
@@ -0,0 +1,19 @@
+# Settings specified here will take precedence over those in config/environment.rb
+
+# The production environment is meant for finished, "live" apps.
+# Code is not reloaded between requests
+config.cache_classes = true
+
+# Use a different logger for distributed setups
+# config.logger = SyslogLogger.new
+
+# Full error reports are disabled and caching is turned on
+config.action_controller.consider_all_requests_local = false
+config.action_controller.perform_caching = true
+config.action_view.cache_template_loading = true
+
+# Enable serving of images, stylesheets, and javascripts from an asset server
+# config.action_controller.asset_host = "http://assets.example.com"
+
+# Disable delivery errors, bad email addresses will be ignored
+# config.action_mailer.raise_delivery_errors = false
@@ -0,0 +1,22 @@
+# Settings specified here will take precedence over those in config/environment.rb
+
+# The test environment is used exclusively to run your application's
+# test suite. You never need to work with it otherwise. Remember that
+# your test database is "scratch space" for the test suite and is wiped
+# and recreated between test runs. Don't rely on the data there!
+config.cache_classes = true
+
+# Log error messages when you accidentally call methods on nil.
+config.whiny_nils = true
+
+# Show full error reports and disable caching
+config.action_controller.consider_all_requests_local = true
+config.action_controller.perform_caching = false
+
+# Disable request forgery protection in test environment
+config.action_controller.allow_forgery_protection = false
+
+# Tell ActionMailer not to deliver emails to the real world.
+# The :test delivery method accumulates sent emails in the
+# ActionMailer::Base.deliveries array.
+config.action_mailer.delivery_method = :test
@@ -0,0 +1,10 @@
+# Be sure to restart your server when you modify this file.
+
+# Add new inflection rules using the following format
+# (all these examples are active by default):
+# Inflector.inflections do |inflect|
+# inflect.plural /^(ox)$/i, '\1en'
+# inflect.singular /^(ox)en/i, '\1'
+# inflect.irregular 'person', 'people'
+# inflect.uncountable %w( fish sheep )
+# end
@@ -0,0 +1,5 @@
+# Be sure to restart your server when you modify this file.
+
+# Add new mime types for use in respond_to blocks:
+# Mime::Type.register "text/richtext", :rtf
+# Mime::Type.register_alias "text/html", :iphone
@@ -0,0 +1,35 @@
+ActionController::Routing::Routes.draw do |map|
+ # The priority is based upon order of creation: first created -> highest priority.
+
+ # Sample of regular route:
+ # map.connect 'products/:id', :controller => 'catalog', :action => 'view'
+ # Keep in mind you can assign values other than :controller and :action
+
+ # Sample of named route:
+ # map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase'
+ # This route can be invoked with purchase_url(:id => product.id)
+
+ # Sample resource route (maps HTTP verbs to controller actions automatically):
+ # map.resources :products
+
+ # Sample resource route with options:
+ # map.resources :products, :member => { :short => :get, :toggle => :post }, :collection => { :sold => :get }
+
+ # Sample resource route with sub-resources:
+ # map.resources :products, :has_many => [ :comments, :sales ], :has_one => :seller
+
+ # Sample resource route within a namespace:
+ # map.namespace :admin do |admin|
+ # # Directs /admin/products/* to Admin::ProductsController (app/controllers/admin/products_controller.rb)
+ # admin.resources :products
+ # end
+
+ # You can have the root of your site routed with map.root -- just remember to delete public/index.html.
+ # map.root :controller => "welcome"
+
+ # See how all your routes lay out with "rake routes"
+
+ # Install the default routes as the lowest priority.
+ map.connect ':controller/:action/:id'
+ map.connect ':controller/:action/:id.:format'
+end
@@ -0,0 +1,14 @@
+class CreateUsers < ActiveRecord::Migration
+ def self.up
+ create_table :users do |t|
+ t.string :username
+ t.integer :score, :allow_nil => false, :default => 0
+ t.integer :zip_code
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :users
+ end
+end
@@ -0,0 +1,13 @@
+class CreateUserScores < ActiveRecord::Migration
+ def self.up
+ create_table :user_scores do |t|
+ t.integer :user_id
+ t.integer :score, :allow_nils => false, :default => 0
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :user_scores
+ end
+end
Oops, something went wrong.

0 comments on commit e8955c6

Please sign in to comment.