rbtags 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +3 -0
- data/Rakefile +8 -0
- data/lib/rbtags.rb +31 -0
- data/lib/rbtags/class.rb +15 -0
- data/lib/rbtags/file.rb +20 -0
- data/lib/rbtags/formats.rb +5 -0
- data/lib/rbtags/formats/extended.rb +26 -0
- data/lib/rbtags/formats/extended/class.rb +14 -0
- data/lib/rbtags/formats/extended/instance.rb +25 -0
- data/lib/rbtags/formats/extended/method.rb +30 -0
- data/lib/rbtags/module.rb +9 -0
- data/lib/rbtags/object.rb +29 -0
- data/lib/rbtags/rake/tasks.rb +10 -0
- data/lib/rbtags/rake/tasks/tags.rb +31 -0
- data/lib/rbtags/version.rb +5 -0
- metadata +115 -0
    
        data/README
    ADDED
    
    
    
        data/Rakefile
    ADDED
    
    
    
        data/lib/rbtags.rb
    ADDED
    
    | @@ -0,0 +1,31 @@ | |
| 1 | 
            +
            # -*- coding: utf-8 -*-
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module RbTags
         | 
| 4 | 
            +
              require 'rbtags/file'
         | 
| 5 | 
            +
              require 'rbtags/formats'
         | 
| 6 | 
            +
              require 'rbtags/version'
         | 
| 7 | 
            +
             | 
| 8 | 
            +
              class << self
         | 
| 9 | 
            +
                def with_format(with)
         | 
| 10 | 
            +
                  saved_format = format
         | 
| 11 | 
            +
                  format with
         | 
| 12 | 
            +
                  yield
         | 
| 13 | 
            +
                  format.finish
         | 
| 14 | 
            +
                ensure
         | 
| 15 | 
            +
                  format saved_format
         | 
| 16 | 
            +
                end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                def format(format = nil)
         | 
| 19 | 
            +
                  return @format = format if format
         | 
| 20 | 
            +
                  @format ||= Formats::Extended.new
         | 
| 21 | 
            +
                end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                def path
         | 
| 24 | 
            +
                  ::File.expand_path('..', __FILE__)
         | 
| 25 | 
            +
                end
         | 
| 26 | 
            +
              end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
              require 'rbtags/class'
         | 
| 29 | 
            +
              require 'rbtags/module'
         | 
| 30 | 
            +
              require 'rbtags/object'
         | 
| 31 | 
            +
            end
         | 
    
        data/lib/rbtags/class.rb
    ADDED
    
    | @@ -0,0 +1,15 @@ | |
| 1 | 
            +
            # -*- coding: utf-8 -*-
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class Class
         | 
| 4 | 
            +
              inherited = method(:inherited)
         | 
| 5 | 
            +
              define_method :inherited do |subclass|
         | 
| 6 | 
            +
                RbTags.format.class subclass, caller
         | 
| 7 | 
            +
                inherited.call(subclass)
         | 
| 8 | 
            +
              end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
              singleton_method_added = method(:singleton_method_added)
         | 
| 11 | 
            +
              define_method :singleton_method_added do |method|
         | 
| 12 | 
            +
                RbTags.format.method self, self, method, true, caller
         | 
| 13 | 
            +
                singleton_method_added.call(method)
         | 
| 14 | 
            +
              end
         | 
| 15 | 
            +
            end
         | 
    
        data/lib/rbtags/file.rb
    ADDED
    
    | @@ -0,0 +1,20 @@ | |
| 1 | 
            +
            # -*- coding: utf-8 -*-
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class RbTags::File
         | 
| 4 | 
            +
              def initialize(file, line)
         | 
| 5 | 
            +
                @file, @line = file, Integer(line)
         | 
| 6 | 
            +
              end
         | 
| 7 | 
            +
             | 
| 8 | 
            +
              def name
         | 
| 9 | 
            +
                @@expanded ||= Hash.new{ |files, file| files[file] = File.expand_path(file) }
         | 
| 10 | 
            +
                @@expanded[@file]
         | 
| 11 | 
            +
              end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
              def line
         | 
| 14 | 
            +
                @@lines ||= Hash.new{ |lines, file|
         | 
| 15 | 
            +
                  sum = 0
         | 
| 16 | 
            +
                  lines[file] = File.open(file, 'rb'){ |io| io.map{ |line| line.chomp } }
         | 
| 17 | 
            +
                }
         | 
| 18 | 
            +
                @@lines[@file][@line - 1]
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
            end
         | 
| @@ -0,0 +1,26 @@ | |
| 1 | 
            +
            # -*- coding: utf-8 -*-
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class RbTags::Formats::Extended
         | 
| 4 | 
            +
              require 'rbtags/formats/extended/instance'
         | 
| 5 | 
            +
              require 'rbtags/formats/extended/class'
         | 
