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
Defined Under Namespace
Classes: InvalidConfigurationError
Class Method Summary collapse
-
.load(filepath) ⇒ Object
include QAT::Logger Registers screen definitions from a YAML file.
-
.load_config(config) ⇒ Object
include QAT::Logger Registers screen definitions from a configuration hash.
-
.load_screen(name, options = {}) ⇒ Object
include QAT::Logger Registers a screen definition.
-
.screens ⇒ Hash
List of known virtual screen definitions.
Class Method Details
.load(filepath) ⇒ Object
include QAT::Logger Registers screen definitions from a YAML file
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
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
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/qat/web/screen/loader.rb', line 47 def load_screen(name, ={}) if name.is_a?(Array) log.debug { "Parsing #{name.first}" } parsed_opts = name.last.dup rescue {} raise InvalidConfigurationError.new "Configuration for screen #{name} is empty!" unless parsed_opts&.any? parse_resolution name.first, parsed_opts self.screens[name.first.to_sym] = parsed_opts log.debug { "Parsed #{name.first}" } else log.debug { "Parsing #{name.first}" } parsed_opts = .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 end |
.screens ⇒ Hash
List of known virtual screen definitions
75 76 77 |
# File 'lib/qat/web/screen/loader.rb', line 75 def screens @screens ||= { default: {} } end |