Class: VisualModels::Config

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

Overview

Configuration for the visual_models engine.

Examples:

Minimal setup (no auth, all ApplicationRecord descendants)

VisualModels.configure do |c|
  # no-op — just mounting the engine is enough
end

With basic auth, ActiveModel inclusion, and named scopes

VisualModels.configure do |c|
  c.username = 'admin'
  c.password = 'secret'

  c.include_active_model = true

  c.exclude = [/^Audit::/, 'LegacyImport']

  c.scopes = {
    'all'       => nil,
    'core'      => -> { [User, Post, Comment, Tag] },
    'admin'     => /^Admin::/
  }
end

Multi-database app — explicit bases

# Equivalent to the default (nil), but explicit if you prefer:
VisualModels.configure do |c|
  c.base_class = ['ApplicationRecord', 'AuditRecord', 'AnalyticsRecord']
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



66
67
68
69
70
71
72
73
74
# File 'lib/visual_models/config.rb', line 66

def initialize
  @username             = nil
  @password             = nil
  @title                = 'Model Graph'
  @base_class           = nil   # auto-discover every AR hierarchy
  @include_active_model = false
  @exclude              = []
  @scopes               = { 'all' => nil }
end

Instance Attribute Details

#base_classObject

Abstract base(s) whose descendants are introspected.

Accepts:

- nil      — auto-discover. Walks `ActiveRecord::Base.descendants`, which
             catches ApplicationRecord, AuditRecord, AnalyticsRecord, and any
             other abstract base your app defines. Recommended default.
- String   — single class name, e.g. 'ApplicationRecord'.
- Array    — list of class names, e.g. ['ApplicationRecord', 'AuditRecord'].


47
48
49
# File 'lib/visual_models/config.rb', line 47

def base_class
  @base_class
end

#excludeObject

Array of class-name strings or Regexp patterns. Any model whose name matches is dropped from the graph.



55
56
57
# File 'lib/visual_models/config.rb', line 55

def exclude
  @exclude
end

#include_active_modelObject

Whether to also pull in ActiveModel-only classes (those that include ActiveModel::Model or ActiveModel::Attributes) — handy for form objects.



51
52
53
# File 'lib/visual_models/config.rb', line 51

def include_active_model
  @include_active_model
end

#passwordObject

HTTP Basic Auth credentials. Leave nil to disable auth entirely.



34
35
36
# File 'lib/visual_models/config.rb', line 34

def password
  @password
end

#scopesObject

Hash of label => filter. Each entry becomes a tab.

Filter values:

- nil       — all classes (after `exclude` is applied)
- Regexp    — keep models whose name matches
- Proc      — invoked at request time, must return an array of classes
- Array     — explicit list of class names (strings) or class objects


64
65
66
# File 'lib/visual_models/config.rb', line 64

def scopes
  @scopes
end

#titleObject

Page title shown in the browser tab and header.



37
38
39
# File 'lib/visual_models/config.rb', line 37

def title
  @title
end

#usernameObject

HTTP Basic Auth credentials. Leave nil to disable auth entirely.



34
35
36
# File 'lib/visual_models/config.rb', line 34

def username
  @username
end