bro_hub 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5e8da50149016fb9bbf5775f4257a85855b058372b1077ee0e1f8e24d6ac4811
4
- data.tar.gz: c609ff0fca64a15b7a3682cdcc74c5a61ff8b944e18c075d0583b6515e0fa1e2
3
+ metadata.gz: c58315415147812aef646d84120a0b41873fcdc68c854103525495ae857e57be
4
+ data.tar.gz: c2f5e8065183d9e69679f96927827dced7865c6f1a19ea3034a64eb54522244d
5
5
  SHA512:
6
- metadata.gz: 2ee002d30eff44fa14bbff1261b76c0ac101ea6adf6c756e328abb6d059e9e7971f75912e03db7f1a05e490205250a0396109d9db6742a22ba87a70c9d6fae9a
7
- data.tar.gz: 8f963753dd73fa6a0ac48e4c59e130ddd5f5d5bbb47e5e73228580c1bef3f48e2067b21ce004498f8dcd494913ae2e82937e6336ad08c276f3d4b7cdf92d059c
6
+ metadata.gz: 6aefb62a9ac21abe8455c64da8b7d8b384e099a8d4c6a878ccb1cdbdb99939774f48727a4f95ff211997f1f70f17c7267f6571e6a9b0c5213a246b1c76e53390
7
+ data.tar.gz: 336d8b3283433dbc9c30795fb6f974b62363f31479578c85f3a526d08fbec0794f6dd5294045b1cfc495bc61be2cca1459e92b4546880843e25c240797c63c3d
data/README.md CHANGED
@@ -17,6 +17,9 @@ Rails 7.1+, Ruby 3.2+. No database, no JavaScript, no asset pipeline.
17
17
  gem "bro_hub"
18
18
  ```
19
19
 
20
+ Minimum versions: **env_bro 0.2.0** and **safe_bro 0.1.0**. Older EnvBro (0.1.x) has no BroHub support: the installer skips
21
+ it with a warning and leaves its old mount alone, so `bundle update env_bro` first.
22
+
20
23
  ```sh
21
24
  bin/rails generate bro_hub:install
22
25
  ```
@@ -32,9 +35,16 @@ This sets up the whole dashboard in one go:
32
35
  (`--remove-direct-mounts` says yes without asking; without a terminal the lines are left alone with a warning),
33
36
  4. runs the installer of every Bro gem in your Gemfile (SafeBro's initializer and migrations, EnvBro's, ...).
34
37
 
38
+ Existing config is never overwritten: if `config/initializers/bro_hub.rb` (or `env_bro.rb` / `safe_bro.rb`) is there already,
39
+ it is skipped, and `--skip` / `--force` / `--pretend` are passed on to every gem's installer. In scripts and agents, pass
40
+ `--skip` and `--mount-path=...` so nothing waits on a prompt.
41
+
35
42
  You can also run a gem's own installer on its own: `bin/rails generate safe_bro:install` sets up BroHub first, then SafeBro.
36
43
  Running both, in any order, mounts BroHub once.
37
44
 
45
+ Who is signed in: the default calls `current_user` on your controller, and falls back to `Current.user` (the Rails 8
46
+ authentication generator has only that). The top-right label tries `email`, `email_address` (Rails 8) then `name`.
47
+
38
48
  ```ruby
39
49
  # config/initializers/bro_hub.rb
40
50
  BroHub.configure do |config|
@@ -3,7 +3,8 @@ module BroHub
3
3
  # Controller the shell's own pages inherit from, so the host's authentication runs.
4
4
  attr_accessor :parent_controller
5
5
 
6
- # ->(controller) { the signed-in user, or nil }. The default calls `current_user` when the controller has it.
6
+ # ->(controller) { the signed-in user, or nil }. The default calls `current_user` when the controller has it,
7
+ # and otherwise falls back to `Current.user` (what the Rails 8 authentication generator sets up).
7
8
  attr_accessor :current_user
8
9
 
9
10
  # ->(user) { text shown at the top right }
@@ -16,8 +17,14 @@ module BroHub
16
17
 
17
18
  def initialize
18
19
  @parent_controller = "::ApplicationController"
19
- @current_user = ->(controller) { controller.send(:current_user) if controller.respond_to?(:current_user, true) }
20
- @user_label = ->(user) { user.try(:email) || user.try(:name) || user.to_s }
20
+ @current_user = ->(controller) do
21
+ if controller.respond_to?(:current_user, true)
22
+ controller.send(:current_user)
23
+ elsif defined?(::Current) && ::Current.respond_to?(:user)
24
+ ::Current.user
25
+ end
26
+ end
27
+ @user_label = ->(user) { user.try(:email) || user.try(:email_address) || user.try(:name) || user.to_s }
21
28
  @require_ssl = defined?(Rails) && Rails.respond_to?(:env) ? Rails.env.production? : false
22
29
  @brand_name = "DeadBro"
23
30
  @brand_url = "https://www.deadbro.com"
@@ -1,3 +1,3 @@
1
1
  module BroHub
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -19,8 +19,25 @@ module BroHub
19
19
  class_option :remove_direct_mounts, type: :boolean, default: nil,
20
20
  desc: "Comment out old `mount SafeBro::Engine`-style lines (asked interactively when omitted)"
21
21
 
22
+ # Bro gems that only work with BroHub from these versions on.
23
+ MINIMUM_VERSIONS = { "env_bro" => "0.2.0", "safe_bro" => "0.1.0" }.freeze
24
+
25
+ def check_gem_versions
26
+ MINIMUM_VERSIONS.each do |name, minimum|
27
+ installed = Gem.loaded_specs[name]&.version
28
+ next if installed.nil? || installed >= Gem::Version.new(minimum)
29
+
30
+ say_status :warning, "#{name} #{installed} is too old for BroHub (needs #{minimum}+), so it is not installed " \
31
+ "and its old mount is left alone. Run `bundle update #{name}` and install again.", :red
32
+ end
33
+ end
34
+
22
35
  def copy_initializer
23
- copy_file "bro_hub.rb", "config/initializers/bro_hub.rb"
36
+ if File.exist?(File.join(destination_root, "config/initializers/bro_hub.rb"))
37
+ say_status :skip, "config/initializers/bro_hub.rb already exists, leaving it alone", :yellow
38
+ else
39
+ copy_file "bro_hub.rb", "config/initializers/bro_hub.rb"
40
+ end
24
41
  end
25
42
 
26
43
  def mount_engine
@@ -35,7 +52,8 @@ module BroHub
35
52
  def retire_direct_mounts
36
53
  direct_mounts.each do |line|
37
54
  if remove_direct_mount?(line)
38
- gsub_file "config/routes.rb", line, "# BroHub mounts this now: #{line.strip}"
55
+ indent = line[/\A\s*/]
56
+ gsub_file "config/routes.rb", line, "#{indent}# BroHub mounts this now: #{line.strip}"
39
57
  else
40
58
  say_status :warning, "#{line.strip} is still mounted directly; BroHub also serves it under #{mount_path}. " \
41
59
  "Re-run with --remove-direct-mounts or delete the line.", :yellow
@@ -48,7 +66,7 @@ module BroHub
48
66
 
49
67
  bro_gem_installers.each do |section, namespace|
50
68
  say_status :install, "#{section.name} (#{namespace})", :green
51
- invoke namespace, [], skip_bro_hub: true, mount_path: mount_path
69
+ invoke namespace, [], { skip_bro_hub: true, mount_path: mount_path }.merge(conflict_options)
52
70
  end
53
71
  end
54
72
 
@@ -62,6 +80,11 @@ module BroHub
62
80
  end
63
81
 
64
82
  private
83
+ # Pass --skip/--force/--pretend/--quiet on to the installers of the other gems.
84
+ def conflict_options
85
+ options.slice(:force, :skip, :pretend, :quiet).to_h.symbolize_keys.select { |_, value| value }
86
+ end
87
+
65
88
  def routes_source
66
89
  path = File.join(destination_root, "config/routes.rb")
67
90
  File.exist?(path) ? File.read(path) : ""
@@ -1,9 +1,10 @@
1
1
  BroHub.configure do |config|
2
- # How to find the signed-in user. The default calls `current_user` on the controller when it has one.
2
+ # How to find the signed-in user. The default calls `current_user` on the controller when it has one,
3
+ # and falls back to `Current.user` (Rails 8 authentication generator).
3
4
  # config.current_user = ->(controller) { controller.current_user }
4
5
 
5
6
  # What to show at the top right.
6
- # config.user_label = ->(user) { user.email }
7
+ # config.user_label = ->(user) { user.email } # Rails 8 auth generator: user.email_address (also tried by default)
7
8
 
8
9
  # Which controller the dashboard's own pages inherit from (so your authentication runs).
9
10
  # config.parent_controller = "::ApplicationController"
@@ -29,7 +29,7 @@ module BroHub
29
29
  def install_bro_hub
30
30
  return if options[:skip_bro_hub]
31
31
 
32
- forward = { install_gems: false }
32
+ forward = { install_gems: false }.merge(bro_hub_conflict_options)
33
33
  forward[:mount_path] = options[:mount_path] if options[:mount_path].present?
34
34
  forward[:remove_direct_mounts] = options[:remove_direct_mounts] unless options[:remove_direct_mounts].nil?
35
35
  invoke "bro_hub:install", [], forward
@@ -37,6 +37,21 @@ module BroHub
37
37
  end
38
38
 
39
39
  private
40
+ # --skip / --force / --pretend / --quiet must reach the generators we invoke, or a nested
41
+ # installer would fall back to asking about conflicts (and with no terminal, overwrite).
42
+ def bro_hub_conflict_options
43
+ options.slice(:force, :skip, :pretend, :quiet).to_h.symbolize_keys.select { |_, value| value }
44
+ end
45
+
46
+ # Copies a config file once. An existing file is yours: it is never replaced, even with --force.
47
+ def copy_config_once(source, destination)
48
+ if File.exist?(File.join(destination_root, destination))
49
+ say_status :skip, "#{destination} already exists, leaving it alone", :yellow
50
+ else
51
+ copy_file source, destination
52
+ end
53
+ end
54
+
40
55
  # Where BroHub ended up, read back from the routes (it may have been mounted before).
41
56
  def bro_hub_path
42
57
  routes = File.join(destination_root, "config/routes.rb")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bro_hub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruby Dev SRL