Extensions needed for Hash#to_query

Namespace
Methods
A
B
C
E
H
I
L
M
N
R
S
T
Included Modules
Constants
Person = Struct.new("Person", :id, :name, :email_address, :phone_number)
 
RUNS = ARGV[0] ? ARGV[0].to_i : 50
 
PATH_TO_AR = "#{File.dirname(__FILE__)}/../../activerecord/lib"
 
CACHE_DIR = 'test_cache'
 
FILE_STORE_PATH = File.join(File.dirname(__FILE__), '/../temp/', CACHE_DIR)
 

Don’t change ‘/../temp/’ cavalierly or you might hoze something you don’t want hozed

MemCache = Struct.new(:MemCache, :address) unless Object.const_defined?(:MemCache)
 
Customer = Struct.new("Customer", :name) }
 
RunTimeTests = ARGV.include? 'time'
 
ROUTING = ActionController::Routing
 
TimeZone = MockTimeZone
 
RequestMock = Struct.new("Request", :request_uri, :protocol, :host_with_port)
 
ConfigTable = ConfigTable_class.new(common_conf + multipackage_conf)
 
FB_TRACE = false
 
MysqlRes = Mysql::Result
 

for compatibility

MysqlField = Mysql::Field
 
MysqlError = Mysql::Error
 
RAILS_CONNECTION_ADAPTERS = %w( mysql postgresql sqlite firebird sqlserver db2 oracle sybase openbase frontbase )
 
QUOTED_TYPE = ActiveRecord::Base.connection.quote_column_name('type') unless Object.const_defined?(:QUOTED_TYPE)
 
RAILS_DEFAULT_LOGGER = Logger.new('debug.log')
 
BASE_DIR = File.expand_path(File.dirname(__FILE__) + '/../../fixtures')
 
DeveloperSalary = Struct.new(:amount)
 
ApplicationController = 10
 
Conflict = 2
 
B = "10"
 
MultipleConstantFile = 10
 
SiblingConstant = MultipleConstantFile * 2
 
Payment = Struct.new(:price)
 
Somewhere = Struct.new(:street, :city)
 
Someone = Struct.new(:name, :place) do delegate :street, :city, :to => :place delegate :state, :to => :@place delegate :upcase, :to => "place.city" end
 
UNIDATA_URL = "http://www.unicode.org/Public/#{ActiveSupport::Multibyte::UNICODE_VERSION}/ucd"
 
UNIDATA_FILE = '/NormalizationTest.txt'
 
RailsInfoController = Rails::InfoController
 

Alias to ensure old public.html still works.

RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
 

