<commit_before>require 'tempfile'

module Geminabox
  module Proxy
    class Splicer < FileHandler

      def self.make(file_name)
        splicer = new(file_name)
        splicer.create
        splicer
      end

      def create
        data = new_content
        return nil if data.nil?
        begin
          tmp = Tempfile.new('geminabox')
          File.open(tmp, 'w'){|f| f.write(data)}
        rescue
          return nil
        end

        FileUtils.mv tmp, splice_path
      end

      def new_content
        if local_file_exists?
          merge_content
        else
          remote_content
        end
      end

      def splice_path
        proxy_path
      end

      def splice_folder_path
        proxy_folder_path
      end

      def splice_file_exists?
        file_exists? splice_path<commit_msg>Fix #245 not to disguise an exception<commit_after>require 'tempfile'
require 'fileutils'

module Geminabox
  module Proxy
    class Splicer < FileHandler

      def self.make(file_name)
        splicer = new(file_name)
        splicer.create
        splicer
      end

      def create
        data = new_content
        f = Tempfile.create('geminabox')
        begin
          f.write(data)
        ensure
          f.close rescue nil
        end
        FileUtils.mv f.path, splice_path
      end

      def new_content
        if local_file_exists?
          merge_content
        else
          remote_content
        end
      end

      def splice_path
        proxy_path
      end

      def splice_folder_path
        proxy_folder_path
      end

      def splice_file_exists?
        file_exists? splice_path
{'fraction_non_alphanumeric': 0.04451219512195122, 'fraction_numerical': 0.001829268292682927, 'mean_word_length': 1.6006339144215531, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '752526', 'n_tokens_mistral': 499, 'n_tokens_neox': 473, 'n_words': 120}