├── .rspec ├── Rakefile ├── .travis.yml ├── lib ├── rails2_ruby2 │ ├── backport_ruby_config.rb │ ├── version.rb │ ├── action_view.rb │ ├── action_mailer.rb │ ├── active_model.rb │ ├── active_resource.rb │ ├── active_record.rb │ ├── active_support.rb │ ├── action_controller.rb │ ├── active_support │ │ ├── compressed_memcached_store_patch.rb │ │ ├── i18n_patch.rb │ │ └── erb_util_silence.rb │ ├── active_record │ │ ├── schema_statements.rb │ │ ├── postgresql_column.rb │ │ └── postgresql_adapter.rb │ └── action_controller │ │ └── named_route_collection_patch.rb └── rails2_ruby2.rb ├── spec ├── spec_helper.rb └── rails2_ruby2_spec.rb ├── Gemfile ├── .gitignore ├── bin ├── setup └── console ├── tags ├── rails2_ruby2.gemspec ├── LICENSE.txt ├── CODE_OF_CONDUCT.md └── README.md /.rspec: -------------------------------------------------------------------------------- 1 | --format documentation 2 | --color 3 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | rvm: 3 | - 2.2.1 4 | -------------------------------------------------------------------------------- /lib/rails2_ruby2/backport_ruby_config.rb: -------------------------------------------------------------------------------- 1 | Config = RbConfig 2 | -------------------------------------------------------------------------------- /lib/rails2_ruby2/version.rb: -------------------------------------------------------------------------------- 1 | module Rails2Ruby2 2 | VERSION = "1.0.3" 3 | end 4 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) 2 | require 'rails2_ruby2' 3 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in rails2_ruby2.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /lib/rails2_ruby2/action_view.rb: -------------------------------------------------------------------------------- 1 | # Add extensions to action_view/ directory 2 | 3 | # Shim for action_view extensions 4 | -------------------------------------------------------------------------------- /lib/rails2_ruby2/action_mailer.rb: -------------------------------------------------------------------------------- 1 | # Add extensions to action_mailer/ directory 2 | 3 | # Shim for action_mailer extensions 4 | -------------------------------------------------------------------------------- /lib/rails2_ruby2/active_model.rb: -------------------------------------------------------------------------------- 1 | # Add extensions to active_model/ directory 2 | 3 | # Shim for active_model extensions 4 | -------------------------------------------------------------------------------- /lib/rails2_ruby2/active_resource.rb: -------------------------------------------------------------------------------- 1 | # Add extensions to active_resource/ directory 2 | 3 | # Shim for active_resource extensions 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle/ 2 | /.yardoc 3 | /Gemfile.lock 4 | /_yardoc/ 5 | /coverage/ 6 | /doc/ 7 | /pkg/ 8 | /spec/reports/ 9 | /tmp/ 10 | -------------------------------------------------------------------------------- /lib/rails2_ruby2.rb: -------------------------------------------------------------------------------- 1 | require "rails2_ruby2/version" 2 | 3 | require 'rails2_ruby2/backport_ruby_config' 4 | 5 | module Rails2Ruby2 6 | end 7 | -------------------------------------------------------------------------------- /lib/rails2_ruby2/active_record.rb: -------------------------------------------------------------------------------- 1 | Dir[File.dirname(__FILE__) + '/active_record/**/*.rb'].each do |file| 2 | require file.chomp('.rb') 3 | end 4 | -------------------------------------------------------------------------------- /bin/setup: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -euo pipefail 3 | IFS=$'\n\t' 4 | 5 | bundle install 6 | 7 | # Do any other automated setup that you need to do here 8 | -------------------------------------------------------------------------------- /lib/rails2_ruby2/active_support.rb: -------------------------------------------------------------------------------- 1 | Dir[File.dirname(__FILE__) + '/active_support/**/*.rb'].each do |file| 2 | require file.chomp('.rb') 3 | end 4 | -------------------------------------------------------------------------------- /lib/rails2_ruby2/action_controller.rb: -------------------------------------------------------------------------------- 1 | Dir[File.dirname(__FILE__) + '/action_controller/**/*.rb'].each do |file| 2 | require file.chomp('.rb') 3 | end 4 | -------------------------------------------------------------------------------- /spec/rails2_ruby2_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe Rails2Ruby2 do 4 | it 'has a version number' do 5 | expect(Rails2Ruby2::VERSION).not_to be nil 6 | end 7 | 8 | it 'does something useful' do 9 | expect(false).to eq(true) 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/rails2_ruby2/active_support/compressed_memcached_store_patch.rb: -------------------------------------------------------------------------------- 1 | ActiveSupport::Cache::CompressedMemCacheStore.module_eval do 2 | def write(name, value, options = nil) 3 | value = ActiveSupport::Gzip.compress(Marshal.dump(value)).force_encoding('ascii') unless raw?(options) 4 | super(name, value, (options || {}).merge(:raw => true)) 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /bin/console: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require "bundler/setup" 4 | require "rails2_ruby2" 5 | 6 | # You can add fixtures and/or initialization code here to make experimenting 7 | # with your gem easier. You can also use a different console, if you like. 8 | 9 | # (If you use this, don't forget to add pry to your Gemfile!) 10 | # require "pry" 11 | # Pry.start 12 | 13 | require "irb" 14 | IRB.start 15 | -------------------------------------------------------------------------------- /tags: -------------------------------------------------------------------------------- 1 | !_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/ 2 | !_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/ 3 | !_TAG_PROGRAM_AUTHOR Darren Hiebert /dhiebert@users.sourceforge.net/ 4 | !_TAG_PROGRAM_NAME Exuberant Ctags // 5 | !_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/ 6 | !_TAG_PROGRAM_VERSION 5.8 // 7 | Rails2Ruby2 lib/rails2_ruby2.rb /^module Rails2Ruby2$/;" m 8 | Rails2Ruby2 lib/rails2_ruby2/version.rb /^module Rails2Ruby2$/;" m 9 | -------------------------------------------------------------------------------- /lib/rails2_ruby2/active_record/schema_statements.rb: -------------------------------------------------------------------------------- 1 | require 'active_record/connection_adapters/abstract/schema_statements' 2 | 3 | ActiveRecord::ConnectionAdapters::SchemaStatements.module_eval do 4 | def dump_schema_information #:nodoc: 5 | sm_table = "public.#{ActiveRecord::Migrator.schema_migrations_table_name}" 6 | migrated = select_values("SELECT version FROM #{sm_table} ORDER BY version") 7 | migrated.map { |v| "INSERT INTO #{sm_table} (version) VALUES ('#{v}');" }.join("\n\n") 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /lib/rails2_ruby2/active_record/postgresql_column.rb: -------------------------------------------------------------------------------- 1 | require 'active_record/connection_adapters/postgresql_adapter' 2 | 3 | ActiveRecord::ConnectionAdapters::PostgreSQLColumn.class_eval do 4 | class << self 5 | def extract_value_from_default_with_negative_integer_support(default) 6 | if default =~ /\A'(-?\d+(\.\d*)?\)?)'::integer\z/i 7 | $1 8 | else 9 | extract_value_from_default_without_negative_integer_support(default) 10 | end 11 | end 12 | 13 | alias_method_chain :extract_value_from_default, :negative_integer_support 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /lib/rails2_ruby2/active_support/i18n_patch.rb: -------------------------------------------------------------------------------- 1 | # This patch will no longer be necessary at Rails 3.2. See commit message 2 | # for more information. 3 | I18n::Backend::Base.class_eval do 4 | def load_file(filename) 5 | type = File.extname(filename).tr('.', '').downcase 6 | # As a fix added second argument as true to respond_to? method 7 | raise UnknownFileType.new(type, filename) unless respond_to?(:"load_#{type}", true) 8 | data = send(:"load_#{type}", filename) # TODO raise a meaningful exception if this does not yield a Hash 9 | data.each { |locale, d| store_translations(locale, d) } 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/rails2_ruby2/action_controller/named_route_collection_patch.rb: -------------------------------------------------------------------------------- 1 | ActionController::Routing::RouteSet::NamedRouteCollection.prepend(Module.new do 2 | private 3 | 4 | def define_hash_access(route, name, kind, options) 5 | super(route, name, kind, options).tap do 6 | selector = hash_access_name(name, kind) 7 | named_helper_module_eval "public :#{selector}" 8 | end 9 | end 10 | 11 | def define_url_helper(route, name, kind, options) 12 | super(route, name, kind, options).tap do 13 | selector = url_helper_name(name, kind) 14 | named_helper_module_eval "public :#{selector}" 15 | end 16 | end 17 | end) 18 | -------------------------------------------------------------------------------- /lib/rails2_ruby2/active_support/erb_util_silence.rb: -------------------------------------------------------------------------------- 1 | # from https://gist.github.com/grosser/599b47bea7f3c5a044cb 2 | # fixed in rails 3 by https://github.com/rails/rails/commit/4f12e3a3a5d28b63a74344cc8997b8466d276277 3 | # see https://github.com/rails/rails/issues/7430 4 | 5 | class ERB 6 | module Util 7 | def html_escape(s) 8 | s = s.to_s 9 | if s.html_safe? 10 | s 11 | else 12 | s.gsub(/[&"'><]/, HTML_ESCAPE).html_safe 13 | end 14 | end 15 | 16 | alias h html_escape 17 | 18 | singleton_class.send(:remove_method, :html_escape) 19 | module_function :html_escape, :h 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /rails2_ruby2.gemspec: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | lib = File.expand_path('../lib', __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | require 'rails2_ruby2/version' 5 | 6 | Gem::Specification.new do |spec| 7 | spec.name = "rails2_ruby2" 8 | spec.version = Rails2Ruby2::VERSION 9 | spec.authors = ["Andrew Warner", "Mat Brown"] 10 | spec.email = ["andrew@genius.com", "mat@genius.com"] 11 | 12 | spec.summary = %q{Patches to run rails 2 with ruby 2} 13 | spec.description = %q{Patches to run rails 2 with ruby 2} 14 | spec.homepage = "https://github.com/Genius/rails2_ruby2" 15 | spec.license = "MIT" 16 | 17 | spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } 18 | spec.require_paths = ["lib"] 19 | 20 | spec.add_development_dependency "bundler", "~> 1.8" 21 | spec.add_development_dependency "rake", "~> 10.0" 22 | 23 | spec.add_dependency "syck", "~> 1.4" 24 | spec.add_dependency 'iconv' 25 | 26 | spec.required_ruby_version = '~> 2.0' 27 | end 28 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Andrew Warner 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Code of Conduct 2 | 3 | As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities. 4 | 5 | We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion. 6 | 7 | Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct. 8 | 9 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team. 10 | 11 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers. 12 | 13 | This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/) 14 | -------------------------------------------------------------------------------- /lib/rails2_ruby2/active_record/postgresql_adapter.rb: -------------------------------------------------------------------------------- 1 | require 'active_record/connection_adapters/postgresql_adapter' 2 | 3 | ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.class_eval do 4 | def schema_search_path 5 | @schema_search_path ||= query('SHOW search_path')[0][0].split(',').map(&:strip).join(',') 6 | end 7 | 8 | # Resets the sequence of a table's primary key to the maximum value. 9 | def reset_pk_sequence!(table, pk = nil, sequence = nil) #:nodoc: 10 | unless pk and sequence 11 | default_pk, default_sequence = pk_and_sequence_for(table) 12 | 13 | pk ||= default_pk 14 | sequence ||= default_sequence 15 | end 16 | 17 | if @logger && pk && !sequence 18 | @logger.warn "#{table} has primary key #{pk} with no default sequence" 19 | end 20 | 21 | if pk && sequence 22 | quoted_sequence = quote_table_name(sequence) 23 | max_pk = select_value("SELECT MAX(#{quote_column_name pk}) FROM #{quote_table_name(table)}") 24 | if max_pk.nil? 25 | if postgresql_version >= 100000 26 | minvalue = select_value("SELECT seqmin FROM pg_sequence WHERE seqrelid = #{quote(quoted_sequence)}::regclass") 27 | else 28 | minvalue = select_value("SELECT min_value FROM #{quoted_sequence}") 29 | end 30 | end 31 | 32 | select_value <<-end_sql, 'SCHEMA' 33 | SELECT setval(#{quote(quoted_sequence)}, #{max_pk ? max_pk : minvalue}, #{max_pk ? true : false}) 34 | end_sql 35 | end 36 | end 37 | end 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Rails2Ruby2 2 | 3 | A collection of monkey-patches to make Rails 2 work on Ruby 2. 4 | 5 | ## Installation 6 | 7 | Add this line to your application's Gemfile: 8 | 9 | ```ruby 10 | gem 'rails2_ruby2' 11 | ``` 12 | 13 | And then execute: 14 | 15 | $ bundle 16 | 17 | Or install it yourself as: 18 | 19 | $ gem install rails2_ruby2 20 | 21 | ## Usage 22 | 23 | If you are using this gem in conjunction with the [Genius rails2 fork]('https://github.com/Genius/rails2') include the following line in your Gemfile: 24 | 25 | ```ruby 26 | gem "rails2_ruby2", "~>1.0" 27 | ``` 28 | 29 | If you are not using the Genius rails2 fork but are instead using something like [rails 2.3 lts](https://github.com/makandra/rails/tree/2-3-lts) you will need to add `rails2_ruby2` to your Gemfile as specified above and manually include the patches by component, e.g.: 30 | 31 | ```ruby 32 | require "rails2_ruby2/action_mailer" 33 | 34 | require "rails2_ruby2/action_pack" 35 | 36 | require "rails2_ruby2/action_view" 37 | 38 | require "rails2_ruby2/active_model" 39 | 40 | require "rails2_ruby2/active_record" 41 | 42 | require "rails2_ruby2/active_resource" 43 | 44 | require "rails2_ruby2/active_support" 45 | ``` 46 | 47 | 48 | ## Development 49 | 50 | After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment. 51 | 52 | To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). 53 | 54 | ## Contributing 55 | 56 | 1. Fork it ( https://github.com/[my-github-username]/rails2_ruby2/fork ) 57 | 2. Create your feature branch (`git checkout -b my-new-feature`) 58 | 3. Commit your changes (`git commit -am 'Add some feature'`) 59 | 4. Push to the branch (`git push origin my-new-feature`) 60 | 5. Create a new Pull Request 61 | --------------------------------------------------------------------------------