read_source 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/read_source/read_source.rb +11 -2
- data/lib/read_source/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e2b9a4bf7b96355cb4ca92c1c5cba7eb95afbe4
|
4
|
+
data.tar.gz: 357675e49290e47b79d7cfc1531fa1b4c40da0be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 936410346fcd4c0f8a4f2cf081b40b0b3beb9170ba5db17cb7b13b09712668ef166c7ad97024a65eedc3a64c022ab8385f0891c4a7808e14be85558eaec0e873
|
7
|
+
data.tar.gz: dd3f670c46f70bed6da723f31f04d565cd53179d9f6e59d47185d4b1ce5d21c9760d24247887c45d8a2b0066a883ed2f63351fb7deaf7da8fd79b24235183942
|
@@ -2,11 +2,19 @@ module ReadSource
|
|
2
2
|
module ReadSource
|
3
3
|
def read_source
|
4
4
|
(file, line_num = send :source_location) || return
|
5
|
+
|
6
|
+
is_inline_method = ->str{
|
7
|
+
defs = str.scan(/def(?:\b|ine_method.*do)/).count
|
8
|
+
ends = str.scan(/end/).count
|
9
|
+
def_method_regex = /define_method[ (]+(?::|\w)+[ ),]+(?:{.*}|(?:instance_)?method\((?::|\w)+\)|&\w+)\)?/
|
10
|
+
defs == ends || str =~ def_method_regex
|
11
|
+
}
|
12
|
+
|
5
13
|
readlines = IO.readlines(file)
|
6
14
|
source = readlines[line_num-1]
|
7
15
|
indent = /\A[[:space:]]*/.match(source).to_s.length
|
8
16
|
source = source[indent..-1]
|
9
|
-
return source if source
|
17
|
+
return source if source.=~(/\A[[:space:]]*attr[\w]*/) || is_inline_method.(source)
|
10
18
|
readlines[line_num..-1].each do |line|
|
11
19
|
source += line[indent..-1]
|
12
20
|
if indent == /\A[[:space:]]*/.match(line).to_s.length
|
@@ -18,7 +26,8 @@ module ReadSource
|
|
18
26
|
def attr?
|
19
27
|
(file, line_num = send :source_location) || return
|
20
28
|
def_header = IO.readlines(file)[line_num-1]
|
21
|
-
def_header[
|
29
|
+
return unless def_header =~ /\A[[:space:]]*attr[\w]*/
|
30
|
+
def_header[/attr[\w]*/].to_sym rescue nil
|
22
31
|
end
|
23
32
|
end
|
24
33
|
end
|
data/lib/read_source/version.rb
CHANGED