Sha256: 7a39c7ac090b029452e0fff364c9fcfe18f07962e1221e13be9435a9de49a91a

Contents?: true

Size: 710 Bytes

Versions: 1

Compression:

Stored size: 710 Bytes

Contents

# frozen_string_literal: true

# GroupAction is compose of multiple actions.
class NodeMutation::GroupAction < NodeMutation::Action
  include NodeMutation::Actionable

  DEFAULT_START = 2**30

  # Initialize a GroupAction.
  def initialize(adapter:, &block)
    @actions = []
    @type = :group
    @adapter = adapter
    @block = block
  end

  def new_code
    nil
  end

  def process
    instance_eval(&@block)
    super
  end

  private

  # Calculate the begin and end positions.
  def calculate_position
    @start = DEFAULT_START
    @end = 0
    NodeMutation::Helper.iterate_actions(@actions) do |action|
      @start = [action.start, @start].min
      @end = [action.end, @end].max
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
node_mutation-1.22.3 lib/node_mutation/action/group_action.rb