rvnc 0.0.1

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
+ SHA256:
3
+ metadata.gz: 9e52afc427f5f80eb3c633330ee4fa0f301672c0cb2fb65ff901ce0a99063a43
4
+ data.tar.gz: 76410c82c67cff0a8ce4ee60d55b3b952b2fb0116b25143dec19d3ed92c89644
5
+ SHA512:
6
+ metadata.gz: 2cfeed5f5fe595c3f7e3e34b6f9559d58b08878659a99ec1eab95ed2acbea513c248afa550167a59199f3b46dac8a6916b4666ffa79089e1d63017b6a036d0b1
7
+ data.tar.gz: 1e0bbd454a2049c920151af027c49c74da1fa3c21015429da703c1b5a14ef16f57329d497c66dc018bf31dc5ee3acc1a26dfe735c51d25b9f0b9e3b3c485befd
checksums.yaml.gz.sig ADDED
Binary file
data.tar.gz.sig ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.6.0
5
+ before_install: gem install bundler -v 1.16.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at tmshuichi@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in rvnc.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,39 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rvnc (0.0.1)
5
+ terminal-table (~> 1.8.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.3)
11
+ rake (10.5.0)
12
+ rspec (3.7.0)
13
+ rspec-core (~> 3.7.0)
14
+ rspec-expectations (~> 3.7.0)
15
+ rspec-mocks (~> 3.7.0)
16
+ rspec-core (3.7.1)
17
+ rspec-support (~> 3.7.0)
18
+ rspec-expectations (3.7.0)
19
+ diff-lcs (>= 1.2.0, < 2.0)
20
+ rspec-support (~> 3.7.0)
21
+ rspec-mocks (3.7.0)
22
+ diff-lcs (>= 1.2.0, < 2.0)
23
+ rspec-support (~> 3.7.0)
24
+ rspec-support (3.7.1)
25
+ terminal-table (1.8.0)
26
+ unicode-display_width (~> 1.1, >= 1.1.1)
27
+ unicode-display_width (1.4.0)
28
+
29
+ PLATFORMS
30
+ ruby
31
+
32
+ DEPENDENCIES
33
+ bundler (~> 1.16)
34
+ rake (~> 10.0)
35
+ rspec (~> 3.0)
36
+ rvnc!
37
+
38
+ BUNDLED WITH
39
+ 1.16.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Shuichi Tamayose
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,75 @@
1
+ # RVNC
2
+
3
+ Ruby Variable Name Collector.
4
+
5
+ RVNC collects variable name by using RubyVM::AST.
6
+
7
+ Argument names don't supported.
8
+
9
+ require 'RUBY_VERSION >= 2.6.0preview2'
10
+
11
+ ## Installation
12
+
13
+ ```ruby
14
+ gem 'rvnc'
15
+ ```
16
+
17
+ Or install it yourself as:
18
+
19
+ ```
20
+ $ gem install rvnc
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ example.rb
26
+
27
+ ```ruby
28
+ $global = 'global'
29
+ foo = 1
30
+ bar = 'hi'
31
+ BAZ = :baz
32
+ a, *b = [1, 2, 3]
33
+
34
+ class A
35
+ @@test = 'test'
36
+
37
+ def initialize
38
+ @name = 'test'
39
+ end
40
+ end
41
+ ```
42
+
43
+ run `rvnc` command
44
+
45
+ ```
46
+ $ rvnc example.rb
47
+ ```
48
+
49
+ result
50
+
51
+ ```
52
+ +---------+---------------+
53
+ | Name | Location |
54
+ +---------+---------------+
55
+ | $global | example.rb:1 |
56
+ | foo | example.rb:2 |
57
+ | bar | example.rb:3 |
58
+ | BAZ | example.rb:4 |
59
+ | a | example.rb:5 |
60
+ | b | example.rb:5 |
61
+ | @@test | example.rb:8 |
62
+ | @name | example.rb:11 |
63
+ +---------+---------------+
64
+ ```
65
+
66
+ If you specify a directory path, it collects recursively.
67
+
68
+
69
+ ## License
70
+
71
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
72
+
73
+ ## Code of Conduct
74
+
75
+ Everyone interacting in the Rvnc project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/siman-man/rvnc/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rvnc"
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(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/rvnc ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rvnc'
4
+ require 'optparse'
5
+ require 'terminal-table'
6
+
7
+ options = {}
8
+
9
+ OptionParser.new do |opt|
10
+ opt.banner = 'Usage: rvnc [options] filepath'
11
+ opt.on('-v', '--version', 'display the version.') { options[:version] = true }
12
+
13
+ opt.parse!(ARGV)
14
+ end
15
+
16
+ case
17
+ when options[:version]
18
+ puts "RVNC version: #{RVNC::VERSION}"
19
+ else
20
+ result = RVNC.collect(ARGV.first)
21
+ table = Terminal::Table.new(rows: result.map(&:values), headings: ['Name', 'Location'])
22
+ puts table
23
+ end
data/lib/rvnc.rb ADDED
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rvnc/source_file'
4
+ require 'rvnc/version'
5
+
6
+ module RVNC
7
+ VARIABLE_NODES = %w[
8
+ NODE_CDECL
9
+ NODE_CVASGN
10
+ NODE_DASGN_CURR
11
+ NODE_GASGN
12
+ NODE_IASGN
13
+ NODE_MASGN
14
+ ].freeze
15
+
16
+ def self.collect(root)
17
+ if File.directory?(root)
18
+ Dir.glob("#{root}/**/*.rb").map do |path|
19
+ variables(path)
20
+ end.flatten
21
+ else
22
+ variables(root)
23
+ end
24
+ end
25
+
26
+ def self.variables(path)
27
+ SourceFile.new(File.expand_path(path)).variables
28
+ end
29
+ end
@@ -0,0 +1,59 @@
1
+ require 'pathname'
2
+
3
+ module RVNC
4
+ class SourceFile
5
+ def initialize(path)
6
+ @path = path
7
+ @relative_path = Pathname.new(path).relative_path_from(Pathname.new(Dir.pwd))
8
+ @source = File.readlines(path)
9
+ @variables = []
10
+ end
11
+
12
+ def variables
13
+ ast = RubyVM::AST.parse(@source.join)
14
+ traverse(ast)
15
+ @variables.flatten
16
+ end
17
+
18
+ private
19
+
20
+ def traverse(parent)
21
+ if RVNC::VARIABLE_NODES.include?(parent.type)
22
+ extract_variables(parent)
23
+ end
24
+
25
+ parent.children.compact.each do |child|
26
+ traverse(child)
27
+ end
28
+ end
29
+
30
+ def extract_variables(node)
31
+ first_lineno = node.first_lineno - 1
32
+ first_column = node.first_column
33
+ last_lineno = node.last_lineno - 1
34
+ last_column = node.last_column
35
+
36
+ if first_lineno == last_lineno
37
+ src = @source[first_lineno][first_column..last_column]
38
+ else
39
+ src = @source[first_lineno][first_column..]
40
+ ((first_lineno + 1)...(last_lineno)).each do |lineno|
41
+ src << @source[lineno]
42
+ end
43
+ src << @source[last_lineno][0..last_column]
44
+ end
45
+
46
+ return unless src.include?('=')
47
+
48
+ location = [@relative_path, node.first_lineno].join(':')
49
+ vars = src
50
+ .partition('=')
51
+ .first
52
+ .split(',')
53
+ .map { |v| v.delete('*+-/%|&') }
54
+ .map(&:strip)
55
+ .map { |v| { name: v, location: location } }
56
+ @variables << vars
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RVNC
4
+ VERSION = '0.0.1'
5
+ end
data/rvnc.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'rvnc/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'rvnc'
7
+ spec.version = RVNC::VERSION
8
+ spec.authors = ['Shuichi Tamayose']
9
+ spec.email = ['tmshuichi@gmail.com']
10
+
11
+ spec.summary = %q{Collect variable names}
12
+ spec.description = %q{Collect variable names}
13
+ spec.homepage = 'https://github.com/siman-man/rvnc'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = '> 2.5.9'
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
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_runtime_dependency 'terminal-table', '~> 1.8.0'
27
+
28
+ spec.add_development_dependency 'bundler', '~> 1.16'
29
+ spec.add_development_dependency 'rake', '~> 10.0'
30
+ spec.add_development_dependency 'rspec', '~> 3.0'
31
+ end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rvnc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Shuichi Tamayose
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-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+ON8GMupRcb6m+1yhsEPf2lHKEuvDF/1Qz/4upj
29
+ FtmrnXOWDU8d9BWIoQusX9ifVX232r4Jxg4W6tfp1NckQj2M/AEXtTv2pdX8kerI
30
+ vFCoZpQlUKkcebHO1UlQP2S1W1uk+Ss/0ds6VHX/JENi8TlqNhvX6CyXkZhtBubE
31
+ EIHgBk3NBymdmaMNmlFR25Pq83VCHQ5D41n2it3QNacnKYqrkGbNrl2Q/j5atgfu
32
+ zslpHv2c8jZnJW+sf/RrxMm7/NECNeaK9/+tg31QIowLKO8v9DzbiAAHXZkIFn75
33
+ p6iTQKLI/q7Gnl5DWnL7ZUjva9Dqio6oaV3gyb0wod0fF+nUUtuGvVgLg9Ma5KE8
34
+ qhBmALr0zPrR292f2IxpPPpA3EGv375Yy0dblIxJ2U0C0p2JafJlIbdzTttaG+nR
35
+ hYkTSRBLdxDTa7SbFGW40+TWobTOX/itwk9w0F6Zo7Y=
36
+ -----END CERTIFICATE-----
37
+ date: 2018-06-06 00:00:00.000000000 Z
38
+ dependencies:
39
+ - !ruby/object:Gem::Dependency
40
+ name: terminal-table
41
+ requirement: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - "~>"
44
+ - !ruby/object:Gem::Version
45
+ version: 1.8.0
46
+ type: :runtime
47
+ prerelease: false
48
+ version_requirements: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: 1.8.0
53
+ - !ruby/object:Gem::Dependency
54
+ name: bundler
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '1.16'
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '1.16'
67
+ - !ruby/object:Gem::Dependency
68
+ name: rake
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: '10.0'
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: '10.0'
81
+ - !ruby/object:Gem::Dependency
82
+ name: rspec
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - "~>"
86
+ - !ruby/object:Gem::Version
87
+ version: '3.0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - "~>"
93
+ - !ruby/object:Gem::Version
94
+ version: '3.0'
95
+ description: Collect variable names
96
+ email:
97
+ - tmshuichi@gmail.com
98
+ executables:
99
+ - rvnc
100
+ extensions: []
101
+ extra_rdoc_files: []
102
+ files:
103
+ - ".gitignore"
104
+ - ".rspec"
105
+ - ".travis.yml"
106
+ - CODE_OF_CONDUCT.md
107
+ - Gemfile
108
+ - Gemfile.lock
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/setup
114
+ - exe/rvnc
115
+ - lib/rvnc.rb
116
+ - lib/rvnc/source_file.rb
117
+ - lib/rvnc/version.rb
118
+ - rvnc.gemspec
119
+ homepage: https://github.com/siman-man/rvnc
120
+ licenses:
121
+ - MIT
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">"
130
+ - !ruby/object:Gem::Version
131
+ version: 2.5.9
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 2.7.7
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: Collect variable names
143
+ test_files: []
metadata.gz.sig ADDED
Binary file