pry-macro 0.0.0 → 0.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 56a53b4143036617956d9e08fbc8800c0d40f8dd
4
- data.tar.gz: fcb4da6bfc57dcea687dfc71883dbe00e463759d
3
+ metadata.gz: fa23fdc47bd8ace9361a778a65e06445a01d7296
4
+ data.tar.gz: 80e28a0aec12087d7286db13e4f3a6d28191cca0
5
5
  SHA512:
6
- metadata.gz: 28c338a3bf09e12d5c12625dd5c09ff3f39d9ffe4537f305c8b8427772420536675b8ce0d2728f83d76bc01577a48d5a9b8294abcb3e4352dfe782c90dd3c62f
7
- data.tar.gz: 6d68e9477d7484b3868865ef517e65b17273a3b007c063761d551562b183a1a18a3a86afa34505c71c115dd28f9a51d621d7ee4266310d0014c646997cbda766
6
+ metadata.gz: 906c94122071786ca8ec8653e6397b410c4ed3f7c0203f3bc9e3bad406b3ab5d4b01c1a87447af727a1a5f55a4de9171096e7f0cbeddf4f9257da94222efb65c
7
+ data.tar.gz: 1c7c0677a19d4a84841f9fc4400efe31dbc45c3f5382313996a3788bbd20e53ef83ce4d635da6a6c966fa8d04474fce030f13623a484849a2bb1c4b1ff8c36ff
data/README.md CHANGED
@@ -1,6 +1,32 @@
1
- # Pry::Macro
1
+ # PryMacro
2
2
 
3
- TODO: Write a gem description
3
+ Record command line actions for replaying.
4
+
5
+ ## How is this different from play and history?
6
+
7
+ You can dynamically make your own command sets and have them saved for
8
+ later.
9
+
10
+ ## Why?
11
+
12
+ * Cycling next to check a variable or content? Macro it.
13
+ * Repeating yourself for a workflow? Macro it.
14
+ * Auto retry after edits? Macro it.
15
+ * Error? Get the source, the stacktrace, and post it? Macro it.
16
+ * Going to Google that error? Fetch the error message, and Macro it.
17
+ * Someone wrote a bad method? Git blame, irc bot, and Macro it.
18
+ * Clever code? Shoot it to hubot to karma that person, and Macro it.
19
+
20
+ The possibilities here are endless. Make your own command sets as you
21
+ REPL along from what you've already written.
22
+
23
+ ## Auto Pilot
24
+
25
+ Want to "live code" for a presentation? Set it on auto-pilot and let it
26
+ code itself. Define a keystroke to "type" the next command and watch it
27
+ go.
28
+
29
+ Why risk it when you can make it look like you're coding?
4
30
 
5
31
  ## Installation
6
32
 
