depryve 0.1 → 0.2

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
  SHA256:
3
- metadata.gz: 20cf73cc7a27c615cd9f10141604de9e66c79e1b583d7e1e6fde78096e7d9f9f
4
- data.tar.gz: 3bc530649e4de846c792951504c94c910014a17a11dda8a4192bea557f1d57f9
3
+ metadata.gz: f21e64630caad5267e9f9c52b20750012e9620207f2d6f848d4cfd1a7f840dc0
4
+ data.tar.gz: 70737e7e3c61b23e511c0216ca6158d32276ca0fb6cdd626eb21d490e7db41b0
5
5
  SHA512:
6
- metadata.gz: e23fd2d1ea6f7316d8b0350a83dcfb2f80b9ba33756742bc6b675b648fe0e8cccb0de26d715f116abd88aa222f87bccfafbd94f635de5005c0ef3f71ec73cc00
7
- data.tar.gz: dad9bf126cfe3284708e729f18b1d70feb1a50b063d5bf9a23a6a06ba5f5935180a4f2fb4933129a1d01d15c088981c7bfc61360945bf7019e89d474610552e0
6
+ metadata.gz: 0d0fd7db9f89c3254062be9075fb37143c30f04e3e9bc438693e6c1904cfec9ed9f6ed09b1bcc36e6b8ac22185968a1ebf31654a33c44c66269f98b040f0c030
7
+ data.tar.gz: fe4f3103dbead73bffdf64900ac5f3d288075b49742d664711bf36fbf5afaaee4640a17f490387ce06d4d4b5f6feb03c69fe12b7cd941d343cc38339b67620fd
data/.gitignore ADDED
@@ -0,0 +1,28 @@
1
+ *.gem
2
+ /.config
3
+ /coverage/
4
+ /InstalledFiles
5
+ /pkg/
6
+ /spec/reports/
7
+ /spec/examples.txt
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Documentation cache and generated files:
13
+ /.yardoc/
14
+ /_yardoc/
15
+ /doc/
16
+ /rdoc/
17
+
18
+ ## Environment normalization:
19
+ /.bundle/
20
+ /vendor/bundle
21
+ /lib/bundler/man/
22
+ Gemfile.lock
23
+ .ruby-version
24
+ .ruby-gemset
25
+
26
+ # Temp Files
27
+ .ms.tmp/
28
+ *.tmp
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "http://rubygems.org"
2
+ gemspec
data/README.md CHANGED
@@ -9,15 +9,29 @@ Install with RubyGems:
9
9
 
10
10
  gem install depryve
11
11
 
12
- ## Linux Support
12
+ ## X11 Selections
13
13
 
14
- That is to say, right now this only works well with Linux. It uses the X11
15
- primary clipboard (the one that text is copied to when you select it, and
16
- pasted with the middle mouse button). The output is sent to all clipboards.
17
- Support for other clipboards coming if there is demand.
14
+ `depryve` reads your primary selection (the "middle click clipboard") by default;
15
+ this is the "clipboard" that is copied to whenever you highlight text, making
16
+ usage super easy; just highlight, run `depryve`, then paste wherever you
17
+ please. If you would like `depryve` to read from your clipboard selection (the
18
+ "Ctrl+C clipboard"), run `depryve -c`.
18
19
 
19
- ## Contributing
20
+ The output from `depryve` will be placed on all of your clipboards, so you may
21
+ paste it with either Ctrl+V or middle click.
20
22
 
21
- If anyone wants to modify this to make it work better/with more setups, great.
22
- There's only 5 lines of code in here right now. It's MIT licensed, feel free to
23
- fork it. Maybe send a pull request.
23
+ ## From the REPL
24
+
25
+ You may require `depryve` from an `irb` or `pry` session and run it at any time
26
+ by running one of the included methods:
27
+
28
+ ```ruby
29
+ require "depryve"
30
+
31
+ # write your code...
32
+ # whenever you want to copy something highlight it and:
33
+ depryve
34
+
35
+ # or, to run with the -c flag:
36
+ depryve_c
37
+ ```
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler"
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ task dist: :build
5
+ task default: :build
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1
1
+ 0.2
data/bin/depryve CHANGED
@@ -1,9 +1,3 @@
1
1
  #!/usr/bin/env ruby
