Sha256: c279da8991ed9d3deddf80283cb950234c0b94bf2b477e076133001bf7540245

Contents?: true

Size: 642 Bytes

Versions: 10

Compression:

Stored size: 642 Bytes

Contents

module RailsExecution
  module Services
    class SyntaxChecker
      OK_MESSAGE = 'Syntax OK'

      def initialize(code)
        @code = code
      end

      def call
        return false if code.blank?

        init_tempfile
        return is_ok?
      end

      private

      attr_reader :code

      def init_tempfile
        @file = ::Tempfile.new('syntax_checker')
        @file.binmode
        @file.write(code)
        @file.flush
        @file
      end

      def is_ok?
        result = `cat #{@file.path} | ruby -c`
        result.strip == OK_MESSAGE
      rescue SyntaxError
        return false
      end

    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rails_execution-0.1.12 lib/rails_execution/services/syntax_checker.rb
rails_execution-0.1.11 lib/rails_execution/services/syntax_checker.rb
rails_execution-0.1.10 lib/rails_execution/services/syntax_checker.rb
rails_execution-0.1.9 lib/rails_execution/services/syntax_checker.rb
rails_execution-0.1.8 lib/rails_execution/services/syntax_checker.rb
rails_execution-0.1.7 lib/rails_execution/services/syntax_checker.rb
rails_execution-0.1.5 lib/rails_execution/services/syntax_checker.rb
rails_execution-0.1.4 lib/rails_execution/services/syntax_checker.rb
rails_execution-0.1.2 lib/rails_execution/services/syntax_checker.rb
rails_execution-0.1.1 lib/rails_execution/services/syntax_checker.rb