nuggets 1.0.1 → 1.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 +9 -1
- data/README +1 -1
- data/Rakefile +1 -1
- data/lib/nuggets/log_parser/rails.rb +1 -1
- data/lib/nuggets/object/rescue_if.rb +5 -0
- data/lib/nuggets/object/rescue_if_mixin.rb +61 -0
- data/lib/nuggets/ruby.rb +18 -11
- data/lib/nuggets/version.rb +2 -2
- data/spec/nuggets/object/rescue_if_spec.rb +109 -0
- metadata +21 -13
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 5770eebf6f2e382109a635d9f45c9855158c5a31
         | 
| 4 | 
            +
              data.tar.gz: 6894e3ab73e1b9c743b2af81e76f15003e6a5311
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 1118fc142d9093d67e5e4269f7988abfbbae0d9404d120150d30b6836b6e208517f1361b55c9e44146530a54bd1cfcc57964ae6a2cc297e5f2480ce236956583
         | 
| 7 | 
            +
              data.tar.gz: 96225bab56c69d06f0701e787ae6d123d383aebd6564874d0ff8f5e094a28c83561acd759b74efb2cdee512e221e1cb5a953963026af728d2061b5755bd5fa06
         | 
    
        data/ChangeLog
    CHANGED
    
    | @@ -2,9 +2,17 @@ | |
| 2 2 |  | 
| 3 3 | 
             
            = Revision history for nuggets
         | 
| 4 4 |  | 
| 5 | 
            +
            == 1.1.0 [2014-11-26]
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            * Nuggets::LogParser::Rails no longer <tt>eval</tt>s the params hash; set the
         | 
| 8 | 
            +
              environment variable +NUGGETS_LOG_PARSER_RAILS_EVAL_PARAMS+ to restore this
         | 
| 9 | 
            +
              behaviour.
         | 
| 10 | 
            +
            * Added Object#rescue_if and Object#rescue_unless.
         | 
| 11 | 
            +
            * Added JRuby variant of Process.ruby.
         | 
| 12 | 
            +
             | 
| 5 13 | 
             
            == 1.0.1 [2014-08-27]
         | 
| 6 14 |  | 
| 7 | 
            -
            * Added DATA.{consume,reposition,update} | 
| 15 | 
            +
            * Added <tt>DATA.{consume,reposition,update}</tt>.
         | 
| 8 16 | 
             
            * Added Module#query_attr.
         | 
| 9 17 | 
             
            * Added Module#lazy_attr.
         | 
| 10 18 | 
             
            * Added Integer#to_roman.
         | 
    
        data/README
    CHANGED
    
    
    
        data/Rakefile
    CHANGED
    
    
| @@ -0,0 +1,61 @@ | |
| 1 | 
            +
            #--
         | 
| 2 | 
            +
            ###############################################################################
         | 
| 3 | 
            +
            #                                                                             #
         | 
| 4 | 
            +
            # nuggets -- Extending Ruby                                                   #
         | 
| 5 | 
            +
            #                                                                             #
         | 
| 6 | 
            +
            # Copyright (C) 2007-2014 Jens Wille                                          #
         | 
| 7 | 
            +
            #                                                                             #
         | 
| 8 | 
            +
            # Authors:                                                                    #
         | 
| 9 | 
            +
            #     Jens Wille <jens.wille@gmail.com>                                       #
         | 
| 10 | 
            +
            #                                                                             #
         | 
| 11 | 
            +
            # nuggets is free software; you can redistribute it and/or modify it under    #
         | 
| 12 | 
            +
            # the terms of the GNU Affero General Public License as published by the Free #
         | 
| 13 | 
            +
            # Software Foundation; either version 3 of the License, or (at your option)   #
         | 
| 14 | 
            +
            # any later version.                                                          #
         | 
| 15 | 
            +
            #                                                                             #
         | 
| 16 | 
            +
            # nuggets is distributed in the hope that it will be useful, but WITHOUT ANY  #
         | 
| 17 | 
            +
            # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS   #
         | 
| 18 | 
            +
            # FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for     #
         | 
