Class: Yoda::Store::YardImporter

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, root_path: nil, source_path: nil) ⇒ YardImporter

Returns a new instance of YardImporter.

Parameters:

  • id (String)


32
33
34
35
36
37
# File 'lib/yoda/store/yard_importer.rb', line 32

def initialize(id, root_path: nil, source_path: nil)
  @patch = Objects::Patch.new(id)
  @root_path = root_path
  @source_path = source_path
  @registered = Set.new
end

Instance Attribute Details

#patchObjects::Patch (readonly)

Returns:



7
8
9
# File 'lib/yoda/store/yard_importer.rb', line 7

def patch
  @patch
end

#root_pathString? (readonly)

Returns:

  • (String, nil)


10
11
12
# File 'lib/yoda/store/yard_importer.rb', line 10

def root_path
  @root_path
end

#source_pathString? (readonly)

Returns:

  • (String, nil)


13
14
15
# File 'lib/yoda/store/yard_importer.rb', line 13

def source_path
  @source_path
end

Class Method Details

.import(file, root_path: nil) ⇒ Objects::Patch

Parameters:

  • file (String)
  • root_path (String, nil) (defaults to: nil)

Returns:



18
19
20
21
22
23
# File 'lib/yoda/store/yard_importer.rb', line 18

def self.import(file, root_path: nil)
  store = YARD::RegistryStore.new
  store.load(file)
  root_path ||= File.expand_path('..', file)
  new(patch_id_for_file(file), root_path: root_path).import(store.values).patch
end

.patch_id_for_file(file) ⇒ String

Parameters:

  • file (String)

Returns:

  • (String)


27
28
29
# File 'lib/yoda/store/yard_importer.rb', line 27

def self.patch_id_for_file(file)
  file
end

Instance Method Details

#import(values) ⇒ self

Parameters:

  • values (Array<YARD::CodeObjects::Base>)

Returns:

  • (self)


41
42
43
44
45
46
# File 'lib/yoda/store/yard_importer.rb', line 41

def import(values)
  values.each do |el|
    register(el)
  end
  self
end

#register(code_object) ⇒ Object

Parameters:

  • code_object (YARD::CodeObjects::Base)


49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/yoda/store/yard_importer.rb', line 49

def register(code_object)
  return if @registered.member?(code_object.path)
  @registered.add(code_object.path)
  register(code_object.parent) if code_object.parent

  new_objects = begin
    case code_object.type
    when :root
      convert_root_object(code_object)
    when :class
      convert_class_object(code_object)
    when :module
      convert_module_object(code_object)
    when :classvariable
      # convert_class_variable_object(code_object)
    when :method
      convert_method_object(code_object)
    when :macro
      # convert_macro_object(code_object)
    when :constant
      convert_constant_object(code_object)
    when :proxy
      create_proxy_module(code_object)
    else
      fail ArgumentError, 'Unsupported type code object'
    end
  end

  [new_objects].flatten.compact.each { |new_object| patch.register(new_object) }
end