Class: RubyCritic::Command::Utils::BuildNumberFile

Inherits:
Object
  • Object
show all
Defined in:
lib/rubycritic/commands/utils/build_number_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBuildNumberFile

Returns a new instance of BuildNumberFile.


9
10
11
# File 'lib/rubycritic/commands/utils/build_number_file.rb', line 9

def initialize
  open_build_number_file
end

Instance Attribute Details

#build_numberObject (readonly)

Returns the value of attribute build_number


7
8
9
# File 'lib/rubycritic/commands/utils/build_number_file.rb', line 7

def build_number
  @build_number
end

#fileObject (readonly)

Returns the value of attribute file


7
8
9
# File 'lib/rubycritic/commands/utils/build_number_file.rb', line 7

def file
  @file
end

Instance Method Details

#open_build_number_fileObject


27
28
29
30
31
32
33
# File 'lib/rubycritic/commands/utils/build_number_file.rb', line 27

def open_build_number_file
  root = Config.root
  FileUtils.mkdir_p(root) unless File.directory?(root)
  location = "#{root}/build_number.txt"
  File.new(location, 'a') unless File.exist?(location)
  @file = File.open(location, 'r+')
end

#update_build_numberObject

keep track of the number of builds and use this build number to create separate directory for each build


15
16
17
18
19
# File 'lib/rubycritic/commands/utils/build_number_file.rb', line 15

def update_build_number
  @build_number = file.read.to_i + 1
  write_build_number
  build_number
end

#write_build_numberObject


21
22
23
24
25
# File 'lib/rubycritic/commands/utils/build_number_file.rb', line 21

def write_build_number
  file.rewind
  file.write(build_number)
  file.close
end