Sha256: d0d3c176f63cd0ba0eb277c379bfe02fe38ba106a7629dbf111ac03e8c7fd364

Contents?: true

Size: 1013 Bytes

Versions: 16

Compression:

Stored size: 1013 Bytes

Contents

require 'tempfile'
require 'yaml'
require 'json'
module Consul
  module Async
    class Utilities
      def self.bytes_to_h(bytes)
        if bytes < 1024
          "#{bytes} b"
        elsif bytes < 1_048_576
          "#{(bytes / 1024).round(2)} Kb"
        elsif bytes < 1_073_741_824
          "#{(bytes / 1_048_576.0).round(2)} Mb"
        else
          "#{(bytes / 1_073_741_824.0).round(2)} Gb"
        end
      end

      # Loads parameters from a file, supports JSON and YAML
      def self.load_parameters_from_file(parameters_file)
        raise "Parameters file #{parameters_file} does not exists" unless File.exist? parameters_file
        if parameters_file.downcase.end_with?('.yaml', '.yml')
          YAML.load_file(parameters_file)
        elsif parameters_file.downcase.end_with?('.json')
          JSON.parse(File.read(parameters_file))
        else
          raise "Don't know how to load parameters file #{parameters_file}: JSON and YAML supported"
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
consul-templaterb-1.5.3 lib/consul/async/utilities.rb
consul-templaterb-1.5.2 lib/consul/async/utilities.rb
consul-templaterb-1.5.1 lib/consul/async/utilities.rb
consul-templaterb-1.5.0 lib/consul/async/utilities.rb
consul-templaterb-1.4.0 lib/consul/async/utilities.rb
consul-templaterb-1.3.1 lib/consul/async/utilities.rb
consul-templaterb-1.3.0 lib/consul/async/utilities.rb
consul-templaterb-1.2.1 lib/consul/async/utilities.rb
consul-templaterb-1.2.0 lib/consul/async/utilities.rb
consul-templaterb-1.1.3 lib/consul/async/utilities.rb
consul-templaterb-1.1.2 lib/consul/async/utilities.rb
consul-templaterb-1.1.1 lib/consul/async/utilities.rb
consul-templaterb-1.1.0 lib/consul/async/utilities.rb
consul-templaterb-1.0.11 lib/consul/async/utilities.rb
consul-templaterb-1.0.10 lib/consul/async/utilities.rb
consul-templaterb-1.0.9 lib/consul/async/utilities.rb