Class: Lescopr::Filesystem::ProjectAnalyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/lescopr/filesystem/project_analyzer.rb

Overview

Analyses the project directory and detects framework / stack.

Constant Summary collapse

FRAMEWORK_SIGNATURES =
{
  "rails"     => %w[config/application.rb app/controllers config/routes.rb Gemfile],
  "sinatra"   => %w[config.ru],
  "rack"      => %w[config.ru Gemfile],
  "hanami"    => %w[config/app.rb config/environment.rb],
  "padrino"   => %w[config/apps.rb],
  "grape"     => %w[Gemfile],
}.freeze
GEMFILE_PATTERNS =
{
  "rails"   => /gem\s+['"]rails['"]/,
  "sinatra" => /gem\s+['"]sinatra['"]/,
  "hanami"  => /gem\s+['"]hanami['"]/,
  "padrino" => /gem\s+['"]padrino['"]/,
  "grape"   => /gem\s+['"]grape['"]/,
  "rack"    => /gem\s+['"]rack['"]/,
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(root: Dir.pwd) ⇒ ProjectAnalyzer

Returns a new instance of ProjectAnalyzer.



25
26
27
# File 'lib/lescopr/filesystem/project_analyzer.rb', line 25

def initialize(root: Dir.pwd)
  @root = root
end

Instance Method Details

#analyzeHash

Returns payload for POST /api/v1/sdk/verify/.

Returns:

  • (Hash)

    payload for POST /api/v1/sdk/verify/



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/lescopr/filesystem/project_analyzer.rb', line 30

def analyze
  stack      = detect_stack
  ruby_ver   = RUBY_VERSION rescue "unknown"
  gemfile    = read_gemfile

  {
    project_name:    File.basename(@root),
    project_path:    @root,
    project_stack:   stack,
    language:        "ruby",
    language_version: ruby_ver,
    sdk_type:        "ruby",
    gemfile_present: File.exist?(File.join(@root, "Gemfile")),
    dependencies:    parse_gemfile_deps(gemfile),
    environment:     ENV.fetch("RAILS_ENV", ENV.fetch("RACK_ENV", "development"))
  }
end