Class: Ea::Spa::Projector
- Inherits:
-
Object
- Object
- Ea::Spa::Projector
- Defined in:
- lib/ea/spa/projector.rb
Overview
One-way transform: Ea::Model::Document → SPA view artifacts.
The projector walks the model once and emits:
- Skeleton (with package tree + per-classifier entries)
- SearchIndex (flat searchable rows)
- Shards (one per entity, generated lazily via #shard_for)
Sharding strategy is configurable via the shard_url_for
proc — by default it produces "data/
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#shard_url_for ⇒ Object
readonly
Returns the value of attribute shard_url_for.
Instance Method Summary collapse
-
#each_shard ⇒ Object
Enumerate every (id, kind, shard) triple the SPA can address.
-
#initialize(document, shard_url_for: nil, configuration: nil) ⇒ Projector
constructor
A new instance of Projector.
- #search_index ⇒ Object
- #shard_for(model_element) ⇒ Object
- #skeleton ⇒ Object
Constructor Details
#initialize(document, shard_url_for: nil, configuration: nil) ⇒ Projector
Returns a new instance of Projector.
18 19 20 21 22 |
# File 'lib/ea/spa/projector.rb', line 18 def initialize(document, shard_url_for: nil, configuration: nil) @document = document @shard_url_for = shard_url_for || default_shard_url @configuration = configuration end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
16 17 18 |
# File 'lib/ea/spa/projector.rb', line 16 def configuration @configuration end |
#document ⇒ Object (readonly)
Returns the value of attribute document.
16 17 18 |
# File 'lib/ea/spa/projector.rb', line 16 def document @document end |
#shard_url_for ⇒ Object (readonly)
Returns the value of attribute shard_url_for.
16 17 18 |
# File 'lib/ea/spa/projector.rb', line 16 def shard_url_for @shard_url_for end |
Instance Method Details
#each_shard ⇒ Object
Enumerate every (id, kind, shard) triple the SPA can address.
46 47 48 49 50 51 52 |
# File 'lib/ea/spa/projector.rb', line 46 def each_shard return enum_for(:each_shard) unless block_given? document.classifiers.each { |c| yield shard_for(c) } document.packages.each { |p| yield shard_for(p) } document.diagrams.each { |d| yield shard_for(d) } end |
#search_index ⇒ Object
33 34 35 |
# File 'lib/ea/spa/projector.rb', line 33 def search_index SearchIndex.new(entries: build_search_entries) end |
#shard_for(model_element) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/ea/spa/projector.rb', line 37 def shard_for(model_element) Shard.new( id: model_element.id, kind: kind_of(model_element), payload: payload_for(model_element) ) end |
#skeleton ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/ea/spa/projector.rb', line 24 def skeleton Skeleton.new( metadata: , package_tree: build_package_tree, entries: build_entries, view_extras: view_extras ) end |