Sha256: 89dc19a710955c30c730b6b3870cd03f9791a8846c55884bbe7c0ab4f2c4ed44

Contents?: true

Size: 1.08 KB

Versions: 7018

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module Parser
  module Source

    ##
    # @api private
    #
    class Rewriter::Action
      include Comparable

      attr_reader :range, :replacement, :allow_multiple_insertions, :order
      alias_method :allow_multiple_insertions?, :allow_multiple_insertions

      def initialize(range, replacement='', allow_multiple_insertions = false, order = 0)
        @range = range
        @replacement = replacement
        @allow_multiple_insertions = allow_multiple_insertions
        @order = order

        freeze
      end

      def <=>(other)
        result = range.begin_pos <=> other.range.begin_pos
        return result unless result.zero?
        order <=> other.order
      end

      def to_s
        if @range.length == 0 && @replacement.empty?
          'do nothing'
        elsif @range.length == 0
          "insert #{@replacement.inspect}"
        elsif @replacement.empty?
          "remove #{@range.length} character(s)"
        else
          "replace #{@range.length} character(s) with #{@replacement.inspect}"
        end
      end
    end

  end
end

Version data entries

7,018 entries across 6,995 versions & 51 rubygems

Version Path
ory-client-0.0.1.alpha28 vendor/bundle/ruby/2.5.0/gems/parser-3.0.2.0/lib/parser/source/rewriter/action.rb
primary_connect_proto-0.0.5 vendor/bundle/ruby/2.6.0/gems/parser-3.0.2.0/lib/parser/source/rewriter/action.rb
ory-client-0.0.1.alpha27 vendor/bundle/ruby/2.5.0/gems/parser-3.0.2.0/lib/parser/source/rewriter/action.rb
ory-client-0.0.1.alpha24 vendor/bundle/ruby/2.5.0/gems/parser-3.0.2.0/lib/parser/source/rewriter/action.rb
primary_connect_proto-0.0.4 vendor/bundle/ruby/2.6.0/gems/parser-3.0.2.0/lib/parser/source/rewriter/action.rb
primary_connect_proto-0.0.3 vendor/bundle/ruby/2.6.0/gems/parser-3.0.2.0/lib/parser/source/rewriter/action.rb
ory-client-0.0.1.alpha23 vendor/bundle/ruby/2.5.0/gems/parser-3.0.2.0/lib/parser/source/rewriter/action.rb
plaid-14.7.0 vendor/bundle/ruby/2.6.0/gems/parser-2.7.2.0/lib/parser/source/rewriter/action.rb
ory-kratos-client-0.8.0.alpha2 vendor/bundle/ruby/2.5.0/gems/parser-3.0.2.0/lib/parser/source/rewriter/action.rb
ory-client-0.0.1.alpha21 vendor/bundle/ruby/2.5.0/gems/parser-3.0.2.0/lib/parser/source/rewriter/action.rb
ory-keto-client-0.7.0.alpha1 vendor/bundle/ruby/2.5.0/gems/parser-3.0.2.0/lib/parser/source/rewriter/action.rb
ory-keto-client-0.7.0.alpha0 vendor/bundle/ruby/2.5.0/gems/parser-3.0.2.0/lib/parser/source/rewriter/action.rb
ory-kratos-client-0.7.6.alpha7 vendor/bundle/ruby/2.5.0/gems/parser-3.0.2.0/lib/parser/source/rewriter/action.rb
ory-kratos-client-0.7.6.alpha6 vendor/bundle/ruby/2.5.0/gems/parser-3.0.2.0/lib/parser/source/rewriter/action.rb
ory-kratos-client-0.7.6.alpha5 vendor/bundle/ruby/2.5.0/gems/parser-3.0.2.0/lib/parser/source/rewriter/action.rb
ory-kratos-client-0.7.6.alpha4 vendor/bundle/ruby/2.5.0/gems/parser-3.0.2.0/lib/parser/source/rewriter/action.rb
ory-kratos-client-0.7.6.alpha3 vendor/bundle/ruby/2.5.0/gems/parser-3.0.2.0/lib/parser/source/rewriter/action.rb
ory-kratos-client-0.7.6.alpha1 vendor/bundle/ruby/2.5.0/gems/parser-3.0.2.0/lib/parser/source/rewriter/action.rb
ory-kratos-client-0.7.5.alpha2 vendor/bundle/ruby/2.5.0/gems/parser-3.0.2.0/lib/parser/source/rewriter/action.rb
mx-platform-ruby-0.4.0 vendor/bundle/ruby/2.6.0/gems/parser-3.0.2.0/lib/parser/source/rewriter/action.rb