clippy 0.2.0 → 0.2.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.
data/bin/clippy CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ $:.unshift('../lib')
2
3
  require 'optparse'
3
4
  require 'clippy'
4
5
 
@@ -8,18 +9,19 @@ do_return = nil
8
9
  did_cmd = nil
9
10
  OptionParser.new do |opts|
10
11
  opts.banner = "Clippy v#{Clippy.version} by Envygeeks"
12
+ opts.on('--no-encoding', 'Encoding') { Clippy.encode = false }
11
13
  opts.on('--paste', 'Paste') { do_return = Clippy.paste }
12
14
  opts.on('--help', 'This') { do_return = opts }
13
15
  opts.on('--clear', 'Clear') { did_cmd = Clippy.clear }
14
16
 
15
17
  opts.on('--copy', 'Copy') do
16
18
  unless ARGV.count > 0
17
- text = ARGF.readlines.join.gsub(/\n$/, '')
19
+ text = ARGF.readlines.join
18
20
  else
19
21
  if ARGV.count > 1
20
22
  raise(RuntimeError, 'More than one arg.', 'Clippy')
21
23
  else
22
- text = ARGV.first
24
+ text = ARGV.first.dup
23
25
  end
24
26
  end
25
27
 
@@ -0,0 +1,9 @@
1
+ 0.2.1
2
+ Fix an issue with '\n$' on Ruby 1.9.3 by removing it.
3
+ No longer require open3 for Windows users.
4
+ Add an option for users to disable encoding.
5
+ Fix an issue with frozen argv by duping.
6
+ Micro-optimise the encoding checks a bit.
7
+ Update the readme to use Markdown.
8
+ Other various fixes that might not be mentioned.
9
+ Avoid shitty Gem pkg problems by forcing permissions.
@@ -0,0 +1,8 @@
1
+ Feature: Clippy
2
+ Background:
3
+ Sometimes you would like to copy and paste from a Ruby script. In order to
4
+ that though we will need a small little class called Clippy that can copy,
5
+ paste and also clear the clipboard on Windows, Linux and Mac.
6
+
7
+ Given Clippy exist and it has a version.
8
+ Then Copy, Paste and Clear should exist.
@@ -0,0 +1,10 @@
1
+ Given 'Clippy exist and it has a version.' do
2
+ should be_defined Clippy
3
+ should be_defined Clippy.version
4
+ end
5
+
6
+ Then 'Copy, Paste and Clear should exist.' do
7
+ [:copy, :paste, :clear].each do |service|
8
+ true.should == Clippy.respond_to?(service)
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ $:.unshift(File.join(File.dirname(__FILE__), '../../lib'))
2
+ require 'rspec/expectations'
3
+ require 'clippy'
4
+
5
+ RSpec::Matchers.define :be_defined do
6
+ match do |defyned|
7
+ defined? defyned
8
+ end
9
+ end
@@ -1,13 +1,15 @@
1
1
  require 'rbconfig'
2
- require 'open3'
3
2
 
4
- if RbConfig::CONFIG['host_os'] =~ /mswin/
3
+ unless RbConfig::CONFIG['host_os'] =~ /mswin/
4
+ require 'open3'
5
+ else
5
6
  require 'Win32API'
6
7
  require 'tempfile'
7
8
  end
8
9
 
9
10
  class Clippy
10
11
  private_class_method :new
12
+ @@encode = true
11
13
 
12
14
  [:UnsupportedOS, :UnknownClipboard, :InvalidEncoding].each do |status|
13
15
  const_set(status, Class.new(StandardError))
@@ -18,13 +20,17 @@ class Clippy
18
20
  ##
19
21
  # Version.
20
22
  def version
21
- '0.2.0'
23
+ '0.2.1'
22
24
  end
23
25
 
24
26
  def binary_exist?(bin)
25
27
  system("which #{bin} > /dev/null 2>&1")
26
28
  end
27
29
 
