Sha256: 5c9b72728a9950862ca8c7db85b5b1c495ef05caa5a95a696300b567fee9685c

Contents?: true

Size: 768 Bytes

Versions: 2

Compression:

Stored size: 768 Bytes

Contents

module DRG
  module Tasks
    class GemfileLine < Struct.new(:line, :index)
      alias to_s line
      alias to_int index

      def ==(other)
        line.to_s == other.to_s
      end

      # @param [String] version is the new value for the gem (add/replace)
      def update(version)
        if line =~ /,.+\n?/
          if line =~ /,\s*['"].+['"]/
            line[/,\s*['"].+['"]/] = ", '#{version.to_s}'"
          else
            line[/,\s*/] = ", '#{version.to_s}', "
          end
        elsif line.end_with?("\n")
          line.sub!("\n", ", '#{version.to_s}'\n")
        else
          line << ", '#{version.to_s}'\n"
        end
        line
      end

      # @note not used
      def version
        line[/, (.+)\n?/, 1]
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
drg-0.4.1 lib/drg/tasks/gemfile_line.rb
drg-0.4.0 lib/drg/tasks/gemfile_line.rb