Class: Yoda::Store::Actions::ReadFile

Inherits:
Object
  • Object
show all
Defined in:
lib/yoda/store/actions/read_file.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(registry, file, content: nil, root_path: nil) ⇒ ReadFile

Returns a new instance of ReadFile.

Parameters:

  • registry (Registry)
  • file (String)
  • content (String, nil) (defaults to: nil)


30
31
32
33
34
35
# File 'lib/yoda/store/actions/read_file.rb', line 30

def initialize(registry, file, content: nil, root_path: nil)
  @registry = registry
  @file = file
  @content = content
  @root_path = root_path
end

Instance Attribute Details

#contentString? (readonly)

Returns:

  • (String, nil)


12
13
14
# File 'lib/yoda/store/actions/read_file.rb', line 12

def content
  @content
end

#fileString (readonly)

Returns:

  • (String)


9
10
11
# File 'lib/yoda/store/actions/read_file.rb', line 9

def file
  @file
end

#registryRegistry (readonly)

Returns:



6
7
8
# File 'lib/yoda/store/actions/read_file.rb', line 6

def registry
  @registry
end

Class Method Details

.patch_id_for_file(file) ⇒ String

Parameters:

  • file (String)

Returns:

  • (String)


23
24
25
# File 'lib/yoda/store/actions/read_file.rb', line 23

def self.patch_id_for_file(file)
  YardImporter.patch_id_for_file(file)
end

.run(registry, file, content: nil, root_path: nil) ⇒ void

This method returns an undefined value.

Parameters:



17
18
19
# File 'lib/yoda/store/actions/read_file.rb', line 17

def self.run(registry, file, content: nil, root_path: nil)
  self.new(registry, file, content: content, root_path: root_path).run
end

Instance Method Details

#runvoid

This method returns an undefined value.



38
39
40
41
42
43
44
45
46
47
# File 'lib/yoda/store/actions/read_file.rb', line 38

def run
  YARD::Registry.clear
  if content
    YARD.parse_string(content) if Yoda::Parsing.parse_with_comments(content)
  else
    YARD.parse([file])
  end
  patch = YardImporter.new(file, source_path: file).import(YARD::Registry.all + [YARD::Registry.root]).patch
  registry.local_store.add_file_patch(patch)
end