Sha256: 3d2bbae176ea8ecf5292cef9567d21c9a743c47ebe98661e10745020068f97ae

Contents?: true

Size: 1.73 KB

Versions: 1

Compression:

Stored size: 1.73 KB

Contents

require 'pathname'

module HackBoxen

  module Paths

    def paths
      @paths ||= default_paths
    end

    def path_to *pathsegs
      path = Pathname.new path_to_helper(*pathsegs)
      path.absolute? ? File.expand_path(path) : path.to_s
    end

    def output_dirs
      [
        path_to(:hb_dataroot),
        path_to(:env_dir),
        path_to(:fixd_dir),
        path_to(:log_dir),
        path_to(:ripd_dir),
        path_to(:rawd_dir),
        path_to(:data_dir)
      ]
    end

    def default_paths
      {
        # root directories
        :home        => ENV['HOME'],
        :data_root   => WorkingConfig[:dataroot],
        :code_root   => WorkingConfig[:coderoot],
        # local hackbox directories
        :hb_current  => [:code_root, HackBoxen.current],
        :hb_engine   => [:hb_current, 'engine'],
        :hb_config   => [:hb_current, 'config'],
        # output directories
        :hb_dataroot => [:data_root, HackBoxen.current],
        :ripd_dir    => [:hb_dataroot, 'ripd'],
        :rawd_dir    => [:hb_dataroot, 'rawd'],
        :fixd_dir    => [:hb_dataroot, 'fixd'],
        :pkgd_dir    => [:hb_dataroot, 'pkgd'],
        :log_dir     => [:hb_dataroot, 'log'],
        :env_dir     => [:hb_dataroot, 'env'],
        :data_dir    => [:fixd_dir, 'data'],
        :code_dir    => [:fixd_dir, 'code']
    }

    end

    private
    def path_to_helper *pathsegs
      expanded = pathsegs.flatten.compact.map do |pathseg|
        case
        when pathseg.is_a?(Symbol) && paths.include?(pathseg) then path_to(paths[pathseg])
        when pathseg.is_a?(Symbol)                            then raise "No path expansion set for #{pathseg.inspect}"
        else pathseg
        end
      end
      File.join(*expanded)
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hackboxen-0.1.0 lib/hackboxen/utils/paths.rb