Module: Forgitter
- Defined in:
- lib/forgitter.rb,
lib/forgitter/cli.rb,
lib/forgitter/runner.rb,
lib/forgitter/options.rb,
lib/forgitter/version.rb,
lib/forgitter/ignorefiles.rb,
lib/forgitter/cli/option_parser.rb
Defined Under Namespace
Constant Summary collapse
- DATA_PATH =
File.realpath(File.join(File.dirname(__FILE__), '..', 'data'))
- DEFAULT_OPTIONS =
{ :list => false, :tags => [] }
- VERSION =
'0.1.4'
Class Method Summary collapse
-
.filter(options = {}) ⇒ Array
Filter ignorefiles by tags.
-
.ignorefile(path) ⇒ String
Pull a parameterized ignorefile out of the given path.
-
.ignorefiles ⇒ Array
Fetch all available ignorefiles.
-
.list(tags = []) ⇒ Object
Output a list of ignorefile tags along with the relative path to the gitignore, formatted into columns.
-
.parameterize(str) ⇒ String
Strip unnecessary characters and downcase the given string.
-
.paths ⇒ Array
Fetch all available ignorefile paths, relative to the DATA_PATH.
-
.tags(path) ⇒ Array
Pull parameterized tags out of the given path.
Class Method Details
.filter(options = {}) ⇒ Array
Filter ignorefiles by tags.
If tags is empty, this will return all ignorefiles.
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/forgitter/ignorefiles.rb', line 20 def self.filter( = {}) return ignorefiles if [:tags].empty? ignorefiles.select do |ignorefile| selected = true [:tags].uniq.each do |tag| selected &&= ignorefile[:tags].count(tag) >= [:tags].count(tag) end selected end end |
.ignorefile(path) ⇒ String
Pull a parameterized ignorefile out of the given path.
53 54 55 |
# File 'lib/forgitter/ignorefiles.rb', line 53 def self.ignorefile(path) parameterize(File.basename(path).sub('.gitignore', '')) end |
.ignorefiles ⇒ Array
Fetch all available ignorefiles.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# 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 => (path) } end end @@ignorefiles end |
.list(tags = []) ⇒ Object
Output a list of ignorefile tags along with the relative path to the gitignore, formatted into columns.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/forgitter/ignorefiles.rb', line 103 def self.list( = []) ignorefiles = filter({ :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 |
.parameterize(str) ⇒ String
Strip unnecessary characters and downcase the given string.
8 9 10 |
# File 'lib/forgitter/ignorefiles.rb', line 8 def self.parameterize(str) str.gsub(/[^a-z0-9+]+/i, '').downcase end |
.paths ⇒ Array
Fetch all available ignorefile paths, relative to the DATA_PATH.
.gitignore files placed directly under DATA_PATH are ignored.
39 40 41 42 43 44 45 |
# 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 |
.tags(path) ⇒ Array
Pull parameterized tags out of the given path.
If path does not contain a /, this just returns the ignorefile name in an array.
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/forgitter/ignorefiles.rb', line 65 def self.(path) = [] if path =~ /\// = path.sub("/#{File.basename(path)}", '').split('/') .map! do |tag| parameterize(tag) end end << ignorefile(path) end |