Skip to content

Commit

Permalink
Merge pull request #3 from prog-supdex/show_required_thruster_message
Browse files Browse the repository at this point in the history
add a notification about a required "thruster"
  • Loading branch information
palkan authored Jul 8, 2024
2 parents 0485439 + c65399c commit 1587ce7
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ This gem makes it possible to use [Thruster][] as a Capybara server. Run your br
## Getting started

### Prerequisites

Before adding the gem to your project, ensure you have either `thruster` or `anycable-thruster` installed. You can add one of these gems to your `Gemfile`:

```ruby
# For thruster
gem "thruster"

# or for anycable-thruster
gem "anycable-thruster"
```

Adding the gem to your project:

```ruby
Expand Down
30 changes: 30 additions & 0 deletions lib/capybara/dependency_checker.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true

module Capybara
module Thruster
class DependencyChecker
def self.call
new.call
end

def call
unless thruster_installed?
warn "*********************************************************"
warn "Warning: capybara-thruster requires either 'thruster' or 'anycable-thruster' gem."
warn "Please install one of them to ensure proper functionality."
warn "*********************************************************"
end
end

private

def thruster_installed?
gem_installed?("thruster") || gem_installed?("anycable-thruster")
end

def gem_installed?(name)
Gem::Specification.find_all_by_name(name).any?
end
end
end
end
4 changes: 4 additions & 0 deletions lib/capybara/thruster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

require "childprocess"
require "capybara"
require "capybara/dependency_checker"
require "rack/handler"

Capybara::Thruster::DependencyChecker.call

# Replaces the default Puma server on CAPYBARA_SERVER_PORT port with Thruster server.
# Requests are proxied to the Puma server running on the internal port (CAPYBARA_SERVER_PORT + 1).
Expand Down

0 comments on commit 1587ce7

Please sign in to comment.