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.
166 167 168 169 170 |
# File 'lib/julewire/core/records/record.rb', line 166 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)
164 165 166 |
# File 'lib/julewire/core/records/record.rb', line 164 def lineage @lineage end |
Class Method Details
.from_normalized_hash(record, lineage: nil) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/julewire/core/records/record.rb', line 21 def from_normalized_hash(record, lineage: nil) validate_normalized_hash!(record) execution = record.fetch(:execution) lineage ||= Execution::Lineage.from_execution_hash(execution) record = record.merge( execution: Execution::Lineage.clean_normalized_lazy_relationship_hash(execution) ) new(snapshot_hash(record), lineage: lineage) end |
.from_owned_hash(record, lineage: nil, trust_frozen: false) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/julewire/core/records/record.rb', line 31 def from_owned_hash(record, lineage: nil, trust_frozen: false) validate_normalized_hash!(record) lineage ||= Execution::Lineage.from_execution_hash(record.fetch(:execution)) execution = Execution::Lineage.clean_normalized_lazy_relationship_hash(record.fetch(:execution)) record = record.frozen? ? record.merge(execution: execution) : replace_execution(record, execution) new(Serialization::DeepFreeze.call(record, trust_frozen: trust_frozen), lineage: lineage) end |
.validate_normalized!(record) ⇒ Object
39 40 41 42 43 |
# File 'lib/julewire/core/records/record.rb', line 39 def validate_normalized!(record) return record if record.is_a?(self) raise TypeError, "expected Julewire::Record" end |
.validate_normalized_hash!(record) ⇒ Object
45 46 47 48 |
# File 'lib/julewire/core/records/record.rb', line 45 def validate_normalized_hash!(record) validate_hash!(record) record end |
Instance Method Details
#==(other) ⇒ Object
191 192 193 |
# File 'lib/julewire/core/records/record.rb', line 191 def ==(other) other.instance_of?(Record) && @data == other.serializable_data end |
#[](key) ⇒ Object
172 |
# File 'lib/julewire/core/records/record.rb', line 172 def [](key) = @data[key] |
#dig ⇒ Object
176 |
# File 'lib/julewire/core/records/record.rb', line 176 def dig(...) = @data.dig(...) |
#each ⇒ Object
180 |
# File 'lib/julewire/core/records/record.rb', line 180 def each(&) = @data.each(&) |
#eql?(other) ⇒ Boolean
195 196 197 |
# File 'lib/julewire/core/records/record.rb', line 195 def eql?(other) other.instance_of?(Record) && @data.eql?(other.serializable_data) end |
#fetch ⇒ Object
174 |
# File 'lib/julewire/core/records/record.rb', line 174 def fetch(...) = @data.fetch(...) |
#hash ⇒ Object
199 |
# File 'lib/julewire/core/records/record.rb', line 199 def hash = @data.hash |
#inspect ⇒ Object
201 |
# File 'lib/julewire/core/records/record.rb', line 201 def inspect = "#<#{self.class} #{@data}>" |
#key?(key) ⇒ Boolean
178 |
# File 'lib/julewire/core/records/record.rb', line 178 def key?(key) = @data.key?(key) |
#serializable_data ⇒ Object
185 |
# File 'lib/julewire/core/records/record.rb', line 185 def serializable_data = @data |
#to_h ⇒ Object
182 |
# File 'lib/julewire/core/records/record.rb', line 182 def to_h = Fields::FieldSet.deep_dup_owned(@data) |