Class: VMC::Cli::Framework

Inherits:
Object show all
Defined in:
lib/cli/frameworks.rb

Constant Summary collapse

DEFAULT_FRAMEWORK =
"http://b20nine.com/unknown"
DEFAULT_MEM =
'256M'
FRAMEWORKS =
{
  'Topaz'    => ['topaz',   { :mem => '128M', :description => 'Topaz for GemStone/S Application'}],
  'Rails'    => ['rails3',  { :mem => '256M', :description => 'Rails Application', :console=>true}],
  'Spring'   => ['spring',  { :mem => '512M', :description => 'Java SpringSource Spring Application'}],
  'Grails'   => ['grails',  { :mem => '512M', :description => 'Java SpringSource Grails Application'}],
  'Lift'   =>   ['lift',    { :mem => '512M', :description => 'Scala Lift Application'}],
  'JavaWeb'  => ['java_web',{ :mem => '512M', :description => 'Java Web Application'}],
  'Sinatra'  => ['sinatra', { :mem => '128M', :description => 'Sinatra Application'}],
  'Node'     => ['node',    { :mem => '64M',  :description => 'Node.js Application'}],
  'PHP'      => ['php',     { :mem => '128M', :description => 'PHP Application'}],
  'Erlang/OTP Rebar' => ['otp_rebar',  { :mem => '64M',  :description => 'Erlang/OTP Rebar Application'}],
  'WSGI'     => ['wsgi',    { :mem => '64M',  :description => 'Python WSGI Application'}],
  'Django'   => ['django',  { :mem => '128M', :description => 'Python Django Application'}],
  'Rack'     => ['rack', { :mem => '128M', :description => 'Rack Application'}]
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(framework = nil, opts = {}) ⇒ Framework

Returns a new instance of Framework.



129
130
131
132
133
134
135
# File 'lib/cli/frameworks.rb', line 129

def initialize(framework=nil, opts={})
  @name = framework || DEFAULT_FRAMEWORK
  @memory = opts[:mem] || DEFAULT_MEM
  @description = opts[:description] || 'Unknown Application Type'
  @exec = opts[:exec]
  @console = opts[:console] || false
end

Instance Attribute Details

#consoleObject (readonly)

Returns the value of attribute console.



124
125
126
# File 'lib/cli/frameworks.rb', line 124

def console
  @console
end

#descriptionObject (readonly)

Returns the value of attribute description.



124
125
126
# File 'lib/cli/frameworks.rb', line 124

def description
  @description
end

#execObject

Returns the value of attribute exec.



125
126
127
# File 'lib/cli/frameworks.rb', line 125

def exec
  @exec
end

#memoryObject (readonly) Also known as: mem

Returns the value of attribute memory.



124
125
126
# File 'lib/cli/frameworks.rb', line 124

def memory
  @memory
end

#nameObject (readonly)

Returns the value of attribute name.



124
125
126
# File 'lib/cli/frameworks.rb', line 124

def name
  @name
end

Class Method Details

.detect(path, available_frameworks) ⇒ Object



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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/cli/frameworks.rb', line 40

def detect(path, available_frameworks)
  Dir.chdir(path) do
    # Rails
    if File.exist?('config/environment.rb')
      return Framework.lookup('Rails')

    # Topaz
    elsif File.exist?('main.tpz') && available_frameworks.include?(["topaz"])
      return Framework.lookup('Topaz')

    # Rack
    elsif File.exist?('config.ru') && available_frameworks.include?(["rack"])
      return Framework.lookup('Rack')

    # Java
    elsif Dir.glob('*.war').first || File.exist?('WEB-INF/web.xml')
      war_file = Dir.glob('*.war').first

      if war_file
        contents = ZipUtil.entry_lines(war_file)
      else
        contents = Dir['**/*'].join("\n")
      end

      # Spring/Lift Variations
      if contents =~ /WEB-INF\/lib\/grails-web.*\.jar/
        return Framework.lookup('Grails')
      elsif contents =~ /WEB-INF\/lib\/lift-webkit.*\.jar/
        return Framework.lookup('Lift')
      elsif contents =~ /WEB-INF\/classes\/org\/springframework/
        return Framework.lookup('Spring')
      elsif contents =~ /WEB-INF\/lib\/spring-core.*\.jar/
        return Framework.lookup('Spring')
      elsif contents =~ /WEB-INF\/lib\/org\.springframework\.core.*\.jar/
        return Framework.lookup('Spring')
      else
        return Framework.lookup('JavaWeb')
      end
    # Simple Ruby Apps
    elsif !Dir.glob('*.rb').empty?
      matched_file = nil
      Dir.glob('*.rb').each do |fname|
        next if matched_file
        File.open(fname, 'r') do |f|
          str = f.read # This might want to be limited
          matched_file = fname if (str && str.match(/^\s*require[\s\(]*['"]sinatra['"]/))
        end
      end
      if matched_file
        f = Framework.lookup('Sinatra')
        f.exec = "ruby #{matched_file}"
        return f
      end

    # Node.js
    elsif !Dir.glob('*.js').empty?
      if File.exist?('server.js') || File.exist?('app.js') || File.exist?('index.js') || File.exist?('main.js')
        return Framework.lookup('Node')
      end

    # PHP
    elsif !Dir.glob('*.php').empty?
      return Framework.lookup('PHP')

    # Erlang/OTP using Rebar
    elsif !Dir.glob('releases/*/*.rel').empty? && !Dir.glob('releases/*/*.boot').empty?
      return Framework.lookup('Erlang/OTP Rebar')

    # Python Django
    # XXX: not all django projects keep settings.py in top-level directory
    elsif File.exist?('manage.py') && File.exist?('settings.py')
      return Framework.lookup('Django')

    # Python
    elsif !Dir.glob('wsgi.py').empty?
      return Framework.lookup('WSGI')

    end
  end
  nil
end

.known_frameworksObject



26
27
28
# File 'lib/cli/frameworks.rb', line 26

def known_frameworks
  FRAMEWORKS.keys
end

.lookup(name) ⇒ Object



30
31
32
# File 'lib/cli/frameworks.rb', line 30

def lookup(name)
  return Framework.new(*FRAMEWORKS[name])
end

.lookup_by_framework(name) ⇒ Object



34
35
36
37
38
# File 'lib/cli/frameworks.rb', line 34

def lookup_by_framework(name)
  FRAMEWORKS.each do |key,fw|
    return Framework.new(fw[0], fw[1]) if fw[0] == name
  end
end

Instance Method Details

#to_sObject



137
138
139
# File 'lib/cli/frameworks.rb', line 137

def to_s
  description
end