Class: Igniter::Store::Fact
- Inherits:
-
Struct
- Object
- Struct
- Igniter::Store::Fact
- Defined in:
- lib/igniter/store/fact.rb,
lib/igniter/store/fact.rb
Overview
Reopen Fact (Ruby Struct or native class) and add from_h + normalizations.
Instance Attribute Summary collapse
-
#causation ⇒ Object
Returns the value of attribute causation.
-
#derivation ⇒ Object
Returns the value of attribute derivation.
-
#id ⇒ Object
Returns the value of attribute id.
-
#key ⇒ Object
Returns the value of attribute key.
-
#producer ⇒ Object
Returns the value of attribute producer.
-
#schema_version ⇒ Object
Returns the value of attribute schema_version.
-
#store ⇒ Object
Returns the value of attribute store.
-
#transaction_time ⇒ Object
(also: #timestamp)
Returns the value of attribute transaction_time.
-
#valid_time ⇒ Object
(also: #term)
Returns the value of attribute valid_time.
-
#value ⇒ Object
Returns the value of attribute value.
-
#value_hash ⇒ Object
Returns the value of attribute value_hash.
Class Method Summary collapse
-
.build(store:, key:, value:, causation: nil, valid_time: nil, term: nil, schema_version: 1, producer: nil, derivation: nil) ⇒ Object
Canonical build entry point.
-
.from_h(h) ⇒ Object
Reconstruct a Fact from a wire-deserialized hash.
Instance Method Summary collapse
-
#_native_store_str ⇒ Object
Returns the value of attribute store Native extension stores ‘store` as a Rust String; normalize to Symbol to match the Ruby Struct fallback behaviour.
Instance Attribute Details
#causation ⇒ Object
Returns the value of attribute causation
12 13 14 |
# File 'lib/igniter/store/fact.rb', line 12 def causation @causation end |
#derivation ⇒ Object
Returns the value of attribute derivation
12 13 14 |
# File 'lib/igniter/store/fact.rb', line 12 def derivation @derivation end |
#id ⇒ Object
Returns the value of attribute id
12 13 14 |
# File 'lib/igniter/store/fact.rb', line 12 def id @id end |
#key ⇒ Object
Returns the value of attribute key
12 13 14 |
# File 'lib/igniter/store/fact.rb', line 12 def key @key end |
#producer ⇒ Object
Returns the value of attribute producer
12 13 14 |
# File 'lib/igniter/store/fact.rb', line 12 def producer @producer end |
#schema_version ⇒ Object
Returns the value of attribute schema_version
12 13 14 |
# File 'lib/igniter/store/fact.rb', line 12 def schema_version @schema_version end |
#store ⇒ Object
Returns the value of attribute store
12 13 14 |
# File 'lib/igniter/store/fact.rb', line 12 def store @store end |
#transaction_time ⇒ Object Also known as: timestamp
Returns the value of attribute transaction_time
12 13 14 |
# File 'lib/igniter/store/fact.rb', line 12 def transaction_time @transaction_time end |
#valid_time ⇒ Object Also known as: term
Returns the value of attribute valid_time
12 13 14 |
# File 'lib/igniter/store/fact.rb', line 12 def valid_time @valid_time end |
#value ⇒ Object
Returns the value of attribute value
12 13 14 |
# File 'lib/igniter/store/fact.rb', line 12 def value @value end |
#value_hash ⇒ Object
Returns the value of attribute value_hash
12 13 14 |
# File 'lib/igniter/store/fact.rb', line 12 def value_hash @value_hash end |
Class Method Details
.build(store:, key:, value:, causation: nil, valid_time: nil, term: nil, schema_version: 1, producer: nil, derivation: nil) ⇒ Object
Canonical build entry point. valid_time: domain time (writer-supplied, nullable Float). term: backward-compat alias for valid_time — accepted but deprecated.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/igniter/store/fact.rb', line 29 def self.build(store:, key:, value:, causation: nil, valid_time: nil, term: nil, schema_version: 1, producer: nil, derivation: nil) vt = valid_time.nil? ? (term ? term.to_f : nil) : valid_time.to_f serialized = JSON.generate(stable_sort(value)) new( id: SecureRandom.uuid, store: store, key: key, value: deep_freeze(value), value_hash: Digest::SHA256.hexdigest(serialized), causation: causation, transaction_time: Process.clock_gettime(Process::CLOCK_REALTIME), valid_time: vt, schema_version: schema_version, producer: producer ? deep_freeze(producer) : nil, derivation: derivation ? deep_freeze(derivation) : nil ).freeze end |
.from_h(h) ⇒ Object
Reconstruct a Fact from a wire-deserialized hash. Accepts both old field names (timestamp, term) and new names (transaction_time, valid_time) for smooth transition.
In native mode: Fact.new is unavailable (no Ruby allocator), so we call Fact.build which recomputes id and transaction_time. This is a known Phase 2 gap for time-travel fidelity over the network.
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/igniter/store/fact.rb', line 95 def self.from_h(h) h = h.transform_keys(&:to_sym) h[:store] = h.fetch(:store).to_sym # Accept both old (timestamp) and new (transaction_time) key names. h[:transaction_time] = (h[:transaction_time] || h[:timestamp])&.to_f || 0.0 h[:valid_time] = (h[:valid_time] || h[:term])&.to_f if defined?(Igniter::Store::NATIVE) && Igniter::Store::NATIVE build( store: h[:store], key: h[:key], value: h[:value], causation: h[:causation], valid_time: h[:valid_time], schema_version: h.fetch(:schema_version, 1), producer: h[:producer], derivation: h[:derivation] ) else new(**h.slice(:id, :store, :key, :value, :value_hash, :causation, :transaction_time, :valid_time, :schema_version, :producer, :derivation)).freeze end end |
Instance Method Details
#_native_store_str ⇒ Object
Returns the value of attribute store Native extension stores ‘store` as a Rust String; normalize to Symbol to match the Ruby Struct fallback behaviour.
84 85 86 |
# File 'lib/igniter/store/fact.rb', line 84 def store @store end |