pbcopy 1.0.0

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.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pbcopy.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Josh Cheek
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,66 @@
1
+ # Pbcopy
2
+
3
+ Enables piping and redirecting into pbcopy from within Ruby.
4
+
5
+ Mac OS X only.
6
+
7
+ This lib is intended as a development aid, not a production utility.
8
+
9
+ Note that this adds `String#|`
10
+
11
+
12
+ ## Pipe strings into pbcopy
13
+
14
+ On the command line you might do
15
+
16
+ $ which ruby | pbcopy
17
+
18
+ Which would copy the location of the ruby binary into your system's paste board. Later you could retrieve it with Command-V.
19
+
20
+ In Ruby you can pipe any string into pbcopy to achieve the same result
21
+
22
+ RUBY_VERSION | pbcopy
23
+ User.last.login | pbcopy
24
+
25
+
26
+ ## Redirect arbitrary objects into pbcopy
27
+
28
+ On the command line you might do
29
+
30
+ $ pbcopy < some_file
31
+
32
+ In Ruby you can do
33
+
34
+ pbcopy < 123
35
+ pbcopy < [4, 5, 6]
36
+
37
+ You can redirect any arbitrary object into pbcopy, it will be turned into a string and placed in the system clipboard
38
+
39
+
40
+ ## Shorter more Ruby-like version of redirect
41
+
42
+ You can omit the chevron when redirecting into pbcopy
43
+
44
+ pbcopy 123
45
+ pbcopy [4, 5, 6]
46
+
47
+
48
+ ## Make available in irb / pry
49
+
50
+ $ echo 'require "pbcopy"' >> ~/.irbrc
51
+ $ echo 'require "pbcopy"' >> ~/.pryrc
52
+
53
+
54
+ ## Installation
55
+
56
+ Add this line to your application's Gemfile:
57
+
58
+ gem 'pbcopy'
59
+
60
+ And then execute:
61
+
62
+ $ bundle
63
+
64
+ Or install it yourself as:
65
+
66
+ $ gem install pbcopy
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,25 @@
1
+ require "pbcopy/version"
2
+ require 'pasteboard'
3
+
4
+
5
+ module Pbcopy
6
+ Pasteboard = ::Pasteboard.new
7
+
8
+ def Pasteboard.<(other)
9
+ other.to_s | self
10
+ end
11
+ end
12
+
13
+
14
+ class String
15
+ def |(pbcopy)
16
+ pbcopy.put [[Pasteboard::Type::UTF_8, self]]
17
+ self
18
+ end
19
+ end
20
+
21
+
22
+ def pbcopy(obj = (no_obj=true))
23
+ return Pbcopy::Pasteboard if no_obj
24
+ pbcopy < obj
25
+ end
@@ -0,0 +1,3 @@
1
+ module Pbcopy
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,18 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/pbcopy/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Josh Cheek"]
6
+ gem.email = ["josh.cheek@gmail.com"]
7
+ gem.description = %q{Replicates OSX commandline utility where piping into pbcopy places things into the clipboard}
8
+ gem.summary = %q{Use pbcopy in Ruby in the same way you would from the terminal}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "pbcopy"
15
+ gem.require_paths = ["lib"]
16
+ gem.add_development_dependency 'pasteboard', '~> 1.0'
17
+ gem.version = Pbcopy::VERSION
18
+ end
@@ -0,0 +1,62 @@
1
+ require 'pbcopy'
2
+
3
+ describe 'pbcopy' do
4
+
5
+ # stolen from pasteboard's tests
6
+ def assert_put *expecteds
7
+ pb = Pasteboard.new
8
+ expecteds.length.should == pb.get_item_count
9
+
10
+ expecteds.each do |expected|
11
+ expected.each_with_index do |(flavor, data), index|
12
+ flavor.should == pb.copy_item_flavors(0)[index]
13
+ data.should == pb.first(flavor)
14
+ end
15
+ end
16
+ end
17
+
18
+ it 'is available everywhere, but not visible in method lists' do
19
+ expect { Object.new.pbcopy }.to raise_error NoMethodError
20
+ expect { Object.new.instance_eval { pbcopy } }.to_not raise_error
21
+ end
22
+
23
+
24
+ describe 'piping a string into pbcopy' do
25
+ specify 'they end up in system clipboard' do
26
+ "hello world" | pbcopy
27
+ assert_put [[Pasteboard::Type::UTF_8, "hello world"]]
28
+ end
29
+
30
+ specify 'the string is returned' do
31
+ ("hello world" | pbcopy).should == "hello world"
32
+ end
33
+ end
34
+
35
+
36
+ describe 'redirecting an object into pbcopy' do
37
+ specify 'is the same as `obj.to_s | pbcopy`' do
38
+ (pbcopy < "hello world").should == "hello world"
39
+ assert_put [[Pasteboard::Type::UTF_8, "hello world"]]
40
+
41
+ (pbcopy < 123).should == "123"
42
+ assert_put [[Pasteboard::Type::UTF_8, "123"]]
43
+ end
44
+ end
45
+
46
+
47
+ describe 'treating it like a method' do
48
+ specify 'pass any object to pbcopy as an alternative to pbcopy < obj' do
49
+ (pbcopy "hello world").should == "hello world"
50
+ assert_put [[Pasteboard::Type::UTF_8, "hello world"]]
51
+
52
+ (pbcopy 123).should == "123"
53
+ assert_put [[Pasteboard::Type::UTF_8, "123"]]
54
+
55
+ (pbcopy false).should == "false"
56
+ assert_put [[Pasteboard::Type::UTF_8, "false"]]
57
+
58
+ (pbcopy nil).should == ""
59
+ assert_put [[Pasteboard::Type::UTF_8, ""]]
60
+ end
61
+ end
62
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pbcopy
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Josh Cheek
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: pasteboard
16
+ requirement: &70201725756660 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70201725756660
25
+ description: Replicates OSX commandline utility where piping into pbcopy places things
26
+ into the clipboard
27
+ email:
28
+ - josh.cheek@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - .gitignore
34
+ - Gemfile
35
+ - LICENSE
36
+ - README.md
37
+ - Rakefile
38
+ - lib/pbcopy.rb
39
+ - lib/pbcopy/version.rb
40
+ - pbcopy.gemspec
41
+ - spec/pbcopy_spec.rb
42
+ homepage: ''
43
+ licenses: []
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubyforge_project:
62
+ rubygems_version: 1.8.11
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: Use pbcopy in Ruby in the same way you would from the terminal
66
+ test_files:
67
+ - spec/pbcopy_spec.rb
68
+ has_rdoc: