Sha256: 037d10d3f79bfef1d905bd2b060542899a3d1dd321e8f4bf9064f96cb9ac0d53

Contents?: true

Size: 1.38 KB

Versions: 4

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true

module Aws
  # @api private
  class IniParser
    class << self

      def ini_parse(raw)
        current_profile = nil
        current_prefix = nil
        raw.lines.inject({}) do |acc, line|
          line = line.split(/^|\s;/).first # remove comments
          profile = line.match(/^\[([^\[\]]+)\]\s*(#.+)?$/) unless line.nil?
          if profile
            current_profile = profile[1]
            named_profile = current_profile.match(/^profile\s+(.+?)$/)
            current_profile = named_profile[1] if named_profile
          elsif current_profile
            unless line.nil?
              item = line.match(/^(.+?)\s*=\s*([^\s].*?)\s*$/)
              prefix = line.match(/^(.+?)\s*=\s*$/)
            end
            if item && item[1].match(/^\s+/)
              # Need to add lines to a nested configuration.
              inner_item = line.match(/^\s*(.+?)\s*=\s*(.+?)\s*$/)
              acc[current_profile] ||= {}
              acc[current_profile][current_prefix] ||= {}
              acc[current_profile][current_prefix][inner_item[1]] = inner_item[2]
            elsif item
              current_prefix = nil
              acc[current_profile] ||= {}
              acc[current_profile][item[1]] = item[2]
            elsif prefix
              current_prefix = prefix[1]
            end
          end
          acc
        end
      end

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
aws-sdk-core-3.180.1 lib/aws-sdk-core/ini_parser.rb
aws-sdk-core-3.180.0 lib/aws-sdk-core/ini_parser.rb
aws-sdk-core-3.179.0 lib/aws-sdk-core/ini_parser.rb
aws-sdk-core-3.178.0 lib/aws-sdk-core/ini_parser.rb