Class: GenerateVhosts

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code_dir = "~/code") ⇒ GenerateVhosts

Returns a new instance of GenerateVhosts.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/generate_vhosts.rb', line 8

def initialize(code_dir="~/code")
  @vhosts = ""
  @hostname = Socket.gethostname.split('.').first
  @code_dir = code_dir
  Dir.chdir(File.expand_path(code_dir)) do
    Dir.glob("*").each do |subdir|
      @app_dir = subdir
      @vhosts << generate_vhost if is_web_app
    end
  end
  @vhosts
end

Instance Attribute Details

#vhostsObject

Returns the value of attribute vhosts.



6
7
8
# File 'lib/generate_vhosts.rb', line 6

def vhosts
  @vhosts
end

Instance Method Details

#generate_vhostObject



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

def generate_vhost
  template = ERB.new(File.read(File.join(File.dirname(__FILE__), "/template.vhost.erb")))
  template.result(binding)
end

#is_web_appObject



21
22
23
# File 'lib/generate_vhosts.rb', line 21

def is_web_app
  rack? || rails_legacy?
end

#rack?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/generate_vhosts.rb', line 25

def rack?
  File.exists?("./#{@app_dir}/config.ru") and File.directory?("./#{@app_dir}/public")
end

#rails_legacy?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/generate_vhosts.rb', line 29

def rails_legacy?
  File.exists?("./#{@app_dir}/config/boot.rb") and File.directory?("./#{@app_dir}/public")
end