Sha256: a7988472783d9268063bfba4e0bf18810f013981099b6de25b0b7a6523e0186c

Contents?: true

Size: 950 Bytes

Versions: 8

Compression:

Stored size: 950 Bytes

Contents

require 'ruby_parser'
require 'rbconfig'

module Roodi
  module Core
    class Parser
      def parse(content, filename)
        silence_stream(STDERR) do
          return silent_parse(content, filename)
        end
      end

      private

      def silence_stream(stream)
        old_stream = stream.dup
        stream.reopen(null_stream_output)
        stream.sync = true
        yield
      ensure
        stream.reopen(old_stream)
      end

      def silent_parse(content, filename)
        @parser ||= RubyParser.new
        @parser.parse(content, filename)
      end

      def null_stream_output
        null_output_for_platform(RbConfig::CONFIG['host_os'])
      end

      def null_output_for_platform(host_os)
        case host_os
        when windows_host_os_matcher
          'NUL:'
        else
          '/dev/null'
        end
      end

      def windows_host_os_matcher
        /mingw|mswin32|cygwin/o
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
roodi-5.0.0 lib/roodi/core/parser.rb
roodi-4.1.1 lib/roodi/core/parser.rb
roodi-4.1.0 lib/roodi/core/parser.rb
roodi-4.0.0 lib/roodi/core/parser.rb
roodi-3.3.1 lib/roodi/core/parser.rb
roodi-3.3.0 lib/roodi/core/parser.rb
roodi-3.2.0 lib/roodi/core/parser.rb
roodi-3.1.1 lib/roodi/core/parser.rb