Class: Gravitext::DevTools::ManifestWriter

Inherits:
Object
  • Object
show all
Includes:
FileUtils, Gravitext::DevTools
Defined in:
lib/gravitext-devtools/manifest_writer.rb

Constant Summary

Constants included from Gravitext::DevTools

VERSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Gravitext::DevTools

configure, load_config_from_pwd

Constructor Details

#initializeManifestWriter

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

#exclusionsObject

Returns the value of attribute exclusions.



32
33
34
# File 'lib/gravitext-devtools/manifest_writer.rb', line 32

def exclusions
  @exclusions
end

#inclusionsObject

Returns the value of attribute inclusions.



33
34
35
# File 'lib/gravitext-devtools/manifest_writer.rb', line 33

def inclusions
  @inclusions
end

#staticObject

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 parse_options( args = ARGV )

  @git_lister.parse_options( args ) do |opts|
    opts.banner = "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 )

  parse_options( 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