whiteout 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/lib/whiteout.rb +34 -9
  3. data/lib/whiteout/version.rb +1 -1
  4. metadata +30 -24
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6523c7f6069854c9f3dcf74f55f52f1670987146
4
+ data.tar.gz: 667c7ff958751432cdd5916aa69d9f04863d0ecd
5
+ SHA512:
6
+ metadata.gz: 34e6d9ed6e45f7b0b1b71c195751e0b70431563ddaef32cd2e5f0a3dfdf216037196c8ac9a22623c9c747ec9aac5c8f62a9cd57206d084afcb4ef423ea66c39b
7
+ data.tar.gz: d3f0fbb4ba62c185dd7ab7a54f86392392a34e88176e0fc65e25cdaef50e07be84ed35ff8da25fecd76153beb49819d3cd7d4bfbb044adecf4ab3906fda5e516
data/lib/whiteout.rb CHANGED
@@ -37,25 +37,50 @@ module Whiteout
37
37
  abort opts.to_s if args.empty?
38
38
 
39
39
  self.input_list(args, recurse).each do |file|
40
- File.open(file) do |infile|
41
- puts file if verbose
40
+ self.clean_file(file, verbose)
41
+ end
42
+ end
43
+ end
42
44
 
43
- outfile = Tempfile.new('whiteout')
45
+ class InvalidByteSequenceError < StandardError
46
+ attr_reader :original
44
47
 
45
- infile.each do |line|
46
- outfile.write(self.clean(line))
47
- end
48
+ def initialize(msg, original = nil)
49
+ super(msg)
50
+ @original = original
51
+ end
52
+ end
48
53
 
49
- outfile.chmod(infile.stat.mode)
50
- outfile.close
51
- FileUtils.mv(outfile, infile)
54
+ def self.clean_file(file, verbose = false)
55
+ File.open(file) do |infile|
56
+ puts file if verbose
57
+
58
+ outfile = Tempfile.new('whiteout')
59
+
60
+ begin
61
+ infile.each do |line|
62
+ outfile.write(self.clean(line))
52
63
  end
64
+ rescue InvalidByteSequenceError
65
+ warn "#{file} is a binary file; not processing"
66
+ outfile.close
67
+ outfile.unlink
68
+ else
69
+ outfile.chmod(infile.stat.mode)
70
+ outfile.close
71
+ FileUtils.mv(outfile, infile)
53
72
  end
54
73
  end
55
74
  end
56
75
 
57
76
  def self.clean(str)
58
77
  str.gsub(/[ \t]+$/, '')
78
+ rescue ArgumentError => e
79
+ if e.message == "invalid byte sequence in UTF-8"
80
+ raise InvalidByteSequenceError.new(e.message, e)
81
+ else
82
+ raise e
83
+ end
59
84
  end
60
85
 
61
86
  def self.input_list(file_args, recurse)
@@ -1,3 +1,3 @@
1
1
  module Whiteout
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  end
metadata CHANGED
@@ -1,52 +1,59 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whiteout
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
5
- prerelease:
4
+ version: 0.2.4
6
5
  platform: ruby
7
6
  authors:
8
7
  - Cameron Desautels
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-05-13 00:00:00.000000000 Z
11
+ date: 2013-11-14 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rspec
16
- requirement: &70356011014000 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :development
23
21
  prerelease: false
24
- version_requirements: *70356011014000
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
25
27
  - !ruby/object:Gem::Dependency
26
28
  name: ronn
27
- requirement: &70356011004720 !ruby/object:Gem::Requirement
28
- none: false
29
+ requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
- - - ! '>='
31
+ - - '>='
31
32
  - !ruby/object:Gem::Version
32
33
  version: '0'
33
34
  type: :development
34
35
  prerelease: false
35
- version_requirements: *70356011004720
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
36
41
  - !ruby/object:Gem::Dependency
37
42
  name: rake
38
- requirement: &70356011002740 !ruby/object:Gem::Requirement
39
- none: false
43
+ requirement: !ruby/object:Gem::Requirement
40
44
  requirements:
41
- - - ! '>='
45
+ - - '>='
42
46
  - !ruby/object:Gem::Version
43
47
  version: '0'
44
48
  type: :development
45
49
  prerelease: false
46
- version_requirements: *70356011002740
47
- description: ! ' Removes trailing whitespace from standard input or from named files.
48
-
49
- '
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: |2
56
+ Removes trailing whitespace from standard input or from named files.
50
57
  email:
51
58
  - camdez@gmail.com
52
59
  executables:
@@ -71,27 +78,26 @@ files:
71
78
  homepage: http://github.com/camdez/whiteout
72
79
  licenses:
73
80
  - MIT
81
+ metadata: {}
74
82
  post_install_message:
75
83
  rdoc_options: []
76
84
  require_paths:
77
85
  - lib
78
86
  required_ruby_version: !ruby/object:Gem::Requirement
79
- none: false
80
87
  requirements:
81
- - - ! '>='
88
+ - - '>='
82
89
  - !ruby/object:Gem::Version
83
90
  version: '0'
84
91
  required_rubygems_version: !ruby/object:Gem::Requirement
85
- none: false
86
92
  requirements:
87
- - - ! '>='
93
+ - - '>='
88
94
  - !ruby/object:Gem::Version
89
95
  version: '0'
90
96
  requirements: []
91
97
  rubyforge_project: whiteout
92
- rubygems_version: 1.8.6
98
+ rubygems_version: 2.0.3
93
99
  signing_key:
94
- specification_version: 3
100
+ specification_version: 4
95
101
  summary: Remove trailing whitespace from files.
96
102
  test_files:
97
103
  - spec/whiteout_spec.rb