Class: Julewire::Core::Records::Record
- Inherits:
-
Object
- Object
- Julewire::Core::Records::Record
- Includes:
- Enumerable
- Defined in:
- lib/julewire/core/records/record.rb
Constant Summary collapse
- KINDS =
{ "point" => :point, "summary" => :summary }.freeze
- HASH_SECTIONS =
Fields::Bags.record_hash_sections
- REQUIRED_KEYS =
Fields::Bags.required_record_keys
Instance Attribute Summary collapse
- #lineage ⇒ Object readonly
Class Method Summary collapse
- .from_normalized_hash(record, lineage: nil) ⇒ Object
- .from_owned_hash(record, lineage: nil, trust_frozen: false) ⇒ Object
- .validate_normalized!(record) ⇒ Object
- .validate_normalized_hash!(record) ⇒ Object
Instance Method Summary collapse
- #==(other) ⇒ Object
- #[](key) ⇒ Object
- #dig ⇒ Object
- #each ⇒ Object
- #eql?(other) ⇒ Boolean
- #fetch ⇒ Object
- #hash ⇒ Object
-
#initialize(data, lineage: nil) ⇒ Record
constructor
A new instance of Record.
- #inspect ⇒ Object
- #key?(key) ⇒ Boolean
- #serializable_data ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(data, lineage: nil) ⇒ Record
Returns a new instance of Record.
136 137 138 139 140 |
# File 'lib/julewire/core/records/record.rb', line 136 def initialize(data, lineage: nil) @data = data @lineage = (lineage || Execution::Lineage.from_execution_hash(fetch(:execution))).freeze freeze end |
Instance Attribute Details
#lineage ⇒ Object (readonly)
134 135 136 |
# File 'lib/julewire/core/records/record.rb', line 134 def lineage @lineage end |
Class Method Details
.from_normalized_hash(record, lineage: nil) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/julewire/core/records/record.rb', line 21 def from_normalized_hash(record, lineage: nil) if record.is_a?(Hash) lineage ||= Execution::Lineage.from_execution_hash(record[:execution]) record = record.merge(execution: Execution::Lineage.clean_lazy_relationship_hash(record[:execution])) end validate_normalized_hash!(record) new(snapshot_hash(record), lineage: lineage) end |
.from_owned_hash(record, lineage: nil, trust_frozen: false) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/julewire/core/records/record.rb', line 30 def from_owned_hash(record, lineage: nil, trust_frozen: false) if record.is_a?(Hash) lineage ||= Execution::Lineage.from_execution_hash(record.fetch(:execution)) execution = Execution::Lineage.clean_lazy_relationship_hash(record.fetch(:execution)) record = record.frozen? ? record.merge(execution: execution) : replace_execution(record, execution) end validate_normalized_hash!(record) new(Serialization::DeepFreeze.call(record, trust_frozen: trust_frozen), lineage: lineage) end |
.validate_normalized!(record) ⇒ Object
40 41 42 43 44 |
# File 'lib/julewire/core/records/record.rb', line 40 def validate_normalized!(record) return record if record.is_a?(self) raise TypeError, "expected Julewire::Record" end |
.validate_normalized_hash!(record) ⇒ Object
46 47 48 49 |
# File 'lib/julewire/core/records/record.rb', line 46 def validate_normalized_hash!(record) validate_hash!(record) record end |
Instance Method Details
#==(other) ⇒ Object
161 162 163 |
# File 'lib/julewire/core/records/record.rb', line 161 def ==(other) other.instance_of?(Record) && @data == other.serializable_data end |
#[](key) ⇒ Object
142 |
# File 'lib/julewire/core/records/record.rb', line 142 def [](key) = @data[key] |
#dig ⇒ Object
146 |
# File 'lib/julewire/core/records/record.rb', line 146 def dig(...) = @data.dig(...) |
#each ⇒ Object
150 |
# File 'lib/julewire/core/records/record.rb', line 150 def each(&) = @data.each(&) |
#eql?(other) ⇒ Boolean
165 166 167 |
# File 'lib/julewire/core/records/record.rb', line 165 def eql?(other) other.instance_of?(Record) && @data.eql?(other.serializable_data) end |
#fetch ⇒ Object
144 |
# File 'lib/julewire/core/records/record.rb', line 144 def fetch(...) = @data.fetch(...) |
#hash ⇒ Object
169 |
# File 'lib/julewire/core/records/record.rb', line 169 def hash = @data.hash |
#inspect ⇒ Object
171 |
# File 'lib/julewire/core/records/record.rb', line 171 def inspect = "#<#{self.class} #{@data}>" |
#key?(key) ⇒ Boolean
148 |
# File 'lib/julewire/core/records/record.rb', line 148 def key?(key) = @data.key?(key) |
#serializable_data ⇒ Object
155 |
# File 'lib/julewire/core/records/record.rb', line 155 def serializable_data = @data |