code stringlengths 1 1.73M | language stringclasses 1
value |
|---|---|
class CreateConversations < ActiveRecord::Migration
def self.up
create_table :conversations do |t|
# We only need the id, but the migration chokes if we don't pass a block.
end
add_column :communications, :conversation_id, :integer
add_index :communications, :conversation_id
system("rake db:... | Ruby |
class RemoveSessionColumn < ActiveRecord::Migration
def self.up
remove_column :page_views, :session
end
def self.down
add_column :page_views, :session, :string, :limit => 32
end
end
| Ruby |
class CreatePageView < ActiveRecord::Migration
def self.up
create_table :page_views do |t|
t.integer :user_id
t.string :request_url, :limit => 200
t.string :session, :limit => 32
t.string :ip_address, :limit => 16
t.string :referer, :limit => 200
t.string :user_agent, :limit =>... | Ruby |
class CreateEmailVerifications < ActiveRecord::Migration
def self.up
create_table :email_verifications do |t|
t.integer :person_id
t.string :code
t.timestamps
end
add_index :email_verifications, :code
end
def self.down
drop_table :email_verifications
end
end
| Ruby |
class MigratePhotoData < ActiveRecord::Migration
def self.up
# For each person, create a gallery and put all their photos there.
Person.find(:all).each do |person|
gallery = person.galleries.new
gallery.title = "Primary"
primary_photo = person.photos.detect(&:primary?)
gallery.prima... | Ruby |
class CreateAttendeesToEvents < ActiveRecord::Migration
def self.up
create_table :event_attendees do |t|
t.references :person
t.references :event
end
end
def self.down
drop_table :event_attendees
end
end
| Ruby |
class AddAboutToPreferences < ActiveRecord::Migration
def self.up
add_column :preferences, :about, :text
end
def self.down
remove_column :preferences, :about
end
end
| Ruby |
class CreateThumbnails < ActiveRecord::Migration
def self.up
create_table :thumbnails do |t|
t.integer :parent_id
t.string :content_type
t.string :filename
t.string :thumbnail
t.integer :size
t.integer :width
t.integer :height
t.timestamps
end
end
def self.... | Ruby |
class AddAnalyticsPreference < ActiveRecord::Migration
def self.up
add_column :preferences, :analytics, :text
end
def self.down
remove_column :preferences, :analytics
end
end
| Ruby |
class AddDemoBoolean < ActiveRecord::Migration
def self.up
add_column :preferences, :demo, :boolean, :default => false
end
def self.down
remove_column :preferences, :demo
end
end
| Ruby |
class RemoveBlogCommentCounterCache < ActiveRecord::Migration
def self.up
remove_column :posts, :blog_post_comments_count
end
def self.down
add_column :posts, :blog_post_comments_count, :integer, :default => 0,
:null => false
end
end
| Ruby |
class FixMessageParentId < ActiveRecord::Migration
def self.up
# This converts the communications parent_id from a string to an integer.
# Amazingly, it works as a string, which is why it took a while to
# notice the problem. Even more amazingly, this conversion works
# even for an existing database;... | Ruby |
class RenameEventsToActivities < ActiveRecord::Migration
def self.up
remove_index :events, :item_id
remove_index :events, :item_type
remove_index :feeds, [:person_id, :event_id]
rename_table :events, :activities
rename_column :feeds, :event_id, :activity_id
add_index :activities, ... | Ruby |
class CreatePhotos < ActiveRecord::Migration
def self.up
create_table :photos do |t|
t.integer :person_id
t.integer :parent_id
t.string :content_type
t.string :filename
t.string :thumbnail
t.integer :size
t.integer :width
t.integer :height
t.boolean :primar... | Ruby |
class AddWhitelistBoolPreferences < ActiveRecord::Migration
def self.up
add_column :preferences, :whitelist, :boolean, :default => false
end
def self.down
remove_column :preferences, :whitelist
end
end
| Ruby |
class CreatePeople < ActiveRecord::Migration
def self.up
create_table "people", :force => true do |t|
t.string :email, :name, :remember_token, :crypted_password
t.text :description
t.datetime :remember_token_expires_at,
:last_contacted_at,
:last_logged_in_... | Ruby |
class MoveThumbnails < ActiveRecord::Migration
class Photo < ActiveRecord::Base
end
ATTRIBUTES = %w[parent_id content_type filename thumbnail size width
height created_at updated_at]
def self.up
# Move thumbnails to their new table.
old_thumbnails = Photo.find(:all, :conditions => ... | Ruby |
class CreateGalleries < ActiveRecord::Migration
def self.up
create_table :galleries do |t|
t.integer :person_id
t.string :title
t.string :description
t.integer :photos_count, :null => false, :default => 0
t.integer :primary_photo_id
t.timestamps
end
end
def self.down
... | Ruby |
class UpdatePhotos < ActiveRecord::Migration
def self.up
add_column :photos, :avatar, :boolean
add_column :photos, :gallery_id, :integer
add_column :photos, :title, :string
add_column :photos, :position, :integer
end
def self.down
remove_column :photos, :position
remove_column :photos, :t... | Ruby |
class CreateCommunications < ActiveRecord::Migration
def self.up
create_table :communications do |t|
t.string :subject
t.text :content
t.string :parent_id
t.integer :sender_id
t.integer :recipient_id
t.datetime :sender_deleted_at
t.datetime :sender_read_at
... | Ruby |
class AddPersonAvatar < ActiveRecord::Migration
def self.up
add_column :people, :avatar_id, :integer
end
def self.down
remove_column :people, :avatar_id
end
end
| Ruby |
class CreateEventsAndFeed < ActiveRecord::Migration
def self.up
create_table :events do |t|
t.boolean :public
t.integer :item_id
t.integer :person_id
t.string :item_type
t.timestamps
end
add_index :events, :item_id
add_index :events, :item_type
create_table :fee... | Ruby |
class ExtendPreferences < ActiveRecord::Migration
def self.up
add_column :preferences, :sidebar_title, :string
add_column :preferences, :sidebar_body, :text
end
def self.down
remove_column :preferences, :sidebar_body
remove_column :preferences, :sidebar_title
end
end
| Ruby |
class CreateConnections < ActiveRecord::Migration
def self.up
create_table :connections do |t|
t.integer :person_id
t.integer :contact_id
t.integer :status
t.timestamp :accepted_at
t.timestamps
end
add_index :connections, [:person_id, :contact_id]
end
def self.down
... | Ruby |
class AddEmailVerified < ActiveRecord::Migration
class Person < ActiveRecord::Base
end
def self.up
add_column :people, :email_verified, :boolean, :default => nil
if Preference.find(:first).email_verifications?
# This is to modify the database for the splitting between
# 'deactivated'... | Ruby |
class CreateEvents < ActiveRecord::Migration
def self.up
create_table :events do |t|
t.string :title, :null => false
t.string :description
t.references :person, :null => false
t.datetime :start_time, :null => false
t.datetime :end_time
t.boolean :reminder
t.timestamps
... | 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 |
#!/usr/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/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 |
#!/usr/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/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/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 |
#!/usr/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
# Create some files and directories so they won't be created as root.
# This doesn't do the actual installation, since that needs to be done as root.
puts "Creating empty files. Please ignore permissions error messages."
system("rake gems:install")
# Install the gem dependencies (if any).
system("... | Ruby |
#!/usr/bin/env ruby
gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9
ENV['RSPEC'] = 'true' # allows autotest to discover rspec
ENV['AUTOTEST'] = 'true' # allows autotest to run w/ color on linux
system((RUBY_PLATFORM =~ /mswin|mingw/ ? 'autotest.bat' : 'autotest'), *ARGV) ||
$stderr.puts("Unable to find auto... | 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
gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9
puts "Loading Rails environment"
ENV["RAILS_ENV"] ||= 'test'
require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT)
require 'optparse'
require 'spec/rails/spec_server'
| 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
# Create some files and directories so they won't be created as root.
# This doesn't do the actual installation, since that needs to be done as root.
puts "Creating empty files. Please ignore permissions error messages."
system("rake gems:install")
# Install the gem dependencies (if any).
system("... | Ruby |
#!/usr/bin/env ruby
# Create some files and directories so they won't be created as root.
# This doesn't do the actual installation, since that needs to be done as root.
puts "Creating empty files. Please ignore permissions error messages."
system("rake gems:install")
# Install the gem dependencies (if any).
system("... | Ruby |
#!/usr/bin/env ruby
if ARGV.any? {|arg| %w[--drb -X --generate-options -G --help -h --version -v].include?(arg)}
require 'rubygems' unless ENV['NO_RUBYGEMS']
else
gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9
ENV["RAILS_ENV"] ||= 'test'
require File.dirname(__FILE__) + "/../config/environment" unless def... | 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
if ARGV.any? {|arg| %w[--drb -X --generate-options -G --help -h --version -v].include?(arg)}
require 'rubygems' unless ENV['NO_RUBYGEMS']
else
gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9
ENV["RAILS_ENV"] ||= 'test'
require File.dirname(__FILE__) + "/../config/environment" unless def... | Ruby |
#!/usr/bin/env ruby
# Create some files and directories so they won't be created as root.
# This doesn't do the actual installation, since that needs to be done as root.
puts "Creating empty files. Please ignore permissions error messages."
system("rake gems:install")
# Install the gem dependencies (if any).
system("... | Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/console'
| Ruby |
#!/usr/bin/env ruby
gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9
ENV['RSPEC'] = 'true' # allows autotest to discover rspec
ENV['AUTOTEST'] = 'true' # allows autotest to run w/ color on linux
system((RUBY_PLATFORM =~ /mswin|mingw/ ? 'autotest.bat' : 'autotest'), *ARGV) ||
$stderr.puts("Unable to find auto... | Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/plugin'
| Ruby |
#!/usr/bin/env ruby
gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9
puts "Loading Rails environment"
ENV["RAILS_ENV"] ||= 'test'
require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT)
require 'optparse'
require 'spec/rails/spec_server'
| 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 File.dirname(__FILE__) + '/../config/boot'
require 'commands/generate'
| Ruby |
module CustomModelMatchers
# Verify that a model instance has a maximum length on the given attribute.
class MaximumLength
def initialize(attribute, maxlength)
@attribute = attribute
@maxlength = maxlength
end
def matches?(model)
@model = model
just_right = model
to... | Ruby |
# This file is copied to ~/spec when you run 'ruby script/generate rspec'
# from the project root directory.
ENV["RAILS_ENV"] = "test"
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require 'spec'
require 'spec/rails'
include AuthenticatedTestHelper
Spec::Runner.configure do |config|
# A... | Ruby |
unless ActiveRecord::Base.respond_to? :paginate
require 'will_paginate'
WillPaginate.enable
end
| Ruby |
# This is currently unused, but a nice example of how to make a cache sweeper.
class ActivitySweeper < ActionController::Caching::Sweeper
observe Activity
def after_create(activity)
clear_cache
end
def after_destroy(activity)
clear_cache
end
private
def clear_cache
logger.info ... | Ruby |
atom_feed do |feed|
feed.title(app_name + " Forum - Topic " + @topic.name)
feed.updated(@topic.posts.first.created_at)
for post in @topic.posts
feed.entry(post, :url => forum_topic_posts_url(@forum, @topic)) do |entry|
entry.title(@topic.name + ' - Comment ' + post.id.to_s)
entry.content(post.bod... | Ruby |
activities = @feed
atom_feed do |feed|
feed.title(app_name + " Activity")
feed.updated(activities.first.updated_at)
for activity in activities
feed.entry(activity, :url => activity_path(activity)) do |entry|
entry.title(strip_tags(feed_message(activity, false)))
entry.content(feed_message(activit... | Ruby |
atom_feed do |feed|
feed.title(app_name + " Forum Topics")
feed.updated(@forum.topics.first.created_at)
for topic in @forum.topics
feed.entry(topic, :url => forum_topic_url(@forum, topic.id)) do |entry|
entry.title(topic.name)
firstBody = (topic.forum_posts_count > 0) ? topic.posts.first.body : '... | Ruby |
module GalleriesHelper
end
| Ruby |
# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
## Application-wide values
def app_name
name = global_prefs.app_name
default = "Tom, Dick, and Harry"
name.blank? ? default : name
end
## Menu helpers
def menu
home = menu_... | Ruby |
module PreferencesHelper
# Return the global preferences.
# The separate line for test mode lets the tests change the global prefs
# on a test-by-test basis. Without that line, changes to the prefs
# don't show up because of the ||=. Usually, this is a feature (avoiding
# the redundant database hits is the... | Ruby |
module EventsHelper
end
| Ruby |
module PeopleHelper
def message_links(people)
people.map { |p| email_link(p)}
end
# Return a person's image link.
# The default is to display the person's icon linked to the profile.
def image_link(person, options = {})
link = options[:link] || person
image = options[:image] || :icon
image_o... | Ruby |
module SearchesHelper
# Return the model to be searched based on params.
def search_model
return "Person" if params[:controller] =~ /home/
return "ForumPost" if params[:controller] =~ /forums/
params[:model] || params[:controller].classify
end
def search_type
if params[:controller] == "... | Ruby |
module ConnectionsHelper
end
| Ruby |
module SessionsHelper
end | Ruby |
module TopicsHelper
end
| Ruby |
module EmailVerificationsHelper
end
| Ruby |
module PostsHelper
end
| Ruby |
module CommunicationsHelper
def contact_links(requested_contacts)
requested_contacts.map do |contact|
conn = Connection.conn(current_person, contact)
edit_connection_path(conn)
end
end
def message_anchor(message)
"message_#{message.id}"
end
end
| Ruby |
module MessagesHelper
def list_link_with_active(name, options = {}, html_options = {}, &block)
opts = {}
opts.merge!(:class => "active") if current_page?(options)
content_tag(:li, link_to(name, options, html_options, &block), opts)
end
def message_icon(message)
if message.new?(current_person)
... | Ruby |
module PhotosHelper
def photo_id(photo)
photo.label_from_filename.gsub(/ /,'').gsub(/\./, "_")
end
end
| Ruby |
module ForumsHelper
def forum_name(forum)
forum.name.nil? || forum.name.blank? ? "Forum ##{forum.id}" : forum.name
end
end
| Ruby |
# Helpers added to this module are available in both controllers and views.
module SharedHelper
def current_person?(person)
logged_in? and person == current_person
end
# Return true if a person is connected to (or is) the current person
def connected_to?(person)
current_person?(person) or Connection... | Ruby |
module ActivitiesHelper
# Given an activity, return a message for the feed for the activity's class.
def feed_message(activity, recent = false)
person = activity.person
case activity_type(activity)
when "BlogPost"
post = activity.item
blog = post.blog
view_blog = blog_link("#{h person... | Ruby |
module HomeHelper
end
| Ruby |
module CommentsHelper
end
| Ruby |
module BlogsHelper
def blog_tab_path(blog)
person_path(blog.person, :anchor => "tBlog")
end
def blog_tab_url(blog)
person_url(blog.person, :anchor => "tBlog")
end
end
| Ruby |
# == Schema Information
# Schema version: 20080916002106
#
# Table name: posts
#
# id :integer(4) not null, primary key
# blog_id :integer(4)
# topic_id :integer(4)
# person_id :integer(4)
# title :string(255)
# body :text
# type :string(255)... | Ruby |
# == Schema Information
# Schema version: 20080916002106
#
# Table name: page_views
#
# id :integer(4) not null, primary key
# request_url :string(200)
# ip_address :string(16)
# referer :string(200)
# user_agent :string(200)
# created_at :datetime
# updated_at ... | Ruby |
# == Schema Information
# Schema version: 20080916002106
#
# Table name: event_attendees
#
# id :integer(4) not null, primary key
# person_id :integer(4)
# event_id :integer(4)
#
class EventAttendee < ActiveRecord::Base
include ActivityLogger
belongs_to :person
belongs_to :event, :co... | Ruby |
# == Schema Information
# Schema version: 20080916002106
#
# Table name: preferences
#
# id :integer(4) not null, primary key
# domain :string(255) default(""), not null
# smtp_server :string(255) default(""), not null
# email_notifications :boolean(1) not nul... | Ruby |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.