class SketchUpYARD::Stubs::AutoLoadGenerator
Public Instance Methods
generate(namespace_objects, out)
click to toggle source
@param [YARD::CodeObject::Base] namespace_objects @param [IO] out
# File lib/yard-sketchup/stubs/autoload.rb, line 7 def generate(namespace_objects, out) dependencies = resolve_dependencies(namespace_objects) out.puts "# This file is auto-generated by the `thor stubs` command." required = Set.new # Top level is special case. top_level_path = File.join(sketchup_stubs_path, '_top_level.rb') out.puts "require '#{top_level_path}'" # The rest is resolved recursively. dependencies.each { |object| recurse_require(object, required, out) } end
Private Instance Methods
print_dependencies(object, indent = 0)
click to toggle source
# File lib/yard-sketchup/stubs/autoload.rb, line 96 def print_dependencies(object, indent = 0) indent_space = ' ' * indent puts "#{indent_space}#{object.path}" object.dependencies.each { |dependency| print_dependencies(dependency, indent + 1) } end
recurse_require(object, required, out, indent = 0)
click to toggle source
# File lib/yard-sketchup/stubs/autoload.rb, line 114 def recurse_require(object, required, out, indent = 0) return if required.include?(object.path) # If a class inherit from a core Ruby class we might get a Proxy code # object here. We don't generate stubs for those and thus we don't want # to create a require for them either. return if object.object.is_a?(YARD::CodeObjects::Proxy) # First require the dependencies. object.dependencies.each { |dependency| recurse_require(dependency, required, out, indent + 1) } # Then we're good to require this object. require_path = stub_filename(object) # indent_space = ' ' * indent # out.puts "#{indent_space}require '#{require_path}'" out.puts "require '#{require_path}'" required << object.path end
resolve_dependencies(yard_objects)
click to toggle source
# File lib/yard-sketchup/stubs/autoload.rb, line 76 def resolve_dependencies(yard_objects) factory = NodeFactory.new dependencies = SortedSet.new yard_objects.each { |yard_object| object = factory.node(yard_object) if yard_object.type == :class && yard_object.superclass.name != :Object object << factory.node(yard_object.superclass) end unless yard_object.namespace.path.empty? object << factory.node(yard_object.namespace) end dependencies << object } dependencies end
sketchup_stubs_path()
click to toggle source
# File lib/yard-sketchup/stubs/autoload.rb, line 104 def sketchup_stubs_path File.join('sketchup-api-stubs', 'stubs') end
stub_filename(object)
click to toggle source
# File lib/yard-sketchup/stubs/autoload.rb, line 108 def stub_filename(object) basename = object.path.gsub('::', '/') basename = '_top_level' if basename.empty? File.join(sketchup_stubs_path, "#{basename}.rb") end