paranoid_versioning 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e68dd05d3b3a0fec00447e861b3761f5ad6e2fbf
4
+ data.tar.gz: bb1a948cf290c72b76d7a1963d92c022c9774aa2
5
+ SHA512:
6
+ metadata.gz: ea408644348844fdac09648232d07e19b91918fef54d85e47de15956f183c4c531fcc28267fac871e0b0db36738d319e2173cfbc49b6ca128b732bc257547f20
7
+ data.tar.gz: 8612be2052269c6fa07695dc6ec3d49571b7a4524e10cbfe0911da9d84e3c6e1d62515022d8e023837d1761e7a7c531f01976bca129ba259c3f60441d80c70a1
@@ -0,0 +1,147 @@
1
+ require 'yaml'
2
+
3
+ class ParanoidVersioning
4
+ include Comparable
5
+
6
+ attr_accessor :major, :minor, :patch, :milestone, :build, :branch, :commiter, :build_date, :format
7
+
8
+ [:major, :minor, :patch, :milestone, :build, :branch, :commiter, :build_date, :format].each do |attr|
9
+ define_method "#{attr}=".to_sym do |value|
10
+ instance_variable_set("@#{attr}".to_sym, value.blank? ? nil : value.to_s)
11
+ end
12
+ end
13
+
14
+ # Creates a new instance of the version class using information in the passed
15
+ # Hash to construct the version number
16
+ #
17
+ # ParanoidVersioning.new(:major => 1, :minor => 0) #=> "1.0"
18
+ def initialize(args = nil)
19
+ if args && args.is_a?(Hash)
20
+ args.keys.reject { |key| key.is_a?(Symbol) }.each{ |key| args[key.to_sym] = args.delete(key) }
21
+
22
+ [:major, :minor].each do |param|
23
+ raise ArgumentError.new("The #{param.to_s} parameter is required") if args[param].nil?
24
+ end
25
+ end
26
+
27
+ @major = args[:major].to_s
28
+ @minor = args[:minor].to_s
29
+ @patch = args[:patch].to_s unless args[:patch].nil?
30
+ @milestone = args[:milestone].to_s unless args[:milestone].nil?
31
+ @branch = args[:branch].to_s unless args[:branch].nil?
32
+ @commiter = args[:commiter].to_s unless args[:commiter].nil?
33
+ @format = args[:format].to_s unless args[:format].nil?
34
+
35
+ unless args[:build_date].nil?
36
+ get_date = case args[:build_date]
37
+ when 'git-revdate'
38
+ get_revdate_from_git
39
+ else
40
+ args[:build_date].to_s
41
+ end
42
+ @build_date = Date.parse(get_date)
43
+ end
44
+
45
+ unless args[:branch].nil?
46
+ @branch = get_branch_name_from_git
47
+ end
48
+
49
+ @build = case args[:build]
50
+ when 'git-revcount'
51
+ get_revcount_from_git
52
+ when 'git-hash'
53
+ get_hash_from_git
54
+ when nil, ''
55
+ unless args[:build].nil?
56
+ args.delete(:build)
57
+ end
58
+ else
59
+ args[:build].to_s
60
+ end
61
+ end
62
+
63
+ # Parses a version string to create an instance of the Version class
64
+ def self.parse(version)
65
+ m = version.match(/(\d+)\.(\d+)(?:\.(\d+))?(?:\sM(\d+))?(?:\sof\s(\w+))?(?:\sby\s(\w+))?(?:\son\s(\S+))?/)
66
+
67
+ raise ArgumentError.new("The version '#{version}' is unparsable") if m.nil?
68
+
69
+ version = ParanoidVersioning.new :major => m[1],
70
+ :minor => m[2],
71
+ :patch => m[3],
72
+ :milestone => m[4],
73
+ :build => m[5],
74
+ :branch => m[6],
75
+ :commiter => m[7]
76
+
77
+ if (m[8] && m[8] != '')
78
+ date = Date.parse(m[8])
79
+ version.build_date = date
80
+ end
81
+
82
+ return version
83
+
84
+ end
85
+
86
+ # Loads the version information from a YAML file
87
+ def self.load(path)
88
+ if File.exist?(path)
89
+ ParanoidVersioning.new YAML::load(File.open(path))
90
+ else
91
+ header = ["COMMENT"]
92
+ recipe = { "major" => 1, "minor" => 0 }
93
+ template_yml = File.read('templates/version.yml')
94
+ File.open(path, "w+") { |f| f.write template_yml } #Store
95
+ File.open(path, "a") { |f| f << recipe.to_yaml } #Store
96
+ ParanoidVersioning.new YAML::load(File.open(path))
97
+ end
98
+ end
99
+
100
+ def to_s
101
+ if @format
102
+ str = eval(@format.to_s.inspect)
103
+ else
104
+ str = "#{major}.#{minor}"
105
+ str << ".#{patch}" unless patch.nil?
106
+ str << ".#{milestone} " unless milestone.nil?
107
+ str << "(#{build}) " unless build.nil?
108
+ str << "of #{branch}" unless branch.nil?
109
+ str << "by #{commiter} " unless commiter.nil?
110
+ str << "on #{build_date}" unless build_date.nil?
111
+ end
112
+ str
113
+ end
114
+
115
+ def get_revcount_from_git
116
+ if File.exist?(".git")
117
+ `git rev-list --count HEAD`.strip
118
+ end
119
+ end
120
+
121
+ def get_revdate_from_git
122
+ if File.exist?(".git")
123
+ `git show --date=short --pretty=format:%cd`.split("\n")[0].strip
124
+ end
125
+ end
126
+
127
+ def get_hash_from_git
128
+ if File.exist?(".git")
129
+ `git show --pretty=format:%H`.split("\n")[0].strip[0..5]
130
+ end
131
+ end
132
+
133
+ def get_branch_name_from_git
134
+ if File.exist?(".git")
135
+ `git rev-parse --abbrev-ref HEAD`
136
+ end
137
+ end
138
+
139
+ if defined?(Rails.root.to_s) && File.exist?("#{(Rails.root.to_s)}/config/version.yml")
140
+ APP_VERSION = ParanoidVersioning.load "#{(Rails.root.to_s)}/config/version.yml"
141
+ end
142
+
143
+ def self.get_version
144
+ ParanoidVersioning.load "#{(Rails.root.to_s)}/config/version.yml"
145
+ end
146
+
147
+ end
@@ -0,0 +1,4 @@
1
+ # Control version for Rails App
2
+ # major: Cambio mayor
3
+ # minor: Cambios minimos
4
+ # patch: Cambios criticos o parches
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: paranoid_versioning
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Cristian Ramirez
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-03-04 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Gem for manage the version of the app. Gem based on https://github.com/toland/app_version.git
14
+ email: cristian.ramirez@pdc.la
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/paranoid_versioning.rb
20
+ - templates/version.yml
21
+ homepage: ''
22
+ licenses:
23
+ - MIT
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.6.14.1
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: Paranoid Versioning
45
+ test_files: []