Sha256: d13f2138b98e0d16711a32ecda1d2346b1c352a1e75d17a6857b0f195536f7b0
Contents?: true
Size: 1.58 KB
Versions: 7
Compression:
Stored size: 1.58 KB
Contents
# frozen_string_literal: true require_relative "parameter_bag" require_relative "../logging/logger" module Kanal module Core module Helpers # Parameter bag but it checks registrator for existence of parameters # and if they are has needed by registrator allowances, types etc, whatever # registrator rules are stored for property class ParameterBagWithRegistrator < ParameterBag include Logging::Logger def initialize(registrator) super() @registrator = registrator end def get(name) validate_parameter_registration name super name end def set(name, value) validate_parameter_registration name readonly = @registrator.get_parameter_registration_if_exists(name).readonly? if readonly value_exists = !get(name).nil? if value_exists logger.fatal "Parameter #{name} is marked readonly! Attempted to set it's value, but it already has value." raise "Parameter #{name} is marked readonly! You tried to set it's value, but it already has value." end end super name, value end def validate_parameter_registration(name) unless @registrator.parameter_registered? name logger.fatal "Parameter #{name} was not registered! Did you forget to register that parameter?" raise "Parameter #{name} was not registered! Did you forget to register that parameter?" end end end end end end
Version data entries
7 entries across 7 versions & 1 rubygems