Class: Gravitext::DevTools::GitFileLister
- Inherits:
-
Object
- Object
- Gravitext::DevTools::GitFileLister
- Defined in:
- lib/gravitext-devtools.rb
Instance Attribute Summary collapse
-
#exclusions ⇒ Object
Exclusions to the list expressed in various ways Array<Regexp|Proc|String>.
-
#extra_files ⇒ Object
Additional files to add to files list Array<~to_s>.
-
#git_flags ⇒ Object
Flags for use in call to git ls-files Array<~to_s>.
-
#inclusions ⇒ Object
Inclusions to the list expressed in various ways Array<Regexp|Proc|String>.
Instance Method Summary collapse
- #files ⇒ Object
- #generate_list(args = @args) ⇒ Object
-
#initialize ⇒ GitFileLister
constructor
A new instance of GitFileLister.
- #match?(list, fname) ⇒ Boolean
- #parse_options(args = ARGV, &block) ⇒ Object
Constructor Details
#initialize ⇒ GitFileLister
Returns a new instance of GitFileLister.
75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/gravitext-devtools.rb', line 75 def initialize @args = [] @files = nil @exclusions = [ %r{(^|/).gitignore$}, # gt-manifest, gt-header %r{(^|/).gt-config$}, # gt-manifest, (gt-header) %r{(^|/)src(/|$)}, # gt-manifest 'lib/**/*.jar', # all 'Manifest.static' ] # gt-manifest, gt-header @inclusions = [] @git_flags = [] @extra_files = [] end |
Instance Attribute Details
#exclusions ⇒ Object
Exclusions to the list expressed in various ways Array<Regexp|Proc|String>
65 66 67 |
# File 'lib/gravitext-devtools.rb', line 65 def exclusions @exclusions end |
#extra_files ⇒ Object
Additional files to add to files list Array<~to_s>
73 74 75 |
# File 'lib/gravitext-devtools.rb', line 73 def extra_files @extra_files end |
#git_flags ⇒ Object
Flags for use in call to git ls-files Array<~to_s>
69 70 71 |
# File 'lib/gravitext-devtools.rb', line 69 def git_flags @git_flags end |
#inclusions ⇒ Object
Inclusions to the list expressed in various ways Array<Regexp|Proc|String>
61 62 63 |
# File 'lib/gravitext-devtools.rb', line 61 def inclusions @inclusions end |
Instance Method Details
#files ⇒ Object
99 100 101 |
# File 'lib/gravitext-devtools.rb', line 99 def files @files ||= generate_list end |
#generate_list(args = @args) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/gravitext-devtools.rb', line 103 def generate_list( args = @args ) files, dirs = args.partition { |a| File.file?( a ) } if files.empty? || ! dirs.empty? gcmd = [ 'git', 'ls-files', @git_flags, dirs ].flatten.compact.join( ' ' ) files += IO.popen( gcmd ) { |inp| inp.readlines } end files += extra_files files.map! { |f| f.strip } files.uniq! unless @inclusions.empty? files = files.select { |f| match?( @inclusions, f ) } end files.reject { |f| match?( @exclusions, f ) } end |
#match?(list, fname) ⇒ Boolean
122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/gravitext-devtools.rb', line 122 def match?( list, fname ) list.any? do |ex| case ex when Proc ex.call( fname ) when Regexp fname =~ ex when /[*?]/ File.fnmatch?( ex, fname, File::FNM_PATHNAME ) else fname == ex end end end |
#parse_options(args = ARGV, &block) ⇒ Object
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/gravitext-devtools.rb', line 88 def ( args = ARGV, &block ) opts = OptionParser.new do |opts| opts.on( "-g", "--git-updates", "Include files from modified/untracked git working tree" ) do @git_flags += %w[ -m -o --exclude-standard ] end block.call( opts ) if block end @args = opts.parse( args ) end |