Class: Solargraph::Arc::Storage

Inherits:
Object
  • Object
show all
Defined in:
lib/solargraph/arc/storage.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.instanceObject



4
5
6
# File 'lib/solargraph/arc/storage.rb', line 4

def self.instance
  @instance ||= self.new
end

Instance Method Details

#process(source_map, ns) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/solargraph/arc/storage.rb', line 8

def process(source_map, ns)
  return [] unless source_map.filename.include?("app/models")

  walker = Walker.from_source(source_map.source)
  pins   = []

  walker.on :send, [nil, :has_one_attached] do |ast|
    name = ast.children[2].children.first

    pins << Util.build_public_method(
      ns,
      name.to_s,
      types: ["ActiveStorage::Attached::One"],
      location: Util.build_location(ast, ns.filename)
    )
  end

  walker.on :send, [nil, :has_many_attached] do |ast|
    name = ast.children[2].children.first

    pins << Util.build_public_method(
      ns,
      name.to_s,
      types: ["ActiveStorage::Attached::Many"],
      location: Util.build_location(ast, ns.filename)
    )
  end

  walker.walk
  Solargraph.logger.debug("[ARC][Storage] added #{pins.map(&:name)} to #{ns.path}") if pins.any?
  pins
end