Class: Sesame::Jinn
- Inherits:
-
Object
- Object
- Sesame::Jinn
- Defined in:
- lib/sesame/jinn.rb
Overview
The Jinn class is wholly responsible for interacting with the terminal.
Instance Method Summary collapse
-
#initialize(opts, pow = 30) ⇒ Jinn
constructor
Pass in parsed command-line options as a Slop instance.
-
#process! ⇒ Object
Process the users request, possibly starting an interactive session.
Constructor Details
#initialize(opts, pow = 30) ⇒ Jinn
Pass in parsed command-line options as a Slop instance. The optional pow parameter should only be used to speed up tests.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/sesame/jinn.rb', line 12 def initialize(opts, pow = 30) I18n.load_path = Dir[File.join(File.dirname(__FILE__), 'lang', '*yml')] @opts = opts _config _parse _welcome @cave = Cave.new(@opts[:path], pow) rescue Fail => e _error(e.) end |
Instance Method Details
#process! ⇒ Object
Process the users request, possibly starting an interactive session.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/sesame/jinn.rb', line 24 def process! return if @cave.nil? @was_locked = false raise Fail, 'Cannot lock and expunge simultaneously' if @opts.lock? && @opts.expunge? if @cave.exists? raise Fail, 'Please remove the cave before attempting to reconstruct' if @opts.reconstruct? raise Fail, 'Cannot expunge lock; it doesn\'t exist' if @opts.expunge? && !@cave.locked? raise Fail, 'Please specify a command (or use interactive mode)' if !@opts.interactive? && @opts[:command].nil? && !@opts.lock? && !@opts.expunge? if @cave.locked? && @opts.expunge? @cave.forget _warn('Lock expunged') end if @cave.locked? _unlock @was_locked = true else _open end else @cave.forget if @cave.locked? _new end _process(@opts[:command]) if @opts.interactive? loop do say("\n") break if _prompt end if @opts.expunge? @cave.close else _lock end elsif @opts.expunge? || (!@was_locked && !@opts.lock?) @cave.close else _lock end rescue Fail => e _error(e.) rescue SystemExit, Interrupt _error('Stopped by user') end |