lib/discourse_theme/uploader.rb in discourse_theme-0.8.0 vs lib/discourse_theme/uploader.rb in discourse_theme-0.9.0

- old
+ new

@@ -7,17 +7,17 @@ @theme_id = theme_id @components = components end def compress_dir(gzip, dir) - sgz = Zlib::GzipWriter.new(File.open(gzip, 'wb')) + sgz = Zlib::GzipWriter.new(File.open(gzip, "wb")) tar = Archive::Tar::Minitar::Output.new(sgz) Dir.chdir(dir + "/../") do Find.find(File.basename(dir)) do |x| bn = File.basename(x) - Find.prune if bn == "node_modules" || bn == "src" || bn[0] == ?. + Find.prune if bn == "node_modules" || bn == "src" || bn[0] == "." next if File.directory?(x) Minitar.pack_file(x, tar) end end @@ -37,29 +37,22 @@ end end count end - def upload_theme_field(target: , name: , type_id: , value:) + def upload_theme_field(target:, name:, type_id:, value:) raise "expecting theme_id to be set!" unless @theme_id args = { theme: { - theme_fields: [{ - name: name, - target: target, - type_id: type_id, - value: value - }] - } + theme_fields: [{ name: name, target: target, type_id: type_id, value: value }], + }, } response = @client.update_theme(@theme_id, args) json = JSON.parse(response.body) - if diagnose_errors(json) != 0 - UI.error "(end of errors)" - end + UI.error "(end of errors)" if diagnose_errors(json) != 0 end def upload_full_theme filename = "#{Pathname.new(Dir.tmpdir).realpath}/bundle_#{SecureRandom.hex}.tar.gz" compress_dir(filename, @dir) @@ -67,16 +60,13 @@ File.open(filename) do |tgz| response = @client.upload_full_theme(tgz, theme_id: @theme_id, components: @components) json = JSON.parse(response.body) @theme_id = json["theme"]["id"] - if diagnose_errors(json) != 0 - UI.error "(end of errors)" - end + UI.error "(end of errors)" if diagnose_errors(json) != 0 @theme_id end ensure FileUtils.rm_f filename end - end end