Sha256: 93ba7a3b4e00138da9cb062d489f5ada4a6d97f8b5859d34461e52e7aee8a9e4

Contents?: true

Size: 1.2 KB

Versions: 2

Compression:

Stored size: 1.2 KB

Contents

require_relative 'annotation'
require_relative 'path/find'
require_relative 'path/util'
require_relative 'path/tmpfile'
require_relative 'path/digest'

module Path
  extend Annotation
  annotation :pkgdir, :libdir, :path_maps, :map_order

  def self.default_pkgdir
    @@default_pkgdir ||= 'scout'
  end
  
  def self.default_pkgdir=(pkgdir)
    @@default_pkgdir = pkgdir
  end

  def pkgdir
    @pkgdir ||= Path.default_pkgdir
  end

  def libdir
    @libdir || Path.caller_lib_dir
  end

  def path_maps
    @path_maps ||= Path.path_maps.dup
  end

  def map_order
    @map_order ||= (path_maps.keys & Path.map_order) + (path_maps.keys - Path.map_order)
  end

  def join(subpath = nil, prevpath = nil)
    return self if subpath.nil?

    subpath = subpath.to_s if Symbol === subpath
    prevpath = prevpath.to_s if Symbol === prevpath

    subpath = File.join(prevpath.to_s, subpath) if prevpath
    new = self.empty? ? subpath.dup : File.join(self, subpath)
    self.annotate(new)
    new
  end

  alias [] join
  alias / join

  def method_missing(name, prev = nil, *args, &block)
    if block_given? || name.to_s.start_with?('to_')
      super name, prev, *args, &block
    else
      join(name, prev)
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
scout-essentials-1.6.3 lib/scout/path.rb
scout-essentials-1.6.2 lib/scout/path.rb