Class: Graphlyte::Editors::CollectVariableReferences

Inherits:
Object
  • Object
show all
Defined in:
lib/graphlyte/editors/collect_variable_references.rb

Overview

Find all variable references in a document

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCollectVariableReferences

Returns a new instance of CollectVariableReferences.



14
15
16
# File 'lib/graphlyte/editors/collect_variable_references.rb', line 14

def initialize
  @references = { Syntax::Operation => {}, Syntax::Fragment => {} }
end

Instance Attribute Details

#referencesObject (readonly)

Returns the value of attribute references.



12
13
14
# File 'lib/graphlyte/editors/collect_variable_references.rb', line 12

def references
  @references
end

Instance Method Details

#collectorObject



27
28
29
30
31
32
33
# File 'lib/graphlyte/editors/collect_variable_references.rb', line 27

def collector
  Editor.new.on_variable_reference do |ref, action|
    d = action.definition
    references[d.class][d.name] ||= [].to_set
    references[d.class][d.name] << ref
  end
end

#edit(doc) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/graphlyte/editors/collect_variable_references.rb', line 18

def edit(doc)
  doc = doc.dup

  InlineFragments.new.edit(doc)
  collector.edit(doc)

  references
end