pry-macro 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fa23fdc47bd8ace9361a778a65e06445a01d7296
4
- data.tar.gz: 80e28a0aec12087d7286db13e4f3a6d28191cca0
3
+ metadata.gz: 177ddefdcbd1a0559fb3a4c515100cc9efd693ca
4
+ data.tar.gz: eaa0cf476554da956516491d56529022f06430ff
5
5
  SHA512:
6
- metadata.gz: 906c94122071786ca8ec8653e6397b410c4ed3f7c0203f3bc9e3bad406b3ab5d4b01c1a87447af727a1a5f55a4de9171096e7f0cbeddf4f9257da94222efb65c
7
- data.tar.gz: 1c7c0677a19d4a84841f9fc4400efe31dbc45c3f5382313996a3788bbd20e53ef83ce4d635da6a6c966fa8d04474fce030f13623a484849a2bb1c4b1ff8c36ff
6
+ metadata.gz: 071baa80cd6584b7b346038ec4fde4edbcfa2487e0325d9f09128d396cf7a76f6e156d7a1f95098f7f6b3cc9717931338adb1d8cc3107ea51904580119b796f8
7
+ data.tar.gz: 36e363f4bd719d7db88673a6f3281f3a48abba35e25fb4ca80a44aa3a9f130c5b4ceaf366689556023c31b2cf9f12fc02783e180300c0b297ed0ea68e7f33b6f
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
@@ -0,0 +1 @@
1
+ language: ruby
@@ -0,0 +1,24 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :rspec do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+
9
+ # Rails example
10
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11
+ watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
13
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
14
+ watch('config/routes.rb') { "spec/routing" }
15
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
16
+
17
+ # Capybara features specs
18
+ watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
19
+
20
+ # Turnip features and steps
21
+ watch(%r{^spec/acceptance/(.+)\.feature$})
22
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
23
+ end
24
+
data/README.md CHANGED
@@ -5,7 +5,63 @@ Record command line actions for replaying.
5
5
  ## How is this different from play and history?
6
6
 
7
7
  You can dynamically make your own command sets and have them saved for
8
- later.
8
+ later, as well as use pry commands.
9
+
10
+ ## Basic Usage
11
+
12
+ Start recording:
13
+
14
+ ```ruby
15
+ [1] pry(main)> record
16
+ [2] pry(main)> 1
17
+ => 1
18
+ [3] pry(main)> 'foo'
19
+ => "foo"
20
+ [4] pry(main)> ls
21
+ self.methods: inspect to_s
22
+ locals: _ __ _dir_ _ex_ _file_ _in_ _out_ _pry_
23
+ ```
24
+
25
+ Stop the recording and name it:
26
+
27
+ ```ruby
28
+ [5] pry(main)> stop
29
+ Macro Name: testing
30
+ ```
31
+
32
+ Run it like any other command:
33
+
34
+ ```ruby
35
+ [6] pry(main)> testing
36
+ => 1
37
+ => "foo"
38
+ self.methods: inspect to_s
39
+ locals: _ __ _dir_ _ex_ _file_ _in_ _out_ _pry_
40
+ ```
41
+
42
+ Like it? You can save it and have it automatically append to your PryRC:
43
+
44
+ ```ruby
45
+ [10] pry(main)> save-macro testing
46
+ ```
47
+
48
+ ...and here it is, nice and formatted:
49
+
50
+ ```ruby
51
+ Pry::Commands.block_command 'testing', 'no description' do
52
+ _pry_.input = StringIO.new(
53
+ <<-MACRO.gsub(/^ {4,6}/, '')
54
+ 1
55
+ 'foo'
56
+ ls
57
+ MACRO
58
+ )
59
+ end
60
+ ```
61
+
62
+ ## More Advanced Usage
63
+
64
+ We're working on getting the Wiki up to date to cover more advanced usage.
9
65
 
10
66
  ## Why?
11
67
 
@@ -20,13 +76,9 @@ later.
20
76
  The possibilities here are endless. Make your own command sets as you
21
77
  REPL along from what you've already written.
22
78
 
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.
79
+ ## To do
28
80
 
29
- Why risk it when you can make it look like you're coding?
81
+ Next step is finding out how to properly test Pry and getting RSPEC written up for this.
30
82
 
31
83
  ## Installation
32
84
 
@@ -42,13 +94,10 @@ Or install it yourself as:
42
94
 
43
95
  $ gem install pry-macro
44
96
 
45
- ## Usage
46
-
47
- TODO: Write usage instructions here
48
97
 
49
98
  ## Contributing
50
99
 
