fastlane-plugin-plist_surgeon 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8a4c842111d0642840d28e07781a460e50c2391ece4591051efea52033861617
4
- data.tar.gz: f6065508091457bee57180beb14181b688771f0f16c6198fa9723226c001b3d2
3
+ metadata.gz: e2e62e85c8e6796d2c4c70e8c4fe1b343b522d7d199662018185b0176d172f2e
4
+ data.tar.gz: 1baf91af0fe8f8fdf22032a74cf4a1db2a85cd65d3ef06f327353d38df3f0e81
5
5
  SHA512:
6
- metadata.gz: d94f7e8ac67bfa10333845e5dc07694dd741c1f22f5d8729218d52517a3e4cee8cd9a00a2c7fb106f760db685f350fbc0418958ff8a802ca6397c02b21548f17
7
- data.tar.gz: 3e14d8221bf389634e6352d5be9a257eeeabf8d9aa7b318f901844840eb3f1f60899fc90d7e3e138818c930763b57593e958ac8cdcf223839324c6a38b802d32
6
+ metadata.gz: f18b64b3e54100c1861af402d66983189ab87b37ab4bd7e9b45fb6e82da702bf5609466b2024c1730e0fe394141c57e74f040c70c86868973bda7e7c0ffdb217
7
+ data.tar.gz: 23234c26f559a682406ccd9d0d0fad48b44340b1582b5545f3ac9eb857e494f59b77b8c2fb903730614bf39d0520f52fb7f03353120e0482e50a02426b71675a
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # plist_surgeon plugin
2
2
  _The all-in-one tool to edit iOS configuration files from one plugin._
3
3
 
4
- [![fastlane Plugin Badge](https://rawcdn.githack.com/fastlane/fastlane/master/fastlane/assets/plugin-badge.svg)](https://rubygems.org/gems/fastlane-plugin-plist_surgeon)
4
+ [![Gem Version](https://badge.fury.io/rb/fastlane-plugin-plist_surgeon.svg)](https://badge.fury.io/rb/fastlane-plugin-plist_surgeon)
5
5
 
6
6
  ## Getting Started
7
7
 
@@ -82,6 +82,40 @@ fastlane run plist_surgeon \
82
82
  value:'{"CFBundlePrimaryIcon":{"CFBundleIconFiles":["AppIcon"]}}'
83
83
  ```
84
84
 
85
+ ### Array Search Syntax
86
+
87
+ When dealing with arrays of dictionaries, you can use the `(key=value)` syntax to find the correct element instead of relying on a fixed index.
88
+
89
+ For example, given an `Info.plist` with:
90
+
91
+ ```xml
92
+ <key>service_api_key</key>
93
+ <array>
94
+ <dict>
95
+ <key>test</key>
96
+ <string>other_app</string>
97
+ <key>live</key>
98
+ <string>old_key_1</string>
99
+ </dict>
100
+ <dict>
101
+ <key>test</key>
102
+ <string>my_app</string>
103
+ <key>live</key>
104
+ <string>old_key_2</string>
105
+ </dict>
106
+ </array>
107
+ ```
108
+
109
+ You can update the `live` key for the dictionary where `test` is `my_app`:
110
+
111
+ ```rb
112
+ plist_surgeon(
113
+ path: "Info.plist",
114
+ key: "service_api_key.(test=my_app).live",
115
+ value: "new_live_key"
116
+ )
117
+ ```
118
+
85
119
  ### Run tests for this plugin
86
120
 
87
121
  To run both the tests, and code style validation, run
@@ -34,12 +34,25 @@ module Fastlane
34
34
 
35
35
  def self.set_direct_value(plist, key, value)
36
36
  if plist.kind_of?(Array)
37
- plist[key.to_i] = value
37
+ index = find_index_for_key(plist, key)
38
+ plist[index] = value
38
39
  else
39
40
  plist[key] = value
40
41
  end
41
42
  end
42
43
 
44
+ def self.find_index_for_key(array, key)
45
+ if key.start_with?('(') && key.end_with?(')')
46
+ search_term = key[1...-1]
47
+ search_key, search_value = search_term.split('=', 2)
48
+ if search_key && search_value
49
+ index = array.index { |item| item.kind_of?(Hash) && item[search_key].to_s == search_value }
50
+ return index if index
51
+ end
52
+ end
53
+ key.to_i
54
+ end
55
+
43
56
  def self.parse_json_if_needed(value)
44
57
  if value.kind_of?(String) && value.start_with?('{', '[')
45
58
  begin
@@ -82,7 +95,8 @@ module Fastlane
82
95
  current = plist
83
96
  keys.each do |k|
84
97
  if current.kind_of?(Array)
85
- current = current[k.to_i]
98
+ index = find_index_for_key(current, k)
99
+ current = current[index]
86
100
  else
87
101
  current[k] ||= {}
88
102
  current = current[k]
@@ -90,7 +104,8 @@ module Fastlane
90
104
  end
91
105
 
92
106
  if current.kind_of?(Array)
93
- current[last_key.to_i] = value
107
+ index = find_index_for_key(current, last_key)
108
+ current[index] = value
94
109
  else
95
110
  current[last_key] = value
96
111
  end
@@ -1,5 +1,5 @@
1
1
  module Fastlane
2
2
  module PlistSurgeon
3
- VERSION = "0.1.2"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastlane-plugin-plist_surgeon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sourcetoad