Sha256: b75ef8a3e575fd48b16a17bdfe57968ed0f51181c0e99ae3b538c959aa631c80

Contents?: true

Size: 1.19 KB

Versions: 61

Compression:

Stored size: 1.19 KB

Contents

require 'pact/provider/help/content'
require 'fileutils'
require 'pact/consumer/configuration'

module Pact
  module Provider
    module Help
      class Write

        HELP_FILE_NAME = 'help.md'

        def self.call pact_jsons, reports_dir = Pact.configuration.reports_dir
          new(pact_jsons, reports_dir).call
        end

        def initialize pact_jsons, reports_dir
          @pact_jsons = pact_jsons
          @reports_dir = File.expand_path(reports_dir)
        end

        def call
          clean_reports_dir
          write
        end

        private

        attr_reader :reports_dir, :pact_jsons

        def clean_reports_dir
          raise "Cleaning report dir #{reports_dir} would delete project!" if reports_dir_contains_pwd
          FileUtils.rm_rf reports_dir
          FileUtils.mkdir_p reports_dir
        end

        def reports_dir_contains_pwd
          Dir.pwd.start_with?(reports_dir)
        end

        def write
          File.open(help_path, "w") { |file| file << help_text }
        end

        def help_path
          File.join(reports_dir, 'help.md')
        end

        def help_text
          Content.new(pact_jsons).text
        end

      end
    end
  end
end

Version data entries

61 entries across 61 versions & 1 rubygems

Version Path
pact-1.43.0 lib/pact/provider/help/write.rb
pact-1.42.3 lib/pact/provider/help/write.rb
pact-1.42.2 lib/pact/provider/help/write.rb
pact-1.42.1 lib/pact/provider/help/write.rb
pact-1.42.0 lib/pact/provider/help/write.rb
pact-1.41.2 lib/pact/provider/help/write.rb
pact-1.41.1 lib/pact/provider/help/write.rb
pact-1.41.0 lib/pact/provider/help/write.rb
pact-1.40.0 lib/pact/provider/help/write.rb
pact-1.39.0 lib/pact/provider/help/write.rb
pact-1.38.0 lib/pact/provider/help/write.rb
pact-1.37.0 lib/pact/provider/help/write.rb
pact-1.36.2 lib/pact/provider/help/write.rb
pact-1.36.0 lib/pact/provider/help/write.rb
pact-1.34.0 lib/pact/provider/help/write.rb
pact-1.33.2 lib/pact/provider/help/write.rb
pact-1.33.1 lib/pact/provider/help/write.rb
pact-1.33.0 lib/pact/provider/help/write.rb
pact-1.32.0 lib/pact/provider/help/write.rb
pact-1.31.0 lib/pact/provider/help/write.rb