Class: Fastlane::Actions::RevertPatchAction
- Inherits:
-
Action
- Object
- Action
- Fastlane::Actions::RevertPatchAction
- Defined in:
- lib/fastlane/plugin/patch/actions/revert_patch_action.rb
Class Method Summary collapse
- .authors ⇒ Object
- .available_options ⇒ Object
- .description ⇒ Object
- .details ⇒ Object
- .example_code ⇒ Object
- .is_supported?(platform) ⇒ Boolean
- .run(params) ⇒ Object
Class Method Details
.authors ⇒ Object
55 56 57 |
# File 'lib/fastlane/plugin/patch/actions/revert_patch_action.rb', line 55 def self. ["Jimmy Dee"] end |
.available_options ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/fastlane/plugin/patch/actions/revert_patch_action.rb', line 85 def self. [ FastlaneCore::ConfigItem.new(key: :files, description: "Absolute or relative path(s) to one or more files to patch", optional: false, is_string: false), FastlaneCore::ConfigItem.new(key: :regexp, description: "A regular expression to match", optional: true, type: Regexp), FastlaneCore::ConfigItem.new(key: :text, description: "Text used to modify to the match", optional: true, type: String), FastlaneCore::ConfigItem.new(key: :global, description: "If true, patch all occurrences of the pattern", optional: true, default_value: false, is_string: false), FastlaneCore::ConfigItem.new(key: :offset, description: "Offset from which to start matching", optional: true, default_value: 0, type: Integer), FastlaneCore::ConfigItem.new(key: :mode, description: ":append or :prepend", optional: true, default_value: :append, type: Symbol), FastlaneCore::ConfigItem.new(key: :patch, description: "A YAML file specifying patch data", optional: true, type: String) ] end |
.description ⇒ Object
51 52 53 |
# File 'lib/fastlane/plugin/patch/actions/revert_patch_action.rb', line 51 def self.description "Revert the action of apply_patch" end |
.details ⇒ Object
59 60 61 62 63 64 |
# File 'lib/fastlane/plugin/patch/actions/revert_patch_action.rb', line 59 def self.details "Revert a patch by specifying the arguments provided to apply_patch\nusing arguments or the same YAML patch files.\n EOF\nend\n" |
.example_code ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/fastlane/plugin/patch/actions/revert_patch_action.rb', line 66 def self.example_code [ " revert_patch(\n files: \"examples/PatchTestAndroid/app/src/main/AndroidManifest.xml\",\n regexp: %r{^\\s*</application>},\n mode: :prepend,\n text: \" <meta-data android:name=\\\"foo\\\" android:value=\\\"bar\\\" />\\n\"\n )\n EOF,\n <<-EOF\n revert_patch(\n files: \"examples/PatchTestAndroid/app/src/main/AndroidManifest.xml\",\n patch: \"patch.yaml\"\n )\n EOF\n ]\nend\n" |
.is_supported?(platform) ⇒ Boolean
121 122 123 |
# File 'lib/fastlane/plugin/patch/actions/revert_patch_action.rb', line 121 def self.is_supported?(platform) true end |
.run(params) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/fastlane/plugin/patch/actions/revert_patch_action.rb', line 6 def self.run(params) if params[:patch] # raises patch = YAML.load_file params[:patch] # If the :patch option is present, load these params from the # specified file. Action args override. %w{regexp text mode global}.each do |option| value = patch[option] next if value.nil? case option.to_sym when :regexp params[:regexp] = /#{value}/ when :mode params[:mode] = value.to_sym else params[option.to_sym] = value end end end UI.user_error! "Must specify :regexp and :text either in a patch or via arguments" if params[:regexp].nil? || params[:text].nil? helper = Helper::PatchHelper files = helper.files_from_params params UI.user_error! "Must specify at least one file to revert using the :files option" if files.empty? files.each do |file| modified_contents = File.open(file, "r") do |f| helper.revert_patch f.read, params[:regexp], params[:text], params[:global], params[:mode], params[:offset] end File.open(file, "w") { |f| f.write modified_contents } end rescue => e UI.user_error! "Error in RevertPatchAction: #{e.message}\n#{e.backtrace}" end |