Class: Gravitext::DevTools::ManifestWriter
- Inherits:
-
Object
- Object
- Gravitext::DevTools::ManifestWriter
- Includes:
- FileUtils, Gravitext::DevTools
- Defined in:
- lib/gravitext-devtools/manifest_writer.rb
Constant Summary
Constants included from Gravitext::DevTools
Instance Attribute Summary collapse
-
#exclusions ⇒ Object
Returns the value of attribute exclusions.
-
#inclusions ⇒ Object
Returns the value of attribute inclusions.
-
#static ⇒ Object
Set true if Manifest.txt should be written instead of Manifest.txt.
Instance Method Summary collapse
-
#initialize ⇒ ManifestWriter
constructor
A new instance of ManifestWriter.
- #parse_options(args = ARGV) ⇒ Object
-
#priority_to_base(files) ⇒ Object
Move up any foo/base.rb or version.rb files.
- #run(args = ARGV) ⇒ Object
- #sort(files) ⇒ Object
Methods included from Gravitext::DevTools
configure, load_config_from_pwd
Constructor Details
#initialize ⇒ ManifestWriter
Returns a new instance of ManifestWriter.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/gravitext-devtools/manifest_writer.rb', line 35 def initialize @verbose = false @static = File.exist?( 'Manifest.static' ) @git_lister = GitFileLister.new @inclusions = [] @exclusions = [ %r{(^|/).gitignore$}, %r{(^|/).gt-config$}, %r{(^|/)src(/|$)}, 'lib/**/*.jar', 'Manifest.static', '*.gemspec', 'Gemfile*' ] Hooker.apply( [ :gt, :manifest ], self ) end |
Instance Attribute Details
#exclusions ⇒ Object
Returns the value of attribute exclusions.
32 33 34 |
# File 'lib/gravitext-devtools/manifest_writer.rb', line 32 def exclusions @exclusions end |
#inclusions ⇒ Object
Returns the value of attribute inclusions.
33 34 35 |
# File 'lib/gravitext-devtools/manifest_writer.rb', line 33 def inclusions @inclusions end |
#static ⇒ Object
Set true if Manifest.txt should be written instead of Manifest.txt. (Default: true if Manifest.static exists) Boolean
30 31 32 |
# File 'lib/gravitext-devtools/manifest_writer.rb', line 30 def static @static end |
Instance Method Details
#parse_options(args = ARGV) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/gravitext-devtools/manifest_writer.rb', line 53 def ( args = ARGV ) @git_lister.( args ) do |opts| opts. = "Usage: gt-manifest [dir|file] ..." opts.on( "-v", "--verbose", "Output full manifest details" ) do @verbose = true end opts.on( "-s", "--static", "Write to Manifest.static instead of Manifest.txt" ) do @static = true end end end |
#priority_to_base(files) ⇒ Object
Move up any foo/base.rb or version.rb files. By convention (originally based on rdoc issues) these come before a foo.rb, i.e:
lib/foo/base.rb
lib/foo.rb
lib/foo/other.rb
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/gravitext-devtools/manifest_writer.rb', line 123 def priority_to_base( files ) bases, nfiles = files.partition { |f| f.last =~ /^(base|version)\.rb$/ } bases.each do |base| key = base[0..-2] key[-1] += ".rb" nfiles.each_with_index do |file, i| if file == key nfiles.insert( i, base ) base = nil break end end return files if base end nfiles end |
#run(args = ARGV) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/gravitext-devtools/manifest_writer.rb', line 68 def run( args = ARGV ) ( args ) @git_lister.inclusions = @inclusions @git_lister.exclusions = @exclusions @git_lister.extra_files << 'Manifest.txt' unless @static @git_lister.git_flags << '-c' # Include cached by default files = @git_lister.files files.map! do |f| f = f.split( File::SEPARATOR ) f.shift if f[0] == '.' f end files.uniq! files = sort( files ) files.map! { |f| File.join( f ) } open( 'Manifest.' + ( @static ? 'static' : 'txt' ), 'w' ) do |out| files.each do |fname| puts fname if @verbose out.puts fname end end end |
#sort(files) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/gravitext-devtools/manifest_writer.rb', line 97 def sort( files ) files = files.sort do |a,b| i = 0 o = 0 while( o == 0 ) o = -1 if ( a.length == i+1 ) && a.length < b.length o = 1 if ( b.length == i+1 ) && a.length > b.length o = a[i] <=> b[i] if o == 0 i += 1 end o end files = priority_to_base( files ) files end |