Sha256: f76993b0936e7028466d2a2a72e00c33637d34e2d8809fe55fbdbe8bc5a210f2

Contents?: true

Size: 1.23 KB

Versions: 3

Compression:

Stored size: 1.23 KB

Contents

module App
  def self.rails?
    defined?(RAILS_ROOT)
  end

  def self.revision
    @revision ||= begin
      "r#{File.read("#{root}/REVISION")}"
    rescue Errno::ENOENT
      ""
    end 
  end

  def self.env
    if rails?
      RAILS_ENV
    elsif defined?(APP_ENV)
      APP_ENV
    else
      "production"
    end
  end
  
  def self.root
    if defined?(RAILS_ROOT)
      RAILS_ROOT
    elsif defined?(APP_ROOT)
      APP_ROOT
    else
      raise "Cannot determine application root"
    end
  end

  def self.logger
    if rails?
      RAILS_DEFAULT_LOGGER
    else
      require "logger"

      logdir = "#{root}/log"
      FileUtils.mkdir_p logdir
      Logger.new "#{logdir}/#{env}.log"
    end
  end
  
  def self.tmpdir
    @tmpdir ||= begin
      tmpdir = if rails?
        "#{root}/tmp"
      else
        ENV["TMPDIR"]
      end

      tmpdir = tmpdir.gsub(/\/$/, "")

      raise "Cannot determine tmpdir setting" if tmpdir.blank?
      tmpdir
    end
  end

  def self.local_conf
    @local_conf = nil if App.env == "development"
    @local_conf ||= LocalConf.new("local.yml")
  end
end

module App::Etest
  def test_app
    assert_not_nil(App.root)
  end

  def test_app
    assert_equal("", App.revision)
  end
end if VEX_TEST == "base"

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
vex-0.2.2 lib/vex/base/app.rb
vex-0.2.1 lib/vex/base/app.rb
vex-0.2 lib/vex/base/app.rb