Class: CaptiveStackDetector::GemfileAnalyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/captive_stack_detector/gemfile_analyzer.rb

Constant Summary collapse

ASSET_GEMS =
%w[
  sprockets sprockets-rails propshaft importmap-rails
  cssbundling-rails jsbundling-rails dartsass-rails tailwindcss-rails
].freeze
REDIS_GEMS =
%w[redis redis-client sidekiq].freeze

Instance Method Summary collapse

Constructor Details

#initialize(gemfile) ⇒ GemfileAnalyzer

Returns a new instance of GemfileAnalyzer.



12
13
14
# File 'lib/captive_stack_detector/gemfile_analyzer.rb', line 12

def initialize(gemfile)
  @gemfile = gemfile
end

Instance Method Details

#databaseObject



18
# File 'lib/captive_stack_detector/gemfile_analyzer.rb', line 18

def database = gem?("pg") ? "postgres" : nil

#queueObject



19
# File 'lib/captive_stack_detector/gemfile_analyzer.rb', line 19

def queue    = REDIS_GEMS.any? { |g| gem?(g) } ? "redis" : nil

#rails?Boolean

Returns:

  • (Boolean)


16
# File 'lib/captive_stack_detector/gemfile_analyzer.rb', line 16

def rails?   = gem?("rails")

#subtypeObject



17
# File 'lib/captive_stack_detector/gemfile_analyzer.rb', line 17

def subtype  = ASSET_GEMS.any? { |g| gem?(g) } ? "app" : "api"

#worker_command(procfile) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/captive_stack_detector/gemfile_analyzer.rb', line 21

def worker_command(procfile)
  if procfile
    procfile.each_line do |line|
      m = line.match(/^worker:\s*(.+)$/)
      return m[1].strip if m
    end
  end
  gem?("sidekiq") ? "bundle exec sidekiq" : nil
end