Class: Nova::Project
- Inherits:
-
Object
- Object
- Nova::Project
- Defined in:
- lib/nova/project.rb
Overview
A Nova project, containing the galaxy and configuration settings for that project.
Constant Summary collapse
- DEFAULT_PATHS =
The default paths to load from.
[File.absolute_path("../../../galaxy", __FILE__)]
Instance Attribute Summary collapse
-
#directory ⇒ Directory
readonly
The directory the project is based in.
-
#load_paths ⇒ Array<String>
readonly
The load paths for this project.
-
#options ⇒ Hash
readonly
The options that were loaded from the config for this project.
Class Method Summary collapse
-
.valid?(dir) ⇒ Boolean
Whether or not the given directory is deemable as a Nova project.
Instance Method Summary collapse
-
#initialize(dir, load_config = true) ⇒ Project
constructor
Initializes the project.
-
#load_config! ⇒ Hash
Loads the configuration file.
-
#require_files ⇒ void
Requires all of the star files that is in the project.
-
#run_servers(do_fork = true, which = []) ⇒ void
Runs the servers defined in the options.
-
#shoot(which = []) ⇒ void
Takes down running servers.
Constructor Details
#initialize(dir, load_config = true) ⇒ Project
Initializes the project. Loads the configuration file by default.
42 43 44 45 46 47 48 49 50 |
# File 'lib/nova/project.rb', line 42 def initialize(dir, load_config = true) @directory = Dir.new(dir) @load_paths = DEFAULT_PATHS.dup = {} if load_config load_config! end end |
Instance Attribute Details
#directory ⇒ Directory (readonly)
The directory the project is based in.
24 25 26 |
# File 'lib/nova/project.rb', line 24 def directory @directory end |
#load_paths ⇒ Array<String> (readonly)
The load paths for this project.
29 30 31 |
# File 'lib/nova/project.rb', line 29 def load_paths @load_paths end |
#options ⇒ Hash (readonly)
The options that were loaded from the config for this project.
34 35 36 |
# File 'lib/nova/project.rb', line 34 def end |
Class Method Details
.valid?(dir) ⇒ Boolean
Whether or not the given directory is deemable as a Nova project.
17 18 19 |
# File 'lib/nova/project.rb', line 17 def self.valid?(dir) Dir.new(dir).each.include?("nova.yml") end |
Instance Method Details
#load_config! ⇒ Hash
Loads the configuration file.
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/nova/project.rb', line 56 def load_config! return unless .empty? data = ::YAML.load_file(File.open("#{directory.path}/nova.yml", "r")) load_paths.push(*data.fetch("load_paths", [])) load_paths.map! do |path| File.absolute_path(path, directory.path) end = data end |
#require_files ⇒ void
This method returns an undefined value.
Requires all of the star files that is in the project.
72 73 74 75 76 77 78 |
# File 'lib/nova/project.rb', line 72 def require_files @load_paths.each do |path| Dir["#{path}/**/*"].each do |f| require f end end end |
#run_servers(do_fork = true, which = []) ⇒ void
If do_fork is false, only the first server in the config file will actually be created.
This method returns an undefined value.
Runs the servers defined in the options.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/nova/project.rb', line 89 def run_servers(do_fork = true, which = []) each_server(which) do |server, name| puts name if File.exists?(server[:files][:pid]) Nova.logger.warn { "PID file #{server[:files][:pid]} already exists. " + "Ignoring server definition." } next end if do_fork process_id = fork end if process_id File.open(server[:files][:pid], "w") { |f| f.write process_id } Process.detach(process_id) else return build_server(server, do_fork) end end end |
#shoot(which = []) ⇒ void
This method returns an undefined value.
Takes down running servers.
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/nova/project.rb', line 119 def shoot(which = []) each_server do |server, name| if File.exists?(server[:files][:pid]) pid = File.open(server[:files][:pid], "r") { |f| f.read }.to_i print "Sending INT to #{pid}... " Process.kill :INT, pid rescue Errno::ESRCH File.delete(server[:files][:pid]) rescue Errno::ENOENT puts "OK!" end end end |