Sha256: 2488b8882f05c67174dc5752e069c1ffaff8c6e18221c19550de004ab51bf8c7

Contents?: true

Size: 722 Bytes

Versions: 19

Compression:

Stored size: 722 Bytes

Contents

# frozen_string_literal: true

module Dry
  module System
    class MagicCommentsParser
      VALID_LINE_RE = /^(#.*)?$/.freeze
      COMMENT_RE = /^#\s+(?<name>[A-Za-z]{1}[A-Za-z0-9_]+):\s+(?<value>.+?)$/.freeze

      COERCIONS = {
        "true" => true,
        "false" => false
      }.freeze

      def self.call(file_name)
        {}.tap do |options|
          File.foreach(file_name) do |line|
            break unless line =~ VALID_LINE_RE

            if (comment = line.match(COMMENT_RE))
              options[comment[:name].to_sym] = coerce(comment[:value])
            end
          end
        end
      end

      def self.coerce(value)
        COERCIONS.fetch(value) { value }
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
dry-system-1.0.1 lib/dry/system/magic_comments_parser.rb
dry-system-1.0.0 lib/dry/system/magic_comments_parser.rb
dry-system-1.0.0.rc1 lib/dry/system/magic_comments_parser.rb
dry-system-0.27.2 lib/dry/system/magic_comments_parser.rb
dry-system-0.27.1 lib/dry/system/magic_comments_parser.rb
dry-system-0.27.0 lib/dry/system/magic_comments_parser.rb
dry-system-0.26.0 lib/dry/system/magic_comments_parser.rb
dry-system-0.25.0 lib/dry/system/magic_comments_parser.rb
dry-system-0.24.0 lib/dry/system/magic_comments_parser.rb
dry-system-0.23.0 lib/dry/system/magic_comments_parser.rb
dry-system-0.22.0 lib/dry/system/magic_comments_parser.rb
dry-system-0.21.0 lib/dry/system/magic_comments_parser.rb
dry-system-0.20.0 lib/dry/system/magic_comments_parser.rb
dry-system-0.19.2 lib/dry/system/magic_comments_parser.rb
dry-system-0.18.2 lib/dry/system/magic_comments_parser.rb
dry-system-0.19.1 lib/dry/system/magic_comments_parser.rb
dry-system-0.19.0 lib/dry/system/magic_comments_parser.rb
dry-system-0.18.1 lib/dry/system/magic_comments_parser.rb
dry-system-0.18.0 lib/dry/system/magic_comments_parser.rb