Class: Gravitext::DevTools::HeaderWriter
- Inherits:
-
Object
- Object
- Gravitext::DevTools::HeaderWriter
- Includes:
- FileUtils
- Defined in:
- lib/gravitext-devtools/header_writer.rb
Constant Summary collapse
- TDIR =
File.( File.join( File.dirname( __FILE__ ), '..', '..', 'templates' ) )
Instance Attribute Summary collapse
-
#exclusions ⇒ Object
Returns the value of attribute exclusions.
-
#holder ⇒ Object
Returns the value of attribute holder.
-
#inception ⇒ Object
Returns the value of attribute inception.
-
#inclusions ⇒ Object
Returns the value of attribute inclusions.
-
#license ⇒ Object
Returns the value of attribute license.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Instance Method Summary collapse
- #cached_header(format) ⇒ Object
- #cached_license ⇒ Object
- #expand(template, bnd) ⇒ Object
- #gen_header(format) ⇒ Object
- #gen_license ⇒ Object
-
#initialize ⇒ HeaderWriter
constructor
A new instance of HeaderWriter.
- #parse_options(args = ARGV) ⇒ Object
- #run(args = ARGV) ⇒ Object
- #years ⇒ Object
Constructor Details
#initialize ⇒ HeaderWriter
Returns a new instance of HeaderWriter.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/gravitext-devtools/header_writer.rb', line 35 def initialize @verbose = false @do_write = false @license = :apache @inception = Time.now.year @git_lister = GitFileLister.new @inclusions = [] @exclusions = [ '**/.gitignore', '**/.gt-config', '**/History.rdoc', '**/History.txt', '**/Manifest.static', '**/Manifest.txt', '**/*.jar', '**/Rakefile', '**/pom.xml', '**/assembly.xml', '*.gemspec', 'Gemfile*' ] @cached_header = {} Hooker.apply( [ :gt, :header ], self ) end |
Instance Attribute Details
#exclusions ⇒ Object
Returns the value of attribute exclusions.
32 33 34 |
# File 'lib/gravitext-devtools/header_writer.rb', line 32 def exclusions @exclusions end |
#holder ⇒ Object
Returns the value of attribute holder.
29 30 31 |
# File 'lib/gravitext-devtools/header_writer.rb', line 29 def holder @holder end |
#inception ⇒ Object
Returns the value of attribute inception.
30 31 32 |
# File 'lib/gravitext-devtools/header_writer.rb', line 30 def inception @inception end |
#inclusions ⇒ Object
Returns the value of attribute inclusions.
33 34 35 |
# File 'lib/gravitext-devtools/header_writer.rb', line 33 def inclusions @inclusions end |
#license ⇒ Object
Returns the value of attribute license.
31 32 33 |
# File 'lib/gravitext-devtools/header_writer.rb', line 31 def license @license end |
#verbose ⇒ Object
Returns the value of attribute verbose.
28 29 30 |
# File 'lib/gravitext-devtools/header_writer.rb', line 28 def verbose @verbose end |
Instance Method Details
#cached_header(format) ⇒ Object
95 96 97 |
# File 'lib/gravitext-devtools/header_writer.rb', line 95 def cached_header( format ) @cached_header[ format ] ||= gen_header( format ) end |
#cached_license ⇒ Object
105 106 107 |
# File 'lib/gravitext-devtools/header_writer.rb', line 105 def cached_license @cached_license ||= gen_license end |
#expand(template, bnd) ⇒ Object
118 119 120 121 |
# File 'lib/gravitext-devtools/header_writer.rb', line 118 def ( template, bnd ) ERB.new( template, nil, '%' ).result( bnd ). split( $/ ).map { |l| l.rstrip } end |
#gen_header(format) ⇒ Object
99 100 101 102 103 |
# File 'lib/gravitext-devtools/header_writer.rb', line 99 def gen_header( format ) efile = File.join( TDIR, 'format', "format.#{format}" ) license = cached_license ( IO.read( efile ), binding ) end |
#gen_license ⇒ Object
109 110 111 112 113 114 115 116 |
# File 'lib/gravitext-devtools/header_writer.rb', line 109 def gen_license template = if license.is_a?( Symbol ) IO.read( File.join( TDIR, 'license', license.to_s ) ) else license.to_s end ( template, binding ) end |
#parse_options(args = ARGV) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/gravitext-devtools/header_writer.rb', line 62 def ( args = ARGV ) @git_lister.( args ) do |opts| opts. = "Usage: gt-header [dir|file] ..." opts.on( "-v", "--verbose", "Output full details" ) do @verbose = true end opts.on( "-w", "--write", "Write headers if needed" ) do @do_write = true end end end |
#run(args = ARGV) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/gravitext-devtools/header_writer.rb', line 78 def run( args = ARGV ) ( args ) @git_lister.inclusions = @inclusions @git_lister.exclusions = @exclusions files = @git_lister.files files.each do |fname| HeaderProcessor.new( fname, @do_write, self ).process end end |
#years ⇒ Object
123 124 125 |
# File 'lib/gravitext-devtools/header_writer.rb', line 123 def years @years ||= [ inception, Time.now.year ].uniq.join( '-' ) end |