Class: Gamefic::Shell

Inherits:
Thor
  • Object
show all
Defined in:
lib/gamefic/shell.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol, *args) ⇒ Object

Custom error message for invalid command or filename

Raises:

  • (UndefinedCommandError)


48
49
50
# File 'lib/gamefic/shell.rb', line 48

def method_missing(symbol, *args)
  raise UndefinedCommandError, "Could not find command or file named \"#{symbol}\"."
end

Instance Method Details

#info(file) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/gamefic/shell.rb', line 34

def info(file)
  Dir.mktmpdir 'gamefic_' do |dir|
    decompress file, dir
     = YAML.load_file File.join(dir, 'metadata.yaml')
    .each { |k, v|
      puts "#{k}: #{v}"
    }
  end
rescue StandardError, Zip::Error => e
  puts "'#{file}' does not appear to be a valid Gamefic file."
  show_exception(e) if options[:verbose]
end

#play(file) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/gamefic/shell.rb', line 18

def play(file)
  Dir.mktmpdir 'gamefic_' do |dir|
    puts 'Loading...'
    decompress file, dir
    run_game(dir)
  end
rescue Zip::Error => e
  puts "'#{file}' does not appear to be a valid Gamefic file."
  show_exception(e) if options[:verbose]
rescue StandardError => e
  puts "An error occurred: #{e.message}"
  show_exception(e) if options[:verbose]
end

#versionObject



12
13
14
# File 'lib/gamefic/shell.rb', line 12

def version
  puts "gamefic #{Gamefic::VERSION}"
end