nuggets 1.1.0 → 1.2.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 +6 -0
- data/README +2 -2
- data/Rakefile +1 -1
- data/lib/nuggets/enumerable/all_any_extended.rb +4 -65
- data/lib/nuggets/enumerable/all_any_extended_mixin.rb +65 -0
- data/lib/nuggets/hash/deproc.rb +5 -0
- data/lib/nuggets/hash/deproc_mixin.rb +79 -0
- data/lib/nuggets/io/null_mixin.rb +4 -2
- data/lib/nuggets/module/lazy_attr_mixin.rb +3 -5
- data/lib/nuggets/net/ssh.rb +45 -0
- data/lib/nuggets/ruby.rb +3 -182
- data/lib/nuggets/ruby_mixin.rb +215 -0
- data/lib/nuggets/version.rb +1 -1
- data/spec/nuggets/env/user_home_spec.rb +1 -1
- data/spec/nuggets/object/singleton_class_spec.rb +1 -1
- metadata +15 -12
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: b0b959bddb4e1b2d928bcb059f1ea972929212ba
         | 
| 4 | 
            +
              data.tar.gz: 21aa2cb33d3d74c60fcc464c8be1daf8048b0d4b
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 8ecfb6dcc2afadaf74e24823fa679a54ce178a1312b3e16aad6d5149a5354ab6be1031e29683049667bf162d37b8bbe41e0ab83f79d80b4d10446b2dc3b5aa39
         | 
| 7 | 
            +
              data.tar.gz: 2f24ba68b5046c446abdc1352170009ad2b15a55b116a3cdea96fb5b633d20bc41d6109f9606dc0f4b6276524d509709c1192163f30118c70bbd2d88bbc21f96
         | 
    
        data/ChangeLog
    CHANGED
    
    | @@ -2,6 +2,12 @@ | |
| 2 2 |  | 
| 3 3 | 
             
            = Revision history for nuggets
         | 
| 4 4 |  | 
| 5 | 
            +
            == 1.2.0 [2015-03-13]
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            * Extracted Nuggets::RubyMixin from Nuggets::Ruby.
         | 
| 8 | 
            +
            * Added Net::SSH::Connection::Session#exec_sudo.
         | 
| 9 | 
            +
            * Added Hash.deproc.
         | 
| 10 | 
            +
             | 
| 5 11 | 
             
            == 1.1.0 [2014-11-26]
         | 
| 6 12 |  | 
| 7 13 | 
             
            * Nuggets::LogParser::Rails no longer <tt>eval</tt>s the params hash; set the
         | 
    
        data/README
    CHANGED
    
    | @@ -2,7 +2,7 @@ | |
| 2 2 |  | 
| 3 3 | 
             
            == VERSION
         | 
| 4 4 |  | 
| 5 | 
            -
            This documentation refers to nuggets version 1. | 
| 5 | 
            +
            This documentation refers to nuggets version 1.2.0.
         | 
| 6 6 |  | 
| 7 7 |  | 
| 8 8 | 
             
            == DESCRIPTION
         | 
| @@ -58,7 +58,7 @@ Travis CI::     https://travis-ci.org/blackwinter/nuggets | |
| 58 58 |  | 
| 59 59 | 
             
            == LICENSE AND COPYRIGHT
         | 
| 60 60 |  | 
| 61 | 
            -
            Copyright (C) 2007- | 
| 61 | 
            +
            Copyright (C) 2007-2015 Jens Wille
         | 
| 62 62 |  | 
| 63 63 | 
             
            nuggets is free software: you can redistribute it and/or modify it
         | 
| 64 64 | 
             
            under the terms of the GNU Affero General Public License as published by
         | 
    
        data/Rakefile
    CHANGED
    
    
| @@ -1,66 +1,5 @@ | |
| 1 | 
            -
             | 
| 2 | 
            -
            ###############################################################################
         | 
| 3 | 
            -
            #                                                                             #
         | 
| 4 | 
            -
            # nuggets -- Extending Ruby                                                   #
         | 
| 5 | 
            -
            #                                                                             #
         | 
| 6 | 
            -
            # Copyright (C) 2007-2011 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 | 
            -
            #++
         | 
| 1 | 
            +
            require 'nuggets/enumerable/all_any_extended_mixin'
         | 
| 26 2 |  | 
| 27 | 
            -
             | 
| 28 | 
            -
             | 
| 29 | 
            -
             | 
| 30 | 
            -
              alias_method :_nuggets_original_any?, :any?
         | 
| 31 | 
            -
             | 
| 32 | 
            -
              # call-seq:
         | 
| 33 | 
            -
              #   enum.all?(obj[, operator]) => +true+ or +false+
         | 
| 34 | 
            -
              #   enum.all? { ... } => +true+ or +false+
         | 
| 35 | 
            -
              #
         | 
| 36 | 
            -
              # Adds the ability to pass an +object+ instead of a block, which will then
         | 
| 37 | 
            -
              # be tested against each item in _enum_ according to +operator+, defaulting
         | 
| 38 | 
            -
              # to <tt>:===</tt>.
         | 
| 39 | 
            -
              def all?(object = default = true, operator = :===, &block)
         | 
| 40 | 
            -
                _nuggets_original_all?(&_block_for_all_any_extended(object, default, operator, &block))
         | 
| 41 | 
            -
              end
         | 
| 42 | 
            -
             | 
| 43 | 
            -
              # call-seq:
         | 
| 44 | 
            -
              #   enum.any?(obj[, operator]) => +true+ or +false+
         | 
| 45 | 
            -
              #   enum.any? { ... } => +true+ or +false+
         | 
| 46 | 
            -
              #
         | 
| 47 | 
            -
              # Adds the ability to pass an +object+ instead of a block, which will then
         | 
| 48 | 
            -
              # be tested against each item in _enum_ according to +operator+, defaulting
         | 
| 49 | 
            -
              # to <tt>:===</tt>.
         | 
| 50 | 
            -
              def any?(object = default = true, operator = :===, &block)
         | 
| 51 | 
            -
                _nuggets_original_any?(&_block_for_all_any_extended(object, default, operator, &block))
         | 
| 52 | 
            -
              end
         | 
| 53 | 
            -
             | 
| 54 | 
            -
              private
         | 
| 55 | 
            -
             | 
| 56 | 
            -
              # Common argument processing for extended versions of #all? and #any?.
         | 
| 57 | 
            -
              def _block_for_all_any_extended(object, default, operator, &block)
         | 
