Sha256: e50d896ac263738b692bf54c96e6a1d0d936e67e947c7322a4dba0cd4a701786

Contents?: true

Size: 806 Bytes

Versions: 4

Compression:

Stored size: 806 Bytes

Contents

# frozen_string_literal: true

module RSGem
  module Tasks
    class CleanGemspec
      attr_reader :context

      KEYS_TO_EMPTY = %w[summary description homepage].freeze

      def initialize(context:)
        @context = context
      end

      def clean
        comment_metadata!
        empty_keys!
        write
      end

      private

      def gemspec
        @gemspec ||= File.read(context.gemspec_path)
      end

      def empty_keys!
        KEYS_TO_EMPTY.each do |key|
          gemspec.gsub!(/(spec.#{key}.*)=(.*)\n/, "\\1= ''\n")
        end
      end

      def comment_metadata!
        gemspec.gsub!(/spec.metadata/, '# spec.metadata')
      end

      def write
        File.open(context.gemspec_path, 'w') do |file|
          file.puts gemspec
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rsgem-0.1.3 lib/rsgem/tasks/clean_gemspec.rb
rsgem-0.1.2 lib/rsgem/tasks/clean_gemspec.rb
rsgem-0.1.1 lib/rsgem/tasks/clean_gemspec.rb
rsgem-0.1.0 lib/rsgem/tasks/clean_gemspec.rb