class GitPrepareBranch::App
Attributes
logger[R]
router[RW]
title[RW]
Public Class Methods
configure(*options, &block)
click to toggle source
# File lib/git-prepare-branch/app.rb, line 93 def configure(*options, &block) self.new(*options).configure(&block) end
new(logger: nil)
click to toggle source
# File lib/git-prepare-branch/app.rb, line 17 def initialize(logger: nil) @logger = logger || Logger.new end
Public Instance Methods
add_event_handler(event, &block)
click to toggle source
# File lib/git-prepare-branch/app.rb, line 21 def add_event_handler(event, &block) event_handlers[event] ||= [] event_handlers[event] << block end
add_screen(screen)
click to toggle source
# File lib/git-prepare-branch/app.rb, line 26 def add_screen screen screen.context = context screens[screen.name] = screen end
add_variable(name, capture: nil, value: nil)
click to toggle source
# File lib/git-prepare-branch/app.rb, line 31 def add_variable name, capture: nil, value: nil context.variables[name] = Variable.new(name, context: context, capture: capture, value: value).value end
configure(&block)
click to toggle source
# File lib/git-prepare-branch/app.rb, line 35 def configure(&block) Configurator.new(self).apply(&block) self end
context()
click to toggle source
# File lib/git-prepare-branch/app.rb, line 40 def context @context ||= Context.new( terminal: terminal, variables: {} ) end
current_screen()
click to toggle source
# File lib/git-prepare-branch/app.rb, line 47 def current_screen screens[current_screen_name] end
current_screen_name()
click to toggle source
# File lib/git-prepare-branch/app.rb, line 51 def current_screen_name router.call(context) end
screens()
click to toggle source
# File lib/git-prepare-branch/app.rb, line 55 def screens @screens ||= {} end
start(variables = [])
click to toggle source
# File lib/git-prepare-branch/app.rb, line 59 def start(variables = []) variables.each { |name, args| add_variable(name, args) } trigger :load while true do begin terminal.clear trigger :display terminal.write_line format(current_screen.heading, context.variables.to_h), current_screen.heading_style terminal.call current_screen.display, context.variables.to_h terminal.say 'Press a command key or ? for help', :hint begin result = terminal.wait_for_keypress current_screen.handle_keypress result, context rescue Interrupt end rescue Interrupt exit end end end
terminal()
click to toggle source
# File lib/git-prepare-branch/app.rb, line 80 def terminal @terminal ||= Terminal.new(logger: logger) end
trigger(event)
click to toggle source
# File lib/git-prepare-branch/app.rb, line 84 def trigger event return unless event_handlers[event] event_handlers[event].each do |block| block.call(context) end end
Private Instance Methods
event_handlers()
click to toggle source
# File lib/git-prepare-branch/app.rb, line 100 def event_handlers @event_handlers ||= {} end