| 6 | 
            +
              require 'rbtags/formats/extended/method'
         | 
| 7 | 
            +
             | 
| 8 | 
            +
              def initialize(io = $stdout)
         | 
| 9 | 
            +
                @io = io
         | 
| 10 | 
            +
                @lines = []
         | 
| 11 | 
            +
              end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
              def class(klass, trace)
         | 
| 14 | 
            +
                @lines << Class.new(klass, trace)
         | 
| 15 | 
            +
              end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
              def method(klass, object, method, singleton, trace)
         | 
| 18 | 
            +
                @lines << Method.new(klass, object, method, singleton, trace)
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
              def finish
         | 
| 22 | 
            +
                @lines.reject{ |line| line.reject? }.map{ |line| line.to_s }.sort.each do |line|
         | 
| 23 | 
            +
                  @io.puts line
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
              end
         | 
| 26 | 
            +
            end
         | 
| @@ -0,0 +1,25 @@ | |
| 1 | 
            +
            # -*- coding: utf-8 -*-
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module RbTags::Formats::Extended::Instance
         | 
| 4 | 
            +
              def initialize(trace)
         | 
| 5 | 
            +
                @file = RbTags::File.new(*%r{\A(.*):(\d+)\z}.match(trace.find{ |line| line !~ %r{\A(.*):(\d+):in .*\z} })[1..2])
         | 
| 6 | 
            +
              end
         | 
| 7 | 
            +
             | 
| 8 | 
            +
              def reject?
         | 
| 9 | 
            +
                @file.name.start_with? RbTags.path
         | 
| 10 | 
            +
              end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            private
         | 
| 13 | 
            +
             | 
| 14 | 
            +
              def line(tag)
         | 
| 15 | 
            +
                "%s\t%s\t%s" % [tag, filename, pattern]
         | 
| 16 | 
            +
              end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
              def filename
         | 
| 19 | 
            +
                @file.name.start_with?(Dir.pwd) ? @file.name[Dir.pwd.length+1..-1] : @file.name
         | 
| 20 | 
            +
              end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
              def pattern
         | 
| 23 | 
            +
                '/^%s$/' % @file.line
         | 
| 24 | 
            +
              end
         | 
| 25 | 
            +
            end
         | 
| @@ -0,0 +1,30 @@ | |
| 1 | 
            +
            # -*- coding: utf-8 -*-
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class RbTags::Formats::Extended::Method
         | 
| 4 | 
            +
              include RbTags::Formats::Extended::Instance
         | 
| 5 | 
            +
             | 
| 6 | 
            +
              def initialize(klass, object, method, singleton, trace)
         | 
| 7 | 
            +
                @klass, @object, @method, @singleton = klass, object, method, singleton
         | 
| 8 | 
            +
                super trace
         | 
| 9 | 
            +
              end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
              def reject?
         | 
| 12 | 
            +
                not (not @singleton and @method == :initialize) and
         | 
| 13 | 
            +
                ((class << (@singleton ? @klass : @object); self; end).private_method_defined?(@method) or
         | 
| 14 | 
            +
                 super)
         | 
| 15 | 
            +
              end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
              def to_s
         | 
| 18 | 
            +
                line(qualified)
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            private
         | 
| 22 | 
            +
             | 
| 23 | 
            +
              def qualified
         | 
| 24 | 
            +
                if not @singleton and @method == :initialize
         | 
| 25 | 
            +
                  '%s.new' % @klass
         | 
| 26 | 
            +
                else
         | 
| 27 | 
            +
                  '%s%s%s' % [@klass, @singleton ? '.' : '#', @method]
         | 
| 28 | 
            +
                end
         | 
| 29 | 
            +
              end
         | 
| 30 | 
            +
            end
         | 
| @@ -0,0 +1,9 @@ | |
| 1 | 
            +
            # -*- coding: utf-8 -*-
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class Module
         | 
| 4 | 
            +
              unbound_method_added = instance_method(:method_added)
         | 
| 5 | 
            +
              define_method :method_added do |method|
         | 
| 6 | 
            +
                RbTags.format.method self, Object.new.extend(self), method, false, caller if instance_of? Module
         | 
| 7 | 
            +
                unbound_method_added.bind(self).call(method)
         | 
| 8 | 
            +
              end
         | 
| 9 | 
            +
            end
         | 
| @@ -0,0 +1,29 @@ | |
| 1 | 
            +
            # -*- coding: utf-8 -*-
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module RbTags::Object
         | 
