Skip to content

Commit

Permalink
Initial import
Browse files Browse the repository at this point in the history
  • Loading branch information
awwaiid committed Aug 5, 2014
0 parents commit 16aa586
Show file tree
Hide file tree
Showing 13 changed files with 228 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.gem
Gemfile.lock
.rbx
.yardoc
doc
tags
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
language: ruby
cache: bundler
rvm:
- 1.9.3
- 2.0.0
- 2.1.0
- rbx
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
source 'https://rubygems.org'
gemspec
19 changes: 19 additions & 0 deletions LICENSE.MIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2012 Conrad Irwin <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# pry-timetravel

DOES NOT WORK. DO NOT USE.

Time travel! For your REPL!

> x = 5
5
> checkpoint
> x = 10
10
> timetravel
> x
5

This is an attempt to package the proof of concept. API WILL CHANGE!

## Meta

Released under the MIT license, see LICENSE.MIT for details. Contributions and bug-reports
are welcome.
14 changes: 14 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'rspec/core/rake_task'

task :default => :test
task :spec => :test

RSpec::Core::RakeTask.new(:test)

task :build do
sh 'gem build *.gemspec'
end

task :install => :build do
sh 'gem install *.gem'
end
60 changes: 60 additions & 0 deletions lib/pry-timetravel.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
require 'rubygems'
require 'pry'

require File.expand_path('../pry-timetravel/commands', __FILE__)

class PryTimetravel
class << self

def dlog(msg)
File.open("meta.log", 'a') do |file|
file.puts(msg)
end
end

def checkpoint
parent_pid = $$
child_pid = fork
if child_pid
dlog("PARENT #{parent_pid}: I have a child pid #{child_pid}")

@previous_pid ||= []
@previous_pid.push child_pid

# The parent universe freezes
# dlog("PARENT #{$$}: I am suspending. My child is #{parent_pid}")
# dlog("PARENT #{$$}: suspending")
# Process.setpgrp
# Process.setsid
# dlog("PARENT #{$$}: resumed!")
else
child_pid = $$

dlog("CHILD: #{child_pid}: I have a parent pid #{parent_pid}")

Process.kill 'SIGSTOP', child_pid

dlog("CHILD #{child_pid}: resumed!")
end
end

def go_back
dlog("ME #{$$}: Thinking about time travel...");
dlog("ME #{$$}: previous_pid = #{ @previous_pid }");
if @previous_pid && ! @previous_pid.empty?
previous_pid = @previous_pid.pop

dlog("ME #{$$}: I found a previous pid #{previous_pid}! TIME TRAVEL TIME")
Process.kill 'SIGCONT', previous_pid
dlog("ME #{$$}: I resumed pid #{previous_pid}... now time to wait")
# Process.waitpid(previous_pid)
Process.waitall
dlog("ME #{$$}: If you meet your previous self, kill yourself.")
# Process.kill 'SIGKILL', $$
Kernel.exit!
end
dlog("ME #{$$}: I was unable to time travel. Maybe it is a myth.");
end
end
end

49 changes: 49 additions & 0 deletions lib/pry-timetravel/commands.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

Pry::Commands.create_command "checkpoint", "Set a marker in the timeline" do
match 'checkpoint'
group 'Timetravel'
# description 'Snapshot the world so we can timetravel back here later'
banner <<-'BANNER'
Usage: checkpoint
checkpoint --list
checkpoint --delete [INDEX]
This will add a checkpoint which you can return to later.
BANNER

# def options(opt)
# opt.on :d, :delete,
# "Delete the checkpoint with the given index. If no index is given delete them all",
# :optional_argument => true, :as => Integer
# opt.on :l, :list,
# "Show all checkpoints"
# end
def process
PryTimetravel.checkpoint
end
end

Pry::Commands.create_command "timetravel", "Set a marker in the timeline" do
match 'timetravel'
group 'Timetravel'
# description 'Snapshot the world so we can timetravel back here later'
banner <<-'BANNER'
Usage: checkpoint
checkpoint --list
checkpoint --delete [INDEX]
This will add a checkpoint which you can return to later.
BANNER

# def options(opt)
# opt.on :d, :delete,
# "Delete the checkpoint with the given index. If no index is given delete them all",
# :optional_argument => true, :as => Integer
# opt.on :l, :list,
# "Show all checkpoints"
# end
def process
PryTimetravel.go_back
end
end

2 changes: 2 additions & 0 deletions lib/pry/timetravel.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#Bundler shenanigans
require 'pry-timetravel'
12 changes: 12 additions & 0 deletions meta.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CHILD: 21499: I have a parent pid 21493
PARENT 21493: I have a child pid 21499
ME 21493: Thinking about time travel...
ME 21493: previous_pid = [21499]
ME 21493: I found a previous pid 21499! TIME TRAVEL TIME
ME 21493: I resumed pid 21499... now time to wait
PARENT 21534: I have a child pid 21551
CHILD: 21551: I have a parent pid 21534
ME 21534: Thinking about time travel...
ME 21534: previous_pid = [21551]
ME 21534: I found a previous pid 21551! TIME TRAVEL TIME
ME 21534: I resumed pid 21551... now time to wait
19 changes: 19 additions & 0 deletions pry-timetravel.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Gem::Specification.new do |s|
s.name = 'pry-timetravel'
s.version = '0.0.1'
s.summary = 'Timetravel'
s.description = 'Allows you to timetravel!'
s.homepage = 'https://github.com/awwaiid/pry-timetravel'
s.email = ['[email protected]']
s.authors = ['Brock Wilcox']
s.files = `git ls-files`.split("\n")
s.require_paths = ['lib']

s.add_dependency 'pry'

s.add_development_dependency 'rake'
# s.add_development_dependency 'rspec'
# s.add_development_dependency 'yard'
# s.add_development_dependency 'redcarpet'
# s.add_development_dependency 'capybara'
end
11 changes: 11 additions & 0 deletions spec/commands_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require './spec/spec_helper'

describe "pry-timetravel commands" do
describe "checkpoint" do
it "forks a child"
end
describe "timetravel" do
it "reinvokes the saved checkpoint and kills itself"
end
end

6 changes: 6 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require 'rspec'
require 'rspec/autorun'

require 'pry/test/helper'

require './lib/pry-timetravel'

0 comments on commit 16aa586

Please sign in to comment.