Sha256: 386eee8c7297d3a8cccfcd657bab0795ede3008609e544deaa9dbe24c73ceedb

Contents?: true

Size: 1.68 KB

Versions: 25

Compression:

Stored size: 1.68 KB

Contents

# frozen_string_literal: true

module PlatformosCheck
  class Corrector
    include JsonHelpers

    def initialize(app_file:)
      @app_file = app_file
    end

    def insert_after(node, content, character_range = nil)
      @app_file.rewriter.insert_after(node, content, character_range)
    end

    def insert_before(node, content, character_range = nil)
      @app_file.rewriter.insert_before(node, content, character_range)
    end

    def remove(node)
      @app_file.rewriter.remove(node)
    end

    def replace(node, content, character_range = nil)
      @app_file.rewriter.replace(node, content, character_range)
      node.markup = content
    end

    def replace_inner_markup(node, content)
      @app_file.rewriter.replace_inner_markup(node, content)
    end

    def replace_inner_json(node, json, **)
      replace_inner_markup(node, pretty_json(json, **))
    end

    def wrap(node, insert_before, insert_after)
      @app_file.rewriter.wrap(node, insert_before, insert_after)
    end

    def create_file(storage, relative_path, content)
      storage.write(relative_path, content)
    end

    def remove_file(storage, relative_path)
      storage.remove(relative_path)
    end

    def mkdir(storage, relative_path)
      storage.mkdir(relative_path)
    end

    # def rename(storage, old_path, new_path)
    #   storage.rename(old_path, new_path)
    # end

    def add_translation(json_file, path, value)
      hash = json_file.content
      JsonHelper.set(hash, path, value)
      json_file.update_contents(hash)
    end

    def remove_translation(json_file, path)
      hash = json_file.content
      JsonHelper.delete(hash, path)
      json_file.update_contents(hash)
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
platformos-check-0.4.14 lib/platformos_check/corrector.rb
platformos-check-0.4.13 lib/platformos_check/corrector.rb
platformos-check-0.4.12 lib/platformos_check/corrector.rb
platformos-check-0.4.11 lib/platformos_check/corrector.rb
platformos-check-0.4.10 lib/platformos_check/corrector.rb
platformos-check-0.4.9 lib/platformos_check/corrector.rb
platformos-check-0.4.8 lib/platformos_check/corrector.rb
platformos-check-0.4.7 lib/platformos_check/corrector.rb
platformos-check-0.4.6 lib/platformos_check/corrector.rb
platformos-check-0.4.5 lib/platformos_check/corrector.rb
platformos-check-0.4.4 lib/platformos_check/corrector.rb
platformos-check-0.4.3 lib/platformos_check/corrector.rb
platformos-check-0.4.2 lib/platformos_check/corrector.rb
platformos-check-0.4.1 lib/platformos_check/corrector.rb
platformos-check-0.4.0 lib/platformos_check/corrector.rb
platformos-check-0.3.3 lib/platformos_check/corrector.rb
platformos-check-0.3.1 lib/platformos_check/corrector.rb
platformos-check-0.3.0 lib/platformos_check/corrector.rb
platformos-check-0.2.2 lib/platformos_check/corrector.rb
platformos-check-0.2.1 lib/platformos_check/corrector.rb