ri_for 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -1,6 +1,10 @@
1
- A "run time RI for ruby methods", this gem allows you to query for information about objects' methods at runtime--for example within irb or ruby-debug. It reveals everything known about the method. This includes source, ri, arity, rdoc comments (1.9 only), etc.
1
+ TODO note my_methods
2
2
 
3
- For me it has proved quite useful, and I wouldn't do a ruby-debug session without it--you might really like it.
3
+ ri_for gem:
4
+
5
+ A "run time RI for existing methods", this gem allows you to grab a method's docu at runtime--for example within a irb. It display the method's source code/comments, ri (if available), arity, parameters, etc.
6
+
7
+ It has proved quite useful, and I wouldn't do a ruby-debug session without it--you might really like it.
4
8
 
5
9
  Examples:
6
10
 
@@ -8,17 +12,19 @@ Examples:
8
12
  def go(a); end;
9
13
  end
10
14
 
11
- >> A.desc_method :go
12
- #<UnboundMethod: A#go> arity: 1
13
- ri for A#go
14
- Nothing known about A
15
- (end ri)
15
+ >> A.new.ri_for :go
16
+ sig: A#go arity 1
16
17
  def go(a)
17
18
  # do nothing
18
19
  end
19
20
  Parameters: go(a)
21
+ Searching ri for sig: A#go arity 1 ...
22
+ (end ri)
23
+ => "Parameters: go(a)"
24
+
25
+ (or you could do A.ri_for :go -- it falls back to show the instance method if it can't find the class method)
20
26
 
21
- >> File.desc_method :delete
27
+ >> File.ri_for :delete
22
28
  ri for File.delete
23
29
  ----------------------------------------------------------- File::delete
24
30
  File.delete(file_name, ...) => integer
data/Rakefile CHANGED
@@ -4,13 +4,13 @@ Jeweler::Tasks.new do |s|
4
4
  s.authors = ["Roger Pack"]
5
5
  s.description = s.summary = %q{ruby method describer to make it possible to inspect methods [rdoc, signature, etc.] at runtime, for example while debugging.}
6
6
  s.email = ["rogerdpack@gmail.comm"]
7
-
8
- s.homepage = %q{http://github.com/rogerdpack/method_describer}
9
- s.add_dependency(%q<rdoc>, [">= 2.3"]) # for sane ri lookup times
7
+ s.homepage = %q{http://github.com/rogerdpack/ri_for}
8
+ s.add_dependency(%q<rdoc>, [">= 2.3"]) # for quick ri lookup times
10
9
  s.add_dependency(%q<rdp-arguments>, [">= 0.6.4"])
11
- s.add_dependency(%q<sane>, ['>= 0.20.1'])
12
10
  s.add_dependency(%q<ParseTree>) # these next two for 1.8 only...
13
11
  s.add_dependency(%q<ruby2ruby>)
12
+ s.add_development_dependency(%q<sane>, ['>= 0.20.1'])
14
13
  s.add_development_dependency("rubydoctest")
14
+ s.add_development_dependency("ffi")
15
15
  end
16
16
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.0
1
+ 0.5.1
@@ -1,4 +1,3 @@
1
- require 'sane'
2
- for file in Dir[__dir__ + '/ri_for/*.rb'] do
1
+ for file in Dir[File.dirname(__FILE__) + '/ri_for/*.rb'] do
3
2
  require file
4
3
  end
@@ -1,5 +1,3 @@
1
- require_relative 'method_ri'
2
-
3
1
  class Class
4
2
  # just runs ri against the class, outputs a big
5
3
  def desc_class options = {}
@@ -1,13 +1,16 @@
1
- require 'sane'
2
-
3
1
  if RUBY_VERSION < '1.9'
4
- require 'rubygems'
5
2
  require 'ruby2ruby'
6
3
  require 'parse_tree'
7
4
  gem 'rdp-arguments' # TODO why is this necessary?
8
5
  require 'arguments' # rogerdpack-arguments
9
6
  end
10
7
 
8
+ class Object
9
+ def singleton_class
10
+ class << self; self; end
11
+ end
12
+ end
13
+
11
14
  module SourceLocationDesc
12
15
 
13
16
  # add a Method#desc which spits out all it knows about that method
@@ -53,7 +56,8 @@ module SourceLocationDesc
53
56
  string =~ /Method: .*([#\.])(.*)>/ # include the # or .
54
57
  joiner = $1
55
58
  method_name = $2
56
- sig = "sig: #{class_name}#{joiner}#{method_name} arity #{arity}"
59
+ full_name = class_name + joiner + method_name
60
+ sig = "sig: #{full_name} arity #{arity}"
57
61
  doc << sig
58
62
  param_string = sig
59
63
 
@@ -67,7 +71,7 @@ module SourceLocationDesc
67
71
  if joiner == '#'
68
72
  raw_code = ParseTree.new.parse_tree_for_method(klass, method_name)
69
73
  else
70
- raw_code = ParseTree.new.parse_tree_for_method(klass.singleton_class, method_name)
74
+ raw_code = ParseTree.new.parse_tree_for_method(klass.singleton_class, method_name) # singleton_class
71
75
  end
72
76
  doc << Ruby2Ruby.new.process(ParseTree.new.process(raw_code))
73
77
 
@@ -84,7 +88,6 @@ module SourceLocationDesc
84
88
  rescue Exception => e
85
89
  doc << "appears to be a c method"
86
90
  puts "fail to parse tree: #{class_name} #{e} #{e.backtrace}" if $DEBUG
87
- doc << "appears to be a c method"
88
91
  end
89
92
  else
90
93
  # 1.9.x
@@ -133,7 +136,7 @@ module SourceLocationDesc
133
136
 
134
137
  # show default RI for it
135
138
  begin
136
- pps 'Searching ri for', sig, '...'
139
+ puts 'Searching ri for', sig, '...'
137
140
  RDoc::RI::Driver.run [full_name, '--no-pager']
138
141
  rescue *[StandardError, SystemExit]
139
142
  # not found
@@ -167,7 +170,11 @@ class Object
167
170
  begin
168
171
  instance_method(name).ri(options)
169
172
  rescue NameError => e #allow for Class.instance_method_name, Module.instance_method_name
170
- method(name).ri(options)
173
+ begin
174
+ method(name).ri(options)
175
+ rescue NameError
176
+ raise NameError.new("appears that this object #{self} does not have this method #{name}")
177
+ end
171
178
  end
172
179
  else
173
180
  method(name).desc(options)
@@ -0,0 +1,5 @@
1
+ require 'rubydoctest.method.rb'
2
+ require '../lib/ri_for'
3
+ #require '_dbg'
4
+ output = A.ri_for(:go22, :want_the_description_returned => true).join(' ')
5
+ puts output.inspect
@@ -1,5 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'ffi'
3
+ require 'os'
3
4
 
4
5
  class A
5
6
  # a suh-weet rdoc
@@ -27,6 +28,7 @@ doctest_require: '../lib/ri_for'
27
28
  => true
28
29
 
29
30
  >> output = A.ri_for(:go22, :want_the_description_returned => true).join(' ')
31
+ >> puts output
30
32
  >> output.include? 'b = 3'
31
33
  => true
32
34
 
@@ -105,6 +107,18 @@ wurx with class methods
105
107
  >> A.ri_for(:go)
106
108
  >> A.ri_for(:go2)
107
109
 
108
- >> File.ri_for :delete
110
+ # shouldn't duplicate "appear to be"
111
+ doctest: fail
112
+ >> a = File.ri_for(:delete, :want_the_description_returned => true).join(' ').scan(/appears to be/).length
113
+ => 1
109
114
 
110
- =end
115
+ # should throw our own style exceptions
116
+ >> e = nil;begin; File.ri_for(:unknown); rescue NameError => e; end
117
+ >> e.to_s.include? "appears that"
118
+ => true
119
+
120
+ >> a = `#{OS.ruby_bin} test_ri.rb`
121
+ >> a.include? "File.delete(file_name"
122
+ => true
123
+
124
+ =end
@@ -0,0 +1,2 @@
1
+ require '../lib/ri_for'
2
+ File.ri_for :delete
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ri_for
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roger Pack
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-13 00:00:00 -07:00
12
+ date: 2010-01-25 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -33,17 +33,17 @@ dependencies:
33
33
  version: 0.6.4
34
34
  version:
35
35
  - !ruby/object:Gem::Dependency
36
- name: sane
36
+ name: ParseTree
37
37
  type: :runtime
38
38
  version_requirement:
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
41
  - - ">="
42
42
  - !ruby/object:Gem::Version
43
- version: 0.20.1
43
+ version: "0"
44
44
  version:
45
45
  - !ruby/object:Gem::Dependency
46
- name: ParseTree
46
+ name: ruby2ruby
47
47
  type: :runtime
48
48
  version_requirement:
49
49
  version_requirements: !ruby/object:Gem::Requirement
@@ -53,14 +53,14 @@ dependencies:
53
53
  version: "0"
54
54
  version:
55
55
  - !ruby/object:Gem::Dependency
56
- name: ruby2ruby
57
- type: :runtime
56
+ name: sane
57
+ type: :development
58
58
  version_requirement:
59
59
  version_requirements: !ruby/object:Gem::Requirement
60
60
  requirements:
61
61
  - - ">="
62
62
  - !ruby/object:Gem::Version
63
- version: "0"
63
+ version: 0.20.1
64
64
  version:
65
65
  - !ruby/object:Gem::Dependency
66
66
  name: rubydoctest
@@ -72,6 +72,16 @@ dependencies:
72
72
  - !ruby/object:Gem::Version
73
73
  version: "0"
74
74
  version:
75
+ - !ruby/object:Gem::Dependency
76
+ name: ffi
77
+ type: :development
78
+ version_requirement:
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: "0"
84
+ version:
75
85
  description: ruby method describer to make it possible to inspect methods [rdoc, signature, etc.] at runtime, for example while debugging.
76
86
  email:
77
87
  - rogerdpack@gmail.comm
@@ -90,12 +100,13 @@ files:
90
100
  - lib/ri_for/class_desc.rb
91
101
  - lib/ri_for/kernel_new_methods_list.rb
92
102
  - lib/ri_for/method_ri.rb
93
- - test/test_big_name.rb
94
- - test/test_method.rb
103
+ - test/rubydoctest.big.rb
104
+ - test/rubydoctest.method.rb
105
+ - test/test_ri.rb
95
106
  - todo
96
107
  - TODO
97
108
  has_rdoc: true
98
- homepage: http://github.com/rogerdpack/method_describer
109
+ homepage: http://github.com/rogerdpack/ri_for
99
110
  licenses: []
100
111
 
101
112
  post_install_message:
@@ -123,5 +134,7 @@ signing_key:
123
134
  specification_version: 3
124
135
  summary: ruby method describer to make it possible to inspect methods [rdoc, signature, etc.] at runtime, for example while debugging.
125
136
  test_files:
126
- - test/test_big_name.rb
127
- - test/test_method.rb
137
+ - test/bad.rb
138
+ - test/rubydoctest.big.rb
139
+ - test/rubydoctest.method.rb
140
+ - test/test_ri.rb