Sha256: 3ff3d2c9ab9c0ebea0c803bc9ea23483f07e353c7373d6bbf59d547e88f08c98

Contents?: true

Size: 1.19 KB

Versions: 3

Compression:

Stored size: 1.19 KB

Contents

module Cts
  module Mpx
    # responsible for low level calls to MPX
    module Driver
      module_function

      #
      # path to our gem directory, includes support for bundled env's.
      #
      # @return [String] full path to the root of our gem directory.
      #
      def gem_dir
        return Dir.pwd unless Gem.loaded_specs.include? 'cts-mpx'
        Gem.loaded_specs['cts-mpx'].full_gem_path
      end

      #
      # path to our config files
      #
      # @return [String] full path to the root of our gem directory.
      #
      def config_dir
        "#{gem_dir}/config"
      end

      #
      # load a json file into a simple hash
      #
      # @param [String] filename filename to load
      #
      # @raise [RuntimeError] if the filename does not exist.
      # @raise [RuntimeError] if the file cannot be parsed, supplies the exception.
      #
      # @return [Hash] data from the file
      #
      def load_json_file(filename)
        raise "#{filename} does not exist" unless File.exist? filename

        begin
          Oj.load File.read filename
        rescue Oj::ParseError => exception
          raise "#{filename}: #{exception.message}"
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cts-mpx-1.0.3 lib/cts/mpx/driver.rb
cts-mpx-1.0.2 lib/cts/mpx/driver.rb
cts-mpx-1.0.1 lib/cts/mpx/driver.rb