diff --git a/Gemfile b/Gemfile index 555c83e..f8cf37b 100644 --- a/Gemfile +++ b/Gemfile @@ -1,12 +1,14 @@ source "https://rubygems.org" git_source(:github) { |repo| "https://github.com/#{repo}.git" } -ruby "3.1.2" +ruby "3.3.0" gem "prefab-cloud-ruby" +gem "amazing_print" +gem "rails_semantic_logger" # Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main" -gem "rails", "~> 7.0.4", ">= 7.0.4.3" +gem "rails" # The original asset pipeline for Rails [https://github.com/rails/sprockets-rails] gem "sprockets-rails" @@ -42,7 +44,7 @@ gem "redis", "~> 4.0" # gem "bcrypt", "~> 3.1.7" # Windows does not include zoneinfo files, so bundle the tzinfo-data gem -gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ] +gem "tzinfo-data", platforms: %i[mingw mswin x64_mingw jruby] # Reduces boot times through caching; required in config/boot.rb gem "bootsnap", require: false @@ -55,7 +57,7 @@ gem "bootsnap", require: false group :development, :test do # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem - gem "debug", platforms: %i[ mri mingw x64_mingw ] + gem "debug", platforms: %i[mri mingw x64_mingw] end group :development do diff --git a/Gemfile.lock b/Gemfile.lock index 4ed5208..75af19f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,77 +1,89 @@ GEM remote: https://rubygems.org/ specs: - actioncable (7.0.4.3) - actionpack (= 7.0.4.3) - activesupport (= 7.0.4.3) + actioncable (7.1.4.1) + actionpack (= 7.1.4.1) + activesupport (= 7.1.4.1) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (7.0.4.3) - actionpack (= 7.0.4.3) - activejob (= 7.0.4.3) - activerecord (= 7.0.4.3) - activestorage (= 7.0.4.3) - activesupport (= 7.0.4.3) + zeitwerk (~> 2.6) + actionmailbox (7.1.4.1) + actionpack (= 7.1.4.1) + activejob (= 7.1.4.1) + activerecord (= 7.1.4.1) + activestorage (= 7.1.4.1) + activesupport (= 7.1.4.1) mail (>= 2.7.1) net-imap net-pop net-smtp - actionmailer (7.0.4.3) - actionpack (= 7.0.4.3) - actionview (= 7.0.4.3) - activejob (= 7.0.4.3) - activesupport (= 7.0.4.3) + actionmailer (7.1.4.1) + actionpack (= 7.1.4.1) + actionview (= 7.1.4.1) + activejob (= 7.1.4.1) + activesupport (= 7.1.4.1) mail (~> 2.5, >= 2.5.4) net-imap net-pop net-smtp - rails-dom-testing (~> 2.0) - actionpack (7.0.4.3) - actionview (= 7.0.4.3) - activesupport (= 7.0.4.3) - rack (~> 2.0, >= 2.2.0) + rails-dom-testing (~> 2.2) + actionpack (7.1.4.1) + actionview (= 7.1.4.1) + activesupport (= 7.1.4.1) + nokogiri (>= 1.8.5) + racc + rack (>= 2.2.4) + rack-session (>= 1.0.1) rack-test (>= 0.6.3) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (7.0.4.3) - actionpack (= 7.0.4.3) - activerecord (= 7.0.4.3) - activestorage (= 7.0.4.3) - activesupport (= 7.0.4.3) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + actiontext (7.1.4.1) + actionpack (= 7.1.4.1) + activerecord (= 7.1.4.1) + activestorage (= 7.1.4.1) + activesupport (= 7.1.4.1) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.0.4.3) - activesupport (= 7.0.4.3) + actionview (7.1.4.1) + activesupport (= 7.1.4.1) builder (~> 3.1) - erubi (~> 1.4) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.1, >= 1.2.0) - activejob (7.0.4.3) - activesupport (= 7.0.4.3) + erubi (~> 1.11) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + activejob (7.1.4.1) + activesupport (= 7.1.4.1) globalid (>= 0.3.6) - activemodel (7.0.4.3) - activesupport (= 7.0.4.3) - activerecord (7.0.4.3) - activemodel (= 7.0.4.3) - activesupport (= 7.0.4.3) - activestorage (7.0.4.3) - actionpack (= 7.0.4.3) - activejob (= 7.0.4.3) - activerecord (= 7.0.4.3) - activesupport (= 7.0.4.3) + activemodel (7.1.4.1) + activesupport (= 7.1.4.1) + activerecord (7.1.4.1) + activemodel (= 7.1.4.1) + activesupport (= 7.1.4.1) + timeout (>= 0.4.0) + activestorage (7.1.4.1) + actionpack (= 7.1.4.1) + activejob (= 7.1.4.1) + activerecord (= 7.1.4.1) + activesupport (= 7.1.4.1) marcel (~> 1.0) - mini_mime (>= 1.1.0) - activesupport (7.0.4.3) + activesupport (7.1.4.1) + base64 + bigdecimal concurrent-ruby (~> 1.0, >= 1.0.2) + connection_pool (>= 2.2.5) + drb i18n (>= 1.6, < 2) minitest (>= 5.1) + mutex_m tzinfo (~> 2.0) - addressable (2.8.4) - public_suffix (>= 2.0.2, < 6.0) + addressable (2.8.7) + public_suffix (>= 2.0.2, < 7.0) + amazing_print (1.6.0) + base64 (0.2.0) + bigdecimal (3.1.8) bindex (0.8.1) bootsnap (1.16.0) msgpack (~> 1.2) - builder (3.2.4) + builder (3.3.0) capybara (3.39.0) addressable matrix @@ -81,37 +93,43 @@ GEM rack-test (>= 0.6.3) regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) - concurrent-ruby (1.2.2) + concurrent-ruby (1.3.4) + connection_pool (2.4.1) crass (1.0.6) - date (3.3.3) + date (3.3.4) debug (1.7.2) irb (>= 1.5.0) reline (>= 0.3.1) - domain_name (0.5.20190701) - unf (>= 0.0.5, < 1.0.0) - erubi (1.12.0) - faraday (2.7.4) - faraday-net_http (>= 2.0, < 3.1) - ruby2_keywords (>= 0.0.4) - faraday-net_http (3.0.2) - ffi (1.15.5) - ffi-compiler (1.0.1) - ffi (>= 1.0.0) + domain_name (0.6.20240107) + drb (2.2.1) + erubi (1.13.0) + faraday (2.12.0) + faraday-net_http (>= 2.0, < 3.4) + json + logger + faraday-net_http (3.3.0) + net-http + ffi (1.17.0-arm64-darwin) + ffi-compiler (1.3.2) + ffi (>= 1.15.5) rake - globalid (1.1.0) - activesupport (>= 5.0) - google-protobuf (3.22.3-arm64-darwin) - googleapis-common-protos-types (1.5.0) - google-protobuf (~> 3.14) - http (5.1.1) + globalid (1.2.1) + activesupport (>= 6.1) + google-protobuf (4.28.2-arm64-darwin) + bigdecimal + rake (>= 13) + googleapis-common-protos-types (1.16.0) + google-protobuf (>= 3.18, < 5.a) + http (5.2.0) addressable (~> 2.8) + base64 (~> 0.1) http-cookie (~> 1.0) http-form_data (~> 2.2) - llhttp-ffi (~> 0.4.0) - http-cookie (1.0.5) + llhttp-ffi (~> 0.5.0) + http-cookie (1.0.7) domain_name (~> 0.5) http-form_data (2.3.0) - i18n (1.12.0) + i18n (1.14.6) concurrent-ruby (~> 1.0) importmap-rails (1.1.6) actionpack (>= 6.0.0) @@ -122,15 +140,17 @@ GEM jbuilder (2.11.5) actionview (>= 5.0.0) activesupport (>= 5.0.0) + json (2.7.2) ld-eventsource (2.2.2) concurrent-ruby (~> 1.0) http (>= 4.4.1, < 6.0.0) - llhttp-ffi (0.4.0) + llhttp-ffi (0.5.0) ffi-compiler (~> 1.0) rake (~> 13.0) - loofah (2.20.0) + logger (1.6.1) + loofah (2.22.0) crass (~> 1.0.2) - nokogiri (>= 1.5.9) + nokogiri (>= 1.12.0) macaddr (1.7.2) systemu (~> 2.6.5) mail (2.8.1) @@ -138,76 +158,94 @@ GEM net-imap net-pop net-smtp - marcel (1.0.2) + marcel (1.0.4) matrix (0.4.2) - method_source (1.0.0) - mini_mime (1.1.2) - minitest (5.18.0) + mini_mime (1.1.5) + mini_portile2 (2.8.7) + minitest (5.25.1) msgpack (1.7.0) - net-imap (0.3.4) + mutex_m (0.2.0) + net-http (0.4.1) + uri + net-imap (0.4.17) date net-protocol net-pop (0.1.2) net-protocol - net-protocol (0.2.1) + net-protocol (0.2.2) timeout - net-smtp (0.3.3) + net-smtp (0.5.0) net-protocol - nio4r (2.5.9) - nokogiri (1.14.3-arm64-darwin) + nio4r (2.7.3) + nokogiri (1.16.7-arm64-darwin) racc (~> 1.4) - prefab-cloud-ruby (0.23.8) + prefab-cloud-ruby (1.8.6) + activesupport (>= 4) concurrent-ruby (~> 1.0, >= 1.0.5) faraday google-protobuf googleapis-common-protos-types ld-eventsource + semantic_logger (!= 4.16.0) uuid - public_suffix (5.0.1) + public_suffix (6.0.1) puma (5.6.5) nio4r (~> 2.0) - racc (1.6.2) - rack (2.2.6.4) + racc (1.8.1) + rack (3.1.8) + rack-session (2.0.0) + rack (>= 3.0.0) rack-test (2.1.0) rack (>= 1.3) - rails (7.0.4.3) - actioncable (= 7.0.4.3) - actionmailbox (= 7.0.4.3) - actionmailer (= 7.0.4.3) - actionpack (= 7.0.4.3) - actiontext (= 7.0.4.3) - actionview (= 7.0.4.3) - activejob (= 7.0.4.3) - activemodel (= 7.0.4.3) - activerecord (= 7.0.4.3) - activestorage (= 7.0.4.3) - activesupport (= 7.0.4.3) + rackup (2.1.0) + rack (>= 3) + webrick (~> 1.8) + rails (7.1.4.1) + actioncable (= 7.1.4.1) + actionmailbox (= 7.1.4.1) + actionmailer (= 7.1.4.1) + actionpack (= 7.1.4.1) + actiontext (= 7.1.4.1) + actionview (= 7.1.4.1) + activejob (= 7.1.4.1) + activemodel (= 7.1.4.1) + activerecord (= 7.1.4.1) + activestorage (= 7.1.4.1) + activesupport (= 7.1.4.1) bundler (>= 1.15.0) - railties (= 7.0.4.3) - rails-dom-testing (2.0.3) - activesupport (>= 4.2.0) + railties (= 7.1.4.1) + rails-dom-testing (2.2.0) + activesupport (>= 5.0.0) + minitest nokogiri (>= 1.6) - rails-html-sanitizer (1.5.0) - loofah (~> 2.19, >= 2.19.1) - railties (7.0.4.3) - actionpack (= 7.0.4.3) - activesupport (= 7.0.4.3) - method_source + rails-html-sanitizer (1.6.0) + loofah (~> 2.21) + nokogiri (~> 1.14) + rails_semantic_logger (4.17.0) + rack + railties (>= 5.1) + semantic_logger (~> 4.16) + railties (7.1.4.1) + actionpack (= 7.1.4.1) + activesupport (= 7.1.4.1) + irb + rackup (>= 1.0.0) rake (>= 12.2) - thor (~> 1.0) - zeitwerk (~> 2.5) - rake (13.0.6) + thor (~> 1.0, >= 1.2.2) + zeitwerk (~> 2.6) + rake (13.2.1) redis (4.8.1) regexp_parser (2.8.0) reline (0.3.3) io-console (~> 0.5) - rexml (3.2.5) - ruby2_keywords (0.0.5) + rexml (3.3.8) rubyzip (2.3.2) selenium-webdriver (4.9.0) rexml (~> 3.2, >= 3.2.5) rubyzip (>= 1.2.2, < 3.0) websocket (~> 1.0) + semantic_logger (4.16.1) + concurrent-ruby (~> 1.0) sprockets (4.2.0) concurrent-ruby (~> 1.0) rack (>= 2.2.4, < 4) @@ -215,23 +253,22 @@ GEM actionpack (>= 5.2) activesupport (>= 5.2) sprockets (>= 3.0.0) - sqlite3 (1.6.2-arm64-darwin) + sqlite3 (1.6.2) + mini_portile2 (~> 2.8.0) stimulus-rails (1.2.1) railties (>= 6.0.0) systemu (2.6.5) tailwindcss-rails (2.0.28-arm64-darwin) railties (>= 6.0.0) - thor (1.2.1) - timeout (0.3.2) + thor (1.3.2) + timeout (0.4.1) turbo-rails (1.4.0) actionpack (>= 6.0.0) activejob (>= 6.0.0) railties (>= 6.0.0) tzinfo (2.0.6) concurrent-ruby (~> 1.0) - unf (0.1.4) - unf_ext - unf_ext (0.0.8.2) + uri (0.13.1) uuid (2.3.9) macaddr (~> 1.0) web-console (4.2.0) @@ -243,18 +280,21 @@ GEM nokogiri (~> 1.6) rubyzip (>= 1.3.0) selenium-webdriver (~> 4.0) + webrick (1.8.2) websocket (1.2.9) - websocket-driver (0.7.5) + websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) xpath (3.2.0) nokogiri (~> 1.8) - zeitwerk (2.6.7) + zeitwerk (2.7.0) PLATFORMS arm64-darwin-21 + arm64-darwin-23 DEPENDENCIES + amazing_print bootsnap capybara debug @@ -262,7 +302,8 @@ DEPENDENCIES jbuilder prefab-cloud-ruby puma (~> 5.0) - rails (~> 7.0.4, >= 7.0.4.3) + rails + rails_semantic_logger redis (~> 4.0) selenium-webdriver sprockets-rails @@ -275,7 +316,7 @@ DEPENDENCIES webdrivers RUBY VERSION - ruby 3.1.2p20 + ruby 3.3.0p0 BUNDLED WITH - 2.4.12 + 2.5.7 diff --git a/README.md b/README.md index 33c4200..44e67f6 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Example Prefab Rails Application +NOTE: this has been updated in the latest commit to use the newest version of the Prefab Ruby SDK + This repo shows how to add [Prefab] to your Rails app to get access to features like - Dynamic log levels @@ -10,7 +12,6 @@ Follow along on YouTube [![YouTube](https://img.youtube.com/vi/F1aaGwGAIUQ/0.jpg)](https://www.youtube.com/watch?v=F1aaGwGAIUQ) - ## `rails new` [Full diff](https://github.com/prefab-cloud/example-rails-app/compare/new-repo...rails-new) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 48b88d1..c16e11e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,7 +2,7 @@ class ApplicationController < ActionController::Base include Authentication around_action do |_, block| - $prefab.with_context(prefab_context, &block) + Prefab.with_context(prefab_context, &block) end def prefab_context @@ -12,7 +12,7 @@ def prefab_context }, user: { - id: current_user&.id, + key: current_user&.id, email: current_user&.email, country: current_user&.country, } diff --git a/app/views/home/_prefab_values.html.erb b/app/views/home/_prefab_values.html.erb index aefdb4f..83a86f2 100644 --- a/app/views/home/_prefab_values.html.erb +++ b/app/views/home/_prefab_values.html.erb @@ -4,24 +4,28 @@ - + - "> - <% $prefab.resolver.presenter.each do |key, config| %> + "> + <% Prefab.instance.resolver.presenter.each do |key, config| %> - + diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index 199e28e..c70f462 100644 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -1,14 +1,23 @@

