method_parser 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ec715241e2d9ab1971cc9ec18587f08211e54e98
4
+ data.tar.gz: a8003b591339cd95c53a41d1e61226021ad1c0fd
5
+ SHA512:
6
+ metadata.gz: 4a04386739bd5cc4db0549b4df6753b26714845a7c77592d121e50ed561048223fae5eafc54093f763e5902bc1528094f54671a6c062e245aecfff06bea860eb
7
+ data.tar.gz: 3a847a9f12babab3b65b51beb64a8acf36ae81305aa5efa7a559841c9d1de6465cdbacc94f2ca9b82b3396c318ea18fcbb0a22b18f8d02e986ccb3043e7b7e70
checksums.yaml.gz.sig ADDED
Binary file
data.tar.gz.sig ADDED
Binary file
@@ -0,0 +1,94 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # file: method_parser.rb
4
+
5
+ require 'parser/current'
6
+
7
+ class MethodParser
8
+
9
+ attr_reader :to_a
10
+
11
+ def initialize(s)
12
+ @to_a = nestify(flatten_down(scan Parser::CurrentRuby.parse(s)))
13
+ end
14
+
15
+ private
16
+
17
+ def scan(x)
18
+
19
+ r = x.children.map do |y|
20
+ if y.is_a? Parser::AST::Node then
21
+ list = scan(y)
22
+ if list.length > 0 then
23
+ list
24
+ else
25
+ nil
26
+ end
27
+ end
28
+ end.compact
29
+
30
+ a2 = case x.type
31
+
32
+ when :def
33
+ [x.type, x.to_a.first]
34
+ when :class
35
+ [x.type, x.to_a.first.to_a[1]]
36
+
37
+ when :send
38
+
39
+ y = x.children.last
40
+
41
+ if y == :private or y == :protected then
42
+ y
43
+ else
44
+ []
45
+ end
46
+
47
+ else
48
+ []
49
+ end
50
+
51
+ [a2.length > 0 ? a2 : nil, r.length > 0 ? r : nil].compact
52
+
53
+ end
54
+
55
+ def flatten_down(a3)
56
+
57
+ r = a3.map do |x|
58
+ x2 = (x[0].is_a?(Array) and x.length == 1) ? x.flatten(1) : x
59
+ x2.is_a?(Array) ? flatten_down(x2) : x2
60
+ end
61
+
62
+ r.length == 1 ? r.flatten(1) : r
63
+ end
64
+
65
+ def nestify(a2)
66
+
67
+ scope = :public
68
+ a2.inject([]) do |r, x|
69
+
70
+ case x.first
71
+ when :class
72
+ r << [:class, x.last, []]
73
+ else
74
+ x.each do |mx|
75
+
76
+ case mx.first
77
+ when :def
78
+
79
+ method = mx.last
80
+ r.last.last <<
81
+ [:def, method, method == :initialize ? :private : scope]
82
+ when :private
83
+ scope = :private
84
+ when :protected
85
+ scope = :protected
86
+ end
87
+ end
88
+ end
89
+ r
90
+ end
91
+
92
+ end
93
+
94
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: method_parser
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - James Robertson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
14
+ YXN0ZXIxHjAcBgoJkiaJk/IsZAEZFg5qYW1lc3JvYmVydHNvbjESMBAGCgmSJomT
15
+ 8ixkARkWAmV1MB4XDTE0MDkxNTE1NDMzMFoXDTE1MDkxNTE1NDMzMFowSDESMBAG
16
+ A1UEAwwJZ2VtbWFzdGVyMR4wHAYKCZImiZPyLGQBGRYOamFtZXNyb2JlcnRzb24x
17
+ EjAQBgoJkiaJk/IsZAEZFgJldTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
18
+ ggEBAKexQp0cPjmGUBbCfGr8yObAz+cU8xxDF+HO/2AZOD9eiC4VvP0C/4/HZz3B
19
+ Elzm0HocBw01jBK+UEX0MqaYu0EL/zN4rdnFXjkHHlwRy9lDK77hpRyhrpcvaEoh
20
+ c9y/LWibHVYWAVxlBWojnHPCRCuejx2DLGGLs46OcL21Sod6mIFp3rrffqnc3HFt
21
+ hE0TtbDdH9g+FacIQeBh4tEkczqNr3Y5mMSSHmrG9seCfWHyrEgLhY2bOmQscrxU
22
+ +OhNNDtj1Z8E1QX4XbqzdUsYRIRDY50QOm9wO432G/lnnxw9/hJ/zwRS2DURx7Cc
23
+ PsVUOqtVrJVqmEYB/ycjlcjdnfcCAwEAAaOBijCBhzAJBgNVHRMEAjAAMAsGA1Ud
24
+ DwQEAwIEsDAdBgNVHQ4EFgQUIKHnLYi6UTIWeUDq7mUVpose8CMwJgYDVR0RBB8w
25
+ HYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0c29uLmV1MCYGA1UdEgQfMB2BG2dlbW1h
26
+ c3RlckBqYW1lc3JvYmVydHNvbi5ldTANBgkqhkiG9w0BAQUFAAOCAQEASXYoVPyd
27
+ 5BJ0pmGpGnY4GTYLqitcW58xCblh0ubcLYhnr3A+mdMvZvIZoxgpuHPePEn1m3VC
28
+ xXVqCEx1Wq8XXvU3u1NjrTa08EBj+ggpkVf5Qsd2mS/wPpBL2N8rZKX2WdkTOHEG
29
+ OOSSrUJ0PyUsFE62/0ecP10vKR2fmy30wnpJY2REVyBGGRqsdndbkZ9kZMZ50F+3
30
+ czQuswn0Qao4frgO4PgzOuy1JTIcIsEDpzQCEHGXz+J4dC2W4wH/9RpccyqVEmLs
31
+ K9vYBtxHayYvCD96peQuwgcRodXugw0ODC9ArfnGO7NPFRPFyIK5SgmNh1YY3yse
32
+ jfv3+Ayxw5bDxA==
33
+ -----END CERTIFICATE-----
34
+ date: 2014-09-15 00:00:00.000000000 Z
35
+ dependencies:
36
+ - !ruby/object:Gem::Dependency
37
+ name: parser
38
+ requirement: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '2.1'
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 2.1.9
46
+ type: :runtime
47
+ prerelease: false
48
+ version_requirements: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: '2.1'
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 2.1.9
56
+ description:
57
+ email: james@r0bertson.co.uk
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - lib/method_parser.rb
63
+ homepage: https://github.com/jrobertson/method_parser
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.2.2
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: Uses the Parser gem to primarily return the defined methods for the class
87
+ test_files: []
metadata.gz.sig ADDED
Binary file