Class: GitPrepareBranch::App
- Inherits:
-
Object
- Object
- GitPrepareBranch::App
- Defined in:
- lib/git-prepare-branch/app.rb
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#router ⇒ Object
Returns the value of attribute router.
-
#title ⇒ Object
Returns the value of attribute title.
Class Method Summary collapse
Instance Method Summary collapse
- #add_event_handler(event, &block) ⇒ Object
- #add_screen(screen) ⇒ Object
- #add_variable(name, capture: nil, value: nil) ⇒ Object
- #configure(&block) ⇒ Object
- #context ⇒ Object
- #current_screen ⇒ Object
- #current_screen_name ⇒ Object
-
#initialize(logger: nil) ⇒ App
constructor
A new instance of App.
- #screens ⇒ Object
- #start(variables = []) ⇒ Object
- #terminal ⇒ Object
- #trigger(event) ⇒ Object
Constructor Details
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
13 14 15 |
# File 'lib/git-prepare-branch/app.rb', line 13 def logger @logger end |
#router ⇒ Object
Returns the value of attribute router.
15 16 17 |
# File 'lib/git-prepare-branch/app.rb', line 15 def router @router end |
#title ⇒ Object
Returns the value of attribute title.
15 16 17 |
# File 'lib/git-prepare-branch/app.rb', line 15 def title @title end |
Class Method Details
.configure(*options, &block) ⇒ Object
93 94 95 |
# File 'lib/git-prepare-branch/app.rb', line 93 def configure(*, &block) self.new(*).configure(&block) end |
Instance Method Details
#add_event_handler(event, &block) ⇒ Object
21 22 23 24 |
# 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) ⇒ Object
26 27 28 29 |
# 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) ⇒ Object
31 32 33 |
# 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) ⇒ Object
35 36 37 38 |
# File 'lib/git-prepare-branch/app.rb', line 35 def configure(&block) Configurator.new(self).apply(&block) self end |
#context ⇒ Object
40 41 42 43 44 45 |
# File 'lib/git-prepare-branch/app.rb', line 40 def context @context ||= Context.new( terminal: terminal, variables: {} ) end |
#current_screen ⇒ Object
47 48 49 |
# File 'lib/git-prepare-branch/app.rb', line 47 def current_screen screens[current_screen_name] end |
#current_screen_name ⇒ Object
51 52 53 |
# File 'lib/git-prepare-branch/app.rb', line 51 def current_screen_name router.call(context) end |
#screens ⇒ Object
55 56 57 |
# File 'lib/git-prepare-branch/app.rb', line 55 def screens @screens ||= {} end |
#start(variables = []) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# 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 ⇒ Object
80 81 82 |
# File 'lib/git-prepare-branch/app.rb', line 80 def terminal @terminal ||= Terminal.new(logger: logger) end |
#trigger(event) ⇒ Object
84 85 86 87 88 89 90 |
# 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 |