Class: Teek::UI::Scope

Inherits:
Object
  • Object
show all
Defined in:
lib/teek/ui/scope.rb

Overview

A component's build-time namespace - ambient builder state, kept on a stack parallel to WidgetDSL's own @stack (see WidgetDSL#component). A real object rather than a bare String/nil on purpose: TOP_LEVEL is one unmistakable sentinel, checked by identity (+#top_level?+/+#equal?+) rather than a value any caller could accidentally collide with (+nil+, an empty string, a label someone else also chose, ...). Two Scope instances are never the same scope just because they share a label - Document keys on identity, so every WidgetDSL#component call gets a genuinely fresh, distinct scope regardless of what label (if any) it's given.

Constant Summary collapse

TOP_LEVEL =

The single sentinel for "not inside any component" - the default scope for a build that never calls WidgetDSL#component at all.

Scope.new(:top_level).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label = nil, parent: nil) ⇒ Scope

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Scope.



25
26
27
28
# File 'lib/teek/ui/scope.rb', line 25

def initialize(label = nil, parent: nil)
  @label = label
  @parent = parent
end

Instance Attribute Details

#labelSymbol, ... (readonly)

Returns a human-readable label, for error messages/debugging - never part of identity/equality.

Returns:

  • (Symbol, String, nil)

    a human-readable label, for error messages/debugging - never part of identity/equality



18
19
20
# File 'lib/teek/ui/scope.rb', line 18

def label
  @label
end

#parentScope? (readonly)

Returns the enclosing scope this one was opened inside - nil only for TOP_LEVEL itself.

Returns:

  • (Scope, nil)

    the enclosing scope this one was opened inside - nil only for TOP_LEVEL itself



22
23
24
# File 'lib/teek/ui/scope.rb', line 22

def parent
  @parent
end

Instance Method Details

#top_level?Boolean

Returns whether this is TOP_LEVEL.

Returns:



31
32
33
# File 'lib/teek/ui/scope.rb', line 31

def top_level?
  equal?(TOP_LEVEL)
end