Class: Shellfie::Parser

Inherits:
Object
  • Object
show all
Extended by:
ParserValidation
Defined in:
lib/shellfie/parser.rb

Constant Summary

Constants included from ParserValidation

Shellfie::ParserValidation::ANIMATION_KEYS, Shellfie::ParserValidation::CURSOR_KEYS, Shellfie::ParserValidation::FONT_KEYS, Shellfie::ParserValidation::FRAME_KEYS, Shellfie::ParserValidation::LIMIT_KEYS, Shellfie::ParserValidation::LINE_KEYS, Shellfie::ParserValidation::TOP_LEVEL_KEYS, Shellfie::ParserValidation::WINDOW_KEYS

Class Method Summary collapse

Class Method Details

.parse(path) ⇒ Object

Raises:



13
14
15
16
17
18
19
# File 'lib/shellfie/parser.rb', line 13

def parse(path)
  return parse_string($stdin.read, base_dir: Dir.pwd) if path == "-"
  raise ParseError, "Configuration file not found: #{path}" unless File.exist?(path)

  content = File.read(path)
  parse_string(content, base_dir: File.dirname(path))
end

.parse_string(content, base_dir: nil) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/shellfie/parser.rb', line 21

def parse_string(content, base_dir: nil)
  raw = YAML.safe_load(content, symbolize_names: true, aliases: true)
  raw = apply_includes(raw, base_dir) if base_dir
  validate_config(raw)
  build_config(raw)
rescue Psych::SyntaxError => e
  raise ParseError, "Invalid YAML syntax: #{e.message}"
end