Class: GameMachine::Console::Install

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Install

Returns a new instance of Install


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

def initialize(argv)
  puts argv
  @plugin = argv.shift
  
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command


7
8
9
# File 'server/lib/game_machine/console/install.rb', line 7

def command
  @command
end

#helpObject (readonly)

Returns the value of attribute help


7
8
9
# File 'server/lib/game_machine/console/install.rb', line 7

def help
  @help
end

#install_pathObject (readonly)

Returns the value of attribute install_path


7
8
9
# File 'server/lib/game_machine/console/install.rb', line 7

def install_path
  @install_path
end

#install_source_pathObject (readonly)

Returns the value of attribute install_source_path


7
8
9
# File 'server/lib/game_machine/console/install.rb', line 7

def install_source_path
  @install_source_path
end

Instance Method Details

#class_contentObject


35
36
37
# File 'server/lib/game_machine/console/install.rb', line 35

def class_content
  File.read(File.join(templates,'PluginTemplate.template'))
end

#class_outObject


47
48
49
# File 'server/lib/game_machine/console/install.rb', line 47

def class_out
  File.join(plugin_dir,"#{@plugin}.java")
end

#java_dirObject


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

def java_dir
  java_dir = File.join(File.expand_path(Dir.pwd),'java','src','main','java')
end

#loader_contentObject


31
32
33
# File 'server/lib/game_machine/console/install.rb', line 31

def loader_content
  File.read(File.join(templates,'PluginLoaderTemplate.template'))
end

#loader_outObject


39
40
41
# File 'server/lib/game_machine/console/install.rb', line 39

def loader_out
  File.join(plugins_dir,"#{@plugin}Plugin.java")
end

#plugin_dirObject


43
44
45
# File 'server/lib/game_machine/console/install.rb', line 43

def plugin_dir
  File.join(plugins_dir,@plugin.downcase)
end

#plugin_package_dir(name) ⇒ Object


22
23
24
25
# File 'server/lib/game_machine/console/install.rb', line 22

def plugin_package_dir(name)
  File.join(plugins_dir,name)
  FileUtils.mkdir_p(model_src)
end

#plugins_dirObject


18
19
20
# File 'server/lib/game_machine/console/install.rb', line 18

def plugins_dir
  File.join(java_dir,'plugins')
end

#runObject


51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'server/lib/game_machine/console/install.rb', line 51

def run
  puts "Creating plugin #{@plugin}"
  if File.exists?(loader_out) || File.exists?(class_out)
    puts "#{@plugin} exists"
    return
  end

  loader = loader_content
  klass = class_content
  loader.gsub!("CLASS",@plugin)
  loader.gsub!("PACKAGE",@plugin.downcase)

  klass.gsub!("PACKAGE",@plugin.downcase)
  klass.gsub!("CLASS",@plugin)

  FileUtils.mkdir_p(plugin_dir)

  File.open(loader_out,'w') {|f| f.write loader}
  File.open(class_out,'w') {|f| f.write klass}
  
end

#templatesObject


27
28
29
# File 'server/lib/game_machine/console/install.rb', line 27

def templates
  File.join(java_dir,'templates')
end