Class: Interfacets::Server::Config
- Inherits:
-
Object
- Object
- Interfacets::Server::Config
- Defined in:
- lib/interfacets/server/config.rb
Instance Attribute Summary collapse
-
#mount_point ⇒ Object
Returns the value of attribute mount_point.
-
#registry ⇒ Object
readonly
Returns the value of attribute registry.
Instance Method Summary collapse
- #all_facets ⇒ Object
- #build_facet(facet_uid: nil, name: nil, id: nil, query: {}) ⇒ Object
- #bundled_assets ⇒ Object
- #default_facet ⇒ Object
- #facet(name) ⇒ Object
- #ingest_facet(data) ⇒ Object
-
#initialize(mount_point:, registry:, assets:) ⇒ Config
constructor
A new instance of Config.
- #register_facet(name, class_or_class_name) ⇒ Object
- #schema ⇒ Object
Constructor Details
#initialize(mount_point:, registry:, assets:) ⇒ Config
Returns a new instance of Config.
12 13 14 15 16 17 18 19 20 |
# File 'lib/interfacets/server/config.rb', line 12 def initialize( mount_point:, registry:, assets: ) @mount_point = mount_point @registry = registry @assets = assets end |
Instance Attribute Details
#mount_point ⇒ Object
Returns the value of attribute mount_point.
7 8 9 |
# File 'lib/interfacets/server/config.rb', line 7 def mount_point @mount_point end |
#registry ⇒ Object (readonly)
Returns the value of attribute registry.
6 7 8 |
# File 'lib/interfacets/server/config.rb', line 6 def registry @registry end |
Instance Method Details
#all_facets ⇒ Object
49 50 51 |
# File 'lib/interfacets/server/config.rb', line 49 def all_facets @facet_registry.keys.map { facet(_1) } end |
#build_facet(facet_uid: nil, name: nil, id: nil, query: {}) ⇒ Object
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/interfacets/server/config.rb', line 75 def build_facet(facet_uid: nil, name: nil, id: nil, query: {}) if name facet(name).build(id, query:) elsif @facet_registry.key?(facet_uid) facet(facet_uid).build(nil, query:) else *name, id = facet_uid.split("/") facet(name.join("/")).build(id, query:) end end |
#bundled_assets ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/interfacets/server/config.rb', line 22 def bundled_assets dirs = @assets.map(&:to_s) facets = ( @registry .values .map { Object.const_get(_1) } ) Interfacets::Server::Assets.bundle(dirs:, facets:) end |
#default_facet ⇒ Object
53 54 55 |
# File 'lib/interfacets/server/config.rb', line 53 def default_facet build_facet(facet_uid: @default_facet) end |
#facet(name) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/interfacets/server/config.rb', line 57 def facet(name) klass_name = ( if @facet_registry.key?(name) @facet_registry.fetch(name) elsif @facet_registry.values.include?(name) name else raise("unknown facet_class: #{name}") end ) klass_name.constantize end |
#ingest_facet(data) ⇒ Object
71 72 73 |
# File 'lib/interfacets/server/config.rb', line 71 def ingest_facet(data) Facets::Deserializer.call(data:, config: self) end |
#register_facet(name, class_or_class_name) ⇒ Object
44 45 46 47 |
# File 'lib/interfacets/server/config.rb', line 44 def register_facet(name, class_or_class_name) # if klass.name is nil, then just use the class reference @facet_registry[name] = class_or_class_name end |
#schema ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/interfacets/server/config.rb', line 34 def schema @facet_registry .values .map { Object.const_get(_1) } .then { Interfacets::Shared::Facets::Schema::Serializer .call(facets: _1) } end |