Class: Yoda::Store::YardImporter
- Inherits:
-
Object
- Object
- Yoda::Store::YardImporter
- Defined in:
- lib/yoda/store/yard_importer.rb
Instance Attribute Summary collapse
- #patch ⇒ Objects::Patch readonly
- #root_path ⇒ String? readonly
- #source_path ⇒ String? readonly
Class Method Summary collapse
Instance Method Summary collapse
- #import(values) ⇒ self
-
#initialize(id, root_path: nil, source_path: nil) ⇒ YardImporter
constructor
A new instance of YardImporter.
- #register(code_object) ⇒ Object
Constructor Details
#initialize(id, root_path: nil, source_path: nil) ⇒ YardImporter
Returns a new instance of YardImporter.
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
#patch ⇒ Objects::Patch (readonly)
7 8 9 |
# File 'lib/yoda/store/yard_importer.rb', line 7 def patch @patch end |
#root_path ⇒ String? (readonly)
10 11 12 |
# File 'lib/yoda/store/yard_importer.rb', line 10 def root_path @root_path end |
#source_path ⇒ String? (readonly)
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
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.('..', file) new(patch_id_for_file(file), root_path: root_path).import(store.values).patch end |
.patch_id_for_file(file) ⇒ 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
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
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 |