Skip to content

Commit

Permalink
Fix require "securerandom"
Browse files Browse the repository at this point in the history
  • Loading branch information
zw963 committed Mar 7, 2023
1 parent 94a955c commit ae77ff7
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
4 changes: 3 additions & 1 deletion bin/port_ruby_to_crystal
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ def replace(code)
code.gsub!(/(?<!Process\.)exec(?=(\s+|\()('|"))/, ' ::Process.exec')
code.gsub!(/\bFile\.mtime\((.*)\)/, 'File.info(\1).modification_time')
code.gsub!(/\bYAML\.load\b/, 'YAML.parse')
code.gsub!(/require (?:'|")fileutils(?:'|")(\s*)/, 'require "file_utils"\1')
code.gsub!(/\.respond_to\?(\s*)/, '.responds_to?\1')
code.gsub!(/\brequire_relative\b/, 'require')
code.gsub!(/require ("|')securerandom(\k<1>)$/, 'require "random/secure"')
code.gsub!(/require ('|")fileutils(\k<1>)$/, 'require "file_utils"')
code.gsub!(/\.include\?(\s*)/, '.includes?\1')
code.gsub!(/\.end_with\?(\s*)/, '.ends_with?\1')
code.gsub!(/\.start_with\?(\s*)/, '.starts_with?\1')
Expand Down Expand Up @@ -59,6 +60,7 @@ def replace(code)
code.gsub!(/<<~([A-Z_]+)/, '<<-\1')
code.gsub!(/\bENV\.key\?/, 'ENV.has_key?')
code.gsub!(/\bProcess\.clock_gettime\(Process::CLOCK_MONOTONIC\)/, 'Time.monotonic')
code.gsub!(/\bProcess\.clock_gettime\(Process::CLOCK_MONOTONIC\)/, 'Time.monotonic')
end

if ARGV[0] == '--test'
Expand Down
1 change: 1 addition & 0 deletions test/test.cr
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ __DIR__
File.read_lines("./test/test.rb")
require "file_utils"
require "file_utils"
require "random/secure"

File.info("./test/test.rb").modification_time

Expand Down
1 change: 1 addition & 0 deletions test/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Test
File.readlines("./test/test.rb")
require 'fileutils'
require "fileutils"
require "securerandom"

File.mtime("./test/test.rb")

Expand Down

0 comments on commit ae77ff7

Please sign in to comment.