| 4 | 
            +
              Allocator = Hash.new{|h,k| h[k] = k.allocate }.merge(Fixnum=>1,
         | 
| 5 | 
            +
                                                                   Bignum=>10000000000000000,
         | 
| 6 | 
            +
                                                                   Float=>1.1,
         | 
| 7 | 
            +
                                                                   Symbol=>:method_args_tmp,
         | 
| 8 | 
            +
                                                                   Binding=>binding,
         | 
| 9 | 
            +
                                                                   UnboundMethod=>Object.instance_method(:object_id),
         | 
| 10 | 
            +
                                                                   Method=>Object.method(:object_id),
         | 
| 11 | 
            +
                                                                   Proc=>lambda{},
         | 
| 12 | 
            +
                                                                   Continuation=>callcc{|c|c},
         | 
| 13 | 
            +
                                                                   Thread=>Thread.new{},
         | 
| 14 | 
            +
                                                                   FalseClass=>false,
         | 
| 15 | 
            +
                                                                   TrueClass=>true,
         | 
| 16 | 
            +
                                                                   NilClass=>nil,
         | 
| 17 | 
            +
                                                                   Struct=>Struct.new(:a).new(1))
         | 
| 18 | 
            +
            end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
            class Object
         | 
| 21 | 
            +
              class << self
         | 
| 22 | 
            +
                method_added = method(:method_added)
         | 
| 23 | 
            +
                define_method :method_added do |method|
         | 
| 24 | 
            +
                  begin o = RbTags::Object::Allocator[self] rescue Exception end
         | 
| 25 | 
            +
                  RbTags.format.method self, o, method, false, caller
         | 
| 26 | 
            +
                  method_added.call(method)
         | 
| 27 | 
            +
                end
         | 
| 28 | 
            +
              end
         | 
| 29 | 
            +
            end
         | 
| @@ -0,0 +1,31 @@ | |
| 1 | 
            +
            # -*- coding: utf-8 -*-
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class RbTags::Rake::Tasks::Tags < Rake::TaskLib
         | 
| 4 | 
            +
              def initialize(libs = nil, requires = nil)
         | 
| 5 | 
            +
                @libs = libs || 'lib'
         | 
