pry-buffers 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2011 David Barral
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
data/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # pry-buffers
2
+
3
+ Use buffers to edit and execute arbitrary code inside of pry. You can
4
+ think of this plugin as a vitamined version of the "edit -t" command
5
+ where the edited files are stored and can be reused.
6
+
7
+ # Installation
8
+
9
+ gem install pry-buffers
10
+
11
+ # Usage
12
+
13
+ WARNING: pry-buffers needs a HOME environment variable to be defined in order to
14
+ work properly.
15
+
16
+ pry(main)> buf -h
17
+ Usage: buf [-l|-s|-d|-h] <BUFFER>
18
+ Open a text editor and evaluate its content upon close. When no buffer
19
+ is given, the "default" buffer is used by default. You can also show or
20
+ delete the contents of a given buffer or list all the stored buffers.
21
+ e.g: buf
22
+ buf test
23
+ buf -d test
24
+ buf -s test
25
+ buf -l
26
+ buf -h
27
+
28
+
29
+ options:
30
+
31
+ -s, --show show the contents of the buffer
32
+ -d, --delete clears the given buffer
33
+ -l, --list List all the stored buffers
34
+ -h, --help This message
35
+
36
+ pry(main)> buf
37
+
38
+ pry(main)> buf -l
39
+ Available buffers: default
40
+
41
+ pry(main)> buf test
42
+ This is a test
43
+
44
+ pry(main)> buf -s test
45
+ Buffer test contents:
46
+ puts "This is a test"
47
+
48
+ pry(main)> buf -l
49
+ Available buffers: default, test
50
+
51
+ pry(main)> buf -d test
52
+ Buffer test cleaned
53
+
54
+ # Compatibility
55
+
56
+ pry-buffers been developed and tested against Ruby 1.9.2 and Pry 0.9.6.2.
57
+
58
+ # Contact
59
+
60
+ Please use GitHub (http://github.com/davidbarral/pry-buffers) to report bugs,
61
+ make suggestions or send patches.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,73 @@
1
+ if ENV['HOME'].nil?
2
+ Pry.output.puts 'WARNING: pry-buffers plugin requires the HOME envronment variable to be set. Plugin not active'
3
+ else
4
+
5
+ require 'fileutils'
6
+
7
+ $pry_bufs = File.join ENV['HOME'], '.pry_bufs'
8
+
9
+ FileUtils.mkdir_p $pry_bufs
10
+ FileUtils.touch File.join($pry_bufs, 'default') unless File.exists?(File.join($pry_bufs, 'default'))
11
+
12
+ Pry.config.commands.command "buf", "Use and manage temporary buffers to execute arbitrary code" do |*args|
13
+
14
+ opts = Slop.parse!(args) do |opt|
15
+ opt.banner unindent <<-USAGE
16
+ Usage: buf [-l|-s|-d|-h] <BUFFER>
17
+ Open a text editor and evaluate its content upon close. When no buffer
18
+ is given, the "default" buffer is used by default. You can show or
19
+ delete the contents of a given buffer or list all the stored buffers.
20
+ e.g: buf
21
+ buf test
22
+ buf -d test
23
+ buf -s test
24
+ buf -l
25
+ buf -h
26
+ USAGE
27
+
28
+ opt.on :s, :show, "show the contents of the buffer"
29
+ opt.on :d, :delete, "clears the given buffer"
30
+ opt.on :l, :list, "List all the stored buffers"
31
+ opt.on :h, :help, "This message"
32
+ end
33
+
34
+ if [opts.s?, opts.d?, opts.l?, opts.h?].count(true) > 1
35
+ output.puts "Error: -s,-d,-l and -h options are incompatible"
36
+
37
+ elsif (opts.d? || opts.s?) && args.empty?
38
+ output.puts "Error: -d|-s options need one argument"
39
+
40
+ elsif opts.l? && !args.empty?
41
+ output.puts "Error: -l must be used without arguments"
42
+
43
+ elsif args.length > 1
44
+ output.puts "Error: can only use one buffer at a time"
45
+
46
+ elsif opts.h?
47
+ output.puts opts
48
+
49
+ elsif opts.l?
50
+ output.puts "Available buffers: #{Dir.glob(File.join($pry_bufs, "*")).map {|f| File.basename(f) }.sort.join(", ")}"
51
+
52
+ else
53
+ buffer = args.empty? ? "default" : args[0]
54
+ buffer_path = File.join($pry_bufs, buffer)
55
+
56
+ if opts.d?
57
+ if File.exists?(buffer_path)
58
+ FileUtils.rm_f buffer_path
59
+ FileUtils.touch buffer_path if buffer == "default"
60
+ output.puts "Buffer #{buffer} cleaned"
61
+ else
62
+ output.puts "Buffer #{buffer} does not exists. No need to clean"
63
+ end
64
+ elsif opts.s?
65
+ output.puts "Buffer #{buffer} contents:"
66
+ output.puts stagger_output(colorize_code(File.read(buffer_path)))
67
+ else
68
+ FileUtils.touch buffer_path
69
+ run "edit #{buffer_path} -r"
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,5 @@
1
+ module Pry
2
+ module Buffers
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "pry-buffers/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "pry-buffers"
7
+ s.version = Pry::Buffers::VERSION
8
+ s.authors = ["David Barral"]
9
+ s.email = ["contact@davidbarral.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Use buffers to edit and execute arbitrary code}
12
+ s.description = %q{Use buffers to edit and execute arbitrary code}
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+
19
+ s.add_dependency "pry"
20
+ s.add_dependency "pry-doc"
21
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pry-buffers
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - David Barral
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-10-19 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: pry
16
+ requirement: &7598400 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *7598400
25
+ - !ruby/object:Gem::Dependency
26
+ name: pry-doc
27
+ requirement: &7597920 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *7597920
36
+ description: Use buffers to edit and execute arbitrary code
37
+ email:
38
+ - contact@davidbarral.com
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .gitignore
44
+ - Gemfile
45
+ - LICENSE
46
+ - README.md
47
+ - Rakefile
48
+ - lib/pry-buffers.rb
49
+ - lib/pry-buffers/version.rb
50
+ - pry-buffers.gemspec
51
+ homepage: ''
52
+ licenses: []
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubyforge_project:
71
+ rubygems_version: 1.8.6
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: Use buffers to edit and execute arbitrary code
75
+ test_files: []