lib/vex/base/app.rb in vex-0.3.3 vs lib/vex/base/app.rb in vex-0.4.2
- old
+ new
@@ -23,28 +23,33 @@
def self.development?
env == "development"
end
- def self.production?
+ def self.production?
env == "production"
end
def self.test?
env == "test"
end
def self.root
- if defined?(RAILS_ROOT)
- RAILS_ROOT
- elsif defined?(APP_ROOT)
- APP_ROOT
- else
- raise "Cannot determine application root"
+ @root ||= begin
+ if defined?(RAILS_ROOT)
+ RAILS_ROOT
+ elsif defined?(APP_ROOT)
+ APP_ROOT
+ elsif defined?($0)
+ File.expand_path File.dirname($0)
+ else
+ raise "Cannot determine application root"
+ end
end
end
+
def self.logger
if rails?
RAILS_DEFAULT_LOGGER
else
require "logger"
@@ -58,19 +63,29 @@
def self.tmpdir
@tmpdir ||= begin
tmpdir = if rails?
"#{root}/tmp"
else
- ENV["TMPDIR"]
+ ENV["TMPDIR"] || "/tmp"
end
tmpdir = tmpdir.gsub(/\/$/, "")
raise "Cannot determine tmpdir setting" if tmpdir.blank?
tmpdir
end
end
-
+
+ #
+ # make a sub dir
+ def subdir(path, *parts)
+ parts.unshift path
+ path = "#{root}/#{parts.join("/")}"
+ return path if File.exists?(path)
+ dlog "Creating dir #{path}"
+ FileUtils.mkdir_p(path)
+ end
+
def self.local_conf
@local_conf = nil if App.env == "development"
@local_conf ||= LocalConf.new("local.yml")
end
end