Class: ThorSCMVersion::P4Version

Inherits:
ScmVersion show all
Defined in:
lib/thor-scmversion/p4_version.rb

Constant Summary

Constants inherited from ScmVersion

ScmVersion::VERSION_FILENAME, ScmVersion::VERSION_FORMAT

Instance Attribute Summary collapse

Attributes inherited from ScmVersion

#build, #major, #minor, #patch, #prerelease

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ScmVersion

#<=>, #bump!, from_path, from_tag, #reset_for, retrieve_tags, #to_s, #write_version

Constructor Details

#initialize(major = 0, minor = 0, patch = 0, prerelease = nil, build = 1) ⇒ P4Version

Returns a new instance of P4Version.



92
93
94
95
96
# File 'lib/thor-scmversion/p4_version.rb', line 92

def initialize(major = 0, minor = 0, patch = 0, prerelease = nil, build = 1)
  self.p4_depot_path = self.class.depot_path('.')
  self.p4_module_name = self.class.module_name('.')
  super
end

Instance Attribute Details

#p4_depot_pathObject

Returns the value of attribute p4_depot_path.



99
100
101
# File 'lib/thor-scmversion/p4_version.rb', line 99

def p4_depot_path
  @p4_depot_path
end

#p4_module_nameObject

Returns the value of attribute p4_module_name.



100
101
102
# File 'lib/thor-scmversion/p4_version.rb', line 100

def p4_module_name
  @p4_module_name
end

#version_file_pathObject

Returns the value of attribute version_file_path.



98
99
100
# File 'lib/thor-scmversion/p4_version.rb', line 98

def version_file_path
  @version_file_path
end

Class Method Details

.all_from_path(path) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/thor-scmversion/p4_version.rb', line 55

def all_from_path(path)
  Dir.chdir(path) do
    all_labels_array = `p4 labels -e \"#{module_name(path)}*\"`.split("\n")
    thor_scmversion_labels = get_thor_scmversion_labels(all_labels_array, module_name(path))

    current_versions = thor_scmversion_labels.collect do |label|
      new_instance = new(*parse_label(label, module_name(path)))
    end.sort.reverse

    if current_versions.empty?
      first_instance = new(0, 0, 0)
    end 

    current_versions << first_instance if current_versions.empty?
    current_versions
  end
end

.depot_path(path) ⇒ Object



73
74
75
76
77
# File 'lib/thor-scmversion/p4_version.rb', line 73

def depot_path(path)
  path = File.expand_path(path)
  path = path.gsub(File::Separator, File::ALT_SEPARATOR) if ThorSCMVersion.windows?
  `p4 where "#{path}/..."`.split(" ").first.gsub("/...", "")
end

.get_thor_scmversion_labels(labels, p4_module_name) ⇒ Object



87
88
89
# File 'lib/thor-scmversion/p4_version.rb', line 87

def get_thor_scmversion_labels(labels, p4_module_name)
  labels.select{|label| label.split(" ")[1].gsub("#{p4_module_name}-", "").match(ScmVersion::VERSION_FORMAT)}        
end

.module_name(path) ⇒ Object



79
80
81
# File 'lib/thor-scmversion/p4_version.rb', line 79

def module_name(path)
  depot_path(path).gsub("//", "").gsub("/", "-")
end

.parse_label(label, p4_module_name) ⇒ Object



83
84
85
# File 'lib/thor-scmversion/p4_version.rb', line 83

def parse_label(label, p4_module_name)
  label.split(" ")[1].gsub("#{p4_module_name}-", "").split('.')
end

Instance Method Details

#auto_bump(options) ⇒ Object



115
116
117
118
# File 'lib/thor-scmversion/p4_version.rb', line 115

def auto_bump(options)
  # TODO: actually implement this
  bump!(:patch)
end

#retrieve_tagsObject



102
103
104
105
# File 'lib/thor-scmversion/p4_version.rb', line 102

def retrieve_tags
  # noop
  # p4 always has labels available, you just have to ask the server for them.
end

#tagObject



107
108
109
110
111
112
113
# File 'lib/thor-scmversion/p4_version.rb', line 107

def tag
  if ThorSCMVersion.windows?
    `type "#{File.expand_path(get_p4_label_file).gsub(File::Separator, File::ALT_SEPARATOR)}" | p4 label -i`
  else
    `cat "#{File.expand_path(get_p4_label_file)}" | p4 label -i`
  end
end