code
stringlengths
1
1.73M
language
stringclasses
1 value
#!/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/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/inspector'
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/console'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/generate'
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
# Methods added to this helper will be available to all templates in the application. module ApplicationHelper def menu(container, item, pages) item_tag, item_opts = [item].flatten; container_tag, container_opts = [container].flatten; itens = pages.map do |url, content| link = content_tag(:a, con...
Ruby
module PagesHelper end
Ruby
class PagesController < ApplicationController def index redirect_to :action => :promo; end def promo render :layout => false; end end
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
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
# 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
ActionController::Routing::Routes.draw do |map| # The priority is based upon order of creation: first created -> highest priority. map.root :controller => "pages"; # Sample of regular route: # map.connect 'products/:id', :controller => 'catalog', :action => 'view' # Keep in mind you can assign values othe...
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
# 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 # 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
#!C:/ruby/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.log #...
Ruby
#!C:/ruby/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 impaired...
Ruby
#!C:/ruby/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.log #...
Ruby
#!C:/ruby/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 impaired...
Ruby
#!C:/ruby/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 impaired...
Ruby
#!C:/ruby/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 impaired...
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 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/runner'
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/server'
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/plugin'
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/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/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/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/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/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/destroy'
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/generate'
Ruby
class CreatePodcasts < ActiveRecord::Migration def self.up create_table :podcasts do |t| t.string :title; t.text :description; t.timestamps; end end def self.down drop_table :podcasts; end end
Ruby
class CreatePosts < ActiveRecord::Migration def self.up create_table :posts do |t| t.references :episode; t.text :body; t.timestamps; end end def self.down drop_table :posts; end end
Ruby
class CreateUsers < ActiveRecord::Migration def self.up create_table :users do |t| t.string :email, :fullname, :username, :password; t.timestamps; end end def self.down drop_table :users; end end
Ruby
class CreateTags < ActiveRecord::Migration def self.up create_table :tags do |t| t.string :name; t.timestamps; end end def self.down drop_table :tags; end end
Ruby
class CreateParticipations < ActiveRecord::Migration def self.up create_table :participations do |t| t.references :episode, :user; end end def self.down drop_table :participations; end end
Ruby
class CreateTaggings < ActiveRecord::Migration def self.up create_table :taggings, :id => false do |t| t.references :tag; t.references :taggable, :polymorphic => true; end end def self.down drop_table :taggings; end end
Ruby
class CreateMemberships < ActiveRecord::Migration def self.up create_table :memberships do |t| t.references :podcast, :user; t.boolean :owner, :default => false; end end def self.down drop_table :memberships; end end
Ruby
class CreateEpisodes < ActiveRecord::Migration def self.up create_table :episodes do |t| t.references :podcast; t.string :title, :file, :format; t.timestamps; end end def self.down drop_table :episodes; end end
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
class Tagging < ActiveRecord::Base belongs_to :tag; belongs_to :taggable, :polymorphic => true; validates_presence_of :tag_id, :taggable_id, :taggable_type; end
Ruby
require "ftools"; class Episode < ActiveRecord::Base belongs_to :podcast; has_one :post; has_many :participations; has_many :users, :through => :participations; has_many :taggings, :as => :taggable; has_many :tags, :through => :taggings; validates_presence_of :title, :file, :format, :podcast_id; val...
Ruby
class Participation < ActiveRecord::Base belongs_to :episode; belongs_to :user; validates_presence_of :episode_id, :user_id; end
Ruby
class Membership < ActiveRecord::Base belongs_to :podcast; belongs_to :user; validates_presence_of :podcast_id, :user_id; end
Ruby
class Tag < ActiveRecord::Base has_many :taggings; has_many :podcasts, :through => :taggings, :source => :taggable, :source_type => "Podcast" has_many :episodes, :through => :taggings, :source => :taggable, :source_type => "Episode" validates_presence_of :name; validates_length_of :name, :within => 1..20; ...
Ruby
class Podcast < ActiveRecord::Base attr_accessor :owners; has_many :episodes; has_many :memberships; has_many :users, :through => :memberships; has_many :taggings, :as => :taggable; has_many :tags, :through => :taggings; validates_presence_of :title, :description; validates_size_of :title, :within...
Ruby
class Post < ActiveRecord::Base belongs_to :episode; validates_presence_of :episode_id, :body; end
Ruby
class User < ActiveRecord::Base attr_accessor :own_podcasts; has_many :memberships; has_many :podcasts, :through => :memberships; has_many :participations; has_many :episodes, :through => :participations; validates_presence_of :fullname, :username, :email, :password; validates_uniqueness_of...
Ruby
module ApplicationHelper def menu(container, item, pages) item_tag, item_opts = [item].flatten; container_tag, container_opts = [container].flatten; itens = pages.map do |url, content| link = content_tag(:a, content, :href => url); extra_opts = (request.path == url) ? {:class => "actual"} :...
Ruby
module PagesHelper end
Ruby
class PagesController < ApplicationController def index redirect_to :action => :contact; end def contact end end
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 Dir def self.inside(dir) old_dir = Dir.pwd; Dir.chdir(dir); yield; Dir.chdir(old_dir); end end
Ruby
ENV["RAILS_ENV"] = "test" require File.expand_path(File.dirname(__FILE__) + "/../config/environment") require 'test_help' # I won't test validations or relationships, as they are explicit in the # models and have been already tested in the core class Test::Unit::TestCase # Transactional fixtures accelerate your te...
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
ActionController::Routing::Routes.draw do |map| # The priority is based upon order of creation: first created -> highest priority. map.root :controller => "pages"; # Sample of regular route: # map.connect 'products/:id', :controller => 'catalog', :action => 'view' # Keep in mind you can assign values othe...
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
# 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 # 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
#!E:/Developer/ruby/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.c...
Ruby
#!E:/Developer/ruby/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 severel...
Ruby
#!E:/Developer/ruby/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.c...
Ruby
#!E:/Developer/ruby/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 severel...
Ruby
#!E:/Developer/ruby/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 severel...
Ruby
#!E:/Developer/ruby/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 severel...
Ruby
class Mp3Model def Mp3Model.find_by_artist(folder, artist) 0.upto(folder.length) do |file| if file.mp3? end end end end
Ruby
$carro_global = "Honda"; $escopo = "global"; class Carro attr_accessor :escopo; def initialize carro_local = "Mercedes"; escopo = "local"; $escopo = "_global" @carro_de_instancia = "BMW"; @escopo = "de instancia"; @@escopo = "de classe"; puts "Global: "+$carro_global+" [] ...
Ruby
class Car aa end
Ruby
class Carro attr_reader :marca, :modelo; def initialize(marca, modelo) @marca = marca || "Volkswagem"; @modelo = modelo || "Polo"; end def to_s return "#{@marca} - #{@modelo}"; end end class Garagem attr_reader :carros; def initialize(*carros) @carros = []; ...
Ruby
class String def remove(*args) str = self.to_s; args.each {|s| str = str.gsub(s,"");} return str end def replace_all(*args) str = self.to_s; args[0].each {|s| str = str.gsub(s[0].to_s, s[1].to_s);} return str end end class Json attr_reader :prop...
Ruby
#hash_symbols = {:um => "um_symbol->", 1 => 1}; #hash_strings = {"um" => "um_string->", 1 => 1}; #puts hash_symbols[:um]+hash_symbols[1].to_s; #puts hash_strings["um"]+hash_symbols[1].to_s; class Teste def teste $teste = :unico_id; end end module Tal def some $try_me = :unico_id...
Ruby
############################################################ #Copyright (c) 2007 Glaucio Melo (a.k.a Proteu Alcebidiano). #Permission is hereby granted, free of charge, #to any person obtaining a copy of this software and #associated documentation files (the "Software"), #to deal in the Software wi...
Ruby
def closures_in_loop_block(nclosures=5) closures = []; #Defining an Array that will hold the closures nclosures.times do |i| closures << lambda{"Actual: i = #{i}"}; end closures; end def closures_in_loop(nclosures=5) closures = []; #Defining an Array that will hold the closures i = 0; whil...
Ruby
class Teste attr_reader :desc, :created_at; def initialize(desc) @desc = desc; @created_at = Time.now; end def initialize_copy(orig) @desc = orig.desc + " Clonada!"; @created_at = Time.now; end def to_s return "#{@desc.to_s} - #{friendly_time}"; ...
Ruby