class_indexer 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/class_indexer.gemspec +31 -0
- data/exe/indexer +15 -0
- data/lib/class_indexer/version.rb +3 -0
- data/lib/class_indexer.rb +79 -0
- metadata +114 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 9a97753d6f810aeaae7c6f6394ee54e9fc56ee80
|
|
4
|
+
data.tar.gz: 57ea902f8af6bb1b5f8ed68aa95fa24f5111a83c
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: c22e78e71b07946ed83661bbc220b29bde79a4a3b64886307fbc7d27f3c5ee5d36d5a7d612b792cd503fe9cb6272cef328d34561fc606c8c98b2602859baddab
|
|
7
|
+
data.tar.gz: 2df9314d79860a8e90c689fb7830bd1a7ba4ec47534413ffb4d3e399c857bb988b29bd5b5d3892cbc091d153f3629ffdb09006c62c6209ab9a5d8b5b7c3311e2
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2015 matugm
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# ClassIndexer
|
|
2
|
+
|
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/class_indexer`. To experiment with that code, run `bin/console` for an interactive prompt.
|
|
4
|
+
|
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Add this line to your application's Gemfile:
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
gem 'class_indexer'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
And then execute:
|
|
16
|
+
|
|
17
|
+
$ bundle
|
|
18
|
+
|
|
19
|
+
Or install it yourself as:
|
|
20
|
+
|
|
21
|
+
$ gem install class_indexer
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
TODO: Write usage instructions here
|
|
26
|
+
|
|
27
|
+
## Development
|
|
28
|
+
|
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
30
|
+
|
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
32
|
+
|
|
33
|
+
## Contributing
|
|
34
|
+
|
|
35
|
+
1. Fork it ( https://github.com/[my-github-username]/class_indexer/fork )
|
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
37
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
39
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "class_indexer"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'class_indexer/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "class_indexer"
|
|
8
|
+
spec.version = ClassIndexer::VERSION
|
|
9
|
+
spec.authors = ["matugm"]
|
|
10
|
+
spec.email = ["matugm@gmail.com"]
|
|
11
|
+
|
|
12
|
+
if spec.respond_to?(:metadata)
|
|
13
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
spec.summary = %q{Index all methods and output json.}
|
|
17
|
+
spec.description = %q{Reads ruby files in the current directory to produce a json index of methods and classes. Use the 'indexer' command to run.}
|
|
18
|
+
spec.homepage = "http://www.blackbytes.info"
|
|
19
|
+
spec.license = "MIT"
|
|
20
|
+
|
|
21
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
22
|
+
spec.bindir = "exe"
|
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
24
|
+
spec.require_paths = ["lib"]
|
|
25
|
+
|
|
26
|
+
spec.add_dependency "parser"
|
|
27
|
+
spec.add_dependency "json"
|
|
28
|
+
|
|
29
|
+
spec.add_development_dependency "bundler", "~> 1.8"
|
|
30
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
31
|
+
end
|
data/exe/indexer
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'class_indexer'
|
|
4
|
+
|
|
5
|
+
# Find ruby files
|
|
6
|
+
files = Dir.glob("**/*.rb")
|
|
7
|
+
output = {}
|
|
8
|
+
|
|
9
|
+
# Parse every file we found
|
|
10
|
+
files.each do |input_file|
|
|
11
|
+
output[input_file] = ClassIndexer::process_file(input_file)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# Output json (pretty format)
|
|
15
|
+
jj output
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
require 'class_indexer/version'
|
|
2
|
+
|
|
3
|
+
require 'parser/current'
|
|
4
|
+
require 'json'
|
|
5
|
+
|
|
6
|
+
module ClassIndexer
|
|
7
|
+
class Processor < AST::Processor
|
|
8
|
+
def initialize
|
|
9
|
+
reset_class
|
|
10
|
+
@class_list = {}
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def reset_class
|
|
14
|
+
@current_class = "main"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def get_list
|
|
18
|
+
@class_list
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def add_method(method_name, line_num)
|
|
22
|
+
unless @class_list.has_key? @current_class
|
|
23
|
+
@class_list[@current_class] = []
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
@class_list[@current_class] << {name: method_name.to_s, line: line_num}
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def on_class(node)
|
|
30
|
+
line_num = node.children[0].loc.line
|
|
31
|
+
class_name = node.children[0].children[1]
|
|
32
|
+
|
|
33
|
+
@current_class = class_name.to_s
|
|
34
|
+
node.children.each { |c| process(c) }
|
|
35
|
+
reset_class
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Instance methods
|
|
39
|
+
def on_def(node)
|
|
40
|
+
line_num = node.loc.line
|
|
41
|
+
method_name = node.children[0]
|
|
42
|
+
|
|
43
|
+
add_method(method_name, line_num)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Class methods
|
|
47
|
+
def on_defs(node)
|
|
48
|
+
line_num = node.loc.line
|
|
49
|
+
method_name = "self.#{node.children[1]}"
|
|
50
|
+
|
|
51
|
+
add_method(method_name, line_num)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def on_const(node)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def on_send(node)
|
|
58
|
+
# method call
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def on_begin(node)
|
|
62
|
+
node.children.each { |c| process(c) }
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def handler_missing(node)
|
|
66
|
+
#puts "missing #{node.type}"
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def self.process_file(file)
|
|
71
|
+
exp = Parser::CurrentRuby.parse(File.read(file))
|
|
72
|
+
ast = Processor.new
|
|
73
|
+
ast.process(exp)
|
|
74
|
+
ast.get_list
|
|
75
|
+
rescue Parser::SyntaxError
|
|
76
|
+
$stderr.puts "Syntax Error found while parsing #{file}"
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: class_indexer
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.2.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- matugm
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-06-27 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: parser
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: json
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: bundler
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '1.8'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '1.8'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: rake
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '10.0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '10.0'
|
|
69
|
+
description: Reads ruby files in the current directory to produce a json index of
|
|
70
|
+
methods and classes. Use the 'indexer' command to run.
|
|
71
|
+
email:
|
|
72
|
+
- matugm@gmail.com
|
|
73
|
+
executables:
|
|
74
|
+
- indexer
|
|
75
|
+
extensions: []
|
|
76
|
+
extra_rdoc_files: []
|
|
77
|
+
files:
|
|
78
|
+
- ".gitignore"
|
|
79
|
+
- Gemfile
|
|
80
|
+
- LICENSE.txt
|
|
81
|
+
- README.md
|
|
82
|
+
- Rakefile
|
|
83
|
+
- bin/console
|
|
84
|
+
- bin/setup
|
|
85
|
+
- class_indexer.gemspec
|
|
86
|
+
- exe/indexer
|
|
87
|
+
- lib/class_indexer.rb
|
|
88
|
+
- lib/class_indexer/version.rb
|
|
89
|
+
homepage: http://www.blackbytes.info
|
|
90
|
+
licenses:
|
|
91
|
+
- MIT
|
|
92
|
+
metadata:
|
|
93
|
+
allowed_push_host: https://rubygems.org
|
|
94
|
+
post_install_message:
|
|
95
|
+
rdoc_options: []
|
|
96
|
+
require_paths:
|
|
97
|
+
- lib
|
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
99
|
+
requirements:
|
|
100
|
+
- - ">="
|
|
101
|
+
- !ruby/object:Gem::Version
|
|
102
|
+
version: '0'
|
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
|
+
requirements:
|
|
105
|
+
- - ">="
|
|
106
|
+
- !ruby/object:Gem::Version
|
|
107
|
+
version: '0'
|
|
108
|
+
requirements: []
|
|
109
|
+
rubyforge_project:
|
|
110
|
+
rubygems_version: 2.4.8
|
|
111
|
+
signing_key:
|
|
112
|
+
specification_version: 4
|
|
113
|
+
summary: Index all methods and output json.
|
|
114
|
+
test_files: []
|