Sha256: 9ccf2e8785ffcb937552212326723caa04ab6140f69484981f24c96e5a3ea9e2

Contents?: true

Size: 1.07 KB

Versions: 4

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

module RSGem
  module Tasks
    #
    # Gemfile should only have the gemspec directive.
    # An exception is when you need to develop against a gem that hasn't yet been released,
    # in this case you can declare that dependency in the Gemfile:
    #
    #   gem 'rack', github: 'rack/rack'
    #
    # gemspec is the place to declare dependencies.
    #
    # https://github.com/rootstrap/tech-guides/blob/master/open-source/developing_gems.md#gemfilegemfilelockgemspec
    #
    class CleanGemfile
      attr_reader :context

      def initialize(context:)
        @context = context
      end

      def clean
        gemfile.gsub!(/gem .+\n/, '') # Remove all gem definitions
        gemfile.sub!(/\n\z/, '') # Remove last new line character
        write_to_gemfile
        puts "\tGemfile cleaned"
      end

      private

      def gemfile
        @gemfile ||= File.read(context.gemfile_path)
      end

      def write_to_gemfile
        File.open(context.gemfile_path, 'w') do |file|
          file.puts gemfile
        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_gemfile.rb
rsgem-0.1.2 lib/rsgem/tasks/clean_gemfile.rb
rsgem-0.1.1 lib/rsgem/tasks/clean_gemfile.rb
rsgem-0.1.0 lib/rsgem/tasks/clean_gemfile.rb