renc 2.0.0 → 2.1.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.
- checksums.yaml +4 -4
 - data/CHANGELOG.md +4 -0
 - data/README.md +1 -1
 - data/lib/renc.rb +7 -48
 - data/lib/renc/configuration.rb +46 -0
 - data/lib/renc/version.rb +1 -1
 - data/renc.gemspec +2 -2
 - metadata +5 -4
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: b87be5d18214f6f0241ba83689760173435cd375
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 7473827a7e4e0d4a383ed28fa148b820978dc96f
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: ca57295a0c03eb1e6cc5b08cb96908c9d3a5e73654c38ee90ff2315aa958f497d86ff8c56519abd1690b12c809248648f35d227a6dce009d5661f19df69e6f83
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 6c47aac8531825d80c21c4c64ec2798a57b44ccb85b7e1093bfc20155bd09a8209d7fff2787cc384c2838c8de8528e7abf27f07ca54dd89b348f74976df08538
         
     | 
    
        data/CHANGELOG.md
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    
    
        data/lib/renc.rb
    CHANGED
    
    | 
         @@ -1,6 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'renc/version'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'renc/configuration'
         
     | 
| 
       2 
3 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
            #  
     | 
| 
      
 4 
     | 
    
         
            +
            # recursive encode for Hash and Array.
         
     | 
| 
       4 
5 
     | 
    
         
             
            # @example
         
     | 
| 
       5 
6 
     | 
    
         
             
            #   require 'renc'
         
     | 
| 
       6 
7 
     | 
    
         
             
            #
         
     | 
| 
         @@ -8,55 +9,13 @@ require 'renc/version' 
     | 
|
| 
       8 
9 
     | 
    
         
             
            #   extend Renc
         
     | 
| 
       9 
10 
     | 
    
         
             
            # @see #renc
         
     | 
| 
       10 
11 
     | 
    
         
             
            module Renc
         
     | 
| 
      
 12 
     | 
    
         
            +
              extend Configuration
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
       11 
14 
     | 
    
         
             
              # for include #renc method
         
     | 
| 
       12 
15 
     | 
    
         
             
              TARGET_CLASS = [String, Array, Hash].freeze
         
     | 
| 
       13 
16 
     | 
    
         
             
              TARGET_CLASS.each { |klass| klass.send(:include, self) }
         
     | 
| 
       14 
17 
     | 
    
         | 
| 
       15 
     | 
    
         
            -
              #  
     | 
| 
       16 
     | 
    
         
            -
              # @see Encoding.default_external
         
     | 
| 
       17 
     | 
    
         
            -
              DEFAULT_ENCODING = Encoding.default_external
         
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
              # this gem's default options for String#encode
         
     | 
| 
       20 
     | 
    
         
            -
              # @see String#encode
         
     | 
| 
       21 
     | 
    
         
            -
              DEFAULT_OPTIONS = { undef: :replace }.freeze
         
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
              class << self
         
     | 
| 
       24 
     | 
    
         
            -
                # return @default_encoding
         
     | 
| 
       25 
     | 
    
         
            -
                # @return [Encoding] @default_encoding
         
     | 
| 
       26 
     | 
    
         
            -
                # @see DEFAULT_ENCODING
         
     | 
| 
       27 
     | 
    
         
            -
                def default_encoding
         
     | 
| 
       28 
     | 
    
         
            -
                  @default_encoding ||= DEFAULT_ENCODING
         
     | 
| 
       29 
     | 
    
         
            -
                end
         
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
                # configure default encoding
         
     | 
| 
       32 
     | 
    
         
            -
                # @example
         
     | 
| 
       33 
     | 
    
         
            -
                #   Renc.default_encoding = 1 # => Renc::ConfigureError
         
     | 
| 
       34 
     | 
    
         
            -
                #   Renc.default_encoding = Encoding::ASCII
         
     | 
| 
       35 
     | 
    
         
            -
                # @param encoding [Encoding]
         
     | 
| 
       36 
     | 
    
         
            -
                def default_encoding=(encoding)
         
     | 
| 
       37 
     | 
    
         
            -
                  raise TypeError unless encoding.is_a?(Encoding)
         
     | 
| 
       38 
     | 
    
         
            -
                  @default_encoding = encoding
         
     | 
| 
       39 
     | 
    
         
            -
                end
         
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
                # return @default_options
         
     | 
| 
       42 
     | 
    
         
            -
                # @return [Encoding] @default_options
         
     | 
| 
       43 
     | 
    
         
            -
                # @see DEFAULT_OPTIONS
         
     | 
| 
       44 
     | 
    
         
            -
                def default_options
         
     | 
| 
       45 
     | 
    
         
            -
                  @default_options ||= DEFAULT_OPTIONS
         
     | 
| 
       46 
     | 
    
         
            -
                end
         
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
                # configure default options
         
     | 
