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.30.0 lib/pact/provider/help/write.rb
pact-1.29.0 lib/pact/provider/help/write.rb
pact-1.28.0 lib/pact/provider/help/write.rb
pact-1.28.0.rc1 lib/pact/provider/help/write.rb
pact-1.27.0 lib/pact/provider/help/write.rb
pact-1.26.0 lib/pact/provider/help/write.rb
pact-1.25.0 lib/pact/provider/help/write.rb
pact-1.24.0 lib/pact/provider/help/write.rb
pact-1.23.0 lib/pact/provider/help/write.rb
pact-1.22.2 lib/pact/provider/help/write.rb
pact-1.22.0 lib/pact/provider/help/write.rb
pact-1.21.0 lib/pact/provider/help/write.rb
pact-1.20.1 lib/pact/provider/help/write.rb
pact-1.20.0 lib/pact/provider/help/write.rb
pact-1.19.2 lib/pact/provider/help/write.rb
pact-1.19.1 lib/pact/provider/help/write.rb
pact-1.19.0 lib/pact/provider/help/write.rb
pact-1.18.0 lib/pact/provider/help/write.rb
pact-1.17.0 lib/pact/provider/help/write.rb
pact-1.16.1 lib/pact/provider/help/write.rb