| 58 | 
            -
                unless default
         | 
| 59 | 
            -
                  raise ::ArgumentError, 'both block and object argument given', caller(1) if block
         | 
| 60 | 
            -
                  lambda { |*a| object.send(operator, *a) }
         | 
| 61 | 
            -
                else
         | 
| 62 | 
            -
                  block
         | 
| 63 | 
            -
                end
         | 
| 64 | 
            -
              end
         | 
| 65 | 
            -
             | 
| 66 | 
            -
            end
         | 
| 3 | 
            +
            [Array, Hash, IO, Range].each { |klass|
         | 
| 4 | 
            +
              klass.send klass.respond_to?(:prepend) ? :prepend : :include, Nuggets::Enumerable::AllAnyExtendedMixin
         | 
| 5 | 
            +
            }
         | 
| @@ -0,0 +1,65 @@ | |
| 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 | 
            +
              module Enumerable
         | 
| 29 | 
            +
                module AllAnyExtendedMixin
         | 
| 30 | 
            +
             | 
| 31 | 
            +
              # call-seq:
         | 
| 32 | 
            +
              #   enum.all?(obj[, operator]) => +true+ or +false+
         | 
| 33 | 
            +
              #   enum.all? { ... } => +true+ or +false+
         | 
| 34 | 
            +
              #
         | 
| 35 | 
            +
              # Adds the ability to pass an +object+ instead of a block, which will then
         | 
| 36 | 
            +
              # be tested against each item in _enum_ according to +operator+, defaulting
         | 
| 37 | 
            +
              # to <tt>:===</tt>.
         | 
| 38 | 
            +
              def all?(object = default = true, operator = :===, &block)
         | 
| 39 | 
            +
                super(&_block_for_all_any_extended(object, default, operator, &block))
         | 
| 40 | 
            +
              end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
              # call-seq:
         | 
| 43 | 
            +
              #   enum.any?(obj[, operator]) => +true+ or +false+
         | 
| 44 | 
            +
              #   enum.any? { ... } => +true+ or +false+
         | 
| 45 | 
            +
              #
         | 
| 46 | 
            +
              # Adds the ability to pass an +object+ instead of a block, which will then
         | 
| 47 | 
            +
              # be tested against each item in _enum_ according to +operator+, defaulting
         | 
| 48 | 
            +
              # to <tt>:===</tt>.
         | 
| 49 | 
            +
              def any?(object = default = true, operator = :===, &block)
         | 
| 50 | 
            +
                super(&_block_for_all_any_extended(object, default, operator, &block))
         | 
| 51 | 
            +
              end
         | 
| 52 | 
            +
             | 
| 53 | 
            +
              private
         | 
| 54 | 
            +
             | 
| 55 | 
            +
              # Common argument processing for extended versions of #all? and #any?.
         | 
| 56 | 
            +
              def _block_for_all_any_extended(object, default, operator, &block)
         | 
| 57 | 
            +
                default ? block : begin
         | 
| 58 | 
            +
                  raise ::ArgumentError, 'both block and object argument given', caller(1) if block
         | 
| 59 | 
            +
                  lambda { |*a| object.send(operator, *a) }
         | 
| 60 | 
            +
                end
         | 
| 61 | 
            +
              end
         | 
| 62 | 
            +
             | 
| 63 | 
            +
                end
         | 
| 64 | 
            +
              end
         | 
| 65 | 
            +
            end
         | 
| @@ -0,0 +1,79 @@ | |
| 1 | 
            +
            #--
         | 
| 2 | 
            +
            ###############################################################################
         | 
| 3 | 
            +
            #                                                                             #
         | 
| 4 | 
            +
            # nuggets -- Extending Ruby                                                   #
         | 
| 5 | 
            +
            #                                                                             #
         | 
| 6 | 
            +
            # Copyright (C) 2007-2015 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 Hash
         | 
| 29 | 
            +
                module DeprocMixin
         | 
| 30 | 
            +
             | 
| 31 | 
            +
              # call-seq:
         | 
| 32 | 
            +
              #   hash.deproc -> aProc
         | 
| 33 | 
            +
              #   hash.deproc { |proc| ... } -> anObject
         | 
| 34 | 
            +
              #
         | 
| 35 | 
            +
              # Removes the default proc from _hash_. If a block is given, yields the proc
         | 
| 36 | 
            +
              # to the block, restores the default proc afterwards and returns the block's
         | 
| 37 | 
            +
              # return value. Otherwise, returns the proc.
         | 
| 38 | 
            +
              #
         | 
| 39 | 
            +
              # Example:
         | 
| 40 | 
            +
              #
         | 
| 41 | 
            +
              #   h = Hash.new { |h, k| h[k] = [] }
         | 
| 42 | 
            +
              #   h.deproc { |_h| Marshal.dump(_h) }  #=> ...dump data...
         | 
| 43 | 
            +
              #   h.default_proc  #=> #<Proc:...>
         | 
| 44 | 
            +
              #
         | 
| 45 | 
            +
              # NOTE: Requires Ruby >= 2.0
         | 
| 46 | 
            +
              def deproc
         | 
| 47 | 
            +
                default_proc, self.default_proc = self.default_proc, nil
         | 
| 48 | 
            +
                return default_proc unless block_given?
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                begin
         | 
| 51 | 
            +
                  yield self
         | 
| 52 | 
            +
                ensure
         | 
| 53 | 
            +
                  self.default_proc = default_proc
         | 
| 54 | 
            +
                end
         | 
| 55 | 
            +
              end
         | 
| 56 | 
            +
             | 
| 57 | 
            +
              # call-seq:
         | 
| 58 | 
            +
              #   hash.deproc! -> _hash_ or nil
         | 
| 59 | 
            +
              #
         | 
| 60 | 
            +
              # Removes the default proc from _hash_, if present, and returns _hash_.
         | 
| 61 | 
            +
              # Otherwise, returns +nil+.
         | 
| 62 | 
            +
              #
         | 
| 63 | 
            +
              # Example:
         | 
| 64 | 
            +
              #
         | 
| 65 | 
            +
              #   h = Hash.new { |h, k| h[k] = [] }
         | 
| 66 | 
            +
              #   Marshal.dump(h.deproc!)  #=> ...dump data...
         | 
| 67 | 
            +
              #   h.default_proc  #=> nil
         | 
| 68 | 
            +
              #
         | 
| 69 | 
            +
              # NOTE: Requires Ruby >= 2.0
         | 
