class Uc::Paths
Attributes
app_dir[R]
Public Class Methods
new(app_dir)
click to toggle source
# File lib/uc/paths.rb, line 11 def initialize(app_dir) @app_dir = Pathname.new(app_dir ) end
Public Instance Methods
errors()
click to toggle source
# File lib/uc/paths.rb, line 35 def errors @errors ||= [] end
log_dir()
click to toggle source
# File lib/uc/paths.rb, line 19 def log_dir absolute_path "log" end
pid_dir()
click to toggle source
# File lib/uc/paths.rb, line 31 def pid_dir absolute_path "tmp/pids" end
rack()
click to toggle source
# File lib/uc/paths.rb, line 15 def rack absolute_path "config.ru" end
socket_dir()
click to toggle source
# File lib/uc/paths.rb, line 27 def socket_dir absolute_path "tmp/sockets" end
tmp_dir()
click to toggle source
# File lib/uc/paths.rb, line 23 def tmp_dir absolute_path "tmp" end
validate_required()
click to toggle source
# File lib/uc/paths.rb, line 39 def validate_required validate_required_dirs verify_readable rack log_and_raise_errors end
Private Instance Methods
absolute_path(path)
click to toggle source
# File lib/uc/paths.rb, line 97 def absolute_path(path) path = Pathname.new(path) raise "absolute path specified: #{path}" if path.absolute? "#{app_dir}/#{path}" end
log_and_raise_errors()
click to toggle source
# File lib/uc/paths.rb, line 47 def log_and_raise_errors if not errors.empty? errors.each { |e| logger.debug e } raise ::Uc::Error, "#{errors.first}" end end
required_dirs()
click to toggle source
# File lib/uc/paths.rb, line 54 def required_dirs [ app_dir, tmp_dir, log_dir, socket_dir, pid_dir ] end
rpath(abs_path)
click to toggle source
# File lib/uc/paths.rb, line 103 def rpath(abs_path) path = Pathname.new abs_path rel_path = path.relative_path_from(app_dir) end
throw_error(type, path)
click to toggle source
# File lib/uc/paths.rb, line 64 def throw_error(type, path) rel_path = rpath(path) case type when :not_exist msg = "path doesn't exist => #{rel_path}" when :not_writable msg = "path not writable => #{rel_path}" when :not_dir msg = "path not a directory => #{rel_path}" end throw :error, msg end
validate_dir(dir)
click to toggle source
# File lib/uc/paths.rb, line 77 def validate_dir(dir) relative_path = rpath(dir) error = catch(:error) do throw_error :not_exist, dir if not File.exist? dir throw_error :not_writable, dir if not File.writable? dir throw_error :not_dir, dir if not File.directory? dir end errors << error if error end
validate_required_dirs()
click to toggle source
# File lib/uc/paths.rb, line 58 def validate_required_dirs required_dirs.each do |d| validate_dir(d) end end
verify_readable(path)
click to toggle source
# File lib/uc/paths.rb, line 87 def verify_readable(path) relative_path = rpath(path) if not File.readable? path errors << "path not readable => #{relative_path}" return false else return true end end