method_source 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -3
- data/Gemfile +4 -0
- data/README.markdown +8 -0
- data/lib/method_source/code_helpers.rb +3 -3
- data/lib/method_source/version.rb +1 -1
- data/lib/method_source.rb +36 -0
- data/method_source.gemspec +4 -18
- data/spec/method_source_spec.rb +14 -0
- data/spec/spec_helper.rb +6 -0
- metadata +9 -37
- data/.circleci/config.yml +0 -139
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e936459f65ba807442d464e51a8d70421850fab753f17df974ffc28e9d414983
|
4
|
+
data.tar.gz: 977611dfab90d749a6001794295428fe05becc43d878db7abdc6014ae589c17a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9021fc9ca214aebf3337563b544137c8a80fb30872222f8334f104a3b6a9ef5ce37f7aed8caabb1061f63066afc16fc6c9a87f384f2279dec7fc9b26d312595f
|
7
|
+
data.tar.gz: 965fc6d9f5df92dee0d8d300e5e7b4942395c9e17d120b727a82ee2082d00c7ca4edbed9689b332eed0007e0ac128322bda317464800c5b1f089961bacdeaa43
|
data/CHANGELOG.md
CHANGED
@@ -1,10 +1,15 @@
|
|
1
|
-
method_source changelog
|
2
|
-
=======================
|
1
|
+
# method_source changelog
|
3
2
|
|
4
3
|
### master
|
5
4
|
|
5
|
+
### [v1.1.0][v1.1.0] (April 15, 2024)
|
6
|
+
|
7
|
+
- Added `MethodSource.clear_cache`
|
8
|
+
- Added support for `RUBYOPT="--enable-frozen-string-literal"`
|
9
|
+
|
6
10
|
### [v1.0.0][v1.0.0] (March 19, 2020)
|
7
11
|
|
8
|
-
|
12
|
+
- Added Ruby 2.7 support
|
9
13
|
|
10
14
|
[v1.0.0]: https://github.com/banister/method_source/releases/tag/v1.0.0
|
15
|
+
[v1.1.0]: https://github.com/banister/method_source/releases/tag/v1.1.0
|
data/Gemfile
CHANGED
data/README.markdown
CHANGED
@@ -50,6 +50,14 @@ Example: display method comments
|
|
50
50
|
# Merges the elements of the given enumerable object to the set and
|
51
51
|
# returns self.
|
52
52
|
|
53
|
+
Example: display module/class comments
|
54
|
+
--------------------------------------
|
55
|
+
|
56
|
+
MethodSource::MethodExtensions.method(:included).module_comment
|
57
|
+
# =>
|
58
|
+
# This module is to be included by `Method` and `UnboundMethod` and
|
59
|
+
# provides the `#source` functionality
|
60
|
+
|
53
61
|
Limitations:
|
54
62
|
------------
|
55
63
|
|
@@ -90,7 +90,7 @@ module MethodSource
|
|
90
90
|
# @return [String] a valid ruby expression
|
91
91
|
# @raise [SyntaxError]
|
92
92
|
def extract_first_expression(lines, consume=0, &block)
|
93
|
-
code = consume.zero? ? "" : lines.slice!(0..(consume - 1)).join
|
93
|
+
code = consume.zero? ? +"" : lines.slice!(0..(consume - 1)).join
|
94
94
|
|
95
95
|
lines.each do |v|
|
96
96
|
code << v
|
@@ -104,7 +104,7 @@ module MethodSource
|
|
104
104
|
# @param [Array<String>] lines
|
105
105
|
# @return [String]
|
106
106
|
def extract_last_comment(lines)
|
107
|
-
buffer = ""
|
107
|
+
buffer = +""
|
108
108
|
|
109
109
|
lines.each do |line|
|
110
110
|
# Add any line that is a valid ruby comment,
|
@@ -112,7 +112,7 @@ module MethodSource
|
|
112
112
|
if (line =~ /^\s*#/) || (line =~ /^\s*$/)
|
113
113
|
buffer << line.lstrip
|
114
114
|
else
|
115
|
-
buffer.
|
115
|
+
buffer.clear
|
116
116
|
end
|
117
117
|
end
|
118
118
|
|
data/lib/method_source.rb
CHANGED
@@ -55,6 +55,11 @@ module MethodSource
|
|
55
55
|
raise SourceNotFoundError, "Could not load source for #{name}: #{e.message}"
|
56
56
|
end
|
57
57
|
|
58
|
+
# Clear cache.
|
59
|
+
def self.clear_cache
|
60
|
+
@lines_for_file = {}
|
61
|
+
end
|
62
|
+
|
58
63
|
# @deprecated — use MethodSource::CodeHelpers#complete_expression?
|
59
64
|
def self.valid_expression?(str)
|
60
65
|
complete_expression?(str)
|
@@ -121,6 +126,37 @@ module MethodSource
|
|
121
126
|
def comment
|
122
127
|
MethodSource.comment_helper(source_location, defined?(name) ? name : inspect)
|
123
128
|
end
|
129
|
+
|
130
|
+
# Return the comments associated with the method class/module.
|
131
|
+
# @return [String] The method's comments as a string
|
132
|
+
# @raise SourceNotFoundException
|
133
|
+
#
|
134
|
+
# @example
|
135
|
+
# MethodSource::MethodExtensions.method(:included).module_comment
|
136
|
+
# =>
|
137
|
+
# # This module is to be included by `Method` and `UnboundMethod` and
|
138
|
+
# # provides the `#source` functionality
|
139
|
+
def class_comment
|
140
|
+
if self.respond_to?(:receiver)
|
141
|
+
class_inst_or_module = self.receiver
|
142
|
+
elsif self.respond_to?(:owner)
|
143
|
+
class_inst_or_module = self.owner
|
144
|
+
else
|
145
|
+
return comment
|
146
|
+
end
|
147
|
+
|
148
|
+
if class_inst_or_module.respond_to?(:name)
|
149
|
+
const_name = class_inst_or_module.name
|
150
|
+
else
|
151
|
+
const_name = class_inst_or_module.class.name
|
152
|
+
class_inst_or_module = class_inst_or_module.class
|
153
|
+
end
|
154
|
+
|
155
|
+
location = class_inst_or_module.const_source_location(const_name)
|
156
|
+
|
157
|
+
MethodSource.comment_helper(location, defined?(name) ? name : inspect)
|
158
|
+
end
|
159
|
+
alias module_comment class_comment
|
124
160
|
end
|
125
161
|
end
|
126
162
|
|
data/method_source.gemspec
CHANGED
@@ -2,32 +2,18 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "method_source".freeze
|
5
|
-
s.version = "1.
|
5
|
+
s.version = "1.1.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
8
8
|
s.require_paths = ["lib".freeze]
|
9
9
|
s.authors = ["John Mair (banisterfiend)".freeze]
|
10
|
-
s.date = "
|
10
|
+
s.date = "2024-04-15"
|
11
11
|
s.description = "retrieve the sourcecode for a method".freeze
|
12
12
|
s.email = "jrmair@gmail.com".freeze
|
13
|
-
s.files = ["CHANGELOG.md".freeze, ".gemtest".freeze, ".
|
13
|
+
s.files = ["CHANGELOG.md".freeze, ".gemtest".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]
|
14
14
|
s.homepage = "http://banisterfiend.wordpress.com".freeze
|
15
|
+
s.metadata["changelog_uri"] = "https://github.com/banister/method_source/blob/master/CHANGELOG.md".freeze
|
15
16
|
s.licenses = ["MIT".freeze]
|
16
17
|
s.summary = "retrieve the sourcecode for a method".freeze
|
17
18
|
s.test_files = ["spec/method_source/code_helpers_spec.rb".freeze, "spec/method_source_spec.rb".freeze, "spec/spec_helper.rb".freeze]
|
18
|
-
|
19
|
-
if s.respond_to? :specification_version then
|
20
|
-
s.specification_version = 4
|
21
|
-
|
22
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
23
|
-
s.add_development_dependency(%q<rspec>.freeze, ["~> 3.6"])
|
24
|
-
s.add_development_dependency(%q<rake>.freeze, ["~> 0.9"])
|
25
|
-
else
|
26
|
-
s.add_dependency(%q<rspec>.freeze, ["~> 3.6"])
|
27
|
-
s.add_dependency(%q<rake>.freeze, ["~> 0.9"])
|
28
|
-
end
|
29
|
-
else
|
30
|
-
s.add_dependency(%q<rspec>.freeze, ["~> 3.6"])
|
31
|
-
s.add_dependency(%q<rake>.freeze, ["~> 0.9"])
|
32
|
-
end
|
33
19
|
end
|
data/spec/method_source_spec.rb
CHANGED
@@ -30,6 +30,8 @@ describe MethodSource do
|
|
30
30
|
@hello_source = "def hello; :hello; end\n"
|
31
31
|
@hello_comment = "# A comment for hello\n# It spans two lines and is indented by 2 spaces\n"
|
32
32
|
@lambda_comment = "# This is a comment for MyLambda\n"
|
33
|
+
@module_comment = "# This is a comment for module\n"
|
34
|
+
@class_comment = "# This is a comment for class\n"
|
33
35
|
@lambda_source = "MyLambda = lambda { :lambda }\n"
|
34
36
|
@proc_source = "MyProc = Proc.new { :proc }\n"
|
35
37
|
@hello_instance_evaled_source = " def hello_\#{name}(*args)\n send_mesg(:\#{name}, *args)\n end\n"
|
@@ -109,6 +111,18 @@ describe MethodSource do
|
|
109
111
|
it 'should return comment for lambda' do
|
110
112
|
expect(MyLambda.comment).to eq(@lambda_comment)
|
111
113
|
end
|
114
|
+
|
115
|
+
it 'should return comment for module' do
|
116
|
+
expect(M.instance_method(:hello).module_comment).to eq(@module_comment)
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'should return comment for class' do
|
120
|
+
expect(C.method(:hello).class_comment).to eq(@class_comment)
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'should return comment for class instance' do
|
124
|
+
expect(C.new.method(:hello).class_comment).to eq(@class_comment)
|
125
|
+
end
|
112
126
|
end
|
113
127
|
# end
|
114
128
|
describe "Comment tests" do
|
data/spec/spec_helper.rb
CHANGED
@@ -10,10 +10,16 @@ def jruby?
|
|
10
10
|
end
|
11
11
|
|
12
12
|
|
13
|
+
# This is a comment for module
|
13
14
|
module M
|
14
15
|
def hello; :hello_module; end
|
15
16
|
end
|
16
17
|
|
18
|
+
# This is a comment for class
|
19
|
+
class C
|
20
|
+
include M
|
21
|
+
end
|
22
|
+
|
17
23
|
$o = Object.new
|
18
24
|
def $o.hello; :hello_singleton; end
|
19
25
|
|
metadata
CHANGED
@@ -1,50 +1,21 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: method_source
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Mair (banisterfiend)
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: rspec
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '3.6'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '3.6'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rake
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0.9'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0.9'
|
11
|
+
date: 2024-04-15 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
41
13
|
description: retrieve the sourcecode for a method
|
42
14
|
email: jrmair@gmail.com
|
43
15
|
executables: []
|
44
16
|
extensions: []
|
45
17
|
extra_rdoc_files: []
|
46
18
|
files:
|
47
|
-
- ".circleci/config.yml"
|
48
19
|
- ".gemtest"
|
49
20
|
- ".yardopts"
|
50
21
|
- CHANGELOG.md
|
@@ -63,8 +34,9 @@ files:
|
|
63
34
|
homepage: http://banisterfiend.wordpress.com
|
64
35
|
licenses:
|
65
36
|
- MIT
|
66
|
-
metadata:
|
67
|
-
|
37
|
+
metadata:
|
38
|
+
changelog_uri: https://github.com/banister/method_source/blob/master/CHANGELOG.md
|
39
|
+
post_install_message:
|
68
40
|
rdoc_options: []
|
69
41
|
require_paths:
|
70
42
|
- lib
|
@@ -79,8 +51,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
51
|
- !ruby/object:Gem::Version
|
80
52
|
version: '0'
|
81
53
|
requirements: []
|
82
|
-
rubygems_version: 3.
|
83
|
-
signing_key:
|
54
|
+
rubygems_version: 3.5.3
|
55
|
+
signing_key:
|
84
56
|
specification_version: 4
|
85
57
|
summary: retrieve the sourcecode for a method
|
86
58
|
test_files:
|
data/.circleci/config.yml
DELETED
@@ -1,139 +0,0 @@
|
|
1
|
-
version: 2
|
2
|
-
references:
|
3
|
-
repo_restore_cache: &repo_restore_cache
|
4
|
-
restore_cache:
|
5
|
-
keys:
|
6
|
-
- repo-{{ .Environment.CIRCLE_SHA1 }}
|
7
|
-
|
8
|
-
repo_save_cache: &repo_save_cache
|
9
|
-
save_cache:
|
10
|
-
key: repo-{{ .Environment.CIRCLE_SHA1 }}-{{ epoch }}
|
11
|
-
paths:
|
12
|
-
- ~/method_source
|
13
|
-
|
14
|
-
bundle_install: &bundle_install
|
15
|
-
run:
|
16
|
-
name: Install Bundler dependencies
|
17
|
-
command: bundle install --path ~/method_source/vendor/bundle --jobs 15
|
18
|
-
|
19
|
-
unit: &unit
|
20
|
-
run:
|
21
|
-
name: Run unit tests
|
22
|
-
command: bundle exec rake
|
23
|
-
|
24
|
-
jobs:
|
25
|
-
"ruby-1.9":
|
26
|
-
docker:
|
27
|
-
- image: kyrylo/ruby-1.9.3p551
|
28
|
-
working_directory: /home/circleci/method_source
|
29
|
-
steps:
|
30
|
-
- checkout
|
31
|
-
- <<: *repo_restore_cache
|
32
|
-
- <<: *bundle_install
|
33
|
-
- <<: *unit
|
34
|
-
"ruby-2.0":
|
35
|
-
docker:
|
36
|
-
- image: kyrylo/ruby-2.0.0p648
|
37
|
-
working_directory: /home/circleci/method_source
|
38
|
-
steps:
|
39
|
-
- checkout
|
40
|
-
- <<: *repo_restore_cache
|
41
|
-
- <<: *bundle_install
|
42
|
-
- <<: *unit
|
43
|
-
"ruby-2.1":
|
44
|
-
docker:
|
45
|
-
- image: circleci/ruby:2.1
|
46
|
-
working_directory: ~/method_source
|
47
|
-
steps:
|
48
|
-
- checkout
|
49
|
-
- <<: *repo_restore_cache
|
50
|
-
- <<: *bundle_install
|
51
|
-
- <<: *unit
|
52
|
-
"ruby-2.2":
|
53
|
-
docker:
|
54
|
-
- image: circleci/ruby:2.2
|
55
|
-
working_directory: ~/method_source
|
56
|
-
steps:
|
57
|
-
- checkout
|
58
|
-
- <<: *repo_restore_cache
|
59
|
-
- <<: *bundle_install
|
60
|
-
- <<: *unit
|
61
|
-
"ruby-2.3":
|
62
|
-
docker:
|
63
|
-
- image: circleci/ruby:2.3
|
64
|
-
working_directory: ~/method_source
|
65
|
-
steps:
|
66
|
-
- checkout
|
67
|
-
- <<: *repo_restore_cache
|
68
|
-
- <<: *bundle_install
|
69
|
-
- <<: *unit
|
70
|
-
"ruby-2.4":
|
71
|
-
docker:
|
72
|
-
- image: circleci/ruby:2.4
|
73
|
-
working_directory: ~/method_source
|
74
|
-
steps:
|
75
|
-
- checkout
|
76
|
-
- <<: *repo_restore_cache
|
77
|
-
- <<: *bundle_install
|
78
|
-
- <<: *unit
|
79
|
-
"ruby-2.5":
|
80
|
-
docker:
|
81
|
-
- image: circleci/ruby:2.5
|
82
|
-
working_directory: ~/method_source
|
83
|
-
steps:
|
84
|
-
- checkout
|
85
|
-
- <<: *repo_restore_cache
|
86
|
-
- <<: *bundle_install
|
87
|
-
- <<: *unit
|
88
|
-
"ruby-2.6":
|
89
|
-
docker:
|
90
|
-
- image: circleci/ruby:2.6
|
91
|
-
working_directory: ~/method_source
|
92
|
-
steps:
|
93
|
-
- checkout
|
94
|
-
- <<: *repo_restore_cache
|
95
|
-
- <<: *bundle_install
|
96
|
-
- <<: *unit
|
97
|
-
"ruby-2.7":
|
98
|
-
docker:
|
99
|
-
- image: circleci/ruby:2.7.0
|
100
|
-
working_directory: ~/method_source
|
101
|
-
steps:
|
102
|
-
- checkout
|
103
|
-
- <<: *repo_restore_cache
|
104
|
-
- <<: *bundle_install
|
105
|
-
- <<: *unit
|
106
|
-
"jruby-9.1-jdk":
|
107
|
-
docker:
|
108
|
-
- image: circleci/jruby:9.1-jdk
|
109
|
-
working_directory: ~/method_source
|
110
|
-
steps:
|
111
|
-
- checkout
|
112
|
-
- <<: *repo_restore_cache
|
113
|
-
- <<: *bundle_install
|
114
|
-
- <<: *unit
|
115
|
-
"jruby-9.2-jdk":
|
116
|
-
docker:
|
117
|
-
- image: circleci/jruby:9.2-jdk
|
118
|
-
working_directory: ~/method_source
|
119
|
-
steps:
|
120
|
-
- checkout
|
121
|
-
- <<: *repo_restore_cache
|
122
|
-
- <<: *bundle_install
|
123
|
-
- <<: *unit
|
124
|
-
|
125
|
-
workflows:
|
126
|
-
version: 2
|
127
|
-
build:
|
128
|
-
jobs:
|
129
|
-
- "ruby-1.9"
|
130
|
-
- "ruby-2.0"
|
131
|
-
- "ruby-2.1"
|
132
|
-
- "ruby-2.2"
|
133
|
-
- "ruby-2.3"
|
134
|
-
- "ruby-2.4"
|
135
|
-
- "ruby-2.5"
|
136
|
-
- "ruby-2.6"
|
137
|
-
- "ruby-2.7"
|
138
|
-
- "jruby-9.1-jdk"
|
139
|
-
- "jruby-9.2-jdk"
|