Class: Raketeer::FilesBumper
- Inherits:
-
Object
- Object
- Raketeer::FilesBumper
- Defined in:
- lib/raketeer/files_bumper.rb
Overview
Instance Attribute Summary collapse
- #bump_ver ⇒ Object readonly
- #bump_ver_empty ⇒ Object (also: #bump_ver_empty?) readonly
- #changes ⇒ Object
- #dry_run ⇒ Object (also: #dry_run?) readonly
- #files ⇒ Object readonly
- #init_per_file ⇒ Object
- #line ⇒ Object
- #lines ⇒ Object
- #sem_ver ⇒ Object
- #strict ⇒ Object (also: #strict?)
- #version ⇒ Object
-
#version_bumped ⇒ Object
(also: #version_bumped?)
Was the version actually bumped?.
Instance Method Summary collapse
- #add_change(line, push: true) ⇒ Object
- #bump_files(&block) ⇒ Object
- #bump_line!(add_change: true) ⇒ :no_ver, ...
-
#initialize(files, bump_ver, dry_run, strict, &init_per_file) ⇒ FilesBumper
constructor
A new instance of FilesBumper.
Constructor Details
#initialize(files, bump_ver, dry_run, strict, &init_per_file) ⇒ FilesBumper
Returns a new instance of FilesBumper.
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/raketeer/files_bumper.rb', line 39 def initialize(files,bump_ver,dry_run,strict,&init_per_file) @bump_ver = bump_ver @bump_ver_empty = bump_ver.empty? @dry_run = dry_run @files = files.to_a @init_per_file = init_per_file @sem_ver = nil @strict = strict @version = nil @version_bumped = false end |
Instance Attribute Details
#bump_ver ⇒ Object (readonly)
21 22 23 |
# File 'lib/raketeer/files_bumper.rb', line 21 def bump_ver @bump_ver end |
#bump_ver_empty ⇒ Object (readonly) Also known as: bump_ver_empty?
22 23 24 |
# File 'lib/raketeer/files_bumper.rb', line 22 def bump_ver_empty @bump_ver_empty end |
#changes ⇒ Object
23 24 25 |
# File 'lib/raketeer/files_bumper.rb', line 23 def changes @changes end |
#dry_run ⇒ Object (readonly) Also known as: dry_run?
24 25 26 |
# File 'lib/raketeer/files_bumper.rb', line 24 def dry_run @dry_run end |
#files ⇒ Object (readonly)
25 26 27 |
# File 'lib/raketeer/files_bumper.rb', line 25 def files @files end |
#init_per_file ⇒ Object
26 27 28 |
# File 'lib/raketeer/files_bumper.rb', line 26 def init_per_file @init_per_file end |
#line ⇒ Object
27 28 29 |
# File 'lib/raketeer/files_bumper.rb', line 27 def line @line end |
#lines ⇒ Object
28 29 30 |
# File 'lib/raketeer/files_bumper.rb', line 28 def lines @lines end |
#sem_ver ⇒ Object
29 30 31 |
# File 'lib/raketeer/files_bumper.rb', line 29 def sem_ver @sem_ver end |
#strict ⇒ Object Also known as: strict?
30 31 32 |
# File 'lib/raketeer/files_bumper.rb', line 30 def strict @strict end |
#version ⇒ Object
31 32 33 |
# File 'lib/raketeer/files_bumper.rb', line 31 def version @version end |
#version_bumped ⇒ Object Also known as: version_bumped?
Was the version actually bumped?
32 33 34 |
# File 'lib/raketeer/files_bumper.rb', line 32 def version_bumped @version_bumped end |
Instance Method Details
#add_change(line, push: true) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/raketeer/files_bumper.rb', line 51 def add_change(line,push: true) puts "+ #{line}" @changes += 1 @lines << line if push end |
#bump_files(&block) ⇒ 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 99 100 |
# File 'lib/raketeer/files_bumper.rb', line 58 def bump_files(&block) @files.each do |filename| puts "[#{filename}]:" if !File.exist?(filename) puts '! File does not exist' next end @changes = 0 # For possible future use @lines = [] @sem_ver = nil @init_per_file&.call(self) File.foreach(filename) do |line| @line = line block.call(self) if !@line.strip.empty? @lines << @line end next if bump_ver_empty? print '= ' if @changes > 0 if dry_run? puts "Nothing written (dry run): #{@sem_ver}" else File.open(filename,'w') do |file| file.puts @lines end puts "#{@changes} change#{@changes == 1 ? '' : 's'} written" end else puts "Nothing written (up-to-date): #{@sem_ver}" end end end |
#bump_line!(add_change: true) ⇒ :no_ver, ...
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/raketeer/files_bumper.rb', line 103 def bump_line!(add_change: true) @sem_ver = SemVer.parse_line(@line,strict: @strict) return :no_ver if @sem_ver.nil? @version = @sem_ver if @version.nil? if bump_ver_empty? puts "= #{@sem_ver}" return :same_ver else orig_line = @line.dup orig_sem_ver_s = @sem_ver.to_s @bump_ver.bump_line!(@line,@sem_ver,strict: @strict) if @sem_ver.to_s != orig_sem_ver_s if !@version_bumped @version = @sem_ver @version_bumped = true end self.add_change(@line,push: false) if add_change return :bumped_ver else @line = orig_line return :same_ver end end end |