From 3e57dd309c64817b0e4ba5a591a4d0ff7901d3a6 Mon Sep 17 00:00:00 2001 From: pvincent Date: Wed, 25 Sep 2024 17:42:45 +0400 Subject: [PATCH] definable clean --- lib/live/constants.rb | 1 - lib/live/definable.rb | 15 +++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/live/constants.rb b/lib/live/constants.rb index bf1cf6b..833b4cc 100644 --- a/lib/live/constants.rb +++ b/lib/live/constants.rb @@ -9,6 +9,5 @@ module Live MY_INTEGER = integer 8 MY_STRING = string 'tutu' - MY_STRING2 = string 'toto' end end diff --git a/lib/live/definable.rb b/lib/live/definable.rb index 5fd4348..ffa62e0 100644 --- a/lib/live/definable.rb +++ b/lib/live/definable.rb @@ -1,7 +1,7 @@ require 'dotenv' # DEFINABLE_THREAD_GROUP ||= ThreadGroup.new -DEFINABLE_LISTENERS ||= [] # rubocop:disable Lint/OrAssignmentToConstant +DEFINABLE_LISTENERS ||= [] # rubocop:disable Lint/OrAssignmentToConstant,Style/MutableConstant module Live # offers typed constant defintions with default value, by using lots of introspecting... @@ -31,10 +31,8 @@ module Live def trigger_rolling_event(changes) logger.info ' ', dimensions: Semantic::FancyDimensions.new(rails: '╔═╗', before: 1) changes.each do |change| - kind = change[:kind] - constant = change[:constant] - value = change[:new_value] - logger.warn "Constant #{kind}:#{Semantic::AnsiColors::CLEAR} #{constant} = #{value.ai}" + value = change[:new_value].ai + logger.warn "Constant #{change[:kind]}:#{Semantic::AnsiColors::CLEAR} #{change[:constant]} = #{value}" end logger.info ' ', dimensions: Semantic::FancyDimensions.new(rails: '╚═╝') @@ -132,7 +130,12 @@ module Live raise "unexpected directory: #{dir_file} != #{dir_source_location}" unless dir_file == dir_source_location @lines ||= File.readlines(file) # cached source code - @lines[line].match(/\s*(.\w+)/)[1] # TODO: should be uppercase! + constant = @lines[line].match(/\s*(.\w+)/)[1] + unless constant.upcase == constant + backtrace = ["#{file}:#{line + 1}"] + raise ArgumentError, "unexpected case: a definable constant <#{constant}> must be uppercase!", backtrace + end + constant end end end