| 
       49 
     | 
    
         
            -
                # @example
         
     | 
| 
       50 
     | 
    
         
            -
                #   Renc.default_options = 1 # => Renc::ConfigureError
         
     | 
| 
       51 
     | 
    
         
            -
                #   Renc.default_options = { undef: nil }
         
     | 
| 
       52 
     | 
    
         
            -
                # @param options [Hash]
         
     | 
| 
       53 
     | 
    
         
            -
                def default_options=(options)
         
     | 
| 
       54 
     | 
    
         
            -
                  raise TypeError unless options.is_a?(Hash)
         
     | 
| 
       55 
     | 
    
         
            -
                  @default_options = options
         
     | 
| 
       56 
     | 
    
         
            -
                end
         
     | 
| 
       57 
     | 
    
         
            -
              end
         
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       59 
     | 
    
         
            -
              # recurse encoding for Hash and Array.
         
     | 
| 
      
 18 
     | 
    
         
            +
              # recursive encode for Hash and Array.
         
     | 
| 
       60 
19 
     | 
    
         
             
              # @example
         
     | 
| 
       61 
20 
     | 
    
         
             
              #   # for example
         
     | 
| 
       62 
21 
     | 
    
         
             
              #   default_src_encoding # => #<Encoding:UTF-8>
         
     | 
| 
         @@ -99,14 +58,14 @@ module Renc 
     | 
|
| 
       99 
58 
     | 
    
         
             
                end
         
     | 
| 
       100 
59 
     | 
    
         
             
              end
         
     | 
| 
       101 
60 
     | 
    
         | 
| 
       102 
     | 
    
         
            -
              #  
     | 
| 
      
 61 
     | 
    
         
            +
              # recursive encode for Hash values of String.
         
     | 
| 
       103 
62 
     | 
    
         
             
              def renc_hash(obj, encoding, options)
         
     | 
| 
       104 
63 
     | 
    
         
             
                obj.each_with_object({}) do |(key, val), h|
         
     | 
| 
       105 
64 
     | 
    
         
             
                  h[key] = renc_internal(val, encoding, options)
         
     | 
| 
       106 
65 
     | 
    
         
             
                end
         
     | 
| 
       107 
66 
     | 
    
         
             
              end
         
     | 
| 
       108 
67 
     | 
    
         | 
| 
       109 
     | 
    
         
            -
              #  
     | 
| 
      
 68 
     | 
    
         
            +
              # recursive encode for Array values of String.
         
     | 
| 
       110 
69 
     | 
    
         
             
              def renc_array(obj, encoding, options)
         
     | 
| 
       111 
70 
     | 
    
         
             
                obj.map { |val| renc_internal(val, encoding, options) }
         
     | 
| 
       112 
71 
     | 
    
         
             
              end
         
     | 
| 
         @@ -0,0 +1,46 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Renc
         
     | 
| 
      
 2 
     | 
    
         
            +
              # namespace
         
     | 
| 
      
 3 
     | 
    
         
            +
              module Configuration
         
     | 
| 
      
 4 
     | 
    
         
            +
                # this gem's default configured encoding
         
     | 
| 
      
 5 
     | 
    
         
            +
                # @see Encoding.default_external
         
     | 
| 
      
 6 
     | 
    
         
            +
                DEFAULT_ENCODING = Encoding.default_external
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
                # this gem's default options for String#encode
         
     | 
| 
      
 9 
     | 
    
         
            +
                # @see String#encode
         
     | 
| 
      
 10 
     | 
    
         
            +
                DEFAULT_OPTIONS = { undef: :replace }.freeze
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                # return @default_encoding
         
     | 
| 
      
 13 
     | 
    
         
            +
                # @return [Encoding] @default_encoding
         
     | 
| 
      
 14 
     | 
    
         
            +
                # @see DEFAULT_ENCODING
         
     | 
| 
      
 15 
     | 
    
         
            +
                def default_encoding
         
     | 
| 
      
 16 
     | 
    
         
            +
                  @default_encoding ||= DEFAULT_ENCODING
         
     | 
| 
      
 17 
     | 
    
         
            +
                end
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                # configure default encoding
         
     | 
| 
      
 20 
     | 
    
         
            +
                # @example
         
     | 
| 
      
 21 
     | 
    
         
            +
                #   Renc.default_encoding = 1 # => Renc::ConfigureError
         
     | 
| 
      
 22 
     | 
    
         
            +
                #   Renc.default_encoding = Encoding::ASCII
         
     | 
| 
      
 23 
     | 
    
         
            +
                # @param encoding [Encoding]
         
     | 
| 
      
 24 
     | 
    
         
            +
                def default_encoding=(encoding)
         
     | 
| 
      
 25 
     | 
    
         
            +
                  raise TypeError unless encoding.is_a?(Encoding)
         
     | 
