Sha256: d47636e4500b2dc16c3a48e588aff0d5fa03d01bbb636e1154e7e2007af0d12e
Contents?: true
Size: 1.69 KB
Versions: 5
Compression:
Stored size: 1.69 KB
Contents
require 'pathname' module IronWorkerNG module Feature module Common module MergeDir class Feature < IronWorkerNG::Feature::Base attr_reader :path attr_reader :dest def initialize(path, dest) unless Dir.exist?(path) IronCore::Logger.error 'IronWorkerNG', "Can't find directory with path='#{path}'" raise IronCore::IronError.new("Can't find directory with path='#{path}'") end @path = File.expand_path(path) @dest = dest @dest = Pathname.new(dest).cleanpath.to_s + '/' unless @dest.empty? end def hash_string s = @path + @dest + File.mtime(@path).to_i.to_s Dir.glob(@path + '/**/**') do |path| s += path + File.mtime(path).to_i.to_s end Digest::MD5.hexdigest(s) end def bundle(zip) IronCore::Logger.debug 'IronWorkerNG', "Bundling dir with path='#{@path}' and dest='#{@dest}'" Dir.glob(@path + '/**/**') do |path| zip.add(@dest + File.basename(@path) + path[@path.length .. -1], path) end end end module InstanceMethods def merge_dir(path, dest = '') IronCore::Logger.info 'IronWorkerNG', "Merging dir with path='#{path}' and dest='#{dest}'" @features << IronWorkerNG::Feature::Common::MergeDir::Feature.new(path, dest) end alias :dir :merge_dir def self.included(base) IronWorkerNG::Code::Base.register_feature(:name => 'merge_dir', :for_klass => base, :args => 'PATH[,DEST]') end end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems