Module: VisualModels

Defined in:
app/services/visual_models/models_to_graph.rb,
lib/visual_models.rb,
lib/visual_models/config.rb,
lib/visual_models/engine.rb,
lib/visual_models/version.rb,
lib/visual_models/installer.rb,
app/controllers/visual_models/graph_controller.rb,
app/controllers/visual_models/application_controller.rb

Overview

Introspects ActiveRecord (and optionally ActiveModel) classes and produces a graph payload consumable by the D3 force-directed renderer.

Returns:

{
  nodes: [
    {
      id:           'User',
      table:        'users',
      database:     'primary' | 'analytics' | nil,   # multi-DB awareness
      is_view:      false,                            # backed by a DB view?
      kind:         'active_record' | 'active_model' | 'sti_child' | 'abstract',
      sti_parent:   'Person' | nil,
      abstract:     false,
      module:       'Admin' | nil,
      fields:       [{ name:, type:, primary:, fk: }],
      virtuals:     [{ name:, type: }],
      validations:  [{ attribute:, kind:, options: }],
      counts:       { fields:, virtuals:, associations: }
    }, 
  ],
  links: [
    {
      from:        'Comment',
      to:          'Post',
      name:        'post',
      macro:       'belongs_to' | 'has_one' | 'has_many' | 'has_and_belongs_to_many',
      through:     'tags' | nil,
      polymorphic: false,
      optional:    false,
      inverse:     'comments' | nil,
      class_name:  'Post'
    }, 
  ],
  polymorphic_targets: [
    {
      id:         '<polymorphic:imageable>',
      name:       'imageable',
      users:      [{ model: 'Image', association: 'imageable' }],
      candidates: [{ model: 'Post', association: 'images', macro: 'has_many' }, ]
    }, 
  ],
  sti_links: [{ from: 'Admin', to: 'User' }],
  databases: ['primary', 'analytics']
}

Defined Under Namespace

Classes: ApplicationController, Config, Engine, GraphController, Installer, ModelsToGraph

Constant Summary collapse

VERSION =
'0.1.0'

Class Method Summary collapse

Class Method Details

.configObject



14
15
16
# File 'lib/visual_models.rb', line 14

def config
  @config ||= Config.new
end

.configure {|config| ... } ⇒ Object

Yields:



10
11
12
# File 'lib/visual_models.rb', line 10

def configure
  yield config
end

.reset_config!Object



18
19
20
# File 'lib/visual_models.rb', line 18

def reset_config!
  @config = Config.new
end