Class: Cumuli::ProjectManager::Project
- Inherits:
-
Object
- Object
- Cumuli::ProjectManager::Project
- Defined in:
- lib/cumuli/project_manager/project.rb
Constant Summary collapse
- DEFAULT_WAIT_TIME =
10
- LOCALHOST =
'127.0.0.1'
Instance Attribute Summary collapse
-
#database_config ⇒ Object
readonly
Returns the value of attribute database_config.
-
#database_sample_config ⇒ Object
readonly
Returns the value of attribute database_sample_config.
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#repository ⇒ Object
readonly
Returns the value of attribute repository.
-
#setup_scripts ⇒ Object
readonly
Returns the value of attribute setup_scripts.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#wait_time ⇒ Object
readonly
Returns the value of attribute wait_time.
Instance Method Summary collapse
- #app_to_procfile ⇒ Object
- #database_config_paths ⇒ Object
- #database_configured?(path) ⇒ Boolean
- #database_sample_paths ⇒ Object
- #full_path(partial_path) ⇒ Object
-
#initialize(name, opts) ⇒ Project
constructor
A new instance of Project.
- #run_command(command) ⇒ Object
- #service_to_procfile ⇒ Object
- #setup ⇒ Object
- #socket_available? ⇒ Boolean
- #submodule_init ⇒ Object
- #to_procfile ⇒ Object
- #url ⇒ Object
- #wait? ⇒ Boolean
- #wait_for_start ⇒ Object
- #wait_for_stop ⇒ Object
- #write_database_config ⇒ Object
- #write_database_config! ⇒ Object
Constructor Details
#initialize(name, opts) ⇒ Project
Returns a new instance of Project.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# 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 |
Instance Attribute Details
#database_config ⇒ Object (readonly)
Returns the value of attribute database_config.
7 8 9 |
# File 'lib/cumuli/project_manager/project.rb', line 7 def database_config @database_config end |
#database_sample_config ⇒ Object (readonly)
Returns the value of attribute database_sample_config.
7 8 9 |
# File 'lib/cumuli/project_manager/project.rb', line 7 def database_sample_config @database_sample_config end |
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
7 8 9 |
# File 'lib/cumuli/project_manager/project.rb', line 7 def domain @domain end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/cumuli/project_manager/project.rb', line 7 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'lib/cumuli/project_manager/project.rb', line 7 def path @path end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
7 8 9 |
# File 'lib/cumuli/project_manager/project.rb', line 7 def port @port end |
#repository ⇒ Object (readonly)
Returns the value of attribute repository.
7 8 9 |
# File 'lib/cumuli/project_manager/project.rb', line 7 def repository @repository end |
#setup_scripts ⇒ Object (readonly)
Returns the value of attribute setup_scripts.
7 8 9 |
# File 'lib/cumuli/project_manager/project.rb', line 7 def setup_scripts @setup_scripts end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
7 8 9 |
# File 'lib/cumuli/project_manager/project.rb', line 7 def type @type end |
#wait_time ⇒ Object (readonly)
Returns the value of attribute wait_time.
7 8 9 |
# File 'lib/cumuli/project_manager/project.rb', line 7 def wait_time @wait_time end |
Instance Method Details
#app_to_procfile ⇒ Object
86 87 88 |
# File 'lib/cumuli/project_manager/project.rb', line 86 def app_to_procfile "#{name}: cumuli #{path} -p #{port}\n" end |
#database_config_paths ⇒ Object
62 63 64 |
# 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) ⇒ Boolean
66 67 68 |
# File 'lib/cumuli/project_manager/project.rb', line 66 def database_configured?(path) File.exist?(path) end |
#database_sample_paths ⇒ Object
58 59 60 |
# 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) ⇒ Object
53 54 55 56 |
# 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) ⇒ Object
98 99 100 101 102 |
# File 'lib/cumuli/project_manager/project.rb', line 98 def run_command(command) fork do CLI::RemoteCommand.new([command, "DIR=#{path}"]).perform end end |
#service_to_procfile ⇒ Object
90 91 92 |
# File 'lib/cumuli/project_manager/project.rb', line 90 def service_to_procfile "#{name}: cumuli #{path}\n" end |
#setup ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/cumuli/project_manager/project.rb', line 104 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? ⇒ Boolean
42 43 44 45 46 47 |
# File 'lib/cumuli/project_manager/project.rb', line 42 def socket_available? TCPSocket.new(domain, port) true rescue Errno::ECONNREFUSED false end |
#submodule_init ⇒ Object
94 95 96 |
# File 'lib/cumuli/project_manager/project.rb', line 94 def submodule_init system "git submodule add #{repository} #{path}" if repository end |
#to_procfile ⇒ Object
82 83 84 |
# File 'lib/cumuli/project_manager/project.rb', line 82 def to_procfile send("#{type}_to_procfile") rescue '' end |
#url ⇒ Object
49 50 51 |
# File 'lib/cumuli/project_manager/project.rb', line 49 def url "http://#{domain}#{port ? ":#{port}" : ''}" end |
#wait? ⇒ Boolean
28 29 30 |
# 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 ⇒ Object
32 33 34 35 |
# 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 ⇒ Object
37 38 39 40 |
# 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 ⇒ Object
76 77 78 79 80 |
# 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! ⇒ Object
70 71 72 73 74 |
# 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 |