| 19 | 
            +
            # more details.                                                               #
         | 
| 20 | 
            +
            #                                                                             #
         | 
| 21 | 
            +
            # You should have received a copy of the GNU Affero General Public License    #
         | 
| 22 | 
            +
            # along with nuggets. If not, see <http://www.gnu.org/licenses/>.             #
         | 
| 23 | 
            +
            #                                                                             #
         | 
| 24 | 
            +
            ###############################################################################
         | 
| 25 | 
            +
            #++
         | 
| 26 | 
            +
             | 
| 27 | 
            +
            module Nuggets
         | 
| 28 | 
            +
              class Object
         | 
| 29 | 
            +
                module RescueIfMixin
         | 
| 30 | 
            +
             | 
| 31 | 
            +
              # call-seq:
         | 
| 32 | 
            +
              #   rescue_if([args]) { |err| ... }
         | 
| 33 | 
            +
              #
         | 
| 34 | 
            +
              # Rescue exceptions matching +args+, or StandardError if not given,
         | 
| 35 | 
            +
              # if +block+ returns true.
         | 
| 36 | 
            +
              def rescue_if(*args, &block)
         | 
| 37 | 
            +
                raise ::ArgumentError, 'no block given' unless block
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                args = [::StandardError] if args.empty?
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                ::Module.new {
         | 
| 42 | 
            +
                  define_singleton_method(:===) { |err|
         | 
| 43 | 
            +
                    block[err] if args.any? { |arg| arg === err }
         | 
| 44 | 
            +
                  }
         | 
| 45 | 
            +
                }
         | 
| 46 | 
            +
              end
         | 
| 47 | 
            +
             | 
| 48 | 
            +
              # call-seq:
         | 
| 49 | 
            +
              #   rescue_unless([args]) { |err| ... }
         | 
| 50 | 
            +
              #
         | 
| 51 | 
            +
              # Rescue exceptions matching +args+, or StandardError if not given,
         | 
| 52 | 
            +
              # unless +block+ returns true.
         | 
| 53 | 
            +
              def rescue_unless(*args, &block)
         | 
| 54 | 
            +
                raise ::ArgumentError, 'no block given' unless block
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                rescue_if(*args) { |err| !block[err] }
         | 
| 57 | 
            +
              end
         | 
| 58 | 
            +
             | 
| 59 | 
            +
                end
         | 
| 60 | 
            +
              end
         | 
| 61 | 
            +
            end
         | 
    
        data/lib/nuggets/ruby.rb
    CHANGED
    
    | @@ -142,7 +142,7 @@ module Nuggets | |
| 142 142 |  | 
| 143 143 | 
             
                %w[gem rake rspec].each { |name| define_ruby_tool(name) }
         | 
| 144 144 |  | 
| 145 | 
            -
                def ruby_options_to_argv(args, ruby_command = ruby_command)
         | 
| 145 | 
            +
                def ruby_options_to_argv(args, ruby_command = ruby_command())
         | 
| 146 146 | 
             
                  argv = [ruby_command]
         | 
| 147 147 |  | 
| 148 148 | 
             
                  ruby_options_from_hash(args.pop, argv) if args.last.is_a?(::Hash)
         | 
| @@ -216,20 +216,27 @@ end | |
| 216 216 |  | 
| 217 217 | 
             
            def File.ruby; ::Nuggets::Ruby.ruby_command; end
         | 
| 218 218 |  | 
| 219 | 
            -
             | 
| 220 | 
            -
              require 'open4'
         | 
| 221 | 
            -
             | 
| 219 | 
            +
            if RUBY_PLATFORM == 'java'
         | 
| 222 220 | 
             
              def Process.ruby(*args, &block)
         | 
| 223 221 | 
             
                argv = ::Nuggets::Ruby.ruby_options_to_argv(args)
         | 
| 224 | 
            -
                :: | 
| 222 | 
            +
                ::IO.popen4(*argv, &block); $?
         | 
| 225 223 | 
             
              end
         | 
| 224 | 
            +
            else
         | 
| 225 | 
            +
              begin
         | 
| 226 | 
            +
                require 'open4'
         | 
