code
stringlengths
1
1.73M
language
stringclasses
1 value
class Repository < ActiveRecord::Base require 'fileutils' before_create :link_repository before_create :create_repository before_destroy :remove_repository validates_uniqueness_of :name, :if => :name_required validates_length_of :name, :within => 1..32, :if => :name_required validates_format_of :name, :wi...
Ruby
class Membership < ActiveRecord::Base belongs_to :user belongs_to :repository end
Ruby
require 'digest/sha1' class User < ActiveRecord::Base # Virtual attribute for the unencrypted password attr_accessor :password validates_presence_of :login, :email validates_presence_of :password, :if => :password_required? validates_presence_of :password_confirmation, :if ...
Ruby
class NotesController < ApplicationController layout 'standard' before_filter :find_repository before_filter :find_notes, :only => [ :index ] def create @note = @repository.notes.new(params[:note]) if @note.save redirect_to url_for :controller => 'notes', :repository_id => @repository.id else render ...
Ruby
class RepositoriesController < ApplicationController include SendFile layout 'standard' before_filter :login_required def index @repositories = Repository.all end def create @repository = Repository.new(params[:repository]) if @repository.save redirect_to repositories_path else render :action ...
Ruby
# # Copyright (C) 2006 Warren Konkel and Bounty Source, Inc. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # T...
Ruby
class MainController < ApplicationController layout 'standard' end
Ruby
class UsersController < ApplicationController layout 'standard' # before_filter :login_required # before_filter :admin_required def create cookies.delete :auth_token # protects against session fixation attacks, wreaks havoc with # request forgery protection. # uncomment at your own risk # r...
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 helper :all # include all helpers, all the time # See ActionController::RequestForgeryProtection for details...
Ruby
class MembersController < ApplicationController layout 'standard' before_filter :login_required before_filter :admin_required before_filter :find_repository, :find_members def index @candidates = User.find(:all, :conditions => ["role!=?", User.ADMIN_ROLE]) - @members end def regenerate_membership # remov...
Ruby
# This controller handles the login/logout function of the site. class SessionsController < ApplicationController layout 'standard' def create self.current_user = User.authenticate(params[:login], params[:password]) if logged_in? if params[:remember_me] == "1" current_user.remember_me unles...
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): # ActiveSupport::Inflector.inflections do |inflect| # inflect.plural /^(ox)$/i, '\1en' # inflect.singular /^(ox)en/i, '\1' # inflect.irregular 'person',...
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. if defined?(ActiveRecord) # Include Active Record class name as root for JSON serialized output. ActiveRecord::Base.include_root_in_json = true # Store the full clas...
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 :users map.signup '/signup', :controller => 'users', :action => 'new', :conditions => { :method => :get } map.signup '/signup', :controller => 'users', :action => 'create', :conditions => { :method => :post } map.signin '/signin', :controller => '...
Ruby
APP_ROOT = "/home/duecorda/Personal/ui_branch_of_beansrock" BACKUP_ROOT = "#{APP_ROOT}/assets" BASE_DOMAIN = "beansrock.com" SVN_PROTOCOL = "svn" REPOSITORY_ROOT = "/home/duecorda/repos" REPOSITORY_CONF = "#{REPOSITORY_ROOT}/conf" ADMIN_LOGIN = "duecorda" ADMIN_EMAIL = "duecorda@gmail.com" ADMIN_PASSWORD = "1234" SE...
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 protected # Returns true or false if the user is logged in. # Preloads @current_user with the user model if they're logged in. def logged_in? !!current_user end # Accesses the current user from the session. # Future calls avoid the database because nil is not...
Ruby
module CustCrypt require 'openssl' require 'digest/sha1' def self.encrypt(s, k) c = OpenSSL::Cipher::Cipher.new("aes-256-cbc") c.encrypt c.key = c.iv = Digest::SHA1.hexdigest(k) ret = c.update(s) ret << c.final Base64.encode64(ret) end def self.decrypt(s, k) s = Base64.decode64(s) c = OpenSSL:...
Ruby
module SendFile def xsend_file(path = nil, options = {}) require 'fileutils' path ||= "#{RAILS_ROOT}/public/images/qmark.jpg" options.reverse_merge!({ :type => "application/octet-stream", :disposition => "inline; filename=#{File.basename(path)}", :content_size => 0 }) _method = SENDFILE_METHOD || "normal_send...
Ruby
module AuthenticatedTestHelper # Sets the current user in the session from the user fixtures. def login_as(user) @request.session[:user_id] = user ? users(user).id : nil end def authorize_as(user) @request.env["HTTP_AUTHORIZATION"] = user ? ActionController::HttpAuthentication::Basic.encode_credentials...
Ruby
namespace :beansrock do desc 'Define Admin' require 'site_config.rb' task :define_admin => :environment do begin login = ADMIN_LOGIN email = ADMIN_EMAIL password = ADMIN_PASSWORD rescue error = true result_message = "configure required.\n1) cp config/site_config.rb.example config/site_config.rb\...
Ruby
class CreateMemberships < ActiveRecord::Migration def self.up create_table :memberships do |t| t.integer :repository_id t.integer :user_id t.timestamps end end def self.down drop_table :memberships end end
Ruby
class CreateRepositories < ActiveRecord::Migration def self.up create_table :repositories do |t| t.string :name t.string :path t.text :desc t.timestamps end end def self.down drop_table :repositories end end
Ruby
class CreateNotes < ActiveRecord::Migration def self.up create_table :notes do |t| t.integer :user_id t.integer :repository_id t.string :title t.text :body t.timestamps end end def self.down drop_table :notes end end
Ruby
class CreateUsers < ActiveRecord::Migration def self.up create_table "users", :force => true do |t| t.column :login, :string t.column :email, :string t.column :crypted_password, :string, :limit => 40 t.column :salt, :str...
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/bin/ruby18 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 impaired ...
Ruby
#!/usr/bin/ruby18 # # 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.log # ...
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' $LOAD_PATH.unshift "#{RAILTIES_PATH}/builtin/rails_info" 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 File.dirname(__FILE__) + '/../config/boot' require 'commands/dbconsole'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' $LOAD_PATH.unshift "#{RAILTIES_PATH}/builtin/rails_info" 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 File.dirname(__FILE__) + '/../config/boot' require 'commands/generate'
Ruby
# Methods added to this helper will be available to all templates in the application. module ApplicationHelper def only_for_admin if logged_in? && @signed_user.is_admin? yield end end def display_sign_action if logged_in? "#{link_to('&deg;Account', user_path(@signed_user))} " + "#{link_to('&deg;Sign...
Ruby
module NotesHelper def display_note_body(note) BlueCloth::new( note.body ).to_html end end
Ruby
module SessionsHelper end
Ruby
module UsersHelper end
Ruby
module MembersHelper end
Ruby
module RepositoriesHelper end
Ruby
# # Copyright (C) 2006 Warren Konkel and Bounty Source, Inc. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # T...
Ruby
module MainHelper end
Ruby
class Note < ActiveRecord::Base belongs_to :repository belongs_to :user validates_presence_of :title, :body end
Ruby
class Repository < ActiveRecord::Base require 'fileutils' require 'svn/client' require 'svn/ra' before_create :load_repository before_create :create_repository before_destroy :remove_repository validates_uniqueness_of :name, :if => :name_required validates_length_of :name, :within => 1..32, :if => :name_r...
Ruby
class Membership < ActiveRecord::Base belongs_to :user belongs_to :repository end
Ruby
require 'digest/sha1' class User < ActiveRecord::Base # Virtual attribute for the unencrypted password attr_accessor :password validates_presence_of :login, :email validates_presence_of :password, :if => :password_required? validates_presence_of :password_confirmation, :if ...
Ruby
class NotesController < ApplicationController layout 'standard' before_filter :login_required before_filter :find_repository before_filter :find_notes, :only => [ :index ] def create @note = @repository.notes.new(params[:note]) if @note.save redirect_to url_for(:controller => 'notes', :repository_id => @...
Ruby
class RepositoriesController < ApplicationController include SendFile layout 'standard' before_filter :login_required def index @repositories = Repository.find(:all, :order => "id desc") end def create @repository = Repository.new(params[:repository]) if @repository.save redirect_to repositories_pa...
Ruby
# # Copyright (C) 2006 Warren Konkel and Bounty Source, Inc. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # T...
Ruby
class MainController < ApplicationController layout 'standard' end
Ruby
class UsersController < ApplicationController layout 'standard' before_filter :login_required, :only => [ :show ] # before_filter :admin_required def create cookies.delete :auth_token # protects against session fixation attacks, wreaks havoc with # request forgery protection. # uncomment at you...
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 helper :all # include all helpers, all the time # See ActionController::RequestForgeryProtection for details...
Ruby
class MembersController < ApplicationController layout 'standard' before_filter :login_required before_filter :admin_required before_filter :find_repository, :find_members def index @candidates = User.find(:all, :conditions => ["role!=?", User.ADMIN_ROLE]) - @members end def regenerate_membership # remov...
Ruby
# This controller handles the login/logout function of the site. class SessionsController < ApplicationController layout 'standard' def create self.current_user = User.authenticate(params[:login], params[:password]) if logged_in? if params[:remember_me] == "1" current_user.remember_me unles...
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): # ActiveSupport::Inflector.inflections do |inflect| # inflect.plural /^(ox)$/i, '\1en' # inflect.singular /^(ox)en/i, '\1' # inflect.irregular 'person',...
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. if defined?(ActiveRecord) # Include Active Record class name as root for JSON serialized output. ActiveRecord::Base.include_root_in_json = true # Store the full clas...
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
beansrock_formats = { :us => '%B %d, %Y %H:%M', :default => '%l:%M%p %m/%d,%Y' } ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!(beansrock_formats) ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS.merge!(beansrock_formats)
Ruby
ActionController::Routing::Routes.draw do |map| map.resources :users map.signup '/signup', :controller => 'users', :action => 'new', :conditions => { :method => :get } map.signup '/signup', :controller => 'users', :action => 'create', :conditions => { :method => :post } map.signin '/signin', :controller => 'se...
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 protected # Returns true or false if the user is logged in. # Preloads @current_user with the user model if they're logged in. def logged_in? !!current_user end # Accesses the current user from the session. # Future calls avoid the database because nil is not...
Ruby
module CustCrypt require 'openssl' require 'digest/sha1' def self.encrypt(s, k) c = OpenSSL::Cipher::Cipher.new("aes-256-cbc") c.encrypt c.key = c.iv = Digest::SHA1.hexdigest(k) ret = c.update(s) ret << c.final Base64.encode64(ret) end def self.decrypt(s, k) s = Base64.decode64(s) c = OpenSSL:...
Ruby
module SendFile def xsend_file(path = nil, options = {}) require 'fileutils' path ||= "#{RAILS_ROOT}/public/images/qmark.jpg" options.reverse_merge!({ :type => "application/octet-stream", :disposition => "inline; filename=#{File.basename(path)}", :content_size => 0 }) _method = SENDFILE_METHOD || "normal_send...
Ruby
module AuthenticatedTestHelper # Sets the current user in the session from the user fixtures. def login_as(user) @request.session[:user_id] = user ? users(user).id : nil end def authorize_as(user) @request.env["HTTP_AUTHORIZATION"] = user ? ActionController::HttpAuthentication::Basic.encode_credentials...
Ruby
namespace :beansrock do desc 'Define Admin' require 'site_config.rb' task :define_admin => :environment do begin login = ADMIN_LOGIN email = ADMIN_EMAIL password = ADMIN_PASSWORD rescue error = true result_message = "configure required.\n1) cp config/site_config.rb.example config/site_config.rb\...
Ruby
# # jQuery File Tree Ruby Connector # # Version 1.01 # # Erik Lax # http://datahack.se # 13 July 2008 # # History # # 1.01 Initial Release # # Output a list of files for jQuery File Tree # #<settings> #root = "/absolute/path/" # or root = File.expand_path(".") #</settings> #<code> require "cgi"...
Ruby
class CreateUsers < ActiveRecord::Migration def up create_table :users do |t| t.string :profile_id t.string :email t.string :refresh_token end add_index :users, :profile_id end def down drop_table :users end end
Ruby