code
stringlengths
1
1.73M
language
stringclasses
1 value
class <%= class_name %>Notifier < ActionMailer::Base def signup_notification(<%= file_name %>) setup_email(<%= file_name %>) @subject += 'Please activate your new account' @body[:url] = "http://YOURSITE/account/activate/#{<%= file_name %>.activation_code}" end def activation(<%= file_name %>) ...
Ruby
class <%= class_name %>Observer < ActiveRecord::Observer def after_create(<%= file_name %>) <%= class_name %>Notifier.deliver_signup_notification(<%= file_name %>) end def after_save(<%= file_name %>) <%= class_name %>Notifier.deliver_activation(<%= file_name %>) if <%= file_name %>.recently_activated? ...
Ruby
module AuthenticatedSystem protected # Returns true or false if the user is logged in. # Preloads @current_<%= file_name %> with the user model if they're logged in. def logged_in? current_<%= file_name %> != :false end # Accesses the current <%= file_name %> from the session. def c...
Ruby
class <%= migration_name %> < ActiveRecord::Migration def self.up create_table "<%= table_name %>", :force => true do |t| t.column :login, :string t.column :email, :string t.column :display_name, :string t.column :given_name, ...
Ruby
module AuthenticatedTestHelper # Sets the current <%= file_name %> in the session from the <%= file_name %> fixtures. def login_as(<%= file_name %>) @request.session[:<%= file_name %>] = <%= file_name %> ? <%= table_name %>(<%= file_name %>).id : nil end def content_type(type) @request.env['Content-Typ...
Ruby
require 'digest/sha1' class <%= class_name %> < ActiveRecord::Base end
Ruby
module <%= controller_class_name %>Helper end
Ruby
require "ldap" require "time" require "yaml" class <%= controller_class_name %>Controller < ApplicationController # Be sure to include AuthenticationSystem in Application Controller instead include AuthenticatedSystem # If you want "remember me" functionality, add this before_filter to Application Controller ...
Ruby
class AuthenticatedGenerator < Rails::Generator::NamedBase attr_reader :controller_name, :controller_class_path, :controller_file_path, :controller_class_nesting, :controller_class_nesting_depth, :controller_class_name, ...
Ruby
# Include hook code here
Ruby
require 'rake' require 'rake/testtask' require 'rake/rdoctask' desc 'Default: run unit tests.' task :default => :test desc 'Test the acts_as_menu plugin.' Rake::TestTask.new(:test) do |t| t.libs << 'lib' t.pattern = 'test/**/*_test.rb' t.verbose = true end desc 'Generate documentation for the acts_as_menu plug...
Ruby
# desc "Explaining what the task does" # task :acts_as_menu do # # Task goes here # end
Ruby
# Uninstall hook code here
Ruby
# Install hook code here require 'fileutils' FileUtils.cp File.dirname(__FILE__) + '/lib/menu_system.rb', \ File.dirname(__FILE__) + '/../../../lib/menu_system.rb' puts IO.read(File.join(File.dirname(__FILE__), 'README'))
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' Spec::Runner.configure do |config| # If you're not using Ac...
Ruby
class Hash def <<(hash) hash.each{|key, value| self[key] = value } end end module MenuSystem def current_role if logged_in? @current_role = User.find(session[:user_id]).roles.first.name.to_sym end end def current_menu @current_menu = menu[@current_role] @current_menu |...
Ruby
# Include hook code here
Ruby
require 'rake' require 'rake/testtask' require 'rake/rdoctask' desc 'Default: run unit tests.' task :default => :test desc 'Test the acts_as_menu plugin.' Rake::TestTask.new(:test) do |t| t.libs << 'lib' t.pattern = 'test/**/*_test.rb' t.verbose = true end desc 'Generate documentation for the acts_as_menu plug...
Ruby
# desc "Explaining what the task does" # task :acts_as_menu do # # Task goes here # end
Ruby
# Uninstall hook code here
Ruby
# Install hook code here require 'fileutils' FileUtils.cp File.dirname(__FILE__) + '/lib/menu_system.rb', \ File.dirname(__FILE__) + '/../../../lib/menu_system.rb' puts IO.read(File.join(File.dirname(__FILE__), 'README'))
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' Spec::Runner.configure do |config| # If you're not using Ac...
Ruby
class Hash def <<(hash) hash.each{|key, value| self[key] = value } end end module MenuSystem def current_role if logged_in? @current_role = User.find(session[:user_id]).roles.first.name.to_sym end end def current_menu @current_menu = menu[@current_role] @current_menu |...
Ruby
# Include hook code here
Ruby
require 'rake' require 'rake/testtask' require 'rake/rdoctask' desc 'Default: run unit tests.' task :default => :test desc 'Test the acts_as_menu plugin.' Rake::TestTask.new(:test) do |t| t.libs << 'lib' t.pattern = 'test/**/*_test.rb' t.verbose = true end desc 'Generate documentation for the acts_as_menu plug...
Ruby
# desc "Explaining what the task does" # task :acts_as_menu do # # Task goes here # end
Ruby
# Uninstall hook code here
Ruby
# Install hook code here require 'fileutils' FileUtils.cp File.dirname(__FILE__) + '/lib/menu_system.rb', \ File.dirname(__FILE__) + '/../../../lib/menu_system.rb' puts IO.read(File.join(File.dirname(__FILE__), 'README'))
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' Spec::Runner.configure do |config| # If you're not using Ac...
Ruby
class Hash def <<(hash) hash.each{|key, value| self[key] = value } end end module MenuSystem def current_role if logged_in? @current_role = User.find(session[:user_id]).roles.first.name.to_sym end end def current_menu @current_menu = menu[@current_role] @current_menu |...
Ruby
# Include hook code here
Ruby
require 'rake' require 'rake/testtask' require 'rake/rdoctask' desc 'Default: run unit tests.' task :default => :test desc 'Test the acts_as_menu plugin.' Rake::TestTask.new(:test) do |t| t.libs << 'lib' t.pattern = 'test/**/*_test.rb' t.verbose = true end desc 'Generate documentation for the acts_as_menu plug...
Ruby
# desc "Explaining what the task does" # task :acts_as_menu do # # Task goes here # end
Ruby
# Uninstall hook code here
Ruby
# Install hook code here require 'fileutils' FileUtils.cp File.dirname(__FILE__) + '/lib/menu_system.rb', \ File.dirname(__FILE__) + '/../../../lib/menu_system.rb' puts IO.read(File.join(File.dirname(__FILE__), 'README'))
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
# 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
# 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 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...
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
ActionController::Routing::Routes.draw do |map| map.resources :users map.resource :session # 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 assig...
Ruby
# Methods added to this helper will be available to all templates in the application. module ApplicationHelper end
Ruby
module UsersHelper end
Ruby
module SessionsHelper end
Ruby
class Role < ActiveRecord::Base end
Ruby
# This controller handles the login/logout function of the site. class SessionsController < ApplicationController # Be sure to include AuthenticationSystem in Application Controller instead include AuthenticatedSystem # render new.rhtml def new end def create self.current_user = User.authenticate(pa...
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 # AuthenticatedSystem must be included for RoleRequirement, and is provided by installing acts_as_authenticates...
Ruby
class UsersController < ApplicationController # Be sure to include AuthenticationSystem in Application Controller instead include AuthenticatedSystem # render new.rhtml def new end def create cookies.delete :auth_token # protects against session fixation attacks, wreaks havoc with # request fo...
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/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/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/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/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 $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../vendor/plugins/rspec/lib")) require 'spec' exit ::Spec::Runner::CommandLine.run(::Spec::Runner::OptionParser.parse(ARGV, STDERR, STDOUT))
Ruby
#!/usr/bin/env ruby $LOAD_PATH.unshift File.dirname(__FILE__) + '/../../rspec/lib' # For svn $LOAD_PATH.unshift File.dirname(__FILE__) + '/../vendor/plugins/rspec/lib' # For rspec installed as plugin require 'rubygems' require 'drb/drb' require 'rbconfig' require 'spec' require 'optparse' # This is based on Florian We...
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/console'
Ruby
#!/usr/bin/env ruby $LOAD_PATH.unshift File.dirname(__FILE__) + '/../../rspec/lib' # For svn $LOAD_PATH.unshift File.dirname(__FILE__) + '/../vendor/plugins/rspec/lib' # For rspec installed as plugin require 'rubygems' require 'drb/drb' require 'rbconfig' require 'spec' require 'optparse' # This is based on Florian We...
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
#!/usr/bin/env ruby $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../vendor/plugins/rspec/lib")) require 'spec' exit ::Spec::Runner::CommandLine.run(::Spec::Runner::OptionParser.parse(ARGV, STDERR, STDOUT))
Ruby
class CreateRoles < ActiveRecord::Migration def self.up create_table "roles" do |t| t.column :name, :string end # generate the join table create_table "roles_users", :id => false do |t| t.column "role_id", :integer t.column "user_id", :integer end add_index "r...
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 'spec/rails/story_adapter'
Ruby
dir = File.dirname(__FILE__) Dir[File.expand_path("#{dir}/**/*.rb")].uniq.each do |file| require file end
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' Spec::Runner.configure do |config| # If you're not using ActiveRecord ...
Ruby
# Main module for authentication. # Include this in ApplicationController to activate RoleRequirement # # See RoleSecurityClassMethods for some methods it provides. module RoleRequirementSystem def self.included(klass) klass.send :class_inheritable_array, :role_requirements klass.send :include, RoleS...
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
# Hijacker class # # This class is used by RoleRequirementTestHelper to temporarily hijack a controller action for testing # # It can be used for other tests as well. # # You can contract the author with questions # Tim C. Harper - irb(main):001:0> ( 'tim_see_harperATgmail._see_om'.gsub('_see_', 'c').gsub('AT'...
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
class Hash # Sintax sugar for merge Hash def <<(hash) self.merge! hash end end module MenuSystem # Set roles of current user def current_roles @current_roles = [:guest] if logged_in? @current_roles = [:member] User.find(session[:user_id]).roles.each{|r| @current_roles << r.name.to_s...
Ruby
# Include this is test_helper.rb to enable test-case helper support for RoleRequirement via: # include RoleRequirementTestHelper # # RoleRequirementTestHelper uses the power of ruby to temporarily "hijack" your target action. (don't worry, it puts things back the way it was after it runs) # This means that the o...
Ruby
#!/usr/bin/ruby1.8 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/ruby1.8 # # 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
ENV["RAILS_ENV"] = "test" require File.expand_path(File.dirname(__FILE__) + "/../config/environment") require 'test_help' class Test::Unit::TestCase # RoleRequirementTestHelper must be included to test RoleRequirement include RoleRequirementTestHelper # Transactional fixtures accelerate your tests by wrapping e...
Ruby
class Hash # Sintax sugar for merge Hash def <<(hash) self.merge! hash end end module MenuSystem # Set roles of current user def current_roles @current_roles = [:guest] if logged_in? @current_roles = [:member] User.find(session[:user_id]).roles.each{|r| @current_roles << r.name.to_s...
Ruby
# Be sure to restart your web server when you modify this file. # Uncomment below to force Rails into production mode # (Use only when you can't set environment variables through your web/app server) # ENV['RAILS_ENV'] ||= 'production' # Bootstrap the Rails environment, frameworks, and default configuration require F...
Ruby
require 'active_merchant' require 'active_merchant/billing/integrations/action_view_helper' ActionView::Base.send(:include, ActiveMerchant::Billing::Integrations::ActionViewHelper)
Ruby
require 'rubygems' require 'rake' require 'rake/testtask' require 'rake/rdoctask' require 'rake/gempackagetask' require 'rake/contrib/rubyforgepublisher' require File.dirname(__FILE__) + '/lib/tasks/cia' PKG_VERSION = "1.0.3" PKG_NAME = "activemerchant" PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}" PKG_FILES = FileLi...
Ruby
#!/usr/bin/env ruby begin require 'active_support' rescue LoadError require 'rubygems' require 'active_support' end require 'erb' require 'script/generator/generator' ActiveMerchant::Generator::Generator.run(ARGV)
Ruby