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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9c8201f06d97a0a87489cd27c6bd19659b29e13b
4
- data.tar.gz: 97ae56a003253399e404933bb7ef369534600cf4
3
+ metadata.gz: 1e2b9a4bf7b96355cb4ca92c1c5cba7eb95afbe4
4
+ data.tar.gz: 357675e49290e47b79d7cfc1531fa1b4c40da0be
5
5
  SHA512:
6
- metadata.gz: 5c6735afb77b530073e5bb3409dad53aae1ba35cb912385e40fd5dbbea4eb2576e2fb8acefd8cf636d734db1e2854b90a98e48c4a6b36851aa4bd052689cb2a1
7
- data.tar.gz: dafa783756676f45fd689eabc1b989c6b43df3db3925924295d354289133a56af849f5316a87d6681ad1ce469e4181742eaa205b8f488f603bd1e603d3c94f7e
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 =~ /(attr[\w]*)/
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[/(attr[\w]*)/].to_sym rescue nil
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
@@ -1,3 +1,3 @@
1
1
  module ReadSource
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: read_source
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel P. Clark