class Yalphabetize::YamlFinder
Constants
- YAML_EXTENSIONS
Attributes
Public Class Methods
Source
# File lib/yalphabetize/yaml_finder.rb, line 9 def self.paths(only:, exclude:) if exclude.any? new.paths(only) - new.paths(exclude) else new.paths(only) end end
Public Instance Methods
Source
# File lib/yalphabetize/yaml_finder.rb, line 21 def paths(paths) if paths.empty? files << files_in_dir else process_paths(paths) end files.flatten.select { |file| valid?(file) }.uniq end
Private Instance Methods
Source
# File lib/yalphabetize/yaml_finder.rb, line 66 def exists?(path) File.exist?(path) end
Source
# File lib/yalphabetize/yaml_finder.rb, line 51 def files_in_dir(dir = Dir.pwd) return if `sh -c 'command -v git'`.empty? output, _error, status = Open3.capture3( 'git', 'ls-files', '-z', *Array(dir), '--exclude-standard', '--others', '--cached', '--modified' ) output.split("\0").uniq if status.success? end
Source
# File lib/yalphabetize/yaml_finder.rb, line 47 def files_in_glob(glob) files_in_dir([glob, glob.gsub('**/', '').gsub('**', '')].uniq) end
Source
# File lib/yalphabetize/yaml_finder.rb, line 74 def glob?(path) path.include?('*') end
Source
# File lib/yalphabetize/yaml_finder.rb, line 35 def process_paths(paths) paths.uniq.each do |path| files << if glob?(path) files_in_glob(path) elsif File.directory?(path) files_in_dir(path) else path end end end
Source
# File lib/yalphabetize/yaml_finder.rb, line 62 def valid?(path) exists?(path) && yml?(path) end
Source
# File lib/yalphabetize/yaml_finder.rb, line 70 def yml?(path) YAML_EXTENSIONS.include? File.extname(path) end