class Cumuli::ProjectManager::Project
Constants
- DEFAULT_WAIT_TIME
- LOCALHOST
Attributes
database_config[R]
database_sample_config[R]
domain[R]
name[R]
path[R]
port[R]
repository[R]
setup_scripts[R]
type[R]
wait_time[R]
Public Class Methods
new(name, opts)
click to toggle source
# File lib/cumuli/project_manager/project.rb, line 10 def initialize(name, opts) @name = name @repository = opts['repository'] @path = opts['path'] || "./#{name}" @port = opts['port'] @type = opts['type'] || 'app' @wait_time = opts['wait_time'] || DEFAULT_WAIT_TIME @domain = opts['domain'] || '127.0.0.1' @database_config = opts['database_config'] || [] @database_sample_config = opts['database_sample_config'] || [] @setup_scripts = opts['setup_scripts'] || [] @database_config = [@database_config] unless @database_config.is_a?(Array) @database_sample_config = [@database_sample_config] unless @database_sample_config.is_a?(Array) end
Public Instance Methods
app_to_procfile()
click to toggle source
# File lib/cumuli/project_manager/project.rb, line 86 def app_to_procfile "#{name}: cumuli #{path} -p #{port}\n" end
database_config_paths()
click to toggle source
# File lib/cumuli/project_manager/project.rb, line 62 def database_config_paths database_config.map { |config_path| full_path("#{path}/#{config_path}") } end
database_configured?(path)
click to toggle source
# File lib/cumuli/project_manager/project.rb, line 66 def database_configured?(path) File.exist?(path) end
database_sample_paths()
click to toggle source
# File lib/cumuli/project_manager/project.rb, line 58 def database_sample_paths database_sample_config.map { |config_path| full_path("#{path}/#{config_path}") } end
full_path(partial_path)
click to toggle source
# File lib/cumuli/project_manager/project.rb, line 53 def full_path(partial_path) partial_path.gsub!(/^\.\//, '') "#{Dir.pwd}/#{partial_path}" end
run_command(command)
click to toggle source
# File lib/cumuli/project_manager/project.rb, line 98 def run_command(command) puts "#{ANSI.blue_on_red} #{name}: #{command} #{ANSI.ansi}" pid = fork do CLI::RemoteCommander.new(command, path).perform end Process.wait pid end
service_to_procfile()
click to toggle source
# File lib/cumuli/project_manager/project.rb, line 90 def service_to_procfile "#{name}: cumuli #{path}\n" end
setup()
click to toggle source
# File lib/cumuli/project_manager/project.rb, line 106 def setup # checkout master, because sometimes on setup no branch is # checked out run_command 'git checkout master' write_database_config setup_scripts.each do |script| run_command script end end
socket_available?()
click to toggle source
# File lib/cumuli/project_manager/project.rb, line 42 def socket_available? TCPSocket.new(domain, port) true rescue Errno::ECONNREFUSED false end
submodule_init()
click to toggle source
# File lib/cumuli/project_manager/project.rb, line 94 def submodule_init system "git submodule add #{repository} #{path}" if repository end
to_procfile()
click to toggle source
# File lib/cumuli/project_manager/project.rb, line 82 def to_procfile send("#{type}_to_procfile") rescue '' end
url()
click to toggle source
# File lib/cumuli/project_manager/project.rb, line 49 def url "http://#{domain}#{port ? ":#{port}" : ''}" end
wait?()
click to toggle source
# File lib/cumuli/project_manager/project.rb, line 28 def wait? type == 'app' && (wait_time && wait_time > 0) && (port || domain != LOCALHOST) end
wait_for_start()
click to toggle source
# File lib/cumuli/project_manager/project.rb, line 32 def wait_for_start return unless wait? Waiter.new("Unable to start #{name}").wait_until(wait_time) { socket_available? } end
wait_for_stop()
click to toggle source
# File lib/cumuli/project_manager/project.rb, line 37 def wait_for_stop return unless wait? Waiter.new("Unable to stop #{name}").wait_until(wait_time) { !socket_available? } end
write_database_config()
click to toggle source
# File lib/cumuli/project_manager/project.rb, line 76 def write_database_config database_config_paths.each_with_index do |config_path, i| FileUtils.cp(database_sample_paths[i], config_path) unless database_configured?(config_path) end end
write_database_config!()
click to toggle source
# File lib/cumuli/project_manager/project.rb, line 70 def write_database_config! database_config_paths.each_with_index do |config_path, i| FileUtils.cp(database_sample_paths[i], config_path) end end