| 6 | 
            +
                @requires = requires || @libs.map{ |lib|
         | 
| 7 | 
            +
                  FileList[lib + '/**/*.rb'].map{ |path| path.sub(%r{\A#{Regexp.escape(lib)}/}, '') }
         | 
| 8 | 
            +
                }.flatten.sort
         | 
| 9 | 
            +
                yield self if block_given?
         | 
| 10 | 
            +
                define
         | 
| 11 | 
            +
              end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
              def define
         | 
| 14 | 
            +
                desc 'Generate TAGS'
         | 
| 15 | 
            +
                task :tags do
         | 
| 16 | 
            +
                  require 'rbtags'
         | 
| 17 | 
            +
                  libs.each do |lib|
         | 
| 18 | 
            +
                    $LOAD_PATH.unshift lib unless $LOAD_PATH.include? lib
         | 
| 19 | 
            +
                  end
         | 
| 20 | 
            +
                  File.open('TAGS', 'wb') do |tags|
         | 
| 21 | 
            +
                    RbTags.with_format RbTags::Formats::Extended.new(tags) do
         | 
| 22 | 
            +
                      requires.each do |path|
         | 
| 23 | 
            +
                        require path
         | 
| 24 | 
            +
                      end
         | 
| 25 | 
            +
                    end
         | 
| 26 | 
            +
                  end
         | 
| 27 | 
            +
                end
         | 
| 28 | 
            +
              end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
              attr_accessor :libs, :requires
         | 
| 31 | 
            +
            end
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,115 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification 
         | 
| 2 | 
            +
            name: rbtags
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            +
              hash: 27
         | 
| 5 | 
            +
              prerelease: false
         | 
| 6 | 
            +
              segments: 
         | 
| 7 | 
            +
              - 0
         | 
| 8 | 
            +
              - 1
         | 
| 9 | 
            +
              - 0
         | 
| 10 | 
            +
              version: 0.1.0
         | 
| 11 | 
            +
            platform: ruby
         | 
| 12 | 
            +
            authors: 
         | 
| 13 | 
            +
            - Nikolai Weibull
         | 
| 14 | 
            +
            autorequire: 
         | 
| 15 | 
            +
            bindir: bin
         | 
| 16 | 
            +
            cert_chain: []
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            date: 2011-03-03 00:00:00 +01:00
         | 
| 19 | 
            +
            default_executable: 
         | 
| 20 | 
            +
            dependencies: 
         | 
| 21 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 22 | 
            +
              name: lookout
         | 
| 23 | 
            +
              prerelease: false
         | 
| 24 | 
            +
              requirement: &id001 !ruby/object:Gem::Requirement 
         | 
| 25 | 
            +
                none: false
         | 
| 26 | 
            +
                requirements: 
         | 
| 27 | 
            +
                - - ~>
         | 
| 28 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 29 | 
            +
                    hash: 3
         | 
| 30 | 
            +
                    segments: 
         | 
| 31 | 
            +
                    - 2
         | 
| 32 | 
            +
                    - 0
         | 
| 33 | 
            +
                    version: "2.0"
         | 
| 34 | 
            +
              type: :development
         | 
| 35 | 
            +
              version_requirements: *id001
         | 
| 36 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 37 | 
            +
              name: yard
         | 
| 38 | 
            +
              prerelease: false
         | 
| 39 | 
            +
              requirement: &id002 !ruby/object:Gem::Requirement 
         | 
| 40 | 
            +
                none: false
         | 
| 41 | 
            +
                requirements: 
         | 
| 42 | 
            +
                - - ~>
         | 
| 43 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 44 | 
            +
                    hash: 7
         | 
| 45 | 
            +
                    segments: 
         | 
| 46 | 
            +
                    - 0
         | 
| 47 | 
            +
                    - 6
         | 
| 48 | 
            +
                    - 0
         | 
| 49 | 
            +
                    version: 0.6.0
         | 
| 50 | 
            +
              type: :development
         | 
| 51 | 
            +
              version_requirements: *id002
         | 
| 52 | 
            +
            description: |
         | 
| 53 | 
            +
              # RbTags #
         | 
| 54 | 
            +
              
         | 
| 55 | 
            +
              RbTags is a replacement for ctags (and rtags) for Ruby.
         | 
| 56 | 
            +
             | 
| 57 | 
            +
            email: now@bitwi.se
         | 
| 58 | 
            +
            executables: []
         | 
| 59 | 
            +
             | 
| 60 | 
            +
            extensions: []
         | 
| 61 | 
            +
             | 
| 62 | 
            +
            extra_rdoc_files: []
         | 
| 63 | 
            +
             | 
| 64 | 
            +
            files: 
         | 
| 65 | 
            +
            - lib/rbtags/class.rb
         | 
| 66 | 
            +
            - lib/rbtags/file.rb
         | 
| 67 | 
            +
            - lib/rbtags/formats/extended/class.rb
         | 
| 68 | 
            +
            - lib/rbtags/formats/extended/instance.rb
         | 
| 69 | 
            +
            - lib/rbtags/formats/extended/method.rb
         | 
| 70 | 
            +
            - lib/rbtags/formats/extended.rb
         | 
| 71 | 
            +
            - lib/rbtags/formats.rb
         | 
| 72 | 
            +
            - lib/rbtags/module.rb
         | 
| 73 | 
            +
            - lib/rbtags/object.rb
         | 
| 74 | 
            +
            - lib/rbtags/rake/tasks/tags.rb
         | 
| 75 | 
            +
            - lib/rbtags/rake/tasks.rb
         | 
| 76 | 
            +
            - lib/rbtags/version.rb
         | 
| 77 | 
            +
            - lib/rbtags.rb
         | 
| 78 | 
            +
            - README
         | 
| 79 | 
            +
            - Rakefile
         | 
| 80 | 
            +
            has_rdoc: true
         | 
| 81 | 
            +
            homepage: http://github.com/now/rbtags
         | 
| 82 | 
            +
            licenses: []
         | 
| 83 | 
            +
             | 
| 84 | 
            +
            post_install_message: 
         | 
| 85 | 
            +
            rdoc_options: []
         | 
| 86 | 
            +
             | 
| 87 | 
            +
            require_paths: 
         | 
| 88 | 
            +
            - lib
         | 
| 89 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement 
         | 
| 90 | 
            +
              none: false
         | 
| 91 | 
            +
              requirements: 
         | 
| 92 | 
            +
              - - ">="
         | 
| 93 | 
            +
                - !ruby/object:Gem::Version 
         | 
| 94 | 
            +
                  hash: 3
         | 
| 95 | 
            +
                  segments: 
         | 
| 96 | 
            +
                  - 0
         | 
| 97 | 
            +
                  version: "0"
         | 
| 98 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement 
         | 
| 99 | 
            +
              none: false
         | 
| 100 | 
            +
              requirements: 
         | 
| 101 | 
            +
              - - ">="
         | 
| 102 | 
            +
                - !ruby/object:Gem::Version 
         | 
| 103 | 
            +
                  hash: 3
         | 
| 104 | 
            +
                  segments: 
         | 
| 105 | 
            +
                  - 0
         | 
| 106 | 
            +
                  version: "0"
         | 
| 107 | 
            +
            requirements: []
         | 
| 108 | 
            +
             | 
| 109 | 
            +
            rubyforge_project: 
         | 
| 110 | 
            +
            rubygems_version: 1.3.7
         | 
| 111 | 
            +
            signing_key: 
         | 
| 112 | 
            +
            specification_version: 3
         | 
| 113 | 
            +
            summary: RbTags is a replacement for ctags (and rtags) for Ruby.
         | 
| 114 | 
            +
            test_files: []
         | 
| 115 | 
            +
             |