class Fastlane::Actions::FindReplaceStringAction

Public Class Methods

authors() click to toggle source
# File lib/fastlane/plugin/find_replace_string/actions/find_replace_string_action.rb, line 26
def self.authors
    ["Jonathan Ritchie"]
end
available_options() click to toggle source
# File lib/fastlane/plugin/find_replace_string/actions/find_replace_string_action.rb, line 34
def self.available_options
    [
        FastlaneCore::ConfigItem.new(key: :old_string,
            env_name: "OLD_STRING",
            description: "The string that will be replaced in the file",
            optional: false,
        type: String),
        FastlaneCore::ConfigItem.new(key: :new_string,
            env_name: "NEW_STRING",
            description: "The string that will be injected into the file",
            optional: false,
        type: String),
        FastlaneCore::ConfigItem.new(key: :path_to_file,
            env_name: "PATH_TO_FILE",
            description: "Path to the file to be modified",
            optional: false,
        type: String)
    ]
end
description() click to toggle source
# File lib/fastlane/plugin/find_replace_string/actions/find_replace_string_action.rb, line 22
def self.description
    "Find and replace a string in a project file"
end
details() click to toggle source
# File lib/fastlane/plugin/find_replace_string/actions/find_replace_string_action.rb, line 30
def self.details
    "This plugin simply allows you to find a replace a string in a project file. All instances of the matched string in the file will be replaced. The string search is case sensitive"
end
is_supported?(platform) click to toggle source
# File lib/fastlane/plugin/find_replace_string/actions/find_replace_string_action.rb, line 54
def self.is_supported?(platform)
    [:ios, :mac, :android].include?(platform)
    true
end
run(params) click to toggle source
# File lib/fastlane/plugin/find_replace_string/actions/find_replace_string_action.rb, line 4
def self.run(params)
    path_to_file = File.expand_path(params[:path_to_file])
    old_string = params[:old_string]
    new_string = params[:new_string]

    UI.user_error!("ERROR - File not found at location: '#{path_to_file}'") unless File.exist?(path_to_file)

    UI.message("Reading file...")
    file = File.open(path_to_file, "r")
    fileText = file.read
    file.close

    UI.message("Replacing all occurences of '#{old_string}' with '#{new_string}' in file...")
    fileText.gsub!(old_string, new_string)
    File.open(path_to_file, "w") { |file| file << fileText }
    UI.success("Find and replace finished!")
end