Class: RubyCms::GemSetup

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_cms/gem_setup.rb

Overview

Ensures the host app's Gemfile declares the gems the admin templates require. Pure Gemfile manipulation — the actual bundle install is run by the Installer.

Constant Summary collapse

RUNTIME_GEMS =
{
  "pagy" => ">= 43.0",
  "discard" => "~> 1.4",
  "audited" => "~> 5.7",
  "friendly_id" => "~> 5.5",
  "noticed" => "~> 2.6",
  "aasm" => "~> 5.5",
  "acts_as_list" => "~> 1.2",
  "pg_search" => "~> 2.3",
  "oj" => "~> 3.16",
  "lograge" => "~> 0.14",
  "rails-i18n" => "~> 8.0",
  "tailwindcss-rails" => nil,
  "ransack" => nil
}.freeze
DEV_GEMS =

ruby_ui ships the Phlex admin components; installed in the development group with require:false, matching the old generator's behavior.

{ "ruby_ui" => nil }.freeze

Instance Method Summary collapse

Constructor Details

#initialize(app_root:) ⇒ GemSetup

Returns a new instance of GemSetup.



29
30
31
# File 'lib/ruby_cms/gem_setup.rb', line 29

def initialize(app_root:)
  @gemfile = Pathname.new(app_root).join("Gemfile")
end

Instance Method Details

#ensure_gems!(modules: [], include_base: true) ⇒ Object

Appends any missing gems to the Gemfile. Returns the list of names added. include_base: add the base RUNTIME/DEV gems (true on a fresh install); on --add pass false so only the newly-selected modules' own gems are added.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/ruby_cms/gem_setup.rb', line 36

def ensure_gems!(modules: [], include_base: true)
  return [] unless @gemfile.exist?

  original = @gemfile.read
  added = []

  if include_base
    RUNTIME_GEMS.each do |name, version|
      next if gem_present?(original, name)

      line = version ? %(gem "#{name}", "#{version}") : %(gem "#{name}")
      append("\n#{line}")
      added << name
    end

    DEV_GEMS.each_key do |name|
      next if gem_present?(original, name)

      append(%(\n\ngroup :development do\n  gem "#{name}", require: false\nend))
      added << name
    end
  end

  modules.each do |mod|
    next unless mod.respond_to?(:gems) && mod.gems

    mod.gems.each do |name, version|
      next if gem_present?(original, name)

      line = version ? %(gem "#{name}", "#{version}") : %(gem "#{name}")
      append("\n#{line}")
      added << name
    end
  end

  added
end

#resolve_conflicts!(modules: []) ⇒ Object

Patch known Gemfile declarations that break optional modules (e.g. passkeys + webauthn vs bitwarden-sdk-secrets both defining WebAuthn). Returns true when the Gemfile was modified.



77
78
79
80
81
82
83
84
85
86
87
# File 'lib/ruby_cms/gem_setup.rb', line 77

def resolve_conflicts!(modules: [])
  return false unless @gemfile.exist?
  return false unless modules.any? { |mod| mod.key == :passkeys }

  content = @gemfile.read
  patched = patch_bitwarden_require_false(content)
  return false if patched == content

  @gemfile.write(patched)
  true
end