Now Reading
Ruby (3.3) on Rails (1.0). · Weblog

Ruby (3.3) on Rails (1.0). · Weblog

2024-01-16 05:48:07

Rails 8.0 has not too long ago branched out on Github, and I discovered myself curious in regards to the feasibility of working Rails 1.0 on the most recent Ruby model. Whereas I used to be fairly positive it wouldn’t work proper off the bat, I questioned: what number of modifications can be essential to no less than attain the enduring “Welcome aboard! You’re driving the Rails!” display screen?

So, let’s dive in. My place to begin was this Gemfile:

supply "https://rubygems.org"
gem "rails", "1.0.0"

Since I knew that it will be required to make some adjustments to Rails gems I set up it with bundle set up --local. This could permit for simpler modifications afterward. My first try was working bundle exec rails --help:

/activesupport-1.2.5/lib/active_support/inflector.rb:157: syntax error, surprising ':', anticipating `then' or ',' or ';' or 'n' (SyntaxError)
        when 1: "#{quantity}st"
              ^

Certainly, older Ruby variations allowed the usage of a colon rather than then in case/when expressions. This syntax is not supported, so I up to date it throughout the codebase to match the present Ruby syntax.

Okay let’s attempt once more with bundle exec rails --help:

can not load such file -- parsedate (LoadError)

Oh yeah, parsedate lib that was shipped with Ruby 1.8 just isn’t longer there. It was used to parse date strings, like so:

ParseDate.parsedate "Tuesday, July fifth, 2007, 18:35:20 UTC"
# => [2007, 7, 5, 18, 35, 20, "UTC", 2]

Undecided why it was returning an array however okay. Now I can substitute it with DateTime.parse that returns DateTime object. So I’ve fastened that and tried to run it once more. Ugh, one other error:

rails-1.0.0/lib/rails_generator/choices.rb:124: syntax error, surprising '[', expecting '|' (SyntaxError)
...make any changes.') options[:pretend]

That’s some bizarre syntax. Seems you can assign one thing to a hash proper contained in the block variable factor:

decide.on('-p', '--pretend', 'Run however don't make any adjustments.')  

that means that no matter you cross as -p possibility will find yourself being assigned to choices[:pretend]. Principally it equals to

decide.on('-p', '--pretend', 'Run however don't make any adjustments.')  choices[:pretend] = o 

Alrighty then. Rerun bundle exec rails --help:

no implicit conversion of Enumerator into Array

And it’s with none stacktrace. Nice. Seems to be like one thing catches all of the errors and simply prints them. After
some investigation I’ve discovered this code:

def cache
  @cache ||= sources.inject([]) cache, supply
finish

In Ruby 1.8 [].map would return an array however now it returns Enumerator object and you’ll concat an Array with
Enumerator therefore the error:

irb(foremost):001> [] + [].map
(irb):1:in `+': no implicit conversion of Enumerator into Array (TypeError)

It’s a straightforward repair although. Let’s simply name .to_a on the supply:

def cache
  @cache ||= sources.inject([]) cache, supply
finish

Are we getting there?

bundle exec rails --help

`load': can not load such file -- config.rb (LoadError)

The code in query is

require 'rbconfig'

DEFAULT_SHEBANG = File.be a part of(Config::CONFIG['bindir'],
                            Config::CONFIG['ruby_install_name'])

Is sensible, in previous Ruby RbConfig might be referenced with Config fixed and now it’s solely RbConfig. Fastened. Does it work now?

bundle exec rails --help

Utilization: /vendor/bundle/ruby/3.3.0/bin/rails /path/to/your/app [options]

Nice Scott! It really works! Let’s attempt to generate a brand new app:

bundle exec rails weblog

undefined technique `exists?' for sophistication File

Dammit, File.exists?/FileTest.exists? had been eliminated in Ruby 1.9. Let’s substitute it with File.exist?/FileTest.exist? and take a look at once more:

bundle exec rails weblog
      create
      create  app/controllers
      create  app/helpers
      create  app/fashions
      create  app/views/layouts
      create  config/environments
      create  elements
      create  db
      create  doc
      create  lib
      create  lib/duties
      create  log
      create  public/pictures
      create  public/javascripts
      create  public/stylesheets
      create  script/efficiency
      create  script/course of
      create  take a look at/fixtures
      create  take a look at/purposeful
      create  take a look at/mocks/improvement
      create  take a look at/mocks/take a look at
      create  take a look at/unit
      create  vendor
      create  vendor/plugins
      create  Rakefile
      create  README
      create  app/controllers/software.rb
Can't create Binding object for non-Ruby caller

Success! Is it although? It has generated an app however all of the information are empty. And you probably have a pointy eye you’ll have seen this error:

Can't create Binding object for non-Ruby caller

Once more, no stacktracks, just a few plain error. It took me a while to find that line of code that was failing with such error however right here it’s:

file(relative_source, relative_destination, template_options) do |file|
  # Consider any assignments in a short lived, throwaway binding.
  vars = template_options[:assigns] || {}
  b = binding
  vars.every { |ok,v| eval "#{ok} = vars[:#{k}] || vars['#{k}']", b }

  ...
finish

Consider me, I actually tried to determine you what this error was about on condition that it’s clearly a Ruby caller however luck wasn’t there for me. Then I attempted to interchange binding with Kernel.binding
and it labored… If you realize what’s occurring right here please let me know! Perhaps Rails had been redefining binding someplace?

Alright, let’s proceed:

bundle exec rails weblog
      create
      create  app/controllers
      create  app/helpers
      create  app/fashions
      ...

Lastly! The app is generated, information should not empty. We’re shut, I can scent it! Let’s attempt to begin it:

 bundle exec ruby script/server -p 3001

`require': can not load such file -- script/../config/boot (LoadError)

Certain, just a few random load error. Seems in Ruby 1.8 you can require a file with relative to present file path and now you possibly can’t:

# In Ruby 1.8
require File.dirname(__FILE__) + '/../config/boot'

# In Ruby 1.9+
require_relative '../config/boot'

With this one fastened we will attempt it yet another time:

bundle exec ruby script/server -p 3001

=> Booting WEBrick...

activerecord-1.13.2/lib/active_record/base.rb:708: round argument reference - table_name (SyntaxError)

Okay this one must be trivial. The code in query:

See Also

def class_name(table_name = table_name)
  ...
finish

I’m a bit stunned that this was working in Ruby 1.8. The error is fairly self-explanatory so I simply renamed default argument worth and continued with my life:

bundle exec ruby script/server -p 3001

=> Booting WEBrick...

`load': can not load such file -- big_decimal.rb (LoadError)
Did you imply?  bigdecimal

Proper, bigdecimal just isn’t required by default now. I’ll spare you a while and say that there was the identical challenge
with rexml and net-smtp gems (net-smtp just isn’t even a part of Ruby anymore and I had so as to add it to the Gemfile). So I fastened it and tried once more:

bundle exec ruby script/server -p 3001

=> Booting WEBrick...
actionmailer-1.1.5/lib/action_mailer/quoting.rb:22: invalid multibyte escape: /[00-11131416-37177-377]/ (SyntaxError)

Oh yeah, Ruby 1.9 did loads of adjustments to string encoding (you possibly can learn extra on this here) and now utilizing uncooked bytes doesn’t work anymore. So I consider we will convert it to /[x00-x11x13x14x16-x1Fx7F-xFF]/n and it’s going to work? Properly, no less than the problem was fastened (yeah, yeah who cares if we’ve simply launched some vulnerability? I don’t):

bundle exec ruby script/server -p 3001

=> Booting WEBrick...
`require': can not load such file -- cleaning soap/rpc/driver (LoadError)

Oh ffs. It comes from action_web_service (god is aware of what was that again within the days) and fortunate us we will take away this Rails part
from our stack with this config:

# Skip frameworks you are not going to make use of
config.frameworks -= [ :action_web_service ]

image

bundle exec ruby script/server -p 3001

=> Booting WEBrick...
`require': can not load such file -- cleaning soap/rpc/driver (LoadError)

rails-1.0.0/lib/rails_info.rb:8: syntax error, surprising ')' (SyntaxError)
        map  identify

Cool cool, you can do .map param1 in Ruby 1.8 to ommit the second block param. You may really do it in Ruby 3.3 however you don’t want this additional comma:

{a: 1, b: 2, c: 3}.map  a  # => [:a, :b, :c]
# or
{a: 1, b: 2, c: 3}.map (a) # => [:a, :b, :c]
# with out
{a: 1, b: 2, c: 3}.map a # =>[[:a, 1], [:b, 2], [:c, 3]]

And yet another time…

bundle exec ruby script/server -p 3001

=> Booting WEBrick...
[2024-01-15 21:23:25] INFO  WEBrick 1.8.1
[2024-01-15 21:23:25] INFO  ruby 3.3.0 (2023-12-25) [arm64-darwin23]
[2024-01-15 21:23:25] INFO  WEBrick::HTTPServer#begin: pid=98161 port=3001

Oh my God, we did it!

Screenshot 2024-01-15 at 21 24 54

If for some purpose you wish to verify the code right here it’s: https://github.com/nashby/rails-from-the-past

I’m fairly positive there are far more points to repair to make it work correctly however I’m not going to do it.
I’m simply blissful sufficient that I’ve bought to the purpose the place I can see this greeting display screen! Fin.

And will Ruby be with you!

Source Link

What's Your Reaction?
Excited
0
Happy
0
In Love
0
Not Sure
0
Silly
0
View Comments (0)

Leave a Reply

Your email address will not be published.

2022 Blinking Robots.
WordPress by Doejo

Scroll To Top