Class: CommandTower::Configuration::Registry::InboxPresentations::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/command_tower/configuration/registry/inbox_presentations/config.rb

Overview

No CommandTower-owned presentations are seeded — no PLATFORM_* constant, unlike AdminWorkspace/PrincipalCapabilities. Every registered key today is host-owned (Rich Messaging Slice 2.5).

Constant Summary collapse

KEY_FORMAT =
/\A[a-z][a-z0-9]*(?:[._][a-z][a-z0-9]*)*\z/

Instance Method Summary collapse

Constructor Details

#initialize ⇒ Config

Returns a new instance of Config.



16
17
18
19
# File 'lib/command_tower/configuration/registry/inbox_presentations/config.rb', line 16

def initialize
  @definitions = {}
  @finalized = false
end

Instance Method Details

#definitions ⇒ Object



58
59
60
# File 'lib/command_tower/configuration/registry/inbox_presentations/config.rb', line 58

def definitions
  @definitions.dup.freeze
end

#fetch(key) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/command_tower/configuration/registry/inbox_presentations/config.rb', line 41

def fetch(key)
  normalized = normalize_key!(key)
  definition = @definitions[normalized]
  if definition.nil?
    raise CommandTower::InboxPresentations::UnregisteredCapabilityError,
      "inbox presentation #{normalized} is not registered"
  end

  definition
end

#finalize! ⇒ Object



62
63
64
65
66
67
68
69
70
71
# File 'lib/command_tower/configuration/registry/inbox_presentations/config.rb', line 62

def finalize!
  @definitions.each_value do |definition|
    next unless definition.respond_to?(:class_composer_freeze_objects!)

    definition.class_composer_freeze_objects!(behavior: :raise, children: true)
  end
  @definitions.freeze
  @finalized = true
  self
end

#finalized? ⇒ Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/command_tower/configuration/registry/inbox_presentations/config.rb', line 73

def finalized?
  @finalized
end

#presentation(key, owner: :host) {|definition| ... } ⇒ Object

Yields:

  • (definition)


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/command_tower/configuration/registry/inbox_presentations/config.rb', line 21

def presentation(key, owner: :host)
  if @finalized
    raise CommandTower::InboxPresentations::FrozenRegistryError,
      "inbox presentations registry is frozen"
  end

  normalized = normalize_key!(key)
  if @definitions.key?(normalized)
    raise CommandTower::InboxPresentations::DuplicateCapabilityError,
      "inbox presentation #{normalized} is already registered"
  end

  definition = PresentationDefinition.new
  yield definition if block_given?
  definition.owner = owner
  definition.validate_definition!(key: normalized)
  @definitions[normalized] = definition
  definition
end

#registered?(key) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
55
56
# File 'lib/command_tower/configuration/registry/inbox_presentations/config.rb', line 52

def registered?(key)
  @definitions.key?(normalize_key!(key))
rescue CommandTower::InboxPresentations::InvalidKeyError
  false
end

#reset_host_definitions! ⇒ Object



77
78
79
80
81
# File 'lib/command_tower/configuration/registry/inbox_presentations/config.rb', line 77

def reset_host_definitions!
  thaw_for_test!
  @definitions.delete_if { |_key, definition| definition.owner == :host }
  self
end