Sha256: 50b12cf9d2ecb657a34c90fd47a0f68b3243a65f344c837454027badd1c66963

Contents?: true

Size: 1.45 KB

Versions: 3

Compression:

Stored size: 1.45 KB

Contents

module Hexx
  module Suit

    # Contains utilitity classes
    module Utils

      # The utility sends multiline string to system
      #
      # Allows stubbing system calls in specifications.
      #
      # @example
      #   System.call %(
      #     inch --pedantic
      #     rubocop
      #   )
      #
      # @api private
      class System < String

        # Initializes multiline text to be sent to system
        #
        # Removes repetitive spaces from itself
        #
        # @param [#to_s] text
        #   Multiline text to be sent to system
        #
        # @return [undefined]
        def initialize(text)
          super
          strip!
          gsub!(/ {2,}/, " ")
        end

        # Returns non-empty lines without trailing spaces
        #
        # @return [Array<String>]
        def lines
          Array(super).map(&:strip).reject(&:empty?)
        end

        # Sends itself to system line by line
        #
        # @return [self]
        def call
          lines.each(&method(:system))

          self
        end

        # Sends multiline string to system
        #
        # @example (see Hexx::Suit::Utils::System)
        #
        # @param  (see #initialize)
        #
        # @return [Hexx::Suit::Utils::System]
        #   utility object (allows chaining)
        def self.call(text)
          new(text).call

          self
        end
      end # class System
    end # module Utils
  end # module Suit
end # module Hexx

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hexx-suit-0.2.2 lib/hexx/suit/utils/system.rb
hexx-suit-0.2.1 lib/hexx/suit/utils/system.rb
hexx-suit-0.2.0 lib/hexx/suit/utils/system.rb