method_source 0.8.2 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +22 -4
- data/Gemfile +1 -1
- data/README.markdown +1 -1
- data/Rakefile +7 -5
- data/lib/method_source/code_helpers.rb +4 -4
- data/lib/method_source/source_location.rb +1 -1
- data/lib/method_source/version.rb +1 -1
- data/method_source.gemspec +22 -20
- data/{test/test_code_helpers.rb → spec/method_source/code_helpers_spec.rb} +6 -4
- data/{test/test.rb → spec/method_source_spec.rb} +38 -33
- data/{test/test_helper.rb → spec/spec_helper.rb} +3 -0
- metadata +23 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a028cf570a878212656d23cea883b8c951d1faba
|
4
|
+
data.tar.gz: 3470552886d0ea7f7ca782dc3d3dee9aed645776
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 587e875c403107b65ec2148565a1fef1c95e6a4426f691f03750382ba10c894f165818e30c52a69fe07ccdf0cec4290f966a382b107bed9e093efd8b7f13f288
|
7
|
+
data.tar.gz: 3ca93afc377f2f53da696f326251688c9cc45956027cdefca84df8ac37c90be26d31ba60405c8cd0d001e0841999286040a6941acecb679671fa850266a093a1
|
data/.travis.yml
CHANGED
@@ -1,12 +1,30 @@
|
|
1
|
+
# To use rbx environment.
|
2
|
+
dist: trusty
|
3
|
+
bundler_args: "--verbose"
|
4
|
+
before_install:
|
5
|
+
- gem update --system
|
6
|
+
- which bundle || gem install bundler
|
7
|
+
- gem update bundler
|
1
8
|
rvm:
|
2
9
|
- 1.8.7
|
3
|
-
- 1.9.2
|
4
10
|
- 1.9.3
|
5
11
|
- ree
|
6
|
-
- rbx-
|
7
|
-
- rbx-19mode
|
12
|
+
- rbx-3
|
8
13
|
- jruby
|
9
|
-
|
14
|
+
- jruby-head
|
15
|
+
- 2.0.0
|
16
|
+
- 2.1
|
17
|
+
- 2.2
|
18
|
+
- 2.3
|
19
|
+
- 2.4.2
|
20
|
+
- ruby-head
|
21
|
+
matrix:
|
22
|
+
allow_failures:
|
23
|
+
- rvm: ruby-head
|
24
|
+
- rvm: jruby
|
25
|
+
- rvm: jruby-head
|
26
|
+
- rvm: rbx-3
|
27
|
+
fast_finish: true
|
10
28
|
notifications:
|
11
29
|
irc: "irc.freenode.org#pry"
|
12
30
|
recipients:
|
data/Gemfile
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
gemspec
|
data/README.markdown
CHANGED
data/Rakefile
CHANGED
@@ -19,17 +19,19 @@ def apply_spec_defaults(s)
|
|
19
19
|
s.email = 'jrmair@gmail.com'
|
20
20
|
s.description = s.summary
|
21
21
|
s.require_path = 'lib'
|
22
|
+
s.license = 'MIT'
|
22
23
|
|
23
|
-
s.add_development_dependency("
|
24
|
+
s.add_development_dependency("rspec","~>3.6")
|
24
25
|
s.add_development_dependency("rake", "~>0.9")
|
25
26
|
s.homepage = "http://banisterfiend.wordpress.com"
|
26
27
|
s.has_rdoc = 'yard'
|
27
28
|
s.files = `git ls-files`.split("\n")
|
28
|
-
s.test_files = `git ls-files --
|
29
|
+
s.test_files = `git ls-files -- spec/*`.split("\n")
|
29
30
|
end
|
30
31
|
|
31
|
-
|
32
|
-
|
32
|
+
require "rspec/core/rake_task"
|
33
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
34
|
+
t.ruby_opts = %w[-w]
|
33
35
|
end
|
34
36
|
|
35
37
|
desc "reinstall gem"
|
@@ -39,7 +41,7 @@ task :reinstall => :gems do
|
|
39
41
|
end
|
40
42
|
|
41
43
|
desc "Set up and run tests"
|
42
|
-
task :default => [:
|
44
|
+
task :default => [:spec]
|
43
45
|
|
44
46
|
desc "Build the gemspec file"
|
45
47
|
task :gemspec => "ruby:gemspec"
|
@@ -6,14 +6,14 @@ module MethodSource
|
|
6
6
|
# This is useful to get module or method source code.
|
7
7
|
#
|
8
8
|
# @param [Array<String>, File, String] file The file to parse, either as a File or as
|
9
|
-
# @param [
|
9
|
+
# @param [Integer] line_number The line number at which to look.
|
10
10
|
# NOTE: The first line in a file is
|
11
11
|
# line 1!
|
12
12
|
# @param [Hash] options The optional configuration parameters.
|
13
13
|
# @option options [Boolean] :strict If set to true, then only completely
|
14
14
|
# valid expressions are returned. Otherwise heuristics are used to extract
|
15
15
|
# expressions that may have been valid inside an eval.
|
16
|
-
# @option options [
|
16
|
+
# @option options [Integer] :consume A number of lines to automatically
|
17
17
|
# consume (add to the expression buffer) without checking for validity.
|
18
18
|
# @return [String] The first complete expression
|
19
19
|
# @raise [SyntaxError] If the first complete expression can't be identified
|
@@ -46,7 +46,7 @@ module MethodSource
|
|
46
46
|
#
|
47
47
|
# @param [Array<String>, File, String] file The file to parse, either as a File or as
|
48
48
|
# a String or an Array of lines.
|
49
|
-
# @param [
|
49
|
+
# @param [Integer] line_number The line number at which to look.
|
50
50
|
# NOTE: The first line in a file is line 1!
|
51
51
|
# @return [String] The comment
|
52
52
|
def comment_describing(file, line_number)
|
@@ -84,7 +84,7 @@ module MethodSource
|
|
84
84
|
# Get the first expression from the input.
|
85
85
|
#
|
86
86
|
# @param [Array<String>] lines
|
87
|
-
# @param [
|
87
|
+
# @param [Integer] consume A number of lines to automatically
|
88
88
|
# consume (add to the expression buffer) without checking for validity.
|
89
89
|
# @yield a clean-up function to run before checking for complete_expression
|
90
90
|
# @return [String] a valid ruby expression
|
@@ -111,7 +111,7 @@ module MethodSource
|
|
111
111
|
case
|
112
112
|
when klass == Symbol
|
113
113
|
return :a.method(name).source_location
|
114
|
-
when klass ==
|
114
|
+
when klass == Integer
|
115
115
|
return 0.method(name).source_location
|
116
116
|
when klass == TrueClass
|
117
117
|
return true.method(name).source_location
|
data/method_source.gemspec
CHANGED
@@ -1,33 +1,35 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
# stub: method_source 0.9.2 ruby lib
|
2
3
|
|
3
4
|
Gem::Specification.new do |s|
|
4
|
-
s.name = "method_source"
|
5
|
-
s.version = "0.
|
5
|
+
s.name = "method_source".freeze
|
6
|
+
s.version = "0.9.2"
|
6
7
|
|
7
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
-
s.
|
9
|
-
s.
|
10
|
-
s.
|
11
|
-
s.
|
12
|
-
s.
|
13
|
-
s.
|
14
|
-
s.
|
15
|
-
s.
|
16
|
-
s.
|
17
|
-
s.
|
8
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
9
|
+
s.require_paths = ["lib".freeze]
|
10
|
+
s.authors = ["John Mair (banisterfiend)".freeze]
|
11
|
+
s.date = "2018-11-12"
|
12
|
+
s.description = "retrieve the sourcecode for a method".freeze
|
13
|
+
s.email = "jrmair@gmail.com".freeze
|
14
|
+
s.files = [".gemtest".freeze, ".travis.yml".freeze, ".yardopts".freeze, "Gemfile".freeze, "LICENSE".freeze, "README.markdown".freeze, "Rakefile".freeze, "lib/method_source.rb".freeze, "lib/method_source/code_helpers.rb".freeze, "lib/method_source/source_location.rb".freeze, "lib/method_source/version.rb".freeze, "method_source.gemspec".freeze, "spec/method_source/code_helpers_spec.rb".freeze, "spec/method_source_spec.rb".freeze, "spec/spec_helper.rb".freeze]
|
15
|
+
s.homepage = "http://banisterfiend.wordpress.com".freeze
|
16
|
+
s.licenses = ["MIT".freeze]
|
17
|
+
s.rubygems_version = "2.7.6".freeze
|
18
|
+
s.summary = "retrieve the sourcecode for a method".freeze
|
19
|
+
s.test_files = ["spec/method_source/code_helpers_spec.rb".freeze, "spec/method_source_spec.rb".freeze, "spec/spec_helper.rb".freeze]
|
18
20
|
|
19
21
|
if s.respond_to? :specification_version then
|
20
|
-
s.specification_version =
|
22
|
+
s.specification_version = 4
|
21
23
|
|
22
24
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
23
|
-
s.add_development_dependency(%q<
|
24
|
-
s.add_development_dependency(%q<rake
|
25
|
+
s.add_development_dependency(%q<rspec>.freeze, ["~> 3.6"])
|
26
|
+
s.add_development_dependency(%q<rake>.freeze, ["~> 0.9"])
|
25
27
|
else
|
26
|
-
s.add_dependency(%q<
|
27
|
-
s.add_dependency(%q<rake
|
28
|
+
s.add_dependency(%q<rspec>.freeze, ["~> 3.6"])
|
29
|
+
s.add_dependency(%q<rake>.freeze, ["~> 0.9"])
|
28
30
|
end
|
29
31
|
else
|
30
|
-
s.add_dependency(%q<
|
31
|
-
s.add_dependency(%q<rake
|
32
|
+
s.add_dependency(%q<rspec>.freeze, ["~> 3.6"])
|
33
|
+
s.add_dependency(%q<rake>.freeze, ["~> 0.9"])
|
32
34
|
end
|
33
35
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
1
3
|
describe MethodSource::CodeHelpers do
|
2
4
|
before do
|
3
5
|
@tester = Object.new.extend(MethodSource::CodeHelpers)
|
@@ -17,9 +19,9 @@ describe MethodSource::CodeHelpers do
|
|
17
19
|
].each do |lines|
|
18
20
|
it "should not raise an error on broken lines: #{lines.join("\\n")}" do
|
19
21
|
1.upto(lines.size - 1) do |i|
|
20
|
-
@tester.complete_expression?(lines[0...i].join("\n") + "\n").
|
22
|
+
expect(@tester.complete_expression?(lines[0...i].join("\n") + "\n")).to be_falsy
|
21
23
|
end
|
22
|
-
@tester.complete_expression?(lines.join("\n")).
|
24
|
+
expect(@tester.complete_expression?(lines.join("\n"))).to be_truthy
|
23
25
|
end
|
24
26
|
end
|
25
27
|
|
@@ -33,9 +35,9 @@ describe MethodSource::CodeHelpers do
|
|
33
35
|
["o = Object.new.tap{ def o.render;","'MEH'", "}"] # in this case the syntax error is "expecting keyword_end".
|
34
36
|
]).compact.each do |foo|
|
35
37
|
it "should raise an error on invalid syntax like #{foo.inspect}" do
|
36
|
-
|
38
|
+
expect {
|
37
39
|
@tester.complete_expression?(foo.join("\n"))
|
38
|
-
}.
|
40
|
+
}.to raise_error(SyntaxError)
|
39
41
|
end
|
40
42
|
end
|
41
43
|
end
|
@@ -1,26 +1,25 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'bacon'
|
5
|
-
require "#{direc}/../lib/method_source"
|
6
|
-
require "#{direc}/test_helper"
|
1
|
+
require 'spec_helper'
|
7
2
|
|
8
3
|
describe MethodSource do
|
9
4
|
|
10
5
|
describe "source_location (testing 1.8 implementation)" do
|
11
6
|
it 'should return correct source_location for a method' do
|
12
|
-
method(:hello).source_location.first.
|
7
|
+
expect(method(:hello).source_location.first).to match(/spec_helper/)
|
13
8
|
end
|
14
9
|
|
15
10
|
it 'should not raise for immediate instance methods' do
|
16
|
-
[Symbol,
|
17
|
-
|
11
|
+
[Symbol, Integer, TrueClass, FalseClass, NilClass].each do |immediate_class|
|
12
|
+
expect do
|
13
|
+
immediate_class.instance_method(:to_s).source_location
|
14
|
+
end.not_to raise_error
|
18
15
|
end
|
19
16
|
end
|
20
17
|
|
21
18
|
it 'should not raise for immediate methods' do
|
22
19
|
[:a, 1, true, false, nil].each do |immediate|
|
23
|
-
|
20
|
+
expect do
|
21
|
+
immediate.method(:to_s).source_location
|
22
|
+
end.not_to raise_error
|
24
23
|
end
|
25
24
|
end
|
26
25
|
end
|
@@ -40,49 +39,55 @@ describe MethodSource do
|
|
40
39
|
end
|
41
40
|
|
42
41
|
it 'should define methods on Method and UnboundMethod and Proc' do
|
43
|
-
Method.method_defined?(:source).
|
44
|
-
UnboundMethod.method_defined?(:source).
|
45
|
-
Proc.method_defined?(:source).
|
42
|
+
expect(Method.method_defined?(:source)).to be_truthy
|
43
|
+
expect(UnboundMethod.method_defined?(:source)).to be_truthy
|
44
|
+
expect(Proc.method_defined?(:source)).to be_truthy
|
46
45
|
end
|
47
46
|
|
48
47
|
describe "Methods" do
|
49
48
|
it 'should return source for method' do
|
50
|
-
method(:hello).source.
|
49
|
+
expect(method(:hello).source).to eq(@hello_source)
|
51
50
|
end
|
52
51
|
|
53
52
|
it 'should return source for a method defined in a module' do
|
54
|
-
M.instance_method(:hello).source.
|
53
|
+
expect(M.instance_method(:hello).source).to eq(@hello_module_source)
|
55
54
|
end
|
56
55
|
|
57
56
|
it 'should return source for a singleton method as an instance method' do
|
58
|
-
class << $o
|
57
|
+
expect(class << $o
|
58
|
+
self
|
59
|
+
end.instance_method(:hello).source).to eq(@hello_singleton_source)
|
59
60
|
end
|
60
61
|
|
61
62
|
it 'should return source for a singleton method' do
|
62
|
-
$o.method(:hello).source.
|
63
|
+
expect($o.method(:hello).source).to eq(@hello_singleton_source)
|
63
64
|
end
|
64
65
|
|
65
66
|
it 'should return a comment for method' do
|
66
|
-
method(:hello).comment.
|
67
|
+
expect(method(:hello).comment).to eq(@hello_comment)
|
67
68
|
end
|
68
69
|
|
69
70
|
# These tests fail because of http://jira.codehaus.org/browse/JRUBY-4576
|
70
71
|
unless defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
|
71
72
|
it 'should return source for an *_evaled method' do
|
72
|
-
M.method(:hello_name).source.
|
73
|
-
M.method(:name_two).source.
|
74
|
-
M.instance_method(:hello_name).source.
|
75
|
-
M.instance_method(:hi_name).source.
|
73
|
+
expect(M.method(:hello_name).source).to eq(@hello_instance_evaled_source)
|
74
|
+
expect(M.method(:name_two).source).to eq(@hello_instance_evaled_source_2)
|
75
|
+
expect(M.instance_method(:hello_name).source).to eq(@hello_class_evaled_source)
|
76
|
+
expect(M.instance_method(:hi_name).source).to eq(@hi_module_evaled_source)
|
76
77
|
end
|
77
78
|
end
|
78
79
|
|
79
80
|
it "should raise error for evaled methods that do not pass __FILE__ and __LINE__ + 1 as its arguments" do
|
80
|
-
|
81
|
+
expect do
|
82
|
+
M.instance_method(:name_three).source
|
83
|
+
end.to raise_error(MethodSource::SourceNotFoundError)
|
81
84
|
end
|
82
85
|
|
83
86
|
if !is_rbx?
|
84
87
|
it 'should raise for C methods' do
|
85
|
-
|
88
|
+
expect do
|
89
|
+
method(:puts).source
|
90
|
+
end.to raise_error(MethodSource::SourceNotFoundError)
|
86
91
|
end
|
87
92
|
end
|
88
93
|
end
|
@@ -90,19 +95,19 @@ describe MethodSource do
|
|
90
95
|
# if RUBY_VERSION =~ /1.9/ || is_rbx?
|
91
96
|
describe "Lambdas and Procs" do
|
92
97
|
it 'should return source for proc' do
|
93
|
-
MyProc.source.
|
98
|
+
expect(MyProc.source).to eq(@proc_source)
|
94
99
|
end
|
95
100
|
|
96
101
|
it 'should return an empty string if there is no comment' do
|
97
|
-
MyProc.comment.
|
102
|
+
expect(MyProc.comment).to eq('')
|
98
103
|
end
|
99
104
|
|
100
105
|
it 'should return source for lambda' do
|
101
|
-
MyLambda.source.
|
106
|
+
expect(MyLambda.source).to eq(@lambda_source)
|
102
107
|
end
|
103
108
|
|
104
109
|
it 'should return comment for lambda' do
|
105
|
-
MyLambda.comment.
|
110
|
+
expect(MyLambda.comment).to eq(@lambda_comment)
|
106
111
|
end
|
107
112
|
end
|
108
113
|
# end
|
@@ -116,23 +121,23 @@ describe MethodSource do
|
|
116
121
|
end
|
117
122
|
|
118
123
|
it "should correctly extract multi-line comments" do
|
119
|
-
method(:comment_test1).comment.
|
124
|
+
expect(method(:comment_test1).comment).to eq(@comment1)
|
120
125
|
end
|
121
126
|
|
122
127
|
it "should correctly strip leading whitespace before comments" do
|
123
|
-
method(:comment_test2).comment.
|
128
|
+
expect(method(:comment_test2).comment).to eq(@comment2)
|
124
129
|
end
|
125
130
|
|
126
131
|
it "should keep empty comment lines" do
|
127
|
-
method(:comment_test3).comment.
|
132
|
+
expect(method(:comment_test3).comment).to eq(@comment3)
|
128
133
|
end
|
129
134
|
|
130
135
|
it "should ignore blank lines between comments" do
|
131
|
-
method(:comment_test4).comment.
|
136
|
+
expect(method(:comment_test4).comment).to eq(@comment4)
|
132
137
|
end
|
133
138
|
|
134
139
|
it "should align all comments to same indent level" do
|
135
|
-
method(:comment_test5).comment.
|
140
|
+
expect(method(:comment_test5).comment).to eq(@comment5)
|
136
141
|
end
|
137
142
|
end
|
138
143
|
end
|
metadata
CHANGED
@@ -1,41 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: method_source
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Mair (banisterfiend)
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: rspec
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '3.6'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: '3.6'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0.9'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0.9'
|
41
41
|
description: retrieve the sourcecode for a method
|
@@ -44,9 +44,9 @@ executables: []
|
|
44
44
|
extensions: []
|
45
45
|
extra_rdoc_files: []
|
46
46
|
files:
|
47
|
-
- .gemtest
|
48
|
-
- .travis.yml
|
49
|
-
- .yardopts
|
47
|
+
- ".gemtest"
|
48
|
+
- ".travis.yml"
|
49
|
+
- ".yardopts"
|
50
50
|
- Gemfile
|
51
51
|
- LICENSE
|
52
52
|
- README.markdown
|
@@ -56,11 +56,12 @@ files:
|
|
56
56
|
- lib/method_source/source_location.rb
|
57
57
|
- lib/method_source/version.rb
|
58
58
|
- method_source.gemspec
|
59
|
-
-
|
60
|
-
-
|
61
|
-
-
|
59
|
+
- spec/method_source/code_helpers_spec.rb
|
60
|
+
- spec/method_source_spec.rb
|
61
|
+
- spec/spec_helper.rb
|
62
62
|
homepage: http://banisterfiend.wordpress.com
|
63
|
-
licenses:
|
63
|
+
licenses:
|
64
|
+
- MIT
|
64
65
|
metadata: {}
|
65
66
|
post_install_message:
|
66
67
|
rdoc_options: []
|
@@ -68,21 +69,21 @@ require_paths:
|
|
68
69
|
- lib
|
69
70
|
required_ruby_version: !ruby/object:Gem::Requirement
|
70
71
|
requirements:
|
71
|
-
- -
|
72
|
+
- - ">="
|
72
73
|
- !ruby/object:Gem::Version
|
73
74
|
version: '0'
|
74
75
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
76
|
requirements:
|
76
|
-
- -
|
77
|
+
- - ">="
|
77
78
|
- !ruby/object:Gem::Version
|
78
79
|
version: '0'
|
79
80
|
requirements: []
|
80
81
|
rubyforge_project:
|
81
|
-
rubygems_version: 2.
|
82
|
+
rubygems_version: 2.6.13
|
82
83
|
signing_key:
|
83
84
|
specification_version: 4
|
84
85
|
summary: retrieve the sourcecode for a method
|
85
86
|
test_files:
|
86
|
-
-
|
87
|
-
-
|
88
|
-
-
|
87
|
+
- spec/method_source/code_helpers_spec.rb
|
88
|
+
- spec/method_source_spec.rb
|
89
|
+
- spec/spec_helper.rb
|