Module: RJack::TarPit::LineMatchTaskDefiner
- Included in:
- BaseStrategy
- Defined in:
- lib/rjack-tarpit/line_match.rb
Instance Attribute Summary collapse
-
#history_date_regexp ⇒ Object
Regexp to use for a valid/releasable date on History.
-
#history_regexp ⇒ Object
Regexp to use for first line of History file with version, date.
-
#history_version_regexp ⇒ Object
Proc returning regexp given gem version as parameter, to use to validate the version of the latest history entry.
-
#init_files ⇒ Object
Array of “init” files to check for gem version references in (default: [ init/<spec.name> ], if exists).
-
#init_line_regexp ⇒ Object
Proc given spec and returning regexp matching gem line to find in init_files.
-
#init_version_regexp ⇒ Object
Proc returning regexp given gem version as parameter, to use to validate the gem version of gem line in init_files.
Instance Method Summary collapse
- #define_line_match_tasks ⇒ Object
- #initialize ⇒ Object
-
#test_line_match(files, line_regex, pass_line_regex = //) ⇒ Object
Test that all specified files have at least one line matching line_regex, and that first line additionally matches (optional) pass_line_regex.
Instance Attribute Details
#history_date_regexp ⇒ Object
Regexp to use for a valid/releasable date on History
25 26 27 |
# File 'lib/rjack-tarpit/line_match.rb', line 25 def history_date_regexp @history_date_regexp end |
#history_regexp ⇒ Object
Regexp to use for first line of History file with version, date
22 23 24 |
# File 'lib/rjack-tarpit/line_match.rb', line 22 def history_regexp @history_regexp end |
#history_version_regexp ⇒ Object
Proc returning regexp given gem version as parameter, to use to validate the version of the latest history entry.
29 30 31 |
# File 'lib/rjack-tarpit/line_match.rb', line 29 def history_version_regexp @history_version_regexp end |
#init_files ⇒ Object
Array of “init” files to check for gem version references in (default: [ init/<spec.name> ], if exists)
33 34 35 |
# File 'lib/rjack-tarpit/line_match.rb', line 33 def init_files @init_files end |
#init_line_regexp ⇒ Object
Proc given spec and returning regexp matching gem line to find in init_files. (default: /^gem.+<spec.name>/)
37 38 39 |
# File 'lib/rjack-tarpit/line_match.rb', line 37 def init_line_regexp @init_line_regexp end |
#init_version_regexp ⇒ Object
Proc returning regexp given gem version as parameter, to use to validate the gem version of gem line in init_files. (default: /= <spec.version>/)
42 43 44 |
# File 'lib/rjack-tarpit/line_match.rb', line 42 def init_version_regexp @init_version_regexp end |
Instance Method Details
#define_line_match_tasks ⇒ Object
58 59 60 61 62 63 64 65 66 67 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 96 97 98 |
# File 'lib/rjack-tarpit/line_match.rb', line 58 def define_line_match_tasks if spec.history_file && history_regexp desc "Check that #{spec.history_file} has latest version" task :check_history_version do test_line_match( spec.history_file, history_regexp, history_version_regexp.call( spec.version ) ) end [ :gem, :tag, :push ].each { |t| task t => :check_history_version } end if spec.history_file && history_date_regexp desc "Check that #{spec.history_file} has a date for release" task :check_history_date do test_line_match( spec.history_file, history_regexp, history_date_regexp ) end [ :tag, :push ].each { |t| task t => :check_history_date } end if init_files == :default self.init_files = [ File.join( 'init', spec.name ) ]. select { |f| File.exist?( f ) } end init_files.each do |inf| desc "Check that #{init_files.join(", ")} has latest version" task :check_init_version do test_line_match( inf, init_line_regexp.call( spec ), init_version_regexp.call( spec.version ) ) end end unless init_files.empty? [ :gem, :tag ].each { |t| task t => :check_init_version } end end |
#initialize ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/rjack-tarpit/line_match.rb', line 44 def initialize super @history_regexp = /^==/ @history_date_regexp = /\([0-9\-]+\)$/ @history_version_regexp = Proc.new { |v| / #{v} / } @init_files = :default @init_line_regexp = Proc.new { |s| /^gem.+#{s.name}/ } @init_version_regexp = Proc.new { |v| /= #{v}/ } add_define_hook( :define_line_match_tasks ) end |
#test_line_match(files, line_regex, pass_line_regex = //) ⇒ Object
Test that all specified files have at least one line matching line_regex, and that first line additionally matches (optional) pass_line_regex.
Parameters
- files<Array(~)>
-
List of files to test
- line_regex<Regexp>
-
Test first matching line
- pass_line_regex
-
Further test on match line (default: match all)
Raises
- RuntimeError
-
on test failure.
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/rjack-tarpit/line_match.rb', line 109 def test_line_match( files, line_regex, pass_line_regex = // ) Array( files ).each do |mfile| found = false open( mfile ) do |mf| num = 0 mf.each do |line| num += 1 if line =~ line_regex found = true unless line =~ pass_line_regex raise( "%s:%d: %s !~ %s" % [ mfile, num, line.strip, pass_line_regex.inspect ] ) end break end end end unless found raise "#{mfile}: #{line_regex.inspect} not found" end end end |