Class: FragmentClient::TypedLedgerEntry
- Inherits:
-
Object
- Object
- FragmentClient::TypedLedgerEntry
- Extended by:
- T::Helpers, T::Sig
- Defined in:
- lib/fragment_client/typed_ledger_entry.rb
Overview
Base class for a typed addLedgerEntries payload. Abstract: one subclass per
(entry type, typeVersion) is built by FragmentClient::TypedEntries.load.
A subclass declares one keyword argument and one reader per Schema parameter,
alongside the common LedgerEntryInput fields, and #to_entry_input reshapes
them into the nested AddLedgerEntryInput the API takes.
entry = FragmentClient::Entries::AuthCaptureV1.new(
ik: 'ik-1', ledger_ik: 'prod', capture_amount: '100'
)
client.add_ledger_entries(entries: [entry])
Section references are to typed-batch-entries.md; see
docs/spec-conformance.md.
Constant Summary collapse
- COMMON_FIELDS =
The
LedgerEntryInputfields every payload carries, whatever its entry type (spec 2.3a). Fixed byLedgerEntryInput, not derived from the operation, which binds only what its CLI version chose to expose.linesis absent deliberately: it cannot be combined with an entry that has atype.type,typeVersionandparametersare derived, never supplied. T.let( %i[ik ledger_ik posted description tags groups conditions].freeze, T::Array[Symbol] )
Instance Attribute Summary collapse
-
#conditions ⇒ Object
readonly
Returns the value of attribute conditions.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#groups ⇒ Object
readonly
Returns the value of attribute groups.
-
#ik ⇒ Object
readonly
Returns the value of attribute ik.
-
#ledger_ik ⇒ Object
readonly
Returns the value of attribute ledger_ik.
-
#posted ⇒ Object
readonly
Returns the value of attribute posted.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
Class Method Summary collapse
- .build(spec, origin: nil) ⇒ Object
- .entry_type ⇒ Object
- .parameters ⇒ Object
- .source_path ⇒ Object
- .spec ⇒ Object
- .type_version ⇒ Object
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #entry_parameters ⇒ Object
- #hash ⇒ Object
-
#initialize(ik:, ledger_ik:, posted: FragmentClient::TypedEntries::UNSET, description: FragmentClient::TypedEntries::UNSET, tags: FragmentClient::TypedEntries::UNSET, groups: FragmentClient::TypedEntries::UNSET, conditions: FragmentClient::TypedEntries::UNSET, **parameters) ⇒ TypedLedgerEntry
constructor
rubocop:disable Metrics/AbcSize -- one assignment per common field;
typed: strictrules out setting them in a loop. - #inspect ⇒ Object
- #set?(name) ⇒ Boolean
- #to_entry_input ⇒ Object (also: #to_h)
Constructor Details
#initialize(ik:, ledger_ik:, posted: FragmentClient::TypedEntries::UNSET, description: FragmentClient::TypedEntries::UNSET, tags: FragmentClient::TypedEntries::UNSET, groups: FragmentClient::TypedEntries::UNSET, conditions: FragmentClient::TypedEntries::UNSET, **parameters) ⇒ TypedLedgerEntry
rubocop:disable Metrics/AbcSize -- one assignment per common field; typed: strict rules out setting them in a loop.
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/fragment_client/typed_ledger_entry.rb', line 140 def initialize(ik:, ledger_ik:, posted: FragmentClient::TypedEntries::UNSET, description: FragmentClient::TypedEntries::UNSET, tags: FragmentClient::TypedEntries::UNSET, groups: FragmentClient::TypedEntries::UNSET, conditions: FragmentClient::TypedEntries::UNSET, **parameters) @ik = ik @ledger_ik = ledger_ik @parameters = T.let(validate(parameters), T::Hash[Symbol, T.untyped]) @provided = T.let(Set.new(@parameters.keys + %i[ik ledger_ik]), T::Set[Symbol]) @posted = T.let(record(:posted, posted), T.nilable(String)) @description = T.let(record(:description, description), T.nilable(String)) @tags = T.let(record(:tags, ), T.nilable(T::Array[T.untyped])) @groups = T.let(record(:groups, groups), T.nilable(T::Array[T.untyped])) @conditions = T.let(record(:conditions, conditions), T.nilable(T::Array[T.untyped])) end |
Instance Attribute Details
#conditions ⇒ Object (readonly)
Returns the value of attribute conditions.
116 117 118 |
# File 'lib/fragment_client/typed_ledger_entry.rb', line 116 def conditions @conditions end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
107 108 109 |
# File 'lib/fragment_client/typed_ledger_entry.rb', line 107 def description @description end |
#groups ⇒ Object (readonly)
Returns the value of attribute groups.
113 114 115 |
# File 'lib/fragment_client/typed_ledger_entry.rb', line 113 def groups @groups end |
#ik ⇒ Object (readonly)
Returns the value of attribute ik.
96 97 98 |
# File 'lib/fragment_client/typed_ledger_entry.rb', line 96 def ik @ik end |
#ledger_ik ⇒ Object (readonly)
Returns the value of attribute ledger_ik.
99 100 101 |
# File 'lib/fragment_client/typed_ledger_entry.rb', line 99 def ledger_ik @ledger_ik end |
#posted ⇒ Object (readonly)
Returns the value of attribute posted.
104 105 106 |
# File 'lib/fragment_client/typed_ledger_entry.rb', line 104 def posted @posted end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
110 111 112 |
# File 'lib/fragment_client/typed_ledger_entry.rb', line 110 def @tags end |
Class Method Details
.build(spec, origin: nil) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/fragment_client/typed_ledger_entry.rb', line 45 def build(spec, origin: nil) klass = Class.new(self) klass.instance_variable_set(:@spec, spec) klass.instance_variable_set(:@source_path, origin) spec.parameters.each do |parameter| name = parameter.name klass.send(:define_method, name) do T.bind(self, TypedLedgerEntry) parameter_value(name) end end klass end |
.entry_type ⇒ Object
73 74 75 |
# File 'lib/fragment_client/typed_ledger_entry.rb', line 73 def entry_type spec.entry_type end |
.parameters ⇒ Object
84 85 86 |
# File 'lib/fragment_client/typed_ledger_entry.rb', line 84 def parameters spec.parameters end |
.source_path ⇒ Object
90 91 92 |
# File 'lib/fragment_client/typed_ledger_entry.rb', line 90 def source_path @source_path = T.let(@source_path, T.nilable(String)) end |
.spec ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/fragment_client/typed_ledger_entry.rb', line 63 def spec @spec = T.let(@spec, T.nilable(FragmentClient::TypedEntries::EntrySpec)) @spec || raise( NotImplementedError, "#{self} has no derived spec. Typed payload classes are built by " \ 'FragmentClient::TypedEntries.load, not subclassed by hand.' ) end |
.type_version ⇒ Object
78 79 80 |
# File 'lib/fragment_client/typed_ledger_entry.rb', line 78 def type_version spec.type_version end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
169 170 171 |
# File 'lib/fragment_client/typed_ledger_entry.rb', line 169 def ==(other) other.instance_of?(self.class) && other.to_entry_input == to_entry_input end |
#entry_parameters ⇒ Object
192 193 194 195 196 |
# File 'lib/fragment_client/typed_ledger_entry.rb', line 192 def entry_parameters self.class.parameters.each_with_object({}) do |parameter, out| out[parameter.wire_name] = @parameters[parameter.name] if @parameters.key?(parameter.name) end end |
#hash ⇒ Object
176 177 178 |
# File 'lib/fragment_client/typed_ledger_entry.rb', line 176 def hash [self.class, to_entry_input].hash end |
#inspect ⇒ Object
199 200 201 202 203 204 |
# File 'lib/fragment_client/typed_ledger_entry.rb', line 199 def inspect shown = COMMON_FIELDS.select { |name| set?(name) } .map { |name| "#{name}: #{public_send(name).inspect}" } shown.concat(@parameters.map { |name, value| "#{name}: #{value.inspect}" }) "#<#{self.class} #{shown.join(', ')}>" end |
#set?(name) ⇒ Boolean
163 164 165 |
# File 'lib/fragment_client/typed_ledger_entry.rb', line 163 def set?(name) @provided.include?(name) end |
#to_entry_input ⇒ Object Also known as: to_h
183 184 185 |
# File 'lib/fragment_client/typed_ledger_entry.rb', line 183 def to_entry_input { 'entry' => entry_input, 'ik' => @ik } end |