Class: Kanal::Core::Helpers::ParameterBagWithRegistrator

Inherits:
ParameterBag
  • Object
show all
Includes:
Logging::Logger
Defined in:
lib/kanal/core/helpers/parameter_bag_with_registrator.rb

Overview

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

Instance Method Summary collapse

Methods included from Logging::Logger

#logger

Constructor Details

#initialize(registrator) ⇒ ParameterBagWithRegistrator

Returns a new instance of ParameterBagWithRegistrator.



15
16
17
18
# File 'lib/kanal/core/helpers/parameter_bag_with_registrator.rb', line 15

def initialize(registrator)
  super()
  @registrator = registrator
end

Instance Method Details

#get(name) ⇒ Object



20
21
22
23
24
# File 'lib/kanal/core/helpers/parameter_bag_with_registrator.rb', line 20

def get(name)
  validate_parameter_registration name

  super name
end

#set(name, value) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/kanal/core/helpers/parameter_bag_with_registrator.rb', line 26

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

#validate_parameter_registration(name) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/kanal/core/helpers/parameter_bag_with_registrator.rb', line 46

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