ruval 0.1.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 +57 -0
- data/.travis.yml +6 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +21 -0
- data/LICENSE.txt +21 -0
- data/README.md +53 -0
- data/Rakefile +14 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/ruval +5 -0
- data/exe/rv +5 -0
- data/lib/ruval.rb +96 -0
- data/lib/ruval/version.rb +3 -0
- data/ruval.gemspec +29 -0
- metadata +59 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2b863b7435fb17b88d4ffd5daa5d1ca2a0222e2a57d3cd429fbea1f57d06c433
|
4
|
+
data.tar.gz: 4a2771ba61e7ff6a3baa0e809907b34c7f6bba63f1c0720c94d932b0ae9f2291
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 219ac8814e1c26af0f1082e6249f40817c0ac5ac3590daf6ff18a04937d83ddb4aa5c8a4bddbc955359a1f3b66575dfb3d6795895fdad76dd8ef6cd11329bbf7
|
7
|
+
data.tar.gz: a339bf6e4baaf077c8c06339bb084b4effb7acfea61e3f7ba6e2ea23de10b6e552491609c826a898a4ce086c9944b3848e7d150875ddef41da0e33ed7ab0d820
|
data/.gitignore
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# files without extensions except directories
|
2
|
+
#*
|
3
|
+
#!/**/
|
4
|
+
#!?*.*
|
5
|
+
|
6
|
+
# directories
|
7
|
+
/.bundle
|
8
|
+
/_yardoc
|
9
|
+
/coverage
|
10
|
+
/doc
|
11
|
+
/pkg
|
12
|
+
/spec/reports
|
13
|
+
/tmp
|
14
|
+
/vendor
|
15
|
+
|
16
|
+
# files
|
17
|
+
*.dump
|
18
|
+
*.log
|
19
|
+
*.mod
|
20
|
+
*.o
|
21
|
+
*~
|
22
|
+
.*.swp
|
23
|
+
.DS_Store
|
24
|
+
.byebug
|
25
|
+
.idea
|
26
|
+
.project
|
27
|
+
.rake*
|
28
|
+
.rake*
|
29
|
+
.ruby-*
|
30
|
+
.rvmrc
|
31
|
+
.rubocop*
|
32
|
+
.secret
|
33
|
+
.yardoc
|
34
|
+
TODO.md
|
35
|
+
core.*
|
36
|
+
cscope.out
|
37
|
+
secrets.yml
|
38
|
+
.tags
|
39
|
+
|
40
|
+
# don't ignore
|
41
|
+
!.gitignore
|
42
|
+
!.keep
|
43
|
+
!Capfile
|
44
|
+
!Cheffile
|
45
|
+
!Gemfile
|
46
|
+
![MR]akefile
|
47
|
+
!bin/**/[^.]*
|
48
|
+
!exe/**/[^.]*
|
49
|
+
|
50
|
+
/.bundle/
|
51
|
+
/.yardoc
|
52
|
+
/_yardoc/
|
53
|
+
/coverage/
|
54
|
+
/doc/
|
55
|
+
/pkg/
|
56
|
+
/spec/reports/
|
57
|
+
/tmp/
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
ruval (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
minitest (5.14.3)
|
10
|
+
rake (12.3.3)
|
11
|
+
|
12
|
+
PLATFORMS
|
13
|
+
ruby
|
14
|
+
|
15
|
+
DEPENDENCIES
|
16
|
+
minitest (~> 5.0)
|
17
|
+
rake (~> 12.0)
|
18
|
+
ruval!
|
19
|
+
|
20
|
+
BUNDLED WITH
|
21
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 sergioro
|
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,53 @@
|
|
1
|
+
# Ruval
|
2
|
+
|
3
|
+
Consider this program:
|
4
|
+
|
5
|
+
$ cat prog.rb
|
6
|
+
'hola'
|
7
|
+
|
8
|
+
def good; ':)'; end
|
9
|
+
|
10
|
+
def bad
|
11
|
+
':('
|
12
|
+
end
|
13
|
+
|
14
|
+
class Person
|
15
|
+
attr_accessor :name, :mood
|
16
|
+
|
17
|
+
def initialize(name='bob')
|
18
|
+
@name='bob'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
person1 = Person.new
|
23
|
+
person1.name
|
24
|
+
person1.mood = good
|
25
|
+
person1.mood
|
26
|
+
|
27
|
+
Run it with ruval:
|
28
|
+
|
29
|
+
$ ruval prog.rb
|
30
|
+
'hola'
|
31
|
+
=> hola
|
32
|
+
def good; ':)'; end
|
33
|
+
=> good
|
34
|
+
def bad
|
35
|
+
':('
|
36
|
+
end
|
37
|
+
=> bad
|
38
|
+
class Person
|
39
|
+
attr_accessor :name, :mood
|
40
|
+
|
41
|
+
def initialize(name='bob')
|
42
|
+
@name='bob'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
=> initialize
|
46
|
+
person1 = Person.new
|
47
|
+
=> #<Person:0x00000000010cfc50>
|
48
|
+
person1.name
|
49
|
+
=> bob
|
50
|
+
person1.mood = bad
|
51
|
+
=> :)
|
52
|
+
person1.mood
|
53
|
+
=> :)
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/clean'
|
4
|
+
|
5
|
+
CLEAN.include ['**/.*.sw?', '**/*.gem', 'test/test.log']
|
6
|
+
|
7
|
+
task default: %i[test package]
|
8
|
+
task package: :clean
|
9
|
+
|
10
|
+
Rake::TestTask.new do |t|
|
11
|
+
t.libs << 'lib' << 'test'
|
12
|
+
t.test_files = FileList['test/**/*_test.rb']
|
13
|
+
t.warning = false
|
14
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ruval"
|
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
data/exe/ruval
ADDED
data/exe/rv
ADDED
data/lib/ruval.rb
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
$LOAD_PATH.unshift __dir__
|
2
|
+
|
3
|
+
require "ruval/version"
|
4
|
+
|
5
|
+
module Ruval
|
6
|
+
class Error < StandardError; end
|
7
|
+
# Your code goes here...
|
8
|
+
end
|
9
|
+
|
10
|
+
#!/usr/bin/env -S ruby -W0
|
11
|
+
# vim: ft=ruby:syntax=ruby
|
12
|
+
|
13
|
+
DEFAULT_NEWLINES = 1
|
14
|
+
KEYWORDS_REGEX = /\b(?:class|module|def|if|do|end)\b/
|
15
|
+
|
16
|
+
def prog
|
17
|
+
File.basename $0
|
18
|
+
end
|
19
|
+
|
20
|
+
def help
|
21
|
+
puts <<~e
|
22
|
+
Usage: #{prog} <file> [option]
|
23
|
+
Print the value of statements in a file
|
24
|
+
|
25
|
+
Options:
|
26
|
+
-h, --help print this message
|
27
|
+
-n N line spacing between evaluations (non-negative value, default 1)
|
28
|
+
e
|
29
|
+
exit
|
30
|
+
end
|
31
|
+
|
32
|
+
class String
|
33
|
+
def remove_comments(padding)
|
34
|
+
# not a perfect regex but good enough to detect most comments. eg it wont work for lines like "fun('#not a comment')"
|
35
|
+
self.gsub(/ *#.*/, '').chop.ljust(padding) + ' # '
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# true if line is a comment
|
40
|
+
def comment?(line)
|
41
|
+
line.strip[0] == '#'
|
42
|
+
end
|
43
|
+
|
44
|
+
if ARGV.empty? || (%w(-h --help) & ARGV).length > 0
|
45
|
+
help
|
46
|
+
end
|
47
|
+
|
48
|
+
file = ARGV.shift
|
49
|
+
|
50
|
+
if ARGV.include?('-n')
|
51
|
+
_, line_spacing = ARGV[ARGV.index('-n'),2]
|
52
|
+
line_spacing = line_spacing.to_i
|
53
|
+
end
|
54
|
+
line_spacing ||= DEFAULT_NEWLINES
|
55
|
+
|
56
|
+
if line_spacing < 0
|
57
|
+
puts "line_spacing cannot be negative"
|
58
|
+
exit
|
59
|
+
end
|
60
|
+
|
61
|
+
# get longest line
|
62
|
+
longest = 0
|
63
|
+
File.read(file).each_line do |l|
|
64
|
+
next if(comment?(l) || l.strip.empty?)
|
65
|
+
line_width = l.remove_comments(0).length
|
66
|
+
longest = line_width > longest ? line_width : longest
|
67
|
+
end
|
68
|
+
|
69
|
+
def update_scope(line, line_stack, scope)
|
70
|
+
keywords = line.scan(KEYWORDS_REGEX)
|
71
|
+
return if keywords.empty? && scope.empty?
|
72
|
+
line_stack << line
|
73
|
+
keywords.each do |kw|
|
74
|
+
unless kw == 'end'
|
75
|
+
scope.push kw
|
76
|
+
else
|
77
|
+
scope.pop
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
line_stack = []
|
83
|
+
scope = []
|
84
|
+
|
85
|
+
File.read(file).each_line do |l|
|
86
|
+
update_scope(l, line_stack, scope)
|
87
|
+
next if(comment?(l) || l.strip.empty? || !scope.empty?)
|
88
|
+
l = if line_stack.empty?
|
89
|
+
line_spacing == 0 ? l.remove_comments(longest) : l
|
90
|
+
else
|
91
|
+
line_stack.join
|
92
|
+
end
|
93
|
+
line_stack = []
|
94
|
+
puts l + "=> #{eval l, TOPLEVEL_BINDING}" + "\n"*line_spacing
|
95
|
+
end
|
96
|
+
|
data/ruval.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative 'lib/ruval/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "ruval"
|
5
|
+
spec.version = Ruval::VERSION
|
6
|
+
spec.authors = ["sergio"]
|
7
|
+
spec.email = ["yo@sergioro.com"]
|
8
|
+
|
9
|
+
spec.summary = %q{Print the value of every statement in a Ruby progam}
|
10
|
+
spec.description = %q{Print the value of every statement in a Ruby progam}
|
11
|
+
#spec.homepage = "TODO: Put your gem's website or public repo URL here."
|
12
|
+
spec.license = "MIT"
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
14
|
+
|
15
|
+
#spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
16
|
+
|
17
|
+
#spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
#spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
|
19
|
+
#spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
end
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruval
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- sergio
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-01-17 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Print the value of every statement in a Ruby progam
|
14
|
+
email:
|
15
|
+
- yo@sergioro.com
|
16
|
+
executables:
|
17
|
+
- ruval
|
18
|
+
- rv
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- ".gitignore"
|
23
|
+
- ".travis.yml"
|
24
|
+
- Gemfile
|
25
|
+
- Gemfile.lock
|
26
|
+
- LICENSE.txt
|
27
|
+
- README.md
|
28
|
+
- Rakefile
|
29
|
+
- bin/console
|
30
|
+
- bin/setup
|
31
|
+
- exe/ruval
|
32
|
+
- exe/rv
|
33
|
+
- lib/ruval.rb
|
34
|
+
- lib/ruval/version.rb
|
35
|
+
- ruval.gemspec
|
36
|
+
homepage:
|
37
|
+
licenses:
|
38
|
+
- MIT
|
39
|
+
metadata: {}
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 2.3.0
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
requirements: []
|
55
|
+
rubygems_version: 3.1.4
|
56
|
+
signing_key:
|
57
|
+
specification_version: 4
|
58
|
+
summary: Print the value of every statement in a Ruby progam
|
59
|
+
test_files: []
|