| 227 | 
            +
             | 
| 228 | 
            +
                def Process.ruby(*args, &block)
         | 
| 229 | 
            +
                  argv = ::Nuggets::Ruby.ruby_options_to_argv(args)
         | 
| 230 | 
            +
                  ::Open4.popen4(*argv, &block)
         | 
| 231 | 
            +
                end
         | 
| 226 232 |  | 
| 227 | 
            -
             | 
| 233 | 
            +
                require 'nuggets/io/interact'
         | 
| 228 234 |  | 
| 229 | 
            -
             | 
| 230 | 
            -
             | 
| 231 | 
            -
             | 
| 232 | 
            -
             | 
| 235 | 
            +
                def Process.interact_ruby(input, *args)
         | 
| 236 | 
            +
                  ruby(*args) { |_, i, o, e|
         | 
| 237 | 
            +
                    ::IO.interact({ input => i }, { o => $stdout, e => $stderr })
         | 
| 238 | 
            +
                  }
         | 
| 239 | 
            +
                end
         | 
| 240 | 
            +
              rescue ::LoadError
         | 
| 233 241 | 
             
              end
         | 
| 234 | 
            -
            rescue ::LoadError
         | 
| 235 242 | 
             
            end
         | 
    
        data/lib/nuggets/version.rb
    CHANGED
    
    
| @@ -0,0 +1,109 @@ | |
| 1 | 
            +
            require 'nuggets/object/rescue_if'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe_extended Object, Nuggets::Object::RescueIfMixin do
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              example {
         | 
| 6 | 
            +
                expect(rescue_if {}).to be_a(Module)
         | 
| 7 | 
            +
              }
         | 
| 8 | 
            +
             | 
| 9 | 
            +
              example {
         | 
| 10 | 
            +
                expect(rescue_unless {}).to be_a(Module)
         | 
| 11 | 
            +
              }
         | 
| 12 | 
            +
             | 
| 13 | 
            +
              example {
         | 
| 14 | 
            +
                expect { rescue_if }.to raise_error(ArgumentError)
         | 
| 15 | 
            +
              }
         | 
| 16 | 
            +
             | 
| 17 | 
            +
              example {
         | 
| 18 | 
            +
                expect { rescue_unless }.to raise_error(ArgumentError)
         | 
| 19 | 
            +
              }
         | 
| 20 | 
            +
             | 
| 21 | 
            +
              example {
         | 
| 22 | 
            +
                expect(begin
         | 
| 23 | 
            +
                  raise 'foo'
         | 
| 24 | 
            +
                rescue rescue_if { true }
         | 
| 25 | 
            +
                  42
         | 
| 26 | 
            +
                end).to eq(42)
         | 
| 27 | 
            +
              }
         | 
| 28 | 
            +
             | 
| 29 | 
            +
              example {
         | 
| 30 | 
            +
                expect(begin
         | 
| 31 | 
            +
                  raise 'foo'
         | 
| 32 | 
            +
                rescue rescue_if { |e| e.message == 'foo' }
         | 
| 33 | 
            +
                  42
         | 
| 34 | 
            +
                end).to eq(42)
         | 
| 35 | 
            +
              }
         | 
| 36 | 
            +
             | 
| 37 | 
            +
              example {
         | 
| 38 | 
            +
                expect { begin
         | 
| 39 | 
            +
                  raise 'bar'
         | 
| 40 | 
            +
                rescue rescue_if { |e| e.message == 'foo' }
         | 
| 41 | 
            +
                  42
         | 
| 42 | 
            +
                end }.to raise_error(RuntimeError, 'bar')
         | 
| 43 | 
            +
              }
         | 
| 44 | 
            +
             | 
| 45 | 
            +
              example {
         | 
| 46 | 
            +
                expect(begin
         | 
| 47 | 
            +
                  raise 'bar'
         | 
| 48 | 
            +
                rescue rescue_unless { |e| e.message == 'foo' }
         | 
| 49 | 
            +
                  42
         | 
| 50 | 
            +
                end).to eq(42)
         | 
| 51 | 
            +
              }
         | 
