usps-support 0.1.0
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 +7 -0
- data/.ruby-version +1 -0
- data/Gemfile.lock +199 -0
- data/Rakefile +12 -0
- data/Readme.md +26 -0
- data/lib/usps/support/helpers/.rubocop.yml +18 -0
- data/lib/usps/support/helpers/badges_helper.rb +137 -0
- data/lib/usps/support/helpers/flags_helper.rb +59 -0
- data/lib/usps/support/helpers/git_helper.rb +25 -0
- data/lib/usps/support/helpers/react_helper.rb +15 -0
- data/lib/usps/support/helpers/scss_helper.rb +26 -0
- data/lib/usps/support/helpers.rb +11 -0
- data/lib/usps/support/models/.rubocop.yml +18 -0
- data/lib/usps/support/models/dynamo_db.rb +58 -0
- data/lib/usps/support/models/git_hub.rb +56 -0
- data/lib/usps/support/models.rb +8 -0
- data/lib/usps/support/version.rb +7 -0
- data/lib/usps/support.rb +11 -0
- data/sig/usps/support.rbs +6 -0
- metadata +73 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 924a50b9ad57969f2c0dce0b64b9abd18a83f803b895182d7410296136ed014c
|
|
4
|
+
data.tar.gz: 154ecc715ff110021b9cb630c79b0304ee9d521cf4497227ad7e8a8fb8815053
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 24b4cc2ee103a4e9f909a88e54fc6b0491e77cd1ce0115c19f654f8c0cf764748c1c75ecf55c95c9a8ece9a4b553aea7e72ceef55e307f3592fa683967953782
|
|
7
|
+
data.tar.gz: 658ff616f328c9e07dba4e791a2e7750fa9a64cb41e9ec255f1c226763f4b7d63468d70aa1a3c70e1c95297fa2d3951ba57095c6c75fed15b4ad55c3289b23f6
|
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.4.6
|
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
usps-support (0.1.0)
|
|
5
|
+
sassc-rails
|
|
6
|
+
|
|
7
|
+
GEM
|
|
8
|
+
remote: https://rubygems.org/
|
|
9
|
+
specs:
|
|
10
|
+
actionpack (8.1.0)
|
|
11
|
+
actionview (= 8.1.0)
|
|
12
|
+
activesupport (= 8.1.0)
|
|
13
|
+
nokogiri (>= 1.8.5)
|
|
14
|
+
rack (>= 2.2.4)
|
|
15
|
+
rack-session (>= 1.0.1)
|
|
16
|
+
rack-test (>= 0.6.3)
|
|
17
|
+
rails-dom-testing (~> 2.2)
|
|
18
|
+
rails-html-sanitizer (~> 1.6)
|
|
19
|
+
useragent (~> 0.16)
|
|
20
|
+
actionview (8.1.0)
|
|
21
|
+
activesupport (= 8.1.0)
|
|
22
|
+
builder (~> 3.1)
|
|
23
|
+
erubi (~> 1.11)
|
|
24
|
+
rails-dom-testing (~> 2.2)
|
|
25
|
+
rails-html-sanitizer (~> 1.6)
|
|
26
|
+
activesupport (8.1.0)
|
|
27
|
+
base64
|
|
28
|
+
bigdecimal
|
|
29
|
+
concurrent-ruby (~> 1.0, >= 1.3.1)
|
|
30
|
+
connection_pool (>= 2.2.5)
|
|
31
|
+
drb
|
|
32
|
+
i18n (>= 1.6, < 2)
|
|
33
|
+
json
|
|
34
|
+
logger (>= 1.4.2)
|
|
35
|
+
minitest (>= 5.1)
|
|
36
|
+
securerandom (>= 0.3)
|
|
37
|
+
tzinfo (~> 2.0, >= 2.0.5)
|
|
38
|
+
uri (>= 0.13.1)
|
|
39
|
+
ast (2.4.3)
|
|
40
|
+
base64 (0.3.0)
|
|
41
|
+
bigdecimal (3.3.1)
|
|
42
|
+
builder (3.3.0)
|
|
43
|
+
concurrent-ruby (1.3.5)
|
|
44
|
+
connection_pool (2.5.4)
|
|
45
|
+
crass (1.0.6)
|
|
46
|
+
date (3.4.1)
|
|
47
|
+
diff-lcs (1.6.2)
|
|
48
|
+
docile (1.4.1)
|
|
49
|
+
drb (2.2.3)
|
|
50
|
+
erb (5.1.3)
|
|
51
|
+
erubi (1.13.1)
|
|
52
|
+
ffi (1.17.2-arm64-darwin)
|
|
53
|
+
i18n (1.14.7)
|
|
54
|
+
concurrent-ruby (~> 1.0)
|
|
55
|
+
io-console (0.8.1)
|
|
56
|
+
irb (1.15.2)
|
|
57
|
+
pp (>= 0.6.0)
|
|
58
|
+
rdoc (>= 4.0.0)
|
|
59
|
+
reline (>= 0.4.2)
|
|
60
|
+
json (2.15.2)
|
|
61
|
+
language_server-protocol (3.17.0.5)
|
|
62
|
+
lint_roller (1.1.0)
|
|
63
|
+
logger (1.7.0)
|
|
64
|
+
loofah (2.24.1)
|
|
65
|
+
crass (~> 1.0.2)
|
|
66
|
+
nokogiri (>= 1.12.0)
|
|
67
|
+
minitest (5.26.0)
|
|
68
|
+
nokogiri (1.18.10-arm64-darwin)
|
|
69
|
+
racc (~> 1.4)
|
|
70
|
+
parallel (1.27.0)
|
|
71
|
+
parser (3.3.10.0)
|
|
72
|
+
ast (~> 2.4.1)
|
|
73
|
+
racc
|
|
74
|
+
pp (0.6.3)
|
|
75
|
+
prettyprint
|
|
76
|
+
prettyprint (0.2.0)
|
|
77
|
+
prism (1.6.0)
|
|
78
|
+
psych (5.2.6)
|
|
79
|
+
date
|
|
80
|
+
stringio
|
|
81
|
+
racc (1.8.1)
|
|
82
|
+
rack (3.2.3)
|
|
83
|
+
rack-session (2.1.1)
|
|
84
|
+
base64 (>= 0.1.0)
|
|
85
|
+
rack (>= 3.0.0)
|
|
86
|
+
rack-test (2.2.0)
|
|
87
|
+
rack (>= 1.3)
|
|
88
|
+
rackup (2.2.1)
|
|
89
|
+
rack (>= 3)
|
|
90
|
+
rails-dom-testing (2.3.0)
|
|
91
|
+
activesupport (>= 5.0.0)
|
|
92
|
+
minitest
|
|
93
|
+
nokogiri (>= 1.6)
|
|
94
|
+
rails-html-sanitizer (1.6.2)
|
|
95
|
+
loofah (~> 2.21)
|
|
96
|
+
nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
|
|
97
|
+
railties (8.1.0)
|
|
98
|
+
actionpack (= 8.1.0)
|
|
99
|
+
activesupport (= 8.1.0)
|
|
100
|
+
irb (~> 1.13)
|
|
101
|
+
rackup (>= 1.0.0)
|
|
102
|
+
rake (>= 12.2)
|
|
103
|
+
thor (~> 1.0, >= 1.2.2)
|
|
104
|
+
tsort (>= 0.2)
|
|
105
|
+
zeitwerk (~> 2.6)
|
|
106
|
+
rainbow (3.1.1)
|
|
107
|
+
rake (13.3.0)
|
|
108
|
+
rdoc (6.15.0)
|
|
109
|
+
erb
|
|
110
|
+
psych (>= 4.0.0)
|
|
111
|
+
tsort
|
|
112
|
+
regexp_parser (2.11.3)
|
|
113
|
+
reline (0.6.2)
|
|
114
|
+
io-console (~> 0.5)
|
|
115
|
+
rspec (3.13.2)
|
|
116
|
+
rspec-core (~> 3.13.0)
|
|
117
|
+
rspec-expectations (~> 3.13.0)
|
|
118
|
+
rspec-mocks (~> 3.13.0)
|
|
119
|
+
rspec-core (3.13.6)
|
|
120
|
+
rspec-support (~> 3.13.0)
|
|
121
|
+
rspec-expectations (3.13.5)
|
|
122
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
123
|
+
rspec-support (~> 3.13.0)
|
|
124
|
+
rspec-mocks (3.13.6)
|
|
125
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
126
|
+
rspec-support (~> 3.13.0)
|
|
127
|
+
rspec-support (3.13.6)
|
|
128
|
+
rubocop (1.81.6)
|
|
129
|
+
json (~> 2.3)
|
|
130
|
+
language_server-protocol (~> 3.17.0.2)
|
|
131
|
+
lint_roller (~> 1.1.0)
|
|
132
|
+
parallel (~> 1.10)
|
|
133
|
+
parser (>= 3.3.0.2)
|
|
134
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
135
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
|
136
|
+
rubocop-ast (>= 1.47.1, < 2.0)
|
|
137
|
+
ruby-progressbar (~> 1.7)
|
|
138
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
|
139
|
+
rubocop-ast (1.47.1)
|
|
140
|
+
parser (>= 3.3.7.2)
|
|
141
|
+
prism (~> 1.4)
|
|
142
|
+
rubocop-rake (0.7.1)
|
|
143
|
+
lint_roller (~> 1.1)
|
|
144
|
+
rubocop (>= 1.72.1)
|
|
145
|
+
rubocop-rspec (3.7.0)
|
|
146
|
+
lint_roller (~> 1.1)
|
|
147
|
+
rubocop (~> 1.72, >= 1.72.1)
|
|
148
|
+
ruby-progressbar (1.13.0)
|
|
149
|
+
sassc (2.4.0)
|
|
150
|
+
ffi (~> 1.9)
|
|
151
|
+
sassc-rails (2.1.2)
|
|
152
|
+
railties (>= 4.0.0)
|
|
153
|
+
sassc (>= 2.0)
|
|
154
|
+
sprockets (> 3.0)
|
|
155
|
+
sprockets-rails
|
|
156
|
+
tilt
|
|
157
|
+
securerandom (0.4.1)
|
|
158
|
+
simplecov (0.22.0)
|
|
159
|
+
docile (~> 1.1)
|
|
160
|
+
simplecov-html (~> 0.11)
|
|
161
|
+
simplecov_json_formatter (~> 0.1)
|
|
162
|
+
simplecov-html (0.13.2)
|
|
163
|
+
simplecov_json_formatter (0.1.4)
|
|
164
|
+
sprockets (4.2.2)
|
|
165
|
+
concurrent-ruby (~> 1.0)
|
|
166
|
+
logger
|
|
167
|
+
rack (>= 2.2.4, < 4)
|
|
168
|
+
sprockets-rails (3.5.2)
|
|
169
|
+
actionpack (>= 6.1)
|
|
170
|
+
activesupport (>= 6.1)
|
|
171
|
+
sprockets (>= 3.0.0)
|
|
172
|
+
stringio (3.1.7)
|
|
173
|
+
thor (1.4.0)
|
|
174
|
+
tilt (2.6.1)
|
|
175
|
+
tsort (0.2.0)
|
|
176
|
+
tzinfo (2.0.6)
|
|
177
|
+
concurrent-ruby (~> 1.0)
|
|
178
|
+
unicode-display_width (3.2.0)
|
|
179
|
+
unicode-emoji (~> 4.1)
|
|
180
|
+
unicode-emoji (4.1.0)
|
|
181
|
+
uri (1.0.4)
|
|
182
|
+
useragent (0.16.11)
|
|
183
|
+
zeitwerk (2.7.3)
|
|
184
|
+
|
|
185
|
+
PLATFORMS
|
|
186
|
+
arm64-darwin-24
|
|
187
|
+
|
|
188
|
+
DEPENDENCIES
|
|
189
|
+
irb
|
|
190
|
+
rake (~> 13.0)
|
|
191
|
+
rspec (~> 3.0)
|
|
192
|
+
rubocop (~> 1.81)
|
|
193
|
+
rubocop-rake (~> 0.7)
|
|
194
|
+
rubocop-rspec (~> 3.7)
|
|
195
|
+
simplecov (~> 0.22)
|
|
196
|
+
usps-support!
|
|
197
|
+
|
|
198
|
+
BUNDLED WITH
|
|
199
|
+
2.7.2
|
data/Rakefile
ADDED
data/Readme.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# USPS Rails Support
|
|
2
|
+
|
|
3
|
+
[](https://rubygems.org/gems/usps-support)
|
|
4
|
+
|
|
5
|
+
Shared helpers and general models for supporting Rails applications.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Add the gem to your Gemfile:
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
gem 'usps-support'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```ruby
|
|
18
|
+
module ApplicationHelper
|
|
19
|
+
include Usps::Supoprt::Helpers::BadgesHelper
|
|
20
|
+
include Usps::Supoprt::Helpers::FlagsHelper
|
|
21
|
+
end
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
```ruby
|
|
25
|
+
Usps::Supoprt::Models::GitHub.latest_tag('usps-support')
|
|
26
|
+
```
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
inherit_from: ../../../../.rubocop.yml
|
|
2
|
+
|
|
3
|
+
Metrics/ClassLength:
|
|
4
|
+
Enabled: true
|
|
5
|
+
Max: 150
|
|
6
|
+
Metrics/ModuleLength:
|
|
7
|
+
Max: 150
|
|
8
|
+
Metrics/CyclomaticComplexity:
|
|
9
|
+
Enabled: true
|
|
10
|
+
Max: 15
|
|
11
|
+
Metrics/PerceivedComplexity:
|
|
12
|
+
Max: 15
|
|
13
|
+
Metrics/AbcSize:
|
|
14
|
+
Enabled: true
|
|
15
|
+
Max: 25
|
|
16
|
+
Metrics/MethodLength:
|
|
17
|
+
Enabled: true
|
|
18
|
+
Max: 25
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Usps::Support::Helpers
|
|
4
|
+
# Generate badge images
|
|
5
|
+
#
|
|
6
|
+
module BadgesHelper
|
|
7
|
+
GITHUB = 'https://github.com/unitedstatespowersquadrons'
|
|
8
|
+
SHIELDS = 'https://img.shields.io'
|
|
9
|
+
|
|
10
|
+
def tag_badge(version, label: nil)
|
|
11
|
+
label = "#{label&.gsub('-', '--')&.gsub('_', '__')&.gsub(' ', '_')}-" if label.present?
|
|
12
|
+
|
|
13
|
+
image_tag("#{SHIELDS}/badge/#{label}#{version}-#{version_color(version)}")
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def branch_badge(branch, repo: nil)
|
|
17
|
+
repo = nil if branch == 'main'
|
|
18
|
+
color = branch == 'main' ? :blue : :orange
|
|
19
|
+
name = badgeify(branch)
|
|
20
|
+
|
|
21
|
+
image = image_tag("#{SHIELDS}/badge/#{name}-#{color}?logo=git&logoColor=white")
|
|
22
|
+
return image unless repo
|
|
23
|
+
|
|
24
|
+
link_to("#{GITHUB}/#{repo}/compare/#{branch}?expand=1", target: :blank) { image }
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def commit_badge(commit, sha: true, repo: nil)
|
|
28
|
+
image = image_tag("#{SHIELDS}/badge/#{'sha-' if sha}#{commit[...12]}-purple")
|
|
29
|
+
return image unless repo
|
|
30
|
+
|
|
31
|
+
link_to("#{GITHUB}/#{repo}/commit/#{commit}", target: :blank) { image }
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def gem_badge(gem, include_prereleases: false)
|
|
35
|
+
link_to("https://rubygems.org/gems/#{gem}", target: :blank) do
|
|
36
|
+
image_tag(
|
|
37
|
+
"#{SHIELDS}/gem/v/#{gem}?logo=rubygems&logoColor=white#{'&include_prereleases' if include_prereleases}"
|
|
38
|
+
)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def npm_badge(package, include_prereleases: false)
|
|
43
|
+
link_to("https://www.npmjs.com/package/@unitedstatespowersquadrons/#{package}", target: :blank) do
|
|
44
|
+
image_base = "#{SHIELDS}/npm/v/@unitedstatespowersquadrons/#{package}?logo=typescript&logoColor=white"
|
|
45
|
+
image_tag("#{image_base}#{'&include_prereleases' if include_prereleases}")
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def php_library_badge(repo, version)
|
|
50
|
+
link_to("#{GITHUB}/#{repo}", target: :blank) do
|
|
51
|
+
image_tag("#{SHIELDS}/badge/library-#{version}-#{version_color(version)}?logo=php&logoColor=white")
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def repo_badge(repo)
|
|
56
|
+
link_to("#{GITHUB}/#{repo}", target: :blank) { image_tag("#{SHIELDS}/badge/repo-gray?logo=github") }
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def suite_badge(suite = {}, repo = nil)
|
|
60
|
+
return if suite.nil?
|
|
61
|
+
|
|
62
|
+
branch = badgeify(suite[:head_branch])
|
|
63
|
+
description =
|
|
64
|
+
if suite[:skip_ci] then 'Skipped'
|
|
65
|
+
elsif suite[:status] == 'completed' then badgeify(suite[:conclusion]&.titleize)
|
|
66
|
+
else
|
|
67
|
+
badgeify(suite[:status]&.titleize)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
image = image_tag(
|
|
71
|
+
"#{SHIELDS}/badge/#{branch}-#{description || 'Unknown'}-#{suite_badge_color(suite)}?logo=github"
|
|
72
|
+
)
|
|
73
|
+
return image if repo.nil? || suite[:conclusion] == 'success'
|
|
74
|
+
|
|
75
|
+
link_to("#{GITHUB}/#{repo}/actions/workflows/main.yml", target: :blank) { image }
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def suite_badge_color(suite = {})
|
|
79
|
+
return :lightgray if suite[:skip_ci]
|
|
80
|
+
|
|
81
|
+
case suite[:status]
|
|
82
|
+
when 'queued', 'in_progress', 'requested', 'waiting', 'pending'
|
|
83
|
+
:yellow
|
|
84
|
+
when 'completed'
|
|
85
|
+
case suite[:conclusion]
|
|
86
|
+
when 'success' then :brightgreen
|
|
87
|
+
when 'failure', 'timed_out', 'action_required' then :red
|
|
88
|
+
when 'cancelled' then :orange
|
|
89
|
+
when 'neutral', 'skipped' then :lightgray
|
|
90
|
+
end
|
|
91
|
+
else
|
|
92
|
+
:lightgray
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def reachable_badge(host, reachable)
|
|
97
|
+
link_to("https://#{host}.aws.usps.org", target: :blank) do
|
|
98
|
+
image_tag("#{SHIELDS}/badge/#{host}-#{reachable ? :Reachable : :Error}-#{reachable ? :brightgreen : :red}")
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def relative_date_badge(datetime, **options)
|
|
103
|
+
timestamp =
|
|
104
|
+
case datetime
|
|
105
|
+
when Integer then datetime
|
|
106
|
+
when String then DateTime.strptime(datetime).in_time_zone('Eastern Time (US & Canada)').to_i
|
|
107
|
+
when DateTime, Time then datetime.to_i
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
query = options.slice(:label, :logo)
|
|
111
|
+
query[:color] = timestamp_color(timestamp)
|
|
112
|
+
image_tag("#{SHIELDS}/date/#{timestamp}?#{query.to_query}")
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
private
|
|
116
|
+
|
|
117
|
+
def version_color(version)
|
|
118
|
+
orange = version[0..1] == 'v0'
|
|
119
|
+
colors = %i[orange blue]
|
|
120
|
+
orange ? colors[0] : colors[1]
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def badgeify(text)
|
|
124
|
+
text&.gsub('-', '--')&.gsub('_', '__')&.gsub(' ', '_')
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def timestamp_color(timestamp)
|
|
128
|
+
case Time.zone.at(timestamp.to_i)
|
|
129
|
+
when ...14.days.ago then '63a2c7' # faded :blue
|
|
130
|
+
when 14.days.ago...1.day.ago then :blue
|
|
131
|
+
when 1.day.ago...1.hour.ago, 10.minutes.from_now...1.hour.from_now then :green
|
|
132
|
+
when 1.hour.ago...10.minutes.from_now then :yellowgreen
|
|
133
|
+
when 1.hour.from_now.. then :brightgreen
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Usps::Support::Helpers
|
|
4
|
+
# Generate officer and signal flag images
|
|
5
|
+
#
|
|
6
|
+
module FlagsHelper
|
|
7
|
+
FLAGS_BASE_URL = 'https://flags.aws.usps.org'
|
|
8
|
+
SIGNAL_BASE_URL = 'https://flags.aws.usps.org/signals'
|
|
9
|
+
RANKS = {
|
|
10
|
+
'31000' => 'CDR', '32000' => 'LTC', '31010' => 'LT',
|
|
11
|
+
'21000' => 'DC', '22000' => 'DLTC', '21010' => 'DLT',
|
|
12
|
+
'11000' => 'CC'
|
|
13
|
+
}.freeze
|
|
14
|
+
RANK_PATTERNS = {
|
|
15
|
+
/1\d000/ => 'VC', /1\d{3}0/ => 'RC', /1\d{3}1/ => 'STFC'
|
|
16
|
+
}.freeze
|
|
17
|
+
|
|
18
|
+
def officer_flag(rank, format: :svg, size: nil)
|
|
19
|
+
size = ".#{size}" unless size.nil?
|
|
20
|
+
image_tag("#{FLAGS_BASE_URL}/#{format.to_s.upcase}/#{rank}#{size}.#{format}", alt: rank)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def officer_flag_for_organization(jobcode)
|
|
24
|
+
rank = RANKS[jobcode] || RANK_PATTERNS.find { |p, _r| jobcode =~ p }[1]
|
|
25
|
+
officer_flag(rank, format: :png, size: 500)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def officer_flag_for_submission(submission)
|
|
29
|
+
if submission.squadron.present?
|
|
30
|
+
officer_flag('CDR', format: :png, size: 500)
|
|
31
|
+
elsif submission.district.present?
|
|
32
|
+
officer_flag('DC', format: :png, size: 500)
|
|
33
|
+
elsif submission.organization == '11000'
|
|
34
|
+
officer_flag('CC', format: :png, size: 500)
|
|
35
|
+
elsif submission.organization =~ /1\d000/
|
|
36
|
+
officer_flag('VC', format: :png, size: 500)
|
|
37
|
+
else
|
|
38
|
+
officer_flag('RC', format: :png, size: 500)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def signal_flags(text, format: :svg)
|
|
43
|
+
safe_join(text.scan(/[A-Za-z0-9\s]/).map(&:downcase).split { |s| s =~ /\s/ }.map do |word|
|
|
44
|
+
content_tag(:div, class: 'word') do
|
|
45
|
+
safe_join(word.map do |letter|
|
|
46
|
+
image_tag("#{SIGNAL_BASE_URL}/#{format.to_s.upcase}/short/#{letter}.#{format}", alt: letter)
|
|
47
|
+
end)
|
|
48
|
+
end
|
|
49
|
+
end)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def signal_flag(flag, dir: 'short', alt: nil, format: :svg)
|
|
53
|
+
image_tag(
|
|
54
|
+
"#{SIGNAL_BASE_URL}/#{format.to_s.upcase}/#{dir}/#{flag}.#{format}",
|
|
55
|
+
alt: alt || flag
|
|
56
|
+
)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Usps::Support::Helpers
|
|
4
|
+
# Get git identifying information
|
|
5
|
+
#
|
|
6
|
+
module GitHelper
|
|
7
|
+
def current_git_tag
|
|
8
|
+
prod_current_tag if Rails.env.production?
|
|
9
|
+
@current_git_tag = 'TESTING' if Rails.env.test?
|
|
10
|
+
dev_current_tag if Rails.env.development?
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# :nocov:
|
|
14
|
+
def prod_current_tag
|
|
15
|
+
@current_git_tag = Rails.root.join('TAG').read.chomp
|
|
16
|
+
@current_branch = Rails.root.join('BRANCH').read.chomp
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def dev_current_tag
|
|
20
|
+
@current_git_tag = `git describe --tags --abbrev=0`.chomp
|
|
21
|
+
@current_branch = `git branch --show-current`.chomp
|
|
22
|
+
end
|
|
23
|
+
# :nocov:
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Usps::Support::Helpers
|
|
4
|
+
# Render React components
|
|
5
|
+
#
|
|
6
|
+
module ReactHelper
|
|
7
|
+
def react_component(component_name, props = {})
|
|
8
|
+
content_tag(:div, '', data: { 'react-component' => component_name, props: props.to_json })
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def action_button(props)
|
|
12
|
+
react_component('ActionButton', props)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Usps::Support::Helpers
|
|
4
|
+
# Build CSS for mailers
|
|
5
|
+
#
|
|
6
|
+
module ScssHelper
|
|
7
|
+
def render_scss(file)
|
|
8
|
+
text = Rails.root.join("app/views/layouts/scss/#{file}.scss").read
|
|
9
|
+
|
|
10
|
+
raw sass_engine(text).render
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def sass_engine(text)
|
|
14
|
+
view_context = controller.view_context
|
|
15
|
+
|
|
16
|
+
SassC::Engine.new(
|
|
17
|
+
text,
|
|
18
|
+
syntax: :scss, cache: false, read_cache: false, style: :compressed,
|
|
19
|
+
sprockets: {
|
|
20
|
+
context: view_context,
|
|
21
|
+
environment: view_context.assets_environment
|
|
22
|
+
}
|
|
23
|
+
)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Shared Rails helpers
|
|
4
|
+
#
|
|
5
|
+
module Usps::Support::Helpers; end
|
|
6
|
+
|
|
7
|
+
require_relative 'helpers/badges_helper'
|
|
8
|
+
require_relative 'helpers/flags_helper'
|
|
9
|
+
require_relative 'helpers/git_helper'
|
|
10
|
+
require_relative 'helpers/react_helper'
|
|
11
|
+
require_relative 'helpers/scss_helper'
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
inherit_from: ../../../../.rubocop.yml
|
|
2
|
+
|
|
3
|
+
Metrics/ClassLength:
|
|
4
|
+
Enabled: true
|
|
5
|
+
Max: 250
|
|
6
|
+
Metrics/ModuleLength:
|
|
7
|
+
Max: 250
|
|
8
|
+
Metrics/CyclomaticComplexity:
|
|
9
|
+
Enabled: true
|
|
10
|
+
Max: 15
|
|
11
|
+
Metrics/PerceivedComplexity:
|
|
12
|
+
Max: 15
|
|
13
|
+
Metrics/AbcSize:
|
|
14
|
+
Enabled: true
|
|
15
|
+
Max: 25
|
|
16
|
+
Metrics/MethodLength:
|
|
17
|
+
Enabled: true
|
|
18
|
+
Max: 25
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Usps::Support::Models
|
|
4
|
+
# DynamoDB API
|
|
5
|
+
#
|
|
6
|
+
class DynamoDb
|
|
7
|
+
REGION = 'us-east-1'
|
|
8
|
+
|
|
9
|
+
attr_accessor :table
|
|
10
|
+
|
|
11
|
+
def initialize(table)
|
|
12
|
+
@table = table
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def scan
|
|
16
|
+
[].tap do |results|
|
|
17
|
+
last_evaluated_key = nil
|
|
18
|
+
loop do
|
|
19
|
+
response = client.scan(table_name: table, exclusive_start_key: last_evaluated_key)
|
|
20
|
+
results.concat(response.items)
|
|
21
|
+
break unless (last_evaluated_key = response.last_evaluated_key)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
results.sort_by! do |result|
|
|
25
|
+
sort_keys.map { result[it] }
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def query(options)
|
|
31
|
+
raise ArgumentError, 'Required: {key}: "value"' unless options.keys.size == 1
|
|
32
|
+
|
|
33
|
+
key = options.keys.first
|
|
34
|
+
value = options[key]
|
|
35
|
+
|
|
36
|
+
client.query(
|
|
37
|
+
table_name: table,
|
|
38
|
+
key_condition_expression: "#{key} = :key",
|
|
39
|
+
expression_attribute_values: { ':key' => value },
|
|
40
|
+
scan_index_forward: true
|
|
41
|
+
).items
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def table_metadata
|
|
45
|
+
client.describe_table(table_name: table).table
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def sort_keys
|
|
49
|
+
table_metadata.key_schema.select { it.key_type == 'RANGE' }.map(&:attribute_name)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
private
|
|
53
|
+
|
|
54
|
+
def client
|
|
55
|
+
@client ||= Aws::DynamoDB::Client.new(region: REGION)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Usps::Support::Models
|
|
4
|
+
# GitHub API
|
|
5
|
+
#
|
|
6
|
+
module GitHub
|
|
7
|
+
ORG = 'unitedstatespowersquadrons'
|
|
8
|
+
|
|
9
|
+
class << self
|
|
10
|
+
def check_suites(repo, branch)
|
|
11
|
+
client.check_suites_for_ref("#{ORG}/#{repo}", branch).check_suites
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def fetch_head_commit(repo, branch)
|
|
15
|
+
sha = client.ref("#{ORG}/#{repo}", "heads/#{branch}").object.sha
|
|
16
|
+
client.commit("#{ORG}/#{repo}", sha).commit
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def latest_tag(repo, include_prereleases: false)
|
|
20
|
+
client
|
|
21
|
+
.tags("#{ORG}/#{repo}")
|
|
22
|
+
.pluck(:name)
|
|
23
|
+
.grep(/^v\d+\.\d+\.\d(?:-[\w\-.]+)?/)
|
|
24
|
+
.index_with { Gem::Version.new(it.delete('v')) }
|
|
25
|
+
.reject { |_, gv| gv.prerelease? unless include_prereleases }
|
|
26
|
+
.max_by { |_, gv| gv }
|
|
27
|
+
.first
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def expired? = expires_at <= Time.zone.now
|
|
31
|
+
def expires_at = @auth[:expires_at]
|
|
32
|
+
def permissions = @auth[:permissions]
|
|
33
|
+
def repository_selection = @auth[:repository_selection]
|
|
34
|
+
|
|
35
|
+
private
|
|
36
|
+
|
|
37
|
+
def client
|
|
38
|
+
return @client if @client && !expired?
|
|
39
|
+
|
|
40
|
+
payload = {
|
|
41
|
+
iat: Time.now.to_i - 60,
|
|
42
|
+
exp: Time.now.to_i + (10 * 60),
|
|
43
|
+
iss: ENV.fetch('GITHUB_CLIENT_ID')
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private_key = OpenSSL::PKey::RSA.new(Rails.root.join('config/github.pem').read)
|
|
47
|
+
jwt = JWT.encode(payload, private_key, 'RS256')
|
|
48
|
+
app_client = Octokit::Client.new(bearer_token: jwt)
|
|
49
|
+
|
|
50
|
+
auth = app_client.create_app_installation_access_token(ENV['GITHUB_INSTALLATION_ID'].to_i)
|
|
51
|
+
@auth = auth.to_h.except(:token)
|
|
52
|
+
@client = Octokit::Client.new(access_token: auth[:token])
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
data/lib/usps/support.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: usps-support
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Julian Fiander
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: sassc-rails
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '0'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '0'
|
|
26
|
+
description: Shared support for USPS Rails applications
|
|
27
|
+
email:
|
|
28
|
+
- jsfiander@gmail.com
|
|
29
|
+
executables: []
|
|
30
|
+
extensions: []
|
|
31
|
+
extra_rdoc_files: []
|
|
32
|
+
files:
|
|
33
|
+
- ".ruby-version"
|
|
34
|
+
- Gemfile.lock
|
|
35
|
+
- Rakefile
|
|
36
|
+
- Readme.md
|
|
37
|
+
- lib/usps/support.rb
|
|
38
|
+
- lib/usps/support/helpers.rb
|
|
39
|
+
- lib/usps/support/helpers/.rubocop.yml
|
|
40
|
+
- lib/usps/support/helpers/badges_helper.rb
|
|
41
|
+
- lib/usps/support/helpers/flags_helper.rb
|
|
42
|
+
- lib/usps/support/helpers/git_helper.rb
|
|
43
|
+
- lib/usps/support/helpers/react_helper.rb
|
|
44
|
+
- lib/usps/support/helpers/scss_helper.rb
|
|
45
|
+
- lib/usps/support/models.rb
|
|
46
|
+
- lib/usps/support/models/.rubocop.yml
|
|
47
|
+
- lib/usps/support/models/dynamo_db.rb
|
|
48
|
+
- lib/usps/support/models/git_hub.rb
|
|
49
|
+
- lib/usps/support/version.rb
|
|
50
|
+
- sig/usps/support.rbs
|
|
51
|
+
homepage: https://github.com/unitedstatespowersquadrons/usps-rails
|
|
52
|
+
licenses: []
|
|
53
|
+
metadata:
|
|
54
|
+
homepage_uri: https://github.com/unitedstatespowersquadrons/usps-rails
|
|
55
|
+
rubygems_mfa_required: 'true'
|
|
56
|
+
rdoc_options: []
|
|
57
|
+
require_paths:
|
|
58
|
+
- lib
|
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
60
|
+
requirements:
|
|
61
|
+
- - ">="
|
|
62
|
+
- !ruby/object:Gem::Version
|
|
63
|
+
version: 3.4.0
|
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
69
|
+
requirements: []
|
|
70
|
+
rubygems_version: 3.7.2
|
|
71
|
+
specification_version: 4
|
|
72
|
+
summary: USPS Rails Support
|
|
73
|
+
test_files: []
|