Class: Farce::Transaction::Molecule
- Inherits:
-
Abstract::Molecule
- Object
- Abstract::Molecule
- Farce::Transaction::Molecule
- Defined in:
- lib/farce/transaction/molecule.rb
Overview
A Molecule that is part of a transaction.
Instance Method Summary collapse
-
#atoms ⇒ Array<Symbol>
The atom accessor names in declaration order.
-
#compare_by_identity? ⇒ Boolean
Whether newly created atoms compare by identity instead of equality.
-
#each {|member, value| ... } ⇒ Array<Symbol>, Enumerator
(also: #each_pair)
Yield field names and current values in declaration order.
-
#each_atom {|name, atom| ... } ⇒ Array<Symbol>, Enumerator
Yield atom accessor names and atomic references in declaration order.
-
#each_member ⇒ Array<Symbol>, Enumerator
(also: #each_key)
Yield field names in declaration order.
-
#each_value ⇒ Array<Symbol>, Enumerator
Yield current field values in declaration order.
-
#members ⇒ Array<Symbol>
The field names in declaration order.
Methods included from Unshareable
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, **, &block) return access { @atoms.fetch(name) } if @atoms.key?(name) && arguments.empty? && .empty? && !block return super unless .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.
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.
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.
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.
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.
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.
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.
33 |
# File 'lib/farce/transaction/molecule.rb', line 33 def members = access { @members } |