| 70 | 
            +
              def deproc!
         | 
| 71 | 
            +
                return unless default_proc
         | 
| 72 | 
            +
             | 
| 73 | 
            +
                self.default_proc = nil
         | 
| 74 | 
            +
                self
         | 
| 75 | 
            +
              end
         | 
| 76 | 
            +
             | 
| 77 | 
            +
                end
         | 
| 78 | 
            +
              end
         | 
| 79 | 
            +
            end
         | 
| @@ -3,7 +3,7 @@ | |
| 3 3 | 
             
            #                                                                             #
         | 
| 4 4 | 
             
            # nuggets -- Extending Ruby                                                   #
         | 
| 5 5 | 
             
            #                                                                             #
         | 
| 6 | 
            -
            # Copyright (C) 2007- | 
| 6 | 
            +
            # Copyright (C) 2007-2014 Jens Wille                                          #
         | 
| 7 7 | 
             
            #                                                                             #
         | 
| 8 8 | 
             
            # Authors:                                                                    #
         | 
| 9 9 | 
             
            #     Jens Wille <jens.wille@gmail.com>                                       #
         | 
| @@ -24,11 +24,13 @@ | |
| 24 24 | 
             
            ###############################################################################
         | 
| 25 25 | 
             
            #++
         | 
| 26 26 |  | 
| 27 | 
            +
            require 'nuggets/ruby_mixin'
         | 
| 28 | 
            +
             | 
| 27 29 | 
             
            module Nuggets
         | 
| 28 30 | 
             
              class IO
         | 
| 29 31 | 
             
                module NullMixin
         | 
| 30 32 |  | 
| 31 | 
            -
                  NULL = case ::RUBY_PLATFORM
         | 
| 33 | 
            +
                  NULL = case RubyMixin::RUBY_PLATFORM
         | 
| 32 34 | 
             
                    when /mswin|mingw/i then 'NUL'
         | 
| 33 35 | 
             
                    when /openvms/i     then 'NL:'
         | 
| 34 36 | 
             
                    when /amiga/i       then 'NIL:'
         | 
| @@ -31,13 +31,11 @@ module Nuggets | |
| 31 31 | 
             
                module LazyAttrMixin
         | 
| 32 32 |  | 
| 33 33 | 
             
              def lazy_accessor(name, options = {}, &block)
         | 
| 34 | 
            -
                 | 
| 35 | 
            -
                lazy_reader(name, options, &block)
         | 
| 34 | 
            +
                attr_writer(attr = lazy_name(name, options))
         | 
| 35 | 
            +
                lazy_reader(name, options, attr, &block)
         | 
| 36 36 | 
             
              end
         | 
| 37 37 |  | 
| 38 | 
            -
              def lazy_reader(name, options = {}, &block)
         | 
| 39 | 
            -
                attr = lazy_name(name, options)
         | 
| 40 | 
            -
             | 
| 38 | 
            +
              def lazy_reader(name, options = {}, attr = lazy_name(name, options), &block)
         | 
| 41 39 | 
             
                define_method(name) { lazy_attr(attr,
         | 
| 42 40 | 
             
                  options.fetch(:freeze, true), &block) }
         | 
| 43 41 | 
             
              end
         | 
| @@ -0,0 +1,45 @@ | |
| 1 | 
            +
            #--
         | 
| 2 | 
            +
            ###############################################################################
         | 
| 3 | 
            +
            #                                                                             #
         | 
| 4 | 
            +
            # nuggets -- Extending Ruby                                                   #
         | 
| 5 | 
            +
            #                                                                             #
         | 
| 6 | 
            +
            # Copyright (C) 2007-2015 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 | 
            +
            require 'net/ssh'
         | 
| 28 | 
            +
             | 
| 29 | 
            +
            class Net::SSH::Connection::Session
         | 
| 30 | 
            +
             | 
| 31 | 
            +
              def exec_sudo(command, prompt = /password/, &block)
         | 
| 32 | 
            +
                block ||= lambda { |data| ask(data) { |q| q.echo = false } }
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                open_channel { |ch|
         | 
| 35 | 
            +
                  ch.request_pty
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                  ch.exec("sudo #{command}") { ch.on_data { |_, data|
         | 
| 38 | 
            +
                    ch.send_data("#{block[data]}\n") if data =~ prompt
         | 
| 39 | 
            +
                  } }
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                  ch.wait
         | 
| 42 | 
            +
                }
         | 
| 43 | 
            +
              end
         | 
| 44 | 
            +
             | 
| 45 | 
            +
            end
         | 
    
        data/lib/nuggets/ruby.rb
    CHANGED
    
    | @@ -24,199 +24,20 @@ | |
| 24 24 | 
             
            ###############################################################################
         | 
| 25 25 | 
             
            #++
         | 
| 26 26 |  | 
| 27 | 
            -
            require ' | 
| 27 | 
            +
            require 'nuggets/ruby_mixin'
         | 
| 28 28 |  | 
| 29 29 | 
             
            module Nuggets
         | 
| 30 | 
            -
             | 
| 31 | 
            -
              # Originally based on Phusion Passenger's
         | 
| 32 | 
            -
              # {PlatformInfo}[https://github.com/FooBarWidget/passenger/blob/release-3.0.2/lib/phusion_passenger/platform_info/ruby.rb]
         | 
| 33 | 
            -
              # module.
         | 
| 34 | 
            -
              #
         | 
| 35 | 
            -
              #--
         | 
| 36 | 
            -
              # Phusion Passenger - http://www.modrails.com/
         | 
| 37 | 
            -
              # Copyright (c) 2010 Phusion
         | 
| 38 | 
            -
              #
         | 
| 39 | 
            -
              # "Phusion Passenger" is a trademark of Hongli Lai & Ninh Bui.
         | 
| 40 | 
            -
              #
         | 
| 41 | 
            -
              # Permission is hereby granted, free of charge, to any person obtaining a
         | 
| 42 | 
            -
              # copy of this software and associated documentation files (the "Software"),
         | 
| 43 | 
            -
              # to deal in the Software without restriction, including without limitation
         | 
| 44 | 
            -
              # the rights to use, copy, modify, merge, publish, distribute, sublicense,
         | 
| 45 | 
            -
              # and/or sell copies of the Software, and to permit persons to whom the
         | 
| 46 | 
            -
              # Software is furnished to do so, subject to the following conditions:
         | 
| 47 | 
            -
              #
         | 
| 48 | 
            -
              # The above copyright notice and this permission notice shall be included in
         | 
| 49 | 
            -
              # all copies or substantial portions of the Software.
         | 
| 50 | 
            -
              #++
         | 
| 51 | 
            -
             | 
| 52 30 | 
             
              module Ruby
         | 
| 53 31 |  | 
| 32 | 
            +
                include RubyMixin
         | 
| 54 33 | 
             
                extend self
         | 
| 55 34 |  | 
| 56 | 
            -
                CONFIG = ::RbConfig::CONFIG
         | 
| 57 | 
            -
             | 
| 58 | 
            -
                # Store original $GEM_HOME value so that even if the app customizes
         | 
| 59 | 
            -
                # $GEM_HOME we can still work with the original value.
         | 
| 60 | 
            -
                if gem_home = ::ENV['GEM_HOME']
         | 
| 61 | 
            -
                  gem_home = gem_home.strip.freeze
         | 
| 62 | 
            -
                  gem_home = nil if gem_home.empty?
         | 
| 63 | 
            -
                end
         | 
| 64 | 
            -
             | 
| 65 | 
            -
                GEM_HOME = gem_home
         | 
| 66 | 
            -
             | 
| 67 | 
            -
                RUBY_ENGINE = defined?(::RUBY_ENGINE) ? ::RUBY_ENGINE : 'ruby'
         | 
| 68 | 
            -
             | 
| 69 | 
            -
                OSX_RUBY_RE = %r{\A/System/Library/Frameworks/Ruby.framework/Versions/.*?/usr/bin/ruby\Z}
         | 
| 70 | 
            -
             | 
| 71 | 
            -
                # Returns correct command for invoking the current Ruby interpreter.
         | 
| 72 | 
            -
                def ruby_command
         | 
| 73 | 
            -
                  defined?(@ruby_command) ? @ruby_command : @ruby_command = ruby_executable
         | 
| 74 | 
            -
                end
         | 
| 75 | 
            -
             | 
| 76 | 
            -
                attr_writer :ruby_command
         | 
| 77 | 
            -
             | 
| 78 | 
            -
                # Returns the full path to the current Ruby interpreter's executable file.
         | 
| 79 | 
            -
                # This might not be the actual correct command to use for invoking the Ruby
         | 
| 80 | 
            -
                # interpreter; use ruby_command instead.
         | 
| 81 | 
            -
                def ruby_executable
         | 
| 82 | 
            -
                  @ruby_executable ||= begin
         | 
| 83 | 
            -
                    dir, name, ext = CONFIG.values_at(*%w[bindir RUBY_INSTALL_NAME EXEEXT])
         | 
| 84 | 
            -
                    ::File.join(dir, name + ext).sub(/.*\s.*/m, '"\&"')
         | 
| 85 | 
            -
                  end
         | 
| 86 | 
            -
                end
         | 
| 87 | 
            -
             | 
| 88 | 
            -
                attr_writer :ruby_executable
         | 
| 89 | 
            -
             | 
| 90 | 
            -
                # Locates a Ruby tool command +name+, e.g. 'gem', 'rake', 'bundle', etc. Instead
         | 
| 91 | 
            -
                # of naively looking in $PATH, this function uses a variety of search heuristics
         | 
| 92 | 
            -
                # to find the command that's really associated with the current Ruby interpreter.
         | 
| 93 | 
            -
                # It should never locate a command that's actually associated with a different
         | 
| 94 | 
            -
                # Ruby interpreter.
         | 
| 95 | 
            -
                #
         | 
| 96 | 
            -
                # NOTE: The return value may not be the actual correct invocation for the tool.
         | 
| 97 | 
            -
                # Use command_for_ruby_tool for that.
         | 
| 98 | 
            -
                #
         | 
| 99 | 
            -
                # Returns +nil+ when nothing's found.
         | 
| 100 | 
            -
                def locate_ruby_tool(name, extensions = ['', CONFIG['EXEEXT']].compact.uniq)
         | 
| 101 | 
            -
                  # Deduce Ruby's --program-prefix and --program-suffix from its install name
         | 
| 102 | 
            -
                  # and transform the given input name accordingly.
         | 
| 103 | 
            -
                  #
         | 
| 104 | 
            -
                  #   "rake" => "jrake", "rake1.8", etc.
         | 
| 105 | 
            -
                  [name, CONFIG['RUBY_INSTALL_NAME'].sub('ruby', name)].uniq.each { |basename|
         | 
| 106 | 
            -
                    extensions.each { |ext|
         | 
| 107 | 
            -
                      result = locate_ruby_tool_by_basename(basename + ext) and return result
         | 
| 108 | 
            -
                    }
         | 
| 109 | 
            -
                  }
         | 
| 110 | 
            -
             | 
| 111 | 
            -
                  nil
         | 
| 112 | 
            -
                end
         | 
| 113 | 
            -
             | 
| 114 | 
            -
                # Returns the correct command string for invoking the +name+ executable
         | 
| 115 | 
            -
                # that belongs to the current Ruby interpreter. Returns +nil+ if the
         | 
| 116 | 
            -
                # command is not found.
         | 
| 117 | 
            -
                #
         | 
| 118 | 
            -
                # If the command executable is a Ruby program, then we need to run it
         | 
| 119 | 
            -
                # in the correct Ruby interpreter just in case the command doesn't
         | 
| 120 | 
            -
                # have the correct shebang line; we don't want a totally different
         | 
| 121 | 
            -
                # Ruby than the current one to be invoked.
         | 
| 122 | 
            -
                def command_for_ruby_tool(name)
         | 
| 123 | 
            -
                  filename = respond_to?(name) ? send(name) : locate_ruby_tool(name)
         | 
| 124 | 
            -
                  shebang_command(filename) =~ /ruby/ ? "#{ruby_command} #{filename}" : filename
         | 
| 125 | 
            -
                end
         | 
| 126 | 
            -
             | 
| 127 | 
            -
                def self.define_ruby_tool(name)
         | 
| 128 | 
            -
                  class_eval <<-EOT, __FILE__, __LINE__ + 1
         | 
| 129 | 
            -
                    def #{name}
         | 
| 130 | 
            -
                      @#{name} ||= locate_ruby_tool('#{name}')
         | 
| 131 | 
            -
                    end
         | 
| 132 | 
            -
             | 
| 133 | 
            -
                    attr_writer :#{name}
         | 
| 134 | 
            -
             | 
| 135 | 
            -
                    def #{name}_command
         | 
