Class: Farce::Transaction::Molecule

Inherits:
Abstract::Molecule show all
Defined in:
lib/farce/transaction/molecule.rb

Overview

A Molecule that is part of a transaction.

Instance Method Summary collapse

Methods included from Unshareable

#ractor_shareable?

Methods inherited from Abstract::Molecule

atoms, compare_by_identity?, define, #freeze, members

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *arguments, **options, &block) ⇒ BasicObject (private)



75
76
77
78
79
80
81
# File 'lib/farce/transaction/molecule.rb', line 75

def method_missing(name, *arguments, **options, &block)
  return access { @atoms.fetch(name) } if @atoms.key?(name) && arguments.empty? && options.empty? && !block
  return super unless options.empty? && !block
  return access { @fields.fetch(name).value } if @fields.key?(name) && arguments.empty?
  return write { @writers.fetch(name).value = arguments.first } if @writers.key?(name) && arguments.size == 1
  super
end

Instance Method Details

#atoms ⇒ Array<Symbol>

Returns the atom accessor names in declaration order.

Returns:

  • (Array<Symbol>) —

    the atom accessor names in declaration order

See Also:



37
# File 'lib/farce/transaction/molecule.rb', line 37

def atoms = access { @atoms.keys.freeze }

#compare_by_identity? ⇒ Boolean

Whether newly created atoms compare by identity instead of equality. Explicitly supplied atoms retain their own comparison policy.

Returns:

  • (Boolean)

See Also:



29
# File 'lib/farce/transaction/molecule.rb', line 29

def compare_by_identity? = access { @object.compare_by_identity? }

#each {|member, value| ... } ⇒ Array<Symbol>, Enumerator Also known as: each_pair

Yield field names and current values in declaration order.

Yield Parameters:

  • member (Symbol) —

    the field name

  • value (BasicObject) —

    its current value

Returns:

  • (Array<Symbol>, Enumerator)

See Also:



41
42
43
44
45
# File 'lib/farce/transaction/molecule.rb', line 41

def each
  return enum_for(__method__) unless block_given?
  access { @members.each { yield it, @atoms.fetch(:"#{it}_atom").value } }
  self
end

#each_atom {|name, atom| ... } ⇒ Array<Symbol>, Enumerator

Yield atom accessor names and atomic references in declaration order.

Yield Parameters:

  • name (Symbol) —

    the atom accessor name

  • atom (Atom) —

    the field's atomic reference

Returns:

  • (Array<Symbol>, Enumerator)

See Also:



50
51
52
53
54
# File 'lib/farce/transaction/molecule.rb', line 50

def each_atom
  return enum_for(__method__) unless block_given?
  access { @atoms.each { yield _1, _2 } }
  self
end

#each_member ⇒ Array<Symbol>, Enumerator Also known as: each_key

Yield field names in declaration order.

Returns:

  • (Array<Symbol>, Enumerator)

See Also:



58
59
60
61
62
# File 'lib/farce/transaction/molecule.rb', line 58

def each_member
  return enum_for(__method__) unless block_given?
  access { @members.each { yield it } }
  self
end

#each_value ⇒ Array<Symbol>, Enumerator

Yield current field values in declaration order.

Returns:

  • (Array<Symbol>, Enumerator)

See Also:



67
68
69
70
71
# File 'lib/farce/transaction/molecule.rb', line 67

def each_value
  return enum_for(__method__) unless block_given?
  each { |_, value| yield value }
  self
end

#members ⇒ Array<Symbol>

Returns the field names in declaration order.

Returns:

  • (Array<Symbol>) —

    the field names in declaration order

See Also:



33
# File 'lib/farce/transaction/molecule.rb', line 33

def members = access { @members }