code stringlengths 1 1.73M | language stringclasses 1
value |
|---|---|
module ActiveScaffold::DataStructures
# Wrapper for error strings so that they may be exported using to_xxx
class ErrorMessage
def initialize(error)
@error = error
end
def public_attributes
{ :error => @error }
end
def to_xml
public_attributes.to_xml(:root => "errors")
en... | Ruby |
require File.join(File.dirname(__FILE__), '../test_helper.rb')
class ArrayTest < Test::Unit::TestCase
def test_after
@sequence = ['a', 'b', 'c']
assert_equal 'b', @sequence.after('a')
assert_equal 'c', @sequence.after('b')
assert_equal 'a', @sequence.after('c')
assert_equal nil, @sequence.after(... | Ruby |
require File.join(File.dirname(__FILE__), '../test_helper.rb')
class PermissionModel < ActiveRecord::Base
def self.columns; [] end
def authorized_for_read?; true; end
def authorized_for_update?; false; end
#def authorized_for_create?; end
def a1_authorized?; true; end
def a2_authorized?; false; end
#de... | Ruby |
class ConstMocker
def initialize(*const_names)
@const_names = const_names
@const_states = {}
@const_names.each{|const_name|
@const_states[const_name] = Object.const_defined?(const_name) ? Object.const_get(const_name) : nil
}
end
def remove
@const_names.each{|const_name|
Object.s... | Ruby |
class ModelStub < ActiveRecord::Base
abstract_class = true
has_one :other_model, :class_name => 'ModelStub'
has_many :other_models, :class_name => 'ModelStub'
cattr_accessor :stubbed_columns
self.stubbed_columns = [:a, :b, :c, :d, :id]
attr_accessor *self.stubbed_columns
def other_model=(val)
@oth... | Ruby |
test_folders = %w[bridges config data_structures extensions misc]
all_tests = test_folders.inject([]) {|output, folder|
output + Dir[File.join(File.dirname(__FILE__), "#{folder}/**/*.rb")]
}
all_tests.each{|filename|
require filename
} | Ruby |
require 'test/unit'
require File.expand_path(File.join(File.dirname(__FILE__), '../../../../config/environment.rb'))
for file in %w[model_stub const_mocker]
require File.join(File.dirname(__FILE__), file)
end
ModelStub.connection.instance_eval do
def quote_column_name(name)
name
end
end | Ruby |
tags = {
"NAV" => IO.read("_nav.html")
}
swf_copies = {
"buttons/basic_button.swf" => [
"buttons/basic_button_link.swf",
"buttons/basic_button_event.swf",
"buttons/basic_button_event2.swf",
... | Ruby |
#!/usr/bin/ruby
require 'rubygems'
require 'stomp'
require 'xmlsimple'
@conn = Stomp::Connection.open 'system', 'manager', 'localhost', 61613, false
@count = 0
@conn.subscribe "/topic/STOCKS.JAVA", { :ack =>"auto" }
@conn.subscribe "/topic/STOCKS.IONA", { :ack =>"auto" }
while @count < 100
@msg = @conn.receive
@... | Ruby |
#!/usr/bin/ruby
require 'rubygems'
require 'stomp'
require 'xmlsimple'
@conn = Stomp::Connection.open 'system', 'manager', 'localhost', 61613, false
@count = 0
@conn.subscribe "/topic/STOCKS.JAVA", { :ack =>"auto" }
@conn.subscribe "/topic/STOCKS.IONA", { :ack =>"auto" }
while @count < 100
@msg = @conn.receive
@... | Ruby |
namespace :arviz do
namespace :argraph do
task :create => :environment do
ar_graph = File.open("#{RAILS_ROOT}/db/argraph.dot", "w")
ActiveRecordViz::ActiveRecordGraph.generate(:file => ar_graph, :show_columns => false)
ar_graph.close
end
end
end
| Ruby |
module ActiveRecordViz
class ActiveRecordGraph
def self.generate(opts = {})
if opts[:file].nil?
graph_file = StringIO.new("", "w")
return_graph_as_string = true
else
graph_file = opts[:file]
return_graph_as_string = false
end
show_column_names = opts... | Ruby |
require 'mongrel_cluster/recipes'
# This defines a deployment "recipe" that you can feed to capistrano
# (http://manuals.rubyonrails.com/read/book/17). It allows you to automate
# (among other things) the deployment of your application.
# =============================================================================
#... | 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 |
# Be sure to restart your web 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 ... | Ruby |
# Don't change this file. Configuration is done in config/environment.rb and config/environments/*.rb
unless defined?(RAILS_ROOT)
root_path = File.join(File.dirname(__FILE__), '..')
unless RUBY_PLATFORM =~ /(:?mswin|mingw)/
require 'pathname'
root_path = Pathname.new(root_path).cleanpath(true).to_s
end
... | Ruby |
ActionController::Routing::Routes.draw do |map|
##########################
# G R A P H S #
##########################
map.activity_graph 'graphs/activity.:format/:year/:month/:day/:period',
:controller=>'graphs',
:action=>'activity',
:requirement=>{:format=>/xml/, :year=>/(19|20)\d\d/, :m... | Ruby |
xml.chart :showBorder=>0, :bgColor=>'ffffff', :showValues=>0, :numberPrefix=>'$', :plotGradientColor=>'', :formatNumberScale=>0 do
xml.categories do
@period.each do |date|
xml.category :label=>date.day
end
end
xml.dataSet :seriesName=>'Income' do
sum = 0
@period.each do |date|
sum ... | Ruby |
xml.graph :showBorder=>0, :bgColor=>'ffffff', :showValues=>1, :numberPrefix=>'$', :baseFontColor=>'000000', :outCnvBaseFontColor=>'666666' do
@data_points.sort.each_with_index do |point, index|
xml.dataSet do
xml.set :x=>index + 1 , :y=>point.value, :z=>point.number, :name=>point.name, :toolText=>"#{poin... | Ruby |
xml.chart :showBorder=>0, :bgColor=>'ffffff', :showValues=>0, :numberPrefix=>'$', :plotGradientColor=>'', :formatNumberScale=>0 do
xml.categories do
@period.each do |date|
xml.category :label=>date.day
end
end
xml.dataSet :seriesName=>'Income' do
sum = 0
@period.each do |date|
sum ... | Ruby |
xml.graph :caption=>'In/Out for '+humanize_period(@period), :numberPrefix=>'$', :decimals=>0, :formatNumberScale=>0 do
xml.categories do
xml.category :label=>'Income'
xml.category :label=>'Expenses'
end
xml.dataset do
xml.set :value=>current_user.sum_income(@period), :color=>'00dd00'
xml.set :v... | Ruby |
xml.chart :showBorder=>0, :bgColor=>'ffffff', :showValues=>0, :numberPrefix=>'$', :plotGradientColor=>'', :formatNumberScale=>0 do
xml.categories do
@period.each do |date|
xml.category :label=>date.day
end
end
xml.dataSet :seriesName=>'Income' do
sum = 0
@period.each do |date|
sum ... | Ruby |
module JobsHelper
end
| Ruby |
module PublicHelper
end
| Ruby |
# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
def color_value(value)
return ' ' if value.nil?
if value < 0
content_tag :span, number_with_delimiter(value*-1), :class=>'red'
elsif value > 0
content_tag :span, number_with_deli... | Ruby |
module TasksHelper
end
| Ruby |
module UsersHelper
end
| Ruby |
module RegisterHelper
end
| Ruby |
module GraphsHelper
end
| Ruby |
module SessionsHelper
end
| Ruby |
module RecurringsHelper
end
| Ruby |
module PaychecksHelper
end
| Ruby |
module HomeHelper
end
| Ruby |
module ItemsHelper
end
| Ruby |
class Paycheck < ActiveRecord::Base
belongs_to :item, :protected=>true
belongs_to :job, :protected=>true
has_many :tasks, :dependent=>:nullify
# Virtual attr paid for checkbox
attr_accessor :paid
def paid=(value)
if value == true || value.to_i == 1
@paid = true
else
@paid = false
... | Ruby |
class Task < ActiveRecord::Base
def self.on(date)
find :all, :conditions=>{:date=>date}
end
belongs_to :job, :protected=>true
belongs_to :paycheck
attr_accessor :hours, :min
def hours
return if minutes.blank?
minutes < 60 ? nil : minutes.div(60)
end
def min
return if minutes.blank?... | Ruby |
require 'digest/sha1'
class User < ActiveRecord::Base
##########################################
# C L A S S M E T H O D S #
##########################################
def self.authenticate(email, password)
return nil if email.blank? or password.blank?
user = User.find_by_email(email)
... | Ruby |
class Tag < ActiveRecord::Base
has_many :taggings, :dependent=>:destroy
has_many :items, :through=>:taggings
before_validation :strip_spaces
def strip_spaces
self.name = name.strip unless name.nil?
end
validates_presence_of :name
validates_uniqueness_of :name
end
| Ruby |
class Job < ActiveRecord::Base
def self.active
find :all, :conditions=>{:active=>true}, :order=>:name
end
belongs_to :user, :protected=>true
has_many :paychecks, :order=>:created_at, :dependent=>:destroy do
def unpaid
find :all, :conditions=>{:item_id=>nil}
end
end
has_many :tasks... | Ruby |
class Tagging < ActiveRecord::Base
belongs_to :item
belongs_to :tag
validates_presence_of :tag, :item
validates_uniqueness_of :tag_id, :scope=>:item_id
end
| Ruby |
class Recurring < ActiveRecord::Base
def self.on(date)
find :all, :conditions=>{:day=>date.mday}
end
belongs_to :user, :protected=>true
def value=(new_value)
new_value = new_value.to_s
return if new_value.blank?
new_value = '-' + new_value unless new_value =~ /^(\+|-)/
write_attribute ... | Ruby |
class Item < ActiveRecord::Base
##########################################
# C L A S S M E T H O D S #
##########################################
# Find all Items on a date or in a date range
def self.on(date)
find :all, :conditions=>{:date=>date}, :order=>:date
end
# Ideally during wou... | Ruby |
class PublicController < ApplicationController
skip_before_filter :login_required
def index
# check if user should be logged in
if !session[:user_id].nil?
redirect_to home_path
elsif !cookies[:user_id].nil? and !cookies[:password_hash].nil?
user = User.find(cookies[:user_id])
if use... | Ruby |
class PaychecksController < ApplicationController
before_filter :load_job
# GET /jobs/1/paychecks.xml
# GET /jobs/1/paychecks.xml?&offset=50
def index
offset = params[:offset].to_i
@paychecks = @job.paychecks.find(:all, :limit=>50, :offset=>offset)
respond_to do |format|
format.html { rend... | Ruby |
class HomeController < ApplicationController
# GET /home
def index
@period = TimePeriod.month_to_date
# If no activity this month, try the last week
@period = @week if current_user.items.during(@period).size == 0
# If no activity in the last week, punt
@period = nil if current_user.it... | Ruby |
class RegisterController < ApplicationController
# GET /register/2007/1
# POST /register?&date[year]=2007&date[month]=1
def index
if request.method == :post
year = params[:date][:year].to_i
month = params[:date][:month].to_i
start = Date.new(year, month, 1)
ending = Date.civil(year... | Ruby |
class TasksController < ApplicationController
# GET /tasks.xml
# GET /tasks.xml?&offset=50
# GET /tasks.xml?&on=20070101
# GET /tasks.xml?&on=20070101&offest=50
# GET /tasks.xml?&job_id=1
# GET /tasks.xml?&job_id=1&on=20070101
# GET /tasks.xml?&job_id=1&on=20070101&offset=50
def index
offset = pa... | Ruby |
class JobsController < ApplicationController
# GET /jobs
# GET /jobs.xml
def index
@jobs = current_user.jobs.find(:all)
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @jobs.to_xml(:except=>[:user_id, :created_at]) }
end
end
# GET /jobs/1
# G... | Ruby |
class SessionsController < ApplicationController
skip_before_filter :login_required
layout 'public'
# GET /login
def login
end
# GET /logout
def logout
clear_session
redirect_to welcome_path
end
# POST /authenticate
def authenticate
user = User.authenticate(params[:email], params[:pas... | Ruby |
class ItemsController < ApplicationController
# GET /items.xml
# GET /items.xml?&offset=50
# GET /items.xml?&on=20070101
# GET /items.xml?&on=20070101&offest=50
def index
offset = params[:offset].to_i
if params[:on].nil?
@items = current_user.items.find(:all, :offset=>offset, :limit=>50... | Ruby |
class GraphsController < ApplicationController
before_filter :period_assign_whole_month, :only=>[:in_out_bar, :tag_bubble]
before_filter :period_assign_to_today, :only=>[:activity]
layout false
# GET /graphs/activity.xml
# GET /graphs/activity.xml/2007
# GET /graphs/activity.xml/2007/1
# GET /gra... | Ruby |
class RecurringsController < ApplicationController
# GET /recurrings
# GET /recurrings.xml
def index
@recurrings = current_user.recurrings.find(:all)
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml=>@recurrings.to_xml(:except=>:user_id) }
end
end
# GE... | Ruby |
# 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
include AuthorizationSystem
include ExceptionNotifiable
# Load ExceptionNotifiable config
# Consider i... | Ruby |
class UsersController < ApplicationController
skip_before_filter :login_required, :only=>[:new, :create]
layout 'public'
# GET /users/new
def new
@user = User.new
set_captcha
end
# POST /users
# Don't allow creation by XML
def create
@user = User.new(params[:user])
if captcha_passed? a... | 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 |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/breakpointer' | 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/runner' | 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/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/profiler'
| 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/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/breakpointer' | 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/console' | 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/process/inspector'
| 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/reaper'
| 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/destroy' | 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/server' | 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/plugin' | Ruby |
class CreatePaychecks < ActiveRecord::Migration
def self.up
create_table :paychecks do |t|
t.column :job_id, :integer
t.column :item_id, :integer
t.column :created_at, :datetime
t.column :description, :string
t.column :value, :decimal, :scale=>2, :precision=>8
... | Ruby |
class CategoriesToTags < ActiveRecord::Migration
def self.up
for item in Item.find(:all, :conditions=>"category_id is not null")
tag = Tag.find_or_create_by_name item.category.name.downcase
item.tags << tag
item.save!
end
end
def self.down
Tagging.find(:all).each(&:destroy)
Tag.... | Ruby |
class RenameTimeZone < ActiveRecord::Migration
def self.up
rename_column :users, :timezone, :time_zone
end
def self.down
rename_column :users, :time_zonze, :timezone
end
end
| Ruby |
class AddDescriptionToTasks < ActiveRecord::Migration
def self.up
add_column :tasks, :description, :string
end
def self.down
remove_column :tasks, :description
end
end
| Ruby |
class CreateItems < ActiveRecord::Migration
def self.up
create_table :items do |t|
t.column :user_id, :integer
t.column :category_id, :integer
t.column :date, :date
t.column :value, :integer
t.column :description, :text
end
add_index :items, :user_id
add_index :items, :da... | Ruby |
class CreateTaggings < ActiveRecord::Migration
def self.up
create_table :taggings do |t|
t.timestamps
t.integer :tag_id, :item_id
end
end
def self.down
drop_table :taggings
end
end
| Ruby |
class CreateCategories < ActiveRecord::Migration
def self.up
create_table :categories do |t|
t.column :name, :string
t.column :user_id, :integer
end
add_index :categories, :user_id
end
def self.down
drop_table :categories
end
end
| Ruby |
class ForgottenIndexes < ActiveRecord::Migration
def self.up
add_index :tasks, :project_id
add_index :projects, :user_id
end
def self.down
remove_index :tasks, :project_id
remove_index :projects, :user_id
end
end
| Ruby |
class CreateTasks < ActiveRecord::Migration
def self.up
create_table :tasks do |t|
t.column :project_id, :integer
t.column :created_at, :datetime
t.column :date, :date
t.column :minutes, :integer
end
end
def self.down
drop_table :tasks
end
end
| Ruby |
class AddUsersCreatedAt < ActiveRecord::Migration
def self.up
add_column :users, :created_at, :datetime, :default=>Time.now
end
def self.down
remove_column :users, :created_at
end
end
| Ruby |
class CreateTags < ActiveRecord::Migration
def self.up
create_table :tags do |t|
t.string :name
end
end
def self.down
drop_table :tags
end
end
| Ruby |
class CreateProjects < ActiveRecord::Migration
def self.up
create_table :projects do |t|
t.column :user_id, :integer
t.column :name, :string
t.column :active, :boolean, :default=>true
t.column :created_at, :datetime
t.column :rate, :integer
end
end
def self.down
drop_tab... | Ruby |
class CreateUsers < ActiveRecord::Migration
def self.up
create_table :users do |t|
t.column :email, :string, :null=>false
t.column :password_salt, :string, :null=>false
t.column :password_hash, :string, :null=>false
t.column :timezone, :string, :null=>false
end
add_index :users, :e... | Ruby |
class RenameProjectsToJobs < ActiveRecord::Migration
def self.up
rename_table :projects, :jobs
change_column :jobs, :rate, :decimal, :scale=>2, :precision=>6
rename_column :tasks, :project_id, :job_id
end
def self.down
rename_column :tasks, :job_id, :project_id
change_column :projects, :rate,... | Ruby |
class RemoveCategories < ActiveRecord::Migration
def self.up
drop_table :categories
end
def self.down
create_table "categories", :force => true do |t|
t.string "name"
t.integer "user_id"
end
add_index "categories", ["user_id"], :name => "index_categories_on_user_id"
end
end
| Ruby |
class CreateRecurrings < ActiveRecord::Migration
def self.up
create_table :recurrings do |t|
t.column :user_id, :integer
t.column :category_id, :integer
t.column :day, :integer
t.column :value, :integer
t.column :description, :text
end
add_index :recurrings, :user_id
add_... | Ruby |
class RemovePaycheckPaid < ActiveRecord::Migration
def self.up
remove_column :paychecks, :paid
end
def self.down
add_column :paychecks, :paid, :boolean
end
end
| Ruby |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.