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.



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

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

Instance Method Details

#all_frameworksObject

helper so that this is cached somewhere



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

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

#all_runtimesObject

helper so that this is cached somewhere



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

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

#detect_frameworkObject

detect the framework



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

def detect_framework
  detected && frameworks[detected]
end

#detect_runtimesObject

detect the language and return the appropriate runtimes



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

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

#detectedObject



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

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



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

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



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

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