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
Class Method Summary collapse
Instance Method Summary collapse
- #import(values) ⇒ self
-
#initialize(id, root_path: nil) ⇒ YardImporter
constructor
A new instance of YardImporter.
- #register(code_object) ⇒ Object
Constructor Details
#initialize(id, root_path: nil) ⇒ YardImporter
Returns a new instance of YardImporter.
23 24 25 26 27 |
# File 'lib/yoda/store/yard_importer.rb', line 23 def initialize(id, root_path: nil) @patch = Objects::Patch.new(id) @root_path = root_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 |
Class Method Details
.import(file, root_path: nil) ⇒ Objects::Patch
15 16 17 18 19 20 |
# File 'lib/yoda/store/yard_importer.rb', line 15 def self.import(file, root_path: nil) store = YARD::RegistryStore.new store.load(file) root_path ||= File.('..', file) new(file, root_path: root_path).import(store.values).patch end |
Instance Method Details
#import(values) ⇒ self
31 32 33 34 35 36 |
# File 'lib/yoda/store/yard_importer.rb', line 31 def import(values) values.each do |el| register(el) end self end |
#register(code_object) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/yoda/store/yard_importer.rb', line 39 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 # In YARD, proxy module is undetermined its absolute path and its defined namespace is undetermined. # In Yoda, proxy module is assumed to be defined directory under parent namespace. register_to_parent(code_object) if code_object.parent && (code_object.type == :proxy || code_object.parent.type == :proxy) [new_objects].flatten.compact.each { |new_object| patch.register(new_object) } end |