Class: Rails::Worktrees::BrowserCommand
- Inherits:
-
Object
- Object
- Rails::Worktrees::BrowserCommand
- Defined in:
- lib/rails/worktrees/browser_command.rb
Overview
Opens the current app/worktree in a browser using the local DEV_PORT. rubocop:disable Metrics/ClassLength
Constant Summary collapse
- APP_ROOT_ENV_KEY =
'RAILS_WORKTREES_APP_ROOT'.freeze
- ENV_FILE_NAME =
'.env'.freeze
- FILE_ENCODING =
'UTF-8'.freeze
Instance Method Summary collapse
-
#initialize(argv:, io:, env:, cwd:, host_os: RbConfig::CONFIG['host_os']) ⇒ BrowserCommand
constructor
A new instance of BrowserCommand.
- #run ⇒ Object
Constructor Details
#initialize(argv:, io:, env:, cwd:, host_os: RbConfig::CONFIG['host_os']) ⇒ BrowserCommand
Returns a new instance of BrowserCommand.
13 14 15 16 17 18 19 20 21 |
# File 'lib/rails/worktrees/browser_command.rb', line 13 def initialize(argv:, io:, env:, cwd:, host_os: RbConfig::CONFIG['host_os']) @argv = argv.dup @stdin = io.fetch(:stdin) @stdout = io.fetch(:stdout) @stderr = io.fetch(:stderr) @env = env @cwd = cwd @host_os = host_os end |
Instance Method Details
#run ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rails/worktrees/browser_command.rb', line 23 def run = return unless .nil? return usage_error if @argv.length > 1 url = build_url(@argv.first) open_browser(url) @stdout.puts("🌐 Opening #{url}") 0 rescue Error => e @stderr.puts("Error: #{e.}") 1 end |