Class: VisualModels::Installer

Inherits:
Object
  • Object
show all
Defined in:
lib/visual_models/installer.rb

Overview

Handles the ‘rails visual_models:install` setup steps. Keeps rake task logic out of the .rake file so it is testable.

Constant Summary collapse

MOUNT_SNIPPET =
<<~RUBY
  \n  # visual_models — interactive ActiveRecord association graph (development only)
    mount VisualModels::Engine, at: '/dev/models' if Rails.env.development?
RUBY
INITIALIZER_CONTENT =
<<~RUBY
  # frozen_string_literal: true

  # visual_models — interactive ActiveRecord / ActiveModel association graph
  # Mount point is configured in config/routes.rb.
  # Remove this file and the mount if you no longer need the graph.
  #
  # Docs: https://github.com/pniemczyk/visual_models
  return unless Rails.env.development?

  VisualModels.configure do |c|
    # HTTP Basic Auth — leave username nil to disable.
    # c.username = ENV.fetch('VMODEL_USER', nil)
    # c.password = ENV.fetch('VMODEL_PASS', nil)

    # Abstract base(s) whose descendants are introspected.
    # Default (nil) auto-discovers every AR hierarchy by walking
    # ActiveRecord::Base.descendants — picks up ApplicationRecord,
    # AuditRecord, AnalyticsRecord, etc. without further configuration.
    # Override only if you want to restrict the graph:
    # c.base_class = 'ApplicationRecord'
    # c.base_class = ['ApplicationRecord', 'AuditRecord']

    # Include ActiveModel-only classes (form objects, etc.) too.
    # c.include_active_model = false

    # Drop classes by name or regexp.
    # c.exclude = [/^Audit::/, 'LegacyImport']

    # Tabs — each entry is a filter applied on top of the base set.
    # nil = no filter, Regexp = name match, Proc = explicit list, Array = names/classes.
    # c.scopes = {
    #   'all'   => nil,
    #   'core'  => /^(User|Post|Comment|Tag)$/,
    #   'admin' => /^Admin::/
    # }

    # Title shown in the browser tab and page header.
    # c.title = 'Model Graph'
  end
RUBY

Instance Method Summary collapse

Constructor Details

#initialize(app_root) ⇒ Installer

Returns a new instance of Installer.



54
55
56
# File 'lib/visual_models/installer.rb', line 54

def initialize(app_root)
  @root = Pathname.new(app_root)
end

Instance Method Details

#runObject



58
59
60
61
62
# File 'lib/visual_models/installer.rb', line 58

def run
  mount_engine
  create_initializer
  print_summary
end