code
stringlengths
1
1.73M
language
stringclasses
1 value
Rails.application.configure do # Settings specified here will take precedence over those in config/application.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 suit...
Ruby
# Load the Rails application. require File.expand_path('../application', __FILE__) # Initialize the Rails application. Rails.application.initialize!
Ruby
# Set up gems listed in the Gemfile. ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
Ruby
require File.expand_path('../boot', __FILE__) require 'rails/all' # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. Bundler.require(*Rails.groups) module Buscapet class Application < Rails::Application # Settings in config/environments/* take prec...
Ruby
Rails.application.routes.draw do get 'welcome/index' # The priority is based upon order of creation: first created -> highest priority. # See how all your routes lay out with "rake routes". # You can have the root of your site routed with "root" root 'welcome#index' # Example of regular route: # get ...
Ruby
module ApplicationHelper end
Ruby
module UsuariosHelper end
Ruby
module WelcomeHelper end
Ruby
class Funcionario < ActiveRecord::Base belongs_to :usuario enum perfil: {diretor: 0, diretor_financeiro: 1, medico_veterinario: 2, tratador: 3, servicos_gerais: 4} end
Ruby
class Tratamento < ActiveRecord::Base has_one :animal end
Ruby
class Usuario < ActiveRecord::Base validates :nome, presence: true validates :email, presence: true has_one :endereco end
Ruby
class Adotante < ActiveRecord::Base belongs_to :usuario end
Ruby
class Animal < ActiveRecord::Base belongs_to :ong belongs_to :adotante enum tipo: {cachorro: 0, gato: 1} end
Ruby
class Adocao < ActiveRecord::Base belongs_to :adotante belongs_to :animal end
Ruby
class Doacao < ActiveRecord::Base belongs_to :doador belongs_to :ong end
Ruby
class Ong < ActiveRecord::Base has_many :enderecos end
Ruby
class Doador < ActiveRecord::Base belongs_to :usuario end
Ruby
class Endereco < ActiveRecord::Base end
Ruby
class UsuariosController < ApplicationController def new @usuario = Usuario.new end def create @usuario = Usuario.new(usuario_params) if @usuario.save redirect_to @usuario else render 'new' end end def show @usuario = Usuario.find(params[:id]) end def index...
Ruby
class WelcomeController < ApplicationController def index end end
Ruby
class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception 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.expand_path('../config/application', __FILE__) Rails.application.load_tasks
Ruby
source 'https://rubygems.org' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '4.1.8' # Use sqlite3 as the database for Active Record gem 'sqlite3' # Use SCSS for stylesheets gem 'sass-rails', '~> 4.0.3' # Use Uglifier as compressor for JavaScript assets gem 'uglifier', '>= 1.3.0' # Use C...
Ruby
class CreateDoacaos < ActiveRecord::Migration def change create_table :doacaos do |t| t.date :data t.decimal :valor t.references :doador, index: true t.references :ong, index: true t.timestamps end end end
Ruby
class CreateOngs < ActiveRecord::Migration def change create_table :ongs do |t| t.string :sigla t.string :nome t.string :email t.timestamps end end end
Ruby
class CreateAdocaos < ActiveRecord::Migration def change create_table :adocaos do |t| t.date :data t.references :adotante, index: true t.references :animal, index: true t.timestamps end end end
Ruby
class CreateDoadors < ActiveRecord::Migration def change create_table :doadors do |t| t.references :usuario, index: true t.timestamps end end end
Ruby
class CreateUsuarios < ActiveRecord::Migration def change create_table :usuarios do |t| t.string :nome t.string :email t.string :fone t.date :data_nascimento t.timestamps end end end
Ruby
class CreateEnderecos < ActiveRecord::Migration def change create_table :enderecos do |t| t.string :cidade t.string :logradouro t.string :cep t.timestamps end end end
Ruby
class CreateAdotantes < ActiveRecord::Migration def change create_table :adotantes do |t| t.references :usuario, index: true t.timestamps end end end
Ruby
class CreateTratamentos < ActiveRecord::Migration def change create_table :tratamentos do |t| t.date :data_inicio t.date :data_termino t.decimal :custo t.text :descricao t.timestamps end end end
Ruby
class CreateAnimals < ActiveRecord::Migration def change create_table :animals do |t| t.string :nome t.string :descricao t.references :ong, index: true t.references :adotante, index: true t.column :tipo, :integer, default: 0 t.timestamps end end end
Ruby
class AddAnimalToTratamentos < ActiveRecord::Migration def change add_column :tratamentos, :animal, :integer end end
Ruby
class AddEnderecoToUsuarios < ActiveRecord::Migration def change add_column :usuarios, :endereco_id, :integer end end
Ruby
class CreateFuncionarios < ActiveRecord::Migration def change create_table :funcionarios do |t| t.references :usuario, index: true t.column :perfil, :integer, default: 0 t.timestamps end end end
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: 'Emanuel...
Ruby
# This file is used by Rack-based servers to start the application. require ::File.expand_path('../config/environment', __FILE__) run Rails.application
Ruby
ENV['RAILS_ENV'] ||= 'test' require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' class ActiveSupport::TestCase # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. fixtures :all # Add more helper methods to be used by all tests here... end
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" cgi = CGI.new cgi.head...
Ruby
class InitialSchema < ActiveRecord::Migration def self.up end def self.down end end
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/env 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 impaire...
Ruby
#!/usr/bin/env 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
#!/usr/bin/env 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 impaire...
Ruby
#!/usr/bin/env 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 impaire...
Ruby
#!/usr/bin/env 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
#!/usr/bin/env 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 impaire...
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/breakpointer'
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 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/breakpointer'
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/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/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/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/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/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/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 will be run for all controllers in the application. # Likewise, all the methods added will be available for all controllers. class ApplicationController < ActionController::Base end
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. Configuration is done in config/environment.rb and config/environments/*.rb unless defined?(RAILS_ROOT) root_path = File.join(File.dirname(__FILE__), '..') unless RUBY_PLATFORM =~ /mswin32/ require 'pathname' root_path = Pathname.new(root_path).cleanpath(true).to_s end RAILS...
Ruby
# Be sure to restart your web 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 ...
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
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
# Copyright 2008-2009 Nokia Siemens Networks Oyj # # 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...
Ruby
#!/usr/bin/env ruby class ExampleRemoteLibrary def count_items_in_directory(path) Dir.entries(path).find_all{|i| not i.match('^\.')}.length end def strings_should_be_equal(str1, str2) puts "Comparing '#{str1}' to '#{str2}'" if str1 != str2 raise RuntimeError, "Given strings are not equal" ...
Ruby
class Entity attr_accessor :x, :y, :velx, :vely def initialize(x, y, velx, vely) @x = x @y = y @velx = velx @vely = vely end public def move_left @x -= velx end def move_right @x += velx end def move_up @y -= vely end def move_down @y += vely end end
Ruby
require 'entity' class Player < Entity attr_reader :image def initialize(window) super(0, 0, 5, 5) @image = Gosu::Image.new(window, "data/player.png", false) end end
Ruby
require 'rubygems' require 'gosu' require 'player' class BuzzKill < Gosu::Window def initialize super 640, 480, false self.caption = "BuzzKill" @hero = Player.new(self) end def update if button_down? Gosu::KbLeft or button_down? Gosu::GpLeft then @hero.move_left end if button_down?...
Ruby
#!/c/Ruby187/bin/ruby ARGV.each do |arg| cfile = File.new(arg + '.c', 'w') cfile.puts '#include "common.h"' cfile.puts "\n\n" cfile.puts "void " + arg + "_init(void)\n{\n\n}" cfile.close hfile = File.new(arg + '.h', 'w') hfile.puts '#ifndef _' + arg.upcase + '_H' hfile.puts '#define ...
Ruby
#!/c/Ruby187/bin/ruby ARGV.each do |arg| cfile = File.new(arg + '.c', 'w') cfile.puts '#include "common.h"' cfile.puts "\n\n" cfile.puts "void " + arg + "_init(void)\n{\n\n}" cfile.close hfile = File.new(arg + '.h', 'w') hfile.puts '#ifndef _' + arg.upcase + '_H' hfile.puts '#define ...
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/breakpointer'
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/breakpointer'
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