code
stringlengths
1
1.73M
language
stringclasses
1 value
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/runner'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/runner'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/server'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/generate'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/destroy'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/plugin'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/console'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/dbconsole'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) $LOAD_PATH.unshift "#{RAILTIES_PATH}/builtin/rails_info" require 'commands/about'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/server'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/dbconsole'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/console'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/plugin'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../../config/boot', __FILE__) require 'commands/performance/benchmarker'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../../config/boot', __FILE__) require 'commands/performance/profiler'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../../config/boot', __FILE__) require 'commands/performance/benchmarker'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../../config/boot', __FILE__) require 'commands/performance/profiler'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/generate'
Ruby
# Methods added to this helper will be available to all templates in the application. module ApplicationHelper 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 protect_from_forgery # See ActionController::RequestForgeryPr...
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
# Be sure to restart your server when you modify this file. # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } # You can also remove all the silencers if you're trying do debug a probl...
Ruby
# Be sure to restart your server when you modify this file. # 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. ActiveReco...
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. # Your secret key for verifying cookie session data integrity. # If you change this key, all old sessions will become invalid! # Make sure the secret is at least 30 characters and all random, # no regular words or you'll be exposed to dictionary attacks. Act...
Ruby
# Be sure to restart your server when you modify this file. # Your secret key for verifying the integrity of signed cookies. # If you change this key, all old signed cookies will become invalid! # Make sure the secret is at least 30 characters and all random, # no regular words or you'll be exposed to dictionary atta...
Ruby
ActionController::Routing::Routes.draw do |map| # 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 assign values other than :controller and :action # ...
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 # Specifies gem version of Rails to use when vendor/rails is not present RAILS_GEM_VERSION = '2.3.8' unless defined? RAILS_GEM_VERSION # Bootstrap the Rails environment, frameworks, and default configuration require File.join(File.dirname(__FILE__), 'boot') ...
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 # Full error reports are disabled and caching is turned on config.action_controller.consider_all_reque...
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
# This file is used by Rack-based servers to start the application. require ::File.expand_path('../config/environment', __FILE__) run Alex::Application
Ruby
#!/usr/bin/env rake # 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.expand_path('../config/application', __FILE__) Alex::Application.load_tasks
Ruby
require 'sinatra/activerecord/rake' require './main'
Ruby
source :gemcutter gem 'sinatra', :require => 'sinatra/base' gem 'thin', '~> 1.3' gem 'pg' gem 'sinatra-activerecord' gem 'google-api-client', '>= 0.4.4', :require => 'google/api_client' group :development do gem 'rake' gem 'sqlite3-ruby' end
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
# Copyright (C) 2012 Google Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writ...
Ruby
require 'sinatra.rb' # Sinatra defines #set at the top level as a way to set application configuration set :run, false set :env, (ENV['RACK_ENV'] ? ENV['RACK_ENV'].to_sym : :development) require './main' run Sinatra::Application
Ruby
# Require any additional compass plugins here. # Set this to the root of your project when deployed: http_path = "/" css_dir = "theme/css" sass_dir = "theme/scss" images_dir = "images" javascripts_dir = "js" # You can select your preferred output style here (can be overridden via the command line): output_style = :co...
Ruby
# This file should contain all the record creation needed to seed the database with its default values. # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). # # Examples: # # cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }]) # Mayor.create(:name =>...
Ruby
class CreateWallets < ActiveRecord::Migration def self.up create_table :wallets do |t| t.string :name, :null => false t.timestamps end end def self.down drop_table :wallets end end
Ruby
class CreateUsersWallets < ActiveRecord::Migration def self.up create_table :user_wallets, :id => false do |t| t.integer :user_id, :null => false t.integer :wallet_id, :null => false t.integer :user_type, :default => 1 # owner t.boolean :is_default_wallet, :default => false end ad...
Ruby
class CreateAmountChanges < ActiveRecord::Migration def self.up create_table :amount_changes do |t| t.references :amount t.references :operation t.decimal :delta, :default => 0 t.decimal :old_value, :default => 0 end end def self.down drop_table :amount_changes end end
Ruby
class CreateTags < ActiveRecord::Migration def self.up create_table :tags do |t| t.string :name, :null => false t.references :wallet end add_index :tags, [:wallet_id, :name], :unique => true create_table :operations_tags, :id => false do |t| t.references :tag t.references :o...
Ruby
class CreateWishLists < ActiveRecord::Migration def self.up create_table :wish_lists do |t| t.string :name t.references :user t.integer :state t.timestamps end add_index :wish_lists, [:user_id, :name], :unique => true end def self.down drop_table :wish_lists end end
Ruby
class CreateProducts < ActiveRecord::Migration def self.up create_table :products do |t| t.string :text, :limit => 140, :null => false t.references :product_tag t.integer :count end add_index :products, :product_tag_id end def self.down drop_table :products end end
Ruby
class AddDefaultWallet < ActiveRecord::Migration def self.up User.all.each do |u| u.wallets.build(:name => "default") if u.wallets.empty? u.save! end end def self.down end end
Ruby
class CreateCurrencyExchangeRates < ActiveRecord::Migration def self.up create_table :currency_exchange_rates do |t| t.integer :timestamp t.decimal :AED t.decimal :AFN t.decimal :ALL t.decimal :AMD t.decimal :ANG t.decimal :AOA t.decimal :ARS t.decimal :AUD ...
Ruby
class CreateShops < ActiveRecord::Migration def self.up create_table :shops do |t| t.string :name t.string :description t.timestamps end add_index :shops, :name, :unique => true end def self.down drop_table :shops end end
Ruby
class AddDefaultWalletToUser < ActiveRecord::Migration def self.up add_column :wallets, :is_default, :boolean, :default => false User.all.each do |user| wallet = user.wallets.first wallet.is_default = true wallet.save! end end def self.down remove_column :wallets, :is_default ...
Ruby
class CreateAuthentications < ActiveRecord::Migration def self.up create_table :authentications do |t| t.integer :user_id t.string :provider t.string :uid t.timestamps end end def self.down drop_table :authentications end end
Ruby
#!ruby19 # encoding: utf-8 class AddCurrencies < ActiveRecord::Migration def self.up add_column :currencies, :symbol, :string add_column :currencies, :num, :integer end def self.down remove_column :currencies, :symbol remove_column :currencies, :num end end
Ruby
class CreateProductTags < ActiveRecord::Migration def self.up create_table :product_tags do |t| t.references :user t.string :name end add_index :product_tags, :user_id add_index :product_tags, :name end def self.down drop_table :product_tags end end
Ruby
class CreateShopProducts < ActiveRecord::Migration def self.up create_table :shop_products do |t| t.references :shop_address t.references :product t.decimal :price t.timestamps end add_index :shop_products, [:shop_address_id, :product_id], :unique => true end def self.down ...
Ruby
class CreateScheduledRecords < ActiveRecord::Migration def self.up create_table :scheduled_records do |t| t.integer :fromDate t.integer :toDate t.integer :generatedFrom t.integer :generatedTo t.string :cron t.string :tweetJson t.references :wallet end add_inde...
Ruby
class AddOperationsCountToTag < ActiveRecord::Migration def self.up add_column :tags, :operations_count, :integer, :default => 0 end def self.down remove_column :tags, :operations_count end end
Ruby
class CreateUserProducts < ActiveRecord::Migration def self.up create_table :user_products do |t| t.references :user t.references :product t.integer :bought_count end end def self.down drop_table :user_products end end
Ruby
class CreateShopAddresses < ActiveRecord::Migration def self.up create_table :shop_addresses do |t| t.references :shop t.string :addr, :limit => 140, :null => false t.string :addr_description end add_index :shop_addresses, [:shop_id, :addr], :unique => true end def self.down dr...
Ruby
class DeviseCreateUsers < ActiveRecord::Migration def self.up create_table(:users) do |t| t.database_authenticatable :null => false t.recoverable t.rememberable t.trackable t.token_authenticatable # t.confirmable # t.lockable :lock_strategy => :failed_attempts, :unlock_s...
Ruby
class FixFieldsInRecord < ActiveRecord::Migration def self.up add_column :operations, :record_date, :integer, :null => false, :default => :created_at add_column :operations, :updated_at, :datetime, :null => false, :default => :created_at change_column :operations, :created_at, :datetime remove_colu...
Ruby
class CreateWishItems < ActiveRecord::Migration def self.up create_table :wish_items do |t| t.references :wish_list t.integer :status t.integer :mark t.references :product end add_index :wish_items, :wish_list_id end def self.down drop_table :wish_items end end
Ruby
class AddSessionsTable < ActiveRecord::Migration def self.up create_table :sessions do |t| t.string :session_id, :null => false t.text :data t.timestamps end add_index :sessions, :session_id add_index :sessions, :updated_at end def self.down drop_table :sessions end end
Ruby
class CreateAmounts < ActiveRecord::Migration def self.up create_table :amounts do |t| t.references :wallet, :null => false t.string :currency_code, :limit => 3, :null => false t.decimal :value, :default => 0 end add_index :amounts, [:wallet_id, :currency_code], :unique => true end ...
Ruby
class AddUsersForWalletsAndOperations < ActiveRecord::Migration def self.up add_column :wallets, :user_id, :integer add_column :operations, :user_id, :integer end def self.down remove_column :wallets, :user_id remove_column :operations, :user_id end end
Ruby
class AddUserDefaultCurrency < ActiveRecord::Migration def self.up add_column :users, :default_currency_code, :string, :limit => 3, end def self.down remove_column :users, :default_currency_code end end
Ruby
class CreateUserShops < ActiveRecord::Migration def self.up create_table :user_shops do |t| t.references :user t.references :shop_address t.integer :visits_count end add_index :user_shops, :user_id add_index :user_shops, :shop_address_id end def self.down drop_table :user_...
Ruby
class CreateOperations < ActiveRecord::Migration def self.up create_table :operations do |t| t.string :operation_type t.string :name t.text :description t.date :created_at end end def self.down drop_table :operations end end
Ruby
class CreateCurrencies < ActiveRecord::Migration def self.up create_table :currencies do |t| t.string :code, :limit => 3, :null => false t.string :name t.string :format end add_index :currencies, :code, :unique => true Currency.create([ {:code => 'EUR', :format => "%.2f"}, ...
Ruby
ENV["RAILS_ENV"] = "test" require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' require File.dirname(__FILE__) + "/../spec/factories.rb" require 'devise/test_helpers' class ActiveSupport::TestCase include Devise::TestHelpers # Setup all fixtures in test/fixtures/*.(yml|csv) for a...
Ruby
source "http://rubygems.org" gem "rails", "3.0.3" gem "active_enum" gem "devise", "1.2.rc" #gem "warden" #gem "oauth2" #gem "omniauth" #gem "nokogiri", "1.5.0" gem "nifty-generators" gem "mongrel", "1.2.0.pre2" gem "yaml_db" gem "citrus", "2.4.0" gem "rufus-scheduler" #gem 'automatic_foreign_key' ...
Ruby
def datas object, data_array, context = {} context[object.to_s.pluralize] = data_array.map do |op| obj = Factory(object, {}.merge!(op).merge!(context)) pp obj end context end def data object, options, context = {} obj = Factory(object, {}.merge!(options).merge!(context)) pp obj context[o...
Ruby
require 'rubygems' require 'spork' Spork.prefork do # Loading more in this block will cause your tests to run faster. However, # if you change any configuration or code from libraries loaded here, you'll # need to restart spork for it take effect. # This file is copied to spec/ when you run 'rails generate rs...
Ruby
module MyRestTestHelpers def check_json_response json @response.should be_success json = ActiveSupport::JSON.encode(json) ActiveSupport::JSON.decode(@response.body).should == ActiveSupport::JSON.decode(json) end def from_json obj ActiveSupport::JSON.decode(obj) end def to_json obj...
Ruby
# encoding: UTF-8 Factory.define :user do |f| f.sequence(:email) { |n| "user_#{n}@email.com" } f.password "123qwe" f.default_currency_code "BYR" end Factory.define :user_wallet do |u| u.association :user u.association :wallet end Factory.define :wallet do |w| w.sequence(:name) { |n| "wallet...
Ruby
require 'polyglot' require 'treetop' module ApplicationHelper def link_to_remove_fields(name, f) f.hidden_field(:_destroy) + link_to_function(name, "remove_fields(this)") end def link_to_add_fields(name, f, association) new_object = f.object.class.reflect_on_association(association).klass.new fields...
Ruby
require "tweetGrammar" module TweeHelper def self.process_tweets user, tweet return TweetGrammar::parse_tweet(tweet).map {|oo| Operation.from_tweet_options(user, oo)} end end
Ruby
class WishItem < ActiveRecord::Base belongs_to :wish_list belongs_to :product validates_presence_of :wish_list_id validates_presence_of :product_id validates_uniqueness_of :product_id, :scope => :wish_list_id def text product.text end def text= t unless self.product pt = ProductTag.crea...
Ruby
class CurrencyExchangeRate < ActiveRecord::Base validates_uniqueness_of :timestamp def external_format res = Hash.new res["timestamp"] = timestamp self.attributes.each { |k,v| res[k] = "#{v}"} res end end
Ruby
class Wallet < ActiveRecord::Base has_many :user_wallets has_many :user, :through => :user_wallets has_many :tags, :dependent => :destroy has_many :amounts, :dependent => :destroy has_many :scheduled_records, :dependent => :destroy validates_presence_of :name accepts_nested_attributes_for :amounts, :re...
Ruby
class Product < ActiveRecord::Base belongs_to :product_tag has_many :shop_products has_many :wish_items validates_presence_of :product_tag_id validates_presence_of :text validates_length_of :text, :in => 2..140, :allow_nil => false validates_uniqueness_of :text end
Ruby
class ShopProduct < ActiveRecord::Base belongs_to :shop_address belongs_to :product validates_presence_of :shop_address_id validates_presence_of :product_id validates_uniqueness_of :product_id, :scope => :shop_address_id end
Ruby
class Authentication < ActiveRecord::Base belongs_to :user def provider_name if provider == 'open_id' "OpenID" else provider.titleize end end end
Ruby
class WishList < ActiveRecord::Base belongs_to :user has_many :wish_items validates_presence_of :user_id validates_presence_of :name validates_uniqueness_of :name, :scope => :user_id accepts_nested_attributes_for :wish_items, :reject_if => lambda { |a| a["text"].blank? }, :allow_destroy => true # Statu...
Ruby
class ShopAddress < ActiveRecord::Base belongs_to :shop has_many :shop_products validates_presence_of :shop_id validates_presence_of :addr validates_length_of :addr, :in => 5..140, :allow_nil => false validates_uniqueness_of :addr, :scope => :shop_id end
Ruby
class UserProduct < ActiveRecord::Base belongs_to :user belongs_to :product validates_presence_of :user_id validates_presence_of :product_id validates_uniqueness_of :product_id, :scope => :user_id end
Ruby
class Amount < ActiveRecord::Base belongs_to :currency, :primary_key => :code, :foreign_key => :currency_code belongs_to :wallet validates_presence_of :wallet validates_presence_of :currency_code validates_uniqueness_of :currency_code, :scope => :wallet_id def currency @currency ||= Currency.find_by_c...
Ruby
class Tag < ActiveRecord::Base belongs_to :wallet has_and_belongs_to_many :operations validates_presence_of :wallet validates_presence_of :name validates_uniqueness_of :name, :scope => :wallet_id end
Ruby
require 'json' class ScheduledRecord < ActiveRecord::Base belongs_to :wallet validates_presence_of :wallet has_and_belongs_to_many :operations, :autosave => true validates_presence_of :fromDate validates_presence_of :toDate validate :validateDates, :on => :create def validateDates if !fromDate.kin...
Ruby
class User < ActiveRecord::Base has_many :authentications # Include default devise modules. Others available are: # :confirmable, :lockable and :timeoutable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :oauthable, :token_authenticatable # S...
Ruby
class ProductTag < ActiveRecord::Base has_many :products validates_presence_of :name validates_uniqueness_of :name end
Ruby
class AmountChange < ActiveRecord::Base belongs_to :operation belongs_to :amount validates_presence_of :operation validates_presence_of :amount after_create :add_changes_to_amount after_destroy :remove_changes_from_amount before_update :remove_changes_from_amount after_update :add_changes_to_amount ...
Ruby
class Currency < ActiveRecord::Base validates_presence_of :code validates_uniqueness_of :code validates_length_of :code, :is => 3 end
Ruby
class UserShop < ActiveRecord::Base belongs_to :user belongs_to :shop_address validates_presence_of :user_id validates_presence_of :shop_address_id validates_uniqueness_of :shop_address_id, :scope => :user_id end
Ruby
class UserWallet < ActiveRecord::Base belongs_to :user, :dependent => :destroy belongs_to :wallet validates_presence_of :user_id validates_presence_of :wallet_id validates_uniqueness_of :wallet_id, :scope => :user_id end
Ruby
class Shop < ActiveRecord::Base has_many :shop_addresses validates_presence_of :name validates_uniqueness_of :name end
Ruby
class Operation < ActiveRecord::Base has_many :amount_changes, :dependent => :destroy has_and_belongs_to_many :tags, :autosave => true has_and_belongs_to_many :scheduled_records belongs_to :user validates_presence_of :user accepts_nested_attributes_for :amount_changes, :reject_if => lambda { |a| a["delta"...
Ruby
class CurrencyController < ApplicationController before_filter :authenticate_user! def render_currencies_list respond_to do |format| format.html format.xml { render :xml => @currencies } format.json { render :json => @currencies.as_json } end end def index @currencies = current_u...
Ruby
class CurrencyExchangeRateController < ApplicationController before_filter :authenticate_user! def rates columns = params[:currencies] && params[:currencies].split(",") || current_user.currencies_codes if not columns.kind_of? Array renderError(5101) end columns.push("timestamp") begin ...
Ruby