Class: GameMachine::Console::Install

Inherits:
Object
  • Object
show all
Defined in:
lib/game_machine/console/install.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command, argv, install_source_path) ⇒ Install

Returns a new instance of Install.



6
7
8
9
10
11
12
# File 'lib/game_machine/console/install.rb', line 6

def initialize(command,argv,install_source_path)
  @command = command
  @install_path = argv.shift
  @install_source_path = install_source_path
  
  puts "Installing from #{install_source_path}"
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



5
6
7
# File 'lib/game_machine/console/install.rb', line 5

def command
  @command
end

#helpObject (readonly)

Returns the value of attribute help.



5
6
7
# File 'lib/game_machine/console/install.rb', line 5

def help
  @help
end

#install_pathObject (readonly)

Returns the value of attribute install_path.



5
6
7
# File 'lib/game_machine/console/install.rb', line 5

def install_path
  @install_path
end

#install_source_pathObject (readonly)

Returns the value of attribute install_source_path.



5
6
7
# File 'lib/game_machine/console/install.rb', line 5

def install_source_path
  @install_source_path
end

Instance Method Details

#bin_sourceObject



100
101
102
# File 'lib/game_machine/console/install.rb', line 100

def bin_source
  File.join(install_source_path,'bin')
end

#config_sourceObject



108
109
110
# File 'lib/game_machine/console/install.rb', line 108

def config_source
  File.join(install_source_path,'config')
end

#error(reason = '') ⇒ Object



14
15
16
# File 'lib/game_machine/console/install.rb', line 14

def error(reason='')
  puts "Invalid install path #{install_path} (#{reason})"
end

#games_sourceObject



112
113
114
# File 'lib/game_machine/console/install.rb', line 112

def games_source
  File.join(install_source_path,'games')
end

#gemfile_sourceObject



84
85
86
# File 'lib/game_machine/console/install.rb', line 84

def gemfile_source
  File.join(install_source_path,'Gemfile')
end

#gemlockfile_sourceObject



88
89
90
# File 'lib/game_machine/console/install.rb', line 88

def gemlockfile_source
  File.join(install_source_path,'Gemfile.lock')
end

#installObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/game_machine/console/install.rb', line 38

def install
  puts "Installing into #{install_path}"
  path = File.expand_path(install_path)
  FileUtils.mkdir(path)
  FileUtils.cp_r(config_source,path)
  FileUtils.cp_r(games_source,path)
  FileUtils.cp_r(java_source,path)
  FileUtils.cp_r(mono_source,path)

  FileUtils.cp_r(web_source,path)
  FileUtils.cp_r(lib_source,path)
  FileUtils.cp_r(bin_source,path)

  FileUtils.cp(gemfile_source,path)
  FileUtils.cp(gemlockfile_source,path)
end

#java_project_sourceObject



116
117
118
# File 'lib/game_machine/console/install.rb', line 116

def java_project_source
  File.join(install_source_path,'java','project')
end

#java_sourceObject



120
121
122
# File 'lib/game_machine/console/install.rb', line 120

def java_source
  File.join(install_source_path,'java')
end

#lib_sourceObject



96
97
98
# File 'lib/game_machine/console/install.rb', line 96

def lib_source
  File.join(install_source_path,'lib')
end

#mono_sourceObject



104
105
106
# File 'lib/game_machine/console/install.rb', line 104

def mono_source
  File.join(install_source_path,'mono')
end

#run!Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/game_machine/console/install.rb', line 18

def run!
  if install_path.nil? || install_path.empty?
    error("Invalid input")
    return
  end

  if command == 'install' && File.exists?(install_path)
    error("Directory exists")
    return
  end

  if command == 'upgrade' && !File.exists?(install_path)
    error("Installation not found")
    return
  end

  @install_path = File.expand_path(install_path)
  send(command.to_sym)
end

#upgradeObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/game_machine/console/install.rb', line 55

def upgrade
  puts "Upgrading installation at #{install_path}"
  path = File.expand_path(install_path)

  puts "Upgrading mono"
  FileUtils.rm_rf(File.join(path,'mono'))
  FileUtils.cp_r(mono_source,path)

  puts 'Upgrading java'
  FileUtils.rm_rf(File.join(path,'java','project'))
  FileUtils.cp_r(java_project_source, File.join(path,'java','project'))

  puts 'Upgrading Gemfile'
  FileUtils.rm_rf(File.join(path,'Gemfile'))
  FileUtils.cp(gemfile_source,path)

  FileUtils.rm_rf(File.join(path,'Gemfile.lock'))
  FileUtils.cp(gemlockfile_source,path)

  puts 'Upgrading lib'
  FileUtils.rm_rf(File.join(path,'lib'))
  FileUtils.cp_r(lib_source,path)

  puts 'Upgrading bin'
  FileUtils.rm_rf(File.join(path,'bin'))
  FileUtils.cp_r(bin_source,path)
  
end

#web_sourceObject



92
93
94
# File 'lib/game_machine/console/install.rb', line 92

def web_source
  File.join(install_source_path,'web')
end