module Forgitter
Constants
- DATA_PATH
- DEFAULT_OPTIONS
- VERSION
Public Class Methods
Filter ignorefiles by tags.
If tags is empty, this will return all ignorefiles.
@param [Hash] the hash of options containing tag strings @return [Array] the array of filtered ignorefiles
# File lib/forgitter/ignorefiles.rb, line 20 def self.filter(options = {}) return ignorefiles if options[:tags].empty? ignorefiles.select do |ignorefile| selected = true options[:tags].uniq.each do |tag| selected &&= ignorefile[:tags].count(tag) >= options[:tags].count(tag) end selected end end
Pull a parameterized ignorefile out of the given path.
@param [String] the path to a .gitignore file @return [String] the ignorefile
# File lib/forgitter/ignorefiles.rb, line 53 def self.ignorefile(path) parameterize(File.basename(path).sub('.gitignore', '')) end
Fetch all available ignorefiles.
@return [Array] the array of available ignorefiles
# File lib/forgitter/ignorefiles.rb, line 82 def self.ignorefiles unless defined?(@@ignorefiles) && !@@ignorefiles.empty? @@ignorefiles = [] paths.each do |path| @@ignorefiles << { :path => path, :name => ignorefile(path), :tags => tags(path) } end end @@ignorefiles end
Output a list of ignorefile tags along with the relative path to the gitignore, formatted into columns.
@param [Array] tags The list of tags to filter.
# File lib/forgitter/ignorefiles.rb, line 103 def self.list(tags = []) ignorefiles = filter({ :tags => tags }) if ignorefiles.empty? puts 'No ignorefiles found!' else lines = [] col1size = 0 ignorefiles.each do |ignorefile| id = ignorefile[:tags].join(' ') col1size = id.length if id.length > col1size lines << [id, ignorefile[:path]] end lines.sort_by { |line| line[0] }.each do |line| printf("%-#{col1size}s\t%s\n", line[0], line[1]) end end end
Strip unnecessary characters and downcase the given string.
@param [String] any string @return [String] the “parameterized” string
# File lib/forgitter/ignorefiles.rb, line 8 def self.parameterize(str) str.gsub(/[^a-z0-9+]+/i, '').downcase end
Fetch all available ignorefile paths, relative to the DATA_PATH
.
.gitignore files placed directly under DATA_PATH
are ignored.
@return [Array] the array of available ignorefile paths
# File lib/forgitter/ignorefiles.rb, line 39 def self.paths @@paths ||= Dir["#{DATA_PATH}/**/*.gitignore"].map do |path| path.sub("#{DATA_PATH}/", '') end.select do |path| path =~ /\// end end