pikabu 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 +9 -0
- data/Gemfile +4 -0
- data/README.md +47 -0
- data/bin/console +14 -0
- data/bin/pikabu +6 -0
- data/bin/setup +7 -0
- data/demo.rb +0 -0
- data/lib/pikabu.rb +97 -0
- data/lib/pikabu/version.rb +3 -0
- data/pikabu.gemspec +24 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cfeb212ca3cc852495150b9342375aa7b524eaeb
|
4
|
+
data.tar.gz: 15eda6d82f6469795ed4e5678fb2dbfe52925687
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: eea6c88e26cb77aa5942a3b38d94c5d999e52e8c3ca9d3505280aadd774356b73840d81ee229d88e9ba3d801bd3b80e403a371c94bb09d8c7a73c84ffdecbf00
|
7
|
+
data.tar.gz: 22e0750aa37c687efdb6a5c4d6b315d4b39b4e2a7a8bf1c005d893e15125d329cd679ee00a0ad481cc15ce1d655f31851e2ee91efe3a282f7bcdac45582adbcb
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# Pikabu
|
2
|
+
## Description
|
3
|
+
|
4
|
+
Pikabu is a gem that makes debugging a little bit easier by detecting errors in your ruby script and placing you in a binding environment right before the error occurs. Alternatively, Pikabu can be called with a line number, placing you directly in a binding environment at that line, and all without modifying your original script.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'pikabu'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install pikabu
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
You don't ever need to require pikabu in any of your scripts. To use it, run
|
25
|
+
|
26
|
+
$ pikabu [file_path.rb]
|
27
|
+
|
28
|
+
from the command line. Pikabu will place a binding.pry before the first error it detects and rerun your script.
|
29
|
+
|
30
|
+
You can also run
|
31
|
+
|
32
|
+
$ pikabu [file_path.rb] [line #]
|
33
|
+
|
34
|
+
and pikabu will insert a binding.pry at the line number specified.
|
35
|
+
|
36
|
+
## To Do
|
37
|
+
- Handle more complex file dependencies
|
38
|
+
- Include error type in message to user
|
39
|
+
|
40
|
+
## Contributing
|
41
|
+
Comments and improvements are always welcome!
|
42
|
+
|
43
|
+
1. Fork it ( https://github.com/dnajjar/pikabu/fork )
|
44
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
45
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
46
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
47
|
+
5. Create a new Pull Request
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "pikabu"
|
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/pikabu
ADDED
data/bin/setup
ADDED
data/demo.rb
ADDED
File without changes
|
data/lib/pikabu.rb
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
require_relative "../lib/pikabu/version.rb"
|
2
|
+
require "fileutils"
|
3
|
+
require "pry"
|
4
|
+
require "open3"
|
5
|
+
|
6
|
+
class Pikabu
|
7
|
+
|
8
|
+
def initialize(file_path, line_num)
|
9
|
+
@file_path = file_path
|
10
|
+
@line_num = line_num
|
11
|
+
check_file_path
|
12
|
+
end
|
13
|
+
|
14
|
+
def check_file_path
|
15
|
+
begin
|
16
|
+
load_paths
|
17
|
+
check_line_num
|
18
|
+
rescue LoadError, Errno::ENOENT => e
|
19
|
+
print_help
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def check_line_num
|
24
|
+
if @line_num == nil
|
25
|
+
capture_stdout
|
26
|
+
elsif (@line_num.to_i>@length) || (@line_num.to_i<0) || (@line_num.to_i.to_s!=@line_num)
|
27
|
+
puts "Please try again with a line number between 0 and #{@length}"
|
28
|
+
else
|
29
|
+
@line_num = @line_num.to_i+1
|
30
|
+
peek
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def load_paths
|
35
|
+
@file = File.open(@file_path)
|
36
|
+
@length = File.readlines(@file_path).size
|
37
|
+
@pwd = FileUtils.pwd()
|
38
|
+
@f = File.new("#{@pwd}/temp.rb", "w")
|
39
|
+
end
|
40
|
+
|
41
|
+
def print_help
|
42
|
+
puts 'Welcome to Pikabu!'
|
43
|
+
puts 'pikabu [file.rb] : places a binding.pry if there is an error in your file'
|
44
|
+
puts 'pikabu [file.rb] [line #]: places a binding.pry on the line number you specify'
|
45
|
+
end
|
46
|
+
|
47
|
+
def capture_stdout
|
48
|
+
stdin, stdout, stderr = Open3.popen3("ruby #{@file_path}")
|
49
|
+
@error = stderr.readlines
|
50
|
+
if @error == []
|
51
|
+
puts "\nYou clever chicken! Pikabu detected no errors in your script!"
|
52
|
+
puts "\n"
|
53
|
+
puts " O> "
|
54
|
+
puts " | "
|
55
|
+
puts " >OOOO "
|
56
|
+
puts " ^ ^ "
|
57
|
+
system 'rm temp.rb'
|
58
|
+
return
|
59
|
+
else
|
60
|
+
m = /.rb:(\d+)/.match(@error.first)
|
61
|
+
@line_num = m[1].to_i
|
62
|
+
puts "\nPikabu detected an error on line #{@line_num} of #{@file_path}"
|
63
|
+
end
|
64
|
+
peek
|
65
|
+
end
|
66
|
+
|
67
|
+
def write_head
|
68
|
+
line = 0
|
69
|
+
@file.each do |l|
|
70
|
+
if line < (@line_num-1)
|
71
|
+
@f.write(l)
|
72
|
+
line+=1
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def write_tail
|
78
|
+
line = 0
|
79
|
+
file = File.open(@file_path)
|
80
|
+
file.each do |l|
|
81
|
+
if line >= (@line_num-1)
|
82
|
+
@f << l
|
83
|
+
end
|
84
|
+
line+=1
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def peek
|
89
|
+
@f.write ("require 'pry'\n")
|
90
|
+
write_head
|
91
|
+
@f << "binding.pry\n"
|
92
|
+
write_tail
|
93
|
+
@f.rewind
|
94
|
+
system 'ruby temp.rb; rm temp.rb'
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
data/pikabu.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'pikabu/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "pikabu"
|
8
|
+
spec.version = Pikabu::VERSION
|
9
|
+
spec.authors = ["Dana Najjar, Waruna Perera"]
|
10
|
+
spec.email = ["najjar.dana@gmail.com, wperera6@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Pikabu is a gem that finds your errors for you.}
|
13
|
+
spec.homepage = "https://github.com/dnajjar/pikabu"
|
14
|
+
spec.license = "MIT License"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.executables << 'pikabu'
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
21
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
+
spec.add_development_dependency "pry"
|
23
|
+
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pikabu
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dana Najjar, Waruna Perera
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.9'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- najjar.dana@gmail.com, wperera6@gmail.com
|
58
|
+
executables:
|
59
|
+
- pikabu
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- Gemfile
|
65
|
+
- README.md
|
66
|
+
- bin/console
|
67
|
+
- bin/pikabu
|
68
|
+
- bin/setup
|
69
|
+
- demo.rb
|
70
|
+
- lib/pikabu.rb
|
71
|
+
- lib/pikabu/version.rb
|
72
|
+
- pikabu.gemspec
|
73
|
+
homepage: https://github.com/dnajjar/pikabu
|
74
|
+
licenses:
|
75
|
+
- MIT License
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.4.6
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: Pikabu is a gem that finds your errors for you.
|
97
|
+
test_files: []
|