-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
97 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails/console/app' | ||
require_relative './rails_console_commands/console_delegation' | ||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
14 changes: 6 additions & 8 deletions
14
...ls_console_commands/console_delegation.rb → lib/rails_console_commands/test_command.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(path, 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters