hot_constants first attempt

This commit is contained in:
pvincent
2024-07-11 16:17:30 +04:00
parent 0b812ac122
commit 86253448f0
7 changed files with 27 additions and 12 deletions
+8 -5
View File
@@ -1,11 +1,11 @@
# STATIC: restart server when changes! # STATIC: restart server when changes!
#------------------------------------- #-------------------------------------
RAILS_PORT=7500 # RAILS_PORT=7500
DATABASE_HOST=localhost # DATABASE_HOST=localhost
DATABASE_NAME=easy-going-rails # DATABASE_NAME=easy-going-rails
DATABASE_USER=$DATABASE_NAME # DATABASE_USER=$DATABASE_NAME
DATABASE_PASSWORD=$DATABASE_NAME # DATABASE_PASSWORD=$DATABASE_NAME
# HOT CONSTANTS # HOT CONSTANTS
#-------------- #--------------
@@ -13,3 +13,6 @@ STIMULUS_DEBUG=false
LOG_ACTIVE_RECORD=false LOG_ACTIVE_RECORD=false
LOG_ACTION_VIEW=false LOG_ACTION_VIEW=false
INTEGER=1
STRING=""
BOOLEAN=true
+2 -1
View File
@@ -32,8 +32,9 @@ New Notes
* [x] Use hotwire_livereload instead of rails_live_reload * [x] Use hotwire_livereload instead of rails_live_reload
* [x] nope, because rails_live_reload is more clever (and sooner) than hotwire_livereload * [x] nope, because rails_live_reload is more clever (and sooner) than hotwire_livereload
* [x] LiveConstants * [x] HotConstants
* [x] monkeypatch rails-live-reload * [x] monkeypatch rails-live-reload
* [ ] meta-programming
* [x] Flash message * [x] Flash message
* [x] https://reinteractive.com/articles/how-to-create-flash-messages-in-Rails-7 * [x] https://reinteractive.com/articles/how-to-create-flash-messages-in-Rails-7
* [x] Minitest * [x] Minitest
+1 -1
View File
@@ -14,7 +14,7 @@
<%= tag :meta, name: :viewport, content: 'width=device-width,initial-scale=1' %> <%= tag :meta, name: :viewport, content: 'width=device-width,initial-scale=1' %>
<% if Rails.env.development? %> <% if Rails.env.development? %>
<%= tag :meta, name: 'turbo-prefetch', content: false %> <%= tag :meta, name: 'turbo-prefetch', content: false %>
<%= tag :meta, name: 'stimulus-debug', content: LiveConstants.stimulus_debug %> <%= tag :meta, name: 'stimulus-debug', content: HotConstants.stimulus_debug %>
<% end%> <% end%>
<!-- LINK--> <!-- LINK-->
+2 -2
View File
@@ -78,8 +78,8 @@ Rails.application.configure do # rubocop:disable Metrics/BlockLength
routes.default_url_options[:host] = '127.0.0.1' routes.default_url_options[:host] = '127.0.0.1'
config.after_initialize do config.after_initialize do
require Rails.root.join('lib', 'hot_constants', 'live_constants') require Rails.root.join('lib', 'hot_constants', 'hot_constants')
LiveConstants.reload! HotConstants.reload!
end end
require Rails.root.join('lib', 'formatters', 'ansi_formatter') require Rails.root.join('lib', 'formatters', 'ansi_formatter')
+6
View File
@@ -0,0 +1,6 @@
Developer documentation
======================
Hint
----
* Do not use AlpineJs bind:class onto a fontawesome i element, it hangs due to the SVG convert of the i element happening concurrently
@@ -1,11 +1,15 @@
require 'dotenv' require 'dotenv'
# Hot Live Constants # Hot Live Constants
module LiveConstants module HotConstants
HOTENV = {} # rubocop:disable Style/MutableConstant HOTENV = {} # rubocop:disable Style/MutableConstant
LOGGER = SemanticLogger[to_s] LOGGER = SemanticLogger[to_s]
class << self class << self
def initialize
LOGGER.info('initializing')
end
def stimulus_debug = load_boolean('STIMULUS_DEBUG', false) def stimulus_debug = load_boolean('STIMULUS_DEBUG', false)
def log_active_record = load_boolean('LOG_ACTIVE_RECORD', true) def log_active_record = load_boolean('LOG_ACTIVE_RECORD', true)
def log_action_view = load_boolean('LOG_ACTION_VIEW', true) def log_action_view = load_boolean('LOG_ACTION_VIEW', true)
@@ -1,7 +1,6 @@
module RailsLiveReload module RailsLiveReload
# MonkeyPath Watcher # MonkeyPath Watcher
class Watcher class Watcher
ENV_FILE = Rails.root.join('.env').to_s
def reload_all def reload_all
before_reload(files) before_reload(files)
data = { event: RailsLiveReload::INTERNAL[:socket_events][:reload], files: }.to_json data = { event: RailsLiveReload::INTERNAL[:socket_events][:reload], files: }.to_json
@@ -10,8 +9,10 @@ module RailsLiveReload
private private
ENV_FILE = Rails.root.join('.env').to_s
def before_reload(files) def before_reload(files)
LiveConstants.reload! if files.find { |change| change[0] == ENV_FILE } HotConstants.reload! if files.find { |change| change[0] == ENV_FILE }
end end
end end
end end