Class: Gemba::FrameStack
- Inherits:
-
Object
- Object
- Gemba::FrameStack
- Defined in:
- lib/gemba/frame_stack.rb
Overview
Push/pop stack for content frames inside the main window.
Mirrors the ModalStack pattern. When a new frame is pushed, the previous frame is hidden and the new one is shown. Popping reverses the transition.
Frames must implement the FrameStack protocol:
show
Defined Under Namespace
Classes: Entry
Instance Method Summary collapse
-
#active? ⇒ Boolean
True if any frame is on the stack.
-
#current ⇒ Symbol?
Name of the topmost frame.
-
#current_frame ⇒ Object?
The topmost frame object.
-
#initialize ⇒ FrameStack
constructor
A new instance of FrameStack.
-
#pop ⇒ Object
Pop the current frame off the stack.
-
#push(name, frame) ⇒ Object
Push a frame onto the stack.
-
#size ⇒ Integer
Number of frames on the stack.
Constructor Details
#initialize ⇒ FrameStack
Returns a new instance of FrameStack.
23 24 25 |
# File 'lib/gemba/frame_stack.rb', line 23 def initialize @stack = [] end |
Instance Method Details
#active? ⇒ Boolean
Returns true if any frame is on the stack.
28 |
# File 'lib/gemba/frame_stack.rb', line 28 def active? = !@stack.empty? |
#current ⇒ Symbol?
Returns name of the topmost frame.
31 |
# File 'lib/gemba/frame_stack.rb', line 31 def current = @stack.last&.name |
#current_frame ⇒ Object?
Returns the topmost frame object.
34 |
# File 'lib/gemba/frame_stack.rb', line 34 def current_frame = @stack.last&.frame |
#pop ⇒ Object
Pop the current frame off the stack.
The popped frame is hidden. If there’s a previous frame, it is re-shown.
54 55 56 57 58 |
# File 'lib/gemba/frame_stack.rb', line 54 def pop return unless (entry = @stack.pop) entry.frame.hide @stack.last&.frame&.show end |
#push(name, frame) ⇒ Object
Push a frame onto the stack.
The previous frame (if any) is hidden before the new one is shown.
45 46 47 48 49 |
# File 'lib/gemba/frame_stack.rb', line 45 def push(name, frame) @stack.last&.frame&.hide @stack.push(Entry.new(name: name, frame: frame)) frame.show end |
#size ⇒ Integer
Returns number of frames on the stack.
37 |
# File 'lib/gemba/frame_stack.rb', line 37 def size = @stack.length |