30
+ def encode=(value)
31
+ @@encode = value if [TrueClass, FalseClass].include?(value.class)
32
+ end
33
+
28
34
  ##
29
35
  # Copy
30
36
  def copy(data)
@@ -77,12 +83,17 @@ class Clippy
77
83
  ##
78
84
  # Paste
79
85
  def paste(encoding = nil, which = nil)
80
- if defined?(Encoding) && encoding
81
- unless Encoding.list.map(&:to_s).include?(encoding)
82
- if ['clipboard', 'primary', 'secondary'].include?(encoding)
83
- which, encoding = encoding, nil
86
+ if encoding
87
+ if %w(clipboard primary secondary).include?(encoding)
88
+ which, encoding = encoding, nil
89
+ else
90
+ if @@encode && defined?(Encoding)
91
+ unless Encoding.list.map(&:to_s).include?(encoding)
92
+ raise(InvalidEncoding, 'The encoding you selected is unsupported')
93
+ end
84
94
  else
85
- raise(InvalidEncoding, 'The encoding you selected is unsupported')
95
+ encoding = nil
96
+ warn('Encoding library wasn\'t found, skipping the encode') unless !@@encode
86
97
  end
87
98
  end
88
99
  end
@@ -124,7 +135,7 @@ class Clippy
124
135
  end
125
136
  end
126
137
 
127
- if defined?(Encoding)
138
+ if @@encode && defined?(Encoding)
128
139
  if data.encoding.name != Encoding.default_external
129
140
  data.encode(encoding ? encoding : Encoding.default_external)
130
141
  end
@@ -0,0 +1,31 @@
1
+ Clippy is a cross-platform clipboard utility and script for Ruby.
2
+
3
+ ---
4
+ * Requirements:
5
+ * Ruby1.9 (if on Windows)
6
+ * Development:
7
+ * Cucumber
8
+ * Rake
9
+ * Minitest
10
+ * RSPEC-Expectations
11
+
12
+ All other distros should work with 1.8+
13
+
14
+ # Shell (Linux and Windows)
15
+ clippy --copy '#1'
16
+ echo '#2' |clippy --copy
17
+ clipy --copy < 'file#3.txt'
18
+
19
+ # Ruby1.8+
20
+ require 'clippy'
21
+ Clippy.copy('#1')
22
+ Clippy.paste and Clippy.clear
23
+ <br />
24
+ <pre>
25
+ Clippy v0.1 by Envygeeks
26
+ --paste Paste
27
+ --help This
28
+ --clear Clear
29
+ --copy Copy
30
+ --version Version
31
+ </pre>
metadata CHANGED
@@ -1,128 +1,102 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: clippy
3
- version: !ruby/object:Gem::Version
4
- hash: 23
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 2
9
- - 0
10
- version: 0.2.0
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Jordon Bedwell
14
9
  - Nathaniel Davidson
15
10
  autorequire:
16
11
  bindir: bin
17
12
  cert_chain: []
18
-
19
- date: 2011-12-31 00:00:00 Z
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
13
+ date: 2012-02-01 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
22
16
  name: rspec-expectations
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: &12760080 !ruby/object:Gem::Requirement
25
18
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
- version: "0"
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
33
23
  type: :development
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: rake
37
24
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
25
+ version_requirements: *12760080
26
+ - !ruby/object:Gem::Dependency
27
+ name: rake
28
+ requirement: &12759640 !ruby/object:Gem::Requirement
39
29
  none: false
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- hash: 3
44
- segments:
45
- - 0
46
- version: "0"
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
47
34
  type: :development
48
- version_requirements: *id002
49
- - !ruby/object:Gem::Dependency
50
- name: minitest
51
35
  prerelease: false
52
- requirement: &id003 !ruby/object:Gem::Requirement
36
+ version_requirements: *12759640
37
+ - !ruby/object:Gem::Dependency
38
+ name: minitest
39
+ requirement: &12901720 !ruby/object:Gem::Requirement
53
40
  none: false
