Class: Xavier::Mutator Private

Inherits:
Object
  • Object
show all
Defined in:
lib/xavier/mutator.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Applies and unapplies state mutations to objects.

Instance Method Summary collapse

Instance Method Details

#apply_state(from:, to:, strategies:) ⇒ Array

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Applies the given state to the given observable.

Parameters:

  • from

    An object where the state will be copied from.

  • to

    An object where the state will be copied to.

  • strategies (Array)

    Array of mutation mutation_strategies that define how the state should be copied.

Returns:

  • (Array)

    An array of mutation_strategies.



31
32
33
# File 'lib/xavier/mutator.rb', line 31

def apply_state(from:, to:, strategies:)
  strategies.each { |strategy| strategy.copy(from: from, to: to) }
end

#create_state_from(observable, strategies:) ⇒ State

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a state representation from a given observable.

Parameters:

  • observable

    The class or instance to copy the state from.

  • strategies (Array)

    Array of mutation mutation_strategies that define how the state should be copied.

Returns:

  • (State)

    The state representation of the given observable



18
19
20
21
22
# File 'lib/xavier/mutator.rb', line 18

def create_state_from(observable, strategies:)
  state = State.new(observable.object_id)
  strategies.each { |strategy| strategy.copy(from: observable, to: state) }
  state
end

#mutation_strategies_for(observable) ⇒ Array

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Finds the mutation mutation_strategies for a given observable.

Parameters:

  • observable

    Any class or instance

Returns:

  • (Array)

    An array of mutation mutation_strategies that define how the state should be copied.



40
41
42
43
44
# File 'lib/xavier/mutator.rb', line 40

def mutation_strategies_for(observable)
  [MutationStrategies::InstanceCopy].tap do |strategies|
    strategies.push(MutationStrategies::ClassCopy) if observable.is_a?(Class)
  end
end