Module: Oschii::ConfigFile
- Included in:
- Device
- Defined in:
- lib/oschii/config_file.rb
Instance Method Summary collapse
- #save_config(filename = nil, silent: false) ⇒ Object
- #upload_config(filename = nil, silent: false) ⇒ Object
Instance Method Details
#save_config(filename = nil, silent: false) ⇒ Object
32 33 34 35 36 |
# File 'lib/oschii/config_file.rb', line 32 def save_config(filename = nil, silent: false) filename ||= "configs/#{name}_#{Time.now.iso8601}.json" File.write filename, JSON.pretty_generate(config) puts "Saved #{filename.split('/')[-1]}" unless silent end |
#upload_config(filename = nil, silent: false) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/oschii/config_file.rb', line 3 def upload_config(filename = nil, silent: false) if filename.nil? filenames = Dir.glob("configs/#{name}_*.json") if filenames.empty? puts 'No previous config' unless silent return end filename = filenames.sort.last unless silent display_name = filename.split('/')[-1] .split('_')[-1] .split('+')[0] .gsub('T', ' ') .gsub('.json', '') puts "Latest: #{display_name}" begin prompt '>> [ENTER] to upload, [ESC] to cancel <<' rescue CancelSerialQuery return end end end self.config = JSON.parse File.read(filename) self end |