Class: Mmi::Interactive::Updater

Inherits:
Object
  • Object
show all
Includes:
Assets, Modloader
Defined in:
lib/mmi/interactive/updater.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Assets

#add_asset, #create_source, #update_asset_source_version, #update_assets

Constructor Details

#initialize(processor, file_path = nil) ⇒ Updater

Returns a new instance of Updater.



15
16
17
18
# File 'lib/mmi/interactive/updater.rb', line 15

def initialize(processor, file_path=nil)
	self.processor = processor
	self.file_path = file_path
end

Instance Attribute Details

#file_pathObject

Returns the value of attribute file_path.



13
14
15
# File 'lib/mmi/interactive/updater.rb', line 13

def file_path
  @file_path
end

#processorObject

Returns the value of attribute processor.



12
13
14
# File 'lib/mmi/interactive/updater.rb', line 12

def processor
  @processor
end

Instance Method Details

#run!Object



20
21
22
23
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
# File 'lib/mmi/interactive/updater.rb', line 20

def run!
	loop do
		to_update = CLI::UI::Prompt.ask('What do you want to update?') do |handler|
			[
				['modloader',              :modloader   ],
				['assets',                 :assets      ],
				['quit & save changes',    :quit_save   ],
				['quit & discard changes', :quit_discard],
			].each do |name, result|
				handler.option(name) do
					result
				end
			end
		end
		
		case to_update
			when :modloader
				update_modloader
			when :assets
				update_assets
			when :quit_save
				file_path = CLI::UI::Prompt.ask('Filename', default: self.file_path, is_file: true)
				yaml      = self.processor.to_h.to_yaml
				
				File.write(File.expand_path(file_path, Dir.pwd), yaml)
				break
			when :quit_discard
				break
			else
				raise 'Consider yourself lucky, you found a bug.'
		end
	end
end