coder 0.1.1 → 0.1.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.
@@ -16,9 +16,9 @@ module Coder
16
16
  @decoder = @charset.new_decoder
17
17
  @decoder.on_malformed_input(::Java::JavaNioCharset::CodingErrorAction::IGNORE)
18
18
  @decoder.on_unmappable_character(::Java::JavaNioCharset::CodingErrorAction::IGNORE)
19
- rescue ::Java::JavaNioCharset::UnsupportedCharsetException
19
+ rescue ::Java::JavaNioCharset::UnsupportedCharsetException, ::Java::JavaNioCharset::IllegalCharsetNameException
20
20
  raise Coder::InvalidEncoding, "unknown encoding name - #{encoding}"
21
- rescue Java::JavaLang::RuntimeException => e
21
+ rescue ::Java::JavaLang::RuntimeException => e
22
22
  raise Coder::Error, e.message, e.backtrace
23
23
  end
24
24
 
@@ -11,7 +11,7 @@ module Coder
11
11
 
12
12
  def initialize(encoding)
13
13
  const_name = encoding.to_s.upcase.gsub('-', '_')
14
- raise Coder::InvalidEncoding, "unknown encoding name - #{encoding}" unless Encodings.const_defined? const_name
14
+ raise Coder::InvalidEncoding, "unknown encoding name - #{encoding}" unless coding_available? const_name
15
15
  @encoding, @name = Encodings.const_get(const_name), encoding
16
16
  end
17
17
 
@@ -23,6 +23,12 @@ module Coder
23
23
 
24
24
  private
25
25
 
26
+ def coding_available?(const_name)
27
+ Encodings.const_defined? const_name
28
+ rescue NameError
29
+ false
30
+ end
31
+
26
32
  def force_encoding(str)
27
33
  return str unless str.respond_to? :force_encoding
28
34
  str.force_encoding(@name)
@@ -1,4 +1,4 @@
1
- module Cleaner
1
+ module Coder
2
2
  class Error < StandardError
3
3
  end
4
4
 
@@ -1,3 +1,3 @@
1
1
  module Coder
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -1,5 +1,6 @@
1
1
  # encoding: UTF-8
2
2
  require 'coder/cleaner'
3
+ require 'coder/error'
3
4
 
4
5
  shared_examples Coder::Cleaner do
5
6
  let(:encoding) { example.example_group.description }
@@ -19,6 +20,10 @@ shared_examples Coder::Cleaner do
19
20
  cleans "{foo \xC3 'bar'}", "{foo 'bar'}"
20
21
  cleans "yummy\xE2 \xF0\x9F\x8D\x94 \x9F\x8D\x94", "yummy 🍔 "
21
22
  end
23
+
24
+ context "Unknown Encoding" do
25
+ it { expect { subject }.to raise_error(Coder::InvalidEncoding) }
26
+ end
22
27
  end
23
28
 
24
29
  describe Coder::Cleaner::Builtin do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: