Sha256: f1b8cb628d74412814efb295c10145a5139082c501d0d2e9ca06f81ef4b9f297

Contents?: true

Size: 1.51 KB

Versions: 36

Compression:

Stored size: 1.51 KB

Contents

module RunLoop
  # @!visibility private
  #
  # A class for interacting with the strings tool
  class Strings

    # @!visibility private
    attr_reader :path

    # @!visibility private
    def initialize(path)
      @path = path

      if !Strings.valid_path?(path)
        raise ArgumentError,
%Q{File:

#{path}

must exist and not be a directory.
}
      end
    end

    # @!visibility private
    def to_s
      "#<STRINGS: #{path}>"
    end

    # @!visibility private
    def inspect
      to_s
    end

    # @!visibility private
    #
    # @return [RunLoop::Version] A version instance or nil if the file
    #   at path does not contain server version information.
    def server_version
      regex = /CALABASH VERSION: (\d+\.\d+\.\d+(\.pre\d+)?)/
      match = dump[regex, 0]

      if match
        str = match.split(":")[1]
        RunLoop::Version.new(str)
      else
        nil
      end
    end

    private

    # @!visibility private
    def dump
      args = ["strings", path]
      opts = { :log_cmd => true }

      hash = xcrun.run_command_in_context(args, opts)

      if hash[:exit_status] != 0
        raise RuntimeError,
%Q{Could not get strings info from file:

#{path}

#{args.join(" ")}

exited #{hash[:exit_status]} with the following output:

#{hash[:out]}
}
      end

      @dump = hash[:out]
    end

    # @!visibility private
    def self.valid_path?(path)
      File.exist?(path) && !File.directory?(path)
    end

    # @!visibility private
    def xcrun
      RunLoop::Xcrun.new
    end
  end
end

Version data entries

36 entries across 36 versions & 2 rubygems

Version Path
run_loop-2.3.2 lib/run_loop/strings.rb
run_loop-2.7.1 lib/run_loop/strings.rb
run_loop-2.7.0 lib/run_loop/strings.rb
run_loop-2.6.6 lib/run_loop/strings.rb
run_loop-2.6.5 lib/run_loop/strings.rb
run_loop-2.6.4 lib/run_loop/strings.rb
run_loop-2.6.3 lib/run_loop/strings.rb
run_loop-2.6.2 lib/run_loop/strings.rb
run_loop-2.6.1 lib/run_loop/strings.rb
run_loop-2.6.0 lib/run_loop/strings.rb
run_loop-2.5.4 lib/run_loop/strings.rb
run_loop-2.5.3 lib/run_loop/strings.rb
run_loop-2.5.2 lib/run_loop/strings.rb
run_loop-2.5.1 lib/run_loop/strings.rb
run_loop-2.5.0 lib/run_loop/strings.rb
run_loop-2.4.1 lib/run_loop/strings.rb
run_loop-2.4.0 lib/run_loop/strings.rb
run_loop_tcc-2.1.6 lib/run_loop/strings.rb
run_loop_tcc-2.1.5 lib/run_loop/strings.rb
run_loop-2.3.1 lib/run_loop/strings.rb