Sha256: 49a1ecf9a3aa7f472fe4e4b460253e9a00baac1ad3d0a5ab1f723ca4ea5d2aff

Contents?: true

Size: 907 Bytes

Versions: 1

Compression:

Stored size: 907 Bytes

Contents

module ModuleMapper
  module Map

    def self.from(content:, filename:)
      orig_stderr = $stderr.clone
      orig_stdout = $stdout.clone
      $stderr.reopen File.new('/dev/null', 'w')
      $stdout.reopen File.new('/dev/null', 'w')
      begin
        parser = Analyst.for_source(content)
        containers = parser.top_level_entities.select{|e| e.respond_to? :all_methods}
        containers << containers.map(&:classes)
        containers.flatten!.reject!{ |container| container.all_methods.empty? }
        containers.map do |container|
          {
            module_name: container.full_name,
            filename: filename
          }
        end
      rescue
        containers = [
          {
            module_name: "Unknown",
            filename: filename
          }
        ]
      ensure
        $stdout.reopen orig_stdout
        $stderr.reopen orig_stderr
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
module_mapper-1.0.1 lib/module_mapper/map.rb