lib/hanami/assets/config/sources.rb in hanami-assets-0.2.1 vs lib/hanami/assets/config/sources.rb in hanami-assets-0.3.0
- old
+ new
@@ -15,10 +15,14 @@
# @see Hanami::Assets.duplicate
# @see http://www.rubydoc.info/gems/hanami-utils/Hanami/Utils/LoadPaths
#
# TODO The perf of this class is poor, consider to improve it.
class Sources < Utils::LoadPaths
+ # @since 0.3.0
+ # @api private
+ SKIPPED_FILE_PREFIX = '_'.freeze
+
# @since 0.1.0
# @api private
attr_writer :root
# @since 0.1.0
@@ -29,11 +33,11 @@
end
# @since 0.1.0
# @api private
def map
- Array.new.tap do |result|
+ [].tap do |result|
each do |source|
result << yield(source)
end
end
end
@@ -49,18 +53,19 @@
# @since 0.1.0
# @api private
def files(name = nil)
result = []
- Dir.glob(map {|source| "#{ source }#{ ::File::SEPARATOR }**#{ ::File::SEPARATOR }#{ name }*"}).each do |file|
- next if ::File.directory?(file) || ::File.basename(file).match(/\A\_/)
+ Dir.glob(map { |source| "#{source}#{::File::SEPARATOR}**#{::File::SEPARATOR}#{name}*" }).each do |file|
+ next if ::File.directory?(file) || ::File.basename(file).start_with?(SKIPPED_FILE_PREFIX)
result << file
end
result
end
private
+
# @since 0.1.0
# @api private
def realpath(path)
@root.join(path).realpath
end