54
- requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
57
- hash: 3
58
- segments:
59
- - 0
60
- version: "0"
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
61
45
  type: :development
62
- version_requirements: *id003
63
- - !ruby/object:Gem::Dependency
64
- name: cucumber
65
46
  prerelease: false
66
- requirement: &id004 !ruby/object:Gem::Requirement
47
+ version_requirements: *12901720
48
+ - !ruby/object:Gem::Dependency
49
+ name: cucumber
50
+ requirement: &12901240 !ruby/object:Gem::Requirement
67
51
  none: false
68
- requirements:
69
- - - ">="
70
- - !ruby/object:Gem::Version
71
- hash: 3
72
- segments:
73
- - 0
74
- version: "0"
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
75
56
  type: :development
76
- version_requirements: *id004
57
+ prerelease: false
58
+ version_requirements: *12901240
77
59
  description: A utility to access the systems clipboard.
78
- email:
60
+ email:
79
61
  - jordon@envygeeks.com
80
62
  - nathaniel.davidson@gmail.com
81
- executables:
63
+ executables:
82
64
  - clippy
83
65
  extensions: []
84
-
85
66
  extra_rdoc_files: []
86
-
87
- files:
67
+ files:
88
68
  - lib/clippy.rb
89
69
  - bin/clippy
90
- - readme.txt
70
+ - features/support/global.rb
71
+ - features/step_definitions/clippy_steps.rb
72
+ - features/clippy.feature
73
+ - readme.md
91
74
  - license.txt
92
75
  - rakefile.rb
93
76
  - gemfile.rb
77
+ - changelog.md
94
78
  homepage: https://github.com/envygeeks/clippy
95
- licenses:
79
+ licenses:
96
80
  - MIT
97
81
  post_install_message:
98
82
  rdoc_options: []
99
-
100
- require_paths:
101
- - lib
102
- required_ruby_version: !ruby/object:Gem::Requirement
83
+ require_paths: lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
103
85
  none: false
104
- requirements:
105
- - - ">="
106
- - !ruby/object:Gem::Version
107
- hash: 3
108
- segments:
109
- - 0
110
- version: "0"
111
- required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
91
  none: false
113
- requirements:
114
- - - ">="
115
- - !ruby/object:Gem::Version
116
- hash: 3
117
- segments:
118
- - 0
119
- version: "0"
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
120
96
  requirements: []
121
-
122
97
  rubyforge_project:
123
- rubygems_version: 1.8.10
98
+ rubygems_version: 1.8.11
124
99
  signing_key:
125
100
  specification_version: 3
126
101
  summary: A utility to access the systems clipboard.
127
102
  test_files: []
128
-
data/readme.txt DELETED
@@ -1,41 +0,0 @@
1
- ---
2
- About:
3
- Clippy is a cross-platform clipboard utility and script for Ruby.
4
-
5
- ---
6
- Requirements:
7
- Windows:
8
- Ruby1.9
9
- Windows Vista+
10
-
11
- Development:
12
- cucumber
13
- rake
14
- minitest
15
- rspec-expectations
16
-
17
- All other distros should work with 1.8+
18
-
19
- ---
20
- Usage:
21
- Shell:
22
- clippy --copy '#1'
23
- echo '#2' |clippy --copy
24
- clipy --copy < 'file#3.txt'
25
- Ruby:
26
- require 'clippy'
27
- Clippy.copy('#1')
28
- Clippy.[paste, clear]
29
-
30
- ---
31
- Clippy v0.1 by Envygeeks
32
- --paste Paste
33
- --help This
34
- --clear Clear
35
- --copy Copy
36
- --version Version
37
-
38
- ---
39
- I want to throw a big thank you to Nathaniel (@firestar) who took the time to
40
- also build a Java version of clippy which will soon also be included as a
41
- fallback for Windows XP users.