Class: GenerateVhosts
- Inherits:
-
Object
- Object
- GenerateVhosts
- Defined in:
- lib/generate_vhosts.rb
Instance Attribute Summary collapse
-
#vhosts ⇒ Object
Returns the value of attribute vhosts.
Instance Method Summary collapse
- #generate_vhost ⇒ Object
-
#initialize(code_dir = "~/code") ⇒ GenerateVhosts
constructor
A new instance of GenerateVhosts.
- #is_web_app ⇒ Object
- #rack? ⇒ Boolean
- #rails_legacy? ⇒ Boolean
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.(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
#vhosts ⇒ Object
Returns the value of attribute vhosts.
6 7 8 |
# File 'lib/generate_vhosts.rb', line 6 def vhosts @vhosts end |
Instance Method Details
#generate_vhost ⇒ Object
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_app ⇒ Object
21 22 23 |
# File 'lib/generate_vhosts.rb', line 21 def is_web_app rack? || rails_legacy? end |
#rack? ⇒ 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
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 |