2
-
3
- require "clipboard"
4
-
5
- START = /\A(irb|\[\d+\] pry)/
6
-
7
- Clipboard.copy(Clipboard.paste(:primary).lines.select { |ln| ln =~ START }.map do |line|
8
- line.gsub(/#{START}[^ ]+ ?/, "")
9
- end.join)
2
+ require "depryve"
3
+ depryve ARGV
data/depryve.gemspec CHANGED
@@ -13,10 +13,14 @@ Gem::Specification.new do |gem|
13
13
 
14
14
  gem.bindir = "bin"
15
15
  gem.executables = %w[depryve]
16
-
16
+ gem.require_paths = %w[lib]
17
+ gem.test_files = Dir["spec/**/*"]
17
18
  gem.files = `git ls-files -z`.split "\x0"
18
19
 
19
- gem.required_ruby_version = ">= 2.7"
20
+ gem.required_ruby_version = ">= 2.0"
20
21
 
21
22
  gem.add_dependency "clipboard", "~> 1.3"
23
+ gem.add_development_dependency "rake", "~> 13.0"
24
+ gem.add_development_dependency "rspec", "~> 3.12"
25
+ gem.add_development_dependency "fuubar", "~> 2.5"
22
26
  end
data/lib/depryve.rb ADDED
@@ -0,0 +1,18 @@
1
+ require "clipboard"
2
+
3
+ def depryve(argv=[])
4
+ # Defined in this scope so that nothing extraneous is created
5
+ # when this gem is required in a REPL session
6
+ prompt = /\A(irb|\[\d+\] pry)/
7
+
8
+ # Use X11 primary selection by default
9
+ selection = argv.include?("-c") ? :clipboard : :primary
10
+
11
+ Clipboard.copy(Clipboard.paste(selection).lines.select { |ln| ln =~ prompt }.map do |line|
12
+ line.gsub(/#{prompt}[^ ]+ ?/, "")
13
+ end.join.strip)
14
+ end
15
+
16
+ def depryve_c
17
+ depryve ["-c"]
18
+ end
@@ -0,0 +1,42 @@
1
+ require "spec_helper"
2
+
3
+ describe "#depryve" do
4
+ %i[irb pry].each do |repl|
5
+ context "when the clipboard contains output from #{repl}" do
6
+ TEST_CASES.each do |title, test|
7
+ it title do
8
+ allow(Clipboard).to receive(:paste).and_return test[repl]
9
+ expect(Clipboard).to receive(:copy).with test[:result]
10
+ depryve
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+
17
+ describe "#depryve_c" do
18
+ it "calls #depryve as if running `depryve -c`" do
19
+ expect_any_instance_of(Object).to receive(:depryve).with ["-c"]
20
+ depryve_c
21
+ end
22
+ end
23
+
24
+ describe "the executable" do
25
+ before(:each) do
26
+ allow(Clipboard).to receive :copy
27
+ end
28
+
29
+ context "when passed no args" do
30
+ it "uses the X11 primary selection" do
31
+ expect(Clipboard).to receive(:paste).with(:primary)
32
+ depryve rescue nil
33
+ end
34
+ end
35
+
36
+ context "when passed a -c flag" do
37
+ it "uses the X11 clipboard selection" do
38
+ expect(Clipboard).to receive(:paste).with(:clipboard)
39
+ depryve ["-c"] rescue nil
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,26 @@
1
+ require "depryve"
2
+ require "test_cases"
3
+
4
+ RSpec.configure do |config|
5
+ # Add `focus: true` hash parameter to a describe/context/it block
6
+ # to only run the specs in that block
7
+ config.filter_run_when_matching :focus
8
+
9
+ # Fuubar
10
+ config.add_formatter "Fuubar"
11
+ config.fuubar_progress_bar_options = { format: " %c/%C |%b>%i|%e " }
12
+
13
+ # More verbose output if only running one spec
14
+ config.default_formatter = "doc" if config.files_to_run.one?
15
+
16
+ # Print the 10 slowest examples and example groups at the
17
+ # end of the spec run, to help surface which specs are running
18
+ # particularly slow.
19
+ config.profile_examples = 10
20
+
21
+ # Run specs in random order to surface order dependencies. If you find an
22
+ # order dependency and want to debug it, fix the order by providing the seed,
23
+ # which is printed after each run, e.g. --seed 1234
24
+ config.order = :random
25
+ Kernel.srand config.seed
26
+ end
@@ -0,0 +1,141 @@
1
+ TEST_CASES = {
2
+ "removes return values": {
3
+ irb: <<~EOS.chop,
4
+ irb(main):003:0> 1 + 1
5
+ => 2
6
+ EOS
7
+ pry: <<~EOS.chop,
8
+ [1] pry(main)> 1 + 1
9
+ => 2
10
+ EOS
11
+ result: <<~EOS.chop
12
+ 1 + 1
13
+ EOS
14
+ },
15
+
16
+ "removes STDOUT output": {
17
+ irb: <<~EOS.chop,
18
+ irb(main):024:0> puts "Hello world!"
19
+ Hello world!
20
+ => nil
21
+ EOS
22
+ pry: <<~EOS.chop,
23
+ [2] pry(main)> puts "Hello world!"
24
+ Hello world!
25
+ => nil
26
+ EOS
27
+ result: <<~EOS.chop
28
+ puts "Hello world!"
29
+ EOS
30
+ },
31
+
32
+ "removes error messages": {
33
+ irb: <<~EOS.chop,
34
+ irb(main):028:0> "foo"
35
+ => "foo"
36
+ irb(main):029:0> wtf
37
+ (irb):29:in `<main>': undefined local variable or method `wtf' for main:Object (NameError)
38
+ from /path/to/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/irb-1.6.4/exe/irb:9:in `<top (required)>'
39
+ from /path/to/.rbenv/versions/3.2.1/bin/irb:25:in `load'
40
+ from /path/to/.rbenv/versions/3.2.1/bin/irb:25:in `<main>'
41
+ irb(main):030:0> "bar"
42
+ => "bar"
43
+ EOS
44
+ pry: <<~EOS.chop,
45
+ [9] pry(main)> "foo"
46
+ => "foo"
47
+ [10] pry(main)> wtf
48
+ Exception: NameError: undefined local variable or method `wtf' for main:Object
49
+ --
50
+ 0: (pry):6:in `__pry__'
51
+ 1: /path/to/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/pry-0.14.2/lib/pry/pry_instance.rb:290:in `eval'
52
+ 2: /path/to/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/pry-0.14.2/lib/pry/pry_instance.rb:290:in `evaluate_ruby'
53
+ 3: /path/to/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/pry-0.14.2/lib/pry/pry_instance.rb:659:in `handle_line'
54
+ 4: /path/to/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/pry-0.14.2/lib/pry/pry_instance.rb:261:in `block (2 levels) in eval'
55
+ [11] pry(main)> "bar"
56
+ => "bar"
57
+ EOS
58
+ result: <<~EOS.chop
59
+ "foo"
60
+ wtf
61
+ "bar"
62
+ EOS
63
+ },
64
+
65
+ "doesn't get tripped up by the > operator": {
66
+ irb: <<~EOS.chop,
67
+ irb(main):031:0> 3 > 2 ? "foo" : "bar"
68
+ => "foo"
69
+ EOS
70
+ pry: <<~EOS.chop,
71
+ [12] pry(main)> 3 > 2 ? "foo" : "bar"
72
+ => "foo"
73
+ EOS
74
+ result: <<~EOS.chop
75
+ 3 > 2 ? "foo" : "bar"
76
+ EOS
77
+ },
78
+
79
+ "removes blank lines": {
80
+ irb: <<~EOS.chop,
81
+ irb(main):037:0>
82
+ irb(main):038:0>
83
+ irb(main):039:0> "foo"
84
+ => "foo"
85
+ irb(main):040:0>
86
+ irb(main):041:0>
87
+ irb(main):042:0> "bar"
88
+ => "bar"
89
+ irb(main):043:0>
90
+ irb(main):044:0>
91
+ EOS
92
+ pry: <<~EOS.chop,
93
+ [16] pry(main)>
94
+ [17] pry(main)>
95
+ [18] pry(main)> "foo"
96
+ => "foo"
97
+ [19] pry(main)>
98
+ [20] pry(main)>
99
+ [21] pry(main)> "bar"
100
+ => "bar"
101
+ [22] pry(main)>
102
+ [23] pry(main)>
103
+ EOS
104
+ result: <<~EOS.chop
105
+ "foo"
106
+ "bar"
107
+ EOS
108
+ },
109
+
110
+ "handles indentation correctly": {
111
+ irb: <<~EOS.chop,
112
+ irb(main):044:1* def foo(n)
113
+ irb(main):045:2* if n < 3
114
+ irb(main):046:2* puts "bar"
115
+ irb(main):047:2* else
116
+ irb(main):048:2* puts "baz"
117
+ irb(main):050:1* end
118
+ irb(main):051:0> end
119
+ => :foo
120
+ EOS
121
+ pry: <<~EOS.chop,
122
+ [26] pry(main)> def foo(n)
123
+ [26] pry(main)* if n < 3
124
+ [26] pry(main)* puts "bar"
125
+ [26] pry(main)* else
126
+ [26] pry(main)* puts "baz"
127
+ [26] pry(main)* end
128
+ [26] pry(main)* end
129
+ => :foo
130
+ EOS
131
+ result: <<~EOS.chop
132
+ def foo(n)
133
+ if n < 3
134
+ puts "bar"
135
+ else
136
+ puts "baz"
137
+ end
138
+ end
139
+ EOS
140
+ }
141
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: depryve
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vinny Diehl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-15 00:00:00.000000000 Z
11
+ date: 2023-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clipboard
@@ -24,6 +24,48 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '13.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '13.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: '3.12'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.12'
55
+ - !ruby/object:Gem::Dependency
56
+ name: fuubar
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.5'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.5'
27
69
  description: Hassle-free copy/pasting of Ruby console output.
28
70
  email: vinny.diehl@gmail.com
29
71
  executables:
@@ -31,11 +73,18 @@ executables:
31
73
  extensions: []
32
74
  extra_rdoc_files: []
33
75
  files:
76
+ - ".gitignore"
77
+ - Gemfile
34
78
  - LICENSE.md
35
79
  - README.md
80
+ - Rakefile
36
81
  - VERSION
37
82
  - bin/depryve
38
83
  - depryve.gemspec
84
+ - lib/depryve.rb
85
+ - spec/depryve_spec.rb
86
+ - spec/spec_helper.rb
87
+ - spec/test_cases.rb
39
88
  homepage: https://github.com/vinnydiehl/depryve
40
89
  licenses:
41
90
  - MIT
@@ -48,15 +97,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
48
97
  requirements:
49
98
  - - ">="
50
99
  - !ruby/object:Gem::Version
51
- version: '2.7'
100
+ version: '2.0'
52
101
  required_rubygems_version: !ruby/object:Gem::Requirement
53
102
  requirements:
54
103
  - - ">="
55
104
  - !ruby/object:Gem::Version
56
105
  version: '0'
57
106
  requirements: []
58
- rubygems_version: 3.4.8
107
+ rubygems_version: 3.4.10
59
108
  signing_key:
60
109
  specification_version: 4
61
110
  summary: Remove the IRB/Pry prompt and output when copying code
62
- test_files: []
111
+ test_files:
112
+ - spec/depryve_spec.rb
113
+ - spec/spec_helper.rb
114
+ - spec/test_cases.rb