| 136 | 
            -
                      @#{name}_command ||= command_for_ruby_tool('#{name}')
         | 
| 137 | 
            -
                    end
         | 
| 138 | 
            -
             | 
| 139 | 
            -
                    attr_writer :#{name}_command
         | 
| 140 | 
            -
                  EOT
         | 
| 141 | 
            -
                end
         | 
| 142 | 
            -
             | 
| 143 | 
            -
                %w[gem rake rspec].each { |name| define_ruby_tool(name) }
         | 
| 144 | 
            -
             | 
| 145 | 
            -
                def ruby_options_to_argv(args, ruby_command = ruby_command())
         | 
| 146 | 
            -
                  argv = [ruby_command]
         | 
| 147 | 
            -
             | 
| 148 | 
            -
                  ruby_options_from_hash(args.pop, argv) if args.last.is_a?(::Hash)
         | 
| 149 | 
            -
             | 
| 150 | 
            -
                  argv.concat(args.map! { |arg| arg.to_s.strip })
         | 
| 151 | 
            -
                end
         | 
| 152 | 
            -
             | 
| 153 | 
            -
                def ruby_options_from_hash(hash, argv = [])
         | 
| 154 | 
            -
                  hash.each { |key, val|
         | 
| 155 | 
            -
                    opt = "-#{key.to_s[0, 1]}"
         | 
| 156 | 
            -
             | 
| 157 | 
            -
                    if val.is_a?(::Array)
         | 
| 158 | 
            -
                      val.each { |v| argv << opt << v.to_s }
         | 
| 159 | 
            -
                    elsif opt == '-e'
         | 
| 160 | 
            -
                      argv << opt << val.to_s
         | 
| 161 | 
            -
                    elsif val != false
         | 
| 162 | 
            -
                      argv << "#{opt}#{val unless val == true}"
         | 
| 163 | 
            -
                    end
         | 
| 164 | 
            -
                  }
         | 
| 165 | 
            -
             | 
| 166 | 
            -
                  argv
         | 
| 167 | 
            -
                end
         | 
| 168 | 
            -
             | 
| 169 | 
            -
                private
         | 
| 170 | 
            -
             | 
| 171 | 
            -
                def locate_ruby_tool_by_basename(name)
         | 
| 172 | 
            -
                  # On OS X we must look for Ruby binaries in /usr/bin.
         | 
| 173 | 
            -
                  # RubyGems puts executables (e.g. 'rake') in there, not in
         | 
| 174 | 
            -
                  # /System/Libraries/(...)/bin.
         | 
| 175 | 
            -
                  dir = ::RUBY_PLATFORM =~ /darwin/ && ruby_command =~ OSX_RUBY_RE ?
         | 
| 176 | 
            -
                    '/usr/bin' : ::File.dirname(ruby_command)
         | 
| 177 | 
            -
             | 
| 178 | 
            -
                  filename = executable_filename(dir, name) and return filename
         | 
| 179 | 
            -
             | 
| 180 | 
            -
                  # RubyGems might put binaries in a directory other
         | 
| 181 | 
            -
                  # than Ruby's bindir. Debian packaged RubyGems and
         | 
| 182 | 
            -
                  # DebGem packaged RubyGems are the prime examples.
         | 
| 183 | 
            -
                  filename = executable_filename(::Gem.bindir, name) and return filename
         | 
| 184 | 
            -
             | 
| 185 | 
            -
                  # Looks like it's not in the RubyGems bindir. Search in $PATH, but
         | 
| 186 | 
            -
                  # be very careful about this because whatever we find might belong
         | 
| 187 | 
            -
                  # to a different Ruby interpreter than the current one.
         | 
| 188 | 
            -
                  ::ENV['PATH'].split(::File::PATH_SEPARATOR).each { |path|
         | 
| 189 | 
            -
                    if filename = executable_filename(path, name)
         | 
| 190 | 
            -
                      return filename if shebang_command(filename) == ruby_command
         | 
| 191 | 
            -
                    end
         | 
| 192 | 
            -
                  }
         | 
| 193 | 
            -
             | 
| 194 | 
            -
                  nil
         | 
| 195 | 
            -
                end
         | 
| 196 | 
            -
             | 
| 197 | 
            -
                def executable_filename(dir, name)
         | 
| 198 | 
            -
                  filename = ::File.join(dir, name)
         | 
| 199 | 
            -
                  filename if ::File.file?(filename) && ::File.executable?(filename)
         | 
| 200 | 
            -
                end
         | 
| 201 | 
            -
             | 
| 202 | 
            -
                def shebang_command(filename)
         | 
| 203 | 
            -
                  ::File.foreach(filename) { |line|
         | 
| 204 | 
            -
                    return $1 if line =~ /\A#!\s*(\S*)/
         | 
| 205 | 
            -
             | 
| 206 | 
            -
                    # Allow one extra line for magic comment.
         | 
| 207 | 
            -
                    break if $. > 1
         | 
| 208 | 
            -
                  }
         | 
| 209 | 
            -
             | 
| 210 | 
            -
                  nil
         | 
| 211 | 
            -
                end
         | 
| 212 | 
            -
             | 
| 213 35 | 
             
              end
         | 
| 214 | 
            -
             | 
| 215 36 | 
             
            end
         | 
| 216 37 |  | 
| 217 38 | 
             
            def File.ruby; ::Nuggets::Ruby.ruby_command; end
         | 
| 218 39 |  | 
| 219 | 
            -
            if  | 
| 40 | 
            +
            if RUBY_ENGINE == 'jruby'
         | 
| 220 41 | 
             
              def Process.ruby(*args, &block)
         | 
| 221 42 | 
             
                argv = ::Nuggets::Ruby.ruby_options_to_argv(args)
         | 
| 222 43 | 
             
                ::IO.popen4(*argv, &block); $?
         | 
| @@ -0,0 +1,215 @@ | |
| 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 | 
            +
            require 'rbconfig'
         | 
| 28 | 
            +
             | 
| 29 | 
            +
            module Nuggets
         | 
| 30 | 
            +
             | 
| 31 | 
            +
              # Originally based on Phusion Passenger's
         | 
| 32 | 
            +
              # {PlatformInfo}[https://github.com/FooBarWidget/passenger/blob/release-3.0.2/lib/phusion_passenger/platform_info/ruby.rb]
         | 
| 33 | 
            +
              # module.
         | 
| 34 | 
            +
              #
         | 
| 35 | 
            +
              #--
         | 
| 36 | 
            +
              # Phusion Passenger - http://www.modrails.com/
         | 
| 37 | 
            +
              # Copyright (c) 2010 Phusion
         | 
| 38 | 
            +
              #
         | 
| 39 | 
            +
              # "Phusion Passenger" is a trademark of Hongli Lai & Ninh Bui.
         | 
| 40 | 
            +
              #
         | 
| 41 | 
            +
              # Permission is hereby granted, free of charge, to any person obtaining a
         | 
| 42 | 
            +
              # copy of this software and associated documentation files (the "Software"),
         | 
| 43 | 
            +
              # to deal in the Software without restriction, including without limitation
         | 
| 44 | 
            +
              # the rights to use, copy, modify, merge, publish, distribute, sublicense,
         | 
| 45 | 
            +
              # and/or sell copies of the Software, and to permit persons to whom the
         | 
| 46 | 
            +
              # Software is furnished to do so, subject to the following conditions:
         | 
| 47 | 
            +
              #
         | 
| 48 | 
            +
              # The above copyright notice and this permission notice shall be included in
         | 
| 49 | 
            +
              # all copies or substantial portions of the Software.
         | 
| 50 | 
            +
              #++
         | 
| 51 | 
            +
             | 
| 52 | 
            +
              module RubyMixin
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                CONFIG = ::RbConfig::CONFIG
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                # Store original $GEM_HOME value so that even if the app customizes
         | 
| 57 | 
            +
                # $GEM_HOME we can still work with the original value.
         | 
| 58 | 
            +
                if gem_home = ::ENV['GEM_HOME']
         | 
| 59 | 
            +
                  gem_home = gem_home.strip.freeze
         | 
| 60 | 
            +
                  gem_home = nil if gem_home.empty?
         | 
| 61 | 
            +
                end
         | 
| 62 | 
            +
             | 
| 63 | 
            +
                GEM_HOME = gem_home
         | 
| 64 | 
            +
             | 
| 65 | 
            +
                RUBY_ENGINE = defined?(::RUBY_ENGINE) ? ::RUBY_ENGINE : 'ruby'
         | 
| 66 | 
            +
             | 
| 67 | 
            +
                RUBY_PLATFORM = ::RUBY_ENGINE == 'jruby' ? CONFIG['target_os'] : ::RUBY_PLATFORM
         | 
| 68 | 
            +
             | 
| 69 | 
            +
                OSX_RUBY_RE = %r{\A/System/Library/Frameworks/Ruby.framework/Versions/.*?/usr/bin/ruby\Z}
         | 
| 70 | 
            +
             | 
| 71 | 
            +
                # Returns correct command for invoking the current Ruby interpreter.
         | 
| 72 | 
            +
                def ruby_command
         | 
| 73 | 
            +
                  defined?(@ruby_command) ? @ruby_command : @ruby_command = ruby_executable
         | 
| 74 | 
            +
                end
         | 
| 75 | 
            +
             | 
| 76 | 
            +
                attr_writer :ruby_command
         | 
| 77 | 
            +
             | 
| 78 | 
            +
                # Returns the full path to the current Ruby interpreter's executable file.
         | 
| 79 | 
            +
                # This might not be the actual correct command to use for invoking the Ruby
         | 
| 80 | 
            +
                # interpreter; use ruby_command instead.
         | 
| 81 | 
            +
                def ruby_executable
         | 
| 82 | 
            +
                  @ruby_executable ||= begin
         | 
| 83 | 
            +
                    dir, name, ext = CONFIG.values_at(*%w[bindir RUBY_INSTALL_NAME EXEEXT])
         | 
| 84 | 
            +
                    ::File.join(dir, name + ext).sub(/.*\s.*/m, '"\&"')
         | 
| 85 | 
            +
                  end
         | 
| 86 | 
            +
                end
         | 
| 87 | 
            +
             | 
| 88 | 
            +
                attr_writer :ruby_executable
         | 
| 89 | 
            +
             | 
| 90 | 
            +
                # Locates a Ruby tool command +name+, e.g. 'gem', 'rake', 'bundle', etc. Instead
         | 
| 91 | 
            +
                # of naively looking in $PATH, this function uses a variety of search heuristics
         | 
| 92 | 
            +
                # to find the command that's really associated with the current Ruby interpreter.
         | 
| 93 | 
            +
                # It should never locate a command that's actually associated with a different
         | 
| 94 | 
            +
                # Ruby interpreter.
         | 
| 95 | 
            +
                #
         | 
| 96 | 
            +
                # NOTE: The return value may not be the actual correct invocation for the tool.
         | 
| 97 | 
            +
                # Use command_for_ruby_tool for that.
         | 
| 98 | 
            +
                #
         | 
| 99 | 
            +
                # Returns +nil+ when nothing's found.
         | 
| 100 | 
            +
                def locate_ruby_tool(name, extensions = ['', CONFIG['EXEEXT']].compact.uniq)
         | 
| 101 | 
            +
                  # Deduce Ruby's --program-prefix and --program-suffix from its install name
         | 
| 102 | 
            +
                  # and transform the given input name accordingly.
         | 
| 103 | 
            +
                  #
         | 
| 104 | 
            +
                  #   "rake" => "jrake", "rake1.8", etc.
         | 
| 105 | 
            +
                  [name, CONFIG['RUBY_INSTALL_NAME'].sub('ruby', name)].uniq.each { |basename|
         | 
| 106 | 
            +
                    extensions.each { |ext|
         | 
| 107 | 
            +
                      result = locate_ruby_tool_by_basename(basename + ext) and return result
         | 
| 108 | 
            +
                    }
         | 
| 109 | 
            +
                  }
         | 
| 110 | 
            +
             | 
| 111 | 
            +
                  nil
         | 
| 112 | 
            +
                end
         | 
| 113 | 
            +
             | 
| 114 | 
            +
                # Returns the correct command string for invoking the +name+ executable
         | 
| 115 | 
            +
                # that belongs to the current Ruby interpreter. Returns +nil+ if the
         | 
| 116 | 
            +
                # command is not found.
         | 
| 117 | 
            +
                #
         | 
| 118 | 
            +
                # If the command executable is a Ruby program, then we need to run it
         | 
| 119 | 
            +
                # in the correct Ruby interpreter just in case the command doesn't
         | 
| 120 | 
            +
                # have the correct shebang line; we don't want a totally different
         | 
| 121 | 
            +
                # Ruby than the current one to be invoked.
         | 
