railties-3.2.16/ 0000755 0001750 0001750 00000000000 12247655524 012757 5 ustar ondrej ondrej railties-3.2.16/CHANGELOG.md 0000644 0001750 0001750 00000011546 12247655524 014577 0 ustar ondrej ondrej ## Rails 3.2.15 (Oct 16, 2013) ##
* No changes.
## Rails 3.2.14 (Jul 22, 2013) ##
* Fix bugs that crashed `rake test:benchmark`, `rails profiler` and
`rails benchmarker`.
Fixes #4938.
Backport rails/rails-perftest#2.
*Dmitry Vorotilin + Yves Senn*
* Add support for runner hook.
Backport #7695.
*Ben Holley*
* Fixes bug with scaffold generator with `--assets=false --resource-route=false`.
Fixes #9525.
*Arun Agrawal*
## Rails 3.2.13 (Mar 18, 2013) ##
* No changes.
## Rails 3.2.12 (Feb 11, 2013) ##
* No changes.
## Rails 3.2.11 (Jan 8, 2013) ##
* No changes.
## Rails 3.2.10 (Jan 2, 2013) ##
* No changes.
## Rails 3.2.9 (Nov 12, 2012) ##
* Quote column names in generates fixture files. This prevents
conflicts with reserved YAML keywords such as 'yes' and 'no'
Fix #8612.
Backport #8616.
*Yves Senn*
* Engines with a dummy app include the rake tasks of dependencies in the app namespace. [Backport: #8262]
Fix #8229
*Yves Senn*
* Add dummy app Rake tasks when --skip-test-unit and --dummy-path is passed to the plugin generator. [Backport #8139]
Fix #8121
*Yves Senn*
* Update supported ruby versions error message in ruby_version_check.rb *Lihan Li*
## Rails 3.2.8 (Aug 9, 2012) ##
* ERB scaffold generator use the `:data => { :confirm => "Text" }` syntax instead of `:confirm`.
*Rafael Mendonça França*
## Rails 3.2.7 (Jul 26, 2012) ##
* Since Rails 3.2, use layout false to render no layout
* Use strict_args_position! if available from Thor
## Rails 3.2.6 (Jun 12, 2012) ##
* No changes.
## Rails 3.2.4 (May 31, 2012) ##
* Add hook for resource route's generator. *Santiago Pastorino*
## Rails 3.2.3 (unreleased) ##
* No changes.
## Rails 3.2.2 (March 1, 2012) ##
* No changes.
## Rails 3.2.1 (January 26, 2012) ##
* Documentation fixes.
* Migration generation understands decimal{1.2} and decimal{1-2}, in
addition to decimal{1,2}. *José Valim*
## Rails 3.2.0 (January 20, 2012) ##
* Rails 2.3-style plugins in vendor/plugins are deprecated and will be removed in Rails 4.0. Move them out of vendor/plugins and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. *Santiago Pastorino*
* Guides are available as a single .mobi for the Kindle and free Kindle readers apps. *Michael Pearson & Xavier Noria*
* Allow scaffold/model/migration generators to accept a "index" and "uniq" modifiers, as in: "tracking_id:integer:uniq" in order to generate (unique) indexes. Some types also accept custom options, for instance, you can specify the precision and scale for decimals as "price:decimal{7,2}". *Dmitrii Samoilov*
* Added `config.exceptions_app` to set the exceptions application invoked by the ShowException middleware when an exception happens. Defaults to `ActionDispatch::PublicExceptions.new(Rails.public_path)`. *José Valim*
* Speed up development by only reloading classes if dependencies files changed. This can be turned off by setting `config.reload_classes_only_on_change` to false. *José Valim*
* New applications get a flag `config.active_record.auto_explain_threshold_in_seconds` in the environments configuration files. With a value of 0.5 in development.rb, and commented out in production.rb. No mention in test.rb. *fxn*
* Add DebugExceptions middleware which contains features extracted from ShowExceptions middleware *José Valim*
* Display mounted engine's routes in `rake routes` *Piotr Sarnacki*
* Allow to change the loading order of railties with `config.railties_order=` *Piotr Sarnacki*
Example:
config.railties_order = [Blog::Engine, :main_app, :all]
* Scaffold returns 204 No Content for API requests without content. This makes scaffold work with jQuery out of the box *José Valim*
* Update Rails::Rack::Logger middleware to apply any tags set in config.log_tags to the newly ActiveSupport::TaggedLogging Rails.logger. This makes it easy to tag log lines with debug information like subdomain and request id -- both very helpful in debugging multi-user production applications *DHH*
* Default options to `rails new` can be set in ~/.railsrc *Guillermo Iguaran*
* Add destroy alias to Rails engines *Guillermo Iguaran*
* Add destroy alias for Rails command line. This allows the following: `rails d model post` *Andrey Ognevsky*
* Attributes on scaffold and model generators default to string. This allows the following: "rails g scaffold Post title body:text author" *José Valim*
* Remove old plugin generator (`rails generate plugin`) in favor of `rails plugin new` command *Guillermo Iguaran*
* Remove old 'config.paths.app.controller' API in favor of 'config.paths["app/controller"]' API *Guillermo Iguaran*
Please check [3-1-stable](https://github.com/rails/rails/blob/3-1-stable/railties/CHANGELOG.md) for previous changes.
railties-3.2.16/README.rdoc 0000644 0001750 0001750 00000001375 12247655524 014573 0 ustar ondrej ondrej = Railties -- Gluing the Engine to the Rails
Railties is responsible for gluing all frameworks together. Overall, it:
* handles the bootstrapping process for a Rails application;
* manages the +rails+ command line interface;
* and provides the Rails generators core.
== Download
The latest version of Railties can be installed with RubyGems:
* gem install railties
Source code can be downloaded as part of the Rails project on GitHub
* https://github.com/rails/rails/tree/3-2-stable/railties
== License
Railties is released under the MIT license.
== Support
API documentation is at
* http://api.rubyonrails.org
Bug reports and feature requests can be filed with the rest for the Ruby on Rails project here:
* https://github.com/rails/rails/issues
railties-3.2.16/checksums.yaml.gz 0000444 0001750 0001750 00000000413 12247655524 016243 0 ustar ondrej ondrej #Re;R0D"#tt@$*&ǤVOv]^r~#2}FBZĦyH1a{2zr%Y G3Тި(:%o&Ja)!h1pF5]hi@'٪\1+GxC.m%
sZL} dRD8LgdVYTpyGw 7]% w-企Vك9.?qZb railties-3.2.16/lib/ 0000755 0001750 0001750 00000000000 12247655524 013525 5 ustar ondrej ondrej railties-3.2.16/lib/rails/ 0000755 0001750 0001750 00000000000 12247655524 014637 5 ustar ondrej ondrej railties-3.2.16/lib/rails/tasks.rb 0000644 0001750 0001750 00000000314 12247655524 016307 0 ustar ondrej ondrej $VERBOSE = nil
# Load Rails rakefile extensions
%w(
annotations
documentation
framework
log
middleware
misc
routes
statistics
tmp
).each do |task|
load "rails/tasks/#{task}.rake"
end
railties-3.2.16/lib/rails/railtie/ 0000755 0001750 0001750 00000000000 12247655524 016270 5 ustar ondrej ondrej railties-3.2.16/lib/rails/railtie/configuration.rb 0000644 0001750 0001750 00000005275 12247655524 021475 0 ustar ondrej ondrej require 'rails/configuration'
module Rails
class Railtie
class Configuration
def initialize
@@options ||= {}
end
# Add files that should be watched for change.
def watchable_files
@@watchable_files ||= []
end
# Add directories that should be watched for change.
# The key of the hashes should be directories and the values should
# be an array of extensions to match in each directory.
def watchable_dirs
@@watchable_dirs ||= {}
end
# This allows you to modify the application's middlewares from Engines.
#
# All operations you run on the app_middleware will be replayed on the
# application once it is defined and the default_middlewares are
# created
def app_middleware
@@app_middleware ||= Rails::Configuration::MiddlewareStackProxy.new
end
# This allows you to modify application's generators from Railties.
#
# Values set on app_generators will become defaults for application, unless
# application overwrites them.
def app_generators
@@app_generators ||= Rails::Configuration::Generators.new
yield(@@app_generators) if block_given?
@@app_generators
end
# First configurable block to run. Called before any initializers are run.
def before_configuration(&block)
ActiveSupport.on_load(:before_configuration, :yield => true, &block)
end
# Third configurable block to run. Does not run if config.cache_classes
# set to false.
def before_eager_load(&block)
ActiveSupport.on_load(:before_eager_load, :yield => true, &block)
end
# Second configurable block to run. Called before frameworks initialize.
def before_initialize(&block)
ActiveSupport.on_load(:before_initialize, :yield => true, &block)
end
# Last configurable block to run. Called after frameworks initialize.
def after_initialize(&block)
ActiveSupport.on_load(:after_initialize, :yield => true, &block)
end
# Array of callbacks defined by #to_prepare.
def to_prepare_blocks
@@to_prepare_blocks ||= []
end
# Defines generic callbacks to run before #after_initialize. Useful for
# Rails::Railtie subclasses.
def to_prepare(&blk)
to_prepare_blocks << blk if blk
end
def respond_to?(name)
super || @@options.key?(name.to_sym)
end
private
def method_missing(name, *args, &blk)
if name.to_s =~ /=$/
@@options[$`.to_sym] = args.first
elsif @@options.key?(name)
@@options[name]
else
super
end
end
end
end
end
railties-3.2.16/lib/rails/railtie/configurable.rb 0000644 0001750 0001750 00000001242 12247655524 021254 0 ustar ondrej ondrej require 'active_support/concern'
module Rails
class Railtie
module Configurable
extend ActiveSupport::Concern
module ClassMethods
delegate :config, :to => :instance
def inherited(base)
raise "You cannot inherit from a #{self.superclass.name} child"
end
def instance
@instance ||= new
end
def respond_to?(*args)
super || instance.respond_to?(*args)
end
def configure(&block)
class_eval(&block)
end
protected
def method_missing(*args, &block)
instance.send(*args, &block)
end
end
end
end
end
railties-3.2.16/lib/rails/generators.rb 0000644 0001750 0001750 00000024047 12247655524 017344 0 ustar ondrej ondrej activesupport_path = File.expand_path('../../../../activesupport/lib', __FILE__)
$:.unshift(activesupport_path) if File.directory?(activesupport_path) && !$:.include?(activesupport_path)
require 'active_support'
require 'active_support/core_ext/object/blank'
require 'active_support/core_ext/kernel/singleton_class'
require 'active_support/core_ext/array/extract_options'
require 'active_support/core_ext/hash/deep_merge'
require 'active_support/core_ext/module/attribute_accessors'
require 'active_support/core_ext/string/inflections'
require 'rails/generators/base'
module Rails
module Generators
autoload :Actions, 'rails/generators/actions'
autoload :ActiveModel, 'rails/generators/active_model'
autoload :Migration, 'rails/generators/migration'
autoload :NamedBase, 'rails/generators/named_base'
autoload :ResourceHelpers, 'rails/generators/resource_helpers'
autoload :TestCase, 'rails/generators/test_case'
mattr_accessor :namespace
DEFAULT_ALIASES = {
:rails => {
:actions => '-a',
:orm => '-o',
:javascripts => '-j',
:javascript_engine => '-je',
:resource_controller => '-c',
:scaffold_controller => '-c',
:stylesheets => '-y',
:stylesheet_engine => '-se',
:template_engine => '-e',
:test_framework => '-t'
},
:test_unit => {
:fixture_replacement => '-r',
},
:plugin => {
:generator => '-g',
:tasks => '-r'
}
}
DEFAULT_OPTIONS = {
:rails => {
:assets => true,
:force_plural => false,
:helper => true,
:integration_tool => nil,
:javascripts => true,
:javascript_engine => :js,
:orm => false,
:performance_tool => nil,
:resource_controller => :controller,
:resource_route => true,
:scaffold_controller => :scaffold_controller,
:stylesheets => true,
:stylesheet_engine => :css,
:test_framework => false,
:template_engine => :erb
},
:plugin => {
:generator => false,
:tasks => false
}
}
def self.configure!(config) #:nodoc:
no_color! unless config.colorize_logging
aliases.deep_merge! config.aliases
options.deep_merge! config.options
fallbacks.merge! config.fallbacks
templates_path.concat config.templates
templates_path.uniq!
hide_namespaces(*config.hidden_namespaces)
end
def self.templates_path
@templates_path ||= []
end
def self.aliases #:nodoc:
@aliases ||= DEFAULT_ALIASES.dup
end
def self.options #:nodoc:
@options ||= DEFAULT_OPTIONS.dup
end
# Hold configured generators fallbacks. If a plugin developer wants a
# generator group to fallback to another group in case of missing generators,
# they can add a fallback.
#
# For example, shoulda is considered a test_framework and is an extension
# of test_unit. However, most part of shoulda generators are similar to
# test_unit ones.
#
# Shoulda then can tell generators to search for test_unit generators when
# some of them are not available by adding a fallback:
#
# Rails::Generators.fallbacks[:shoulda] = :test_unit
#
def self.fallbacks
@fallbacks ||= {}
end
# Remove the color from output.
def self.no_color!
Thor::Base.shell = Thor::Shell::Basic
end
# Track all generators subclasses.
def self.subclasses
@subclasses ||= []
end
# Rails finds namespaces similar to thor, it only adds one rule:
#
# Generators names must end with "_generator.rb". This is required because Rails
# looks in load paths and loads the generator just before it's going to be used.
#
# ==== Examples
#
# find_by_namespace :webrat, :rails, :integration
#
# Will search for the following generators:
#
# "rails:webrat", "webrat:integration", "webrat"
#
# Notice that "rails:generators:webrat" could be loaded as well, what
# Rails looks for is the first and last parts of the namespace.
#
def self.find_by_namespace(name, base=nil, context=nil) #:nodoc:
lookups = []
lookups << "#{base}:#{name}" if base
lookups << "#{name}:#{context}" if context
unless base || context
unless name.to_s.include?(?:)
lookups << "#{name}:#{name}"
lookups << "rails:#{name}"
end
lookups << "#{name}"
end
lookup(lookups)
namespaces = Hash[subclasses.map { |klass| [klass.namespace, klass] }]
lookups.each do |namespace|
klass = namespaces[namespace]
return klass if klass
end
invoke_fallbacks_for(name, base) || invoke_fallbacks_for(context, name)
end
# Receives a namespace, arguments and the behavior to invoke the generator.
# It's used as the default entry point for generate, destroy and update
# commands.
def self.invoke(namespace, args=ARGV, config={})
names = namespace.to_s.split(':')
if klass = find_by_namespace(names.pop, names.any? && names.join(':'))
args << "--help" if args.empty? && klass.arguments.any? { |a| a.required? }
klass.start(args, config)
else
puts "Could not find generator #{namespace}."
end
end
def self.hidden_namespaces
@hidden_namespaces ||= begin
orm = options[:rails][:orm]
test = options[:rails][:test_framework]
template = options[:rails][:template_engine]
css = options[:rails][:stylesheet_engine]
[
"rails",
"resource_route",
"#{orm}:migration",
"#{orm}:model",
"#{orm}:observer",
"#{orm}:session_migration",
"#{test}:controller",
"#{test}:helper",
"#{test}:integration",
"#{test}:mailer",
"#{test}:model",
"#{test}:observer",
"#{test}:scaffold",
"#{test}:view",
"#{test}:performance",
"#{test}:plugin",
"#{template}:controller",
"#{template}:scaffold",
"#{template}:mailer",
"#{css}:scaffold",
"#{css}:assets",
"css:assets",
"css:scaffold"
]
end
end
class << self
def hide_namespaces(*namespaces)
hidden_namespaces.concat(namespaces)
end
alias hide_namespace hide_namespaces
end
# Show help message with available generators.
def self.help(command = 'generate')
lookup!
namespaces = subclasses.map{ |k| k.namespace }
namespaces.sort!
groups = Hash.new { |h,k| h[k] = [] }
namespaces.each do |namespace|
base = namespace.split(':').first
groups[base] << namespace
end
puts "Usage: rails #{command} GENERATOR [args] [options]"
puts
puts "General options:"
puts " -h, [--help] # Print generator's options and usage"
puts " -p, [--pretend] # Run but do not make any changes"
puts " -f, [--force] # Overwrite files that already exist"
puts " -s, [--skip] # Skip files that already exist"
puts " -q, [--quiet] # Suppress status output"
puts
puts "Please choose a generator below."
puts
# Print Rails defaults first.
rails = groups.delete("rails")
rails.map! { |n| n.sub(/^rails:/, '') }
rails.delete("app")
rails.delete("plugin_new")
print_list("rails", rails)
hidden_namespaces.each {|n| groups.delete(n.to_s) }
groups.sort.each { |b, n| print_list(b, n) }
end
protected
# Prints a list of generators.
def self.print_list(base, namespaces) #:nodoc:
namespaces = namespaces.reject do |n|
hidden_namespaces.include?(n)
end
return if namespaces.empty?
puts "#{base.camelize}:"
namespaces.each do |namespace|
puts(" #{namespace}")
end
puts
end
# Try fallbacks for the given base.
def self.invoke_fallbacks_for(name, base) #:nodoc:
return nil unless base && fallbacks[base.to_sym]
invoked_fallbacks = []
Array(fallbacks[base.to_sym]).each do |fallback|
next if invoked_fallbacks.include?(fallback)
invoked_fallbacks << fallback
klass = find_by_namespace(name, fallback)
return klass if klass
end
nil
end
# Receives namespaces in an array and tries to find matching generators
# in the load path.
def self.lookup(namespaces) #:nodoc:
paths = namespaces_to_paths(namespaces)
paths.each do |raw_path|
["rails/generators", "generators"].each do |base|
path = "#{base}/#{raw_path}_generator"
begin
require path
return
rescue LoadError => e
raise unless e.message =~ /#{Regexp.escape(path)}$/
rescue Exception => e
warn "[WARNING] Could not load generator #{path.inspect}. Error: #{e.message}.\n#{e.backtrace.join("\n")}"
end
end
end
end
# This will try to load any generator in the load path to show in help.
def self.lookup! #:nodoc:
$LOAD_PATH.each do |base|
Dir[File.join(base, "{rails/generators,generators}", "**", "*_generator.rb")].each do |path|
begin
path = path.sub("#{base}/", "")
require path
rescue Exception
# No problem
end
end
end
end
# Convert namespaces to paths by replacing ":" for "/" and adding
# an extra lookup. For example, "rails:model" should be searched
# in both: "rails/model/model_generator" and "rails/model_generator".
def self.namespaces_to_paths(namespaces) #:nodoc:
paths = []
namespaces.each do |namespace|
pieces = namespace.split(":")
paths << pieces.dup.push(pieces.last).join("/")
paths << pieces.join("/")
end
paths.uniq!
paths
end
end
end
railties-3.2.16/lib/rails/paths.rb 0000644 0001750 0001750 00000013762 12247655524 016314 0 ustar ondrej ondrej require 'set'
module Rails
module Paths
# This object is an extended hash that behaves as root of the Rails::Paths system.
# It allows you to collect information about how you want to structure your application
# paths by a Hash like API. It requires you to give a physical path on initialization.
#
# root = Root.new "/rails"
# root.add "app/controllers", :eager_load => true
#
# The command above creates a new root object and add "app/controllers" as a path.
# This means we can get a +Rails::Paths::Path+ object back like below:
#
# path = root["app/controllers"]
# path.eager_load? # => true
# path.is_a?(Rails::Paths::Path) # => true
#
# The +Path+ object is simply an array and allows you to easily add extra paths:
#
# path.is_a?(Array) # => true
# path.inspect # => ["app/controllers"]
#
# path << "lib/controllers"
# path.inspect # => ["app/controllers", "lib/controllers"]
#
# Notice that when you add a path using +add+, the path object created already
# contains the path with the same path value given to +add+. In some situations,
# you may not want this behavior, so you can give :with as option.
#
# root.add "config/routes", :with => "config/routes.rb"
# root["config/routes"].inspect # => ["config/routes.rb"]
#
# The +add+ method accepts the following options as arguments:
# eager_load, autoload, autoload_once and glob.
#
# Finally, the +Path+ object also provides a few helpers:
#
# root = Root.new "/rails"
# root.add "app/controllers"
#
# root["app/controllers"].expanded # => ["/rails/app/controllers"]
# root["app/controllers"].existent # => ["/rails/app/controllers"]
#
# Check the Rails::Paths::Path documentation for more information.
class Root < ::Hash
attr_accessor :path
def initialize(path)
raise "Argument should be a String of the physical root path" if path.is_a?(Array)
@current = nil
@path = path
@root = self
super()
end
def []=(path, value)
value = Path.new(self, path, value) unless value.is_a?(Path)
super(path, value)
end
def add(path, options={})
with = options[:with] || path
self[path] = Path.new(self, path, with, options)
end
def all_paths
values.tap { |v| v.uniq! }
end
def autoload_once
filter_by(:autoload_once?)
end
def eager_load
filter_by(:eager_load?)
end
def autoload_paths
filter_by(:autoload?)
end
def load_paths
filter_by(:load_path?)
end
protected
def filter_by(constraint)
all = []
all_paths.each do |path|
if path.send(constraint)
paths = path.existent
paths -= path.children.map { |p| p.send(constraint) ? [] : p.existent }.flatten
all.concat(paths)
end
end
all.uniq!
all
end
end
class Path < Array
attr_reader :path
attr_accessor :glob
def initialize(root, current, *paths)
options = paths.last.is_a?(::Hash) ? paths.pop : {}
super(paths.flatten)
@current = current
@root = root
@glob = options[:glob]
options[:autoload_once] ? autoload_once! : skip_autoload_once!
options[:eager_load] ? eager_load! : skip_eager_load!
options[:autoload] ? autoload! : skip_autoload!
options[:load_path] ? load_path! : skip_load_path!
end
def children
keys = @root.keys.select { |k| k.include?(@current) }
keys.delete(@current)
@root.values_at(*keys.sort)
end
def first
expanded.first
end
def last
expanded.last
end
%w(autoload_once eager_load autoload load_path).each do |m|
class_eval <<-RUBY, __FILE__, __LINE__ + 1
def #{m}! # def eager_load!
@#{m} = true # @eager_load = true
end # end
#
def skip_#{m}! # def skip_eager_load!
@#{m} = false # @eager_load = false
end # end
#
def #{m}? # def eager_load?
@#{m} # @eager_load
end # end
RUBY
end
# Expands all paths against the root and return all unique values.
def expanded
raise "You need to set a path root" unless @root.path
result = []
each do |p|
path = File.expand_path(p, @root.path)
if @glob
if File.directory? path
result.concat expand_dir(path, @glob)
else
# FIXME: I think we can remove this branch, but I'm not sure.
# Say the filesystem has this file:
#
# /tmp/foobar
#
# and someone adds this path:
#
# /tmp/foo
#
# with a glob of "*", then this function will return
#
# /tmp/foobar
#
# We need to figure out if that is desired behavior.
result.concat expand_file(path, @glob)
end
else
result << path
end
end
result.uniq!
result
end
# Returns all expanded paths but only if they exist in the filesystem.
def existent
expanded.select { |f| File.exists?(f) }
end
def existent_directories
expanded.select { |d| File.directory?(d) }
end
alias to_a expanded
private
def expand_file(path, glob)
Dir[File.join(path, glob)].sort
end
def expand_dir(path, glob)
Dir.chdir(path) do
Dir.glob(@glob).map { |file| File.join path, file }.sort
end
end
end
end
end
railties-3.2.16/lib/rails/test_help.rb 0000644 0001750 0001750 00000002611 12247655524 017153 0 ustar ondrej ondrej # Make double-sure the RAILS_ENV is not set to production,
# so fixtures aren't loaded into that environment
abort("Abort testing: Your Rails environment is running in production mode!") if Rails.env.production?
require 'test/unit'
require 'active_support/test_case'
require 'action_controller/test_case'
require 'action_dispatch/testing/integration'
if defined?(Test::Unit::Util::BacktraceFilter) && ENV['BACKTRACE'].nil?
require 'rails/backtrace_cleaner'
Test::Unit::Util::BacktraceFilter.module_eval { include Rails::BacktraceFilterForTestUnit }
end
if defined?(MiniTest)
# Enable turn if it is available
begin
require 'turn'
Turn.config do |c|
c.natural = true
end
rescue LoadError
end
end
if defined?(ActiveRecord::Base)
require 'active_record/test_case'
class ActiveSupport::TestCase
include ActiveRecord::TestFixtures
self.fixture_path = "#{Rails.root}/test/fixtures/"
setup do
ActiveRecord::IdentityMap.clear
end
end
ActionDispatch::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path
def create_fixtures(*table_names, &block)
Fixtures.create_fixtures(ActiveSupport::TestCase.fixture_path, table_names, {}, &block)
end
end
class ActionController::TestCase
setup do
@routes = Rails.application.routes
end
end
class ActionDispatch::IntegrationTest
setup do
@routes = Rails.application.routes
end
end
railties-3.2.16/lib/rails/cli.rb 0000644 0001750 0001750 00000000636 12247655524 015740 0 ustar ondrej ondrej require 'rbconfig'
require 'rails/script_rails_loader'
# If we are inside a Rails application this method performs an exec and thus
# the rest of this script is not run.
Rails::ScriptRailsLoader.exec_script_rails!
require 'rails/ruby_version_check'
Signal.trap("INT") { puts; exit(1) }
if ARGV.first == 'plugin'
ARGV.shift
require 'rails/commands/plugin_new'
else
require 'rails/commands/application'
end
railties-3.2.16/lib/rails/plugin.rb 0000644 0001750 0001750 00000006527 12247655524 016474 0 ustar ondrej ondrej require 'rails/engine'
require 'active_support/core_ext/array/conversions'
module Rails
# Rails::Plugin is nothing more than a Rails::Engine, but since it's loaded too late
# in the boot process, it does not have the same configuration powers as a bare
# Rails::Engine.
#
# Opposite to Rails::Railtie and Rails::Engine, you are not supposed to inherit from
# Rails::Plugin. Rails::Plugin is automatically configured to be an engine by simply
# placing inside vendor/plugins. Since this is done automatically, you actually cannot
# declare a Rails::Engine inside your Plugin, otherwise it would cause the same files
# to be loaded twice. This means that if you want to ship an Engine as gem it cannot
# be used as plugin and vice-versa.
#
# Besides this conceptual difference, the only difference between Rails::Engine and
# Rails::Plugin is that plugins automatically load the file "init.rb" at the plugin
# root during the boot process.
#
class Plugin < Engine
def self.global_plugins
@global_plugins ||= []
end
def self.inherited(base)
raise "You cannot inherit from Rails::Plugin"
end
def self.all(list, paths)
plugins = []
paths.each do |path|
Dir["#{path}/*"].each do |plugin_path|
plugin = new(plugin_path)
next unless list.include?(plugin.name) || list.include?(:all)
if global_plugins.include?(plugin.name)
warn "WARNING: plugin #{plugin.name} from #{path} was not loaded. Plugin with the same name has been already loaded."
next
end
global_plugins << plugin.name
plugins << plugin
end
end
plugins.sort_by do |p|
[list.index(p.name) || list.index(:all), p.name.to_s]
end
end
attr_reader :name, :path
def railtie_name
name.to_s
end
def initialize(root)
ActiveSupport::Deprecation.warn "You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released"
@name = File.basename(root).to_sym
config.root = root
end
def config
@config ||= Engine::Configuration.new
end
initializer :handle_lib_autoload, :before => :set_load_path do |app|
autoload = if app.config.reload_plugins
config.autoload_paths
else
config.autoload_once_paths
end
autoload.concat paths["lib"].existent
end
initializer :load_init_rb, :before => :load_config_initializers do |app|
init_rb = File.expand_path("init.rb", root)
if File.file?(init_rb)
# This double assignment is to prevent an "unused variable" warning on Ruby 1.9.3.
config = config = app.config
# TODO: think about evaling initrb in context of Engine (currently it's
# always evaled in context of Rails::Application)
eval(File.read(init_rb), binding, init_rb)
end
end
initializer :sanity_check_railties_collision do
if Engine.subclasses.map { |k| k.root.to_s }.include?(root.to_s)
raise "\"#{name}\" is a Railtie/Engine and cannot be installed as a plugin"
end
end
end
end
railties-3.2.16/lib/rails/console/ 0000755 0001750 0001750 00000000000 12247655524 016301 5 ustar ondrej ondrej railties-3.2.16/lib/rails/console/helpers.rb 0000644 0001750 0001750 00000000302 12247655524 020263 0 ustar ondrej ondrej module Rails
module ConsoleMethods
def helper
@helper ||= ApplicationController.helpers
end
def controller
@controller ||= ApplicationController.new
end
end
end
railties-3.2.16/lib/rails/console/app.rb 0000644 0001750 0001750 00000002052 12247655524 017405 0 ustar ondrej ondrej require 'active_support/all'
require 'active_support/test_case'
require 'action_controller'
# work around the at_exit hook in test/unit, which kills IRB
Test::Unit.run = true if Test::Unit.respond_to?(:run=)
module Rails
module ConsoleMethods
# reference the global "app" instance, created on demand. To recreate the
# instance, pass a non-false value as the parameter.
def app(create=false)
@app_integration_instance = nil if create
@app_integration_instance ||= new_session do |sess|
sess.host! "www.example.com"
end
end
# create a new session. If a block is given, the new session will be yielded
# to the block before being returned.
def new_session
app = Rails.application
session = ActionDispatch::Integration::Session.new(app)
yield session if block_given?
session
end
# reloads the environment
def reload!(print=true)
puts "Reloading..." if print
ActionDispatch::Reloader.cleanup!
ActionDispatch::Reloader.prepare!
true
end
end
end
railties-3.2.16/lib/rails/test_unit/ 0000755 0001750 0001750 00000000000 12247655524 016655 5 ustar ondrej ondrej railties-3.2.16/lib/rails/test_unit/sub_test_task.rb 0000644 0001750 0001750 00000000275 12247655524 022060 0 ustar ondrej ondrej module Rails
# Silence the default description to cut down on `rake -T` noise.
class SubTestTask < Rake::TestTask
def desc(string)
# Ignore the description.
end
end
end
railties-3.2.16/lib/rails/test_unit/testing.rake 0000644 0001750 0001750 00000011544 12247655524 021203 0 ustar ondrej ondrej require 'rbconfig'
require 'rake/testtask'
require 'rails/test_unit/sub_test_task'
TEST_CHANGES_SINCE = Time.now - 600
# Look up tests for recently modified sources.
def recent_tests(source_pattern, test_path, touched_since = 10.minutes.ago)
FileList[source_pattern].map do |path|
if File.mtime(path) > touched_since
tests = []
source_dir = File.dirname(path).split("/")
source_file = File.basename(path, '.rb')
# Support subdirs in app/models and app/controllers
modified_test_path = source_dir.length > 2 ? "#{test_path}/" << source_dir[1..source_dir.length].join('/') : test_path
# For modified files in app/ run the tests for it. ex. /test/functional/account_controller.rb
test = "#{modified_test_path}/#{source_file}_test.rb"
tests.push test if File.exist?(test)
# For modified files in app, run tests in subdirs too. ex. /test/functional/account/*_test.rb
test = "#{modified_test_path}/#{File.basename(path, '.rb').sub("_controller","")}"
FileList["#{test}/*_test.rb"].each { |f| tests.push f } if File.exist?(test)
return tests
end
end.flatten.compact
end
# Recreated here from Active Support because :uncommitted needs it before Rails is available
module Kernel
remove_method :silence_stderr # Removing old method to prevent method redefined warning
def silence_stderr
old_stderr = STDERR.dup
STDERR.reopen(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ ? 'NUL:' : '/dev/null')
STDERR.sync = true
yield
ensure
STDERR.reopen(old_stderr)
end
end
task :default => :test
desc 'Runs test:units, test:functionals, test:integration together (also available: test:benchmark, test:profile, test:plugins)'
task :test do
Rake::Task[ENV['TEST'] ? 'test:single' : 'test:run'].invoke
end
namespace :test do
task :prepare do
# Placeholder task for other Railtie and plugins to enhance. See Active Record for an example.
end
task :run do
errors = %w(test:units test:functionals test:integration).collect do |task|
begin
Rake::Task[task].invoke
nil
rescue => e
{ :task => task, :exception => e }
end
end.compact
if errors.any?
puts errors.map { |e| "Errors running #{e[:task]}! #{e[:exception].inspect}" }.join("\n")
abort
end
end
Rake::TestTask.new(:recent => "test:prepare") do |t|
since = TEST_CHANGES_SINCE
touched = FileList['test/**/*_test.rb'].select { |path| File.mtime(path) > since } +
recent_tests('app/models/**/*.rb', 'test/unit', since) +
recent_tests('app/controllers/**/*.rb', 'test/functional', since)
t.libs << 'test'
t.test_files = touched.uniq
end
Rake::Task['test:recent'].comment = "Test recent changes"
Rake::TestTask.new(:uncommitted => "test:prepare") do |t|
def t.file_list
if File.directory?(".svn")
changed_since_checkin = silence_stderr { `svn status` }.split.map { |path| path.chomp[7 .. -1] }
elsif File.directory?(".git")
changed_since_checkin = silence_stderr { `git ls-files --modified --others` }.split.map { |path| path.chomp }
else
abort "Not a Subversion or Git checkout."
end
models = changed_since_checkin.select { |path| path =~ /app[\\\/]models[\\\/].*\.rb$/ }
controllers = changed_since_checkin.select { |path| path =~ /app[\\\/]controllers[\\\/].*\.rb$/ }
unit_tests = models.map { |model| "test/unit/#{File.basename(model, '.rb')}_test.rb" }
functional_tests = controllers.map { |controller| "test/functional/#{File.basename(controller, '.rb')}_test.rb" }
(unit_tests + functional_tests).uniq.select { |file| File.exist?(file) }
end
t.libs << 'test'
end
Rake::Task['test:uncommitted'].comment = "Test changes since last checkin (only Subversion and Git)"
Rake::TestTask.new(:single => "test:prepare") do |t|
t.libs << "test"
end
Rails::SubTestTask.new(:units => "test:prepare") do |t|
t.libs << "test"
t.pattern = 'test/unit/**/*_test.rb'
end
Rails::SubTestTask.new(:functionals => "test:prepare") do |t|
t.libs << "test"
t.pattern = 'test/functional/**/*_test.rb'
end
Rails::SubTestTask.new(:integration => "test:prepare") do |t|
t.libs << "test"
t.pattern = 'test/integration/**/*_test.rb'
end
task 'test:benchmark_mode' do
ENV["BENCHMARK_TESTS"] = '1'
end
Rails::SubTestTask.new(:benchmark => ['test:prepare', 'test:benchmark_mode']) do |t|
t.libs << 'test'
t.pattern = 'test/performance/**/*_test.rb'
end
Rails::SubTestTask.new(:profile => 'test:prepare') do |t|
t.libs << 'test'
t.pattern = 'test/performance/**/*_test.rb'
end
Rails::SubTestTask.new(:plugins => :environment) do |t|
t.libs << "test"
if ENV['PLUGIN']
t.pattern = "vendor/plugins/#{ENV['PLUGIN']}/test/**/*_test.rb"
else
t.pattern = 'vendor/plugins/*/**/test/**/*_test.rb'
end
end
end
railties-3.2.16/lib/rails/test_unit/railtie.rb 0000644 0001750 0001750 00000000553 12247655524 020636 0 ustar ondrej ondrej module Rails
class TestUnitRailtie < Rails::Railtie
config.app_generators do |c|
c.test_framework :test_unit, :fixture => true,
:fixture_replacement => nil
c.integration_tool :test_unit
c.performance_tool :test_unit
end
rake_tasks do
load "rails/test_unit/testing.rake"
end
end
end
railties-3.2.16/lib/rails/ruby_version_check.rb 0000644 0001750 0001750 00000001110 12247655524 021040 0 ustar ondrej ondrej if RUBY_VERSION < '1.8.7'
desc = defined?(RUBY_DESCRIPTION) ? RUBY_DESCRIPTION : "ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE})"
abort <<-end_message
Rails 3 requires Ruby 1.8.7 or >= 1.9.2.
You're running
#{desc}
Please upgrade to continue.
end_message
elsif RUBY_VERSION > '1.9' and RUBY_VERSION < '1.9.2'
$stderr.puts <<-end_message
Rails 3 doesn't officially support Ruby 1.9.1 since recent stable
releases have segfaulted the test suite. Please upgrade to Ruby 1.9.2 or later.
You're running
#{RUBY_DESCRIPTION}
end_message
end
railties-3.2.16/lib/rails/rack.rb 0000644 0001750 0001750 00000000276 12247655524 016111 0 ustar ondrej ondrej module Rails
module Rack
autoload :Debugger, "rails/rack/debugger"
autoload :Logger, "rails/rack/logger"
autoload :LogTailer, "rails/rack/log_tailer"
end
end
railties-3.2.16/lib/rails/configuration.rb 0000644 0001750 0001750 00000004427 12247655524 020042 0 ustar ondrej ondrej require 'active_support/deprecation'
require 'active_support/ordered_options'
require 'active_support/core_ext/hash/deep_dup'
require 'rails/paths'
require 'rails/rack'
module Rails
module Configuration
class MiddlewareStackProxy #:nodoc:
def initialize
@operations = []
end
def insert_before(*args, &block)
@operations << [:insert_before, args, block]
end
alias :insert :insert_before
def insert_after(*args, &block)
@operations << [:insert_after, args, block]
end
def swap(*args, &block)
@operations << [:swap, args, block]
end
def use(*args, &block)
@operations << [:use, args, block]
end
def delete(*args, &block)
@operations << [:delete, args, block]
end
def merge_into(other)
@operations.each do |operation, args, block|
other.send(operation, *args, &block)
end
other
end
end
class Generators #:nodoc:
attr_accessor :aliases, :options, :templates, :fallbacks, :colorize_logging
attr_reader :hidden_namespaces
def initialize
@aliases = Hash.new { |h,k| h[k] = {} }
@options = Hash.new { |h,k| h[k] = {} }
@fallbacks = {}
@templates = []
@colorize_logging = true
@hidden_namespaces = []
end
def initialize_copy(source)
@aliases = @aliases.deep_dup
@options = @options.deep_dup
@fallbacks = @fallbacks.deep_dup
@templates = @templates.dup
end
def hide_namespace(namespace)
@hidden_namespaces << namespace
end
def method_missing(method, *args)
method = method.to_s.sub(/=$/, '').to_sym
return @options[method] if args.empty?
if method == :rails || args.first.is_a?(Hash)
namespace, configuration = method, args.shift
else
namespace, configuration = args.shift, args.shift
namespace = namespace.to_sym if namespace.respond_to?(:to_sym)
@options[:rails][method] = namespace
end
if configuration
aliases = configuration.delete(:aliases)
@aliases[namespace].merge!(aliases) if aliases
@options[namespace].merge!(configuration)
end
end
end
end
end
railties-3.2.16/lib/rails/railtie.rb 0000644 0001750 0001750 00000014465 12247655524 016627 0 ustar ondrej ondrej require 'rails/initializable'
require 'rails/configuration'
require 'active_support/inflector'
require 'active_support/core_ext/module/introspection'
require 'active_support/core_ext/module/delegation'
module Rails
# Railtie is the core of the Rails framework and provides several hooks to extend
# Rails and/or modify the initialization process.
#
# Every major component of Rails (Action Mailer, Action Controller,
# Action View, Active Record and Active Resource) is a Railtie. Each of
# them is responsible for their own initialization. This makes Rails itself
# absent of any component hooks, allowing other components to be used in
# place of any of the Rails defaults.
#
# Developing a Rails extension does _not_ require any implementation of
# Railtie, but if you need to interact with the Rails framework during
# or after boot, then Railtie is needed.
#
# For example, an extension doing any of the following would require Railtie:
#
# * creating initializers
# * configuring a Rails framework for the application, like setting a generator
# * adding config.* keys to the environment
# * setting up a subscriber with ActiveSupport::Notifications
# * adding rake tasks
#
# == Creating your Railtie
#
# To extend Rails using Railtie, create a Railtie class which inherits
# from Rails::Railtie within your extension's namespace. This class must be
# loaded during the Rails boot process.
#
# The following example demonstrates an extension which can be used with or without Rails.
#
# # lib/my_gem/railtie.rb
# module MyGem
# class Railtie < Rails::Railtie
# end
# end
#
# # lib/my_gem.rb
# require 'my_gem/railtie' if defined?(Rails)
#
# == Initializers
#
# To add an initialization step from your Railtie to Rails boot process, you just need
# to create an initializer block:
#
# class MyRailtie < Rails::Railtie
# initializer "my_railtie.configure_rails_initialization" do
# # some initialization behavior
# end
# end
#
# If specified, the block can also receive the application object, in case you
# need to access some application specific configuration, like middleware:
#
# class MyRailtie < Rails::Railtie
# initializer "my_railtie.configure_rails_initialization" do |app|
# app.middleware.use MyRailtie::Middleware
# end
# end
#
# Finally, you can also pass :before and :after as option to initializer, in case
# you want to couple it with a specific step in the initialization process.
#
# == Configuration
#
# Inside the Railtie class, you can access a config object which contains configuration
# shared by all railties and the application:
#
# class MyRailtie < Rails::Railtie
# # Customize the ORM
# config.app_generators.orm :my_railtie_orm
#
# # Add a to_prepare block which is executed once in production
# # and before each request in development
# config.to_prepare do
# MyRailtie.setup!
# end
# end
#
# == Loading rake tasks and generators
#
# If your railtie has rake tasks, you can tell Rails to load them through the method
# rake_tasks:
#
# class MyRailtie < Rails::Railtie
# rake_tasks do
# load "path/to/my_railtie.tasks"
# end
# end
#
# By default, Rails load generators from your load path. However, if you want to place
# your generators at a different location, you can specify in your Railtie a block which
# will load them during normal generators lookup:
#
# class MyRailtie < Rails::Railtie
# generators do
# require "path/to/my_railtie_generator"
# end
# end
#
# == Application, Plugin and Engine
#
# A Rails::Engine is nothing more than a Railtie with some initializers already set.
# And since Rails::Application and Rails::Plugin are engines, the same configuration
# described here can be used in all three.
#
# Be sure to look at the documentation of those specific classes for more information.
#
class Railtie
autoload :Configurable, "rails/railtie/configurable"
autoload :Configuration, "rails/railtie/configuration"
include Initializable
ABSTRACT_RAILTIES = %w(Rails::Railtie Rails::Plugin Rails::Engine Rails::Application)
class << self
private :new
def subclasses
@subclasses ||= []
end
def inherited(base)
unless base.abstract_railtie?
base.send(:include, Railtie::Configurable)
subclasses << base
end
end
def rake_tasks(&blk)
@rake_tasks ||= []
@rake_tasks << blk if blk
@rake_tasks
end
def console(&blk)
@load_console ||= []
@load_console << blk if blk
@load_console
end
def runner(&blk)
@load_runner ||= []
@load_runner << blk if blk
@load_runner
end
def generators(&blk)
@generators ||= []
@generators << blk if blk
@generators
end
def abstract_railtie?
ABSTRACT_RAILTIES.include?(name)
end
def railtie_name(name = nil)
@railtie_name = name.to_s if name
@railtie_name ||= generate_railtie_name(self.name)
end
protected
def generate_railtie_name(class_or_module)
ActiveSupport::Inflector.underscore(class_or_module).gsub("/", "_")
end
end
delegate :railtie_name, :to => "self.class"
def config
@config ||= Railtie::Configuration.new
end
def eager_load!
end
def load_console(app=self)
self.class.console.each { |block| block.call(app) }
end
def load_runner(app=self)
self.class.runner.each { |block| block.call(app) }
end
def load_tasks(app=self)
extend Rake::DSL if defined? Rake::DSL
self.class.rake_tasks.each { |block| self.instance_exec(app, &block) }
# load also tasks from all superclasses
klass = self.class.superclass
while klass.respond_to?(:rake_tasks)
klass.rake_tasks.each { |t| self.instance_exec(app, &t) }
klass = klass.superclass
end
end
def load_generators(app=self)
self.class.generators.each { |block| block.call(app) }
end
def railtie_namespace
@railtie_namespace ||= self.class.parents.detect { |n| n.respond_to?(:railtie_namespace) }
end
end
end
railties-3.2.16/lib/rails/rubyprof_ext.rb 0000644 0001750 0001750 00000001726 12247655524 017722 0 ustar ondrej ondrej require 'prof'
module Prof #:nodoc:
# Adapted from Shugo Maeda's unprof.rb
def self.print_profile(results, io = $stderr)
total = results.detect { |i|
i.method_class.nil? && i.method_id == :"#toplevel"
}.total_time
total = 0.001 if total < 0.001
io.puts " %% cumulative self self total"
io.puts " time seconds seconds calls ms/call ms/call name"
sum = 0.0
for r in results
sum += r.self_time
name = if r.method_class.nil?
r.method_id.to_s
elsif r.method_class.is_a?(Class)
"#{r.method_class}##{r.method_id}"
else
"#{r.method_class}.#{r.method_id}"
end
io.printf "%6.2f %8.3f %8.3f %8d %8.2f %8.2f %s\n",
r.self_time / total * 100,
sum,
r.self_time,
r.count,
r.self_time * 1000 / r.count,
r.total_time * 1000 / r.count,
name
end
end
end
railties-3.2.16/lib/rails/engine/ 0000755 0001750 0001750 00000000000 12247655524 016104 5 ustar ondrej ondrej railties-3.2.16/lib/rails/engine/configuration.rb 0000644 0001750 0001750 00000005275 12247655524 021311 0 ustar ondrej ondrej require 'rails/railtie/configuration'
module Rails
class Engine
class Configuration < ::Rails::Railtie::Configuration
attr_reader :root
attr_writer :middleware, :eager_load_paths, :autoload_once_paths, :autoload_paths
attr_accessor :plugins
def initialize(root=nil)
super()
@root = root
@generators = app_generators.dup
end
# Returns the middleware stack for the engine.
def middleware
@middleware ||= Rails::Configuration::MiddlewareStackProxy.new
end
# Holds generators configuration:
#
# config.generators do |g|
# g.orm :datamapper, :migration => true
# g.template_engine :haml
# g.test_framework :rspec
# end
#
# If you want to disable color in console, do:
#
# config.generators.colorize_logging = false
#
def generators #:nodoc:
@generators ||= Rails::Configuration::Generators.new
yield(@generators) if block_given?
@generators
end
def paths
@paths ||= begin
paths = Rails::Paths::Root.new(@root)
paths.add "app", :eager_load => true, :glob => "*"
paths.add "app/assets", :glob => "*"
paths.add "app/controllers", :eager_load => true
paths.add "app/helpers", :eager_load => true
paths.add "app/models", :eager_load => true
paths.add "app/mailers", :eager_load => true
paths.add "app/views"
paths.add "lib", :load_path => true
paths.add "lib/assets", :glob => "*"
paths.add "lib/tasks", :glob => "**/*.rake"
paths.add "config"
paths.add "config/environments", :glob => "#{Rails.env}.rb"
paths.add "config/initializers", :glob => "**/*.rb"
paths.add "config/locales", :glob => "*.{rb,yml}"
paths.add "config/routes", :with => "config/routes.rb"
paths.add "db"
paths.add "db/migrate"
paths.add "db/seeds", :with => "db/seeds.rb"
paths.add "vendor", :load_path => true
paths.add "vendor/assets", :glob => "*"
paths.add "vendor/plugins"
paths
end
end
def root=(value)
@root = paths.path = Pathname.new(value).expand_path
end
def eager_load_paths
@eager_load_paths ||= paths.eager_load
end
def autoload_once_paths
@autoload_once_paths ||= paths.autoload_once
end
def autoload_paths
@autoload_paths ||= paths.autoload_paths
end
end
end
end
railties-3.2.16/lib/rails/engine/railties.rb 0000644 0001750 0001750 00000001426 12247655524 020250 0 ustar ondrej ondrej module Rails
class Engine < Railtie
class Railties
# TODO Write tests for this behavior extracted from Application
def initialize(config)
@config = config
end
def all(&block)
@all ||= plugins
@all.each(&block) if block
@all
end
def plugins
@plugins ||= begin
plugin_names = (@config.plugins || [:all]).map { |p| p.to_sym }
Plugin.all(plugin_names, @config.paths["vendor/plugins"].existent)
end
end
def self.railties
@railties ||= ::Rails::Railtie.subclasses.map(&:instance)
end
def self.engines
@engines ||= ::Rails::Engine.subclasses.map(&:instance)
end
delegate :railties, :engines, :to => "self.class"
end
end
end
railties-3.2.16/lib/rails/engine/commands.rb 0000644 0001750 0001750 00000002134 12247655524 020232 0 ustar ondrej ondrej require 'active_support/core_ext/object/inclusion'
ARGV << '--help' if ARGV.empty?
aliases = {
"g" => "generate",
"d" => "destroy"
}
command = ARGV.shift
command = aliases[command] || command
require ENGINE_PATH
engine = ::Rails::Engine.find(ENGINE_ROOT)
case command
when 'generate', 'destroy'
require 'rails/generators'
Rails::Generators.namespace = engine.railtie_namespace
engine.load_generators
require "rails/commands/#{command}"
when '--version', '-v'
ARGV.unshift '--version'
require 'rails/commands/application'
else
puts "Error: Command not recognized" unless command.in?(['-h', '--help'])
puts <<-EOT
Usage: rails COMMAND [ARGS]
The common rails commands available for engines are:
generate Generate new code (short-cut alias: "g")
destroy Undo code generated with "generate" (short-cut alias: "d")
All commands can be run with -h for more information.
If you want to run any commands that need to be run in context
of the application, like `rails server` or `rails console`,
you should do it from application's directory (typically test/dummy).
EOT
exit(1)
end
railties-3.2.16/lib/rails/application.rb 0000644 0001750 0001750 00000026543 12247655524 017501 0 ustar ondrej ondrej require 'active_support/core_ext/hash/reverse_merge'
require 'fileutils'
require 'rails/plugin'
require 'rails/engine'
module Rails
# In Rails 3.0, a Rails::Application object was introduced which is nothing more than
# an Engine but with the responsibility of coordinating the whole boot process.
#
# == Initialization
#
# Rails::Application is responsible for executing all railties, engines and plugin
# initializers. It also executes some bootstrap initializers (check
# Rails::Application::Bootstrap) and finishing initializers, after all the others
# are executed (check Rails::Application::Finisher).
#
# == Configuration
#
# Besides providing the same configuration as Rails::Engine and Rails::Railtie,
# the application object has several specific configurations, for example
# "allow_concurrency", "cache_classes", "consider_all_requests_local", "filter_parameters",
# "logger", "reload_plugins" and so forth.
#
# Check Rails::Application::Configuration to see them all.
#
# == Routes
#
# The application object is also responsible for holding the routes and reloading routes
# whenever the files change in development.
#
# == Middlewares
#
# The Application is also responsible for building the middleware stack.
#
# == Booting process
#
# The application is also responsible for setting up and executing the booting
# process. From the moment you require "config/application.rb" in your app,
# the booting process goes like this:
#
# 1) require "config/boot.rb" to setup load paths
# 2) require railties and engines
# 3) Define Rails.application as "class MyApp::Application < Rails::Application"
# 4) Run config.before_configuration callbacks
# 5) Load config/environments/ENV.rb
# 6) Run config.before_initialize callbacks
# 7) Run Railtie#initializer defined by railties, engines and application.
# One by one, each engine sets up its load paths, routes and runs its config/initializers/* files.
# 9) Custom Railtie#initializers added by railties, engines and applications are executed
# 10) Build the middleware stack and run to_prepare callbacks
# 11) Run config.before_eager_load and eager_load if cache classes is true
# 12) Run config.after_initialize callbacks
#
class Application < Engine
autoload :Bootstrap, 'rails/application/bootstrap'
autoload :Configuration, 'rails/application/configuration'
autoload :Finisher, 'rails/application/finisher'
autoload :Railties, 'rails/application/railties'
autoload :RoutesReloader, 'rails/application/routes_reloader'
class << self
def inherited(base)
raise "You cannot have more than one Rails::Application" if Rails.application
super
Rails.application = base.instance
Rails.application.add_lib_to_load_path!
ActiveSupport.run_load_hooks(:before_configuration, base.instance)
end
end
attr_accessor :assets, :sandbox
alias_method :sandbox?, :sandbox
attr_reader :reloaders
delegate :default_url_options, :default_url_options=, :to => :routes
def initialize
super
@initialized = false
@reloaders = []
end
# This method is called just after an application inherits from Rails::Application,
# allowing the developer to load classes in lib and use them during application
# configuration.
#
# class MyApplication < Rails::Application
# require "my_backend" # in lib/my_backend
# config.i18n.backend = MyBackend
# end
#
# Notice this method takes into consideration the default root path. So if you
# are changing config.root inside your application definition or having a custom
# Rails application, you will need to add lib to $LOAD_PATH on your own in case
# you need to load files in lib/ during the application configuration as well.
def add_lib_to_load_path! #:nodoc:
path = config.root.join('lib').to_s
$LOAD_PATH.unshift(path) if File.exists?(path)
end
def require_environment! #:nodoc:
environment = paths["config/environment"].existent.first
require environment if environment
end
# Reload application routes regardless if they changed or not.
def reload_routes!
routes_reloader.reload!
end
def routes_reloader #:nodoc:
@routes_reloader ||= RoutesReloader.new
end
# Returns an array of file paths appended with a hash of directories-extensions
# suitable for ActiveSupport::FileUpdateChecker API.
def watchable_args
files = []
files.concat config.watchable_files
dirs = {}
dirs.merge! config.watchable_dirs
ActiveSupport::Dependencies.autoload_paths.each do |path|
dirs[path.to_s] = [:rb]
end
[files, dirs]
end
# Initialize the application passing the given group. By default, the
# group is :default but sprockets precompilation passes group equals
# to assets if initialize_on_precompile is false to avoid booting the
# whole app.
def initialize!(group=:default) #:nodoc:
raise "Application has been already initialized." if @initialized
run_initializers(group, self)
@initialized = true
self
end
# Load the application and its railties tasks and invoke the registered hooks.
# Check Rails::Railtie.rake_tasks for more info.
def load_tasks(app=self)
initialize_tasks
super
self
end
# Load the application console and invoke the registered hooks.
# Check Rails::Railtie.console for more info.
def load_console(app=self)
initialize_console
super
self
end
# Load the application runner and invoke the registered hooks.
# Check Rails::Railtie.runner for more info.
def load_runner(app=self)
initialize_runner
super
self
end
# Rails.application.env_config stores some of the Rails initial environment parameters.
# Currently stores:
#
# * "action_dispatch.parameter_filter" => config.filter_parameters,
# * "action_dispatch.secret_token" => config.secret_token,
# * "action_dispatch.show_exceptions" => config.action_dispatch.show_exceptions,
# * "action_dispatch.show_detailed_exceptions" => config.consider_all_requests_local,
# * "action_dispatch.logger" => Rails.logger,
# * "action_dispatch.backtrace_cleaner" => Rails.backtrace_cleaner
#
# These parameters will be used by middlewares and engines to configure themselves.
#
def env_config
@app_env_config ||= super.merge({
"action_dispatch.parameter_filter" => config.filter_parameters,
"action_dispatch.secret_token" => config.secret_token,
"action_dispatch.show_exceptions" => config.action_dispatch.show_exceptions,
"action_dispatch.show_detailed_exceptions" => config.consider_all_requests_local,
"action_dispatch.logger" => Rails.logger,
"action_dispatch.backtrace_cleaner" => Rails.backtrace_cleaner
})
end
# Returns the ordered railties for this application considering railties_order.
def ordered_railties #:nodoc:
@ordered_railties ||= begin
order = config.railties_order.map do |railtie|
if railtie == :main_app
self
elsif railtie.respond_to?(:instance)
railtie.instance
else
railtie
end
end
all = (railties.all - order)
all.push(self) unless (all + order).include?(self)
order.push(:all) unless order.include?(:all)
index = order.index(:all)
order[index] = all
order.reverse.flatten
end
end
def initializers #:nodoc:
Bootstrap.initializers_for(self) +
super +
Finisher.initializers_for(self)
end
def config #:nodoc:
@config ||= Application::Configuration.new(find_root_with_flag("config.ru", Dir.pwd))
end
def to_app
self
end
def helpers_paths #:nodoc:
config.helpers_paths
end
def call(env)
env["ORIGINAL_FULLPATH"] = build_original_fullpath(env)
super(env)
end
protected
alias :build_middleware_stack :app
def reload_dependencies?
config.reload_classes_only_on_change != true || reloaders.map(&:updated?).any?
end
def default_middleware_stack
require 'action_controller/railtie'
ActionDispatch::MiddlewareStack.new.tap do |middleware|
if rack_cache = config.action_controller.perform_caching && config.action_dispatch.rack_cache
require "action_dispatch/http/rack_cache"
middleware.use ::Rack::Cache, rack_cache
end
if config.force_ssl
require "rack/ssl"
middleware.use ::Rack::SSL, config.ssl_options
end
if config.serve_static_assets
middleware.use ::ActionDispatch::Static, paths["public"].first, config.static_cache_control
end
middleware.use ::Rack::Lock unless config.allow_concurrency
middleware.use ::Rack::Runtime
middleware.use ::Rack::MethodOverride
middleware.use ::ActionDispatch::RequestId
middleware.use ::Rails::Rack::Logger, config.log_tags # must come after Rack::MethodOverride to properly log overridden methods
middleware.use ::ActionDispatch::ShowExceptions, config.exceptions_app || ActionDispatch::PublicExceptions.new(Rails.public_path)
middleware.use ::ActionDispatch::DebugExceptions
middleware.use ::ActionDispatch::RemoteIp, config.action_dispatch.ip_spoofing_check, config.action_dispatch.trusted_proxies
if config.action_dispatch.x_sendfile_header.present?
middleware.use ::Rack::Sendfile, config.action_dispatch.x_sendfile_header
end
unless config.cache_classes
app = self
middleware.use ::ActionDispatch::Reloader, lambda { app.reload_dependencies? }
end
middleware.use ::ActionDispatch::Callbacks
middleware.use ::ActionDispatch::Cookies
if config.session_store
if config.force_ssl && !config.session_options.key?(:secure)
config.session_options[:secure] = true
end
middleware.use config.session_store, config.session_options
middleware.use ::ActionDispatch::Flash
end
middleware.use ::ActionDispatch::ParamsParser
middleware.use ::ActionDispatch::Head
middleware.use ::Rack::ConditionalGet
middleware.use ::Rack::ETag, "no-cache"
if config.action_dispatch.best_standards_support
middleware.use ::ActionDispatch::BestStandardsSupport, config.action_dispatch.best_standards_support
end
end
end
def initialize_tasks #:nodoc:
self.class.rake_tasks do
require "rails/tasks"
task :environment do
$rails_rake_task = true
require_environment!
end
end
end
def initialize_console #:nodoc:
require "pp"
require "rails/console/app"
require "rails/console/helpers"
end
def initialize_runner #:nodoc:
end
def build_original_fullpath(env)
path_info = env["PATH_INFO"]
query_string = env["QUERY_STRING"]
script_name = env["SCRIPT_NAME"]
if query_string.present?
"#{script_name}#{path_info}?#{query_string}"
else
"#{script_name}#{path_info}"
end
end
end
end
railties-3.2.16/lib/rails/source_annotation_extractor.rb 0000644 0001750 0001750 00000007171 12247655524 023017 0 ustar ondrej ondrej # Implements the logic behind the rake tasks for annotations like
#
# rake notes
# rake notes:optimize
#
# and friends. See rake -T notes and railties/lib/tasks/annotations.rake.
#
# Annotation objects are triplets :line, :tag, :text that
# represent the line where the annotation lives, its tag, and its text. Note
# the filename is not stored.
#
# Annotations are looked for in comments and modulus whitespace they have to
# start with the tag optionally followed by a colon. Everything up to the end
# of the line (or closing ERB comment tag) is considered to be their text.
class SourceAnnotationExtractor
class Annotation < Struct.new(:line, :tag, :text)
# Returns a representation of the annotation that looks like this:
#
# [126] [TODO] This algorithm is simple and clearly correct, make it faster.
#
# If +options+ has a flag :tag the tag is shown as in the example above.
# Otherwise the string contains just line and text.
def to_s(options={})
s = "[%3d] " % line
s << "[#{tag}] " if options[:tag]
s << text
end
end
# Prints all annotations with tag +tag+ under the root directories +app+, +config+, +lib+,
# +script+, and +test+ (recursively). Only filenames with extension
# +.builder+, +.rb+, and +.erb+ are taken into account. The +options+
# hash is passed to each annotation's +to_s+.
#
# This class method is the single entry point for the rake tasks.
def self.enumerate(tag, options={})
extractor = new(tag)
extractor.display(extractor.find, options)
end
attr_reader :tag
def initialize(tag)
@tag = tag
end
# Returns a hash that maps filenames under +dirs+ (recursively) to arrays
# with their annotations.
def find(dirs=%w(app config lib script test))
dirs.inject({}) { |h, dir| h.update(find_in(dir)) }
end
# Returns a hash that maps filenames under +dir+ (recursively) to arrays
# with their annotations. Only files with annotations are included, and only
# those with extension +.builder+, +.rb+, +.erb+, +.haml+, +.slim+ and +.coffee+
# are taken into account.
def find_in(dir)
results = {}
Dir.glob("#{dir}/*") do |item|
next if File.basename(item)[0] == ?.
if File.directory?(item)
results.update(find_in(item))
elsif item =~ /\.(builder|rb|coffee)$/
results.update(extract_annotations_from(item, /#\s*(#{tag}):?\s*(.*)$/))
elsif item =~ /\.erb$/
results.update(extract_annotations_from(item, /<%\s*#\s*(#{tag}):?\s*(.*?)\s*%>/))
elsif item =~ /\.haml$/
results.update(extract_annotations_from(item, /-\s*#\s*(#{tag}):?\s*(.*)$/))
elsif item =~ /\.slim$/
results.update(extract_annotations_from(item, /\/\s*\s*(#{tag}):?\s*(.*)$/))
end
end
results
end
# If +file+ is the filename of a file that contains annotations this method returns
# a hash with a single entry that maps +file+ to an array of its annotations.
# Otherwise it returns an empty hash.
def extract_annotations_from(file, pattern)
lineno = 0
result = File.readlines(file).inject([]) do |list, line|
lineno += 1
next list unless line =~ pattern
list << Annotation.new(lineno, $1, $2)
end
result.empty? ? {} : { file => result }
end
# Prints the mapping from filenames to annotations in +results+ ordered by filename.
# The +options+ hash is passed to each annotation's +to_s+.
def display(results, options={})
results.keys.sort.each do |file|
puts "#{file}:"
results[file].each do |note|
puts " * #{note.to_s(options)}"
end
puts
end
end
end
railties-3.2.16/lib/rails/tasks/ 0000755 0001750 0001750 00000000000 12247655524 015764 5 ustar ondrej ondrej railties-3.2.16/lib/rails/tasks/documentation.rake 0000644 0001750 0001750 00000012036 12247655524 021503 0 ustar ondrej ondrej begin
require 'rdoc/task'
rescue LoadError
require 'rdoc/rdoc'
require 'rake/rdoctask'
RDoc::Task = Rake::RDocTask
end
# Monkey-patch to remove redoc'ing and clobber descriptions to cut down on rake -T noise
class RDocTaskWithoutDescriptions < RDoc::Task
include ::Rake::DSL if defined?(::Rake::DSL)
def define
task rdoc_task_name
task rerdoc_task_name => [clobber_task_name, rdoc_task_name]
task clobber_task_name do
rm_r rdoc_dir rescue nil
end
task :clobber => [clobber_task_name]
directory @rdoc_dir
task rdoc_task_name => [rdoc_target]
file rdoc_target => @rdoc_files + [Rake.application.rakefile] do
rm_r @rdoc_dir rescue nil
@before_running_rdoc.call if @before_running_rdoc
args = option_list + @rdoc_files
if @external
argstring = args.join(' ')
sh %{ruby -Ivendor vendor/rd #{argstring}}
else
require 'rdoc/rdoc'
RDoc::RDoc.new.document(args)
end
end
self
end
end
namespace :doc do
def gem_path(gem_name)
path = $LOAD_PATH.grep(/#{gem_name}[\w.-]*\/lib$/).first
yield File.dirname(path) if path
end
RDocTaskWithoutDescriptions.new("app") { |rdoc|
rdoc.rdoc_dir = 'doc/app'
rdoc.template = ENV['template'] if ENV['template']
rdoc.title = ENV['title'] || "Rails Application Documentation"
rdoc.options << '--line-numbers'
rdoc.options << '--charset' << 'utf-8'
rdoc.rdoc_files.include('doc/README_FOR_APP')
rdoc.rdoc_files.include('app/**/*.rb')
rdoc.rdoc_files.include('lib/**/*.rb')
}
Rake::Task['doc:app'].comment = "Generate docs for the app -- also available doc:rails, doc:guides, doc:plugins (options: TEMPLATE=/rdoc-template.rb, TITLE=\"Custom Title\")"
# desc 'Generate documentation for the Rails framework.'
RDocTaskWithoutDescriptions.new("rails") { |rdoc|
rdoc.rdoc_dir = 'doc/api'
rdoc.template = "#{ENV['template']}.rb" if ENV['template']
rdoc.title = "Rails Framework Documentation"
rdoc.options << '--line-numbers'
rdoc.rdoc_files.include('README.rdoc')
gem_path('actionmailer') do |actionmailer|
%w(README.rdoc CHANGELOG.md MIT-LICENSE lib/action_mailer/base.rb).each do |file|
rdoc.rdoc_files.include("#{actionmailer}/#{file}")
end
end
gem_path('actionpack') do |actionpack|
%w(README.rdoc CHANGELOG.md MIT-LICENSE lib/action_controller/**/*.rb lib/action_view/**/*.rb).each do |file|
rdoc.rdoc_files.include("#{actionpack}/#{file}")
end
end
gem_path('activemodel') do |activemodel|
%w(README.rdoc CHANGELOG.md MIT-LICENSE lib/active_model/**/*.rb).each do |file|
rdoc.rdoc_files.include("#{activemodel}/#{file}")
end
end
gem_path('activerecord') do |activerecord|
%w(README.rdoc CHANGELOG.md lib/active_record/**/*.rb).each do |file|
rdoc.rdoc_files.include("#{activerecord}/#{file}")
end
end
gem_path('activeresource') do |activeresource|
%w(README.rdoc CHANGELOG.md lib/active_resource.rb lib/active_resource/*).each do |file|
rdoc.rdoc_files.include("#{activeresource}/#{file}")
end
end
gem_path('activesupport') do |activesupport|
%w(README.rdoc CHANGELOG.md lib/active_support/**/*.rb).each do |file|
rdoc.rdoc_files.include("#{activesupport}/#{file}")
end
end
gem_path('railties') do |railties|
%w(README.rdoc CHANGELOG.md lib/{*.rb,commands/*.rb,generators/*.rb}).each do |file|
rdoc.rdoc_files.include("#{railties}/#{file}")
end
end
}
plugins = FileList['vendor/plugins/**'].collect { |plugin| File.basename(plugin) }
# desc "Generate documentation for all installed plugins"
task :plugins => plugins.collect { |plugin| "doc:plugins:#{plugin}" }
# desc "Remove plugin documentation"
task :clobber_plugins do
rm_rf 'doc/plugins' rescue nil
end
# desc "Generate Rails Guides"
task :guides do
rails_gem_dir = Gem::Specification.find_by_name("rails").gem_dir
require File.expand_path(File.join(rails_gem_dir, "railties/guides/rails_guides"))
RailsGuides::Generator.new(Rails.root.join("doc/guides")).generate
end
namespace :plugins do
# Define doc tasks for each plugin
plugins.each do |plugin|
# desc "Generate documentation for the #{plugin} plugin"
task(plugin => :environment) do
plugin_base = "vendor/plugins/#{plugin}"
options = []
files = Rake::FileList.new
options << "-o doc/plugins/#{plugin}"
options << "--title '#{plugin.titlecase} Plugin Documentation'"
options << '--line-numbers'
options << '--charset' << 'utf-8'
options << '-T html'
files.include("#{plugin_base}/lib/**/*.rb")
if File.exist?("#{plugin_base}/README")
files.include("#{plugin_base}/README")
options << "--main '#{plugin_base}/README'"
end
files.include("#{plugin_base}/CHANGELOG") if File.exist?("#{plugin_base}/CHANGELOG")
options << files.to_s
sh %(rdoc #{options * ' '})
end
end
end
end
railties-3.2.16/lib/rails/tasks/misc.rake 0000644 0001750 0001750 00000004365 12247655524 017573 0 ustar ondrej ondrej task :rails_env do
# TODO Do we really need this?
unless defined? RAILS_ENV
RAILS_ENV = ENV['RAILS_ENV'] ||= 'development'
end
end
desc 'Generate a cryptographically secure secret key (this is typically used to generate a secret for cookie sessions).'
task :secret do
require 'securerandom'
puts SecureRandom.hex(64)
end
desc 'List versions of all Rails frameworks and the environment'
task :about => :environment do
puts Rails::Info
end
namespace :time do
namespace :zones do
desc 'Displays all time zones, also available: time:zones:us, time:zones:local -- filter with OFFSET parameter, e.g., OFFSET=-6'
task :all do
build_time_zone_list(:all)
end
# desc 'Displays names of US time zones recognized by the Rails TimeZone class, grouped by offset. Results can be filtered with optional OFFSET parameter, e.g., OFFSET=-6'
task :us do
build_time_zone_list(:us_zones)
end
# desc 'Displays names of time zones recognized by the Rails TimeZone class with the same offset as the system local time'
task :local do
require 'active_support'
require 'active_support/time'
jan_offset = Time.now.beginning_of_year.utc_offset
jul_offset = Time.now.beginning_of_year.change(:month => 7).utc_offset
offset = jan_offset < jul_offset ? jan_offset : jul_offset
build_time_zone_list(:all, offset)
end
# to find UTC -06:00 zones, OFFSET can be set to either -6, -6:00 or 21600
def build_time_zone_list(method, offset = ENV['OFFSET'])
require 'active_support'
require 'active_support/time'
if offset
offset = if offset.to_s.match(/(\+|-)?(\d+):(\d+)/)
sign = $1 == '-' ? -1 : 1
hours, minutes = $2.to_f, $3.to_f
((hours * 3600) + (minutes.to_f * 60)) * sign
elsif offset.to_f.abs <= 13
offset.to_f * 3600
else
offset.to_f
end
end
previous_offset = nil
ActiveSupport::TimeZone.__send__(method).each do |zone|
if offset.nil? || offset == zone.utc_offset
puts "\n* UTC #{zone.formatted_offset} *" unless zone.utc_offset == previous_offset
puts zone.name
previous_offset = zone.utc_offset
end
end
puts "\n"
end
end
end
railties-3.2.16/lib/rails/tasks/framework.rake 0000644 0001750 0001750 00000006073 12247655524 020633 0 ustar ondrej ondrej namespace :rails do
desc "Update configs and some other initially generated files (or use just update:configs, update:scripts, or update:application_controller)"
task :update => [ "update:configs", "update:scripts", "update:application_controller" ]
desc "Applies the template supplied by LOCATION=(/path/to/template) or URL"
task :template do
template = ENV["LOCATION"]
raise "No LOCATION value given. Please set LOCATION either as path to a file or a URL" if template.blank?
template = File.expand_path(template) if template !~ %r{\A[A-Za-z][A-Za-z0-9+\-\.]*://}
require 'rails/generators'
require 'rails/generators/rails/app/app_generator'
generator = Rails::Generators::AppGenerator.new [Rails.root], {}, :destination_root => Rails.root
generator.apply template, :verbose => false
end
namespace :templates do
# desc "Copy all the templates from rails to the application directory for customization. Already existing local copies will be overwritten"
task :copy do
generators_lib = File.expand_path("../../generators", __FILE__)
project_templates = "#{Rails.root}/lib/templates"
default_templates = { "erb" => %w{controller mailer scaffold},
"rails" => %w{controller helper scaffold_controller assets} }
default_templates.each do |type, names|
local_template_type_dir = File.join(project_templates, type)
FileUtils.mkdir_p local_template_type_dir
names.each do |name|
dst_name = File.join(local_template_type_dir, name)
src_name = File.join(generators_lib, type, name, "templates")
FileUtils.cp_r src_name, dst_name
end
end
end
end
namespace :update do
def invoke_from_app_generator(method)
app_generator.send(method)
end
def app_generator
@app_generator ||= begin
require 'rails/generators'
require 'rails/generators/rails/app/app_generator'
gen = Rails::Generators::AppGenerator.new ["rails"], { :with_dispatchers => true },
:destination_root => Rails.root
File.exists?(Rails.root.join("config", "application.rb")) ?
gen.send(:app_const) : gen.send(:valid_app_const?)
gen
end
end
# desc "Update config/boot.rb from your current rails install"
task :configs do
invoke_from_app_generator :create_boot_file
invoke_from_app_generator :create_config_files
end
# desc "Adds new scripts to the application script/ directory"
task :scripts do
invoke_from_app_generator :create_script_files
end
# desc "Rename application.rb to application_controller.rb"
task :application_controller do
old_style = Rails.root + '/app/controllers/application.rb'
new_style = Rails.root + '/app/controllers/application_controller.rb'
if File.exists?(old_style) && !File.exists?(new_style)
FileUtils.mv(old_style, new_style)
puts "#{old_style} has been renamed to #{new_style}, update your SCM as necessary"
end
end
end
end
railties-3.2.16/lib/rails/tasks/statistics.rake 0000644 0001750 0001750 00000001120 12247655524 021014 0 ustar ondrej ondrej STATS_DIRECTORIES = [
%w(Controllers app/controllers),
%w(Helpers app/helpers),
%w(Models app/models),
%w(Libraries lib/),
%w(APIs app/apis),
%w(Integration\ tests test/integration),
%w(Functional\ tests test/functional),
%w(Unit\ tests test/unit)
].collect { |name, dir| [ name, "#{Rails.root}/#{dir}" ] }.select { |name, dir| File.directory?(dir) }
desc "Report code statistics (KLOCs, etc) from the application"
task :stats do
require 'rails/code_statistics'
CodeStatistics.new(*STATS_DIRECTORIES).to_s
end
railties-3.2.16/lib/rails/tasks/engine.rake 0000644 0001750 0001750 00000003467 12247655524 020107 0 ustar ondrej ondrej task "load_app" do
namespace :app do
load APP_RAKEFILE
end
task :environment => "app:environment"
if !defined?(ENGINE_PATH) || !ENGINE_PATH
ENGINE_PATH = find_engine_path(APP_RAKEFILE)
end
end
def app_task(name)
task name => [:load_app, "app:db:#{name}"]
end
namespace :db do
app_task "reset"
desc "Migrate the database (options: VERSION=x, VERBOSE=false)."
app_task "migrate"
app_task "migrate:up"
app_task "migrate:down"
app_task "migrate:redo"
app_task "migrate:reset"
desc "Display status of migrations"
app_task "migrate:status"
desc 'Create the database from config/database.yml for the current Rails.env (use db:create:all to create all dbs in the config)'
app_task "create"
app_task "create:all"
desc 'Drops the database for the current Rails.env (use db:drop:all to drop all databases)'
app_task "drop"
app_task "drop:all"
desc "Load fixtures into the current environment's database."
app_task "fixtures:load"
desc "Rolls the schema back to the previous version (specify steps w/ STEP=n)."
app_task "rollback"
desc "Create a db/schema.rb file that can be portably used against any DB supported by AR"
app_task "schema:dump"
desc "Load a schema.rb file into the database"
app_task "schema:load"
desc "Load the seed data from db/seeds.rb"
app_task "seed"
desc "Create the database, load the schema, and initialize with the seed data (use db:reset to also drop the db first)"
app_task "setup"
desc "Dump the database structure to an SQL file"
app_task "structure:dump"
desc "Retrieves the current schema version number"
app_task "version"
end
def find_engine_path(path)
return if path == "/"
if Rails::Engine.find(path)
path
else
find_engine_path(File.expand_path('..', path))
end
end
Rake.application.invoke_task(:load_app)
railties-3.2.16/lib/rails/tasks/middleware.rake 0000644 0001750 0001750 00000000352 12247655524 020745 0 ustar ondrej ondrej desc 'Prints out your Rack middleware stack'
task :middleware => :environment do
Rails.configuration.middleware.each do |middleware|
puts "use #{middleware.inspect}"
end
puts "run #{Rails.application.class.name}.routes"
end
railties-3.2.16/lib/rails/tasks/tmp.rake 0000644 0001750 0001750 00000001767 12247655524 017443 0 ustar ondrej ondrej namespace :tmp do
desc "Clear session, cache, and socket files from tmp/ (narrow w/ tmp:sessions:clear, tmp:cache:clear, tmp:sockets:clear)"
task :clear => [ "tmp:sessions:clear", "tmp:cache:clear", "tmp:sockets:clear"]
desc "Creates tmp directories for sessions, cache, sockets, and pids"
task :create do
FileUtils.mkdir_p(%w( tmp/sessions tmp/cache tmp/sockets tmp/pids tmp/cache/assets ))
end
namespace :sessions do
# desc "Clears all files in tmp/sessions"
task :clear do
FileUtils.rm(Dir['tmp/sessions/[^.]*'])
end
end
namespace :cache do
# desc "Clears all files and directories in tmp/cache"
task :clear do
FileUtils.rm_rf(Dir['tmp/cache/[^.]*'])
end
end
namespace :sockets do
# desc "Clears all files in tmp/sockets"
task :clear do
FileUtils.rm(Dir['tmp/sockets/[^.]*'])
end
end
namespace :pids do
# desc "Clears all files in tmp/pids"
task :clear do
FileUtils.rm(Dir['tmp/pids/[^.]*'])
end
end
end
railties-3.2.16/lib/rails/tasks/log.rake 0000644 0001750 0001750 00000000314 12247655524 017407 0 ustar ondrej ondrej namespace :log do
desc "Truncates all *.log files in log/ to zero bytes"
task :clear do
FileList["log/*.log"].each do |log_file|
f = File.open(log_file, "w")
f.close
end
end
end
railties-3.2.16/lib/rails/tasks/annotations.rake 0000644 0001750 0001750 00000001137 12247655524 021167 0 ustar ondrej ondrej require 'rails/source_annotation_extractor'
desc "Enumerate all annotations (use notes:optimize, :fixme, :todo for focus)"
task :notes do
SourceAnnotationExtractor.enumerate "OPTIMIZE|FIXME|TODO", :tag => true
end
namespace :notes do
["OPTIMIZE", "FIXME", "TODO"].each do |annotation|
# desc "Enumerate all #{annotation} annotations"
task annotation.downcase.intern do
SourceAnnotationExtractor.enumerate annotation
end
end
desc "Enumerate a custom annotation, specify with ANNOTATION=CUSTOM"
task :custom do
SourceAnnotationExtractor.enumerate ENV['ANNOTATION']
end
end railties-3.2.16/lib/rails/tasks/routes.rake 0000644 0001750 0001750 00000000611 12247655524 020147 0 ustar ondrej ondrej desc 'Print out all defined routes in match order, with names. Target specific controller with CONTROLLER=x.'
task :routes => :environment do
Rails.application.reload_routes!
all_routes = Rails.application.routes.routes
require 'rails/application/route_inspector'
inspector = Rails::Application::RouteInspector.new
puts inspector.format(all_routes, ENV['CONTROLLER']).join "\n"
end
railties-3.2.16/lib/rails/rack/ 0000755 0001750 0001750 00000000000 12247655524 015557 5 ustar ondrej ondrej railties-3.2.16/lib/rails/rack/debugger.rb 0000644 0001750 0001750 00000001115 12247655524 017666 0 ustar ondrej ondrej module Rails
module Rack
class Debugger
def initialize(app)
@app = app
ARGV.clear # clear ARGV so that rails server options aren't passed to IRB
require 'ruby-debug'
::Debugger.start
::Debugger.settings[:autoeval] = true if ::Debugger.respond_to?(:settings)
puts "=> Debugger enabled"
rescue LoadError
puts "You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'"
exit
end
def call(env)
@app.call(env)
end
end
end
end
railties-3.2.16/lib/rails/rack/log_tailer.rb 0000644 0001750 0001750 00000001300 12247655524 020217 0 ustar ondrej ondrej module Rails
module Rack
class LogTailer
def initialize(app, log = nil)
@app = app
path = Pathname.new(log || "#{::File.expand_path(Rails.root)}/log/#{Rails.env}.log").cleanpath
@cursor = @file = nil
if ::File.exists?(path)
@cursor = ::File.size(path)
@file = ::File.open(path, 'r')
end
end
def call(env)
response = @app.call(env)
tail!
response
end
def tail!
return unless @cursor
@file.seek @cursor
unless @file.eof?
contents = @file.read
@cursor = @file.tell
$stdout.print contents
end
end
end
end
end
railties-3.2.16/lib/rails/rack/logger.rb 0000644 0001750 0001750 00000003024 12247655524 017362 0 ustar ondrej ondrej require 'active_support/core_ext/time/conversions'
require 'active_support/core_ext/object/blank'
module Rails
module Rack
# Sets log tags, logs the request, calls the app, and flushes the logs.
class Logger < ActiveSupport::LogSubscriber
def initialize(app, taggers = nil)
@app, @taggers = app, taggers || []
end
def call(env)
request = ActionDispatch::Request.new(env)
if Rails.logger.respond_to?(:tagged)
Rails.logger.tagged(compute_tags(request)) { call_app(request, env) }
else
call_app(request, env)
end
end
protected
def call_app(request, env)
# Put some space between requests in development logs.
if Rails.env.development?
Rails.logger.info ''
Rails.logger.info ''
end
Rails.logger.info started_request_message(request)
@app.call(env)
ensure
ActiveSupport::LogSubscriber.flush_all!
end
# Started GET "/session/new" for 127.0.0.1 at 2012-09-26 14:51:42 -0700
def started_request_message(request)
'Started %s "%s" for %s at %s' % [
request.request_method,
request.filtered_path,
request.ip,
Time.now.to_default_s ]
end
def compute_tags(request)
@taggers.collect do |tag|
case tag
when Proc
tag.call(request)
when Symbol
request.send(tag)
else
tag
end
end
end
end
end
end
railties-3.2.16/lib/rails/script_rails_loader.rb 0000644 0001750 0001750 00000001772 12247655524 021217 0 ustar ondrej ondrej require 'pathname'
module Rails
module ScriptRailsLoader
RUBY = File.join(*RbConfig::CONFIG.values_at("bindir", "ruby_install_name")) + RbConfig::CONFIG["EXEEXT"]
SCRIPT_RAILS = File.join('script', 'rails')
def self.exec_script_rails!
cwd = Dir.pwd
return unless in_rails_application? || in_rails_application_subdirectory?
exec RUBY, SCRIPT_RAILS, *ARGV if in_rails_application?
Dir.chdir("..") do
# Recurse in a chdir block: if the search fails we want to be sure
# the application is generated in the original working directory.
exec_script_rails! unless cwd == Dir.pwd
end
rescue SystemCallError
# could not chdir, no problem just return
end
def self.in_rails_application?
File.exists?(SCRIPT_RAILS)
end
def self.in_rails_application_subdirectory?(path = Pathname.new(Dir.pwd))
File.exists?(File.join(path, SCRIPT_RAILS)) || !path.root? && in_rails_application_subdirectory?(path.parent)
end
end
end railties-3.2.16/lib/rails/engine.rb 0000644 0001750 0001750 00000054545 12247655524 016446 0 ustar ondrej ondrej require 'rails/railtie'
require 'active_support/core_ext/module/delegation'
require 'pathname'
require 'rbconfig'
require 'rails/engine/railties'
module Rails
# Rails::Engine allows you to wrap a specific Rails application or subset of
# functionality and share it with other applications. Since Rails 3.0, every
# Rails::Application is just an engine, which allows for simple
# feature and application sharing.
#
# Any Rails::Engine is also a Rails::Railtie, so the same
# methods (like rake_tasks and +generators+) and configuration
# options that are available in railties can also be used in engines.
#
# == Creating an Engine
#
# In Rails versions prior to 3.0, your gems automatically behaved as engines, however,
# this coupled Rails to Rubygems. Since Rails 3.0, if you want a gem to automatically
# behave as an engine, you have to specify an +Engine+ for it somewhere inside
# your plugin's +lib+ folder (similar to how we specify a +Railtie+):
#
# # lib/my_engine.rb
# module MyEngine
# class Engine < Rails::Engine
# end
# end
#
# Then ensure that this file is loaded at the top of your config/application.rb
# (or in your +Gemfile+) and it will automatically load models, controllers and helpers
# inside +app+, load routes at config/routes.rb, load locales at
# config/locales/*, and load tasks at lib/tasks/*.
#
# == Configuration
#
# Besides the +Railtie+ configuration which is shared across the application, in a
# Rails::Engine you can access autoload_paths, eager_load_paths
# and autoload_once_paths, which, differently from a Railtie, are scoped to
# the current engine.
#
# Example:
#
# class MyEngine < Rails::Engine
# # Add a load path for this specific Engine
# config.autoload_paths << File.expand_path("../lib/some/path", __FILE__)
#
# initializer "my_engine.add_middleware" do |app|
# app.middleware.use MyEngine::Middleware
# end
# end
#
# == Generators
#
# You can set up generators for engines with config.generators method:
#
# class MyEngine < Rails::Engine
# config.generators do |g|
# g.orm :active_record
# g.template_engine :erb
# g.test_framework :test_unit
# end
# end
#
# You can also set generators for an application by using config.app_generators:
#
# class MyEngine < Rails::Engine
# # note that you can also pass block to app_generators in the same way you
# # can pass it to generators method
# config.app_generators.orm :datamapper
# end
#
# == Paths
#
# Since Rails 3.0, applications and engines have more flexible path configuration (as
# opposed to the previous hardcoded path configuration). This means that you are not
# required to place your controllers at app/controllers, but in any place
# which you find convenient.
#
# For example, let's suppose you want to place your controllers in lib/controllers.
# You can set that as an option:
#
# class MyEngine < Rails::Engine
# paths["app/controllers"] = "lib/controllers"
# end
#
# You can also have your controllers loaded from both app/controllers and
# lib/controllers:
#
# class MyEngine < Rails::Engine
# paths["app/controllers"] << "lib/controllers"
# end
#
# The available paths in an engine are:
#
# class MyEngine < Rails::Engine
# paths["app"] # => ["app"]
# paths["app/controllers"] # => ["app/controllers"]
# paths["app/helpers"] # => ["app/helpers"]
# paths["app/models"] # => ["app/models"]
# paths["app/views"] # => ["app/views"]
# paths["lib"] # => ["lib"]
# paths["lib/tasks"] # => ["lib/tasks"]
# paths["config"] # => ["config"]
# paths["config/initializers"] # => ["config/initializers"]
# paths["config/locales"] # => ["config/locales"]
# paths["config/routes"] # => ["config/routes.rb"]
# end
#
# The Application class adds a couple more paths to this set. And as in your
# Application, all folders under +app+ are automatically added to the load path.
# If you have an app/observers folder for example, it will be added by default.
#
# == Endpoint
#
# An engine can be also a rack application. It can be useful if you have a rack application that
# you would like to wrap with +Engine+ and provide some of the +Engine+'s features.
#
# To do that, use the +endpoint+ method:
#
# module MyEngine
# class Engine < Rails::Engine
# endpoint MyRackApplication
# end
# end
#
# Now you can mount your engine in application's routes just like that:
#
# MyRailsApp::Application.routes.draw do
# mount MyEngine::Engine => "/engine"
# end
#
# == Middleware stack
#
# As an engine can now be a rack endpoint, it can also have a middleware
# stack. The usage is exactly the same as in Application:
#
# module MyEngine
# class Engine < Rails::Engine
# middleware.use SomeMiddleware
# end
# end
#
# == Routes
#
# If you don't specify an endpoint, routes will be used as the default
# endpoint. You can use them just like you use an application's routes:
#
# # ENGINE/config/routes.rb
# MyEngine::Engine.routes.draw do
# match "/" => "posts#index"
# end
#
# == Mount priority
#
# Note that now there can be more than one router in your application, and it's better to avoid
# passing requests through many routers. Consider this situation:
#
# MyRailsApp::Application.routes.draw do
# mount MyEngine::Engine => "/blog"
# match "/blog/omg" => "main#omg"
# end
#
# +MyEngine+ is mounted at /blog, and /blog/omg points to application's
# controller. In such a situation, requests to /blog/omg will go through +MyEngine+,
# and if there is no such route in +Engine+'s routes, it will be dispatched to main#omg.
# It's much better to swap that:
#
# MyRailsApp::Application.routes.draw do
# match "/blog/omg" => "main#omg"
# mount MyEngine::Engine => "/blog"
# end
#
# Now, +Engine+ will get only requests that were not handled by +Application+.
#
# == Engine name
#
# There are some places where an Engine's name is used:
#
# * routes: when you mount an Engine with mount(MyEngine::Engine => '/my_engine'),
# it's used as default :as option
# * some of the rake tasks are based on engine name, e.g. my_engine:install:migrations,
# my_engine:install:assets
#
# Engine name is set by default based on class name. For MyEngine::Engine it will be
# my_engine_engine. You can change it manually using the engine_name method:
#
# module MyEngine
# class Engine < Rails::Engine
# engine_name "my_engine"
# end
# end
#
# == Isolated Engine
#
# Normally when you create controllers, helpers and models inside an engine, they are treated
# as if they were created inside the application itself. This means that all helpers and
# named routes from the application will be available to your engine's controllers as well.
#
# However, sometimes you want to isolate your engine from the application, especially if your engine
# has its own router. To do that, you simply need to call +isolate_namespace+. This method requires
# you to pass a module where all your controllers, helpers and models should be nested to:
#
# module MyEngine
# class Engine < Rails::Engine
# isolate_namespace MyEngine
# end
# end
#
# With such an engine, everything that is inside the +MyEngine+ module will be isolated from
# the application.
#
# Consider such controller:
#
# module MyEngine
# class FooController < ActionController::Base
# end
# end
#
# If an engine is marked as isolated, +FooController+ has access only to helpers from +Engine+ and
# url_helpers from MyEngine::Engine.routes.
#
# The next thing that changes in isolated engines is the behavior of routes. Normally, when you namespace
# your controllers, you also need to do namespace all your routes. With an isolated engine,
# the namespace is applied by default, so you can ignore it in routes:
#
# MyEngine::Engine.routes.draw do
# resources :articles
# end
#
# The routes above will automatically point to MyEngine::ApplicationController. Furthermore, you don't
# need to use longer url helpers like my_engine_articles_path. Instead, you should simply use
# articles_path as you would do with your application.
#
# To make that behavior consistent with other parts of the framework, an isolated engine also has influence on
# ActiveModel::Naming. When you use a namespaced model, like MyEngine::Article, it will normally
# use the prefix "my_engine". In an isolated engine, the prefix will be omitted in url helpers and
# form fields for convenience.
#
# polymorphic_url(MyEngine::Article.new) # => "articles_path"
#
# form_for(MyEngine::Article.new) do
# text_field :title # =>
# end
#
# Additionally, an isolated engine will set its name according to namespace, so
# MyEngine::Engine.engine_name will be "my_engine". It will also set MyEngine.table_name_prefix
# to "my_engine_", changing the MyEngine::Article model to use the my_engine_articles table.
#
# == Using Engine's routes outside Engine
#
# Since you can now mount an engine inside application's routes, you do not have direct access to +Engine+'s
# url_helpers inside +Application+. When you mount an engine in an application's routes, a special helper is
# created to allow you to do that. Consider such a scenario:
#
# # config/routes.rb
# MyApplication::Application.routes.draw do
# mount MyEngine::Engine => "/my_engine", :as => "my_engine"
# match "/foo" => "foo#index"
# end
#
# Now, you can use the my_engine helper inside your application:
#
# class FooController < ApplicationController
# def index
# my_engine.root_url #=> /my_engine/
# end
# end
#
# There is also a main_app helper that gives you access to application's routes inside Engine:
#
# module MyEngine
# class BarController
# def index
# main_app.foo_path #=> /foo
# end
# end
# end
#
# Note that the :as option given to mount takes the engine_name as default, so most of the time
# you can simply omit it.
#
# Finally, if you want to generate a url to an engine's route using
# polymorphic_url, you also need to pass the engine helper. Let's
# say that you want to create a form pointing to one of the engine's routes.
# All you need to do is pass the helper as the first element in array with
# attributes for url:
#
# form_for([my_engine, @user])
#
# This code will use my_engine.user_path(@user) to generate the proper route.
#
# == Isolated engine's helpers
#
# Sometimes you may want to isolate engine, but use helpers that are defined for it.
# If you want to share just a few specific helpers you can add them to application's
# helpers in ApplicationController:
#
# class ApplicationController < ActionController::Base
# helper MyEngine::SharedEngineHelper
# end
#
# If you want to include all of the engine's helpers, you can use #helpers method on an engine's
# instance:
#
# class ApplicationController < ActionController::Base
# helper MyEngine::Engine.helpers
# end
#
# It will include all of the helpers from engine's directory. Take into account that this does
# not include helpers defined in controllers with helper_method or other similar solutions,
# only helpers defined in the helpers directory will be included.
#
# == Migrations & seed data
#
# Engines can have their own migrations. The default path for migrations is exactly the same
# as in application: db/migrate
#
# To use engine's migrations in application you can use rake task, which copies them to
# application's dir:
#
# rake ENGINE_NAME:install:migrations
#
# Note that some of the migrations may be skipped if a migration with the same name already exists
# in application. In such a situation you must decide whether to leave that migration or rename the
# migration in the application and rerun copying migrations.
#
# If your engine has migrations, you may also want to prepare data for the database in
# the seeds.rb file. You can load that data using the load_seed method, e.g.
#
# MyEngine::Engine.load_seed
#
# == Loading priority
#
# In order to change engine's priority you can use config.railties_order in main application.
# It will affect the priority of loading views, helpers, assets and all the other files
# related to engine or application.
#
# Example:
#
# # load Blog::Engine with highest priority, followed by application and other railties
# config.railties_order = [Blog::Engine, :main_app, :all]
#
class Engine < Railtie
autoload :Configuration, "rails/engine/configuration"
autoload :Railties, "rails/engine/railties"
def load_generators(app=self)
initialize_generators
railties.all { |r| r.load_generators(app) }
Rails::Generators.configure!(app.config.generators)
super
self
end
class << self
attr_accessor :called_from, :isolated
alias :isolated? :isolated
alias :engine_name :railtie_name
def inherited(base)
unless base.abstract_railtie?
base.called_from = begin
# Remove the line number from backtraces making sure we don't leave anything behind
call_stack = caller.map { |p| p.sub(/:\d+.*/, '') }
File.dirname(call_stack.detect { |p| p !~ %r[railties[\w.-]*/lib/rails|rack[\w.-]*/lib/rack] })
end
end
super
end
def endpoint(endpoint = nil)
@endpoint ||= nil
@endpoint = endpoint if endpoint
@endpoint
end
def isolate_namespace(mod)
engine_name(generate_railtie_name(mod))
self.routes.default_scope = { :module => ActiveSupport::Inflector.underscore(mod.name) }
self.isolated = true
unless mod.respond_to?(:railtie_namespace)
name, railtie = engine_name, self
mod.singleton_class.instance_eval do
define_method(:railtie_namespace) { railtie }
unless mod.respond_to?(:table_name_prefix)
define_method(:table_name_prefix) { "#{name}_" }
end
unless mod.respond_to?(:use_relative_model_naming?)
class_eval "def use_relative_model_naming?; true; end", __FILE__, __LINE__
end
unless mod.respond_to?(:railtie_helpers_paths)
define_method(:railtie_helpers_paths) { railtie.helpers_paths }
end
unless mod.respond_to?(:railtie_routes_url_helpers)
define_method(:railtie_routes_url_helpers) { railtie.routes_url_helpers }
end
end
end
end
# Finds engine with given path
def find(path)
expanded_path = File.expand_path path.to_s
Rails::Engine::Railties.engines.find { |engine|
File.expand_path(engine.root.to_s) == expanded_path
}
end
end
delegate :middleware, :root, :paths, :to => :config
delegate :engine_name, :isolated?, :to => "self.class"
def load_tasks(app=self)
railties.all { |r| r.load_tasks(app) }
super
paths["lib/tasks"].existent.sort.each { |ext| load(ext) }
end
def load_console(app=self)
railties.all { |r| r.load_console(app) }
super
end
def load_runner(app=self)
railties.all { |r| r.load_runner(app) }
super
end
def eager_load!
railties.all(&:eager_load!)
config.eager_load_paths.each do |load_path|
matcher = /\A#{Regexp.escape(load_path)}\/(.*)\.rb\Z/
Dir.glob("#{load_path}/**/*.rb").sort.each do |file|
require_dependency file.sub(matcher, '\1')
end
end
end
def railties
@railties ||= self.class::Railties.new(config)
end
def helpers
@helpers ||= begin
helpers = Module.new
all = ActionController::Base.all_helpers_from_path(helpers_paths)
ActionController::Base.modules_for_helpers(all).each do |mod|
helpers.send(:include, mod)
end
helpers
end
end
def helpers_paths
paths["app/helpers"].existent
end
def routes_url_helpers
routes.url_helpers
end
def app
@app ||= begin
config.middleware = config.middleware.merge_into(default_middleware_stack)
config.middleware.build(endpoint)
end
end
def endpoint
self.class.endpoint || routes
end
def call(env)
app.call(env.merge!(env_config))
end
def env_config
@env_config ||= {
'action_dispatch.routes' => routes
}
end
def routes
@routes ||= ActionDispatch::Routing::RouteSet.new
@routes.append(&Proc.new) if block_given?
@routes
end
def ordered_railties
railties.all + [self]
end
def initializers
initializers = []
ordered_railties.each do |r|
if r == self
initializers += super
else
initializers += r.initializers
end
end
initializers
end
def config
@config ||= Engine::Configuration.new(find_root_with_flag("lib"))
end
# Load data from db/seeds.rb file. It can be used in to load engines'
# seeds, e.g.:
#
# Blog::Engine.load_seed
def load_seed
seed_file = paths["db/seeds"].existent.first
load(seed_file) if seed_file
end
# Add configured load paths to ruby load paths and remove duplicates.
initializer :set_load_path, :before => :bootstrap_hook do
_all_load_paths.reverse_each do |path|
$LOAD_PATH.unshift(path) if File.directory?(path)
end
$LOAD_PATH.uniq!
end
# Set the paths from which Rails will automatically load source files,
# and the load_once paths.
#
# This needs to be an initializer, since it needs to run once
# per engine and get the engine as a block parameter
initializer :set_autoload_paths, :before => :bootstrap_hook do |app|
ActiveSupport::Dependencies.autoload_paths.unshift(*_all_autoload_paths)
ActiveSupport::Dependencies.autoload_once_paths.unshift(*_all_autoload_once_paths)
# Freeze so future modifications will fail rather than do nothing mysteriously
config.autoload_paths.freeze
config.eager_load_paths.freeze
config.autoload_once_paths.freeze
end
initializer :add_routing_paths do |app|
paths = self.paths["config/routes"].existent
if routes? || paths.any?
app.routes_reloader.paths.unshift(*paths)
app.routes_reloader.route_sets << routes
end
end
# I18n load paths are a special case since the ones added
# later have higher priority.
initializer :add_locales do
config.i18n.railties_load_path.concat(paths["config/locales"].existent)
end
initializer :add_view_paths do
views = paths["app/views"].existent
unless views.empty?
ActiveSupport.on_load(:action_controller){ prepend_view_path(views) }
ActiveSupport.on_load(:action_mailer){ prepend_view_path(views) }
end
end
initializer :load_environment_config, :before => :load_environment_hook, :group => :all do
environment = paths["config/environments"].existent.first
require environment if environment
end
initializer :append_assets_path, :group => :all do |app|
app.config.assets.paths.unshift(*paths["vendor/assets"].existent_directories)
app.config.assets.paths.unshift(*paths["lib/assets"].existent_directories)
app.config.assets.paths.unshift(*paths["app/assets"].existent_directories)
end
initializer :prepend_helpers_path do |app|
if !isolated? || (app == self)
app.config.helpers_paths.unshift(*paths["app/helpers"].existent)
end
end
initializer :load_config_initializers do
config.paths["config/initializers"].existent.sort.each do |initializer|
load(initializer)
end
end
initializer :engines_blank_point do
# We need this initializer so all extra initializers added in engines are
# consistently executed after all the initializers above across all engines.
end
rake_tasks do
next if self.is_a?(Rails::Application)
next unless has_migrations?
namespace railtie_name do
namespace :install do
desc "Copy migrations from #{railtie_name} to application"
task :migrations do
ENV["FROM"] = railtie_name
Rake::Task["railties:install:migrations"].invoke
end
end
end
end
protected
def initialize_generators
require "rails/generators"
end
def routes?
defined?(@routes)
end
def has_migrations?
paths["db/migrate"].existent.any?
end
def find_root_with_flag(flag, default=nil)
root_path = self.class.called_from
while root_path && File.directory?(root_path) && !File.exist?("#{root_path}/#{flag}")
parent = File.dirname(root_path)
root_path = parent != root_path && parent
end
root = File.exist?("#{root_path}/#{flag}") ? root_path : default
raise "Could not find root path for #{self}" unless root
RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ ?
Pathname.new(root).expand_path : Pathname.new(root).realpath
end
def default_middleware_stack
ActionDispatch::MiddlewareStack.new
end
def _all_autoload_once_paths
config.autoload_once_paths
end
def _all_autoload_paths
@_all_autoload_paths ||= (config.autoload_paths + config.eager_load_paths + config.autoload_once_paths).uniq
end
def _all_load_paths
@_all_load_paths ||= (config.paths.load_paths + _all_autoload_paths).uniq
end
end
end
railties-3.2.16/lib/rails/generators/ 0000755 0001750 0001750 00000000000 12247655524 017010 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/actions.rb 0000644 0001750 0001750 00000024107 12247655524 021001 0 ustar ondrej ondrej require 'open-uri'
require 'rbconfig'
require 'active_support/core_ext/array/wrap'
module Rails
module Generators
module Actions
# Install a plugin. You must provide either a Subversion url or Git url.
#
# For a Git-hosted plugin, you can specify a branch and
# whether it should be added as a submodule instead of cloned.
#
# For a Subversion-hosted plugin you can specify a revision.
#
# ==== Examples
#
# plugin 'restful-authentication', :git => 'git://github.com/technoweenie/restful-authentication.git'
# plugin 'restful-authentication', :git => 'git://github.com/technoweenie/restful-authentication.git', :branch => 'stable'
# plugin 'restful-authentication', :git => 'git://github.com/technoweenie/restful-authentication.git', :submodule => true
# plugin 'restful-authentication', :svn => 'svn://svnhub.com/technoweenie/restful-authentication/trunk'
# plugin 'restful-authentication', :svn => 'svn://svnhub.com/technoweenie/restful-authentication/trunk', :revision => 1234
#
def plugin(name, options)
log :plugin, name
if options[:git] && options[:submodule]
options[:git] = "-b #{options[:branch]} #{options[:git]}" if options[:branch]
in_root do
run "git submodule add #{options[:git]} vendor/plugins/#{name}", :verbose => false
end
elsif options[:git] || options[:svn]
options[:git] = "-b #{options[:branch]} #{options[:git]}" if options[:branch]
options[:svn] = "-r #{options[:revision]} #{options[:svn]}" if options[:revision]
in_root do
run_ruby_script "script/rails plugin install #{options[:svn] || options[:git]}", :verbose => false
end
else
log "! no git or svn provided for #{name}. Skipping..."
end
end
# Adds an entry into Gemfile for the supplied gem. If env
# is specified, add the gem to the given environment.
#
# ==== Example
#
# gem "rspec", :group => :test
# gem "technoweenie-restful-authentication", :lib => "restful-authentication", :source => "http://gems.github.com/"
# gem "rails", "3.0", :git => "git://github.com/rails/rails"
#
def gem(*args)
options = args.extract_options!
name, version = args
# Set the message to be shown in logs. Uses the git repo if one is given,
# otherwise use name (version).
parts, message = [ name.inspect ], name
if version ||= options.delete(:version)
parts << version.inspect
message << " (#{version})"
end
message = options[:git] if options[:git]
log :gemfile, message
options.each do |option, value|
parts << ":#{option} => #{value.inspect}"
end
in_root do
str = "gem #{parts.join(", ")}"
str = " " + str if @in_group
str = "\n" + str
append_file "Gemfile", str, :verbose => false
end
end
# Wraps gem entries inside a group.
#
# ==== Example
#
# gem_group :development, :test do
# gem "rspec-rails"
# end
#
def gem_group(*names, &block)
name = names.map(&:inspect).join(", ")
log :gemfile, "group #{name}"
in_root do
append_file "Gemfile", "\ngroup #{name} do", :force => true
@in_group = true
instance_eval(&block)
@in_group = false
append_file "Gemfile", "\nend\n", :force => true
end
end
# Add the given source to Gemfile
#
# ==== Example
#
# add_source "http://gems.github.com/"
def add_source(source, options={})
log :source, source
in_root do
prepend_file "Gemfile", "source #{source.inspect}\n", :verbose => false
end
end
# Adds a line inside the Application class for config/application.rb.
#
# If options :env is specified, the line is appended to the corresponding
# file in config/environments.
#
def environment(data=nil, options={}, &block)
sentinel = /class [a-z_:]+ < Rails::Application/i
env_file_sentinel = /::Application\.configure do/
data = block.call if !data && block_given?
in_root do
if options[:env].nil?
inject_into_file 'config/application.rb', "\n #{data}", :after => sentinel, :verbose => false
else
Array.wrap(options[:env]).each do |env|
inject_into_file "config/environments/#{env}.rb", "\n #{data}", :after => env_file_sentinel, :verbose => false
end
end
end
end
alias :application :environment
# Run a command in git.
#
# ==== Examples
#
# git :init
# git :add => "this.file that.rb"
# git :add => "onefile.rb", :rm => "badfile.cxx"
#
def git(commands={})
if commands.is_a?(Symbol)
run "git #{commands}"
else
commands.each do |cmd, options|
run "git #{cmd} #{options}"
end
end
end
# Create a new file in the vendor/ directory. Code can be specified
# in a block or a data string can be given.
#
# ==== Examples
#
# vendor("sekrit.rb") do
# sekrit_salt = "#{Time.now}--#{3.years.ago}--#{rand}--"
# "salt = '#{sekrit_salt}'"
# end
#
# vendor("foreign.rb", "# Foreign code is fun")
#
def vendor(filename, data=nil, &block)
log :vendor, filename
create_file("vendor/#{filename}", data, :verbose => false, &block)
end
# Create a new file in the lib/ directory. Code can be specified
# in a block or a data string can be given.
#
# ==== Examples
#
# lib("crypto.rb") do
# "crypted_special_value = '#{rand}--#{Time.now}--#{rand(1337)}--'"
# end
#
# lib("foreign.rb", "# Foreign code is fun")
#
def lib(filename, data=nil, &block)
log :lib, filename
create_file("lib/#{filename}", data, :verbose => false, &block)
end
# Create a new Rakefile with the provided code (either in a block or a string).
#
# ==== Examples
#
# rakefile("bootstrap.rake") do
# project = ask("What is the UNIX name of your project?")
#
# <<-TASK
# namespace :#{project} do
# task :bootstrap do
# puts "i like boots!"
# end
# end
# TASK
# end
#
# rakefile("seed.rake", "puts 'im plantin ur seedz'")
#
def rakefile(filename, data=nil, &block)
log :rakefile, filename
create_file("lib/tasks/#{filename}", data, :verbose => false, &block)
end
# Create a new initializer with the provided code (either in a block or a string).
#
# ==== Examples
#
# initializer("globals.rb") do
# data = ""
#
# ['MY_WORK', 'ADMINS', 'BEST_COMPANY_EVAR'].each do |const|
# data << "#{const} = :entp\n"
# end
#
# data
# end
#
# initializer("api.rb", "API_KEY = '123456'")
#
def initializer(filename, data=nil, &block)
log :initializer, filename
create_file("config/initializers/#{filename}", data, :verbose => false, &block)
end
# Generate something using a generator from Rails or a plugin.
# The second parameter is the argument string that is passed to
# the generator or an Array that is joined.
#
# ==== Example
#
# generate(:authenticated, "user session")
#
def generate(what, *args)
log :generate, what
argument = args.map {|arg| arg.to_s }.flatten.join(" ")
in_root { run_ruby_script("script/rails generate #{what} #{argument}", :verbose => false) }
end
# Runs the supplied rake task
#
# ==== Example
#
# rake("db:migrate")
# rake("db:migrate", :env => "production")
# rake("gems:install", :sudo => true)
#
def rake(command, options={})
log :rake, command
env = options[:env] || ENV["RAILS_ENV"] || 'development'
sudo = options[:sudo] && RbConfig::CONFIG['host_os'] !~ /mswin|mingw/ ? 'sudo ' : ''
in_root { run("#{sudo}#{extify(:rake)} #{command} RAILS_ENV=#{env}", :verbose => false) }
end
# Just run the capify command in root
#
# ==== Example
#
# capify!
#
def capify!
log :capify, ""
in_root { run("#{extify(:capify)} .", :verbose => false) }
end
# Make an entry in Rails routing file config/routes.rb
#
# === Example
#
# route "root :to => 'welcome'"
#
def route(routing_code)
log :route, routing_code
sentinel = /\.routes\.draw do(?:\s*\|map\|)?\s*$/
in_root do
inject_into_file 'config/routes.rb', "\n #{routing_code}\n", { :after => sentinel, :verbose => false }
end
end
# Reads the given file at the source root and prints it in the console.
#
# === Example
#
# readme "README"
#
def readme(path)
log File.read(find_in_source_paths(path))
end
protected
# Define log for backwards compatibility. If just one argument is sent,
# invoke say, otherwise invoke say_status. Differently from say and
# similarly to say_status, this method respects the quiet? option given.
#
def log(*args)
if args.size == 1
say args.first.to_s unless options.quiet?
else
args << (self.behavior == :invoke ? :green : :red)
say_status(*args)
end
end
# Add an extension to the given name based on the platform.
#
def extify(name)
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
"#{name}.bat"
else
name
end
end
end
end
end
railties-3.2.16/lib/rails/generators/test_unit/ 0000755 0001750 0001750 00000000000 12247655524 021026 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/test_unit/plugin/ 0000755 0001750 0001750 00000000000 12247655524 022324 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/test_unit/plugin/plugin_generator.rb 0000644 0001750 0001750 00000000360 12247655524 026214 0 ustar ondrej ondrej require 'rails/generators/test_unit'
module TestUnit
module Generators
class PluginGenerator < Base
check_class_collision :suffix => "Test"
def create_test_files
directory '.', 'test'
end
end
end
end
railties-3.2.16/lib/rails/generators/test_unit/plugin/templates/ 0000755 0001750 0001750 00000000000 12247655524 024322 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/test_unit/plugin/templates/%file_name%_test.rb.tt 0000644 0001750 0001750 00000000203 12247655524 030360 0 ustar ondrej ondrej require 'test_helper'
class <%= class_name %>Test < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
railties-3.2.16/lib/rails/generators/test_unit/plugin/templates/test_helper.rb 0000644 0001750 0001750 00000000100 12247655524 027154 0 ustar ondrej ondrej require 'rubygems'
require 'test/unit'
require 'active_support'
railties-3.2.16/lib/rails/generators/test_unit/scaffold/ 0000755 0001750 0001750 00000000000 12247655524 022607 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb 0000644 0001750 0001750 00000002012 12247655524 026756 0 ustar ondrej ondrej require 'rails/generators/test_unit'
require 'rails/generators/resource_helpers'
module TestUnit
module Generators
class ScaffoldGenerator < Base
include Rails::Generators::ResourceHelpers
check_class_collision :suffix => "ControllerTest"
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
def create_test_files
template 'functional_test.rb',
File.join('test/functional', controller_class_path, "#{controller_file_name}_controller_test.rb")
end
private
def resource_attributes
key_value singular_table_name, "{ #{attributes_hash} }"
end
def attributes_hash
return if accessible_attributes.empty?
accessible_attributes.map do |a|
name = a.name
key_value name, "@#{singular_table_name}.#{name}"
end.sort.join(', ')
end
def accessible_attributes
attributes.reject(&:reference?)
end
end
end
end
railties-3.2.16/lib/rails/generators/test_unit/scaffold/templates/ 0000755 0001750 0001750 00000000000 12247655524 024605 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb 0000644 0001750 0001750 00000002662 12247655524 030341 0 ustar ondrej ondrej require 'test_helper'
<% module_namespacing do -%>
class <%= controller_class_name %>ControllerTest < ActionController::TestCase
setup do
@<%= singular_table_name %> = <%= table_name %>(:one)
end
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:<%= table_name %>)
end
test "should get new" do
get :new
assert_response :success
end
test "should create <%= singular_table_name %>" do
assert_difference('<%= class_name %>.count') do
post :create, <%= resource_attributes %>
end
assert_redirected_to <%= singular_table_name %>_path(assigns(:<%= singular_table_name %>))
end
test "should show <%= singular_table_name %>" do
get :show, <%= key_value :id, "@#{singular_table_name}" %>
assert_response :success
end
test "should get edit" do
get :edit, <%= key_value :id, "@#{singular_table_name}" %>
assert_response :success
end
test "should update <%= singular_table_name %>" do
put :update, <%= key_value :id, "@#{singular_table_name}" %>, <%= resource_attributes %>
assert_redirected_to <%= singular_table_name %>_path(assigns(:<%= singular_table_name %>))
end
test "should destroy <%= singular_table_name %>" do
assert_difference('<%= class_name %>.count', -1) do
delete :destroy, <%= key_value :id, "@#{singular_table_name}" %>
end
assert_redirected_to <%= index_helper %>_path
end
end
<% end -%>
railties-3.2.16/lib/rails/generators/test_unit/mailer/ 0000755 0001750 0001750 00000000000 12247655524 022277 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/test_unit/mailer/templates/ 0000755 0001750 0001750 00000000000 12247655524 024275 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/test_unit/mailer/templates/functional_test.rb 0000644 0001750 0001750 00000001017 12247655524 030022 0 ustar ondrej ondrej require 'test_helper'
<% module_namespacing do -%>
class <%= class_name %>Test < ActionMailer::TestCase
<% actions.each do |action| -%>
test "<%= action %>" do
mail = <%= class_name %>.<%= action %>
assert_equal <%= action.to_s.humanize.inspect %>, mail.subject
assert_equal ["to@example.org"], mail.to
assert_equal ["from@example.com"], mail.from
assert_match "Hi", mail.body.encoded
end
<% end -%>
<% if actions.blank? -%>
# test "the truth" do
# assert true
# end
<% end -%>
end
<% end -%>
railties-3.2.16/lib/rails/generators/test_unit/mailer/mailer_generator.rb 0000644 0001750 0001750 00000000617 12247655524 026147 0 ustar ondrej ondrej require 'rails/generators/test_unit'
module TestUnit
module Generators
class MailerGenerator < Base
argument :actions, :type => :array, :default => [], :banner => "method method"
check_class_collision :suffix => "Test"
def create_test_files
template "functional_test.rb", File.join('test/functional', class_path, "#{file_name}_test.rb")
end
end
end
end
railties-3.2.16/lib/rails/generators/test_unit/integration/ 0000755 0001750 0001750 00000000000 12247655524 023351 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/test_unit/integration/templates/ 0000755 0001750 0001750 00000000000 12247655524 025347 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/test_unit/integration/templates/integration_test.rb 0000644 0001750 0001750 00000000213 12247655524 031252 0 ustar ondrej ondrej require 'test_helper'
class <%= class_name %>Test < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end
railties-3.2.16/lib/rails/generators/test_unit/integration/integration_generator.rb 0000644 0001750 0001750 00000000501 12247655524 030263 0 ustar ondrej ondrej require 'rails/generators/test_unit'
module TestUnit
module Generators
class IntegrationGenerator < Base
check_class_collision :suffix => "Test"
def create_test_files
template 'integration_test.rb', File.join('test/integration', class_path, "#{file_name}_test.rb")
end
end
end
end
railties-3.2.16/lib/rails/generators/test_unit/helper/ 0000755 0001750 0001750 00000000000 12247655524 022305 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/test_unit/helper/templates/ 0000755 0001750 0001750 00000000000 12247655524 024303 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/test_unit/helper/templates/helper_test.rb 0000644 0001750 0001750 00000000174 12247655524 027150 0 ustar ondrej ondrej require 'test_helper'
<% module_namespacing do -%>
class <%= class_name %>HelperTest < ActionView::TestCase
end
<% end -%>
railties-3.2.16/lib/rails/generators/test_unit/helper/helper_generator.rb 0000644 0001750 0001750 00000000507 12247655524 026161 0 ustar ondrej ondrej require 'rails/generators/test_unit'
module TestUnit
module Generators
class HelperGenerator < Base
check_class_collision :suffix => "HelperTest"
def create_helper_files
template 'helper_test.rb', File.join('test/unit/helpers', class_path, "#{file_name}_helper_test.rb")
end
end
end
end
railties-3.2.16/lib/rails/generators/test_unit/performance/ 0000755 0001750 0001750 00000000000 12247655524 023327 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/test_unit/performance/performance_generator.rb 0000644 0001750 0001750 00000000501 12247655524 030217 0 ustar ondrej ondrej require 'rails/generators/test_unit'
module TestUnit
module Generators
class PerformanceGenerator < Base
check_class_collision :suffix => "Test"
def create_test_files
template 'performance_test.rb', File.join('test/performance', class_path, "#{file_name}_test.rb")
end
end
end
end
railties-3.2.16/lib/rails/generators/test_unit/performance/templates/ 0000755 0001750 0001750 00000000000 12247655524 025325 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/test_unit/performance/templates/performance_test.rb 0000644 0001750 0001750 00000000573 12247655524 031217 0 ustar ondrej ondrej require 'test_helper'
require 'rails/performance_test_help'
class <%= class_name %>Test < ActionDispatch::PerformanceTest
# Refer to the documentation for all available options
# self.profile_options = { :runs => 5, :metrics => [:wall_time, :memory]
# :output => 'tmp/performance', :formats => [:flat] }
def test_homepage
get '/'
end
end
railties-3.2.16/lib/rails/generators/test_unit/controller/ 0000755 0001750 0001750 00000000000 12247655524 023211 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/test_unit/controller/templates/ 0000755 0001750 0001750 00000000000 12247655524 025207 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/test_unit/controller/templates/functional_test.rb 0000644 0001750 0001750 00000000563 12247655524 030741 0 ustar ondrej ondrej require 'test_helper'
<% module_namespacing do -%>
class <%= class_name %>ControllerTest < ActionController::TestCase
<% if actions.empty? -%>
# test "the truth" do
# assert true
# end
<% else -%>
<% actions.each do |action| -%>
test "should get <%= action %>" do
get :<%= action %>
assert_response :success
end
<% end -%>
<% end -%>
end
<% end -%>
railties-3.2.16/lib/rails/generators/test_unit/controller/controller_generator.rb 0000644 0001750 0001750 00000000671 12247655524 027773 0 ustar ondrej ondrej require 'rails/generators/test_unit'
module TestUnit
module Generators
class ControllerGenerator < Base
argument :actions, :type => :array, :default => [], :banner => "action action"
check_class_collision :suffix => "ControllerTest"
def create_test_files
template 'functional_test.rb',
File.join('test/functional', class_path, "#{file_name}_controller_test.rb")
end
end
end
end
railties-3.2.16/lib/rails/generators/test_unit/observer/ 0000755 0001750 0001750 00000000000 12247655524 022655 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/test_unit/observer/templates/ 0000755 0001750 0001750 00000000000 12247655524 024653 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/test_unit/observer/templates/unit_test.rb 0000644 0001750 0001750 00000000263 12247655524 027217 0 ustar ondrej ondrej require 'test_helper'
<% module_namespacing do -%>
class <%= class_name %>ObserverTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
<% end -%>
railties-3.2.16/lib/rails/generators/test_unit/observer/observer_generator.rb 0000644 0001750 0001750 00000000502 12247655524 027074 0 ustar ondrej ondrej require 'rails/generators/test_unit'
module TestUnit
module Generators
class ObserverGenerator < Base
check_class_collision :suffix => "ObserverTest"
def create_test_files
template 'unit_test.rb', File.join('test/unit', class_path, "#{file_name}_observer_test.rb")
end
end
end
end
railties-3.2.16/lib/rails/generators/test_unit/model/ 0000755 0001750 0001750 00000000000 12247655524 022126 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/test_unit/model/model_generator.rb 0000644 0001750 0001750 00000001737 12247655524 025631 0 ustar ondrej ondrej require 'rails/generators/test_unit'
module TestUnit
module Generators
class ModelGenerator < Base
RESERVED_YAML_KEYWORDS = %w(y yes n no true false on off null)
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
class_option :fixture, :type => :boolean
check_class_collision :suffix => "Test"
def create_test_file
template 'unit_test.rb', File.join('test/unit', class_path, "#{file_name}_test.rb")
end
hook_for :fixture_replacement
def create_fixture_file
if options[:fixture] && options[:fixture_replacement].nil?
template 'fixtures.yml', File.join('test/fixtures', class_path, "#{plural_file_name}.yml")
end
end
private
def yaml_key_value(key, value)
if RESERVED_YAML_KEYWORDS.include?(key.downcase)
"'#{key}': #{value}"
else
"#{key}: #{value}"
end
end
end
end
end
railties-3.2.16/lib/rails/generators/test_unit/model/templates/ 0000755 0001750 0001750 00000000000 12247655524 024124 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/test_unit/model/templates/fixtures.yml 0000644 0001750 0001750 00000001173 12247655524 026522 0 ustar ondrej ondrej # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
<% unless attributes.empty? -%>
one:
<% attributes.each do |attribute| -%>
<%= yaml_key_value(attribute.name, attribute.default) %>
<% end -%>
two:
<% attributes.each do |attribute| -%>
<%= yaml_key_value(attribute.name, attribute.default) %>
<% end -%>
<% else -%>
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
<% end -%>
railties-3.2.16/lib/rails/generators/test_unit/model/templates/unit_test.rb 0000644 0001750 0001750 00000000253 12247655524 026467 0 ustar ondrej ondrej require 'test_helper'
<% module_namespacing do -%>
class <%= class_name %>Test < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
<% end -%>
railties-3.2.16/lib/rails/generators/erb/ 0000755 0001750 0001750 00000000000 12247655524 017560 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/erb/scaffold/ 0000755 0001750 0001750 00000000000 12247655524 021341 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/erb/scaffold/scaffold_generator.rb 0000644 0001750 0001750 00000001331 12247655524 025513 0 ustar ondrej ondrej require 'rails/generators/erb'
require 'rails/generators/resource_helpers'
module Erb
module Generators
class ScaffoldGenerator < Base
include Rails::Generators::ResourceHelpers
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
def create_root_folder
empty_directory File.join("app/views", controller_file_path)
end
def copy_view_files
available_views.each do |view|
filename = filename_with_extensions(view)
template filename, File.join("app/views", controller_file_path, filename)
end
end
protected
def available_views
%w(index edit show new _form)
end
end
end
end
railties-3.2.16/lib/rails/generators/erb/scaffold/templates/ 0000755 0001750 0001750 00000000000 12247655524 023337 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/erb/scaffold/templates/show.html.erb 0000644 0001750 0001750 00000000516 12247655524 025756 0 ustar ondrej ondrej
<%% end %>
railties-3.2.16/lib/rails/generators/erb/scaffold/templates/index.html.erb 0000644 0001750 0001750 00000001523 12247655524 026104 0 ustar ondrej ondrej
Listing <%= plural_table_name %>
<% attributes.each do |attribute| -%>
<%= attribute.human_name %>
<% end -%>
<%% @<%= plural_table_name %>.each do |<%= singular_table_name %>| %>
<%%= link_to 'New <%= human_name %>', new_<%= singular_table_name %>_path %>
railties-3.2.16/lib/rails/generators/erb/mailer/ 0000755 0001750 0001750 00000000000 12247655524 021031 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/erb/mailer/templates/ 0000755 0001750 0001750 00000000000 12247655524 023027 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/erb/mailer/templates/view.text.erb 0000644 0001750 0001750 00000000127 12247655524 025456 0 ustar ondrej ondrej <%= class_name %>#<%= @action %>
<%%= @greeting %>, find me in app/views/<%= @path %>
railties-3.2.16/lib/rails/generators/erb/mailer/mailer_generator.rb 0000644 0001750 0001750 00000000333 12247655524 024674 0 ustar ondrej ondrej require 'rails/generators/erb/controller/controller_generator'
module Erb
module Generators
class MailerGenerator < ControllerGenerator
protected
def format
:text
end
end
end
end
railties-3.2.16/lib/rails/generators/erb/controller/ 0000755 0001750 0001750 00000000000 12247655524 021743 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/erb/controller/templates/ 0000755 0001750 0001750 00000000000 12247655524 023741 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/erb/controller/templates/view.html.erb 0000644 0001750 0001750 00000000111 12247655524 026341 0 ustar ondrej ondrej
<%= class_name %>#<%= @action %>
Find me in <%= @path %>
railties-3.2.16/lib/rails/generators/erb/controller/controller_generator.rb 0000644 0001750 0001750 00000001040 12247655524 026514 0 ustar ondrej ondrej require 'rails/generators/erb'
module Erb
module Generators
class ControllerGenerator < Base
argument :actions, :type => :array, :default => [], :banner => "action action"
def copy_view_files
base_path = File.join("app/views", class_path, file_name)
empty_directory base_path
actions.each do |action|
@action = action
@path = File.join(base_path, filename_with_extensions(action))
template filename_with_extensions(:view), @path
end
end
end
end
end
railties-3.2.16/lib/rails/generators/migration.rb 0000644 0001750 0001750 00000004702 12247655524 021331 0 ustar ondrej ondrej module Rails
module Generators
# Holds common methods for migrations. It assumes that migrations has the
# [0-9]*_name format and can be used by another frameworks (like Sequel)
# just by implementing the next migration version method.
#
module Migration
attr_reader :migration_number, :migration_file_name, :migration_class_name
def self.included(base) #:nodoc:
base.extend ClassMethods
end
module ClassMethods
def migration_lookup_at(dirname) #:nodoc:
Dir.glob("#{dirname}/[0-9]*_*.rb")
end
def migration_exists?(dirname, file_name) #:nodoc:
migration_lookup_at(dirname).grep(/\d+_#{file_name}.rb$/).first
end
def current_migration_number(dirname) #:nodoc:
migration_lookup_at(dirname).collect do |file|
File.basename(file).split("_").first.to_i
end.max.to_i
end
def next_migration_number(dirname) #:nodoc:
raise NotImplementedError
end
end
# Creates a migration template at the given destination. The difference
# to the default template method is that the migration version is appended
# to the destination file name.
#
# The migration version, migration file name, migration class name are
# available as instance variables in the template to be rendered.
#
# ==== Examples
#
# migration_template "migration.rb", "db/migrate/add_foo_to_bar.rb"
#
def migration_template(source, destination=nil, config={})
destination = File.expand_path(destination || source, self.destination_root)
migration_dir = File.dirname(destination)
@migration_number = self.class.next_migration_number(migration_dir)
@migration_file_name = File.basename(destination).sub(/\.rb$/, '')
@migration_class_name = @migration_file_name.camelize
destination = self.class.migration_exists?(migration_dir, @migration_file_name)
if !(destination && options[:skip]) && behavior == :invoke
if destination && options.force?
remove_file(destination)
elsif destination
raise Error, "Another migration is already named #{@migration_file_name}: #{destination}"
end
destination = File.join(migration_dir, "#{@migration_number}_#{@migration_file_name}.rb")
end
template(source, destination, config)
end
end
end
end
railties-3.2.16/lib/rails/generators/test_case.rb 0000644 0001750 0001750 00000022345 12247655524 021315 0 ustar ondrej ondrej require 'active_support/core_ext/class/attribute'
require 'active_support/core_ext/module/delegation'
require 'active_support/core_ext/hash/reverse_merge'
require 'active_support/core_ext/kernel/reporting'
require 'rails/generators'
require 'fileutils'
module Rails
module Generators
# Disable color in output. Easier to debug.
no_color!
# This class provides a TestCase for testing generators. To setup, you need
# just to configure the destination and set which generator is being tested:
#
# class AppGeneratorTest < Rails::Generators::TestCase
# tests AppGenerator
# destination File.expand_path("../tmp", File.dirname(__FILE__))
# end
#
# If you want to ensure your destination root is clean before running each test,
# you can set a setup callback:
#
# class AppGeneratorTest < Rails::Generators::TestCase
# tests AppGenerator
# destination File.expand_path("../tmp", File.dirname(__FILE__))
# setup :prepare_destination
# end
#
class TestCase < ActiveSupport::TestCase
include FileUtils
class_attribute :destination_root, :current_path, :generator_class, :default_arguments
delegate :destination_root, :current_path, :generator_class, :default_arguments, :to => :'self.class'
# Generators frequently change the current path using +FileUtils.cd+.
# So we need to store the path at file load and revert back to it after each test.
self.current_path = File.expand_path(Dir.pwd)
self.default_arguments = []
setup :destination_root_is_set?, :ensure_current_path
teardown :ensure_current_path
# Sets which generator should be tested:
#
# tests AppGenerator
#
def self.tests(klass)
self.generator_class = klass
end
# Sets default arguments on generator invocation. This can be overwritten when
# invoking it.
#
# arguments %w(app_name --skip-active-record)
#
def self.arguments(array)
self.default_arguments = array
end
# Sets the destination of generator files:
#
# destination File.expand_path("../tmp", File.dirname(__FILE__))
#
def self.destination(path)
self.destination_root = path
end
# Asserts a given file exists. You need to supply an absolute path or a path relative
# to the configured destination:
#
# assert_file "config/environment.rb"
#
# You can also give extra arguments. If the argument is a regexp, it will check if the
# regular expression matches the given file content. If it's a string, it compares the
# file with the given string:
#
# assert_file "config/environment.rb", /initialize/
#
# Finally, when a block is given, it yields the file content:
#
# assert_file "app/controller/products_controller.rb" do |controller|
# assert_instance_method :index, content do |index|
# assert_match(/Product\.all/, index)
# end
# end
#
def assert_file(relative, *contents)
absolute = File.expand_path(relative, destination_root)
assert File.exists?(absolute), "Expected file #{relative.inspect} to exist, but does not"
read = File.read(absolute) if block_given? || !contents.empty?
yield read if block_given?
contents.each do |content|
case content
when String
assert_equal content, read
when Regexp
assert_match content, read
end
end
end
alias :assert_directory :assert_file
# Asserts a given file does not exist. You need to supply an absolute path or a
# path relative to the configured destination:
#
# assert_no_file "config/random.rb"
#
def assert_no_file(relative)
absolute = File.expand_path(relative, destination_root)
assert !File.exists?(absolute), "Expected file #{relative.inspect} to not exist, but does"
end
alias :assert_no_directory :assert_no_file
# Asserts a given migration exists. You need to supply an absolute path or a
# path relative to the configured destination:
#
# assert_migration "db/migrate/create_products.rb"
#
# This method manipulates the given path and tries to find any migration which
# matches the migration name. For example, the call above is converted to:
#
# assert_file "db/migrate/003_create_products.rb"
#
# Consequently, assert_migration accepts the same arguments has assert_file.
#
def assert_migration(relative, *contents, &block)
file_name = migration_file_name(relative)
assert file_name, "Expected migration #{relative} to exist, but was not found"
assert_file file_name, *contents, &block
end
# Asserts a given migration does not exist. You need to supply an absolute path or a
# path relative to the configured destination:
#
# assert_no_migration "db/migrate/create_products.rb"
#
def assert_no_migration(relative)
file_name = migration_file_name(relative)
assert_nil file_name, "Expected migration #{relative} to not exist, but found #{file_name}"
end
# Asserts the given class method exists in the given content. This method does not detect
# class methods inside (class << self), only class methods which starts with "self.".
# When a block is given, it yields the content of the method.
#
# assert_migration "db/migrate/create_products.rb" do |migration|
# assert_class_method :up, migration do |up|
# assert_match(/create_table/, up)
# end
# end
#
def assert_class_method(method, content, &block)
assert_instance_method "self.#{method}", content, &block
end
# Asserts the given method exists in the given content. When a block is given,
# it yields the content of the method.
#
# assert_file "app/controller/products_controller.rb" do |controller|
# assert_instance_method :index, content do |index|
# assert_match(/Product\.all/, index)
# end
# end
#
def assert_instance_method(method, content)
assert content =~ /def #{method}(\(.+\))?(.*?)\n end/m, "Expected to have method #{method}"
yield $2.strip if block_given?
end
alias :assert_method :assert_instance_method
# Asserts the given attribute type gets translated to a field type
# properly:
#
# assert_field_type :date, :date_select
#
def assert_field_type(attribute_type, field_type)
assert_equal(field_type, create_generated_attribute(attribute_type).field_type)
end
# Asserts the given attribute type gets a proper default value:
#
# assert_field_default_value :string, "MyString"
#
def assert_field_default_value(attribute_type, value)
assert_equal(value, create_generated_attribute(attribute_type).default)
end
# Runs the generator configured for this class. The first argument is an array like
# command line arguments:
#
# class AppGeneratorTest < Rails::Generators::TestCase
# tests AppGenerator
# destination File.expand_path("../tmp", File.dirname(__FILE__))
# teardown :cleanup_destination_root
#
# test "database.yml is not created when skipping Active Record" do
# run_generator %w(myapp --skip-active-record)
# assert_no_file "config/database.yml"
# end
# end
#
# You can provide a configuration hash as second argument. This method returns the output
# printed by the generator.
def run_generator(args=self.default_arguments, config={})
capture(:stdout) { self.generator_class.start(args, config.reverse_merge(:destination_root => destination_root)) }
end
# Instantiate the generator.
def generator(args=self.default_arguments, options={}, config={})
@generator ||= self.generator_class.new(args, options, config.reverse_merge(:destination_root => destination_root))
end
# Create a Rails::Generators::GeneratedAttribute by supplying the
# attribute type and, optionally, the attribute name:
#
# create_generated_attribute(:string, 'name')
#
def create_generated_attribute(attribute_type, name = 'test', index = nil)
Rails::Generators::GeneratedAttribute.parse([name, attribute_type, index].compact.join(':'))
end
protected
def destination_root_is_set? #:nodoc:
raise "You need to configure your Rails::Generators::TestCase destination root." unless destination_root
end
def ensure_current_path #:nodoc:
cd current_path
end
def prepare_destination
rm_rf(destination_root)
mkdir_p(destination_root)
end
def migration_file_name(relative) #:nodoc:
absolute = File.expand_path(relative, destination_root)
dirname, file_name = File.dirname(absolute), File.basename(absolute).sub(/\.rb$/, '')
Dir.glob("#{dirname}/[0-9]*_*.rb").grep(/\d+_#{file_name}.rb$/).first
end
end
end
end
railties-3.2.16/lib/rails/generators/test_unit.rb 0000644 0001750 0001750 00000000224 12247655524 021351 0 ustar ondrej ondrej require 'rails/generators/named_base'
module TestUnit
module Generators
class Base < Rails::Generators::NamedBase #:nodoc:
end
end
end
railties-3.2.16/lib/rails/generators/active_model.rb 0000644 0001750 0001750 00000003357 12247655524 022000 0 ustar ondrej ondrej module Rails
module Generators
# ActiveModel is a class to be implemented by each ORM to allow Rails to
# generate customized controller code.
#
# The API has the same methods as ActiveRecord, but each method returns a
# string that matches the ORM API.
#
# For example:
#
# ActiveRecord::Generators::ActiveModel.find(Foo, "params[:id]")
# # => "Foo.find(params[:id])"
#
# Datamapper::Generators::ActiveModel.find(Foo, "params[:id]")
# # => "Foo.get(params[:id])"
#
# On initialization, the ActiveModel accepts the instance name that will
# receive the calls:
#
# builder = ActiveRecord::Generators::ActiveModel.new "@foo"
# builder.save # => "@foo.save"
#
# The only exception in ActiveModel for ActiveRecord is the use of self.build
# instead of self.new.
#
class ActiveModel
attr_reader :name
def initialize(name)
@name = name
end
# GET index
def self.all(klass)
"#{klass}.all"
end
# GET show
# GET edit
# PUT update
# DELETE destroy
def self.find(klass, params=nil)
"#{klass}.find(#{params})"
end
# GET new
# POST create
def self.build(klass, params=nil)
if params
"#{klass}.new(#{params})"
else
"#{klass}.new"
end
end
# POST create
def save
"#{name}.save"
end
# PUT update
def update_attributes(params=nil)
"#{name}.update_attributes(#{params})"
end
# POST create
# PUT update
def errors
"#{name}.errors"
end
# DELETE destroy
def destroy
"#{name}.destroy"
end
end
end
end
railties-3.2.16/lib/rails/generators/generated_attribute.rb 0000644 0001750 0001750 00000006426 12247655524 023366 0 ustar ondrej ondrej require 'active_support/time'
require 'active_support/core_ext/object/inclusion'
require 'active_support/core_ext/object/blank'
module Rails
module Generators
class GeneratedAttribute
attr_accessor :name, :type
attr_reader :attr_options
class << self
def parse(column_definition)
name, type, has_index = column_definition.split(':')
# if user provided "name:index" instead of "name:string:index"
# type should be set blank so GeneratedAttribute's constructor
# could set it to :string
has_index, type = type, nil if %w(index uniq).include?(type)
type, attr_options = *parse_type_and_options(type)
new(name, type, has_index, attr_options)
end
private
# parse possible attribute options like :limit for string/text/binary/integer or :precision/:scale for decimals
# when declaring options curly brackets should be used
def parse_type_and_options(type)
case type
when /(string|text|binary|integer)\{(\d+)\}/
return $1, :limit => $2.to_i
when /decimal\{(\d+)(,|\.|\-)(\d+)\}/
return :decimal, :precision => $1.to_i, :scale => $3.to_i
else
return type, {}
end
end
end
def initialize(name, type=nil, index_type=false, attr_options={})
@name = name
@type = (type.presence || :string).to_sym
@has_index = %w(index uniq).include?(index_type)
@has_uniq_index = %w(uniq).include?(index_type)
@attr_options = attr_options
end
def field_type
@field_type ||= case type
when :integer then :number_field
when :float, :decimal then :text_field
when :time then :time_select
when :datetime, :timestamp then :datetime_select
when :date then :date_select
when :text then :text_area
when :boolean then :check_box
else
:text_field
end
end
def default
@default ||= case type
when :integer then 1
when :float then 1.5
when :decimal then "9.99"
when :datetime, :timestamp, :time then Time.now.to_s(:db)
when :date then Date.today.to_s(:db)
when :string then name == "type" ? "" : "MyString"
when :text then "MyText"
when :boolean then false
when :references, :belongs_to then nil
else
""
end
end
def human_name
name.to_s.humanize
end
def index_name
reference? ? "#{name}_id" : name
end
def reference?
self.type.in?([:references, :belongs_to])
end
def has_index?
@has_index
end
def has_uniq_index?
@has_uniq_index
end
def inject_options
"".tap { |s| @attr_options.each { |k,v| s << ", :#{k} => #{v.inspect}" } }
end
def inject_index_options
has_uniq_index? ? ", :unique => true" : ''
end
end
end
end
railties-3.2.16/lib/rails/generators/rails/ 0000755 0001750 0001750 00000000000 12247655524 020122 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/migration/ 0000755 0001750 0001750 00000000000 12247655524 022113 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/migration/migration_generator.rb 0000644 0001750 0001750 00000000406 12247655524 026477 0 ustar ondrej ondrej module Rails
module Generators
class MigrationGenerator < NamedBase #metagenerator
argument :attributes, :type => :array, :default => [], :banner => "field[:type][:index] field[:type][:index]"
hook_for :orm, :required => true
end
end
end
railties-3.2.16/lib/rails/generators/rails/migration/USAGE 0000644 0001750 0001750 00000002200 12247655524 022674 0 ustar ondrej ondrej Description:
Stubs out a new database migration. Pass the migration name, either
CamelCased or under_scored, and an optional list of attribute pairs as arguments.
A migration class is generated in db/migrate prefixed by a timestamp of the current date and time.
You can name your migration in either of these formats to generate add/remove
column lines from supplied attributes: AddColumnsToTable or RemoveColumnsFromTable
Example:
`rails generate migration AddSslFlag`
If the current date is May 14, 2008 and the current time 09:09:12, this creates the AddSslFlag migration
db/migrate/20080514090912_add_ssl_flag.rb
`rails generate migration AddTitleBodyToPost title:string body:text published:boolean`
This will create the AddTitleBodyToPost in db/migrate/20080514090912_add_title_body_to_post.rb with
this in the Up migration:
add_column :posts, :title, :string
add_column :posts, :body, :text
add_column :posts, :published, :boolean
And this in the Down migration:
remove_column :posts, :published
remove_column :posts, :body
remove_column :posts, :title
railties-3.2.16/lib/rails/generators/rails/scaffold/ 0000755 0001750 0001750 00000000000 12247655524 021703 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/scaffold/scaffold_generator.rb 0000644 0001750 0001750 00000001467 12247655524 026067 0 ustar ondrej ondrej require 'rails/generators/rails/resource/resource_generator'
module Rails
module Generators
class ScaffoldGenerator < ResourceGenerator #metagenerator
remove_hook_for :resource_controller
remove_class_option :actions
class_option :stylesheets, :type => :boolean, :desc => "Generate Stylesheets"
class_option :stylesheet_engine, :desc => "Engine for Stylesheets"
class_option :assets, :type => :boolean
class_option :resource_route, :type => :boolean
hook_for :scaffold_controller, :required => true
hook_for :assets do |assets|
invoke assets, [controller_name]
end
hook_for :stylesheet_engine do |stylesheet_engine|
invoke stylesheet_engine, [controller_name] if options[:stylesheets] && behavior == :invoke
end
end
end
end
railties-3.2.16/lib/rails/generators/rails/scaffold/templates/ 0000755 0001750 0001750 00000000000 12247655524 023701 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/scaffold/templates/scaffold.css 0000644 0001750 0001750 00000001624 12247655524 026177 0 ustar ondrej ondrej body { background-color: #fff; color: #333; }
body, p, ol, ul, td {
font-family: verdana, arial, helvetica, sans-serif;
font-size: 13px;
line-height: 18px;
}
pre {
background-color: #eee;
padding: 10px;
font-size: 11px;
}
a { color: #000; }
a:visited { color: #666; }
a:hover { color: #fff; background-color:#000; }
div.field, div.actions {
margin-bottom: 10px;
}
#notice {
color: green;
}
.field_with_errors {
padding: 2px;
background-color: red;
display: table;
}
#error_explanation {
width: 450px;
border: 2px solid red;
padding: 7px;
padding-bottom: 0;
margin-bottom: 20px;
background-color: #f0f0f0;
}
#error_explanation h2 {
text-align: left;
font-weight: bold;
padding: 5px 5px 5px 15px;
font-size: 12px;
margin: -7px;
margin-bottom: 0px;
background-color: #c00;
color: #fff;
}
#error_explanation ul li {
font-size: 12px;
list-style: square;
}
railties-3.2.16/lib/rails/generators/rails/scaffold/USAGE 0000644 0001750 0001750 00000003240 12247655524 022471 0 ustar ondrej ondrej Description:
Scaffolds an entire resource, from model and migration to controller and
views, along with a full test suite. The resource is ready to use as a
starting point for your RESTful, resource-oriented application.
Pass the name of the model (in singular form), either CamelCased or
under_scored, as the first argument, and an optional list of attribute
pairs.
Attributes are field arguments specifying the model's attributes. You can
optionally pass the type and an index to each field. For instance:
"title body:text tracking_id:integer:uniq" will generate a title field of
string type, a body with text type and a tracking_id as an integer with an
unique index. "index" could also be given instead of "uniq" if one desires
a non unique index.
Timestamps are added by default, so you don't have to specify them by hand
as 'created_at:datetime updated_at:datetime'.
You don't have to think up every attribute up front, but it helps to
sketch out a few so you can start working with the resource immediately.
For example, 'scaffold post title body:text published:boolean' gives
you a model with those three attributes, a controller that handles
the create/show/update/destroy, forms to create and edit your posts, and
an index that lists them all, as well as a resources :posts declaration
in config/routes.rb.
If you want to remove all the generated files, run
'rails destroy scaffold ModelName'.
Examples:
`rails generate scaffold post`
`rails generate scaffold post title body:text published:boolean`
`rails generate scaffold purchase amount:decimal tracking_id:integer:uniq`
railties-3.2.16/lib/rails/generators/rails/helper/ 0000755 0001750 0001750 00000000000 12247655524 021401 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/helper/templates/ 0000755 0001750 0001750 00000000000 12247655524 023377 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/helper/templates/helper.rb 0000644 0001750 0001750 00000000113 12247655524 025176 0 ustar ondrej ondrej <% module_namespacing do -%>
module <%= class_name %>Helper
end
<% end -%>
railties-3.2.16/lib/rails/generators/rails/helper/USAGE 0000644 0001750 0001750 00000000772 12247655524 022176 0 ustar ondrej ondrej Description:
Stubs out a new helper. Pass the helper name, either CamelCased
or under_scored.
To create a helper within a module, specify the helper name as a
path like 'parent_module/helper_name'.
This generates a helper class in app/helpers and invokes the configured
test framework.
Example:
`rails generate helper CreditCard`
Credit card helper.
Helper: app/helpers/credit_card_helper.rb
Test: test/unit/helpers/credit_card_helper_test.rb
railties-3.2.16/lib/rails/generators/rails/helper/helper_generator.rb 0000644 0001750 0001750 00000000457 12247655524 025261 0 ustar ondrej ondrej module Rails
module Generators
class HelperGenerator < NamedBase
check_class_collision :suffix => "Helper"
def create_helper_files
template 'helper.rb', File.join('app/helpers', class_path, "#{file_name}_helper.rb")
end
hook_for :test_framework
end
end
end
railties-3.2.16/lib/rails/generators/rails/scaffold_controller/ 0000755 0001750 0001750 00000000000 12247655524 024146 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/scaffold_controller/templates/ 0000755 0001750 0001750 00000000000 12247655524 026144 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/scaffold_controller/templates/controller.rb 0000644 0001750 0001750 00000005732 12247655524 030663 0 ustar ondrej ondrej <% if namespaced? -%>
require_dependency "<%= namespaced_file_path %>/application_controller"
<% end -%>
<% module_namespacing do -%>
class <%= controller_class_name %>Controller < ApplicationController
# GET <%= route_url %>
# GET <%= route_url %>.json
def index
@<%= plural_table_name %> = <%= orm_class.all(class_name) %>
respond_to do |format|
format.html # index.html.erb
format.json { render <%= key_value :json, "@#{plural_table_name}" %> }
end
end
# GET <%= route_url %>/1
# GET <%= route_url %>/1.json
def show
@<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
respond_to do |format|
format.html # show.html.erb
format.json { render <%= key_value :json, "@#{singular_table_name}" %> }
end
end
# GET <%= route_url %>/new
# GET <%= route_url %>/new.json
def new
@<%= singular_table_name %> = <%= orm_class.build(class_name) %>
respond_to do |format|
format.html # new.html.erb
format.json { render <%= key_value :json, "@#{singular_table_name}" %> }
end
end
# GET <%= route_url %>/1/edit
def edit
@<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
end
# POST <%= route_url %>
# POST <%= route_url %>.json
def create
@<%= singular_table_name %> = <%= orm_class.build(class_name, "params[:#{singular_table_name}]") %>
respond_to do |format|
if @<%= orm_instance.save %>
format.html { redirect_to @<%= singular_table_name %>, <%= key_value :notice, "'#{human_name} was successfully created.'" %> }
format.json { render <%= key_value :json, "@#{singular_table_name}" %>, <%= key_value :status, ':created' %>, <%= key_value :location, "@#{singular_table_name}" %> }
else
format.html { render <%= key_value :action, '"new"' %> }
format.json { render <%= key_value :json, "@#{orm_instance.errors}" %>, <%= key_value :status, ':unprocessable_entity' %> }
end
end
end
# PUT <%= route_url %>/1
# PUT <%= route_url %>/1.json
def update
@<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
respond_to do |format|
if @<%= orm_instance.update_attributes("params[:#{singular_table_name}]") %>
format.html { redirect_to @<%= singular_table_name %>, <%= key_value :notice, "'#{human_name} was successfully updated.'" %> }
format.json { head :no_content }
else
format.html { render <%= key_value :action, '"edit"' %> }
format.json { render <%= key_value :json, "@#{orm_instance.errors}" %>, <%= key_value :status, ':unprocessable_entity' %> }
end
end
end
# DELETE <%= route_url %>/1
# DELETE <%= route_url %>/1.json
def destroy
@<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
@<%= orm_instance.destroy %>
respond_to do |format|
format.html { redirect_to <%= index_helper %>_url }
format.json { head :no_content }
end
end
end
<% end -%>
railties-3.2.16/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb 0000644 0001750 0001750 00000001421 12247655524 032563 0 ustar ondrej ondrej require 'rails/generators/resource_helpers'
module Rails
module Generators
class ScaffoldControllerGenerator < NamedBase
include ResourceHelpers
check_class_collision :suffix => "Controller"
class_option :orm, :banner => "NAME", :type => :string, :required => true,
:desc => "ORM to generate the controller for"
def create_controller_files
template 'controller.rb', File.join('app/controllers', class_path, "#{controller_file_name}_controller.rb")
end
hook_for :template_engine, :test_framework, :as => :scaffold
# Invoke the helper using the controller name (pluralized)
hook_for :helper, :as => :scaffold do |invoked|
invoke invoked, [ controller_name ]
end
end
end
end
railties-3.2.16/lib/rails/generators/rails/scaffold_controller/USAGE 0000644 0001750 0001750 00000001561 12247655524 024740 0 ustar ondrej ondrej Description:
Stubs out a scaffolded controller, its seven RESTful actions and related
views. Pass the model name, either CamelCased or under_scored. The
controller name is retrieved as a pluralized version of the model name.
To create a controller within a module, specify the model name as a
path like 'parent_module/controller_name'.
This generates a controller class in app/controllers and invokes helper,
template engine and test framework generators.
Example:
`rails generate scaffold_controller CreditCard`
Credit card controller with URLs like /credit_card/debit.
Controller: app/controllers/credit_cards_controller.rb
Functional Test: test/functional/credit_cards_controller_test.rb
Views: app/views/credit_cards/index.html.erb [...]
Helper: app/helpers/credit_cards_helper.rb
railties-3.2.16/lib/rails/generators/rails/resource/ 0000755 0001750 0001750 00000000000 12247655524 021751 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/resource/USAGE 0000644 0001750 0001750 00000002127 12247655524 022542 0 ustar ondrej ondrej Description:
Stubs out a new resource including an empty model and controller suitable
for a restful, resource-oriented application. Pass the singular model name,
either CamelCased or under_scored, as the first argument, and an optional
list of attribute pairs.
Attribute pairs are field:type arguments specifying the
model's attributes. Timestamps are added by default, so you don't have to
specify them by hand as 'created_at:datetime updated_at:datetime'.
You don't have to think up every attribute up front, but it helps to
sketch out a few so you can start working with the model immediately.
This generator invokes your configured ORM and test framework, besides
creating helpers and add routes to config/routes.rb.
Unlike the scaffold generator, the resource generator does not create
views or add any methods to the generated controller.
Examples:
`rails generate resource post` # no attributes
`rails generate resource post title:string body:text published:boolean`
`rails generate resource purchase order_id:integer amount:decimal`
railties-3.2.16/lib/rails/generators/rails/resource/resource_generator.rb 0000644 0001750 0001750 00000001216 12247655524 026173 0 ustar ondrej ondrej require 'rails/generators/resource_helpers'
require 'rails/generators/rails/model/model_generator'
require 'active_support/core_ext/object/blank'
module Rails
module Generators
class ResourceGenerator < ModelGenerator #metagenerator
include ResourceHelpers
hook_for :resource_controller, :required => true do |controller|
invoke controller, [ controller_name, options[:actions] ]
end
class_option :actions, :type => :array, :banner => "ACTION ACTION", :default => [],
:desc => "Actions for the resource controller"
hook_for :resource_route, :required => true
end
end
end
railties-3.2.16/lib/rails/generators/rails/plugin_new/ 0000755 0001750 0001750 00000000000 12247655524 022271 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/plugin_new/templates/ 0000755 0001750 0001750 00000000000 12247655524 024267 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/plugin_new/templates/config/ 0000755 0001750 0001750 00000000000 12247655524 025534 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/plugin_new/templates/config/routes.rb 0000644 0001750 0001750 00000000171 12247655524 027401 0 ustar ondrej ondrej <% if mountable? -%>
<%= camelized %>::Engine.routes.draw do
<% else -%>
Rails.application.routes.draw do
<% end -%>
end
railties-3.2.16/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec 0000644 0001750 0001750 00000001745 12247655524 026675 0 ustar ondrej ondrej $:.push File.expand_path("../lib", __FILE__)
# Maintain your gem's version:
require "<%= name %>/version"
# Describe your gem and declare its dependencies:
Gem::Specification.new do |s|
s.name = "<%= name %>"
s.version = <%= camelized %>::VERSION
s.authors = ["TODO: Your name"]
s.email = ["TODO: Your email"]
s.homepage = "TODO"
s.summary = "TODO: Summary of <%= camelized %>."
s.description = "TODO: Description of <%= camelized %>."
s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.rdoc"]
<% unless options.skip_test_unit? -%>
s.test_files = Dir["test/**/*"]
<% end -%>
<%= '# ' if options.dev? || options.edge? -%>s.add_dependency "rails", "~> <%= Rails::VERSION::STRING %>"
<% if full? && !options[:skip_javascript] -%>
# s.add_dependency "<%= "#{options[:javascript]}-rails" %>"
<% end -%>
<% unless options[:skip_active_record] -%>
s.add_development_dependency "<%= gem_for_database %>"
<% end -%>
end
railties-3.2.16/lib/rails/generators/rails/plugin_new/templates/README.rdoc 0000644 0001750 0001750 00000000074 12247655524 026076 0 ustar ondrej ondrej = <%= camelized %>
This project rocks and uses MIT-LICENSE. railties-3.2.16/lib/rails/generators/rails/plugin_new/templates/gitignore 0000644 0001750 0001750 00000000210 12247655524 026172 0 ustar ondrej ondrej .bundle/
log/*.log
pkg/
<%= dummy_path %>/db/*.sqlite3
<%= dummy_path %>/log/*.log
<%= dummy_path %>/tmp/
<%= dummy_path %>/.sass-cache
railties-3.2.16/lib/rails/generators/rails/plugin_new/templates/script/ 0000755 0001750 0001750 00000000000 12247655524 025573 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/plugin_new/templates/script/rails.tt 0000644 0001750 0001750 00000000457 12247655524 027264 0 ustar ondrej ondrej # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
ENGINE_ROOT = File.expand_path('../..', __FILE__)
ENGINE_PATH = File.expand_path('../../lib/<%= name -%>/engine', __FILE__)
require 'rails/all'
require 'rails/engine/commands'
railties-3.2.16/lib/rails/generators/rails/plugin_new/templates/rails/ 0000755 0001750 0001750 00000000000 12247655524 025401 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/plugin_new/templates/rails/boot.rb 0000644 0001750 0001750 00000000353 12247655524 026672 0 ustar ondrej ondrej require 'rubygems'
gemfile = File.expand_path('../../../../Gemfile', __FILE__)
if File.exist?(gemfile)
ENV['BUNDLE_GEMFILE'] = gemfile
require 'bundler'
Bundler.setup
end
$:.unshift File.expand_path('../../../../lib', __FILE__) railties-3.2.16/lib/rails/generators/rails/plugin_new/templates/rails/application.rb 0000644 0001750 0001750 00000001032 12247655524 030225 0 ustar ondrej ondrej require File.expand_path('../boot', __FILE__)
<% if include_all_railties? -%>
require 'rails/all'
<% else -%>
# Pick the frameworks you want:
<%= comment_if :skip_active_record %>require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
<%= comment_if :skip_sprockets %>require "sprockets/railtie"
<%= comment_if :skip_test_unit %>require "rails/test_unit/railtie"
<% end -%>
Bundler.require(*Rails.groups)
require "<%= name %>"
<%= application_definition %>
railties-3.2.16/lib/rails/generators/rails/plugin_new/templates/rails/routes.rb 0000644 0001750 0001750 00000000131 12247655524 027242 0 ustar ondrej ondrej Rails.application.routes.draw do
mount <%= camelized %>::Engine => "/<%= name %>"
end
railties-3.2.16/lib/rails/generators/rails/plugin_new/templates/Gemfile 0000644 0001750 0001750 00000001507 12247655524 025565 0 ustar ondrej ondrej source "https://rubygems.org"
# Declare your gem's dependencies in <%= name %>.gemspec.
# Bundler will treat runtime dependencies like base dependencies, and
# development dependencies will be added by default to the :development group.
gemspec
# jquery-rails is used by the dummy application
gem "jquery-rails"
# Declare any dependencies that are still in development here instead of in
# your gemspec. These might include edge Rails or gems from your path or
# Git. Remember to move these dependencies to your gemspec before releasing
# your gem to rubygems.org.
<% if options.dev? || options.edge? -%>
# Your gem is dependent on dev or edge Rails. Once you can lock this
# dependency down to a specific version, move it to your gemspec.
<%= rails_gemfile_entry -%>
<% end -%>
# To use debugger
# <%= ruby_debugger_gemfile_entry %>
railties-3.2.16/lib/rails/generators/rails/plugin_new/templates/lib/ 0000755 0001750 0001750 00000000000 12247655524 025035 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/plugin_new/templates/lib/%name%.rb 0000644 0001750 0001750 00000000125 12247655524 026412 0 ustar ondrej ondrej <% if full? -%>
require "<%= name %>/engine"
<% end -%>
module <%= camelized %>
end
railties-3.2.16/lib/rails/generators/rails/plugin_new/templates/lib/%name%/ 0000755 0001750 0001750 00000000000 12247655524 026067 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/plugin_new/templates/lib/%name%/engine.rb 0000644 0001750 0001750 00000000212 12247655524 027654 0 ustar ondrej ondrej module <%= camelized %>
class Engine < ::Rails::Engine
<% if mountable? -%>
isolate_namespace <%= camelized %>
<% end -%>
end
end
railties-3.2.16/lib/rails/generators/rails/plugin_new/templates/lib/%name%/version.rb 0000644 0001750 0001750 00000000060 12247655524 030075 0 ustar ondrej ondrej module <%= camelized %>
VERSION = "0.0.1"
end
railties-3.2.16/lib/rails/generators/rails/plugin_new/templates/lib/tasks/ 0000755 0001750 0001750 00000000000 12247655524 026162 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/plugin_new/templates/lib/tasks/%name%_tasks.rake 0000644 0001750 0001750 00000000131 12247655524 031260 0 ustar ondrej ondrej # desc "Explaining what the task does"
# task :<%= name %> do
# # Task goes here
# end
railties-3.2.16/lib/rails/generators/rails/plugin_new/templates/app/ 0000755 0001750 0001750 00000000000 12247655524 025047 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/plugin_new/templates/app/mailers/ 0000755 0001750 0001750 00000000000 12247655524 026503 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/plugin_new/templates/app/mailers/.empty_directory 0000644 0001750 0001750 00000000000 12247655524 031714 0 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/plugin_new/templates/app/controllers/ 0000755 0001750 0001750 00000000000 12247655524 027415 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/plugin_new/templates/app/controllers/%name%/ 0000755 0001750 0001750 00000000000 12247655524 030447 5 ustar ondrej ondrej ././@LongLink 0000000 0000000 0000000 00000000164 00000000000 011566 L ustar root root railties-3.2.16/lib/rails/generators/rails/plugin_new/templates/app/controllers/%name%/application_controller.rb.tt railties-3.2.16/lib/rails/generators/rails/plugin_new/templates/app/controllers/%name%/application_c0000644 0001750 0001750 00000000131 12247655524 033172 0 ustar ondrej ondrej module <%= camelized %>
class ApplicationController < ActionController::Base
end
end
railties-3.2.16/lib/rails/generators/rails/plugin_new/templates/app/helpers/ 0000755 0001750 0001750 00000000000 12247655524 026511 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/plugin_new/templates/app/helpers/%name%/ 0000755 0001750 0001750 00000000000 12247655524 027543 5 ustar ondrej ondrej ././@LongLink 0000000 0000000 0000000 00000000154 00000000000 011565 L ustar root root railties-3.2.16/lib/rails/generators/rails/plugin_new/templates/app/helpers/%name%/application_helper.rb.tt railties-3.2.16/lib/rails/generators/rails/plugin_new/templates/app/helpers/%name%/application_helpe0000644 0001750 0001750 00000000075 12247655524 033150 0 ustar ondrej ondrej module <%= camelized %>
module ApplicationHelper
end
end
railties-3.2.16/lib/rails/generators/rails/plugin_new/templates/app/models/ 0000755 0001750 0001750 00000000000 12247655524 026332 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/plugin_new/templates/app/models/.empty_directory 0000644 0001750 0001750 00000000000 12247655524 031543 0 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/plugin_new/templates/app/views/ 0000755 0001750 0001750 00000000000 12247655524 026204 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/plugin_new/templates/app/views/layouts/ 0000755 0001750 0001750 00000000000 12247655524 027704 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/plugin_new/templates/app/views/layouts/%name%/ 0000755 0001750 0001750 00000000000 12247655524 030736 5 ustar ondrej ondrej ././@LongLink 0000000 0000000 0000000 00000000161 00000000000 011563 L ustar root root railties-3.2.16/lib/rails/generators/rails/plugin_new/templates/app/views/layouts/%name%/application.html.erb.tt railties-3.2.16/lib/rails/generators/rails/plugin_new/templates/app/views/layouts/%name%/application0000644 0001750 0001750 00000000417 12247655524 033166 0 ustar ondrej ondrej
<%= camelized %>
<%%= stylesheet_link_tag "<%= name %>/application", :media => "all" %>
<%%= javascript_include_tag "<%= name %>/application" %>
<%%= csrf_meta_tags %>
<%%= yield %>
railties-3.2.16/lib/rails/generators/rails/plugin_new/templates/Rakefile 0000755 0001750 0001750 00000001373 12247655524 025743 0 ustar ondrej ondrej #!/usr/bin/env rake
begin
require 'bundler/setup'
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end
begin
require 'rdoc/task'
rescue LoadError
require 'rdoc/rdoc'
require 'rake/rdoctask'
RDoc::Task = Rake::RDocTask
end
RDoc::Task.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = '<%= camelized %>'
rdoc.options << '--line-numbers'
rdoc.rdoc_files.include('README.rdoc')
rdoc.rdoc_files.include('lib/**/*.rb')
end
<% if full? && !options[:skip_active_record] && with_dummy_app? -%>
APP_RAKEFILE = File.expand_path("../<%= dummy_path -%>/Rakefile", __FILE__)
load 'rails/tasks/engine.rake'
<% end %>
<% unless options[:skip_gemspec] -%>
Bundler::GemHelper.install_tasks
<% end %>
railties-3.2.16/lib/rails/generators/rails/plugin_new/templates/test/ 0000755 0001750 0001750 00000000000 12247655524 025246 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/plugin_new/templates/test/integration/ 0000755 0001750 0001750 00000000000 12247655524 027571 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/plugin_new/templates/test/integration/navigation_test.rb 0000644 0001750 0001750 00000000314 12247655524 033312 0 ustar ondrej ondrej require 'test_helper'
class NavigationTest < ActionDispatch::IntegrationTest
<% unless options[:skip_active_record] -%>
fixtures :all
<% end -%>
# test "the truth" do
# assert true
# end
end
railties-3.2.16/lib/rails/generators/rails/plugin_new/templates/test/test_helper.rb 0000644 0001750 0001750 00000000725 12247655524 030115 0 ustar ondrej ondrej # Configure Rails Environment
ENV["RAILS_ENV"] = "test"
require File.expand_path("../dummy/config/environment.rb", __FILE__)
require "rails/test_help"
Rails.backtrace_cleaner.remove_silencers!
# Load support files
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
# Load fixtures from the engine
if ActiveSupport::TestCase.method_defined?(:fixture_path=)
ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
end
railties-3.2.16/lib/rails/generators/rails/plugin_new/templates/test/%name%_test.rb 0000644 0001750 0001750 00000000224 12247655524 027662 0 ustar ondrej ondrej require 'test_helper'
class <%= camelized %>Test < ActiveSupport::TestCase
test "truth" do
assert_kind_of Module, <%= camelized %>
end
end
railties-3.2.16/lib/rails/generators/rails/plugin_new/templates/MIT-LICENSE 0000644 0001750 0001750 00000002052 12247655524 025722 0 ustar ondrej ondrej Copyright <%= Date.today.year %> YOURNAME
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, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
railties-3.2.16/lib/rails/generators/rails/plugin_new/USAGE 0000644 0001750 0001750 00000000535 12247655524 023063 0 ustar ondrej ondrej Description:
The 'rails plugin new' command creates a skeleton for developing any
kind of Rails extension with ability to run tests using dummy Rails
application.
Example:
rails plugin new ~/Code/Ruby/blog
This generates a skeletal Rails plugin in ~/Code/Ruby/blog.
See the README in the newly created plugin to get going.
railties-3.2.16/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb 0000644 0001750 0001750 00000020574 12247655524 027043 0 ustar ondrej ondrej require 'active_support/core_ext/hash/slice'
require "rails/generators/rails/app/app_generator"
require 'date'
module Rails
class PluginBuilder
def rakefile
template "Rakefile"
end
def app
if mountable?
directory "app"
empty_directory_with_gitkeep "app/assets/images/#{name}"
elsif full?
empty_directory_with_gitkeep "app/models"
empty_directory_with_gitkeep "app/controllers"
empty_directory_with_gitkeep "app/views"
empty_directory_with_gitkeep "app/helpers"
empty_directory_with_gitkeep "app/mailers"
empty_directory_with_gitkeep "app/assets/images/#{name}"
end
end
def readme
template "README.rdoc"
end
def gemfile
template "Gemfile"
end
def license
template "MIT-LICENSE"
end
def gemspec
template "%name%.gemspec"
end
def gitignore
template "gitignore", ".gitignore"
end
def lib
template "lib/%name%.rb"
template "lib/tasks/%name%_tasks.rake"
template "lib/%name%/version.rb"
if full?
template "lib/%name%/engine.rb"
end
end
def config
template "config/routes.rb" if full?
end
def test
template "test/test_helper.rb"
template "test/%name%_test.rb"
append_file "Rakefile", <<-EOF
#{rakefile_test_tasks}
task :default => :test
EOF
if full?
template "test/integration/navigation_test.rb"
end
end
PASSTHROUGH_OPTIONS = [
:skip_active_record, :skip_javascript, :database, :javascript, :quiet, :pretend, :force, :skip
]
def generate_test_dummy(force = false)
opts = (options || {}).slice(*PASSTHROUGH_OPTIONS)
opts[:force] = force
opts[:skip_bundle] = true
invoke Rails::Generators::AppGenerator,
[ File.expand_path(dummy_path, destination_root) ], opts
end
def test_dummy_config
template "rails/boot.rb", "#{dummy_path}/config/boot.rb", :force => true
template "rails/application.rb", "#{dummy_path}/config/application.rb", :force => true
if mountable?
template "rails/routes.rb", "#{dummy_path}/config/routes.rb", :force => true
end
end
def test_dummy_clean
inside dummy_path do
remove_file ".gitignore"
remove_file "db/seeds.rb"
remove_file "doc"
remove_file "Gemfile"
remove_file "lib/tasks"
remove_file "app/assets/images/rails.png"
remove_file "public/index.html"
remove_file "public/robots.txt"
remove_file "README"
remove_file "test"
remove_file "vendor"
end
end
def stylesheets
if mountable?
copy_file "#{app_templates_dir}/app/assets/stylesheets/application.css",
"app/assets/stylesheets/#{name}/application.css"
elsif full?
empty_directory_with_gitkeep "app/assets/stylesheets/#{name}"
end
end
def javascripts
return if options.skip_javascript?
if mountable?
template "#{app_templates_dir}/app/assets/javascripts/application.js.tt",
"app/assets/javascripts/#{name}/application.js"
elsif full?
empty_directory_with_gitkeep "app/assets/javascripts/#{name}"
end
end
def script(force = false)
return unless full?
directory "script", :force => force do |content|
"#{shebang}\n" + content
end
chmod "script", 0755, :verbose => false
end
end
module Generators
class PluginNewGenerator < AppBase
add_shared_options_for "plugin"
alias_method :plugin_path, :app_path
class_option :dummy_path, :type => :string, :default => "test/dummy",
:desc => "Create dummy application at given path"
class_option :full, :type => :boolean, :default => false,
:desc => "Generate rails engine with integration tests"
class_option :mountable, :type => :boolean, :default => false,
:desc => "Generate mountable isolated application"
class_option :skip_gemspec, :type => :boolean, :default => false,
:desc => "Skip gemspec file"
def initialize(*args)
raise Error, "Options should be given after the plugin name. For details run: rails plugin --help" if args[0].blank?
@dummy_path = nil
super
end
public_task :create_root
def create_root_files
build(:readme)
build(:rakefile)
build(:gemspec) unless options[:skip_gemspec]
build(:license)
build(:gitignore) unless options[:skip_git]
build(:gemfile) unless options[:skip_gemfile]
end
def create_app_files
build(:app)
end
def create_config_files
build(:config)
end
def create_lib_files
build(:lib)
end
def create_public_stylesheets_files
build(:stylesheets)
end
def create_javascript_files
build(:javascripts)
end
def create_images_directory
build(:images)
end
def create_script_files
build(:script)
end
def create_test_files
build(:test) unless options[:skip_test_unit]
end
def create_test_dummy_files
return unless with_dummy_app?
create_dummy_app
end
def finish_template
build(:leftovers)
end
public_task :apply_rails_template, :run_bundle
def name
@name ||= begin
# same as ActiveSupport::Inflector#underscore except not replacing '-'
underscored = original_name.dup
underscored.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
underscored.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
underscored.downcase!
underscored
end
end
protected
def app_templates_dir
"../../app/templates"
end
def create_dummy_app(path = nil)
dummy_path(path) if path
say_status :vendor_app, dummy_path
mute do
build(:generate_test_dummy)
store_application_definition!
build(:test_dummy_config)
build(:test_dummy_clean)
# ensure that script/rails has proper dummy_path
build(:script, true)
end
end
def full?
options[:full] || options[:mountable]
end
def mountable?
options[:mountable]
end
def with_dummy_app?
options[:skip_test_unit].blank? || options[:dummy_path] != 'test/dummy'
end
def self.banner
"rails plugin new #{self.arguments.map(&:usage).join(' ')} [options]"
end
def original_name
@original_name ||= File.basename(destination_root)
end
def camelized
@camelized ||= name.gsub(/\W/, '_').squeeze('_').camelize
end
def valid_const?
if camelized =~ /^\d/
raise Error, "Invalid plugin name #{original_name}. Please give a name which does not start with numbers."
elsif RESERVED_NAMES.include?(name)
raise Error, "Invalid plugin name #{original_name}. Please give a name which does not match one of the reserved rails words."
elsif Object.const_defined?(camelized)
raise Error, "Invalid plugin name #{original_name}, constant #{camelized} is already in use. Please choose another plugin name."
end
end
def application_definition
@application_definition ||= begin
dummy_application_path = File.expand_path("#{dummy_path}/config/application.rb", destination_root)
unless options[:pretend] || !File.exists?(dummy_application_path)
contents = File.read(dummy_application_path)
contents[(contents.index(/module ([\w]+)\n(.*)class Application/m))..-1]
end
end
end
alias :store_application_definition! :application_definition
def get_builder_class
defined?(::PluginBuilder) ? ::PluginBuilder : Rails::PluginBuilder
end
def rakefile_test_tasks
<<-RUBY
require 'rake/testtask'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
t.verbose = false
end
RUBY
end
def dummy_path(path = nil)
@dummy_path = path if path
@dummy_path || options[:dummy_path]
end
def mute(&block)
shell.mute(&block)
end
end
end
end
railties-3.2.16/lib/rails/generators/rails/controller/ 0000755 0001750 0001750 00000000000 12247655524 022305 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/controller/templates/ 0000755 0001750 0001750 00000000000 12247655524 024303 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/controller/templates/controller.rb 0000644 0001750 0001750 00000000500 12247655524 027006 0 ustar ondrej ondrej <% if namespaced? -%>
require_dependency "<%= namespaced_file_path %>/application_controller"
<% end -%>
<% module_namespacing do -%>
class <%= class_name %>Controller < ApplicationController
<% actions.each do |action| -%>
def <%= action %>
end
<%= "\n" unless action == actions.last -%>
<% end -%>
end
<% end -%>
railties-3.2.16/lib/rails/generators/rails/controller/controller_generator.rb 0000644 0001750 0001750 00000001105 12247655524 027060 0 ustar ondrej ondrej module Rails
module Generators
class ControllerGenerator < NamedBase
argument :actions, :type => :array, :default => [], :banner => "action action"
check_class_collision :suffix => "Controller"
def create_controller_files
template 'controller.rb', File.join('app/controllers', class_path, "#{file_name}_controller.rb")
end
def add_routes
actions.reverse.each do |action|
route %{get "#{file_name}/#{action}"}
end
end
hook_for :template_engine, :test_framework, :helper, :assets
end
end
end
railties-3.2.16/lib/rails/generators/rails/controller/USAGE 0000644 0001750 0001750 00000001462 12247655524 023077 0 ustar ondrej ondrej Description:
Stubs out a new controller and its views. Pass the controller name, either
CamelCased or under_scored, and a list of views as arguments.
To create a controller within a module, specify the controller name as a
path like 'parent_module/controller_name'.
This generates a controller class in app/controllers and invokes helper,
template engine and test framework generators.
Example:
`rails generate controller CreditCard open debit credit close`
Credit card controller with URLs like /credit_card/debit.
Controller: app/controllers/credit_card_controller.rb
Functional Test: test/functional/credit_card_controller_test.rb
Views: app/views/credit_card/debit.html.erb [...]
Helper: app/helpers/credit_card_helper.rb
railties-3.2.16/lib/rails/generators/rails/resource_route/ 0000755 0001750 0001750 00000000000 12247655524 023167 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/resource_route/resource_route_generator.rb 0000644 0001750 0001750 00000002416 12247655524 030632 0 ustar ondrej ondrej module Rails
module Generators
class ResourceRouteGenerator < NamedBase
# Properly nests namespaces passed into a generator
#
# $ rails generate resource admin/users/products
#
# should give you
#
# namespace :admin do
# namespace :users
# resources :products
# end
# end
def add_resource_route
return if options[:actions].present?
# iterates over all namespaces and opens up blocks
regular_class_path.each_with_index do |namespace, index|
write("namespace :#{namespace} do", index + 1)
end
# inserts the primary resource
write("resources :#{file_name.pluralize}", route_length + 1)
# ends blocks
regular_class_path.each_index do |index|
write("end", route_length - index)
end
# route prepends two spaces onto the front of the string that is passed, this corrects that
route route_string[2..-1]
end
private
def route_string
@route_string ||= ""
end
def write(str, indent)
route_string << "#{" " * indent}#{str}\n"
end
def route_length
regular_class_path.length
end
end
end
end
railties-3.2.16/lib/rails/generators/rails/task/ 0000755 0001750 0001750 00000000000 12247655524 021064 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/task/templates/ 0000755 0001750 0001750 00000000000 12247655524 023062 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/task/templates/task.rb 0000644 0001750 0001750 00000000214 12247655524 024346 0 ustar ondrej ondrej namespace :<%= file_name %> do
<% actions.each do |action| -%>
desc "TODO"
task :<%= action %> => :environment do
end
<% end -%>
end
railties-3.2.16/lib/rails/generators/rails/task/USAGE 0000644 0001750 0001750 00000000367 12247655524 021661 0 ustar ondrej ondrej Description:
Stubs out a new Rake task. Pass the namespace name, and a list of tasks as arguments.
This generates a task file in lib/tasks.
Example:
`rails generate task feeds fetch erase add`
Task: lib/tasks/feeds.rake railties-3.2.16/lib/rails/generators/rails/task/task_generator.rb 0000644 0001750 0001750 00000000434 12247655524 024422 0 ustar ondrej ondrej module Rails
module Generators
class TaskGenerator < NamedBase
argument :actions, :type => :array, :default => [], :banner => "action action"
def create_task_files
template 'task.rb', File.join('lib/tasks', "#{file_name}.rake")
end
end
end
end
railties-3.2.16/lib/rails/generators/rails/generator/ 0000755 0001750 0001750 00000000000 12247655524 022110 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/generator/templates/ 0000755 0001750 0001750 00000000000 12247655524 024106 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/generator/templates/%file_name%_generator.rb.tt 0000644 0001750 0001750 00000000175 12247655524 031163 0 ustar ondrej ondrej class <%= class_name %>Generator < Rails::Generators::NamedBase
source_root File.expand_path('../templates', __FILE__)
end
railties-3.2.16/lib/rails/generators/rails/generator/templates/templates/ 0000755 0001750 0001750 00000000000 12247655524 026104 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/generator/templates/templates/.empty_directory 0000644 0001750 0001750 00000000000 12247655524 031315 0 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/generator/templates/USAGE.tt 0000644 0001750 0001750 00000000216 12247655524 025322 0 ustar ondrej ondrej Description:
Explain the generator
Example:
rails generate <%= file_name %> Thing
This will create:
what/will/it/create
railties-3.2.16/lib/rails/generators/rails/generator/generator_generator.rb 0000644 0001750 0001750 00000001175 12247655524 026475 0 ustar ondrej ondrej module Rails
module Generators
class GeneratorGenerator < NamedBase
check_class_collision :suffix => "Generator"
class_option :namespace, :type => :boolean, :default => true,
:desc => "Namespace generator under lib/generators/name"
def create_generator_files
directory '.', generator_dir
end
protected
def generator_dir
if options[:namespace]
File.join("lib", "generators", regular_class_path, file_name)
else
File.join("lib", "generators", regular_class_path)
end
end
end
end
end
railties-3.2.16/lib/rails/generators/rails/generator/USAGE 0000644 0001750 0001750 00000000613 12247655524 022677 0 ustar ondrej ondrej Description:
Stubs out a new generator at lib/generators. Pass the generator name as an argument,
either CamelCased or snake_cased.
Example:
`rails generate generator Awesome`
creates a standard awesome generator:
lib/generators/awesome/
lib/generators/awesome/awesome_generator.rb
lib/generators/awesome/USAGE
lib/generators/awesome/templates/
railties-3.2.16/lib/rails/generators/rails/performance_test/ 0000755 0001750 0001750 00000000000 12247655524 023462 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/performance_test/performance_test_generator.rb 0000644 0001750 0001750 00000000230 12247655524 031410 0 ustar ondrej ondrej module Rails
module Generators
class PerformanceTestGenerator < NamedBase
hook_for :performance_tool, :as => :performance
end
end
end
railties-3.2.16/lib/rails/generators/rails/performance_test/USAGE 0000644 0001750 0001750 00000000570 12247655524 024253 0 ustar ondrej ondrej Description:
Stubs out a new performance test. Pass the name of the test, either
CamelCased or under_scored, as an argument.
This generator invokes the current performance tool, which defaults to
TestUnit.
Example:
`rails generate performance_test GeneralStories` creates a GeneralStories
performance test in test/performance/general_stories_test.rb
railties-3.2.16/lib/rails/generators/rails/app/ 0000755 0001750 0001750 00000000000 12247655524 020702 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/app/templates/ 0000755 0001750 0001750 00000000000 12247655524 022700 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/app/templates/public/ 0000755 0001750 0001750 00000000000 12247655524 024156 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/app/templates/public/favicon.ico 0000644 0001750 0001750 00000000000 12247655524 026265 0 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/app/templates/public/robots.txt 0000644 0001750 0001750 00000000314 12247655524 026225 0 ustar ondrej ondrej # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
#
# To ban all spiders from the entire site uncomment the next two lines:
# User-Agent: *
# Disallow: /
railties-3.2.16/lib/rails/generators/rails/app/templates/public/index.html 0000644 0001750 0001750 00000013422 12247655524 026155 0 ustar ondrej ondrej
Ruby on Rails: Welcome aboard
Use rails generate to create your models and controllers
To see all available options, run it without parameters.
Set up a default route and remove public/index.html
Routes are set up in config/routes.rb.
Create your database
Run rake db:create to create your database. If you're not using SQLite (the default), edit config/database.yml with your username and password.
railties-3.2.16/lib/rails/generators/rails/app/templates/public/422.html 0000644 0001750 0001750 00000001307 12247655524 025354 0 ustar ondrej ondrej
The change you wanted was rejected (422)
The change you wanted was rejected.
Maybe you tried to change something you didn't have access to.
railties-3.2.16/lib/rails/generators/rails/app/templates/public/500.html 0000644 0001750 0001750 00000001203 12247655524 025344 0 ustar ondrej ondrej
We're sorry, but something went wrong (500)
We're sorry, but something went wrong.
railties-3.2.16/lib/rails/generators/rails/app/templates/public/stylesheets/ 0000755 0001750 0001750 00000000000 12247655524 026532 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/app/templates/public/stylesheets/.empty_directory 0000644 0001750 0001750 00000000000 12247655524 031743 0 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/app/templates/public/404.html 0000644 0001750 0001750 00000001330 12247655524 025350 0 ustar ondrej ondrej
The page you were looking for doesn't exist (404)
The page you were looking for doesn't exist.
You may have mistyped the address or the page may have moved.
railties-3.2.16/lib/rails/generators/rails/app/templates/config/ 0000755 0001750 0001750 00000000000 12247655524 024145 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/app/templates/config/boot.rb 0000644 0001750 0001750 00000000277 12247655524 025443 0 ustar ondrej ondrej require 'rubygems'
# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
railties-3.2.16/lib/rails/generators/rails/app/templates/config/databases/ 0000755 0001750 0001750 00000000000 12247655524 026074 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml 0000644 0001750 0001750 00000002330 12247655524 031643 0 ustar ondrej ondrej # PostgreSQL. Versions 8.2 and up are supported.
#
# Configure Using Gemfile
# gem 'activerecord-jdbcpostgresql-adapter'
development:
adapter: postgresql
encoding: unicode
database: <%= app_name %>_development
username: <%= app_name %>
password:
# Connect on a TCP socket. Omitted by default since the client uses a
# domain socket that doesn't need configuration. Windows does not have
# domain sockets, so uncomment these lines.
#host: localhost
#port: 5432
# Schema search path. The server defaults to $user,public
#schema_search_path: myapp,sharedapp,public
# Minimum log levels, in increasing order:
# debug5, debug4, debug3, debug2, debug1,
# log, notice, warning, error, fatal, and panic
# The server defaults to notice.
#min_messages: warning
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: postgresql
encoding: unicode
database: <%= app_name %>_test
username: <%= app_name %>
password:
production:
adapter: postgresql
encoding: unicode
database: <%= app_name %>_production
username: <%= app_name %>
password:
railties-3.2.16/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml 0000644 0001750 0001750 00000004035 12247655524 030035 0 ustar ondrej ondrej # IBM Dataservers
#
# Home Page
# http://rubyforge.org/projects/rubyibm/
#
# To install the ibm_db gem:
#
# On Linux:
# . /home/db2inst1/sqllib/db2profile
# export IBM_DB_INCLUDE=/opt/ibm/db2/V9.7/include
# export IBM_DB_LIB=/opt/ibm/db2/V9.7/lib32
# gem install ibm_db
#
# On Mac OS X 10.5:
# . /home/db2inst1/sqllib/db2profile
# export IBM_DB_INCLUDE=/opt/ibm/db2/V9.7/include
# export IBM_DB_LIB=/opt/ibm/db2/V9.7/lib32
# export ARCHFLAGS="-arch i386"
# gem install ibm_db
#
# On Mac OS X 10.6:
# . /home/db2inst1/sqllib/db2profile
# export IBM_DB_INCLUDE=/opt/ibm/db2/V9.7/include
# export IBM_DB_LIB=/opt/ibm/db2/V9.7/lib64
# export ARCHFLAGS="-arch x86_64"
# gem install ibm_db
#
# On Windows:
# Issue the command: gem install ibm_db
#
# Configure Using Gemfile
# gem 'ibm_db'
#
# For more details on the installation and the connection parameters below,
# please refer to the latest documents at http://rubyforge.org/docman/?group_id=2361
development:
adapter: ibm_db
username: db2inst1
password:
database: <%= app_name[0,4] %>_dev
#schema: db2inst1
#host: localhost
#port: 50000
#account: my_account
#app_user: my_app_user
#application: my_application
#workstation: my_workstation
#security: SSL
#timeout: 10
#authentication: SERVER
#parameterized: false
test:
adapter: ibm_db
username: db2inst1
password:
database: <%= app_name[0,4] %>_tst
#schema: db2inst1
#host: localhost
#port: 50000
#account: my_account
#app_user: my_app_user
#application: my_application
#workstation: my_workstation
#security: SSL
#timeout: 10
#authentication: SERVER
#parameterized: false
production:
adapter: ibm_db
username: db2inst1
password:
database: <%= app_name[0,8] %>
#schema: db2inst1
#host: localhost
#port: 50000
#account: my_account
#app_user: my_app_user
#application: my_application
#workstation: my_workstation
#security: SSL
#timeout: 10
#authentication: SERVER
#parameterized: false railties-3.2.16/lib/rails/generators/rails/app/templates/config/databases/oracle.yml 0000644 0001750 0001750 00000002077 12247655524 030072 0 ustar ondrej ondrej # Oracle/OCI 8i, 9, 10g
#
# Requires Ruby/OCI8:
# http://rubyforge.org/projects/ruby-oci8/
#
# Specify your database using any valid connection syntax, such as a
# tnsnames.ora service name, or an SQL connect string of the form:
#
# //host:[port][/service name]
#
# By default prefetch_rows (OCI_ATTR_PREFETCH_ROWS) is set to 100. And
# until true bind variables are supported, cursor_sharing is set by default
# to 'similar'. Both can be changed in the configuration below; the defaults
# are equivalent to specifying:
#
# prefetch_rows: 100
# cursor_sharing: similar
#
development:
adapter: oracle
database: <%= app_name %>_development
username: <%= app_name %>
password:
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: oracle
database: <%= app_name %>_test
username: <%= app_name %>
password:
production:
adapter: oracle
database: <%= app_name %>_production
username: <%= app_name %>
password:
railties-3.2.16/lib/rails/generators/rails/app/templates/config/databases/mysql.yml 0000644 0001750 0001750 00000002231 12247655524 027762 0 ustar ondrej ondrej # MySQL. Versions 4.1 and 5.0 are recommended.
#
# Install the MYSQL driver
# gem install mysql2
#
# Ensure the MySQL gem is defined in your Gemfile
# gem 'mysql2'
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: <%= app_name %>_development
pool: 5
username: root
password:
<% if mysql_socket -%>
socket: <%= mysql_socket %>
<% else -%>
host: localhost
<% end -%>
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: mysql2
encoding: utf8
reconnect: false
database: <%= app_name %>_test
pool: 5
username: root
password:
<% if mysql_socket -%>
socket: <%= mysql_socket %>
<% else -%>
host: localhost
<% end -%>
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: <%= app_name %>_production
pool: 5
username: root
password:
<% if mysql_socket -%>
socket: <%= mysql_socket %>
<% else -%>
host: localhost
<% end -%>
railties-3.2.16/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml 0000644 0001750 0001750 00000002767 12247655524 031036 0 ustar ondrej ondrej # PostgreSQL. Versions 8.2 and up are supported.
#
# Install the pg driver:
# gem install pg
# On Mac OS X with macports:
# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
# On Windows:
# gem install pg
# Choose the win32 build.
# Install PostgreSQL and put its /bin directory on your path.
#
# Configure Using Gemfile
# gem 'pg'
#
development:
adapter: postgresql
encoding: unicode
database: <%= app_name %>_development
pool: 5
username: <%= app_name %>
password:
# Connect on a TCP socket. Omitted by default since the client uses a
# domain socket that doesn't need configuration. Windows does not have
# domain sockets, so uncomment these lines.
#host: localhost
#port: 5432
# Schema search path. The server defaults to $user,public
#schema_search_path: myapp,sharedapp,public
# Minimum log levels, in increasing order:
# debug5, debug4, debug3, debug2, debug1,
# log, notice, warning, error, fatal, and panic
# The server defaults to notice.
#min_messages: warning
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: postgresql
encoding: unicode
database: <%= app_name %>_test
pool: 5
username: <%= app_name %>
password:
production:
adapter: postgresql
encoding: unicode
database: <%= app_name %>_production
pool: 5
username: <%= app_name %>
password:
railties-3.2.16/lib/rails/generators/rails/app/templates/config/databases/frontbase.yml 0000644 0001750 0001750 00000001311 12247655524 030576 0 ustar ondrej ondrej # FrontBase versions 4.x
#
# Get the bindings:
# gem install ruby-frontbase
#
# Configure Using Gemfile
# gem 'ruby-frontbase'
#
development:
adapter: frontbase
host: localhost
database: <%= app_name %>_development
username: <%= app_name %>
password: ''
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: frontbase
host: localhost
database: <%= app_name %>_test
username: <%= app_name %>
password: ''
production:
adapter: frontbase
host: localhost
database: <%= app_name %>_production
username: <%= app_name %>
password: ''
railties-3.2.16/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml 0000644 0001750 0001750 00000001476 12247655524 030617 0 ustar ondrej ondrej # MySQL. Versions 4.1 and 5.0 are recommended.
#
# Install the MySQL driver:
# gem install activerecord-jdbcmysql-adapter
#
# Configure Using Gemfile
# gem 'activerecord-jdbcmysql-adapter'
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
adapter: mysql
database: <%= app_name %>_development
username: root
password:
host: localhost
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: mysql
database: <%= app_name %>_test
username: root
password:
host: localhost
production:
adapter: mysql
database: <%= app_name %>_production
username: root
password:
host: localhost
railties-3.2.16/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml 0000644 0001750 0001750 00000001001 12247655524 031016 0 ustar ondrej ondrej # SQLite version 3.x
# gem 'activerecord-jdbcsqlite3-adapter'
#
# Configure Using Gemfile
# gem 'activerecord-jdbcsqlite3-adapter'
#
development:
adapter: sqlite3
database: db/development.sqlite3
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: sqlite3
database: db/test.sqlite3
production:
adapter: sqlite3
database: db/production.sqlite3
railties-3.2.16/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml 0000644 0001750 0001750 00000003321 12247655524 027520 0 ustar ondrej ondrej # If you are using mssql, derby, hsqldb, or h2 with one of the
# ActiveRecord JDBC adapters, install the appropriate driver, e.g.,:
# gem install activerecord-jdbcmssql-adapter
#
# Configure using Gemfile:
# gem 'activerecord-jdbcmssql-adapter'
#
#development:
# adapter: mssql
# username: <%= app_name %>
# password:
# host: localhost
# database: <%= app_name %>_development
#
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
#
#test:
# adapter: mssql
# username: <%= app_name %>
# password:
# host: localhost
# database: <%= app_name %>_test
#
#production:
# adapter: mssql
# username: <%= app_name %>
# password:
# host: localhost
# database: <%= app_name %>_production
# If you are using oracle, db2, sybase, informix or prefer to use the plain
# JDBC adapter, configure your database setting as the example below (requires
# you to download and manually install the database vendor's JDBC driver .jar
# file). See your driver documentation for the apropriate driver class and
# connection string:
development:
adapter: jdbc
username: <%= app_name %>
password:
driver:
url: jdbc:db://localhost/<%= app_name %>_development
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: jdbc
username: <%= app_name %>
password:
driver:
url: jdbc:db://localhost/<%= app_name %>_test
production:
adapter: jdbc
username: <%= app_name %>
password:
driver:
url: jdbc:db://localhost/<%= app_name %>_production
railties-3.2.16/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml 0000644 0001750 0001750 00000001100 12247655524 030173 0 ustar ondrej ondrej # SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000
railties-3.2.16/lib/rails/generators/rails/app/templates/config/environments/ 0000755 0001750 0001750 00000000000 12247655524 026674 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt 0000644 0001750 0001750 00000002714 12247655524 032175 0 ustar ondrej ondrej <%= app_const %>.configure do
# Settings specified here will take precedence over those in config/application.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 web server when you make code changes.
config.cache_classes = false
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = false
# Print deprecation notices to the Rails logger
config.active_support.deprecation = :log
# Only use best-standards-support built into browsers
config.action_dispatch.best_standards_support = :builtin
<%- unless options.skip_active_record? -%>
# Raise exception on mass assignment protection for Active Record models
config.active_record.mass_assignment_sanitizer = :strict
# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
config.active_record.auto_explain_threshold_in_seconds = 0.5
<%- end -%>
<%- unless options.skip_sprockets? -%>
# Do not compress assets
config.assets.compress = false
# Expands the lines which load the assets
config.assets.debug = true
<%- end -%>
end
railties-3.2.16/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt 0000644 0001750 0001750 00000005126 12247655524 032041 0 ustar ondrej ondrej <%= app_const %>.configure do
# Settings specified here will take precedence over those in config/application.rb
# Code is not reloaded between requests
config.cache_classes = true
# Full error reports are disabled and caching is turned on
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = false
<%- unless options.skip_sprockets? -%>
# Compress JavaScripts and CSS
config.assets.compress = true
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false
# Generate digests for assets URLs
config.assets.digest = true
# Defaults to nil and saved in location specified by config.assets.prefix
# config.assets.manifest = YOUR_PATH
<%- end -%>
# Specifies the header that your server uses for sending files
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
# config.force_ssl = true
# See everything in the log (default is :info)
# config.log_level = :debug
# Prepend all log lines with the following tags
# config.log_tags = [ :subdomain, :uuid ]
# Use a different logger for distributed setups
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
# Use a different cache store in production
# config.cache_store = :mem_cache_store
# Enable serving of images, stylesheets, and JavaScripts from an asset server
# config.action_controller.asset_host = "http://assets.example.com"
<%- unless options.skip_sprockets? -%>
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
# config.assets.precompile += %w( search.js )
<%- end -%>
# Disable delivery errors, bad email addresses will be ignored
# config.action_mailer.raise_delivery_errors = false
# Enable threaded mode
# config.threadsafe!
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation can not be found)
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners
config.active_support.deprecation = :notify
<%- unless options.skip_active_record? -%>
# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
# config.active_record.auto_explain_threshold_in_seconds = 0.5
<%- end -%>
end
railties-3.2.16/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt 0000644 0001750 0001750 00000003056 12247655524 030632 0 ustar ondrej ondrej <%= app_const %>.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 suite and is wiped
# and recreated between test runs. Don't rely on the data there!
config.cache_classes = true
# Configure static asset server for tests with Cache-Control for performance
config.serve_static_assets = true
config.static_cache_control = "public, max-age=3600"
# Log error messages when you accidentally call methods on nil
config.whiny_nils = true
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Raise exceptions instead of rendering exception templates
config.action_dispatch.show_exceptions = false
# Disable request forgery protection in test environment
config.action_controller.allow_forgery_protection = false
# Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test
<%- unless options.skip_active_record? -%>
# Raise exception on mass assignment protection for Active Record models
config.active_record.mass_assignment_sanitizer = :strict
<%- end -%>
# Print deprecation notices to the stderr
config.active_support.deprecation = :stderr
end
railties-3.2.16/lib/rails/generators/rails/app/templates/config/application.rb 0000644 0001750 0001750 00000006342 12247655524 027002 0 ustar ondrej ondrej require File.expand_path('../boot', __FILE__)
<% if include_all_railties? -%>
require 'rails/all'
<% else -%>
# Pick the frameworks you want:
<%= comment_if :skip_active_record %>require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
<%= comment_if :skip_sprockets %>require "sprockets/railtie"
<%= comment_if :skip_test_unit %>require "rails/test_unit/railtie"
<% end -%>
if defined?(Bundler)
# If you precompile assets before deploying to production, use this line
Bundler.require(*Rails.groups(:assets => %w(development test)))
# If you want your assets lazily compiled in production, use this line
# Bundler.require(:default, :assets, Rails.env)
end
module <%= app_const_base %>
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Custom directories with classes and modules you want to be autoloadable.
# config.autoload_paths += %W(#{config.root}/extras)
# Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named.
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
# Activate observers that should always be running.
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
# Configure the default encoding used in templates for Ruby 1.9.
config.encoding = "utf-8"
# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += [:password]
# Enable escaping HTML in JSON.
config.active_support.escape_html_entities_in_json = true
# Use SQL instead of Active Record's schema dumper when creating the database.
# This is necessary if your schema can't be completely dumped by the schema dumper,
# like if you have constraints or database-specific column types
# config.active_record.schema_format = :sql
# Enforce whitelist mode for mass assignment.
# This will create an empty whitelist of attributes available for mass-assignment for all models
# in your app. As such, your models will need to explicitly whitelist or blacklist accessible
# parameters by using an attr_accessible or attr_protected declaration.
<%= comment_if :skip_active_record %>config.active_record.whitelist_attributes = true
<% unless options.skip_sprockets? -%>
# Enable the asset pipeline
config.assets.enabled = true
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
<% end -%>
end
end
railties-3.2.16/lib/rails/generators/rails/app/templates/config/routes.rb 0000644 0001750 0001750 00000003372 12247655524 026020 0 ustar ondrej ondrej <%= app_const %>.routes.draw do
# The priority is based upon order of creation:
# first created -> highest priority.
# Sample of regular route:
# match 'products/:id' => 'catalog#view'
# Keep in mind you can assign values other than :controller and :action
# Sample of named route:
# match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
# This route can be invoked with purchase_url(:id => product.id)
# Sample resource route (maps HTTP verbs to controller actions automatically):
# resources :products
# Sample resource route with options:
# resources :products do
# member do
# get 'short'
# post 'toggle'
# end
#
# collection do
# get 'sold'
# end
# end
# Sample resource route with sub-resources:
# resources :products do
# resources :comments, :sales
# resource :seller
# end
# Sample resource route with more complex sub-resources
# resources :products do
# resources :comments
# resources :sales do
# get 'recent', :on => :collection
# end
# end
# Sample resource route within a namespace:
# namespace :admin do
# # Directs /admin/products/* to Admin::ProductsController
# # (app/controllers/admin/products_controller.rb)
# resources :products
# end
# You can have the root of your site routed with "root"
# just remember to delete public/index.html.
# root :to => 'welcome#index'
# See how all your routes lay out with "rake routes"
# This is a legacy wild controller route that's not recommended for RESTful applications.
# Note: This route will make all actions in every controller accessible via GET requests.
# match ':controller(/:action(/:id))(.:format)'
end
railties-3.2.16/lib/rails/generators/rails/app/templates/config/locales/ 0000755 0001750 0001750 00000000000 12247655524 025567 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/app/templates/config/locales/en.yml 0000644 0001750 0001750 00000000326 12247655524 026715 0 ustar ondrej ondrej # Sample localization file for English. Add more files in this directory for other locales.
# See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
en:
hello: "Hello world"
railties-3.2.16/lib/rails/generators/rails/app/templates/config/environment.rb 0000644 0001750 0001750 00000000223 12247655524 027033 0 ustar ondrej ondrej # Load the rails application
require File.expand_path('../application', __FILE__)
# Initialize the rails application
<%= app_const %>.initialize!
railties-3.2.16/lib/rails/generators/rails/app/templates/config/initializers/ 0000755 0001750 0001750 00000000000 12247655524 026653 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/app/templates/config/initializers/secret_token.rb.tt 0000644 0001750 0001750 00000000577 12247655524 032324 0 ustar ondrej ondrej # 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 attacks.
<%= app_const %>.config.secret_token = '<%= app_secret %>'
railties-3.2.16/lib/rails/generators/rails/app/templates/config/initializers/backtrace_silencers.rb 0000644 0001750 0001750 00000000624 12247655524 033170 0 ustar ondrej ondrej # 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 to debug a problem that might stem from framework code.
# Rails.backtrace_cleaner.remove_silencers!
railties-3.2.16/lib/rails/generators/rails/app/templates/config/initializers/mime_types.rb 0000644 0001750 0001750 00000000315 12247655524 031352 0 ustar ondrej ondrej # 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
railties-3.2.16/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt 0000644 0001750 0001750 00000000655 12247655524 032533 0 ustar ondrej ondrej # Be sure to restart your server when you modify this file.
<%= app_const %>.config.session_store :cookie_store, <%= key_value :key, "'_#{app_name}_session'" %>
# Use the database for sessions instead of the cookie-based default,
# which shouldn't be used to store highly confidential information
# (create the session table with "rails generate session_migration")
# <%= app_const %>.config.session_store :active_record_store
railties-3.2.16/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt 0000644 0001750 0001750 00000001034 12247655524 033020 0 ustar ondrej ondrej # Be sure to restart your server when you modify this file.
#
# This file contains settings for ActionController::ParamsWrapper which
# is enabled by default.
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
ActiveSupport.on_load(:action_controller) do
wrap_parameters <%= key_value :format, "[:json]" %>
end
<%- unless options.skip_active_record? -%>
# Disable root element in JSON by default.
ActiveSupport.on_load(:active_record) do
self.include_root_in_json = false
end
<%- end -%>
railties-3.2.16/lib/rails/generators/rails/app/templates/config/initializers/inflections.rb 0000644 0001750 0001750 00000001025 12247655524 031513 0 ustar ondrej ondrej # 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', 'people'
# inflect.uncountable %w( fish sheep )
# end
#
# These inflection rules are supported but not enabled by default:
# ActiveSupport::Inflector.inflections do |inflect|
# inflect.acronym 'RESTful'
# end
railties-3.2.16/lib/rails/generators/rails/app/templates/config.ru 0000644 0001750 0001750 00000000231 12247655524 024511 0 ustar ondrej ondrej # This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__)
run <%= app_const %>
railties-3.2.16/lib/rails/generators/rails/app/templates/gitignore 0000644 0001750 0001750 00000000656 12247655524 024621 0 ustar ondrej ondrej # See http://help.github.com/ignore-files/ for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile ~/.gitignore_global
# Ignore bundler config
/.bundle
# Ignore the default SQLite database.
/db/*.sqlite3
# Ignore all logfiles and tempfiles.
/log/*.log
/tmp
railties-3.2.16/lib/rails/generators/rails/app/templates/README 0000644 0001750 0001750 00000022004 12247655524 023556 0 ustar ondrej ondrej == Welcome to Rails
Rails is a web-application framework that includes everything needed to create
database-backed web applications according to the Model-View-Control pattern.
This pattern splits the view (also called the presentation) into "dumb"
templates that are primarily responsible for inserting pre-built data in between
HTML tags. The model contains the "smart" domain objects (such as Account,
Product, Person, Post) that holds all the business logic and knows how to
persist themselves to a database. The controller handles the incoming requests
(such as Save New Account, Update Product, Show Post) by manipulating the model
and directing data to the view.
In Rails, the model is handled by what's called an object-relational mapping
layer entitled Active Record. This layer allows you to present the data from
database rows as objects and embellish these data objects with business logic
methods. You can read more about Active Record in
link:files/vendor/rails/activerecord/README.html.
The controller and view are handled by the Action Pack, which handles both
layers by its two parts: Action View and Action Controller. These two layers
are bundled in a single package due to their heavy interdependence. This is
unlike the relationship between the Active Record and Action Pack that is much
more separate. Each of these packages can be used independently outside of
Rails. You can read more about Action Pack in
link:files/vendor/rails/actionpack/README.html.
== Getting Started
1. At the command prompt, create a new Rails application:
rails new myapp (where myapp is the application name)
2. Change directory to myapp and start the web server:
cd myapp; rails server (run with --help for options)
3. Go to http://localhost:3000/ and you'll see:
"Welcome aboard: You're riding Ruby on Rails!"
4. Follow the guidelines to start developing your application. You can find
the following resources handy:
* The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html
* Ruby on Rails Tutorial Book: http://www.railstutorial.org/
== Debugging Rails
Sometimes your application goes wrong. Fortunately there are a lot of tools that
will help you debug it and get it back on the rails.
First area to check is the application log files. Have "tail -f" commands
running on the server.log and development.log. Rails will automatically display
debugging and runtime information to these files. Debugging info will also be
shown in the browser on requests from 127.0.0.1.
You can also log your own messages directly into the log file from your code
using the Ruby logger class from inside your controllers. Example:
class WeblogController < ActionController::Base
def destroy
@weblog = Weblog.find(params[:id])
@weblog.destroy
logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
end
end
The result will be a message in your log file along the lines of:
Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1!
More information on how to use the logger is at http://www.ruby-doc.org/core/
Also, Ruby documentation can be found at http://www.ruby-lang.org/. There are
several books available online as well:
* Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe)
* Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
These two books will bring you up to speed on the Ruby language and also on
programming in general.
== Debugger
Debugger support is available through the debugger command when you start your
Mongrel or WEBrick server with --debugger. This means that you can break out of
execution at any point in the code, investigate and change the model, and then,
resume execution! You need to install ruby-debug to run the server in debugging
mode. With gems, use sudo gem install ruby-debug. Example:
class WeblogController < ActionController::Base
def index
@posts = Post.all
debugger
end
end
So the controller will accept the action, run the first line, then present you
with a IRB prompt in the server window. Here you can do things like:
>> @posts.inspect
=> "[#nil, "body"=>nil, "id"=>"1"}>,
#"Rails", "body"=>"Only ten..", "id"=>"2"}>]"
>> @posts.first.title = "hello from a debugger"
=> "hello from a debugger"
...and even better, you can examine how your runtime objects actually work:
>> f = @posts.first
=> #nil, "body"=>nil, "id"=>"1"}>
>> f.
Display all 152 possibilities? (y or n)
Finally, when you're ready to resume execution, you can enter "cont".
== Console
The console is a Ruby shell, which allows you to interact with your
application's domain model. Here you'll have all parts of the application
configured, just like it is when the application is running. You can inspect
domain models, change values, and save to the database. Starting the script
without arguments will launch it in the development environment.
To start the console, run rails console from the application
directory.
Options:
* Passing the -s, --sandbox argument will rollback any modifications
made to the database.
* Passing an environment name as an argument will load the corresponding
environment. Example: rails console production.
To reload your controllers and models after launching the console run
reload!
More information about irb can be found at:
link:http://www.rubycentral.org/pickaxe/irb.html
== dbconsole
You can go to the command line of your database directly through rails
dbconsole. You would be connected to the database with the credentials
defined in database.yml. Starting the script without arguments will connect you
to the development database. Passing an argument will connect you to a different
database, like rails dbconsole production. Currently works for MySQL,
PostgreSQL and SQLite 3.
== Description of Contents
The default directory structure of a generated Ruby on Rails application:
|-- app
| |-- assets
| | |-- images
| | |-- javascripts
| | `-- stylesheets
| |-- controllers
| |-- helpers
| |-- mailers
| |-- models
| `-- views
| `-- layouts
|-- config
| |-- environments
| |-- initializers
| `-- locales
|-- db
|-- doc
|-- lib
| |-- assets
| `-- tasks
|-- log
|-- public
|-- script
|-- test
| |-- fixtures
| |-- functional
| |-- integration
| |-- performance
| `-- unit
|-- tmp
| `-- cache
| `-- assets
`-- vendor
|-- assets
| |-- javascripts
| `-- stylesheets
`-- plugins
app
Holds all the code that's specific to this particular application.
app/assets
Contains subdirectories for images, stylesheets, and JavaScript files.
app/controllers
Holds controllers that should be named like weblogs_controller.rb for
automated URL mapping. All controllers should descend from
ApplicationController which itself descends from ActionController::Base.
app/models
Holds models that should be named like post.rb. Models descend from
ActiveRecord::Base by default.
app/views
Holds the template files for the view that should be named like
weblogs/index.html.erb for the WeblogsController#index action. All views use
eRuby syntax by default.
app/views/layouts
Holds the template files for layouts to be used with views. This models the
common header/footer method of wrapping views. In your views, define a layout
using the layout :default and create a file named default.html.erb.
Inside default.html.erb, call <% yield %> to render the view using this
layout.
app/helpers
Holds view helpers that should be named like weblogs_helper.rb. These are
generated for you automatically when using generators for controllers.
Helpers can be used to wrap functionality for your views into methods.
config
Configuration files for the Rails environment, the routing map, the database,
and other dependencies.
db
Contains the database schema in schema.rb. db/migrate contains all the
sequence of Migrations for your schema.
doc
This directory is where your application documentation will be stored when
generated using rake doc:app
lib
Application specific libraries. Basically, any kind of custom code that
doesn't belong under controllers, models, or helpers. This directory is in
the load path.
public
The directory available for the web server. Also contains the dispatchers and the
default HTML files. This should be set as the DOCUMENT_ROOT of your web
server.
script
Helper scripts for automation and generation.
test
Unit and functional tests along with fixtures. When using the rails generate
command, template test files will be generated for you and placed in this
directory.
vendor
External libraries that the application depends on. Also includes the plugins
subdirectory. If the app has frozen rails, those gems also go here, under
vendor/rails/. This directory is in the load path.
railties-3.2.16/lib/rails/generators/rails/app/templates/script/ 0000755 0001750 0001750 00000000000 12247655524 024204 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/app/templates/script/rails 0000644 0001750 0001750 00000000423 12247655524 025240 0 ustar ondrej ondrej # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
APP_PATH = File.expand_path('../../config/application', __FILE__)
require File.expand_path('../../config/boot', __FILE__)
require 'rails/commands'
railties-3.2.16/lib/rails/generators/rails/app/templates/Gemfile 0000644 0001750 0001750 00000001034 12247655524 024171 0 ustar ondrej ondrej source 'https://rubygems.org'
<%= rails_gemfile_entry -%>
<%= database_gemfile_entry -%>
<%= "gem 'jruby-openssl'\n" if defined?(JRUBY_VERSION) -%>
<%= "gem 'json'\n" if RUBY_VERSION < "1.9.2" -%>
<%= assets_gemfile_entry %>
<%= javascript_gemfile_entry %>
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# To use Jbuilder templates for JSON
# gem 'jbuilder'
# Use unicorn as the app server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# <%= ruby_debugger_gemfile_entry %>
railties-3.2.16/lib/rails/generators/rails/app/templates/doc/ 0000755 0001750 0001750 00000000000 12247655524 023445 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/app/templates/doc/README_FOR_APP 0000644 0001750 0001750 00000000323 12247655524 025531 0 ustar ondrej ondrej Use this README file to introduce your application and point to useful places in the API for learning more.
Run "rake doc:app" to generate API documentation for your models, controllers, helpers, and libraries.
railties-3.2.16/lib/rails/generators/rails/app/templates/db/ 0000755 0001750 0001750 00000000000 12247655524 023265 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/app/templates/db/seeds.rb.tt 0000644 0001750 0001750 00000000647 12247655524 025352 0 ustar ondrej ondrej # 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([{ <%= key_value :name, "'Chicago'" %> }, { <%= key_value :name, "'Copenhagen'" %> }])
# Mayor.create(<%= key_value :name, "'Emanuel'" %>, <%= key_value :city, "cities.first" %>)
railties-3.2.16/lib/rails/generators/rails/app/templates/app/ 0000755 0001750 0001750 00000000000 12247655524 023460 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/app/templates/app/mailers/ 0000755 0001750 0001750 00000000000 12247655524 025114 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/app/templates/app/mailers/.empty_directory 0000644 0001750 0001750 00000000000 12247655524 030325 0 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/app/templates/app/controllers/ 0000755 0001750 0001750 00000000000 12247655524 026026 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/app/templates/app/controllers/application_controller.rb 0000644 0001750 0001750 00000000120 12247655524 033112 0 ustar ondrej ondrej class ApplicationController < ActionController::Base
protect_from_forgery
end
railties-3.2.16/lib/rails/generators/rails/app/templates/app/helpers/ 0000755 0001750 0001750 00000000000 12247655524 025122 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/app/templates/app/helpers/application_helper.rb 0000644 0001750 0001750 00000000035 12247655524 031307 0 ustar ondrej ondrej module ApplicationHelper
end
railties-3.2.16/lib/rails/generators/rails/app/templates/app/models/ 0000755 0001750 0001750 00000000000 12247655524 024743 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/app/templates/app/models/.empty_directory 0000644 0001750 0001750 00000000000 12247655524 030154 0 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/app/templates/app/assets/ 0000755 0001750 0001750 00000000000 12247655524 024762 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/app/templates/app/assets/javascripts/ 0000755 0001750 0001750 00000000000 12247655524 027313 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt 0000644 0001750 0001750 00000001336 12247655524 032605 0 ustar ondrej ondrej // This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
<% unless options[:skip_javascript] -%>
//= require <%= options[:javascript] %>
//= require <%= options[:javascript] %>_ujs
<% end -%>
//= require_tree .
railties-3.2.16/lib/rails/generators/rails/app/templates/app/assets/images/ 0000755 0001750 0001750 00000000000 12247655524 026227 5 ustar ondrej ondrej railties-3.2.16/lib/rails/generators/rails/app/templates/app/assets/images/rails.png 0000644 0001750 0001750 00000014766 12247655524 030065 0 ustar ondrej ondrej PNG
IHDR 2 @ X${ tEXtSoftware Adobe ImageReadyqe<