Class: Julewire::Core::Records::Draft
- Inherits:
-
Object
- Object
- Julewire::Core::Records::Draft
- Includes:
- Enumerable
- Defined in:
- lib/julewire/core/records/draft.rb
Class Method Summary collapse
-
.build(input = {}, context:, scope:, attributes: {}, neutral: {}, carry: {}, static_labels: {}, freeze_sections: true, error_backtrace_lines: Core::MAX_BACKTRACE_LINES, invalid_severity_reporter: Diagnostics::InvalidSeverityReporter) ⇒ Object
rubocop:disable Metrics/ParameterLists – Record construction has fixed public sections.
-
.build_pipeline_owned(input = {}, context:, scope:, attributes: {}, neutral: {}, carry: {}, static_labels: {}, input_owned: false, freeze_sections: true, error_backtrace_lines: Core::MAX_BACKTRACE_LINES, invalid_severity_reporter: Diagnostics::InvalidSeverityReporter) ⇒ Object
rubocop:disable Metrics/ParameterLists – Record construction has fixed public sections.
- .from_normalized_hash(data, lineage: nil, freeze_sections: true) ⇒ Object
- .from_record(record, freeze_sections: true) ⇒ Object
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #dig ⇒ Object
- #each ⇒ Object
- #each_key ⇒ Object
- #fetch ⇒ Object
-
#initialize(data, lineage: nil, freeze_sections: true) ⇒ Draft
constructor
A new instance of Draft.
- #key?(key) ⇒ Boolean
- #lineage ⇒ Object
- #to_h ⇒ Object
- #to_record ⇒ Object
- #transform_field!(key) ⇒ Object
- #transform_record! ⇒ Object
- #transform_section!(key) ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(data, lineage: nil, freeze_sections: true) ⇒ Draft
Returns a new instance of Draft.
159 160 161 162 163 164 |
# File 'lib/julewire/core/records/draft.rb', line 159 def initialize(data, lineage: nil, freeze_sections: true) @data = data @freeze_sections = freeze_sections @lineage = lineage || Execution::Lineage.from_execution_hash(@data[:execution]) validate! end |
Class Method Details
.build(input = {}, context:, scope:, attributes: {}, neutral: {}, carry: {}, static_labels: {}, freeze_sections: true, error_backtrace_lines: Core::MAX_BACKTRACE_LINES, invalid_severity_reporter: Diagnostics::InvalidSeverityReporter) ⇒ Object
rubocop:disable Metrics/ParameterLists – Record construction has fixed public sections.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/julewire/core/records/draft.rb', line 14 def build( # rubocop:disable Metrics/ParameterLists -- Record construction has fixed public sections. input = {}, context:, scope:, attributes: {}, neutral: {}, carry: {}, static_labels: {}, freeze_sections: true, error_backtrace_lines: Core::MAX_BACKTRACE_LINES, invalid_severity_reporter: Diagnostics::InvalidSeverityReporter ) build_with( input, context: context, neutral: neutral, attributes: attributes, carry: carry, static_labels: static_labels, scope: scope, invalid_severity_reporter: invalid_severity_reporter, options: BuildOptions.defensive( freeze_sections: freeze_sections, error_backtrace_lines: error_backtrace_lines ) ) end |
.build_pipeline_owned(input = {}, context:, scope:, attributes: {}, neutral: {}, carry: {}, static_labels: {}, input_owned: false, freeze_sections: true, error_backtrace_lines: Core::MAX_BACKTRACE_LINES, invalid_severity_reporter: Diagnostics::InvalidSeverityReporter) ⇒ Object
rubocop:disable Metrics/ParameterLists – Record construction has fixed public sections.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/julewire/core/records/draft.rb', line 42 def build_pipeline_owned( # rubocop:disable Metrics/ParameterLists -- Record construction has fixed public sections. input = {}, context:, scope:, attributes: {}, neutral: {}, carry: {}, static_labels: {}, input_owned: false, freeze_sections: true, error_backtrace_lines: Core::MAX_BACKTRACE_LINES, invalid_severity_reporter: Diagnostics::InvalidSeverityReporter ) build_with( input, context: context, neutral: neutral, attributes: attributes, carry: carry, static_labels: static_labels, scope: scope, invalid_severity_reporter: invalid_severity_reporter, options: BuildOptions.pipeline_owned( input_owned: input_owned, freeze_sections: freeze_sections, error_backtrace_lines: error_backtrace_lines ) ) end |
.from_normalized_hash(data, lineage: nil, freeze_sections: true) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/julewire/core/records/draft.rb', line 92 def from_normalized_hash(data, lineage: nil, freeze_sections: true) normalized = Fields::FieldSet.deep_symbolize_keys(data) lineage ||= Execution::Lineage.from_execution_hash(normalized[:execution]) normalized[:execution] = Execution::Lineage.clean_lazy_relationship_hash(normalized[:execution]) normalized = Fields::Internal.frozen_deep_symbolize_keys(normalized) if freeze_sections new( normalized, lineage: lineage, freeze_sections: freeze_sections ) end |
.from_record(record, freeze_sections: true) ⇒ Object
104 105 106 107 |
# File 'lib/julewire/core/records/draft.rb', line 104 def from_record(record, freeze_sections: true) Record.validate_normalized!(record) from_normalized_hash(record.to_h, lineage: record.lineage, freeze_sections: freeze_sections) end |
Instance Method Details
#[](key) ⇒ Object
166 |
# File 'lib/julewire/core/records/draft.rb', line 166 def [](key) = @data[key] |
#[]=(key, value) ⇒ Object
168 169 170 171 172 173 |
# File 'lib/julewire/core/records/draft.rb', line 168 def []=(key, value) @lineage = nil if key == :execution ensure_mutable_data! @data[key] = value @to_record = nil end |
#dig ⇒ Object
177 |
# File 'lib/julewire/core/records/draft.rb', line 177 def dig(...) = @data.dig(...) |
#each ⇒ Object
181 |
# File 'lib/julewire/core/records/draft.rb', line 181 def each(&) = @data.each(&) |
#each_key ⇒ Object
183 |
# File 'lib/julewire/core/records/draft.rb', line 183 def each_key(&) = @data.each_key(&) |
#fetch ⇒ Object
175 |
# File 'lib/julewire/core/records/draft.rb', line 175 def fetch(...) = @data.fetch(...) |
#key?(key) ⇒ Boolean
179 |
# File 'lib/julewire/core/records/draft.rb', line 179 def key?(key) = @data.key?(key) |
#lineage ⇒ Object
222 |
# File 'lib/julewire/core/records/draft.rb', line 222 def lineage = (@lineage ||= Execution::Lineage.from_execution_hash(@data[:execution])) |
#to_h ⇒ Object
185 |
# File 'lib/julewire/core/records/draft.rb', line 185 def to_h = Fields::FieldSet.deep_dup(@data) |
#to_record ⇒ Object
224 225 226 |
# File 'lib/julewire/core/records/draft.rb', line 224 def to_record @to_record ||= Record.from_owned_hash(@data, lineage: @lineage, trust_frozen: @freeze_sections) end |
#transform_field!(key) ⇒ Object
187 188 189 190 191 |
# File 'lib/julewire/core/records/draft.rb', line 187 def transform_field!(key) key = Fields::Internal.normalize_key(key) replace_transformed_field!(key, yield(@data[key])) self end |
#transform_record! ⇒ Object
203 204 205 206 207 208 209 210 211 |
# File 'lib/julewire/core/records/draft.rb', line 203 def transform_record! previous_lineage = @lineage previous_identity = execution_lineage_identity(@data[:execution]) replacement = yield(@data) @lineage = replacement_lineage_for(previous_lineage, previous_identity, replacement) @data = replacement @to_record = nil self end |
#transform_section!(key) ⇒ Object
193 194 195 196 197 198 199 200 201 |
# File 'lib/julewire/core/records/draft.rb', line 193 def transform_section!(key) key = Fields::Internal.normalize_key(key) section = @data[key] replacement = yield(section) raise TypeError, "record #{key} must be a Hash" unless replacement.is_a?(Hash) replace_transformed_field!(key, replacement) self end |
#validate! ⇒ Object
217 218 219 220 |
# File 'lib/julewire/core/records/draft.rb', line 217 def validate! Record.validate_normalized_hash!(@data) self end |