| 122 | 
            +
                def command_for_ruby_tool(name)
         | 
| 123 | 
            +
                  filename = respond_to?(name) ? send(name) : locate_ruby_tool(name)
         | 
| 124 | 
            +
                  shebang_command(filename) =~ /ruby/ ? "#{ruby_command} #{filename}" : filename
         | 
| 125 | 
            +
                end
         | 
| 126 | 
            +
             | 
| 127 | 
            +
                def self.define_ruby_tool(name)
         | 
| 128 | 
            +
                  class_eval <<-EOT, __FILE__, __LINE__ + 1
         | 
| 129 | 
            +
                    def #{name}
         | 
| 130 | 
            +
                      @#{name} ||= locate_ruby_tool('#{name}')
         | 
| 131 | 
            +
                    end
         | 
| 132 | 
            +
             | 
| 133 | 
            +
                    attr_writer :#{name}
         | 
| 134 | 
            +
             | 
| 135 | 
            +
                    def #{name}_command
         | 
| 136 | 
            +
                      @#{name}_command ||= command_for_ruby_tool('#{name}')
         | 
| 137 | 
            +
                    end
         | 
| 138 | 
            +
             | 
| 139 | 
            +
                    attr_writer :#{name}_command
         | 
| 140 | 
            +
                  EOT
         | 
| 141 | 
            +
                end
         | 
| 142 | 
            +
             | 
| 143 | 
            +
                %w[gem rake rspec].each { |name| define_ruby_tool(name) }
         | 
| 144 | 
            +
             | 
| 145 | 
            +
                def ruby_options_to_argv(args, ruby_command = ruby_command())
         | 
| 146 | 
            +
                  argv = [ruby_command]
         | 
| 147 | 
            +
             | 
| 148 | 
            +
                  ruby_options_from_hash(args.pop, argv) if args.last.is_a?(::Hash)
         | 
| 149 | 
            +
             | 
| 150 | 
            +
                  argv.concat(args.map! { |arg| arg.to_s.strip })
         | 
| 151 | 
            +
                end
         | 
| 152 | 
            +
             | 
| 153 | 
            +
                def ruby_options_from_hash(hash, argv = [])
         | 
| 154 | 
            +
                  hash.each { |key, val|
         | 
| 155 | 
            +
                    opt = "-#{key.to_s[0, 1]}"
         | 
| 156 | 
            +
             | 
| 157 | 
            +
                    if val.is_a?(::Array)
         | 
| 158 | 
            +
                      val.each { |v| argv << opt << v.to_s }
         | 
| 159 | 
            +
                    elsif opt == '-e'
         | 
| 160 | 
            +
                      argv << opt << val.to_s
         | 
| 161 | 
            +
                    elsif val != false
         | 
| 162 | 
            +
                      argv << "#{opt}#{val unless val == true}"
         | 
| 163 | 
            +
                    end
         | 
| 164 | 
            +
                  }
         | 
| 165 | 
            +
             | 
| 166 | 
            +
                  argv
         | 
| 167 | 
            +
                end
         | 
| 168 | 
            +
             | 
| 169 | 
            +
                private
         | 
| 170 | 
            +
             | 
| 171 | 
            +
                def locate_ruby_tool_by_basename(name)
         | 
| 172 | 
            +
                  # On OS X we must look for Ruby binaries in /usr/bin.
         | 
| 173 | 
            +
                  # RubyGems puts executables (e.g. 'rake') in there, not in
         | 
| 174 | 
            +
                  # /System/Libraries/(...)/bin.
         | 
| 175 | 
            +
                  dir = ::RUBY_PLATFORM =~ /darwin/ && ruby_command =~ OSX_RUBY_RE ?
         | 
| 176 | 
            +
                    '/usr/bin' : ::File.dirname(ruby_command)
         | 
| 177 | 
            +
             | 
| 178 | 
            +
                  filename = executable_filename(dir, name) and return filename
         | 
| 179 | 
            +
             | 
| 180 | 
            +
                  # RubyGems might put binaries in a directory other
         | 
| 181 | 
            +
                  # than Ruby's bindir. Debian packaged RubyGems and
         | 
| 182 | 
            +
                  # DebGem packaged RubyGems are the prime examples.
         | 
| 183 | 
            +
                  filename = executable_filename(::Gem.bindir, name) and return filename
         | 
| 184 | 
            +
             | 
| 185 | 
            +
                  # Looks like it's not in the RubyGems bindir. Search in $PATH, but
         | 
| 186 | 
            +
                  # be very careful about this because whatever we find might belong
         | 
| 187 | 
            +
                  # to a different Ruby interpreter than the current one.
         | 
| 188 | 
            +
                  ::ENV['PATH'].split(::File::PATH_SEPARATOR).each { |path|
         | 
| 189 | 
            +
                    if filename = executable_filename(path, name)
         | 
| 190 | 
            +
                      return filename if shebang_command(filename) == ruby_command
         | 
| 191 | 
            +
                    end
         | 
| 192 | 
            +
                  }
         | 
| 193 | 
            +
             | 
| 194 | 
            +
                  nil
         | 
| 195 | 
            +
                end
         | 
| 196 | 
            +
             | 
| 197 | 
            +
                def executable_filename(dir, name)
         | 
| 198 | 
            +
                  filename = ::File.join(dir, name)
         | 
| 199 | 
            +
                  filename if ::File.file?(filename) && ::File.executable?(filename)
         | 
| 200 | 
            +
                end
         | 
| 201 | 
            +
             | 
| 202 | 
            +
                def shebang_command(filename)
         | 
| 203 | 
            +
                  ::File.foreach(filename) { |line|
         | 
| 204 | 
            +
                    return $1 if line =~ /\A#!\s*(\S*)/
         | 
| 205 | 
            +
             | 
| 206 | 
            +
                    # Allow one extra line for magic comment.
         | 
| 207 | 
            +
                    break if $. > 1
         | 
| 208 | 
            +
                  }
         | 
| 209 | 
            +
             | 
| 210 | 
            +
                  nil
         | 
| 211 | 
            +
                end
         | 
| 212 | 
            +
             | 
| 213 | 
            +
              end
         | 
| 214 | 
            +
             | 
| 215 | 
            +
            end
         | 
    
        data/lib/nuggets/version.rb
    CHANGED
    
    
| @@ -3,7 +3,7 @@ require 'nuggets/object/singleton_class' | |
| 3 3 | 
             
            describe_extended Object, Nuggets::Object::SingletonClassMixin do
         | 
