Skip to content

Commit 948c7a7

Browse files
committed
Move bulk of deprecated manifest functions into legacy
1 parent 02cd3e1 commit 948c7a7

File tree

2 files changed

+49
-47
lines changed

2 files changed

+49
-47
lines changed

lib/sprockets/legacy.rb

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,4 +254,53 @@ def resolve_with_compat(path, options = {})
254254
alias_method :resolve_without_compat, :resolve
255255
alias_method :resolve, :resolve_with_compat
256256
end
257+
258+
class Manifest
259+
# Deprecated: Compile logical path matching filter into a proc that can be
260+
# passed to logical_paths.select(&proc).
261+
#
262+
# compile_match_filter(proc { |logical_path|
263+
# File.extname(logical_path) == '.js'
264+
# })
265+
#
266+
# compile_match_filter(/application.js/)
267+
#
268+
# compile_match_filter("foo/*.js")
269+
#
270+
# Returns a Proc or raise a TypeError.
271+
def self.compile_match_filter(filter)
272+
# If the filter is already a proc, great nothing to do.
273+
if filter.respond_to?(:call)
274+
filter
275+
# If the filter is a regexp, wrap it in a proc that tests it against the
276+
# logical path.
277+
elsif filter.is_a?(Regexp)
278+
proc { |logical_path| filter.match(logical_path) }
279+
elsif filter.is_a?(String)
280+
# If its an absolute path, detect the matching full filename
281+
if PathUtils.absolute_path?(filter)
282+
proc { |logical_path, filename| filename == filter.to_s }
283+
else
284+
# Otherwise do an fnmatch against the logical path.
285+
proc { |logical_path| File.fnmatch(filter.to_s, logical_path) }
286+
end
287+
else
288+
raise TypeError, "unknown filter type: #{filter.inspect}"
289+
end
290+
end
291+
292+
# Deprecated: Filter logical paths in environment. Useful for selecting what
293+
# files you want to compile.
294+
#
295+
# Returns an Enumerator.
296+
def filter_logical_paths(*args)
297+
filters = args.flatten.map { |arg| self.class.compile_match_filter(arg) }
298+
environment.cached.logical_paths.select do |a, b|
299+
filters.any? { |f| f.call(a, b) }
300+
end
301+
end
302+
303+
# Deprecated alias.
304+
alias_method :find_logical_paths, :filter_logical_paths
305+
end
257306
end

lib/sprockets/manifest.rb

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -106,50 +106,6 @@ def files
106106
@data['files'] ||= {}
107107
end
108108

109-
# Deprecated: Compile logical path matching filter into a proc that can be
110-
# passed to logical_paths.select(&proc).
111-
#
112-
# compile_match_filter(proc { |logical_path|
113-
# File.extname(logical_path) == '.js'
114-
# })
115-
#
116-
# compile_match_filter(/application.js/)
117-
#
118-
# compile_match_filter("foo/*.js")
119-
#
120-
# Returns a Proc or raise a TypeError.
121-
def self.compile_match_filter(filter)
122-
# If the filter is already a proc, great nothing to do.
123-
if filter.respond_to?(:call)
124-
filter
125-
# If the filter is a regexp, wrap it in a proc that tests it against the
126-
# logical path.
127-
elsif filter.is_a?(Regexp)
128-
proc { |logical_path| filter.match(logical_path) }
129-
elsif filter.is_a?(String)
130-
# If its an absolute path, detect the matching full filename
131-
if PathUtils.absolute_path?(filter)
132-
proc { |logical_path, filename| filename == filter.to_s }
133-
else
134-
# Otherwise do an fnmatch against the logical path.
135-
proc { |logical_path| File.fnmatch(filter.to_s, logical_path) }
136-
end
137-
else
138-
raise TypeError, "unknown filter type: #{filter.inspect}"
139-
end
140-
end
141-
142-
# Deprecated: Filter logical paths in environment. Useful for selecting what
143-
# files you want to compile.
144-
#
145-
# Returns an Enumerator.
146-
def filter_logical_paths(*args)
147-
filters = args.flatten.map { |arg| self.class.compile_match_filter(arg) }
148-
environment.cached.logical_paths.select do |a, b|
149-
filters.any? { |f| f.call(a, b) }
150-
end
151-
end
152-
153109
# Public: Find all assets matching pattern set in environment.
154110
#
155111
# Returns Enumerator of Assets.
@@ -174,9 +130,6 @@ def find(*args)
174130
nil
175131
end
176132

177-
# Deprecated alias.
178-
alias_method :find_logical_paths, :filter_logical_paths
179-
180133
# Compile and write asset to directory. The asset is written to a
181134
# fingerprinted filename like
182135
# `application-2e8e9a7c6b0aafa0c9bdeec90ea30213.js`. An entry is

0 commit comments

Comments
 (0)