Class: Fastlane::Actions::PatchAction
- Inherits:
-
Action
- Object
- Action
- Fastlane::Actions::PatchAction
- Defined in:
- lib/fastlane/plugin/patch/actions/patch_action.rb
Class Method Summary collapse
- .authors ⇒ Object
- .available_options ⇒ Object
- .category ⇒ Object
- .description ⇒ Object
- .details ⇒ Object
- .example_code ⇒ Object
- .is_supported?(platform) ⇒ Boolean
- .run(params) ⇒ Object
Class Method Details
.authors ⇒ Object
64 65 66 |
# File 'lib/fastlane/plugin/patch/actions/patch_action.rb', line 64 def self. ["Jimmy Dee"] end |
.available_options ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/fastlane/plugin/patch/actions/patch_action.rb', line 103 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, :prepend or :replace", optional: true, default_value: :append, type: Symbol), FastlaneCore::ConfigItem.new(key: :patch, description: "A YAML file specifying patch data", optional: true, type: String), FastlaneCore::ConfigItem.new(key: :revert, description: "Set to true to revert the specified patch rather than apply it", optional: true, default_value: false, is_string: false) ] end |
.category ⇒ Object
148 149 150 |
# File 'lib/fastlane/plugin/patch/actions/patch_action.rb', line 148 def self.category :project end |
.description ⇒ Object
60 61 62 |
# File 'lib/fastlane/plugin/patch/actions/patch_action.rb', line 60 def self.description "Apply pattern-based patches to any text file." end |
.details ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/fastlane/plugin/patch/actions/patch_action.rb', line 68 def self.details "Append or prepend text to a specified pattern in a list of files or\nreplace it, once or globally. Patches are specified by arguments or\nYAML files. Revert the same patches with the revert option.\n EOF\nend\n" |
.example_code ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/fastlane/plugin/patch/actions/patch_action.rb', line 76 def self.example_code [ " 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 patch(\n files: \"examples/PatchTestAndroid/app/src/main/AndroidManifest.xml\",\n patch: \"patch.yaml\"\n )\n EOF,\n <<-EOF\n patch(\n files: \"examples/PatchTestAndroid/app/src/main/AndroidManifest.xml\",\n patch: \"patch.yaml\",\n revert: true\n )\n EOF\n\n ]\nend\n" |
.is_supported?(platform) ⇒ Boolean
144 145 146 |
# File 'lib/fastlane/plugin/patch/actions/patch_action.rb', line 144 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 50 51 52 53 54 55 56 57 58 |
# File 'lib/fastlane/plugin/patch/actions/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 patch using the :files option" if files.empty? files.each do |file| modified_contents = File.open(file, "r") do |f| if params[:revert] helper.revert_patch f.read, params[:regexp], params[:text], params[:global], params[:mode], params[:offset] else helper.apply_patch f.read, params[:regexp], params[:text], params[:global], params[:mode], params[:offset] end end File.open(file, "w") { |f| f.write modified_contents } end rescue => e UI.user_error! "Error in PatchAction: #{e.message}\n#{e.backtrace}" end |