| 52 | 
            +
             | 
| 53 | 
            +
              example {
         | 
| 54 | 
            +
                expect(begin
         | 
| 55 | 
            +
                  raise 'foo'
         | 
| 56 | 
            +
                rescue rescue_if(RuntimeError) { true }
         | 
| 57 | 
            +
                  42
         | 
| 58 | 
            +
                end).to eq(42)
         | 
| 59 | 
            +
              }
         | 
| 60 | 
            +
             | 
| 61 | 
            +
              example {
         | 
| 62 | 
            +
                expect(begin
         | 
| 63 | 
            +
                  raise 'foo'
         | 
| 64 | 
            +
                rescue rescue_if(StandardError) { true }
         | 
| 65 | 
            +
                  42
         | 
| 66 | 
            +
                end).to eq(42)
         | 
| 67 | 
            +
              }
         | 
| 68 | 
            +
             | 
| 69 | 
            +
              example {
         | 
| 70 | 
            +
                expect(begin
         | 
| 71 | 
            +
                  raise 'foo'
         | 
| 72 | 
            +
                rescue rescue_if(RuntimeError, NameError) { true }
         | 
| 73 | 
            +
                  42
         | 
| 74 | 
            +
                end).to eq(42)
         | 
| 75 | 
            +
              }
         | 
| 76 | 
            +
             | 
| 77 | 
            +
              example {
         | 
| 78 | 
            +
                expect { begin
         | 
| 79 | 
            +
                  raise 'foo'
         | 
| 80 | 
            +
                rescue rescue_if(NameError) { true }
         | 
| 81 | 
            +
                  42
         | 
| 82 | 
            +
                end }.to raise_error(RuntimeError, 'foo')
         | 
| 83 | 
            +
              }
         | 
| 84 | 
            +
             | 
| 85 | 
            +
              example {
         | 
| 86 | 
            +
                expect(begin
         | 
| 87 | 
            +
                  raise 'foo'
         | 
| 88 | 
            +
                rescue rescue_if { true } => e
         | 
| 89 | 
            +
                  e
         | 
| 90 | 
            +
                end).to be_a(RuntimeError)
         | 
| 91 | 
            +
              }
         | 
| 92 | 
            +
             | 
| 93 | 
            +
              example {
         | 
| 94 | 
            +
                expect { begin
         | 
| 95 | 
            +
                  raise Exception, 'foo'
         | 
| 96 | 
            +
                rescue rescue_if { true }
         | 
| 97 | 
            +
                  42
         | 
| 98 | 
            +
                end }.to raise_error(Exception, 'foo')
         | 
| 99 | 
            +
              }
         | 
| 100 | 
            +
             | 
| 101 | 
            +
              example {
         | 
| 102 | 
            +
                expect(begin
         | 
| 103 | 
            +
                  raise Exception, 'foo'
         | 
| 104 | 
            +
                rescue rescue_if(Exception) { true }
         | 
| 105 | 
            +
                  42
         | 
| 106 | 
            +
                end).to eq(42)
         | 
| 107 | 
            +
              }
         | 
| 108 | 
            +
             | 
| 109 | 
            +
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: nuggets
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1.0 | 
| 4 | 
            +
              version: 1.1.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Jens Wille
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2014- | 
| 11 | 
            +
            date: 2014-11-26 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: mime-types
         | 
| @@ -42,16 +42,22 @@ dependencies: | |
| 42 42 | 
             
              name: hen
         | 
| 43 43 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 44 44 | 
             
                requirements:
         | 
| 45 | 
            +
                - - "~>"
         | 
| 46 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 47 | 
            +
                    version: '0.8'
         | 
| 45 48 | 
             
                - - ">="
         | 
| 46 49 | 
             
                  - !ruby/object:Gem::Version
         | 
| 47 | 
            -
                    version:  | 
| 50 | 
            +
                    version: 0.8.0
         | 
| 48 51 | 
             
              type: :development
         | 
| 49 52 | 
             
              prerelease: false
         | 
| 50 53 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 51 54 | 
             
                requirements:
         | 
