Sha256: 338c69eaf11220b847cafcfac54cccdb99565c7026c266a413c548dc2ef6e262

Contents?: true

Size: 1.49 KB

Versions: 4

Compression:

Stored size: 1.49 KB

Contents

WorkingConfig  = Configliere::Param.new
WorkingConfig.use :commandline, :config_file

module HackBoxen

  autoload :ConfigValidator, 'hackboxen/utils/config_validator'
  autoload :Paths,           'hackboxen/utils/paths'
  autoload :Logging,         'hackboxen/utils/logging'

  def self.find_root_dir
    start_dir = File.dirname INCLUDING_FILE
    Dir.chdir start_dir
    until hackbox_root? Dir.pwd
      Dir.chdir('..')
      if Dir.pwd == '/'
        puts "Warning: not in a Hackbox base directory"
        return start_dir
      end
    end
    return Dir.pwd
  end

  def self.hackbox_root? dir = Dir.pwd
    %w[ engine config Rakefile ].each do |expected|
      return false unless Dir.entries(dir).include? expected
    end
    true
  end

  def self.current_fs
    fs = WorkingConfig[:filesystem_scheme] ? WorkingConfig[:filesystem_scheme] : 'file'
    Swineherd::FileSystem.get fs
  end

  def self.name
    hackbox_root? ? Dir.pwd.gsub(/#{coderoot}\/#{current}\//, '') : 'debug'
  end

  def self.current
    hackbox_root? ? WorkingConfig[:namespace].gsub('.', '/') : Dir.pwd
  end

  def self.coderoot
    WorkingConfig[:coderoot].gsub(/\/$/, '')
  end

  def self.dataroot
    WorkingConfig[:dataroot].gsub(/\/$/, '')
  end


  def self.verify_dependencies
    %w[ coderoot dataroot namespace ].each do |req|
      raise "Your hackbox config appears to be missing a [#{req}]" unless WorkingConfig[req.to_sym]
    end
  end

  def self.read_config cfg
    WorkingConfig.read cfg if current_fs.exists?(cfg)
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
hackboxen-0.1.5 lib/hackboxen/utils.rb
hackboxen-0.1.4 lib/hackboxen/utils.rb
hackboxen-0.1.3 lib/hackboxen/utils.rb
hackboxen-0.1.2 lib/hackboxen/utils.rb