cfbundle 0.2.1 → 0.2.2

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
  SHA1:
3
- metadata.gz: 3f16e3d2efd09474b84de78953ebe736859ecad2
4
- data.tar.gz: cdb73bed933efd9a3ae0ad1648354eed14f104bb
3
+ metadata.gz: a0afca942ade636782524dc8764f0a5d1e01b70b
4
+ data.tar.gz: 8f6343b059fbb5654636cdb51073776940eee1df
5
5
  SHA512:
6
- metadata.gz: 6ed47abda281fc8ba40c337504226b93e2cd05952418892699135c8c5d569ffb0512e0ea4b1a5bdeab1f06408744d8b88bb5336a76db76805354aca10739515b
7
- data.tar.gz: 3f878a953002dcf55920628a2d506404a582478ffad62da7156d22813f987598abc916c112066ad3856bfd6e85d425b9a4ce8cb4dc81ebe68f2a14918fd24851
6
+ metadata.gz: 92514490813b48735c35d649dc8c104f48b8d3d89b7f2acda5887526246ec15505bf7e62723683859a6d3ed6fbb1f856f3dc5bd24e3ec9f12a3ae7873a398843
7
+ data.tar.gz: bd0ed63235589bd34826c83ffd04d94ead7753e0ad02b790612cb8a2536add13fbec6c433a046ad48727572e7319b92e81c4e309e42709ce563e213b37d4e91a
@@ -31,13 +31,16 @@ module CFBundle
31
31
  # extension. The product is either empty or starts with a tilde. The
32
32
  # extension is either empty or starts with a dot.
33
33
  # @param path [String] The path to the resource.
34
+ # @param expected_product [String?] The expected value for product.
34
35
  # @return [Array]
35
36
  # @see join_resource
36
- def split_resource(path)
37
+ def split_resource(path, expected_product)
37
38
  directory = File.dirname(path)
38
39
  extension = File.extname(path)
39
40
  basename = File.basename(path, extension)
40
- name, product = split_resource_name_and_product(basename)
41
+ name, product = split_resource_name_and_product(
42
+ basename, expected_product
43
+ )
41
44
  [directory, name, product, extension]
42
45
  end
43
46
 
@@ -57,12 +60,14 @@ module CFBundle
57
60
 
58
61
  private
59
62
 
60
- def split_resource_name_and_product(basename)
61
- name, _, product = basename.rpartition('~')
62
- if name.empty? || product.empty?
63
+ def split_resource_name_and_product(basename, expected_product)
64
+ parts = basename.rpartition('~')
65
+ name = parts[0]
66
+ product = parts[1] + parts[2]
67
+ if name.empty? || product != expected_product
63
68
  [basename, '']
64
69
  else
65
- [name, '~' + product]
70
+ [name, product]
66
71
  end
67
72
  end
68
73
  end
@@ -16,7 +16,6 @@ module CFBundle
16
16
  def initialize(bundle, path)
17
17
  @bundle = bundle
18
18
  @path = path
19
- @directory, @name, @product, @extension = PathUtils.split_resource(path)
20
19
  end
21
20
 
22
21
  # Opens the resource for reading.
@@ -57,41 +56,12 @@ module CFBundle
57
56
  predicate = Predicate.new(name, extension, product)
58
57
  loop do
59
58
  resource = enumerator.next
60
- y << resource if resource.send(:match?, predicate)
59
+ y << resource if predicate.match?(resource)
61
60
  end
62
61
  end
63
62
  enumerator.each(&block)
64
63
  end
65
64
 
66
- private
67
-
68
- def match?(predicate)
69
- return false unless name_match?(predicate) &&
70
- extension_match?(predicate) &&
71
- product_match?(predicate)
72
- predicate.uniq?(@name, @extension)
73
- end
74
-
75
- def name_match?(predicate)
76
- return true if predicate.name.nil?
77
- return predicate.name.match? @name if predicate.name.is_a?(Regexp)
78
- predicate.name == @name
79
- end
80
-
81
- def extension_match?(predicate)
82
- predicate.extension.nil? || @extension == predicate.extension
83
- end
84
-
85
- def product_match?(predicate)
86
- return true if @product == predicate.product
87
- return false unless @product.empty?
88
- !bundle.storage.exist?(path_with_product(predicate.product))
89
- end
90
-
91
- def path_with_product(product)
92
- PathUtils.join_resource(@directory, @name, product, @extension)
93
- end
94
-
95
65
  # @private
96
66
  #
97
67
  # Performs the enumeration of a bundle's resources.
@@ -179,10 +149,43 @@ module CFBundle
179
149
  @keys = Set.new
180
150
  end
181
151
 
182
- # Ensures the given name and extension are unique during the enumeration.
152
+ # Returns whether the predicate matches a given resource.
153
+ #
154
+ # A predicate ensures resource unicity by the caching the filename of
155
+ # previsouly matched resources. Therefore this method always returns
156
+ # when invoked twice with the same resource.
183
157
  #
184
- # @param name [String] The resource name.
185
- # @param extension [String] The resource extension.
158
+ # @param resource [Resource] The resource to test.
159
+ # @return [Boolean]
160
+ def match?(resource)
161
+ directory, name, product, extension = PathUtils.split_resource(
162
+ resource.path, @product
163
+ )
164
+ extension_match?(extension) &&
165
+ name_match?(name) &&
166
+ product_match?(directory, name, product, extension, resource) &&
167
+ uniq?(name, extension)
168
+ end
169
+
170
+ private
171
+
172
+ def extension_match?(extension)
173
+ @extension.nil? || @extension == extension
174
+ end
175
+
176
+ def name_match?(name)
177
+ @name.nil? || @name === name
178
+ end
179
+
180
+ def product_match?(directory, name, product, extension, resource)
181
+ return true if @product == product
182
+ return false unless product.empty?
183
+ exact_path = PathUtils.join_resource(
184
+ directory, name, @product, extension
185
+ )
186
+ !resource.bundle.storage.exist?(exact_path)
187
+ end
188
+
186
189
  def uniq?(name, extension)
187
190
  key = [name, extension].join
188
191
  return false if @keys.include?(key)
@@ -190,8 +193,6 @@ module CFBundle
190
193
  true
191
194
  end
192
195
 
193
- private
194
-
195
196
  def extension_for(extension)
196
197
  return extension if extension.nil? || extension.empty?
197
198
  extension.start_with?('.') ? extension : '.' + extension
@@ -1,3 +1,3 @@
1
1
  module CFBundle
2
- VERSION = '0.2.1'.freeze
2
+ VERSION = '0.2.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cfbundle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicolas Bachschmidt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-21 00:00:00.000000000 Z
11
+ date: 2018-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: CFPropertyList