Sha256: 903c776f4a6fe97735f88db6a6f7bf614a9278645a8886ccb06e77a0f58cd774

Contents?: true

Size: 1.48 KB

Versions: 69

Compression:

Stored size: 1.48 KB

Contents

module PowerStencil
  module Utils

    module FileHelper

      def find_recursively_in_path(dir_or_file, from_dir)
        raise PowerStencil::Error, "Invalid directory '#{from_dir}'" unless Dir.exist?(from_dir) and File.readable?(from_dir)

        candidate = File.join from_dir, dir_or_file

        if Dir.exists? candidate or File.exist? candidate
          if File.readable? candidate and File.writable? candidate
            candidate
          else
            PowerStencil.logger.warn "Humm, found something: '#{candidate}', but with wrong access rights."
            nil
          end
        else
          next_dir = File.expand_path '..', from_dir
          if next_dir == from_dir
            PowerStencil.logger.info "Didn't find any trace of '#{dir_or_file}'... :("
            nil
          else
            find_recursively_in_path dir_or_file, next_dir
          end
        end

      end

      def yaml_file_to_hash(file_name)
        raw_content = File.read file_name
        res = YAML.load raw_content
        if res
          Hash[res.map { |k, v| [k, v] }]
        else
          raise PowerStencil::Error, "Invalid file content for '#{file_name}'" unless raw_content.empty?
          []
        end
      end

      def timestamped_uniq_dir(seed, start_time)
        uniq_dir = timestamp start_time
        uniq_dir += "-#{seed}" unless seed.nil?
        uniq_dir
      end

      def timestamp(timedate)
        timedate.strftime '%Y%m%d-%H%M-%S%L'
      end



    end

  end
end

Version data entries

69 entries across 69 versions & 1 rubygems

Version Path
power_stencil-0.10.0 lib/power_stencil/utils/file_helper.rb
power_stencil-0.9.8 lib/power_stencil/utils/file_helper.rb
power_stencil-0.9.7 lib/power_stencil/utils/file_helper.rb
power_stencil-0.9.6 lib/power_stencil/utils/file_helper.rb
power_stencil-0.9.5 lib/power_stencil/utils/file_helper.rb
power_stencil-0.9.4 lib/power_stencil/utils/file_helper.rb
power_stencil-0.9.3 lib/power_stencil/utils/file_helper.rb
power_stencil-0.9.2 lib/power_stencil/utils/file_helper.rb
power_stencil-0.9.1 lib/power_stencil/utils/file_helper.rb
power_stencil-0.9.0 lib/power_stencil/utils/file_helper.rb
power_stencil-0.8.14 lib/power_stencil/utils/file_helper.rb
power_stencil-0.8.13 lib/power_stencil/utils/file_helper.rb
power_stencil-0.8.12 lib/power_stencil/utils/file_helper.rb
power_stencil-0.8.11 lib/power_stencil/utils/file_helper.rb
power_stencil-0.8.10 lib/power_stencil/utils/file_helper.rb
power_stencil-0.8.9 lib/power_stencil/utils/file_helper.rb
power_stencil-0.8.8 lib/power_stencil/utils/file_helper.rb
power_stencil-0.8.7 lib/power_stencil/utils/file_helper.rb
power_stencil-0.8.6 lib/power_stencil/utils/file_helper.rb
power_stencil-0.8.5 lib/power_stencil/utils/file_helper.rb