Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support and require Rails 7.2 #2

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions lib/rails_console_commands.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
# frozen_string_literal: true

require 'rails/console/app'
require_relative './rails_console_commands/console_delegation'
require "irb"
require_relative './rails_console_commands/test_command'
require_relative './rails_console_commands/rake_command'
require_relative './rails_console_commands/generate_command'
require_relative './rails_console_commands/destroy_command'
require_relative './rails_console_commands/update_command'
require_relative './rails_console_commands/version'

Rails::ConsoleMethods.send :include, RailsConsoleCommands::ConsoleDelegation
IRB::Command.register(:test, RailsConsoleCommands::TestCommand)
IRB::Command.register(:rake, RailsConsoleCommands::RakeCommand)
IRB::Command.register(:generate, RailsConsoleCommands::GenerateCommand)
IRB::Command.register(:destroy, RailsConsoleCommands::DestroyCommand)
IRB::Command.register(:update, RailsConsoleCommands::UpdateCommand)
20 changes: 20 additions & 0 deletions lib/rails_console_commands/arg_parser.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

module RailsConsoleCommands
module ArgParser
def parse_arg(arg)
# IRB parses the arg differently for single and double quotes strings. E.g.
# test 'foo' -> "'foo'"
# test "foo" -> "\"foo\""
# test 'foo', 10 -> "'foo', 10"
# test "foo", 10 -> "\"foo\", 10"
arg = arg.strip
arg = arg.delete("'") # handle single quote case
begin
JSON.parse(arg) # handle double quote case
rescue JSON::ParserError
arg
end
end
end
end
4 changes: 4 additions & 0 deletions lib/rails_console_commands/commander.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

module RailsConsoleCommands
class Commander
def self.commander
@commander ||= Commander.new
end

delegate :rake, to: :raker
delegate :test, to: :tester
delegate :generate, :destroy, :update, to: :generator
Expand Down
14 changes: 14 additions & 0 deletions lib/rails_console_commands/destroy_command.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

require_relative './arg_parser'
require_relative './commander'

module RailsConsoleCommands
class DestroyCommand < IRB::Command::Base
include ArgParser

def execute(arg)
Commander.commander.destroy(parse_arg(arg))
end
end
end
14 changes: 14 additions & 0 deletions lib/rails_console_commands/generate_command.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

require_relative './arg_parser'
require_relative './commander'

module RailsConsoleCommands
class GenerateCommand < IRB::Command::Base
include ArgParser

def execute(arg)
Commander.commander.generate(parse_arg(arg))
end
end
end
14 changes: 14 additions & 0 deletions lib/rails_console_commands/rake_command.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

require_relative './arg_parser'
require_relative './commander'

module RailsConsoleCommands
class RakeCommand < IRB::Command::Base
include ArgParser

def execute(arg)
Commander.commander.rake(parse_arg(arg))
end
end
end
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
# frozen_string_literal: true

require_relative './arg_parser'
require_relative './commander'

module RailsConsoleCommands
module ConsoleDelegation
def commander
@commander ||= Commander.new
end
class TestCommand < IRB::Command::Base
include ArgParser

def test(*args)
def execute(arg)
if Rails.env.test?
commander.test(*args)
what, line = arg.split(',').map{ |a| parse_arg(a) }
Commander.commander.test(what, line)
else
puts 'You can only run tests in a console started in the test environment. ' \
'Use `rails console test` to start such a console'
end
end

delegate :rake, :generate, :destroy, :update, to: :commander
end
end
14 changes: 14 additions & 0 deletions lib/rails_console_commands/update_command.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

require_relative './arg_parser'
require_relative './commander'

module RailsConsoleCommands
class UpdateCommand < IRB::Command::Base
include ArgParser

def execute(arg)
Commander.commander.update(parse_arg(arg))
end
end
end
3 changes: 2 additions & 1 deletion rails_console_commands.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'rubocop', '~> 0.49'

spec.add_dependency 'railties', '>= 5'
spec.add_dependency 'irb', '>= 1.13'
spec.add_dependency 'railties', '>= 7.2'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to figure out a better way to do this so we can point to it, 7.2.0.alpha is < 7.2.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverting for now so I can point to this to run tests locally.

Copy link
Author

@joshuay03 joshuay03 May 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a TODO, pointing payaus to this branch for now, once 7.2 is out need to merge this + point payaus to master.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

7-2-stable is pretty stable now, I think we can lock this in.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can merge this if we want but need to be careful not to delete the branch cause payaus points to this. Might be safer to just leave as is though.

end