Sha256: f5c0f5eff118d40ecdc5ba4e7e9569d5daf500c8c94b8a49b1cb05c923a960a6

Contents?: true

Size: 1.79 KB

Versions: 10

Compression:

Stored size: 1.79 KB

Contents

require 'pp'

module Omnibus
  module Overrides

    DEFAULT_OVERRIDE_FILE_NAME = "omnibus.overrides"

    # Parses a file of override information into a Hash.
    #
    # Each line of the file must be of the form
    #
    #
    #     <package_name> <version>
    #
    # where the two pieces of data are separated by whitespace.
    #
    # @param file [String] the path to an overrides file
    # @return [Hash, nil]
    def self.parse_file(file)
      if file
        File.readlines(file).inject({}) do |acc, line|
          info = line.split

          unless info.count == 2
            raise ArgumentError, "Invalid overrides line: '#{line.chomp}'"
          end

          package, version = info

          if acc[package]
            raise ArgumentError, "Multiple overrides present for '#{package}' in overrides file #{file}!"
          end

          acc[package] = version
          acc
        end
      else
        nil
      end
    end

    # Return the full path to an overrides file, or +nil+ if no such
    # file exists.
    def self.resolve_override_file
      file = ENV['OMNIBUS_OVERRIDE_FILE'] || DEFAULT_OVERRIDE_FILE_NAME
      path = File.expand_path(file)
      File.exist?(path) ? path : nil
    end

    # Return a hash of override information.  If no such information
    # can be found, the hash will be empty
    #
    # @return [Hash]
    def self.overrides
      file = resolve_override_file
      overrides = parse_file(file)

      if overrides
        puts "********************************************************************************"
        puts "Using Overrides from #{Omnibus::Overrides.resolve_override_file}"
        pp overrides
        puts "********************************************************************************"
      end

      overrides || {}
    end

  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
omnibus-1.3.0 lib/omnibus/overrides.rb
omnibus-sonian-1.2.0.1 lib/omnibus/overrides.rb
omnibus-1.2.0 lib/omnibus/overrides.rb
omnibus-1.1.1 lib/omnibus/overrides.rb
omnibus-1.1.0 lib/omnibus/overrides.rb
omnibus-1.0.4 lib/omnibus/overrides.rb
omnibus-1.0.3 lib/omnibus/overrides.rb
omnibus-1.0.2 lib/omnibus/overrides.rb
omnibus-1.0.1 lib/omnibus/overrides.rb
omnibus-1.0.0 lib/omnibus/overrides.rb