- 👋 <%= current_user['name'] %> - <%= image_tag "#{current_user['name'].downcase}.jpg", width: "48px", class: "rounded-full" %> + 👋 + <%= current_user["name"] %> + <%= image_tag "#{current_user["name"].downcase}.jpg", + width: "48px", + class: "rounded-full" %>

- <% if $prefab.enabled?("gdpr.banner") %> -
+ <% if Prefab.enabled?("gdpr.banner") %> +

- This website uses cookies to ensure you get the best experience our lawyers insist you have. + This website uses cookies to ensure you get the best experience our + lawyers insist you have.

-

Your server would provide context to Prefab based on your current user and request. For this demo, we fake the current user.

+

Your server would provide context to Prefab based on your current user + and request. For this demo, we fake the current user.

<% Authentication::DEMO_USERS.each do |user| %> -
- + <%= form_with url: '/sign-in-as', method: :post, class: "space-y-4 grow" do |form| %> + <%= form.text_area :user, value: user.to_json, class: "w-full h-24 font-mono" %>
<%= image_tag "#{user[:name].downcase}.jpg", width: "48px", class: "rounded-full" %> - " /> + <%= form.submit "Sign in as #{user[:name]}", + class: + "cursor-pointer bg-blue-500 hover:bg-blue-600 text-white p-2 rounded" %>
- + <% end %> <% end %>
diff --git a/config/application.rb b/config/application.rb index 09ec79e..2c3c59d 100644 --- a/config/application.rb +++ b/config/application.rb @@ -19,14 +19,13 @@ class Application < Rails::Application # config.time_zone = "Central Time (US & Canada)" # config.eager_load_paths << Rails.root.join("extras") - $prefab = Prefab::Client.new - $prefab.set_rails_loggers + Prefab.init - $prefab.on_update do + Prefab.instance.on_update do if defined?(Turbo::StreamsChannel) Turbo::StreamsChannel.broadcast_replace_to :prefab_values, - target: 'prefab-values', - partial: 'home/prefab_values' + target: 'prefab-values', + partial: 'home/prefab_values' end end end diff --git a/config/initializers/logging.rb b/config/initializers/logging.rb new file mode 100644 index 0000000..73970c1 --- /dev/null +++ b/config/initializers/logging.rb @@ -0,0 +1,7 @@ +SemanticLogger.sync! +SemanticLogger.default_level = :trace # Prefab will take over the filtering +SemanticLogger.add_appender( + io: $stdout, + formatter: Rails.env.development? ? :color : :json, + filter: Prefab.log_filter, +) diff --git a/config/puma.rb b/config/puma.rb index dafd66d..197b49a 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -43,6 +43,6 @@ plugin :tmp_restart on_worker_boot do - $prefab = Prefab::Client.new - $prefab.set_rails_loggers + Prefab.fork + SemanticLogger.reopen # if you are using SemanticLogger end
KeyDefaultDefault Evaluated
<%= key %> <%= config.value %><%= $prefab.get(key) %><%= Prefab.get(key) %>