Sha256: a688e28a12b43b064379856016e3ab584bc3973942165dd5055821ba1c47ae13

Contents?: true

Size: 1017 Bytes

Versions: 15

Compression:

Stored size: 1017 Bytes

Contents

# frozen_string_literal: true

module ConvenientService
  module Examples
    module Standard
      module Gemfile
        module Services
          class AssertValidRubySyntax
            include ConvenientService::Standard::Config

            attr_reader :content

            def initialize(content:)
              @content = content
            end

            def result
              ##
              # NOTE: `> /dev/null 2>&1` is used to hide output.
              # https://unix.stackexchange.com/a/119650/394253
              #
              check_ruby_syntax_result = Services::RunShell.result(command: "ruby -c #{file.path} > /dev/null 2>&1")

              return error("`#{content}` contains invalid Ruby syntax") unless check_ruby_syntax_result.success?

              success
            end

            private

            def file
              @file ||= ::Tempfile.new.tap { |tempfile| tempfile.write(content) }.tap(&:close)
            end
          end
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
convenient_service-0.12.0 lib/convenient_service/examples/standard/gemfile/services/assert_valid_ruby_syntax.rb
convenient_service-0.11.0 lib/convenient_service/examples/standard/gemfile/services/assert_valid_ruby_syntax.rb
convenient_service-0.10.1 lib/convenient_service/examples/standard/gemfile/services/assert_valid_ruby_syntax.rb
convenient_service-0.10.0 lib/convenient_service/examples/standard/gemfile/services/assert_valid_ruby_syntax.rb
convenient_service-0.9.0 lib/convenient_service/examples/standard/gemfile/services/assert_valid_ruby_syntax.rb
convenient_service-0.8.0 lib/convenient_service/examples/standard/gemfile/services/assert_valid_ruby_syntax.rb
convenient_service-0.7.0 lib/convenient_service/examples/standard/gemfile/services/assert_valid_ruby_syntax.rb
convenient_service-0.6.0 lib/convenient_service/examples/standard/gemfile/services/assert_valid_ruby_syntax.rb
convenient_service-0.5.0 lib/convenient_service/examples/standard/gemfile/services/assert_valid_ruby_syntax.rb
convenient_service-0.4.0 lib/convenient_service/examples/standard/gemfile/services/assert_valid_ruby_syntax.rb
convenient_service-0.3.1 lib/convenient_service/examples/standard/gemfile/services/assert_valid_ruby_syntax.rb
convenient_service-0.3.0 lib/convenient_service/examples/standard/gemfile/services/assert_valid_ruby_syntax.rb
convenient_service-0.2.1 lib/convenient_service/examples/standard/gemfile/services/assert_valid_ruby_syntax.rb
convenient_service-0.2.0 lib/convenient_service/examples/standard/gemfile/services/assert_valid_ruby_syntax.rb
convenient_service-0.1.0 lib/convenient_service/examples/standard/gemfile/services/assert_valid_ruby_syntax.rb