51
- 1. Fork it ( http://github.com/<my-github-username>/pry-macro/fork )
100
+ 1. Fork it ( http://github.com/baweaver/pry-macro/fork )
52
101
  2. Create your feature branch (`git checkout -b my-new-feature`)
53
102
  3. Commit your changes (`git commit -am 'Add some feature'`)
54
103
  4. Push to the branch (`git push origin my-new-feature`)
data/Rakefile CHANGED
@@ -1 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -7,6 +7,12 @@ module PryMacro
7
7
 
8
8
  Commands = Pry::CommandSet.new do
9
9
  create_command 'record', 'Starts a recording session' do
10
+ banner <<-BANNER
11
+ Usage: record
12
+
13
+ Starts recording a macro.
14
+ BANNER
15
+
10
16
  def process
11
17
  # Define a few extra ivars on the current pry session so we can persist some state to use
12
18
  unless _pry_.instance_variable_defined?(:@record_stack)
@@ -21,6 +27,14 @@ module PryMacro
21
27
  end
22
28
 
23
29
  create_command 'stop', 'Stops a recording session, and saves a macro' do
30
+ banner <<-BANNER
31
+ Usage: stop [-n name] [-d desc]
32
+
33
+ Stops recording a macro, loads the command, and caches it for later saving if
34
+ desired. If no name is provided, user will be prompted for one. Descriptions
35
+ may be provided, but will default to 'no description'
36
+ BANNER
37
+
24
38
  def setup
25
39
  if !_pry_.instance_variable_defined?(:@record_stack) && _pry_.record_stack.empty?
26
40
  raise 'Cannot stop recording when no recorder is running'
@@ -35,12 +49,21 @@ module PryMacro
35
49
  .to_a
36
50
  .last(session_end - session_begin - 1)
37
51
  .reduce(StringIO.new) { |io, item| io.puts(item); io }
52
+ end
38
53
 
39
- # Have to have a name to execute this later
40
- @name = ask('Macro Name: ')
54
+ def options(opts)
55
+ opts.on :n, :name, "Name to use to define the macro",
56
+ optional_argument: true, as: String
57
+ opts.on :d, :desc, "Description of the macro",
58
+ optional_argument: true, as: String
59
+ opts.on :v, :verbose, "Echoes back the macro definition"
41
60
  end
42
61
 
43
62
  def process
63
+ # Have to have a name to execute this later
64
+ name = opts[:n] || ask('Macro Name: ')
65
+ desc = opts[:d] || 'no description'
66
+
44
67
  history_lines = @history.string.lines.map { |s| " #{s}"}.join.chomp.tap { |h|
45
68
  h.sub!(/^ {6}/,'') # First line won't need the spacing
46
69
  }
@@ -48,7 +71,7 @@ module PryMacro
48
71
  # Save the command into a string, and make it look decent
49
72
  # Tinge of a heredocs hack
50
73
  command_string = <<-COMMAND_STRING.gsub(/^ {10}/, '')
51
- Pry::Commands.block_command '#{@name}', 'no description' do
74
+ Pry::Commands.block_command '#{name}', '#{desc}' do
52
75
  _pry_.input = StringIO.new(
53
76
  <<-MACRO.gsub(/^ {4,6}/, '')
54
77
  #{history_lines}
@@ -57,7 +80,7 @@ module PryMacro
57
80
  end
58
81
  COMMAND_STRING
59
82
 
60
- puts command_string
83
+ puts command_string if opts[:v]
61
84
 
62
85
  # ...so that we can save the contents for saving later (optional)
63
86
  _pry_.macro_strings << MacroString.new(@name, command_string)
@@ -66,22 +89,31 @@ module PryMacro
66
89
  end
67
90
  end
68
91
 
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
92
+ create_command 'save-macro', 'Saves a named macro to your .pryrc file on the tail end' do
93
+ banner <<-BANNER
94
+ Usage: save-macro [-p path]
95
+
96
+ Saves a cached macro to your ~/.pryrc or the path specified.
97
+ BANNER
98
+
99
+ def options(opts)
100
+ opts.on :p, :path, "Pathname to save macro in",
101
+ optional_argument: true, as: String
75
102
  end
76
103
 
77
104
  def process
78
105
  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 }
106
+ raise 'Invalid path!' if opts[:p] && !Dir[opts[:p]]
107
+ raise 'Must specify the macro to save!' if args.empty?
108
+
109
+ path = opts[:p] || Dir.home
110
+ macro = _pry_.macro_strings.find(
111
+ # If nothing is found, raise the error
112
+ -> { raise "Command #{args.first} not found!" }
113
+ ) { |m| m.name == args.first }
82
114
 
83
115
  # Append the Pryrc with the macro, leaving blank lines
84
- File.open(File.join(Dir.home, '.pryrc'), 'a') { |f| f.puts '', @macro.command, '' }
116
+ File.open(File.join(path, '.pryrc'), 'a') { |f| f.puts '', macro.command, '' }
85
117
  end
86
118
  end
87
119
  end
@@ -1,3 +1,3 @@
1
1
  module PryMacro
2
- VERSION = "0.0.1"
2
+ VERSION = '0.0.2'
3
3
  end
@@ -9,7 +9,8 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Brandon Weaver"]
10
10
  spec.email = ["keystonelemur@gmail.com"]
11
11
  spec.summary = %q{Macros for Pry}
12
- spec.homepage = ""
12
+ spec.description = %q{Macro Recording and Saving functionality for pry}
13
+ spec.homepage = "https://github.com/baweaver/pry-macro"
13
14
  spec.license = "MIT"
14
15
 
15
16
  spec.files = `git ls-files -z`.split("\x0")
@@ -19,6 +20,9 @@ Gem::Specification.new do |spec|
19
20
 
20
21
  spec.add_development_dependency "bundler", "~> 1.5"
21
22
  spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "guard"
25
+ spec.add_development_dependency "guard-rspec"
22
26
 
23
27
  spec.add_runtime_dependency "pry"
24
28
  spec.add_runtime_dependency "pry-plus"
@@ -0,0 +1,82 @@
1
+ # require 'spec_helper'
2
+
3
+ # Need to find a more effective way to spec this all out. There are some nuances I haven't quite
4
+ # grasped in mocking out pry commands. As soon as I can figure out the last few bits this will
5
+ # get built on Travis and put under a bit more process.
6
+
7
+ # describe 'PryMacro' do
8
+ # before :all do
9
+ # @str_output = StringIO.new
10
+
11
+ # @t = pry_tester do
12
+ # def insert_nil_input
13
+ # @pry.update_input_history(nil)
14
+ # end
15
+
16
+ # def last_exception=(e)
17
+ # @pry.last_exception = e
18
+ # end
19
+ # end
20
+
21
+ # _pry_.stub(
22
+ # input: @t.pry.input
23
+ # )
24
+
25
+ # @t.eval 'record'
26
+ # @t.pry.input = StringIO.new('1')
27
+ # binding.pry
28
+ # @t.eval 'stop -n test_macro'
29
+ # end
30
+
31
+ # describe '#record' do
32
+ # it 'sets instance variables on @t.pry' do
33
+ # expect(@t.pry.instance_variable_defined?(:@record_stack)).to be_true
34
+ # expect(@t.pry.instance_variable_defined?(:@macro_strings)).to be_true
35
+ # end
36
+ # end
37
+
38
+ # describe '#stop' do
39
+ # context 'Record stack is empty' do
40
+ # before { @t.pry.stub(record_stack: []) }
41
+
42
+ # it 'raises an error' do
43
+ # expect { @t.eval 'stop' }.to raise_error()
44
+ # end
45
+ # end
46
+
47
+ # context 'Record stack present' do
48
+ # it 'pops the start from the record stack' do
49
+ # expect(@t.pry.record_stack.empty?).to be_true
50
+ # end
51
+
52
+ # it 'creates a the macro' do
53
+ # expect(@t.eval 'test_macro').to be(1)
54
+ # end
55
+
56
+ # it 'caches the macro in @macro_strings' do
57
+ # expect(@t.pry.macro_strings.first.name).to be ('test_macro')
58
+ # end
59
+ # end
60
+ # end
61
+
62
+ # describe '#save-macro' do
63
+ # context 'No Macros are defined' do
64
+ # before { @t.pry.stub(macro_strings: [])}
65
+
66
+ # it 'raises an error' do
67
+ # expect { @t.eval 'save' }.to raise_error()
68
+ # end
69
+ # end
70
+
71
+ # context 'Macros are defined' do
72
+ # it 'saves the macro to .pryrc' do
73
+ # fake_file = StringIO.new
74
+ # File.stub(puts: fake_file)
75
+
76
+ # @t.eval 'save'
77
+
78
+ # expect(fake_file.string).to_not be_empty
79
+ # end
80
+ # end
81
+ # end
82
+ # end
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'pry/test/helper'
4
+ require 'pry-macro'
5
+
6
+ RSpec.configure do |config|
7
+ # some (optional) config here
8
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pry-macro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Weaver
@@ -38,6 +38,48 @@ dependencies:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
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
+ - !ruby/object:Gem::Dependency
56
+ name: guard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
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: guard-rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
41
83
  - !ruby/object:Gem::Dependency
42
84
  name: pry
43
85
  requirement: !ruby/object:Gem::Requirement
@@ -80,7 +122,7 @@ dependencies:
80
122
  - - '>='
81
123
  - !ruby/object:Gem::Version
82
124
  version: '0'
83
- description:
125
+ description: Macro Recording and Saving functionality for pry
84
126
  email:
85
127
  - keystonelemur@gmail.com
86
128
  executables: []
@@ -88,14 +130,19 @@ extensions: []
88
130
  extra_rdoc_files: []
89
131
  files:
90
132
  - .gitignore
133
+ - .rspec
134
+ - .travis.yml
91
135
  - Gemfile
136
+ - Guardfile
92
137
  - LICENSE.txt
93
138
  - README.md
94
139
  - Rakefile
95
140
  - lib/pry-macro.rb
96
141
  - lib/pry-macro/version.rb
97
142
  - pry-macro.gemspec
98
- homepage: ''
143
+ - spec/pry-macro_spec.rb
144
+ - spec/spec_helper.rb
145
+ homepage: https://github.com/baweaver/pry-macro
99
146
  licenses:
100
147
  - MIT
101
148
  metadata: {}
@@ -119,5 +166,7 @@ rubygems_version: 2.2.1
119
166
  signing_key:
120
167
  specification_version: 4
121
168
  summary: Macros for Pry
122
- test_files: []
169
+ test_files:
170
+ - spec/pry-macro_spec.rb
171
+ - spec/spec_helper.rb
123
172
  has_rdoc: