Class: Kanal::Core::Helpers::ParameterRegistrator

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

Overview

Class holds parameter names that are allowed to be used.

Instance Method Summary collapse

Methods included from Logging::Logger

#logger

Constructor Details

#initializeParameterRegistrator

Returns a new instance of ParameterRegistrator.



26
27
28
# File 'lib/kanal/core/helpers/parameter_registrator.rb', line 26

def initialize
  @parameters_by_name = {}
end

Instance Method Details

#get_parameter_registration_if_exists(name) ⇒ Object

returns nil if no parameter registered



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

def get_parameter_registration_if_exists(name)
  return nil unless @parameters_by_name.key? name

  @parameters_by_name[name]
end

#parameter_registered?(name) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/kanal/core/helpers/parameter_registrator.rb', line 54

def parameter_registered?(name)
  !get_parameter_registration_if_exists(name).nil?
end

#register_parameter(name, readonly: false) ⇒ Object

readonly paramaeter means that once it was initialized - it cannot be changed. handy for input parameters populated by interface or whatever



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/kanal/core/helpers/parameter_registrator.rb', line 33

def register_parameter(name, readonly: false)
  if @parameters_by_name.key? name
    logger.fatal "Attempted to register already registered parameter '#{name}'"

    raise "Parameter named #{name} already registered!"
  end

  logger.debug "Registering parameter '#{name}'"

  registration = ParameterRegistration.new readonly

  @parameters_by_name[name] = registration
end