Class: YAMLWithLines

Inherits:
Object
  • Object
show all
Defined in:
lib/claws/cli/yaml_with_lines.rb

Class Method Summary collapse

Class Method Details

.load(blob) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/claws/cli/yaml_with_lines.rb', line 111

def self.load(blob)
  handler = TreeBuilderWithLines.new
  parser = Psych::Parser.new(handler)
  handler.parser = parser
  parser.parse(blob)
  parser.handler.root.to_ruby.first.tap do |c|
    c.instance_eval do
      @lines = blob.split("\n")

      def get_line(line:)
        raise "Line number must be positive and one-indexed" if line < 1

        @lines[line - 1]
      end
    end
  end
end