Class: VMC::Detector

Inherits:
Object
  • Object
show all
Defined in:
lib/vmc/detect.rb

Constant Summary collapse

PSEUDO_FRAMEWORKS =

“Basic” framework names for a detected language

{
  :node => "node",
  :python => "wsgi",
  :java => "java_web",
  :php => "php",
  :erlang => "otp_rebar",
  :dotnet => "dotNet"
}
FRAMEWORK_NAMES =

Mismatched framework names

{
  :rails => "rails3"
}
LANGUAGE_RUNTIMES =

Clouseau language symbol => matching runtime names

{
  :ruby => /^ruby.*/,
  :java => /^java.*/,
  :node => /^node.*/,
  :erlang => /^erlang.*/,
  :dotnet => /^dotNet.*/,
  :python => /^python.*/,
  :php => /^php.*/
}

Instance Method Summary collapse

Constructor Details

#initialize(client, path) ⇒ Detector

Returns a new instance of Detector.



34
35
36
37
# File 'lib/vmc/detect.rb', line 34

def initialize(client, path)
  @client = client
  @path = path
end

Instance Method Details

#all_frameworksObject

helper so that this is cached somewhere



76
77
78
# File 'lib/vmc/detect.rb', line 76

def all_frameworks
  @all_frameworks ||= @client.frameworks
end

#all_runtimesObject

helper so that this is cached somewhere



71
72
73
# File 'lib/vmc/detect.rb', line 71

def all_runtimes
  @all_runtimes ||= @client.runtimes
end

#detect_frameworkObject

detect the framework



40
41
42
# File 'lib/vmc/detect.rb', line 40

def detect_framework
  detected && frameworks[detected]
end

#detect_runtimesObject

detect the language and return the appropriate runtimes



45
46
47
48
49
50
51
# File 'lib/vmc/detect.rb', line 45

def detect_runtimes
  if detected && lang = detected.language_name
    runtimes_for(lang)
  else
    []
  end
end

#detectedObject



80
81
82
# File 'lib/vmc/detect.rb', line 80

def detected
  @detected ||= Clouseau.detect(@path)
end

#runtimes(framework) ⇒ Object

determine runtimes for a given framework based on the language its detector reports itself as



55
56
57
58
59
60
61
# File 'lib/vmc/detect.rb', line 55

def runtimes(framework)
  if detector = detectors[framework]
    runtimes_for(detector.language_name)
  else
    []
  end
end

#suggested_memory(framework) ⇒ Object

determine suitable memory allocation via the framework’s detector



64
65
66
67
68
# File 'lib/vmc/detect.rb', line 64

def suggested_memory(framework)
  if detector = detectors[framework]
    detector.memory_suggestion
  end
end