Class: Versioneer::Repo

Inherits:
Object
  • Object
show all
Defined in:
lib/versioneer/repo.rb

Direct Known Subclasses

Bypass, Git

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_within_repo, options = nil) ⇒ Repo

Returns a new instance of Repo.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/versioneer/repo.rb', line 3

def initialize(file_within_repo, options=nil)
  @file = file_within_repo
  @directory = File.dirname(@file)
  @environment = nil

  @bump_segment = :minor
  @prereleases = %w(alpha beta rc)
  @release_pattern = /\Av?([0-9\.]+\z)/
  @starting_release = Gem::Version.new('0.0')

  if options.is_a? Hash
    options.each do |k, v|
      send("#{k}=", v)
    end
  end
end

Instance Attribute Details

#bump_segmentObject

Returns the value of attribute bump_segment.



23
24
25
# File 'lib/versioneer/repo.rb', line 23

def bump_segment
  @bump_segment
end

#environmentObject



29
30
31
# File 'lib/versioneer/repo.rb', line 29

def environment
  @environment || ENV['VERSIONEER_ENV'] || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || ENV['ENV'] || 'development'
end

#prereleasesObject

Returns the value of attribute prereleases.



20
21
22
# File 'lib/versioneer/repo.rb', line 20

def prereleases
  @prereleases
end

#release_patternObject

Returns the value of attribute release_pattern.



67
68
69
# File 'lib/versioneer/repo.rb', line 67

def release_pattern
  @release_pattern
end

#starting_releaseObject

Returns the value of attribute starting_release.



20
21
22
# File 'lib/versioneer/repo.rb', line 20

def starting_release
  @starting_release
end

Class Method Details

.bump(version, bump_segment, prerelease_suffix = nil, bump_count = 1) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/versioneer/repo.rb', line 82

def self.bump(version, bump_segment, prerelease_suffix=nil, bump_count=1)
  length = segment_to_i(bump_segment) + 1 unless bump_segment.nil?

  if version.prerelease? or bump_segment.nil?
    next_version = (version.release.segments + [prerelease_suffix]).compact.join('.')
  else
    next_version = version
    bump_count.times do
      segments = next_version.release.segments.slice(0, length)
      while segments.size < length + 1 # Version.bump strips last segment
        segments << 0
      end
      next_version = Gem::Version.new(segments.join('.')).bump
    end
    next_version = [next_version.to_s, prerelease_suffix].compact.join('.')
  end

  next_version
end

.segment_to_i(segment) ⇒ Object



102
103
104
# File 'lib/versioneer/repo.rb', line 102

def self.segment_to_i(segment)
  [:major, :minor, :patch].index(segment)
end

Instance Method Details

#commits_since_releaseObject



74
75
76
# File 'lib/versioneer/repo.rb', line 74

def commits_since_release
  0
end

#filesystem_dirty?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/versioneer/repo.rb', line 78

def filesystem_dirty?
  true
end

#releaseObject



63
64
65
# File 'lib/versioneer/repo.rb', line 63

def release
  starting_release
end

#to_sObject



35
36
37
# File 'lib/versioneer/repo.rb', line 35

def to_s
  version.to_s
end

#versionObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/versioneer/repo.rb', line 39

def version
  prerelease = nil
  c = commits_since_release

  if environment == 'production'
    if bump_segment == :minor and prereleases[2].nil? and c > 0
      # Use commits as addition to patch level, instead of release candidate.
      return self.class.bump(release.release, :patch, nil, c)
    else
      prerelease = prereleases[2].to_s + c.to_s if c > 0
    end
  elsif filesystem_dirty?
    prerelease = prereleases[0].to_s + (c+1).to_s
  elsif c > 0
    prerelease = prereleases[1].to_s + c.to_s
  end

  if prerelease
    self.class.bump(release, bump_segment, prerelease)
  else
    release
  end
end