| 55 | 
            +
                - - "~>"
         | 
| 56 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 57 | 
            +
                    version: '0.8'
         | 
| 52 58 | 
             
                - - ">="
         | 
| 53 59 | 
             
                  - !ruby/object:Gem::Version
         | 
| 54 | 
            -
                    version:  | 
| 60 | 
            +
                    version: 0.8.0
         | 
| 55 61 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 56 62 | 
             
              name: rake
         | 
| 57 63 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -221,6 +227,8 @@ files: | |
| 221 227 | 
             
            - lib/nuggets/object/metaclass.rb
         | 
| 222 228 | 
             
            - lib/nuggets/object/msend.rb
         | 
| 223 229 | 
             
            - lib/nuggets/object/msend_mixin.rb
         | 
| 230 | 
            +
            - lib/nuggets/object/rescue_if.rb
         | 
| 231 | 
            +
            - lib/nuggets/object/rescue_if_mixin.rb
         | 
| 224 232 | 
             
            - lib/nuggets/object/silence.rb
         | 
| 225 233 | 
             
            - lib/nuggets/object/silence_mixin.rb
         | 
| 226 234 | 
             
            - lib/nuggets/object/singleton_class.rb
         | 
| @@ -312,6 +320,7 @@ files: | |
| 312 320 | 
             
            - spec/nuggets/object/blank_spec.rb
         | 
| 313 321 | 
             
            - spec/nuggets/object/boolean_spec.rb
         | 
| 314 322 | 
             
            - spec/nuggets/object/msend_spec.rb
         | 
| 323 | 
            +
            - spec/nuggets/object/rescue_if_spec.rb
         | 
| 315 324 | 
             
            - spec/nuggets/object/silence_spec.rb
         | 
| 316 325 | 
             
            - spec/nuggets/object/singleton_class_spec.rb
         | 
| 317 326 | 
             
            - spec/nuggets/proc/bind_spec.rb
         | 
| @@ -335,18 +344,17 @@ licenses: | |
| 335 344 | 
             
            metadata: {}
         | 
| 336 345 | 
             
            post_install_message: |2+
         | 
| 337 346 |  | 
| 338 | 
            -
              nuggets-1.0 | 
| 347 | 
            +
              nuggets-1.1.0 [2014-11-26]:
         | 
| 339 348 |  | 
| 340 | 
            -
              *  | 
| 341 | 
            -
             | 
| 342 | 
            -
             | 
| 343 | 
            -
              * Added  | 
| 344 | 
            -
              * Added  | 
| 345 | 
            -
              * Added Array#interpolate.
         | 
| 349 | 
            +
              * Nuggets::LogParser::Rails no longer <tt>eval</tt>s the params hash; set the
         | 
| 350 | 
            +
                environment variable +NUGGETS_LOG_PARSER_RAILS_EVAL_PARAMS+ to restore this
         | 
| 351 | 
            +
                behaviour.
         | 
| 352 | 
            +
              * Added Object#rescue_if and Object#rescue_unless.
         | 
| 353 | 
            +
              * Added JRuby variant of Process.ruby.
         | 
| 346 354 |  | 
| 347 355 | 
             
            rdoc_options:
         | 
| 348 356 | 
             
            - "--title"
         | 
| 349 | 
            -
            - nuggets Application documentation (v1.0 | 
| 357 | 
            +
            - nuggets Application documentation (v1.1.0)
         | 
| 350 358 | 
             
            - "--charset"
         | 
| 351 359 | 
             
            - UTF-8
         | 
| 352 360 | 
             
            - "--line-numbers"
         | 
| @@ -367,7 +375,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 367 375 | 
             
                  version: '0'
         | 
| 368 376 | 
             
            requirements: []
         | 
| 369 377 | 
             
            rubyforge_project: 
         | 
| 370 | 
            -
            rubygems_version: 2.4. | 
| 378 | 
            +
            rubygems_version: 2.4.4
         | 
| 371 379 | 
             
            signing_key: 
         | 
| 372 380 | 
             
            specification_version: 4
         | 
| 373 381 | 
             
            summary: Extending Ruby.
         |