Class: Dry::System::MagicCommentsParser

Inherits:
Object
  • Object
show all
Defined in:
lib/dry/system/magic_comments_parser.rb

Constant Summary collapse

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

Class Method Summary collapse

Class Method Details

.call(file_name) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/dry/system/magic_comments_parser.rb', line 12

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