Class: SmartBrain::Scopes::Registry
- Inherits:
-
Object
- Object
- SmartBrain::Scopes::Registry
- Defined in:
- lib/smart_brain/scopes/registry.rb
Instance Method Summary collapse
-
#initialize(db: nil, clock: -> { Time.now.utc }) ⇒ Registry
constructor
A new instance of Registry.
- #resolve(domain_id:, session_id:, scope_context:, allowed_types: Contracts::ScopeRef::DEFAULT_ALLOWED_TYPES) ⇒ Object
Constructor Details
#initialize(db: nil, clock: -> { Time.now.utc }) ⇒ Registry
Returns a new instance of Registry.
9 10 11 12 13 14 15 16 |
# File 'lib/smart_brain/scopes/registry.rb', line 9 def initialize(db: nil, clock: -> { Time.now.utc }) @db = db @clock = clock @domains = {} @sessions = {} @scopes = {} @links = {} end |
Instance Method Details
#resolve(domain_id:, session_id:, scope_context:, allowed_types: Contracts::ScopeRef::DEFAULT_ALLOWED_TYPES) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/smart_brain/scopes/registry.rb', line 18 def resolve(domain_id:, session_id:, scope_context:, allowed_types: Contracts::ScopeRef::DEFAULT_ALLOWED_TYPES) context = Contracts::ScopeContext.normalize( domain_id: domain_id, session_id: session_id, scope_context: scope_context, allowed_types: allowed_types ) records = db ? resolve_postgres(context, session_id.to_s) : resolve_memory(context, session_id.to_s) default_key = scope_key(context[:default_write]) context.merge( scopes: records, scope_ids: records.map { |record| record[:scope_id] }, default_write_scope: records.find { |record| scope_key(record) == default_key } ) end |