| 4 4 |  | 
| 5 5 | 
             
              objects = [Class, Object.new, Class.new, 's', [1, 2], { :a => 'b' }]
         | 
| 6 | 
            -
              objects.unshift(Object) unless  | 
| 6 | 
            +
              objects.unshift(Object) unless %w[jruby rbx].include?(RUBY_ENGINE)
         | 
| 7 7 |  | 
| 8 8 | 
             
              objects.each { |o|
         | 
| 9 9 | 
             
                example { o.should_not be_a_singleton_class }
         | 
    
        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. | 
| 4 | 
            +
              version: 1.2.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:  | 
| 11 | 
            +
            date: 2015-03-13 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: mime-types
         | 
| @@ -47,7 +47,7 @@ dependencies: | |
| 47 47 | 
             
                    version: '0.8'
         | 
| 48 48 | 
             
                - - ">="
         | 
| 49 49 | 
             
                  - !ruby/object:Gem::Version
         | 
| 50 | 
            -
                    version: 0.8. | 
| 50 | 
            +
                    version: 0.8.1
         | 
| 51 51 | 
             
              type: :development
         | 
| 52 52 | 
             
              prerelease: false
         | 
| 53 53 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| @@ -57,7 +57,7 @@ dependencies: | |
| 57 57 | 
             
                    version: '0.8'
         | 
| 58 58 | 
             
                - - ">="
         | 
| 59 59 | 
             
                  - !ruby/object:Gem::Version
         | 
| 60 | 
            -
                    version: 0.8. | 
| 60 | 
            +
                    version: 0.8.1
         | 
| 61 61 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 62 62 | 
             
              name: rake
         | 
| 63 63 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -152,6 +152,7 @@ files: | |
| 152 152 | 
             
            - lib/nuggets/dotted_decimal.rb
         | 
| 153 153 | 
             
            - lib/nuggets/enumerable/agrep.rb
         | 
| 154 154 | 
             
            - lib/nuggets/enumerable/all_any_extended.rb
         | 
| 155 | 
            +
            - lib/nuggets/enumerable/all_any_extended_mixin.rb
         | 
| 155 156 | 
             
            - lib/nuggets/enumerable/minmax.rb
         | 
| 156 157 | 
             
            - lib/nuggets/env/set.rb
         | 
| 157 158 | 
             
            - lib/nuggets/env/set_mixin.rb
         | 
| @@ -172,6 +173,8 @@ files: | |
| 172 173 | 
             
            - lib/nuggets/hash/deep_fetch_mixin.rb
         | 
| 173 174 | 
             
            - lib/nuggets/hash/deep_merge.rb
         | 
| 174 175 | 
             
            - lib/nuggets/hash/deep_merge_mixin.rb
         | 
| 176 | 
            +
            - lib/nuggets/hash/deproc.rb
         | 
| 177 | 
            +
            - lib/nuggets/hash/deproc_mixin.rb
         | 
| 175 178 | 
             
            - lib/nuggets/hash/idmap.rb
         | 
| 176 179 | 
             
            - lib/nuggets/hash/idmap_mixin.rb
         | 
| 177 180 | 
             
            - lib/nuggets/hash/in_order.rb
         | 
| @@ -210,6 +213,7 @@ files: | |
| 210 213 | 
             
            - lib/nuggets/module/lazy_attr_mixin.rb
         | 
| 211 214 | 
             
            - lib/nuggets/module/query_attr.rb
         | 
| 212 215 | 
             
            - lib/nuggets/module/query_attr_mixin.rb
         | 
| 216 | 
            +
            - lib/nuggets/net/ssh.rb
         | 
| 213 217 | 
             
            - lib/nuggets/net/success.rb
         | 
| 214 218 | 
             
            - lib/nuggets/numeric/between.rb
         | 
| 215 219 | 
             
            - lib/nuggets/numeric/duration.rb
         | 
| @@ -241,6 +245,7 @@ files: | |
| 241 245 | 
             
            - lib/nuggets/range/quantile.rb
         | 
| 242 246 | 
             
            - lib/nuggets/range/quantile_mixin.rb
         | 
| 243 247 | 
             
            - lib/nuggets/ruby.rb
         | 
| 248 | 
            +
            - lib/nuggets/ruby_mixin.rb
         | 
| 244 249 | 
             
            - lib/nuggets/statistics.rb
         | 
| 245 250 | 
             
            - lib/nuggets/statistics_mixins.rb
         | 
| 246 251 | 
             
            - lib/nuggets/string/camelscore.rb
         | 
| @@ -344,17 +349,15 @@ licenses: | |
| 344 349 | 
             
            metadata: {}
         | 
| 345 350 | 
             
            post_install_message: |2+
         | 
| 346 351 |  | 
| 347 | 
            -
              nuggets-1. | 
| 352 | 
            +
              nuggets-1.2.0 [2015-03-13]:
         | 
| 348 353 |  | 
| 349 | 
            -
              * Nuggets:: | 
| 350 | 
            -
             | 
| 351 | 
            -
             | 
| 352 | 
            -
              * Added Object#rescue_if and Object#rescue_unless.
         | 
| 353 | 
            -
              * Added JRuby variant of Process.ruby.
         | 
| 354 | 
            +
              * Extracted Nuggets::RubyMixin from Nuggets::Ruby.
         | 
| 355 | 
            +
              * Added Net::SSH::Connection::Session#exec_sudo.
         | 
| 356 | 
            +
              * Added Hash.deproc.
         | 
| 354 357 |  | 
| 355 358 | 
             
            rdoc_options:
         | 
| 356 359 | 
             
            - "--title"
         | 
| 357 | 
            -
            - nuggets Application documentation (v1. | 
| 360 | 
            +
            - nuggets Application documentation (v1.2.0)
         | 
| 358 361 | 
             
            - "--charset"
         | 
| 359 362 | 
             
            - UTF-8
         | 
| 360 363 | 
             
            - "--line-numbers"
         | 
| @@ -375,7 +378,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 375 378 | 
             
                  version: '0'
         | 
| 376 379 | 
             
            requirements: []
         | 
| 377 380 | 
             
            rubyforge_project: 
         | 
| 378 | 
            -
            rubygems_version: 2.4. | 
| 381 | 
            +
            rubygems_version: 2.4.6
         | 
| 379 382 | 
             
            signing_key: 
         | 
| 380 383 | 
             
            specification_version: 4
         | 
| 381 384 | 
             
            summary: Extending Ruby.
         |