Browse Source

definable clean

main
pvincent 3 weeks ago
parent
commit
3e57dd309c
  1. 1
      lib/live/constants.rb
  2. 15
      lib/live/definable.rb

1
lib/live/constants.rb

@ -9,6 +9,5 @@ module Live
MY_INTEGER = integer 8
MY_STRING = string 'tutu'
MY_STRING2 = string 'toto'
end
end

15
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
Loading…
Cancel
Save