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.

API:

  • private

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:

  • An object where the state will be copied from.

  • An object where the state will be copied to.

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

Returns:

  • An array of mutation_strategies.

API:

  • private



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:

  • The class or instance to copy the state from.

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

Returns:

  • The state representation of the given observable

API:

  • private



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:

  • Any class or instance

Returns:

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

API:

  • private



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