Class: ActiverecordCallbackLens::Collector::CallbackDefinition

Inherits:
Data
  • Object
show all
Defined in:
lib/activerecord_callback_lens/collector/callback_definition.rb,
lib/activerecord_callback_lens/collector/callback_definition.rb

Overview

Reopened to add the shared formatting behaviour every renderer needs: the callback’s lifecycle name and a human-readable label for its filter. Keeping this on the domain object (rather than duplicating it across the Mermaid, Graphviz, and HTML renderers) guarantees identical output everywhere and isolates the one I/O-heavy path (proc source slicing) for focused testing.

Defined Under Namespace

Classes: ProcNodeLocator

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#condition_treeObject (readonly)

Returns the value of attribute condition_tree

Returns:

  • (Object)

    the current value of condition_tree



13
14
15
# File 'lib/activerecord_callback_lens/collector/callback_definition.rb', line 13

def condition_tree
  @condition_tree
end

#eventObject (readonly)

Returns the value of attribute event

Returns:

  • (Object)

    the current value of event



13
14
15
# File 'lib/activerecord_callback_lens/collector/callback_definition.rb', line 13

def event
  @event
end

#filterObject (readonly)

Returns the value of attribute filter

Returns:

  • (Object)

    the current value of filter



13
14
15
# File 'lib/activerecord_callback_lens/collector/callback_definition.rb', line 13

def filter
  @filter
end

#modelObject (readonly)

Returns the value of attribute model

Returns:

  • (Object)

    the current value of model



13
14
15
# File 'lib/activerecord_callback_lens/collector/callback_definition.rb', line 13

def model
  @model
end

#phaseObject (readonly)

Returns the value of attribute phase

Returns:

  • (Object)

    the current value of phase



13
14
15
# File 'lib/activerecord_callback_lens/collector/callback_definition.rb', line 13

def phase
  @phase
end

#raw_conditionsObject (readonly)

Returns the value of attribute raw_conditions

Returns:

  • (Object)

    the current value of raw_conditions



13
14
15
# File 'lib/activerecord_callback_lens/collector/callback_definition.rb', line 13

def raw_conditions
  @raw_conditions
end

#source_locationObject (readonly)

Returns the value of attribute source_location

Returns:

  • (Object)

    the current value of source_location



13
14
15
# File 'lib/activerecord_callback_lens/collector/callback_definition.rb', line 13

def source_location
  @source_location
end

Instance Method Details

#callback_nameString

The callback’s lifecycle name, e.g. “before_save”. Centralises the string the renderers previously each rebuilt from phase + event.

Returns:

  • (String)


33
34
35
# File 'lib/activerecord_callback_lens/collector/callback_definition.rb', line 33

def callback_name
  "#{phase}_#{event}"
end

#filter_label(expand: false) ⇒ String

A human-readable label for the filter (Symbol, String, or Proc).

Symbol/String filters render as their own text. A Proc renders as “(proc)” by default; when expand is true it renders its actual source snippet (e.g. “-> { compute_reading_time }”), falling back to “(proc)” on any I/O or parse error.

Parameters:

  • expand (Boolean) (defaults to: false)

Returns:

  • (String)


46
47
48
49
50
51
52
53
54
55
# File 'lib/activerecord_callback_lens/collector/callback_definition.rb', line 46

def filter_label(expand: false)
  case filter
  when Proc
    return "(proc)" unless expand

    proc_source || "(proc)"
  else
    filter.to_s
  end
end