code
stringlengths
1
1.73M
language
stringclasses
1 value
require 'rake' require 'rake/clean' require 'rake/gempackagetask' require 'rake/rdoctask' require 'rake/testtask' require 'fileutils' include FileUtils NAME = "bulkmail" VERS = "0.2.1" CLEAN.include ['**/.*.sw?', '*.gem', '.config'] RDOC_OPTS = ['--quiet', '--title', "Bulkmail Documentation", "--opname", "index.html...
Ruby
require 'net/smtp' # Symbol extensions class Symbol # Returns the symbol as a header string def to_header to_s.split('_').map{|w| w.capitalize}.join('-') end end class Array def each_slice(bunch_size) a = 0 bunch = inject([]) do |b, i| a += 1 if b.size < bunch_size b << i ...
Ruby
require 'rake' require 'rake/clean' require 'rake/gempackagetask' require 'rake/rdoctask' require 'rake/testtask' require 'fileutils' include FileUtils NAME = "bulkmail" VERS = "0.3.0" CLEAN.include ['**/.*.sw?', '*.gem', '.config'] RDOC_OPTS = ['--quiet', '--title', "Bulkmail Documentation", "--opname", "index.html...
Ruby
require File.join(File.dirname(__FILE__), 'bulkmail/thread_pool') require File.join(File.dirname(__FILE__), 'bulkmail/dns_mx') require File.join(File.dirname(__FILE__), 'bulkmail/message') require File.join(File.dirname(__FILE__), 'bulkmail/sender')
Ruby
require 'net/smtp' module BulkMail # Sender instances perform the actual work of sending an email. Each sender # sets up a thread pool (by default with up to 20 threads) for performing the # work. When creating a Sender instance, a hash of options is supplied: # # BulkMail::Sender.new({ # :list => ...
Ruby
require 'rubygems' require 'net/smtp' require 'net/dns' module BulkMail # Performs a DNS query for a domain's MX records and returns an array # of SMTP servers for the domain ordered by preference. If no records # are found an error is raised. def self.smtp_servers_for_domain(domain) res = Net::DNS::Resol...
Ruby
require 'thread' # This class implements a pool of threads. The pool hands out blocks to be # processed to any available worker thread. If no worker thread is available, # the pool blocks until any of the workers have become available. The pool # size can be specified when constructing the pool. For exmaple: # # poo...
Ruby
# Symbol extensions class Symbol # Returns the symbol as a header string def to_header return @to_header if @to_header s = to_s @to_header = (s.upcase == s) ? s : to_s.split('_').map{|w| w.capitalize}.join('-') end end class String alias_method :to_header, :to_s end module BulkMail # The M...
Ruby
class CreateCurrencies < ActiveRecord::Migration def self.up create_table :currencies do |t| t.float :usd t.float :eur t.float :rub t.timestamps end end def self.down drop_table :currencies end end
Ruby
class CreateRequests < ActiveRecord::Migration def self.up create_table :orders do |t| t.string :name t.string :phone_home t.string :phone_city_code, :limit=>5 t.string :currency_type, :limit=>2 t.float :summa t.float :sum_income t.integer :work_stag_years t.integer :work_stag_month ...
Ruby
class CreatePosts < ActiveRecord::Migration def self.up create_table :posts do |t| t.string :title, :null=>false t.integer :category_id t.text :content t.integer :user_id t.string :slug, :null=>false t.boolean :is_visible, :default=>true t.timestamps end add_index :posts, ...
Ruby
# Copyright (c) 2008 [Sur http://expressica.com] class CreateSimpleCaptchaData < ActiveRecord::Migration def self.up create_table :simple_captcha_data do |t| t.string :key, :limit => 40 t.string :value, :limit => 6 t.timestamps end end def self.down drop_table :simple_captcha_data ...
Ruby
class CreateHeaders < ActiveRecord::Migration def self.up create_table :headers do |t| t.string :title t.string :keywords t.text :description t.string :headerable_type, :limit=>20, :null=>false t.integer :headerable_id, :null=>false t.timestamps ...
Ruby
class CreateUsers < ActiveRecord::Migration def self.up create_table :users, :force => true do |t| t.column :login, :string, :limit => 40 t.column :email, :string t.column :crypted_password, :string, :limit => 40 t.column :salt, ...
Ruby
class CreatePages < ActiveRecord::Migration def self.up create_table :pages do |t| t.string :title t.text :content, :null=>false, :default=>'' t.timestamps end end def self.down drop_table :pages end end
Ruby
class AddFieldToOrder < ActiveRecord::Migration def self.up add_column :orders, :mobile, :string, :limit=>50 add_column :pages, :form_type, :integer, :limit=>1, :default=>0 end def self.down remove_column :orders, :mobile remove_column :pages, :form_type end end
Ruby
class CreateAssets < ActiveRecord::Migration def self.up create_table :assets do |t| t.integer "parent_id" t.string "content_type" t.string "filename", :limit => 80 t.string "thumbnail", :limit => 20 t.integer "size" t.integer "width" t.integer "height" t.string...
Ruby
class AddFieldsToOrders < ActiveRecord::Migration def self.up add_column :orders, :sum_all, :float add_column :orders, :posada, :string add_column :orders, :work, :string add_column :orders, :bank, :text add_column :orders, :forma, :string end def self.down remove_column :orders, :sum_all re...
Ruby
class CreateCategories < ActiveRecord::Migration def self.up create_table :categories do |t| t.string :title, :null=>false t.string :slug t.boolean :is_visible, :default=>true t.boolean :is_menu, :default=>false t.integer :page_id t.integer :parent_id t.integer :position, :default=>0 t...
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/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
#!/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 begin require File.join(File.dirname(__FILE__), '../vendor/plugins/acts_as_ferret/lib/server_manager') rescue LoadError # try the gem require 'rubygems' gem 'acts_as_ferret' require 'server_manager' end
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' 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 begin require File.join(File.dirname(__FILE__), '../vendor/plugins/acts_as_ferret/lib/server_manager') rescue LoadError # try the gem require 'rubygems' gem 'acts_as_ferret' require 'server_manager' end
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
class CategorySweeper < ActionController::Caching::Sweeper observe Category def after_create(category) expire(category) end def after_update(category) expire(category) end def after_destroy(category) expire(category) end private def expire(category) expire_fragment(:controller=>"/includes", :ac...
Ruby
xml.instruct! :xml, :version => "1.0" xml.rss :version => "2.0" do xml.channel do xml.title "Буд Финанс-Консалт RSS" xml.description "Буд Финанс-Консалт" xml.link formatted_posts_url(:rss) for post in @posts xml.item do xml.title post.title xml.description post.content ...
Ruby
module WelcomeHelper end
Ruby
# Methods added to this helper will be available to all templates in the application. module ApplicationHelper def title(content) content_for(:title) { content } end def javascript(*args) content_for(:head) { javascript_include_tag(*args) } end def stylesheet(*args) content_for(:head) { stylesheet...
Ruby
module SearchesHelper def search_item_path(item) return '#' if item.blank? case item.class.to_s when 'Category' then category_path(item) when 'Post' then post_path(item) else "#" end end end
Ruby
module OrdersHelper end
Ruby
module Admin::PostsHelper end
Ruby
module Admin::CategoriesHelper end
Ruby
module Admin::RequestsHelper end
Ruby
module Admin::PagesHelper end
Ruby
module SessionsHelper end
Ruby
module UsersHelper end
Ruby
module PostsHelper end
Ruby
module CategoryHelper end
Ruby
class Header < ActiveRecord::Base # === List of columns === # id : integer # title : string # keywords : string # description : text # headerable_type : string # headerable_id : integer # created_at : datetime # updated_at : datetim...
Ruby
class Asset < ActiveRecord::Base # === List of columns === # id : integer # parent_id : integer # content_type : string # filename : string # thumbnail : string # size : integer # width : integer # height : integer # ...
Ruby
class Post < ActiveRecord::Base include HeaderTools belongs_to :user belongs_to :category validates_presence_of :title, :content define_index do indexes :title, :as=>:name indexes :content, :as=>:content end def to_param "#{self.id}-#{self.slug}" end def before_save self.slug = title.d...
Ruby
class PodtvType attr_accessor :id, :name, :notes def initialize(options = {}) options = options.symbolize_keys @id, @name, @notes = options[:id], options[:name], options[:notes] end def symbol @name.to_s.downcase.intern end def self.[](value) @@data.find { |data| data.symbol == value.to_s...
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 Mailer < ActionMailer::Base def new_order(order) recipients Settings.config.emails subject "[SITE] Заявка на кредит" from Settings.config.from content_type "text/html" sent_on Time.now body :order => order end def new_question(name, phone, email, message) recipients Setting...
Ruby
class Category < ActiveRecord::Base include HeaderTools acts_as_nested_set has_many :posts belongs_to :page validates_presence_of :title, :slug validates_uniqueness_of :slug attr_accessor :mode, :category_id before_save :apply_mode after_save :refresh_tree named_scope :menu, :conditions=>{:is_me...
Ruby
class Picture < Asset # === List of columns === # id : integer # parent_id : integer # content_type : string # filename : string # thumbnail : string # size : integer # width : integer # height : integer # type ...
Ruby
require 'hpricot' class Currency < ActiveRecord::Base validates_numericality_of :usd, :eur, :rub cattr_accessor :parce_url, :value @@parce_url = Settings.config.currency_url def self.today @@value = find(:first, :conditions=>['DATE(created_at) = ?', Date.today]) if @@value.blank? || @@value.created_at.to_dat...
Ruby
module HeaderTools def self.included(base) base.extend(ClassMethods) end module ClassMethods def self.extended(base) base.has_one :header, :as=>:headerable, :dependent=>:destroy base.after_update :save_header base.send :include, InstanceMethods end end module Inst...
Ruby
class Page < ActiveRecord::Base include HeaderTools validates_presence_of :title, :content acts_as_enum :form_type, [:none, :standart, :restructuring] TYPES = [ ['-', :none], ["Стандартная форма", :standart], ["Реструктуризация кредитов и отсрочки", :restructuring] ] # define_index do # index...
Ruby
class Order < ActiveRecord::Base validates_presence_of :name, :email, :phone_home #validates_numericality_of :summa def currency_title case self.currency_type.to_i when 1 then 'грн.' when 2 then '$' when 3 then 'евро' end end def soz_title case self.soz when 'no' then 'Нет' when 's1...
Ruby
class PostsController < ApplicationController before_filter :rss def index @posts = Post.find(:all, :order=>"created_at DESC", :limit=>10) end def show @post = Post.find(params[:id]) end private def rss @rss_feed = true end end
Ruby
require 'credit_calc' class WelcomeController < ApplicationController def index @posts = Post.find(:all, :order=>"created_at DESC", :limit=>4) @rss_feed = true end def calculator unless params[:calc].blank? @calc = CreditCalc.new(params[:calc]) @calc.valid? ? @calc.calculate : flash[:notice] = "Воз...
Ruby
class Admin::PagesController < ApplicationController before_filter :login_required before_filter :find_category def edit @page = @category.page end def update @category.page ||= Page.new(:title=>@category.title) @category.page.update_attributes!(params[:page]) #@category.save! && @category.page.save! ...
Ruby
class Admin::PostsController < ApplicationController before_filter :login_required before_filter :find_post, :only=>[:edit, :update, :destroy] def index @posts = Post.paginate(:page=>params[:page], :per_page=>20, :order=>"created_at DESC") end def new @post = Post.new end def create @post = current_u...
Ruby
class Admin::CategoriesController < ApplicationController before_filter :login_required before_filter :find_category, :only=>[:edit, :update, :destroy] cache_sweeper :category_sweeper, :only=>[:create, :update, :destroy] def index @categories = Category.root.paginate(:page=>params[:page], :per_page=>20, :order=...
Ruby
class Admin::RequestsController < ApplicationController end
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 # reques...
Ruby
class CategoryController < ApplicationController before_filter :find_category def index if @category.is_static? render :partial=>"includes/page", :object=>@category.page, :layout=>"application" else @posts = @category.posts.paginate(:page=>params[:page], :per_page=>10, :order=>"created_at DESC") end e...
Ruby
# Filters added to this controller apply to all controllers in the application. # Likewise, all the methods added will be available for all controllers. require "rutils" require "common" require "hpricot" class ApplicationController < ActionController::Base include AuthenticatedSystem include SimpleCaptcha::Contro...
Ruby
class OrdersController < ApplicationController def create is_have = params[:order].delete(:is_have) params[:order][:has_items] = is_have.join(', ') unless is_have.blank? @order = Order.new(params[:order]) if simple_captcha_valid? && @order.valid? && @order.save Mailer.deliver_new_order(@order) ...
Ruby
class SearchesController < ApplicationController def show unless params[:q].blank? @search_text = CGI.escapeHTML(params[:q]) page = params[:page] page ||= 1 page = 1 if page.to_i == 0 @entries = ThinkingSphinx::Search.search @search_text, :per_page=>20, :page=>page end @entries ||= [] ...
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
# 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
# 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. # Include Active Record class name as root for JSON serialized output. ActiveRecord::Base.include_root_in_json = true # Store the full class name (including module namespa...
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.resource :session map.resource :search map.resources :posts map.resources :orders, :collection=>{:question=>:post} map.namespace :admin do |admin| admin.resources :categories, :has_one=>[:page] admin.resources :posts admin...
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.2.2...
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