Sha256: 162f7fe5be23182735b4d206f656bb191305a3e3267144e154a77569cf673d8f

Contents?: true

Size: 1021 Bytes

Versions: 1

Compression:

Stored size: 1021 Bytes

Contents

require 'posix/spawn'

module Ctags
  class Error < StandardError
  end

  module Exuberant
    include POSIX::Spawn

    BIN = File.expand_path("../../../ext/dst/bin/ctags", __FILE__)

    def tags_for_code(file, code)
      tags_for_file(file, code)
    end

    def tags_for_file(file, code=nil)
      if code
        child = Child.new(BIN, '-f', '-', '--extra=+f', '--excmd=number', "--stdin-filename=#{file}", :input => code)
      else
        child = Child.new(BIN, '-f', '-', '--extra=+f', '--excmd=number', file)
      end

      if !child.status.success?
        raise Error, child.err
      end

      tags = {}

      child.out.each_line.map do |line|
        name, file, line, type, *rest = line.split("\t")
        tags[name] = {
          :file => file,
          :line => line.sub(';"','').to_i,
          :type => type.strip
        }
        rest.each do |part|
          key, value = part.strip.split(':', 2)
          tags[name][key.to_sym] = value
        end
      end

      tags
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ctags.rb-1.0.0 lib/ctags/exuberant.rb