Module: Fly::Scanner

Included in:
Actions
Defined in:
lib/fly.io-rails/scanner.rb

Instance Method Summary collapse

Instance Method Details

#scan_rails_appObject

scan for major features - things that if present will likely affect more than one artifact that is generated.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/fly.io-rails/scanner.rb', line 5

def scan_rails_app

  ### database ###

  database = YAML.load_file('config/database.yml').
    dig('production', 'adapter') rescue nil

  if database == 'sqlite3'
    @sqlite3 = true
  elsif database == 'postgresql'
    @postgresql = true
  elsif database == 'mysql' or database == 'mysql2'
    @mysql = true
  end

  ### ruby gems ###

  @gemfile = []

  if File.exist? 'Gemfile.lock'
    parser = Bundler::LockfileParser.new(Bundler.read_file('Gemfile.lock'))
    @gemfile += parser.specs.map { |spec, version| spec.name }
  end
  
  if File.exist? 'Gemfile'
    @gemfile += Bundler::Definition.build('Gemfile', nil, []).dependencies.map(&:name)
  end

  @sidekiq = @gemfile.include? 'sidekiq'
  @anycable = @gemfile.include? 'anycable-rails'
  @rmagick = @gemfile.include? 'rmagick'
  @image_processing = @gemfile.include? 'image_processing'
  @bootstrap = @gemfile.include? 'bootstrap'
  @puppeteer = @gemfile.include? 'puppeteer'

  ### node modules ###

  @package_json = []

  if File.exist? 'package.json'
    @package_json += JSON.load_file('package.json')['dependencies'].keys rescue []
  end

  @puppeteer ||= @package_json.include? 'puppeteer'

  ### cable/redis ###

  @cable = ! Dir['app/channels/*.rb'].empty?

  if @cable
    @redis_cable = true
    if (YAML.load_file('config/cable.yml').dig('production', 'adapter') rescue '').include? 'any_cable'
      @anycable = true
    end
  end

  if (IO.read('config/environments/production.rb') =~ /redis/i rescue false)
    @redis_cache = true
  end

  @redis = @redis_cable || @redis_cache || @sidekiq
end