class JsonUpdater::UpdateService

Attributes

changeable_file_path[R]
json_changeable[R]
json_etalon[R]

Public Class Methods

new(changeable_file_path:, etalon_file_path:) click to toggle source
# File lib/json_updater.rb, line 22
def initialize(changeable_file_path:, etalon_file_path:)
  @changeable_file_path = changeable_file_path

  @json_changeable = JSON.parse(File.open(changeable_file_path).read)
  @json_etalon = JSON.parse(File.open(etalon_file_path).read)
end
update_json(changeable_file_path:, etalon_file_path:) click to toggle source
# File lib/json_updater.rb, line 18
def self.update_json(changeable_file_path:, etalon_file_path:)
  new(changeable_file_path: changeable_file_path, etalon_file_path: etalon_file_path).update_json
end

Public Instance Methods

update_json() click to toggle source
# File lib/json_updater.rb, line 29
def update_json
  rewrite_file
end

Private Instance Methods

output_json() click to toggle source
# File lib/json_updater.rb, line 39
def output_json
  JSON.pretty_generate(updated_json)
end
rewrite_file() click to toggle source
# File lib/json_updater.rb, line 35
def rewrite_file
  File.open(changeable_file_path, 'w') { |file| file.write(output_json) }
end
updated_json() click to toggle source
# File lib/json_updater.rb, line 43
def updated_json
  JsonUpdater::JsonFullBuilder.build(json_changeable: json_changeable, json_etalon: json_etalon)
end