impl 1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. data/README.md +27 -0
  2. data/Rakefile +16 -0
  3. data/bin/impl +16 -0
  4. data/impl.gemspec +29 -0
  5. data/lib/impl.rb +35 -0
  6. data/spec/impl_spec.rb +23 -0
  7. metadata +93 -0
data/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # impl: What's the implementation of a Ruby method?
2
+
3
+ ## Usage
4
+
5
+ $ cd ~/git/ruby193
6
+ $ ctags -R
7
+ $ impl >> tags
8
+
9
+ After moving into the latest Ruby source code directory of you, the first command builds `tags` by the Ruby C source codes, using your own `ctags` command. Then impl extracts Ruby methods both from the source codes and the `tags` file. The command outputs additional tags to STDOUT, so you may want to redirect to `tags` for appending them.
10
+
11
+ Now you can go into the definition of a Ruby method by Ruby method format like `Random#rand`!
12
+
13
+ Higher level handy command is also available. The following command does almost equivalent to the three command previously I showed.
14
+
15
+ $ impl --suite ~/git/ruby193
16
+
17
+ ## Install
18
+
19
+ $ gem install impl
20
+
21
+ ## Author
22
+
23
+ Tatsuhiro Ujihisa
24
+
25
+ ## Trivia
26
+
27
+ `tags` is an all left handed word. `impl` is an all right handed word. If you are a dvorak user, you can type them easily.
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ require "rspec/core/rake_task"
2
+ require "rake/gempackagetask"
3
+
4
+ task :default => :spec
5
+
6
+ desc "Run all examples"
7
+ RSpec::Core::RakeTask.new(:spec) do |t|
8
+ t.rspec_opts = %w[--color]
9
+ t.verbose = false
10
+ end
11
+
12
+ desc "Create the .gem package"
13
+ $gemspec = eval("#{File.read('impl.gemspec')}")
14
+ Rake::GemPackageTask.new($gemspec) do |pkg|
15
+ pkg.need_tar = true
16
+ end
data/bin/impl ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ require 'impl'
3
+ case ARGV.shift
4
+ when '-h'
5
+ puts Impl.help
6
+ when '--suite'
7
+ Dir.chdir(File.expand_path(ARGV.shift)) do
8
+ additional = `#{__FILE__}`
9
+ File.open('tags', 'a') {|io| io.puts additional }
10
+ end
11
+ else
12
+ ctags = File.read('tags')
13
+ dir = File.expand_path '.'
14
+ puts Impl.generate(ctags, dir)
15
+ end
16
+ # vim: set ft=ruby :
data/impl.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ require File.expand_path('../lib/impl', __FILE__)
2
+ Gem::Specification.new do |s|
3
+ s.name = %q{impl}
4
+ s.version = Impl::VERSION.dup
5
+ s.date = Time.now.strftime('%Y-%m-%d')
6
+
7
+ s.summary = %q{What's the implementation of a Ruby method?}
8
+ s.description = %q{generates additional information for Ruby C implementation's method definitions}
9
+
10
+ s.author = 'ujihisa'
11
+ s.email = %q{ujihisa at gmail.com}
12
+
13
+ s.files =
14
+ Dir['lib/**/*'] +
15
+ Dir['bin/**/*'] +
16
+ Dir['spec/**/*'] +
17
+ %w{ impl.gemspec Rakefile README.md }
18
+
19
+ s.require_paths = ["lib"]
20
+ s.executables = ['impl']
21
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
22
+
23
+ s.homepage = %q{https://github.com/ujihisa/impl}
24
+
25
+ s.extra_rdoc_files = %w< README.md >
26
+
27
+ s.add_development_dependency('rake')
28
+ s.add_development_dependency('rspec')
29
+ end
data/lib/impl.rb ADDED
@@ -0,0 +1,35 @@
1
+ module Impl
2
+ VERSION = '1.0'
3
+
4
+ def generate(ctags, dir)
5
+ memo = []
6
+ Dir.glob(dir + '/**/*.c') do |f|
7
+ File.read(f).each_line do |line|
8
+ if /^\s*rb_define_(singleton_)?(?:private_)?method\(rb_.(.*?),\s*"(.*?)",\s*(\w+),(?#\))/ =~ line
9
+ is_singleton, klass, method, func = [!!$1, $2, $3, $4]
10
+ fullmethod = [klass, is_singleton ? '.' : '#', method].join
11
+ ctags.scan(/^#{func}\t(.*)/) do |x|
12
+ memo << "#{fullmethod}\t#{x[0]}"
13
+ end
14
+ end
15
+ end
16
+ end
17
+ memo
18
+ end
19
+ module_function :generate
20
+
21
+ def help
22
+ <<-EOH
23
+ impl version #{VERSION}
24
+
25
+ USAGE
26
+ impl -h: shows this message
27
+ impl: shows additional information, assuming you already have |tags|
28
+ and Ruby codes in the current directory.
29
+ impl --suite {directory}:
30
+ generates new |tags| file in {directory} using files in
31
+ {directory}.
32
+ EOH
33
+ end
34
+ module_function :help
35
+ end
data/spec/impl_spec.rb ADDED
@@ -0,0 +1,23 @@
1
+ require_relative '../lib/impl'
2
+
3
+ describe Impl do
4
+ describe '.generate' do
5
+ context 'with a tag file and a repository dir' do
6
+ it 'returns strings of additional information like Random#rand, ' +
7
+ 'assuming the ruby source code repo is in ~/git/ruby193' do
8
+ dir = File.expand_path('~/git/ruby193')
9
+ ctags = File.read(dir + '/tags')
10
+ Impl.generate(ctags, dir).should be_include 'Random#rand random.c /^random_rand(int argc, VALUE *argv, VALUE obj)$/;" f file:'
11
+ end
12
+ end
13
+ end
14
+
15
+ describe '.help' do
16
+ it 'returns help message' do
17
+ Impl.help.should be_include 'USAGE'
18
+ end
19
+ end
20
+ end
21
+
22
+ #describe 'bin/impl' do
23
+ # rb_define_singleton_method(rb_vm_top_self(), "to_s", main_to_s, 0);
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: impl
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ version: "1.0"
9
+ platform: ruby
10
+ authors:
11
+ - ujihisa
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+
16
+ date: 2011-02-01 00:00:00 -08:00
17
+ default_executable:
18
+ dependencies:
19
+ - !ruby/object:Gem::Dependency
20
+ name: rake
21
+ prerelease: false
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :development
31
+ version_requirements: *id001
32
+ - !ruby/object:Gem::Dependency
33
+ name: rspec
34
+ prerelease: false
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ segments:
41
+ - 0
42
+ version: "0"
43
+ type: :development
44
+ version_requirements: *id002
45
+ description: generates additional information for Ruby C implementation's method definitions
46
+ email: ujihisa at gmail.com
47
+ executables:
48
+ - impl
49
+ extensions: []
50
+
51
+ extra_rdoc_files:
52
+ - README.md
53
+ files:
54
+ - lib/impl.rb
55
+ - bin/impl
56
+ - spec/impl_spec.rb
57
+ - impl.gemspec
58
+ - Rakefile
59
+ - README.md
60
+ has_rdoc: true
61
+ homepage: https://github.com/ujihisa/impl
62
+ licenses: []
63
+
64
+ post_install_message:
65
+ rdoc_options: []
66
+
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ segments:
83
+ - 0
84
+ version: "0"
85
+ requirements: []
86
+
87
+ rubyforge_project:
88
+ rubygems_version: 1.3.7
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: What's the implementation of a Ruby method?
92
+ test_files: []
93
+