Class: TypedEAV::SchemaPortability::Preview
- Inherits:
-
Object
- Object
- TypedEAV::SchemaPortability::Preview
- Defined in:
- lib/typed_eav/schema_portability/preview.rb
Overview
Read-only comparator for the portable schema wire format. This class is intentionally separate from import_schema: a preview must not run validations, callbacks, jobs, conversions, or a dry-run transaction. Each incoming entry must carry the exact entity_type/scope/parent_scope identity declared by the envelope; preview does not retarget entries. rubocop:disable Metrics/ClassLength -- the validator and comparator form one small, private implementation behind the single preview API.
Constant Summary collapse
- FIELD_IDENTITY_KEYS =
%w[name entity_type scope parent_scope].freeze
- SECTION_IDENTITY_KEYS =
%w[code entity_type scope parent_scope].freeze
- OPTION_KEYS =
%w[label value sort_order].freeze
- CONFLICT_STATUSES =
%w[changed conflict].freeze
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(hash, on_conflict:) ⇒ Preview
constructor
A new instance of Preview.
Constructor Details
#initialize(hash, on_conflict:) ⇒ Preview
Returns a new instance of Preview.
17 18 19 20 |
# File 'lib/typed_eav/schema_portability/preview.rb', line 17 def initialize(hash, on_conflict:) @hash = hash @on_conflict = on_conflict end |
Instance Method Details
#call ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/typed_eav/schema_portability/preview.rb', line 22 def call validate_input! fields = @hash["fields"] sections = @hash["sections"] import_index = ImportIndex.new(fields, sections) field_previews = preview_fields(fields, import_index) section_previews = preview_sections(sections, import_index) entries = field_previews + section_previews { "schema_version" => @hash["schema_version"], "entity_type" => @hash["entity_type"], "scope" => @hash["scope"], "parent_scope" => @hash["parent_scope"], "on_conflict" => @on_conflict.to_s, "importable" => entries.none? { |entry| entry["action"] == "error" }, "summary" => summary_for(entries), "fields" => field_previews, "sections" => section_previews, "risks" => entries.flat_map { |entry| entry["risks"] }.uniq.sort, } end |