Browse Source

hot_constants first attempt

main
pvincent 5 months ago
parent
commit
86253448f0
  1. 13
      .env.sample
  2. 3
      TODO.md
  3. 2
      app/views/layouts/application.html.erb
  4. 4
      config/environments/development.rb
  5. 6
      doc/index.md
  6. 6
      lib/hot_constants/hot_constants.rb
  7. 5
      lib/monkey_patches/rails_live_reload/watcher.rb

13
.env.sample

@ -1,11 +1,11 @@
# STATIC: restart server when changes!
#-------------------------------------
RAILS_PORT=7500
# RAILS_PORT=7500
DATABASE_HOST=localhost
DATABASE_NAME=easy-going-rails
DATABASE_USER=$DATABASE_NAME
DATABASE_PASSWORD=$DATABASE_NAME
# DATABASE_HOST=localhost
# DATABASE_NAME=easy-going-rails
# DATABASE_USER=$DATABASE_NAME
# DATABASE_PASSWORD=$DATABASE_NAME
# HOT CONSTANTS
#--------------
@ -13,3 +13,6 @@ STIMULUS_DEBUG=false
LOG_ACTIVE_RECORD=false
LOG_ACTION_VIEW=false
INTEGER=1
STRING=""
BOOLEAN=true

3
TODO.md

@ -32,8 +32,9 @@ New Notes
* [x] Use hotwire_livereload instead of rails_live_reload
* [x] nope, because rails_live_reload is more clever (and sooner) than hotwire_livereload
* [x] LiveConstants
* [x] HotConstants
* [x] monkeypatch rails-live-reload
* [ ] meta-programming
* [x] Flash message
* [x] https://reinteractive.com/articles/how-to-create-flash-messages-in-Rails-7
* [x] Minitest

2
app/views/layouts/application.html.erb

@ -14,7 +14,7 @@
<%= tag :meta, name: :viewport, content: 'width=device-width,initial-scale=1' %>
<% if Rails.env.development? %>
<%= 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%>
<!-- LINK-->

4
config/environments/development.rb

@ -78,8 +78,8 @@ Rails.application.configure do # rubocop:disable Metrics/BlockLength
routes.default_url_options[:host] = '127.0.0.1'
config.after_initialize do
require Rails.root.join('lib', 'hot_constants', 'live_constants')
LiveConstants.reload!
require Rails.root.join('lib', 'hot_constants', 'hot_constants')
HotConstants.reload!
end
require Rails.root.join('lib', 'formatters', 'ansi_formatter')

6
doc/index.md

@ -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

6
lib/hot_constants/live_constants.rb → lib/hot_constants/hot_constants.rb

@ -1,11 +1,15 @@
require 'dotenv'
# Hot Live Constants
module LiveConstants
module HotConstants
HOTENV = {} # rubocop:disable Style/MutableConstant
LOGGER = SemanticLogger[to_s]
class << self
def initialize
LOGGER.info('initializing')
end
def stimulus_debug = load_boolean('STIMULUS_DEBUG', false)
def log_active_record = load_boolean('LOG_ACTIVE_RECORD', true)
def log_action_view = load_boolean('LOG_ACTION_VIEW', true)

5
lib/monkey_patches/rails_live_reload/watcher.rb

@ -1,7 +1,6 @@
module RailsLiveReload
# MonkeyPath Watcher
class Watcher
ENV_FILE = Rails.root.join('.env').to_s
def reload_all
before_reload(files)
data = { event: RailsLiveReload::INTERNAL[:socket_events][:reload], files: }.to_json
@ -10,8 +9,10 @@ module RailsLiveReload
private
ENV_FILE = Rails.root.join('.env').to_s
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
Loading…
Cancel
Save