class Puman::AppList

Attributes

proxy_apps[RW]

Public Class Methods

new() click to toggle source
# File lib/puman/app.rb, line 16
def initialize
  @symlink_apps = []
  @proxy_apps = []
  Dir.chdir PUMA_DEV_DIR do
    Dir.glob('*').each do |file|
      if File.symlink?(file)
        @symlink_apps.push App.new(file, nil)
      else
        host_port = File.read(file)
        @proxy_apps.push App.new(file, host_port)
      end
    end
  end
  @proxy_max_length = @proxy_apps.map {|app| app.host_port.strip.size}.max
end

Public Instance Methods

include?(name) click to toggle source
# File lib/puman/app.rb, line 64
def include?(name)
  (@symlink_apps + @proxy_apps).map(&:name).include?(name)
end
list() click to toggle source
# File lib/puman/app.rb, line 32
def list
  string = []
  string << "-- symlink apps --"
  @symlink_apps.sort_by(&:name).each do |app|
    string << app.name
  end

  string << ''
  string << "-- proxy apps --"
  @proxy_apps.sort_by(&:host_port).each do |app|
    string << "#{app.host_port.strip.rjust(@proxy_max_length)} => #{app.name}"
  end
  string.join("\n")
end
server_command() click to toggle source
# File lib/puman/app.rb, line 47
def server_command
  name = File.basename(git_dir_or_current_dir)
  apps = @proxy_apps.select{|app| app.name == name}
  if apps.size == 1 && (app = apps.first).host_port.match(/^\d+$/)
    "WEBPACKER_DEV_SERVER_PORT=#{devserver_port(app)} WEBPACKER_DEV_SERVER_PUBLIC=localhost:#{devserver_port(app)} bundle exec rails server -p #{app.host_port}"
  end
end
webpack_dev_server_command() click to toggle source
# File lib/puman/app.rb, line 55
def webpack_dev_server_command
  name = File.basename(git_dir_or_current_dir)
  apps = @proxy_apps.select{|app| app.name == name}
  if apps.size == 1 && File.exists?(File.join(Dir.pwd, 'bin/webpack-dev-server'))
     app = apps.first
    "WEBPACKER_DEV_SERVER_PORT=#{devserver_port(app)} WEBPACKER_DEV_SERVER_PUBLIC=localhost:#{devserver_port(app)} ./bin/webpack-dev-server"
  end
end

Private Instance Methods

devserver_port(app) click to toggle source
# File lib/puman/app.rb, line 70
def devserver_port(app)
  (app.host_port.to_i + 10000).to_s
end
git_dir_or_current_dir() click to toggle source
# File lib/puman/app.rb, line 78
def git_dir_or_current_dir
  current_path = Dir.pwd
  until root_directory?(current_path)
    if File.exist?(File.join(current_path, '.git'))
      return current_path
    else
      current_path = File.dirname(current_path)
    end
  end
  Dir.pwd
end
root_directory?(path) click to toggle source
# File lib/puman/app.rb, line 74
def root_directory?(path)
  File.directory?(path) && File.expand_path(path) == File.expand_path(File.join(path, '..'))
end