Sha256: 96e7b76d802c995f3c9c1bc5730a444f2bd33969cea446f4212e3206b660711f
Contents?: true
Size: 1.33 KB
Versions: 34
Compression:
Stored size: 1.33 KB
Contents
require 'dply/helper' module Dply class Linker include Helper attr_reader :src_dir, :dest_dir, :map def initialize(src_dir, dest_dir, map: {}) verify_absolute src_dir, dest_dir @src_dir = src_dir @dest_dir = dest_dir @map = map end def create_symlinks mapped_files.each do |f| target = link_target(f) source = link_source(f) relative_source = link_relative_source(source, target) logger.debug "linking #{target} -> #{source}" error "source #{source} doesn't exist" if not File.exist? source symlink(relative_source, target) end end def link_target(relative_target) Pathname.new "#{dest_dir}/#{relative_target}" end def link_source(relative_target) relative_source = map[relative_target] Pathname.new "#{src_dir}/#{relative_source}" end def link_relative_source(source, target) source.relative_path_from target.parent end def mapped_files map.keys.collect do |k| path = Pathname.new k raise "config map path cannot be absoulte" if path.absolute? k end end def verify_absolute(*paths) paths.each do |path| absolute = Pathname.new(path).absolute? raise "#{path} not absolute" if not absolute end end end end
Version data entries
34 entries across 34 versions & 1 rubygems