code
stringlengths
1
1.73M
language
stringclasses
1 value
# Set up gems listed in the Gemfile. ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
Ruby
require File.expand_path('../boot', __FILE__) # Pick the frameworks you want: # require "active_record/railtie" require "action_controller/railtie" require "action_mailer/railtie" require "sprockets/railtie" # require "rails/test_unit/railtie" # Require the gems listed in Gemfile, including any gems # you've limited ...
Ruby
Blog::Application.routes.draw do resources :categories resources :posts do resources :comments resources :tags end # 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 route...
Ruby
json.extract! @category, :id, :name, :created_at, :updated_at
Ruby
json.array!(@categories) do |category| json.extract! category, :id, :name json.url category_url(category, format: :json) end
Ruby
json.extract! @post, :id, :title, :content, :name, :created_at, :updated_at
Ruby
json.array!(@posts) do |post| json.extract! post, :id, :title, :content, :name json.url post_url(post, format: :json) end
Ruby
module ApplicationHelper end
Ruby
module TagsHelper end
Ruby
module CategoriesHelper end
Ruby
module SubcategoriesHelper end
Ruby
module PostsHelper end
Ruby
class Category include Mongoid::Document field :name, type: String has_many :posts end
Ruby
class Comment include Mongoid::Document field :author, type: String field :body, type: String embedded_in :post end
Ruby
class Post include Mongoid::Document include Mongoid::Taggable field :title, type: String field :content, type: String field :name, type: String field :tags, type: Array tags_separator ';' embeds_many :comments belongs_to :category end
Ruby
class PostsController < ApplicationController before_action :set_post, only: [:show, :edit, :update, :destroy] # GET /posts # GET /posts.json def index @posts = Post.all @category = Category.all @tags = Post.all.tags end # GET /posts/1 # GET /posts/1.json def show() @category =...
Ruby
class CommentsController < ApplicationController def create @post = Post.find(params[:post_id]) @comment = @post.comments.create(comments_params) redirect_to post_path(@post) end def comments_params params.require(:comment).permit(:author, :body) end end
Ruby
class CategoriesController < ApplicationController before_action :set_category, only: [:show, :edit, :update, :destroy] # GET /categories # GET /categories.json def index @categories = Category.all end # GET /categories/1 # GET /categories/1.json def show @categories = Category.all 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__) Blog::Application.load_tasks
Ruby
#!/usr/bin/env ruby vendored_cucumber_bin = Dir["#{File.dirname(__FILE__)}/../vendor/{gems,plugins}/cucumber*/bin/cucumber"].first if vendored_cucumber_bin load File.expand_path(vendored_cucumber_bin) else require 'rubygems' unless ENV['NO_RUBYGEMS'] require 'cucumber' load Cucumber::BINARY end
Ruby
#!/usr/bin/env ruby vendored_cucumber_bin = Dir["#{File.dirname(__FILE__)}/../vendor/{gems,plugins}/cucumber*/bin/cucumber"].first if vendored_cucumber_bin load File.expand_path(vendored_cucumber_bin) else require 'rubygems' unless ENV['NO_RUBYGEMS'] require 'cucumber' load Cucumber::BINARY end
Ruby
source 'https://rubygems.org' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' require 'mongo' gem 'rails', '4.0.1' gem 'mongoid', github: 'mongoid/mongoid' gem 'mongo_mapper' gem 'bson_ext' gem 'devise', '~>3.0.0.rc' gem "mongoid-tags-arent-hard", "~> 1.1.4" gem 'mongoid_taggable' group :test do ge...
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 copied to spec/ when you run 'rails generate rspec:install' ENV["RAILS_ENV"] ||= 'test' require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' require 'rspec/autorun' # Requires supporting ruby files with custom matchers and macros, etc, # in spec/support/ and its subdirect...
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(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
#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/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/dispat...
Ruby
#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/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 Fast...
Ruby
#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/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/dispat...
Ruby
#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/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/dispat...
Ruby
#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/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 Fast...
Ruby
#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/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/dispat...
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/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/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
# Methods added to this helper will be available to all templates in the application. module ApplicationHelper end
Ruby
module SpeechHelper 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 SpeechController < ApplicationController require 'lib/speech' before_filter :get_speaker def index if request.post? @speech.set_voice(params[:voice_index].to_i) @speech.speak(params[:text]) end end def get_speaker @speech = CocoaSpeak.new end end
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
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 # 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
# 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 'osx/cocoa' include OSX prefix = "com.apple.speech.synthesis.voice." require 'enumerator' VOICES = NSSpeechSynthesizer.availableVoices def display_voices puts VOICES.to_enum(:each_with_index).map {|x, i| "[#{i}] " + x.split('.')[-1] }.join("\t") end display_voices puts "type the number of the voice, and...
Ruby
require 'osx/cocoa' include OSX prefix = "com.apple.speech.synthesis.voice." require 'enumerator' class CocoaSpeak VOICES = NSSpeechSynthesizer.availableVoices def initialize @voice = VOICES[2] @volume = 1.0 @speech = NSSpeechSynthesizer.alloc.initWithVoice(@voice) @speech.setVolume(@volume) en...
Ruby
""" LDTP v2 ruby client. @author: Nagappan Alagappan <nagappan@gmail.com> @copyright: Copyright (c) 2009-13 Nagappan Alagappan @license: LGPL http://ldtp.freedesktop.org This file may be distributed and/or modified under the terms of the GNU Lesser General Public License version 2 as published by the Free Software ...
Ruby
require "ldtp" ldtp = Ldtp.new('*-gedit') #puts ldtp.launchapp('gedit') #puts ldtp.wait(2) #puts ldtp.selectmenuitem('File;Open') #puts ldtp.waittillguinotexist :guiTimeOut => 5 #puts ldtp.click("btnOpen") #ldtp.window_name = "dlgOpenFiles" #puts ldtp.waittillguiexist(:obj_name => "btnCancel") #puts ldtp.click("btnCa...
Ruby
# http://wiki.openqa.org/display/WTR/HTML+report+class class XMLReporter # Initialize the report class def initialize() @overallResult = 'PASSED' @reportContent1 = '' @reportContent2 = '' @tcNbr = 1 end # Create a report def createReport(reportName) # Get current time t = Time.now ...
Ruby
# http://wiki.openqa.org/display/WTR/HTML+report+class class HtmlReporter # Initialize the report class def initialize() @overallResult = 'PASSED' @reportContent1 = '' @reportContent2 = '' @tcNbr = 1 end # Create a report def createReport(reportName) # Get current time t = Time.now...
Ruby
def buildParameterString if ($ss.cell($line,$PARAMETER2) == "") or ($ss.cell($line,$PARAMETER2) == nil) then $parameters = $ss.cell($line,$PARAMETER1) else $parameters = $ss.cell($line,$PARAMETER1) + "|" + $ss.cell($line,$PARAMETER2) end end def buildExpectedResult if ($ss.cell($line,$EXPECTED_R...
Ruby
require 'library/html_reporter.rb' require 'library/xml_reporter.rb' require 'library/methods.rb' require 'rbconfig' require 'watir' require 'funfx' require 'funfx/browser/firewatir' require 'roo' require 'trollop' require 'builder' begin opts = Trollop::options do version "0.1 Alpha (c) Robert H. Koertge Jr." ...
Ruby
#!/usr/bin/ruby if ARGV.length < 2 puts "Usage: ruby sign_update.rb update_archive private_key" exit end puts `openssl dgst -sha1 -binary < "#{ARGV[0]}" | openssl dgst -dss1 -sign "#{ARGV[1]}" | openssl enc -base64`
Ruby
#!/usr/bin/ruby if ARGV.length < 2 puts "Usage: ruby sign_update.rb update_archive private_key" exit end puts `openssl dgst -sha1 -binary < "#{ARGV[0]}" | openssl dgst -dss1 -sign "#{ARGV[1]}" | openssl enc -base64`
Ruby
#!/usr/bin/ruby if ARGV.length < 2 puts "Usage: ruby sign_update.rb update_archive private_key" exit end puts `openssl dgst -sha1 -binary < "#{ARGV[0]}" | openssl dgst -dss1 -sign "#{ARGV[1]}" | openssl enc -base64`
Ruby
#!/usr/bin/ruby if ARGV.length < 2 puts "Usage: ruby sign_update.rb update_archive private_key" exit end puts `openssl dgst -sha1 -binary < "#{ARGV[0]}" | openssl dgst -dss1 -sign "#{ARGV[1]}" | openssl enc -base64`
Ruby
#!/usr/bin/ruby if ARGV.length < 2 puts "Usage: ruby sign_update.rb update_archive private_key" exit end puts `openssl dgst -sha1 -binary < "#{ARGV[0]}" | openssl dgst -dss1 -sign "#{ARGV[1]}" | openssl enc -base64`
Ruby
#!/usr/bin/ruby if ARGV.length < 2 puts "Usage: ruby sign_update.rb update_archive private_key" exit end puts `openssl dgst -sha1 -binary < "#{ARGV[0]}" | openssl dgst -dss1 -sign "#{ARGV[1]}" | openssl enc -base64`
Ruby
#!/usr/bin/ruby if ARGV.length < 2 puts "Usage: ruby sign_update.rb update_archive private_key" exit end puts `openssl dgst -sha1 -binary < "#{ARGV[0]}" | openssl dgst -dss1 -sign "#{ARGV[1]}" | openssl enc -base64`
Ruby
#!/usr/bin/ruby if ARGV.length < 2 puts "Usage: ruby sign_update.rb update_archive private_key" exit end puts `openssl dgst -sha1 -binary < "#{ARGV[0]}" | openssl dgst -dss1 -sign "#{ARGV[1]}" | openssl enc -base64`
Ruby
#!/usr/bin/ruby if ARGV.length < 2 puts "Usage: ruby sign_update.rb update_archive private_key" exit end puts `openssl dgst -sha1 -binary < "#{ARGV[0]}" | openssl dgst -dss1 -sign "#{ARGV[1]}" | openssl enc -base64`
Ruby
#!/usr/bin/ruby if ARGV.length < 2 puts "Usage: ruby sign_update.rb update_archive private_key" exit end puts `openssl dgst -sha1 -binary < "#{ARGV[0]}" | openssl dgst -dss1 -sign "#{ARGV[1]}" | openssl enc -base64`
Ruby
#!/usr/bin/ruby if ARGV.length < 2 puts "Usage: ruby sign_update.rb update_archive private_key" exit end puts `openssl dgst -sha1 -binary < "#{ARGV[0]}" | openssl dgst -dss1 -sign "#{ARGV[1]}" | openssl enc -base64`
Ruby
#!/usr/bin/ruby if ARGV.length < 2 puts "Usage: ruby sign_update.rb update_archive private_key" exit end puts `openssl dgst -sha1 -binary < "#{ARGV[0]}" | openssl dgst -dss1 -sign "#{ARGV[1]}" | openssl enc -base64`
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. # 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. # 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
# 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