Module: QAT::Web::Screen::Loader

Includes:
Logger
Defined in:
lib/qat/web/screen/loader.rb

Overview

Utility methods to load screen definitions from configuration files

Since:

  • 1.0.0

Defined Under Namespace

Classes: InvalidConfigurationError

Class Method Summary collapse

Class Method Details

.load(filepath) ⇒ Object

include QAT::Logger Registers screen definitions from a YAML file

Parameters:

  • filepath (String)

    file containing screen definitions

Raises:

Since:

  • 1.0.0



22
23
24
25
26
27
28
29
30
# File 'lib/qat/web/screen/loader.rb', line 22

def load(filepath)
  log.info { "Opening #{filepath}" }

  screens = HashWithIndifferentAccess.new(YAML::load(ERB.new(File.read(filepath)).result)) || {}

  load_config(screens)

  log.info { "File #{filepath} parsed" }
end

.load_config(config) ⇒ Object

include QAT::Logger Registers screen definitions from a configuration hash

Parameters:

  • config (Hash)

    configuration hash containing screen definitions

Raises:

Since:

  • 2.1.0



37
38
39
# File 'lib/qat/web/screen/loader.rb', line 37

def load_config(config)
  config.each(&method(:load_screen))
end

.load_screen(name, options) ⇒ Object

include QAT::Logger Registers a screen definition

Parameters:

  • name (String)

    screen name

  • options (String)

    screen definitions

Raises:

Since:

  • 2.1.0



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/qat/web/screen/loader.rb', line 47

def load_screen(name, options)
  log.debug { "Parsing #{name}" }
  parsed_opts = options.dup rescue {}

  raise InvalidConfigurationError.new "Configuration for screen #{name} is empty!" unless parsed_opts&.any?

  parse_resolution name, parsed_opts

  self.screens[name.to_sym] = parsed_opts
  log.debug { "Parsed #{name}" }
end

.screensHash

List of known virtual screen definitions

Returns:

  • (Hash)

    list of screen definitions

Since:

  • 1.0.0



62
63
64
# File 'lib/qat/web/screen/loader.rb', line 62

def screens
  @screens ||= { default: {} }
end