upfluence-utils 0.11.0 → 0.11.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 +4 -4
- data/lib/upfluence/peer.rb +107 -9
- data/lib/upfluence/utils/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34482caf62162c18d2dd1baccb5a6779d6842ada6fe2bd9ea93cb59f4a5dd023
|
4
|
+
data.tar.gz: 11d5ee4d37890bce173e6504c68717eb84b02b83e08dc7b49922876cea8b1be1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5783891f47a807fb2e330666f95e613959551c35f515988b3c565a9cb29f81b720adcb2bc2f80e1657e90d789d244546bcb05fb9157d1f17f85e94aab054c377
|
7
|
+
data.tar.gz: 6cc44d846140cbc7b5066d778ebce30944532c9b3e082ccbbb433741cc5ccacd945a5263fa29c94acb6a47f90a58e8a052888b9a7d6f7cfce7c9c6a69bc8fd97
|
data/lib/upfluence/peer.rb
CHANGED
@@ -1,28 +1,126 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
|
1
3
|
module Upfluence
|
2
4
|
class Peer
|
5
|
+
class Version
|
6
|
+
class SemanticVersion
|
7
|
+
attr_reader :major, :minor, :patch, :suffix
|
8
|
+
|
9
|
+
def initialize(major:, minor:, patch:, suffix: nil)
|
10
|
+
@major = major
|
11
|
+
@minor = minor
|
12
|
+
@patch = patch
|
13
|
+
@suffix = suffix
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_s
|
17
|
+
v = "v#{@major}.#{@minor}.#{@patch}"
|
18
|
+
|
19
|
+
v += "-#{@suffix}" if @suffix
|
20
|
+
v
|
21
|
+
end
|
22
|
+
|
23
|
+
class << self
|
24
|
+
def parse(version)
|
25
|
+
return nil unless version
|
26
|
+
|
27
|
+
v, suffix = version.split('-', 2)
|
28
|
+
|
29
|
+
vs = v.split('.')
|
30
|
+
|
31
|
+
return nil unless vs.count.eql? 3
|
32
|
+
|
33
|
+
SemanticVersion.new(
|
34
|
+
major: vs[0].delete_prefix('v').to_i,
|
35
|
+
minor: vs[1].to_i,
|
36
|
+
patch: vs[2].to_i,
|
37
|
+
suffix: suffix
|
38
|
+
)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class GitVersion
|
44
|
+
attr_reader :commit, :remote, :branch
|
45
|
+
|
46
|
+
def initialize(commit:, remote: nil, branch: nil)
|
47
|
+
@commit = commit
|
48
|
+
@remote = remote
|
49
|
+
@branch = branch
|
50
|
+
end
|
51
|
+
|
52
|
+
def to_s
|
53
|
+
"v0.0.0+git-#{@commit[0..6]}"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
DEFAULT_VERSION = 'v0.0.0-dirty'.freeze
|
58
|
+
|
59
|
+
attr_reader :git, :semantic
|
60
|
+
|
61
|
+
def initialize(git, semantic)
|
62
|
+
@git = git
|
63
|
+
@semantic = semantic
|
64
|
+
end
|
65
|
+
|
66
|
+
def to_s
|
67
|
+
return @semantic.to_s if @semantic
|
68
|
+
return @git.to_s if @git
|
69
|
+
|
70
|
+
DEFAULT_VERSION
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
3
74
|
attr_reader :environment, :authority, :instance_name, :project_name,
|
4
75
|
:app_name
|
5
76
|
|
6
|
-
def initialize(
|
7
|
-
|
8
|
-
@
|
9
|
-
@
|
10
|
-
@
|
11
|
-
@
|
77
|
+
def initialize(authority:, instance_name:, app_name:, project_name:,
|
78
|
+
environment:, version: nil)
|
79
|
+
@authority = authority || 'local'
|
80
|
+
@instance_name = instance_name || 'unknown-server'
|
81
|
+
@app_name = app_name || 'unknown-app'
|
82
|
+
@project_name = project_name || 'unknown-app'
|
83
|
+
@environment = environment || 'development'
|
84
|
+
@version = version
|
12
85
|
end
|
13
86
|
|
14
87
|
def to_url
|
15
|
-
|
88
|
+
query = {
|
89
|
+
'app-name' => @app_name,
|
90
|
+
'project-name' => @project_name,
|
91
|
+
'git-version' => @version.git&.commit,
|
92
|
+
'semantic-version' => @version.semantic&.to_s
|
93
|
+
}.compact.map { |k, v| "#{k}=#{CGI.escape(v)}" }.join('&')
|
94
|
+
|
95
|
+
"peer://#{@environment}@#{@authority}/#{@instance_name}?#{query}"
|
16
96
|
end
|
17
97
|
|
18
98
|
class << self
|
19
99
|
def from_env
|
20
100
|
Peer.new(
|
21
101
|
authority: ENV['AUTHORITY'],
|
22
|
-
instance_name: ENV['
|
102
|
+
instance_name: ENV['UNIT_NAME'],
|
23
103
|
app_name: ENV['APP_NAME'],
|
24
104
|
project_name: ENV['PROJECT_NAME'],
|
25
|
-
environment: ENV['ENV']
|
105
|
+
environment: ENV['ENV'],
|
106
|
+
version: Version.new(
|
107
|
+
build_git_version,
|
108
|
+
Version::SemanticVersion.parse(ENV['VERSION'])
|
109
|
+
)
|
110
|
+
)
|
111
|
+
end
|
112
|
+
|
113
|
+
private
|
114
|
+
|
115
|
+
def build_git_version
|
116
|
+
commit = ENV['GIT_COMMIT']
|
117
|
+
|
118
|
+
return nil unless commit
|
119
|
+
|
120
|
+
Version::GitVersion.new(
|
121
|
+
commit: commit,
|
122
|
+
remote: ENV['GIT_REMOTE'],
|
123
|
+
branch: ENV['GIT_BRANCH']
|
26
124
|
)
|
27
125
|
end
|
28
126
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: upfluence-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.11.
|
4
|
+
version: 0.11.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Upfluence
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -234,7 +234,7 @@ dependencies:
|
|
234
234
|
- - ">="
|
235
235
|
- !ruby/object:Gem::Version
|
236
236
|
version: '0'
|
237
|
-
description:
|
237
|
+
description:
|
238
238
|
email:
|
239
239
|
- dev@upfluence.com
|
240
240
|
executables: []
|
@@ -292,7 +292,7 @@ homepage: https://github.com/upfluence/rbutils
|
|
292
292
|
licenses:
|
293
293
|
- MIT
|
294
294
|
metadata: {}
|
295
|
-
post_install_message:
|
295
|
+
post_install_message:
|
296
296
|
rdoc_options: []
|
297
297
|
require_paths:
|
298
298
|
- lib
|
@@ -307,8 +307,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
307
307
|
- !ruby/object:Gem::Version
|
308
308
|
version: '0'
|
309
309
|
requirements: []
|
310
|
-
rubygems_version: 3.
|
311
|
-
signing_key:
|
310
|
+
rubygems_version: 3.2.32
|
311
|
+
signing_key:
|
312
312
|
specification_version: 4
|
313
313
|
summary: Upfluence common utils for Ruby projects
|
314
314
|
test_files: []
|