Sha256: 931a9d84b7e152f74bd4e53b34f2d3f738812f3224279438f6a27e9e7d038de4
Contents?: true
Size: 708 Bytes
Versions: 4
Compression:
Stored size: 708 Bytes
Contents
# frozen_string_literal: true module Dry module System class MagicCommentsParser VALID_LINE_RE = /^(#.*)?$/ COMMENT_RE = /^#\s+(?<name>[A-Za-z]{1}[A-Za-z0-9_]+):\s+(?<value>.+?)$/ 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
4 entries across 4 versions & 1 rubygems