code stringlengths 1 1.73M | language stringclasses 1
value |
|---|---|
class CreateRoutes < ActiveRecord::Migration
def self.up
create_table :routes do |t|
t.string :name
t.text :description
# for uploads
t.string :content_type
t.string :filename
t.integer :size
t.integer :width
t.integer :height
t.timestamps
end
end
d... | Ruby |
class CreatePermissions < ActiveRecord::Migration
def self.up
create_table :permissions do |t|
t.string :name
t.string :role
t.integer :level
end
add_column :users, :role, :string, :default => 'runner'
end
def self.down
drop_table :permissions
remove_column :user... | Ruby |
ENV["RAILS_ENV"] = "test"
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require 'test_help'
class Test::Unit::TestCase
# Transactional fixtures accelerate your tests by wrapping each test method
# in a transaction that's rolled back on completion. This ensures that the
# test datab... | Ruby |
#!/opt/local/bin/ruby
require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT)
# If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like:
# "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispatcher" -- otherwise performance is severely impai... | Ruby |
#!/opt/local/bin/ruby
#
# You may specify the path to the FastCGI crash log (a log of unhandled
# exceptions which forced the FastCGI instance to exit, great for debugging)
# and the number of requests to process before running garbage collection.
#
# By default, the FastCGI crash log is RAILS_ROOT/log/fastcgi.crash.lo... | Ruby |
#!/opt/local/bin/ruby
require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT)
# If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like:
# "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispatcher" -- otherwise performance is severely impai... | Ruby |
#!/opt/local/bin/ruby
require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT)
# If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like:
# "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispatcher" -- otherwise performance is severely impai... | Ruby |
#!/opt/local/bin/ruby
#
# You may specify the path to the FastCGI crash log (a log of unhandled
# exceptions which forced the FastCGI instance to exit, great for debugging)
# and the number of requests to process before running garbage collection.
#
# By default, the FastCGI crash log is RAILS_ROOT/log/fastcgi.crash.lo... | Ruby |
#!/opt/local/bin/ruby
require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT)
# If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like:
# "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispatcher" -- otherwise performance is severely impai... | Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/destroy'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/about'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/runner'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/runner'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/server'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/generate'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/destroy'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/plugin'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/console'
| Ruby |
#!/usr/bin/env ruby
require 'csv'
require 'config/environment'
require 'lib/group_excel'
#
# This script takes 1 argument, locaction of XLS files which contain the student rosters
# If any errors occur, it will notify you on the screen
# The only assumption is that all the csv files are student roster files
# T... | Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/dbconsole'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/about'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/server'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/dbconsole'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/console'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/plugin'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../../config/boot'
require 'commands/process/spawner'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../../config/boot'
require 'commands/process/spawner'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../../config/boot'
require 'commands/process/inspector'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../../config/boot'
require 'commands/process/reaper'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../../config/boot'
require 'commands/process/reaper'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../../config/boot'
require 'commands/process/inspector'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../../config/boot'
require 'commands/performance/benchmarker'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../../config/boot'
require 'commands/performance/request'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../../config/boot'
require 'commands/performance/profiler'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../../config/boot'
require 'commands/performance/benchmarker'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../../config/boot'
require 'commands/performance/profiler'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../../config/boot'
require 'commands/performance/request'
| Ruby |
#!/usr/bin/env ruby
require 'csv'
require 'config/environment'
require 'lib/group_excel'
#
# This script takes 1 argument, locaction of XLS files which contain the student rosters
# If any errors occur, it will notify you on the screen
# The only assumption is that all the csv files are student roster files
# T... | Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/generate'
| Ruby |
module ApplicationHelper
def page_level_messages
messages = ''
for message_type in [:error, :notice]
if flash[message_type]
messages << content_tag('div', content_tag('p',flash[message_type], :class => message_type), :class => 'page_message', :id => "page_message_#{message_type}")
end
... | Ruby |
module AccountHelper
end | Ruby |
module IncentivesHelper
def image_for(incentive, size = nil)
if incentive.incentive_image
image = incentive.incentive_image.public_filename(size)
image_tag(image)
else
image_tag("missing-image-#{size}.png")
end
end
end
| Ruby |
module UsersHelper
end
| Ruby |
module MapHelper
# don't forget endmapsetup
def startmapsetup
@index = 0 if @index.nil? #set default
output = '<script src="http://maps.google.com/maps?file=api&v=2&key=' + @program.gmapapi + '&sensor=false" type="text/javascript"></script>' + "\n"
output += '<script type="text/javascript">'+"\n"
output += <<daEND... | Ruby |
class Runner < ActiveRecord::Base
belongs_to :group
has_one :user
has_many :entries
validates_presence_of :group_id
validates_presence_of :first_name
validates_presence_of :last_name
validates_numericality_of :goal
validates_numericality_of :shoe_size, :message => "must be a number."
validates_inclu... | Ruby |
class Incentive < ActiveRecord::Base
belongs_to :package
has_one :incentive_image, :dependent => :destroy
validates_presence_of :package
validates_presence_of :goal
validates_presence_of :reward
# validates_format_of :content_type,
# :with => /^image/,
# :messa... | Ruby |
require 'common'
class Site < ActiveRecord::Base
belongs_to :program
has_many :groups
has_many :users
belongs_to :package
has_many :routesite
has_many :routes, :through => :routesite
validates_presence_of :name
after_save :update_caches_for_program
after_destroy :update_caches_for_program
after_... | Ruby |
class UserObserver < ActiveRecord::Observer
def after_create(user)
UserNotifier.deliver_signup_notification(user)
end
def after_save(user)
UserNotifier.deliver_activation(user) if user.recently_activated?
end
end | Ruby |
class Entry < ActiveRecord::Base
belongs_to :runner
validates_numericality_of :distance, :message => ': Distance ran must be a number'
validates_numericality_of :sessions, :message => ': Sessions ran must be a number'
validate :Distance_must_be_greater_then_0
after_save :update_caches_for_runner
after... | Ruby |
class Landmarks < ActiveRecord::Base
belongs_to :package
validates_presence_of :lat
validates_presence_of :lng
validates_presence_of :name
validates_presence_of :description
has_attachment :content_type => :image,\
:storage => :file_system,\
# high limit, but these are resized pretty small
:max_s... | Ruby |
class Program < ActiveRecord::Base
has_many :sites
validates_presence_of :name
# validates_length_of :website, :within => 10..100
def percent_complete
return calc_percent_complete(distance_cache, goal_cache)
end
def update_caches!
distance = 0
sessions = 0
goal = 0
runners = 0
... | Ruby |
require 'digest/sha1'
class User < ActiveRecord::Base
# Virtual attribute for the unencrypted password
attr_accessor :password
belongs_to :site
belongs_to :runner
has_many :groups
validates_presence_of :login
validates_presence_of :email, :if => :not_student?
validates_presence_of ... | Ruby |
class IncentiveImage < ActiveRecord::Base
belongs_to :incentive
has_attachment :content_type => :image,
:storage => :file_system,
:max_size => 500.kilobytes,
:resize_to => '384x256>',
:thumbnails => {
:large => '96x9... | Ruby |
class Permission < ActiveRecord::Base
belongs_to :user
def level_name()
d = { 1 => :global,
2 => :site,
3 => :group,
4 => :self }
return d[self.level]
end
end
| Ruby |
class Route < ActiveRecord::Base
validates_presence_of :name
has_many :routesite
has_many :sites, :through => :routesite
has_attachment :storage => :file_system, :path_prefix=>"public/route_files", :content_type => 'application/vnd.google-earth.kml+xml'
validates_as_attachment
def updateSiteRoute(site,order)
... | Ruby |
class Routesite < ActiveRecord::Base
belongs_to :route
belongs_to :site
named_scope :defaultsiteroutes, :order => '"order" DESC', :conditions => {:site_id => '-1'}
named_scope :dbsiteroutes, lambda { |site| {:order => '"order" DESC',:conditions => ['site_id = ?',site.id]}}
def self.defaults
#not sure why this h... | Ruby |
class IncentiveService
attr_reader :incentive, :incentive_image
def initialize(incentive, incentive_image)
@incentive = incentive
@incentive_image = incentive_image
end
def save
return false unless valid?
begin
Incentive.transaction do
if @incentive_image.new_record?
... | Ruby |
require 'common'
class Group < ActiveRecord::Base
belongs_to :site
has_many :runners
has_one :user
validates_presence_of :name
validates_presence_of :description
validates_presence_of :site_id
after_save :update_caches_for_site
after_destroy :update_caches_for_site
after_update :update_caches_for_... | Ruby |
class UserNotifier < ActionMailer::Base
def signup_notification(user)
setup_email(user)
@subject += 'Please activate your new account'
@body[:url] = "http://YOURSITE/account/activate/#{user.activation_code}"
end
def activation(user)
setup_email(user)
@subject += 'Your account has bee... | Ruby |
class Package < ActiveRecord::Base
has_many :incentives
end
| Ruby |
class IncentivesController < ApplicationController
def index
@incentives = Incentive.find(:all, :order => "package_id, goal")
end
def picture
@incentive = Incentive.find(params[:id])
send_data(@incentive.data,
:filename => @incentive.name,
:type => @incentive.content_... | Ruby |
class RoutesController < ApplicationController
def index
@routes = Route.find(:all)
end
def new
@route = Route.new
end
def create
@route = Route.new(params[:route])
return self.unauthorized unless self.current_user.can('create:route', @route)
if @route.save
flash[:notice] = 'New route successfully ... | Ruby |
class RunnersController < ApplicationController
def index
if @group
return self.unauthorized unless self.current_user.can('view:group', @group)
@runners = @group.runners
else
@runners = Runner.find(:all)
end
end
def show
@runner = Runner.find(params[:id])
return self.unauth... | Ruby |
class AccountController < ApplicationController
def index
redirect_to(:action => 'login') unless logged_in? || User.count > 0
end
def login
return unless request.post?
self.current_user = User.authenticate(params[:login], params[:password])
if logged_in?
if params[:remember_me] == "1"
... | Ruby |
class LandmarksController < ApplicationController
def index
@landmarks = Landmarks.find(:all, :order => "package_id")
end
# def show
# @landmarks = Landmarks.find(params[:id])
# add_page_token(@landmarks)
# end
def new
@landmark = Landmarks.new
end
def edit
@landmark = Landmarks.find(p... | Ruby |
class EntriesController < ApplicationController
def index
if @runner
return self.unauthorized unless self.current_user.can('view:entries', @runner)
@entries = @runner.entries
else
# i don't think this will ever be a case, or shouldn't be - nick
# i can't really put a permission on v... | Ruby |
class SitesController < ApplicationController
def show
@site = Site.find(params[:id])
return self.unauthorized unless self.current_user.can('view:site', @site)
@groups = @site.groups
add_page_token(@site.name)
end
def new
return self.unauthorized unless self.current_user.can('create:site', n... | Ruby |
class HomeController < ApplicationController
def home
if (self.current_user.respond_to?("is_not_student?")) && (not self.current_user.is_not_student?)
@runner = self.current_user.get_runner
add_page_token(@runner.name + "'s Map")
@is_student = true
# next two probably should be combined to one db call
@in... | Ruby |
class UsersController < ApplicationController
def index
@users = User.find(:all)
end
def new
@user = User.new
end
def edit
@user = User.find(params[:id])
return self.unauthorized unless self.current_user.can('edit:user', @user)
add_page_token(@user.login)
end
def create
@user ... | Ruby |
class ApplicationController < ActionController::Base
include RenderTools
include AuthenticatedSystem
before_filter :login_from_cookie
before_filter :before_render_tools
before_filter :setup
after_filter :after_render_tools
helper :all
# See ActionController::RequestForgeryProtection for details
#... | Ruby |
class TrophyRoomsController < ApplicationController
def show
count=5
@runner = Runner.find(params[:id])
return self.unauthorized unless self.current_user.can('view:runner', @runner)
# package_id = @runner.package.id
if (not @runner.blank?)
@distance = @runner.distance_cache
@incentives ... | Ruby |
class GroupsController < ApplicationController
layout "application", :except => [ :report ]
def show
@group = Group.find(params[:id])
return self.unauthorized unless self.current_user.can('view:group', @group)
@runners = @group.runners
add_page_token(@group.name)
end
def map
@group = Group... | Ruby |
class ProgramsController < ApplicationController
skip_before_filter :setup, :only => [:new, :create]
before_filter :ensure_application_has_one_program, :only => [:new, :create, :destroy]
def index
@programs = Program.find(:all)
end
def show
@program = Program.find(params[:id])
@sites = @program... | Ruby |
# 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'
# i... | Ruby |
# These settings change the behavior of Rails 2 apps and will be defaults
# for Rails 3. You can remove this initializer when Rails 3 is released.
# Include Active Record class name as root for JSON serialized output.
ActiveRecord::Base.include_root_in_json = true
# Store the full class name (including module namespa... | Ruby |
# 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
| Ruby |
ActionController::Routing::Routes.draw do |map|
map.resources :programs
map.resources :sites
map.resources :groups
map.resources :runners
map.resources :entries
map.resources :incentives
map.resources :landmarks
map.resources :routes
map.resources :users
# The priority is based upon order of c... | Ruby |
# 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?
... | Ruby |
# 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.1... | Ruby |
# 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 repor... | Ruby |
# 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.ca... | Ruby |
# 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... | Ruby |
# 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'
| Ruby |
module AuthenticatedSystem
class FakeUser
def can(capability, object)
return self.can?(capability, object)
end
end
class AnonymousUser < FakeUser
def site_id
return nil
end
def site
return nil
end
def can?(capability, object)
return false
... | Ruby |
require 'rubygems'
require 'parseexcel'
class StudentExcel
# represents an excel spreadsheet of students
attr_reader :school, :class, :coach, :students
def initialize(file,
group_school = {:column => 'c', :row => 2},
group_school_regex = Regexp.new(/School:\s+(.*)/),
... | Ruby |
def calc_percent_complete(distance, goal)
return 0 if goal < 1
(distance / goal * 100).round.to_i
end | Ruby |
module AuthenticatedTestHelper
# Sets the current user in the session from the user fixtures.
def login_as(user)
@request.session[:user] = user ? users(user).id : nil
end
def content_type(type)
@request.env['Content-Type'] = type
end
def accept(accept)
@request.env["HTTP_ACCEPT"] = accept
en... | Ruby |
require 'singleton'
require 'yaml'
class Pages
include Singleton
def initialize
load
end
def reload
load
end
def get(page_key,item)
begin
string = @pages[page_key.to_s][item.to_s]
rescue
string = ''
end
end
private
def load
@pages = YAML::load(File.open("... | Ruby |
module RenderTools
def before_render_tools
@page_tokens = Array.new
end
def after_render_tools
clear_flash_messages
end
def self.included(base)
base.send :helper_method, :page, :page_key
end
##### MESSAGING #####
def clear_flash_messages
if @performed_render
flash.delete(:err... | Ruby |
require 'test/unit'
class TestStudentExcel < Test::Unit::TestCase
def test_simple
i = StudentExcel
t = i.new('test.xls')
assert_equal('Mt. Greenwood', t.school)
assert_equal('Room 110', t.class)
assert_equal('Catherine Schumacher', t.coach)
puts t.students
assert_equal(26, t.students.leng... | Ruby |
class AddGroupConverter < ActiveRecord::Migration
def self.up
add_column :groups, :lap, :integer, :default => 1
end
def self.down
remove_column :groups, :lap
end
end
| Ruby |
class CreatePackages < ActiveRecord::Migration
def self.up
create_table :packages do |t|
t.string :name
t.timestamps
end
Package.create :name => "Basic Package"
end
def self.down
drop_table :packages
end
end
| Ruby |
class AddCaches < ActiveRecord::Migration
def self.up
add_column :runners, :distance_cache, :decimal, :default => 0, :precision => 10, :scale => 2
add_column :runners, :sessions_cache, :integer, :default => 0
add_column :groups, :distance_cache, :decimal, :default => 0, :precision => 10, :scale => 2
... | Ruby |
class AddAnotherPermission < ActiveRecord::Migration
def self.create_permission(name, role, level)
Permission.new({'name'=>name, 'role'=>role, 'level'=>level}).save!
end
def self.destroy_permission(name, role, level)
Permission.destroy({'name'=>name, 'role'=>role, 'level'=>level})
end
def self.up
... | Ruby |
class AddStudentPermissions < ActiveRecord::Migration
def self.create_permission(name, role, level)
Permission.new({'name'=>name, 'role'=>role, 'level'=>level}).save!
end
def self.destroy_permission(name, role, level)
thing = Permission.find_by_name_and_role_and_level(name,role,level)
thing.destroy
... | Ruby |
class CreateLandmarks < ActiveRecord::Migration
def self.up
create_table :landmarks do |t|
t.timestamps
t.belongs_to :package
t.decimal :lat
t.decimal :lng
t.string :name
t.text :description
end
end
def self.down
drop_table :landmarks
end
end
| Ruby |
class CreateEntries < ActiveRecord::Migration
def self.up
create_table :entries do |t|
t.integer :runner_id
t.integer :sessions
t.decimal :distance, :precision => 10, :scale => 2
t.date :date
t.timestamps
end
end
def self.down
drop_table :entries
end
end
| Ruby |
class AllowStudentsToLogin < ActiveRecord::Migration
def self.up
change_table :users do |t|
t.belongs_to :runner, :null => true
end
end
def self.down
change_table :users do |t|
t.remove_belongs_to(:runner)
end
end
end
| Ruby |
class AddGoogleApiKeyToPrograms < ActiveRecord::Migration
def self.up
change_table :programs do |t|
#add default of gmaps api for localhost
t.string :gmapapi, :default => 'ABQIAAAA3gTQRv5vBcxyNZCSofFHjxTX2XchcwgyHzp4Xo0DHRAzt2aLjhT5z4WqOMUYA0rGg7gTgjNgsEjV_w'
end
Program.update_all ["gmapapi = ?", 'ABQI... | Ruby |
class CreateGroups < ActiveRecord::Migration
def self.up
create_table :groups do |t|
t.integer :site_id
t.string :name
t.string :description
t.timestamps
end
end
def self.down
drop_table :groups
end
end
| Ruby |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.