| 
      
 26 
     | 
    
         
            +
                  @default_encoding = encoding
         
     | 
| 
      
 27 
     | 
    
         
            +
                end
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                # return @default_options
         
     | 
| 
      
 30 
     | 
    
         
            +
                # @return [Encoding] @default_options
         
     | 
| 
      
 31 
     | 
    
         
            +
                # @see DEFAULT_OPTIONS
         
     | 
| 
      
 32 
     | 
    
         
            +
                def default_options
         
     | 
| 
      
 33 
     | 
    
         
            +
                  @default_options ||= DEFAULT_OPTIONS
         
     | 
| 
      
 34 
     | 
    
         
            +
                end
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
                # configure default options
         
     | 
| 
      
 37 
     | 
    
         
            +
                # @example
         
     | 
| 
      
 38 
     | 
    
         
            +
                #   Renc.default_options = 1 # => Renc::ConfigureError
         
     | 
| 
      
 39 
     | 
    
         
            +
                #   Renc.default_options = { undef: nil }
         
     | 
| 
      
 40 
     | 
    
         
            +
                # @param options [Hash]
         
     | 
| 
      
 41 
     | 
    
         
            +
                def default_options=(options)
         
     | 
| 
      
 42 
     | 
    
         
            +
                  raise TypeError unless options.is_a?(Hash)
         
     | 
| 
      
 43 
     | 
    
         
            +
                  @default_options = options
         
     | 
| 
      
 44 
     | 
    
         
            +
                end
         
     | 
| 
      
 45 
     | 
    
         
            +
              end
         
     | 
| 
      
 46 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/renc/version.rb
    CHANGED
    
    
    
        data/renc.gemspec
    CHANGED
    
    | 
         @@ -11,8 +11,8 @@ Gem::Specification.new do |spec| 
     | 
|
| 
       11 
11 
     | 
    
         | 
| 
       12 
12 
     | 
    
         
             
              spec.required_ruby_version = '>= 2.0.0'
         
     | 
| 
       13 
13 
     | 
    
         | 
| 
       14 
     | 
    
         
            -
              spec.summary       = ' 
     | 
| 
       15 
     | 
    
         
            -
              spec.description   = ' 
     | 
| 
      
 14 
     | 
    
         
            +
              spec.summary       = 'recursive encode for Hash and Array.'
         
     | 
| 
      
 15 
     | 
    
         
            +
              spec.description   = 'recursive encode for Hash and Array.'
         
     | 
| 
       16 
16 
     | 
    
         
             
              spec.homepage      = 'https://github.com/k-ta-yamada/renc'
         
     | 
| 
       17 
17 
     | 
    
         
             
              spec.license       = 'MIT'
         
     | 
| 
       18 
18 
     | 
    
         | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: renc
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 2. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 2.1.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - k-ta-yamada
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: exe
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2017-02- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2017-02-19 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: bundler
         
     | 
| 
         @@ -136,7 +136,7 @@ dependencies: 
     | 
|
| 
       136 
136 
     | 
    
         
             
                - - ">="
         
     | 
| 
       137 
137 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       138 
138 
     | 
    
         
             
                    version: '0'
         
     | 
| 
       139 
     | 
    
         
            -
            description:  
     | 
| 
      
 139 
     | 
    
         
            +
            description: recursive encode for Hash and Array.
         
     | 
| 
       140 
140 
     | 
    
         
             
            email:
         
     | 
| 
       141 
141 
     | 
    
         
             
            - key.luvless@gmail.com
         
     | 
| 
       142 
142 
     | 
    
         
             
            executables: []
         
     | 
| 
         @@ -157,6 +157,7 @@ files: 
     | 
|
| 
       157 
157 
     | 
    
         
             
            - bin/console
         
     | 
| 
       158 
158 
     | 
    
         
             
            - bin/setup
         
     | 
| 
       159 
159 
     | 
    
         
             
            - lib/renc.rb
         
     | 
| 
      
 160 
     | 
    
         
            +
            - lib/renc/configuration.rb
         
     | 
| 
       160 
161 
     | 
    
         
             
            - lib/renc/version.rb
         
     | 
| 
       161 
162 
     | 
    
         
             
            - renc.gemspec
         
     | 
| 
       162 
163 
     | 
    
         
             
            homepage: https://github.com/k-ta-yamada/renc
         
     | 
| 
         @@ -182,5 +183,5 @@ rubyforge_project: 
     | 
|
| 
       182 
183 
     | 
    
         
             
            rubygems_version: 2.6.8
         
     | 
| 
       183 
184 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       184 
185 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       185 
     | 
    
         
            -
            summary:  
     | 
| 
      
 186 
     | 
    
         
            +
            summary: recursive encode for Hash and Array.
         
     | 
| 
       186 
187 
     | 
    
         
             
            test_files: []
         
     |