Class: Mutx::Support::Update
- Inherits:
-
Object
- Object
- Mutx::Support::Update
- Defined in:
- lib/mutx/support/update.rb
Constant Summary collapse
- @@project_folder =
"#{Dir.pwd}/mutx/"
Class Method Summary collapse
-
.mutx_conf ⇒ Object
Returns the most updated version of mutx_conf file, and updates the file if neded.
-
.update_json_file(name) ⇒ Object
It also removes all keys not longer present in the template file.
Class Method Details
.mutx_conf ⇒ Object
Returns the most updated version of mutx_conf file, and updates the file if neded
10 11 12 |
# File 'lib/mutx/support/update.rb', line 10 def self.mutx_conf update_json_file "conf/mutx.conf" end |
.update_json_file(name) ⇒ Object
It also removes all keys not longer present in the template file.
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 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/mutx/support/update.rb', line 20 def self.update_json_file name file = JSON.parse(IO.read(@@project_folder + name)) # template = JSON.parse(IO.read(@gem_folder + name + ".tt")) # modified = false # deprecated_keys = file.keys - template.keys # if deprecated_keys.any? # deprecated_keys.each { |key| file.delete key } # modified = true # puts "The following keys: #{deprecated_keys} are deprecated and are going to be removed from your #{name} file.".colorize(:green) # end # if file.keys.sort != template.keys.sort # puts "The following keys: #{template.keys - file.keys} are new and are going to be added to your #{name} file.".colorize(:green) # modified = true # file.merge! template # end # file.keys.each do |key| # if file[key].class == Hash # deprecated_sub_keys = file[key].keys - template[key].keys # if deprecated_sub_keys.any? # deprecated_sub_keys.each{ |sub_key| file[key].delete sub_key } # modified = true # puts "The following sub keys: #{deprecated_sub_keys} from #{key} key are deprecated and are going to be removed from your #{name} file.".colorize(:green) # end # if file[key].keys.sort != template[key].keys.sort # puts "The following sub keys: #{template[key].keys - file[key].keys} from #{key} key are new and are going to be added to your #{name} file.".colorize(:green) # modified = true # file[key].merge! template[key] # end # end # end # if modified # File.write(@project_folder + name, JSON.pretty_generate(file)) # puts "Done.".colorize(:green) # end file end |