Sha256: 1c17e3c05e8380e170a095d675684be59e7be8ad1ad25cc51b848feaac6db737

Contents?: true

Size: 1.08 KB

Versions: 4

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module ConvenientService
  module Examples
    module Standard
      module V1
        class Gemfile
          module Services
            class AssertValidRubySyntax
              include ConvenientService::Standard::V1::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::RunShellCommand.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
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
convenient_service-0.17.0 lib/convenient_service/examples/standard/v1/gemfile/services/assert_valid_ruby_syntax.rb
convenient_service-0.16.0 lib/convenient_service/examples/standard/v1/gemfile/services/assert_valid_ruby_syntax.rb
convenient_service-0.15.0 lib/convenient_service/examples/standard/v1/gemfile/services/assert_valid_ruby_syntax.rb
convenient_service-0.14.0 lib/convenient_service/examples/standard/v1/gemfile/services/assert_valid_ruby_syntax.rb