impl 1.0 → 1.1
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.md +12 -1
- data/bin/impl +14 -8
- data/lib/impl.rb +53 -6
- metadata +3 -3
data/README.md
CHANGED
@@ -2,14 +2,25 @@
|
|
2
2
|
|
3
3
|
## Usage
|
4
4
|
|
5
|
+
### Impl normal usage
|
6
|
+
|
7
|
+
$ impl ~/git/ruby193 'Strimg#sum'
|
8
|
+
String#sum string.c /^rb_str_sum(int argc, VALUE *argv, VALUE str)$/;" f file:
|
9
|
+
|
10
|
+
This may take long time in the first time you called, but it won't take time in the next time.
|
11
|
+
|
12
|
+
## Impl plumbing usage (mostly for editor integration)
|
13
|
+
|
5
14
|
$ cd ~/git/ruby193
|
6
15
|
$ ctags -R
|
7
|
-
$ impl >> tags
|
16
|
+
$ impl --create . >> tags
|
8
17
|
|
9
18
|
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
19
|
|
11
20
|
Now you can go into the definition of a Ruby method by Ruby method format like `Random#rand`!
|
12
21
|
|
22
|
+
## Legacy usage (not available right now)
|
23
|
+
|
13
24
|
Higher level handy command is also available. The following command does almost equivalent to the three command previously I showed.
|
14
25
|
|
15
26
|
$ impl --suite ~/git/ruby193
|
data/bin/impl
CHANGED
@@ -1,16 +1,22 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
require 'pathname'
|
3
|
+
$: << 'lib'
|
2
4
|
require 'impl'
|
3
|
-
case ARGV
|
4
|
-
when '-h'
|
5
|
+
case ARGV[0]
|
6
|
+
when '-h', '--help', '-v', '--version'
|
5
7
|
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
|
-
|
8
|
+
#when '--suite'
|
9
|
+
# Dir.chdir(File.expand_path(ARGV.shift)) do
|
10
|
+
# additional = `#{__FILE__}`
|
11
|
+
# File.open('tags', 'a') {|io| io.puts additional }
|
12
|
+
# end
|
13
|
+
when '-c', '--create'
|
12
14
|
ctags = File.read('tags')
|
13
15
|
dir = File.expand_path '.'
|
14
16
|
puts Impl.generate(ctags, dir)
|
17
|
+
else
|
18
|
+
base = Pathname(ARGV.shift).expand_path
|
19
|
+
name = ARGV.shift
|
20
|
+
puts Impl.direct(base, name)
|
15
21
|
end
|
16
22
|
# vim: set ft=ruby :
|
data/lib/impl.rb
CHANGED
@@ -1,5 +1,16 @@
|
|
1
|
+
module Enumerable
|
2
|
+
def take_until
|
3
|
+
memo = []
|
4
|
+
each do |x|
|
5
|
+
memo << x
|
6
|
+
break if yield x
|
7
|
+
end
|
8
|
+
memo
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
1
12
|
module Impl
|
2
|
-
VERSION = '1.
|
13
|
+
VERSION = '1.1'
|
3
14
|
|
4
15
|
def generate(ctags, dir)
|
5
16
|
memo = []
|
@@ -23,13 +34,49 @@ module Impl
|
|
23
34
|
impl version #{VERSION}
|
24
35
|
|
25
36
|
USAGE
|
26
|
-
impl -h:
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
37
|
+
impl -h:
|
38
|
+
shows this message
|
39
|
+
impl {directory} {method name}
|
40
|
+
shows the file name and line number where {method name} like
|
41
|
+
'Strimg#sum' defined, assuming the Ruby source directory is
|
31
42
|
{directory}.
|
43
|
+
impl -d {directory} {method name}
|
44
|
+
impl --description {directory} {method name}
|
45
|
+
shows the description of {method name} like 'Strimg#sum'
|
46
|
+
directly, assuming the Ruby source directory is {directory}.
|
47
|
+
impl -c {directory}:
|
48
|
+
impl --create {directory}:
|
49
|
+
shows additional information, assuming you already have
|
50
|
+
|tags| and Ruby codes in the current directory.
|
32
51
|
EOH
|
33
52
|
end
|
34
53
|
module_function :help
|
54
|
+
|
55
|
+
def direct(base, name)
|
56
|
+
unless File.exists?(base + 'tags')
|
57
|
+
Dir.chdir base do
|
58
|
+
system 'ctags -R'
|
59
|
+
end
|
60
|
+
end
|
61
|
+
if /^String#sum/ !~ File.read(base + 'tags')
|
62
|
+
Dir.chdir base do
|
63
|
+
system 'impl -c .', out: ['tags', 'a']
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
x = File.read(base + 'tags').
|
68
|
+
each_line.
|
69
|
+
select {|l| /^#{name}\t/ =~ l }.
|
70
|
+
map {|l| l.split("\t") }.
|
71
|
+
first
|
72
|
+
r = Regexp.new(x[2][1..-4].gsub(/[\(\*\)]/) {|x| '\\' << x })
|
73
|
+
file = base + x[1]
|
74
|
+
content = File.read(file)
|
75
|
+
line, i = content.
|
76
|
+
each_line.
|
77
|
+
with_index.
|
78
|
+
detect {|line, _| r =~ line }
|
79
|
+
content.each_line.drop(i).take_until {|line| /^}/ =~ line }
|
80
|
+
end
|
81
|
+
module_function :direct
|
35
82
|
end
|
metadata
CHANGED
@@ -4,8 +4,8 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 1
|
7
|
-
-
|
8
|
-
version: "1.
|
7
|
+
- 1
|
8
|
+
version: "1.1"
|
9
9
|
platform: ruby
|
10
10
|
authors:
|
11
11
|
- ujihisa
|
@@ -13,7 +13,7 @@ autorequire:
|
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
15
|
|
16
|
-
date: 2011-
|
16
|
+
date: 2011-03-11 00:00:00 -08:00
|
17
17
|
default_executable:
|
18
18
|
dependencies:
|
19
19
|
- !ruby/object:Gem::Dependency
|