Sha256: 7963eadeb2b21a066e049c418d392a6caf85f29e6fd8342fb51f677b16b71e81

Contents?: true

Size: 1.52 KB

Versions: 12

Compression:

Stored size: 1.52 KB

Contents

# frozen_string_literal: true

# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require "tmpdir"
require "fileutils"

module Gapic
  ##
  # File Formatter
  class FileFormatter
    attr_reader :configuration, :files

    ##
    # Create a new file formatter object
    #
    def initialize configuration, files
      @configuration = configuration
      @files = format! configuration, files
    end

    protected

    def format! configuration, files
      Dir.mktmpdir do |dir|
        files.each do |file|
          write_file dir, file
        end

        system "rubocop --cache false -x #{dir} -o #{dir}/rubocop.out -c #{configuration}"

        files.each do |file|
          read_file dir, file
        end
      end
    end

    def write_file dir, file
      tmp_file = File.join dir, file.name
      FileUtils.mkdir_p File.dirname tmp_file
      File.write tmp_file, file.content
    end

    def read_file dir, file
      tmp_file = File.join dir, file.name
      file.content = File.read tmp_file
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
gapic-generator-0.6.15 lib/gapic/file_formatter.rb
gapic-generator-0.6.14 lib/gapic/file_formatter.rb
gapic-generator-0.6.13 lib/gapic/file_formatter.rb
gapic-generator-0.6.12 lib/gapic/file_formatter.rb
gapic-generator-0.6.11 lib/gapic/file_formatter.rb
gapic-generator-0.6.10 lib/gapic/file_formatter.rb
gapic-generator-0.6.9 lib/gapic/file_formatter.rb
gapic-generator-0.6.8 lib/gapic/file_formatter.rb
gapic-generator-0.6.7 lib/gapic/file_formatter.rb
gapic-generator-0.6.6 lib/gapic/file_formatter.rb
gapic-generator-0.6.5 lib/gapic/file_formatter.rb
gapic-generator-0.6.4 lib/gapic/file_formatter.rb