Sha256: 34198f3c2da37e75d624ee4d853e6f6c283d6a585fa66066d72c865c7482c80e

Contents?: true

Size: 707 Bytes

Versions: 13

Compression:

Stored size: 707 Bytes

Contents

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

      private

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

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
dry-system-0.12.0 lib/dry/system/magic_comments_parser.rb
dry-system-0.11.0 lib/dry/system/magic_comments_parser.rb
dry-system-0.10.1 lib/dry/system/magic_comments_parser.rb
dry-system-0.10.0 lib/dry/system/magic_comments_parser.rb
dry-system-0.9.2 lib/dry/system/magic_comments_parser.rb
dry-system-0.9.1 lib/dry/system/magic_comments_parser.rb
dry-system-0.9.0 lib/dry/system/magic_comments_parser.rb
dry-system-0.8.1 lib/dry/system/magic_comments_parser.rb
dry-system-0.8.0 lib/dry/system/magic_comments_parser.rb
dry-system-0.7.3 lib/dry/system/magic_comments_parser.rb
dry-system-0.7.2 lib/dry/system/magic_comments_parser.rb
dry-system-0.7.1 lib/dry/system/magic_comments_parser.rb
dry-system-0.7.0 lib/dry/system/magic_comments_parser.rb