data/lib/pry-macro.rb ADDED
@@ -0,0 +1,90 @@
1
+ require "pry-macro/version"
2
+ require 'highline/import'
3
+ require 'pry'
4
+
5
+ module PryMacro
6
+ MacroString = Struct.new(:name, :command)
7
+
8
+ Commands = Pry::CommandSet.new do
9
+ create_command 'record', 'Starts a recording session' do
10
+ def process
11
+ # Define a few extra ivars on the current pry session so we can persist some state to use
12
+ unless _pry_.instance_variable_defined?(:@record_stack)
13
+ _pry_.instance_variable_set(:@record_stack, [])
14
+ _pry_.instance_variable_set(:@macro_strings, [])
15
+ _pry_.class.class_eval 'attr_accessor :record_stack, :macro_strings'
16
+ end
17
+
18
+ # By using a stack we can potentially have multiple sessions going. Use at your own peril though...
19
+ _pry_.record_stack << Pry.history.session_line_count
20
+ end
21
+ end
22
+
23
+ create_command 'stop', 'Stops a recording session, and saves a macro' do
24
+ def setup
25
+ if !_pry_.instance_variable_defined?(:@record_stack) && _pry_.record_stack.empty?
26
+ raise 'Cannot stop recording when no recorder is running'
27
+ end
28
+
29
+ session_begin = _pry_.record_stack.pop
30
+ session_end = Pry.history.session_line_count
31
+
32
+ # Get the history between the start and end of the recording session
33
+ @history =
34
+ Pry.history
35
+ .to_a
36
+ .last(session_end - session_begin - 1)
37
+ .reduce(StringIO.new) { |io, item| io.puts(item); io }
38
+
39
+ # Have to have a name to execute this later
40
+ @name = ask('Macro Name: ')
41
+ end
42
+
43
+ def process
44
+ history_lines = @history.string.lines.map { |s| " #{s}"}.join.chomp.tap { |h|
45
+ h.sub!(/^ {6}/,'') # First line won't need the spacing
46
+ }
47
+
48
+ # Save the command into a string, and make it look decent
49
+ # Tinge of a heredocs hack
50
+ command_string = <<-COMMAND_STRING.gsub(/^ {10}/, '')
51
+ Pry::Commands.block_command '#{@name}', 'no description' do
52
+ _pry_.input = StringIO.new(
53
+ <<-MACRO.gsub(/^ {4,6}/, '')
54
+ #{history_lines}
55
+ MACRO
56
+ )
57
+ end
58
+ COMMAND_STRING
59
+
60
+ puts command_string
61
+
62
+ # ...so that we can save the contents for saving later (optional)
63
+ _pry_.macro_strings << MacroString.new(@name, command_string)
64
+ # ...as well as evaluating it and making it immediately usable to us.
65
+ eval command_string
66
+ end
67
+ end
68
+
69
+ create_command 'save_macro', 'Saves a named macro to your .pryrc file on the tail end' do
70
+ def options(opt)
71
+ # Options for later:
72
+ # -p --path : path to save in
73
+ # -n --name : name of the command (override)
74
+ # -d --desc : description of the command
75
+ end
76
+
77
+ def process
78
+ raise 'No Macros are defined!' unless _pry_.instance_variable_defined?(:@macro_strings)
79
+ @macro = _pry_.macro_strings.find(
80
+ -> { raise "Command #{args.first} not found!" } # If nothing is found, raise the error
81
+ ) { |macro| macro.name == args.first }
82
+
83
+ # Append the Pryrc with the macro, leaving blank lines
84
+ File.open(File.join(Dir.home, '.pryrc'), 'a') { |f| f.puts '', @macro.command, '' }
85
+ end
86
+ end
87
+ end
88
+ end
89
+
90
+ Pry.commands.import PryMacro::Commands
@@ -0,0 +1,3 @@
1
+ module PryMacro
2
+ VERSION = "0.0.1"
3
+ end
data/pry-macro.gemspec CHANGED
@@ -1,11 +1,11 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'pry/macro/version'
4
+ require 'pry-macro/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "pry-macro"
8
- spec.version = Pry::Macro::VERSION
8
+ spec.version = PryMacro::VERSION
9
9
  spec.authors = ["Brandon Weaver"]
10
10
  spec.email = ["keystonelemur@gmail.com"]
11
11
  spec.summary = %q{Macros for Pry}
@@ -19,4 +19,8 @@ Gem::Specification.new do |spec|
19
19
 
20
20
  spec.add_development_dependency "bundler", "~> 1.5"
21
21
  spec.add_development_dependency "rake"
22
+
23
+ spec.add_runtime_dependency "pry"
24
+ spec.add_runtime_dependency "pry-plus"
25
+ spec.add_runtime_dependency 'highline'
22
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pry-macro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Weaver
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-28 00:00:00.000000000 Z
11
+ date: 2014-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,48 @@ dependencies:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '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: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-plus
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: highline
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
41
83
  description:
42
84
  email:
43
85
  - keystonelemur@gmail.com
@@ -50,8 +92,8 @@ files:
50
92
  - LICENSE.txt
51
93
  - README.md
52
94
  - Rakefile
53
- - lib/pry/macro.rb
54
- - lib/pry/macro/version.rb
95
+ - lib/pry-macro.rb
96
+ - lib/pry-macro/version.rb
55
97
  - pry-macro.gemspec
56
98
  homepage: ''
57
99
  licenses:
@@ -73,8 +115,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
115
  version: '0'
74
116
  requirements: []
75
117
  rubyforge_project:
76
- rubygems_version: 2.1.10
118
+ rubygems_version: 2.2.1
77
119
  signing_key:
78
120
  specification_version: 4
79
121
  summary: Macros for Pry
80
122
  test_files: []
123
+ has_rdoc:
data/lib/pry/macro.rb DELETED
@@ -1,7 +0,0 @@
1
- require "pry/macro/version"
2
-
3
- module Pry
4
- module Macro
5
- # Your code goes here...
6
- end
7
- end
@@ -1,5 +0,0 @@
1
- module Pry
2
- module Macro
3
- VERSION = "0.0.0"
4
- end
5
- end