code
stringlengths
1
1.73M
language
stringclasses
1 value
#!/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
module HomesHelper end
Ruby
module ContactsHelper end
Ruby
module UsersHelper end
Ruby
module ActionsHelper end
Ruby
module UserSessionsHelper end
Ruby
module ActivitiesHelper end
Ruby
module CompaniesHelper end
Ruby
class UserSession < Authlogic::Session::Base find_by_login_method :find_by_login_or_email end
Ruby
class Action < ActiveRecord::Base belongs_to :user end
Ruby
class Activity < ActiveRecord::Base end
Ruby
class User < ActiveRecord::Base has_many :actions validates_presence_of :screen_name acts_as_authentic do |c| c.login_field = 'email' end def self.find_by_login_or_email(login) User.find_by_email(login) end end
Ruby
class Home < ActiveRecord::Base end
Ruby
class Company < ActiveRecord::Base has_many :contacts end
Ruby
class Contact < ActiveRecord::Base belongs_to :company def self.search(search,page) #if search #find(:all, :conditions => ['name LIKE ?', "%#{search}%"]) #else # find(:all) #end end end
Ruby
class ActionsController < ApplicationController # GET /actions # GET /actions.xml def index @actions = Action.all respond_to do |format| format.html # index.html.erb format.xml { render :xml => @actions } end end # GET /actions/1 # GET /actions/1.xml def show @action = Actio...
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
class CompaniesController < ApplicationController layout 'standard' set_tab :companies # GET /companies # GET /companies.xml def index if params[:search] @companies_search = Company.paginate(:page=>params[:page],:per_page=> 3,:conditions => ['company_name like ?', "%#{params[:search]}%"], :...
Ruby
class UsersController < ApplicationController # GET /users # GET /users.xml def index @users = User.all respond_to do |format| format.html # index.html.erb format.xml { render :xml => @users } end end # GET /users/1 # GET /users/1.xml def show @user = User.find(params[:id]) ...
Ruby
class UserSessionsController < ApplicationController def new @user_session = UserSession.new end def create @user_session = UserSession.new(params[:user_session]) if @user_session.save flash[:notice] = "Successfully logged in." redirect_to root_url else render :action => 'new'...
Ruby
class ActivitiesController < ApplicationController # GET /activities # GET /activities.xml def index @activities = Activity.all respond_to do |format| format.html # index.html.erb format.xml { render :xml => @activities } end end # GET /activities/1 # GET /activities/1.xml def s...
Ruby
class HomesController < ApplicationController layout 'standard' set_tab :home # GET /homes # GET /homes.xml def index if params[:search] @contacts = Contact.paginate(:page=>params[:page],:per_page=> 3,:conditions => ['name like ?', "%#{params[:search]}%"], :order => 'name') # @contacts =...
Ruby
class ContactsController < ApplicationController layout 'standard' set_tab :contact # GET /contacts # GET /contacts.xml def index if params[:search] @contacts = Contact.paginate(:page=>params[:page],:per_page=> 3,:conditions => ['name like ?', "%#{params[:search]}%"], :order => 'name') # ...
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| map.resources :actions map.resources :activities map.resources :companies map.resources :contacts map.resources :user_sessions map.resources :users map.resources :homes map.login "login", :controller => "user_sessions", :action => "new" map.logo...
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
require 'scanner/states/start_state' require 'scanner/states/error_state' require 'logger' class Scanner attr_reader :line_num def initialize(file_name) @source_file = file_name @state = StartState @state.on_enter(nil, "") @line_num = 1 @log = Logger.new(STDOUT) @log.progname = "Sca...
Ruby
class Token attr_accessor :token_type, :literal def initialize(token_type, token_literal) @token_type = token_type @literal = token_literal end def to_s return "<#{@token_type}: \"#{@literal}\">" end end
Ruby
require 'scanner/states/state' require 'scanner/states/word_state' require 'scanner/states/number_state' require 'scanner/states/quote_state' require 'scanner/states/operator_state' require 'scanner/states/operator_equal_state' require 'scanner/states/slash_state' class StartState < State @token_type = :Nil def s...
Ruby
require 'scanner/states/state' require 'scanner/states/start_state' class CommentLineState < State @token_type = :CommentLine def self.on_enter(token, char) literal = "" literal = token.literal unless token.nil? literal << char.to_s # Remove leading slashes if literal[0..1] == "//" liter...
Ruby
require 'scanner/states/state' require 'scanner/states/start_state' class OperatorEqualState < State @token_type = :Operator @complete = false def self.next_state(char) if char == '=' and !@complete @complete = true return OperatorEqualState else @complete = false return StartS...
Ruby
require 'scanner/token' class State @token_type = :Undefined @token = nil def self.on_enter(token, char) literal = "" literal = token.literal unless token.nil? @token = Token.new(@token_type, "#{literal}#{char}") end def self.on_exit return @token end def self.next_state(char) retu...
Ruby
require 'scanner/states/state' require 'scanner/states/string_state' require 'scanner/states/start_state' class QuoteState < State @token_type = :QuoteString def self.on_exit # Chop off the leading quote mark return nil end def self.next_state(char) next_state = case char when '"': StartStat...
Ruby
require 'scanner/states/state' require 'scanner/states/start_state' class StringState < State @token_type = :String @complete = false def self.next_state(char) if @complete @complete = false # Chop off the trailing quote mark @token.literal = @token.literal[0..-2] return StartState ...
Ruby
require 'scanner/states/state' require 'scanner/states/start_state' class WordState < State @token_type = :Identifier def self.next_state(char) next_state = case char when '0'..'9': WordState when 'a'..'z': WordState when 'A'..'Z': WordState when '_': WordState else StartState ...
Ruby
require 'scanner/states/state' require 'scanner/states/start_state' require 'scanner/states/comment_line_state' require 'scanner/states/comment_block_state' class SlashState < State @token_type = :Operator def self.next_state(char) next_state = case char when '/': CommentLineState when '*': Commen...
Ruby
require 'scanner/states/state' require 'scanner/states/start_state' class OperatorState < State @token_type = :Operator def self.next_state(char) next_state = StartState return next_state end end
Ruby
require 'scanner/states/state' require 'scanner/states/start_state' class CommentBlockState < State @token_type = :CommentBlock @counter = 1 @prev = nil def self.on_enter(token, char) literal = "" literal = token.literal unless token.nil? literal << char.to_s # Remove leading slashes if li...
Ruby
require 'scanner/states/state' require 'scanner/states/start_state' class NumberState < State @token_type = :Number def self.next_state(char) next_state = case char when '0'..'9': NumberState else StartState end return next_state end end
Ruby
require 'scanner/states/state' require 'scanner/states/start_state' class ErrorState < State @token_type = :ERROR def self.next_state(char) return StartState end end
Ruby
require 'generator/generator' require 'parser/variable' class Function attr_accessor :scope, :name, :return_var, :arguments def initialize(scope, name, return_var, arguments) @scope = scope @name = name @return_var = return_var @arguments = arguments @return_index = 0 end def next_return...
Ruby
require 'logger' class Scope attr_accessor :name @@next_id = 0 @@next_register = 0 @@next_if = 0 @@next_while = 0 @@stack = [] @@runtime_functions = Hash.new @@log = Logger.new(STDOUT) @@log.progname = "Scope" @@log.datetime_format = "" @@log.level = Logger::INFO # ===Class Methods=== ...
Ruby
require 'logger' require 'generator/generator' require 'parser/scope' require 'parser/variable' require 'parser/function' class Parser def initialize(scanner) @log = Logger.new(STDOUT) @log.progname = "Parser" @log.datetime_format = "" @log.level = Logger::WARN @scanner = scanner @exp...
Ruby
require 'generator/generator' class Variable attr_accessor :scope, :name, :var_type, :addr_base, :addr_offset, :is_array, :size, :is_reference def initialize(scope, name, var_type, addr_base="Reg[FP]", addr_offset=0, is_array=false, size=1) @scope = scope @name = name @var_type = var_type @addr_bas...
Ruby
class Expression attr_accessor :lhs, :op, :rhs def initialize(lhs, op, rhs) @lhs = lhs @op = op @rhs = rhs @var_type = nil end def var_type if(@var_type.nil?) # TODO: Calculate type (Default to LHS type for now) case(@lhs.class) when Expression: @var_type = @l...
Ruby
require 'logger' require 'parser/scope' @@log = Logger.new(STDOUT) @@log.progname = "Generator" @@log.datetime_format = "" @@log.level = Logger::INFO class Generator def self.raw_line(text="") puts text end def self.write_line(inst="", comment="", indent=true) if(comment == "") raw_line(" %...
Ruby
require 'logger' require 'scanner/scanner' require 'parser/parser' log = Logger.new(STDERR) log.datetime_format = "" log.progname = "Main" log.level = Logger::WARN scanner = Scanner.new(STDIN) parser = Parser.new(scanner) log.info {"** Looking for a program **"} begin parse_tree = parser.program() rescue Exception...
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 RubyLibraryExample def get_server_language 'ruby' end # Basic communication def passing end def failing(message) raise message end def logging(message, level='INFO') puts "*#{level}* #{message}" end def returning 'returned string' end # Logging def one_message_w...
Ruby
#!/usr/bin/env ruby require 'rubygems' require 'mqtt' MQTT::Client.connect('localhost',1883) do |client| client.get('#') do |topic,message| puts "#{topic}: #{message}" end end
Ruby
require 'net/https' require 'yaml' require 'date' require 'time' begin require 'xmlsimple' rescue LoadError begin require 'rubygems' require 'xmlsimple' rescue LoadError abort <<-ERROR The 'xml-simple' library could not be loaded. If you have RubyGems installed you can install xml-simple by doing "ge...
Ruby
require "basecamp" require "rexml/document" include REXML Basecamp.establish_connection!(ARGV[0], ARGV[1], ARGV[2]) doc = Document.new("<lists />") lists_element = doc.root basecamp = Basecamp.new basecamp.projects.each do |project| lists_element.attributes["name"] = project.name Basecamp::TodoList.all(project...
Ruby
#-- # Copyright (c) 2005 David Heinemeier Hansson # # 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 without restriction, including # without limitation the rights to use, copy, modify, merge,...
Ruby
require 'active_support'
Ruby
require 'active_resource/connection' module ActiveResource class InvalidRequestError < StandardError; end #:nodoc: # One thing that has always been a pain with remote web services is testing. The HttpMock # class makes it easy to test your Active Resource models by creating a set of mock responses to specific ...
Ruby
module ActiveResource module Formats # Lookup the format class from a mime type reference symbol. Example: # # ActiveResource::Formats[:xml] # => ActiveResource::Formats::XmlFormat # ActiveResource::Formats[:json] # => ActiveResource::Formats::JsonFormat def self.[](mime_type_reference) ...
Ruby
module ActiveResource module Formats module JsonFormat extend self def extension "json" end def mime_type "application/json" end def encode(hash, options={}) hash.to_json(options) end def decode(json) ActiveSupport::JSON.decode(js...
Ruby
module ActiveResource module Formats module XmlFormat extend self def extension "xml" end def mime_type "application/xml" end def encode(hash, options={}) hash.to_xml(options) end def decode(xml) from_xml_data(Hash.from_xml(xml)) ...
Ruby
module ActiveResource module VERSION #:nodoc: MAJOR = 2 MINOR = 2 TINY = 2 STRING = [MAJOR, MINOR, TINY].join('.') end end
Ruby
module ActiveResource class ResourceInvalid < ClientError #:nodoc: end # Active Resource validation is reported to and from this object, which is used by Base#save # to determine whether the object in a valid state to be saved. See usage example in Validations. class Errors include Enumerable attr...
Ruby
require 'net/https' require 'date' require 'time' require 'uri' require 'benchmark' module ActiveResource class ConnectionError < StandardError # :nodoc: attr_reader :response def initialize(response, message = nil) @response = response @message = message end def to_s "Failed wit...
Ruby
require 'active_resource/connection' require 'cgi' require 'set' module ActiveResource # ActiveResource::Base is the main class for mapping RESTful resources as models in a Rails application. # # For an outline of what Active Resource is capable of, see link:files/vendor/rails/activeresource/README.html. # #...
Ruby
module ActiveResource # A module to support custom REST methods and sub-resources, allowing you to break out # of the "default" REST methods with your own custom resource requests. For example, # say you use Rails to expose a REST service and configure your routes with: # # map.resources :people, :new => ...
Ruby
#-- # Copyright (c) 2006 David Heinemeier Hansson # # 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 without restriction, including # without limitation the rights to use, copy, modify, merge,...
Ruby
require 'active_resource'
Ruby
module ActiveSupport Inflector.inflections do |inflect| inflect.plural(/$/, 's') inflect.plural(/s$/i, 's') inflect.plural(/(ax|test)is$/i, '\1es') inflect.plural(/(octop|vir)us$/i, '\1i') inflect.plural(/(alias|status)$/i, '\1es') inflect.plural(/(bu)s$/i, '\1ses') inflect.plural(/(buffal...
Ruby
begin require 'base64' rescue LoadError end module ActiveSupport if defined? ::Base64 Base64 = ::Base64 else # Base64 provides utility methods for encoding and de-coding binary data # using a base 64 representation. A base 64 representation of binary data # consists entirely of printable US-ASCI...
Ruby
module ActiveSupport # Rescuable module adds support for easier exception handling. module Rescuable def self.included(base) # :nodoc: base.class_inheritable_accessor :rescue_handlers base.rescue_handlers = [] base.extend(ClassMethods) end module ClassMethods # Rescue exception...
Ruby
module ActiveSupport # Callbacks are hooks into the lifecycle of an object that allow you to trigger logic # before or after an alteration of the object state. # # Mixing in this module allows you to define callbacks in your class. # # Example: # class Storage # include ActiveSupport::Callbacks ...
Ruby
require 'active_support/base64' require 'active_support/core_ext/base64/encoding' ActiveSupport::Base64.extend ActiveSupport::CoreExtensions::Base64::Encoding
Ruby
# encoding: utf-8 require 'active_support/core_ext/string/inflections' require 'active_support/core_ext/string/conversions' require 'active_support/core_ext/string/access' require 'active_support/core_ext/string/starts_ends_with' require 'active_support/core_ext/string/iterators' require 'active_support/core_ext/strin...
Ruby
require 'active_support/core_ext/integer/even_odd' require 'active_support/core_ext/integer/inflections' require 'active_support/core_ext/integer/time' class Integer #:nodoc: include ActiveSupport::CoreExtensions::Integer::EvenOdd include ActiveSupport::CoreExtensions::Integer::Inflections include ActiveSupport:...
Ruby
require 'active_support/core_ext/class/attribute_accessors' require 'active_support/core_ext/class/inheritable_attributes' require 'active_support/core_ext/class/removal' require 'active_support/core_ext/class/delegating_attributes'
Ruby
# These class attributes behave something like the class # inheritable accessors. But instead of copying the hash over at # the time the subclass is first defined, the accessors simply # delegate to their superclass unless they have been given a # specific value. This stops the strange situation where values # set...
Ruby
# Extends the class object with class and instance accessors for class attributes, # just like the native attr* accessors for instance attributes. # # class Person # cattr_accessor :hair_colors # end # # Person.hair_colors = [:brown, :black, :blonde, :red] class Class def cattr_reader(*syms) syms.flatten.ea...
Ruby
# Retain for backward compatibility. Methods are now included in Class. module ClassInheritableAttributes # :nodoc: end # Allows attributes to be shared within an inheritance hierarchy, but where each descendant gets a copy of # their parents' attributes, instead of just a pointer to the same. This means that the chi...
Ruby