Don’t change this file. Configuration is done in config/environment.rb and config/environments/*.rb

Options = { :ClientURI => nil, :ServerURI => "druby://localhost:42531", :RetryDelay => 2, :Permanent => true, :Verbose => false }
 
N = Integer(ARGV.first)
 
OPTIONS = { :pid_path => File.expand_path(RAILS_ROOT + '/tmp/pids'), :pattern => "dispatch.*.pid", :ps => "ps -o pid,state,user,start,time,pcpu,vsz,majflt,command -p %s" }
 
ARGV = parameters }
 
RAILS_ENV = (ENV['RAILS_ENV'] || 'development').dup unless defined?(RAILS_ENV)
 
CHARSET = "utf-8"
 
RAILTIES_PATH = File.join(File.dirname(__FILE__), '..')
 
ACTION_MAILER_DEF = <<AM class DispatcherTestMailer < ActionMailer::Base end AM
 
ACTION_CONTROLLER_DEF = <<AM class DispatcherControllerTest < ActionController::Base end AM
 
VERSION = ARGV.first
 
PACKAGES = %w( activesupport activerecord actionpack actionmailer actionwebservice )
 
Class Public methods
lookup_missing_generator(class_id)

Lookup missing generators using const_missing. This allows any generator to reference another without having to know its location: RubyGems, ~/.rails/generators, and RAILS_ROOT/generators.

# File rails/railties/lib/rails_generator/lookup.rb, line 8
def lookup_missing_generator(class_id)
  if md = %r(.+)Generator$/.match(class_id.to_s)
    name = md.captures.first.demodulize.underscore
    Rails::Generator::Base.lookup(name).klass
  else
    const_missing_before_generators(class_id)
  end
end
Instance Public methods
app(create=false)

reference the global “app” instance, created on demand. To recreate the instance, pass a non-false value as the parameter.

# File rails/railties/lib/console_app.rb, line 8
def app(create=false)
  @app_integration_instance = nil if create
  @app_integration_instance ||= new_session do |sess|
    sess.host! "www.example.com"
  end
end
assert(&block)
# File rails/activesupport/lib/active_support/breakpoint.rb, line 524
def assert(&block)
  Binding.of_caller do |context|
    Breakpoint.assert(context, &block)
  end
end
blank?()

An object is blank if it’s nil, empty, or a whitespace string. For example, “”, “ ”, nil, [], and {} are blank.

This simplifies

if !address.nil? && !address.empty?

to

if !address.blank?
# File rails/activesupport/lib/active_support/core_ext/blank.rb, line 9
def blank?
  if respond_to?(:empty?) && respond_to?(:strip)
    empty? or strip.empty?
  elsif respond_to?(:empty?)
    empty?
  else
    !self
  end
end
breakpoint(id = nil, &block)
# File rails/activesupport/lib/active_support/breakpoint.rb, line 517
def breakpoint(id = nil, &block)
  Binding.of_caller do |context|
    Breakpoint.breakpoint(id, context, &block)
  end
end
create()

POST /<%= table_name %>.xml

# File rails/railties/lib/rails_generator/generators/components/scaffold_resource/templates/controller.rb, line 36
  def create
    @<%Q file_name %> = <%Q class_name %>.new(params[:<%= file_name %>])

    respond_to do |format|
      if @<%Q file_name %>.save
        flash[:notice] = '<%= class_name %> was successfully created.'
        format.html { redirect_to <%Q file_name %>_url(@<%= file_name %>) }
        format.xml  { head :created, :location => <%Q file_name %>_url(@<%= file_name %>) }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @<%Q file_name %>.errors.to_xml }
      end
    end
  end

  # PUT /<%= table_name %>%r1
  # PUT /<%Q table_name %>/1.xml
  def update
    @<%= file_name %> = <%Q class_name %>.find(params[:id])

    respond_to do |format|
      if @<%= file_name %>.update_attributes(params[:<= file_name %Q<])
        flash[:notice] = '<%= class_name %> was successfully updated.'
        format.html { redirect_to <%= file_name %>_url(@<%= file_name %>) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @<%Q file_name %>.errors.to_xml }
      end
    end
  end

  # DELETE /<%= table_name %>%r1
  # DELETE /<%Q table_name %>/1.xml
  def destroy
    @<%= file_name %> = <%Q class_name %>.find(params[:id])
    @<%= file_name %>.destroy

    respond_to do |format|
      format.html { redirect_to <%Q table_name %>_url }
      format.xml  { head :ok }
    end
  end
end
create_fixtures(*table_names)
# File rails/railties/lib/test_help.rb, line 17
def create_fixtures(*table_names)
  Fixtures.create_fixtures(RAILS_ROOT + "/test/fixtures", table_names)
end
create_table(*args, &block)
# File rails/activerecord/test/fixtures/db_definitions/schema.rb, line 7
def create_table(*args, &block)
  ActiveRecord::Base.connection.create_table(*args, &block)
  ActiveRecord::Base.connection.execute "SET GENERATOR #{args.first}_seq TO 10000"
end
current_adapter?(*types)
# File rails/activerecord/test/abstract_unit.rb, line 56
def current_adapter?(*types)
  types.any? do |type|
    ActiveRecord::ConnectionAdapters.const_defined?(type) &&
      ActiveRecord::Base.connection.is_a?(ActiveRecord::ConnectionAdapters.const_get(type))
  end
end
execute_with_query_counting(sql, name = nil, &block)
# File rails/activerecord/test/abstract_unit.rb, line 70
def execute_with_query_counting(sql, name = nil, &block)
  self.query_count += 1 unless @@ignore_list.any? { |r| sql =~ r }
  execute_without_query_counting(sql, name, &block)
end
helper()
# File rails/railties/lib/console_with_helpers.rb, line 13
def helper
  @helper_proxy ||= Object.new 
end
index()

GET /<%= table_name %>.xml

# File rails/railties/lib/rails_generator/generators/components/scaffold_resource/templates/controller.rb, line 4
  def index
    @<%Q table_name %> = <%Q class_name %>.find(:all)

    respond_to do |format|
      format.html # index.rhtml
      format.xml  { render :xml => @<%Q table_name %>.to_xml }
    end
  end

  # GET /<%= table_name %>%r1
  # GET /<%Q table_name %>/1.xml
  def show
    @<%= file_name %> = <%Q class_name %>.find(params[:id])

    respond_to do |format|
      format.html # show.rhtml
      format.xml  { render :xml => @<%Q file_name %>.to_xml }
    end
  end

  # GET /<%= table_name %>%rnew
  def new
    @<%= file_name %> = <%= class_name %>.new
  end

  # GET /<%Q table_name %>/1;edit
  def edit
    @<%= file_name %> = <%Q class_name %>.find(params[:id])
  end

  # POST /<%= table_name %>
  # POST /<%= table_name %>.xml
  def create
    @<%Q file_name %> = <%Q class_name %>.new(params[:<%= file_name %>])

    respond_to do |format|
      if @<%Q file_name %>.save
        flash[:notice] = '<%= class_name %> was successfully created.'
        format.html { redirect_to <%Q file_name %>_url(@<%= file_name %>) }
        format.xml  { head :created, :location => <%Q file_name %>_url(@<%= file_name %>) }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @<%Q file_name %>.errors.to_xml }
      end
    end
  end

  # PUT /<%= table_name %>%r1
  # PUT /<%Q table_name %>/1.xml
  def update
    @<%= file_name %> = <%Q class_name %>.find(params[:id])

    respond_to do |format|
      if @<%= file_name %>.update_attributes(params[:<= file_name %Q<])
        flash[:notice] = '<%= class_name %> was successfully updated.'
        format.html { redirect_to <%= file_name %>_url(@<%= file_name %>) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @<%Q file_name %>.errors.to_xml }
      end
    end
  end

  # DELETE /<%= table_name %>%r1
  # DELETE /<%Q table_name %>/1.xml
  def destroy
    @<%= file_name %> = <%Q class_name %>.find(params[:id])
    @<%= file_name %>.destroy

    respond_to do |format|
      format.html { redirect_to <%Q table_name %>_url }
      format.xml  { head :ok }
    end
  end
end
make_connection(clazz, db_file, db_definitions_file)
# File rails/activerecord/test/connections/native_sqlite/connection.rb, line 13
def make_connection(clazz, db_file, db_definitions_file)
  ActiveRecord::Base.configurations = { clazz.name => { :adapter => 'sqlite', :database => db_file } }
  unless File.exist?(db_file)
    puts "SQLite database not found at #{db_file}. Rebuilding it."
    sqlite_command = %Q{sqlite #{db_file} "create table a (a integer); drop table a;"}
    puts "Executing '#{sqlite_command}'"
    raise SqliteError.new("Seems that there is no sqlite executable available") unless system(sqlite_command)
    clazz.establish_connection(clazz.name)
    script = File.read("#{BASE_DIR}/db_definitions/#{db_definitions_file}")
    # SQLite-Ruby has problems with semi-colon separated commands, so split and execute one at a time
    script.split(';').each do
      |command|
      clazz.connection.execute(command) unless command.strip.empty?
    end
  else
    clazz.establish_connection(clazz.name)
  end
end
message(s)
# File rails/railties/lib/commands/ncgi/listener, line 7
def message(s)
  $stderr.puts "listener: #{s}" if ENV && ENV["DEBUG_GATEWAY"]
end
multipackage_install?()
# File rails/actionwebservice/setup.rb, line 74
def multipackage_install?
  FileTest.directory?(File.dirname($0) + '/packages')
end
new_session()

create a new session. If a block is given, the new session will be yielded to the block before being returned.

# File rails/railties/lib/console_app.rb, line 17
def new_session
  session = ActionController::Integration::Session.new
  yield session if block_given?
  session
end
reload!()

reloads the environment

# File rails/railties/lib/console_app.rb, line 24
def reload!
  puts "Reloading..."
  Dispatcher.reset_application!
end
setup()
# File rails/railties/lib/rails_generator/generators/components/controller/templates/functional_test.rb, line 8
def setup
  @controller = <%Q class_name %>Controller.new
  @request    = ActionController::TestRequest.new
  @response   = ActionController::TestResponse.new
end
setup_rb_error(msg)
# File rails/actionwebservice/setup.rb, line 58
def setup_rb_error(msg)
  raise SetupError, msg
end
tail(log_file)
# File rails/railties/lib/commands/servers/base.rb, line 1
def tail(log_file)
  cursor = File.size(log_file)
  last_checked = Time.now
  tail_thread = Thread.new do
    File.open(log_file, 'r') do |f|
      loop do
        f.seek cursor
        if f.mtime > last_checked
          last_checked = f.mtime
          contents = f.read
          cursor += contents.length
          print contents
        end
        sleep 1
      end
    end
  end
  tail_thread
end
test_truth()

Replace this with your real tests.

# File rails/railties/lib/rails_generator/generators/components/controller/templates/functional_test.rb, line 15
def test_truth
  assert true
end
to_param()
# File rails/actionpack/lib/action_controller/routing.rb, line 4
def to_param
  to_s
end