readme-metrics 2.1.0 → 2.2.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.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +5 -0
  3. data/Gemfile +0 -1
  4. data/Gemfile.lock +24 -28
  5. data/Makefile +8 -2
  6. data/examples/metrics-rails/.gitattributes +7 -0
  7. data/examples/metrics-rails/.gitignore +20 -0
  8. data/examples/metrics-rails/.ruby-version +1 -0
  9. data/examples/metrics-rails/Gemfile +31 -0
  10. data/examples/metrics-rails/Gemfile.lock +189 -0
  11. data/examples/metrics-rails/README.md +38 -0
  12. data/examples/metrics-rails/Rakefile +6 -0
  13. data/examples/metrics-rails/app/controllers/application_controller.rb +2 -0
  14. data/examples/metrics-rails/app/controllers/metrics_controller.rb +34 -0
  15. data/examples/metrics-rails/app/models/application_record.rb +3 -0
  16. data/examples/metrics-rails/bin/bundle +116 -0
  17. data/examples/metrics-rails/bin/rails +4 -0
  18. data/examples/metrics-rails/bin/rake +4 -0
  19. data/examples/metrics-rails/bin/setup +33 -0
  20. data/examples/metrics-rails/config/application.rb +52 -0
  21. data/examples/metrics-rails/config/boot.rb +3 -0
  22. data/examples/metrics-rails/config/credentials.yml.enc +1 -0
  23. data/examples/metrics-rails/config/database.yml +25 -0
  24. data/examples/metrics-rails/config/environment.rb +5 -0
  25. data/examples/metrics-rails/config/environments/development.rb +56 -0
  26. data/examples/metrics-rails/config/environments/production.rb +68 -0
  27. data/examples/metrics-rails/config/environments/test.rb +50 -0
  28. data/examples/metrics-rails/config/initializers/cors.rb +16 -0
  29. data/examples/metrics-rails/config/initializers/filter_parameter_logging.rb +8 -0
  30. data/examples/metrics-rails/config/initializers/inflections.rb +16 -0
  31. data/examples/metrics-rails/config/locales/en.yml +33 -0
  32. data/examples/metrics-rails/config/puma.rb +43 -0
  33. data/examples/metrics-rails/config/routes.rb +5 -0
  34. data/examples/metrics-rails/config.ru +6 -0
  35. data/examples/metrics-rails/db/seeds.rb +7 -0
  36. data/examples/metrics-rails/public/robots.txt +1 -0
  37. data/lib/readme/errors.rb +1 -1
  38. data/lib/readme/har/collection.rb +3 -1
  39. data/lib/readme/har/serializer.rb +2 -2
  40. data/lib/readme/http_request.rb +7 -0
  41. data/lib/readme/http_response.rb +2 -2
  42. data/lib/readme/metrics/version.rb +2 -2
  43. data/lib/readme/metrics.rb +4 -4
  44. data/lib/readme/payload.rb +9 -3
  45. data/lib/readme/webhook.rb +42 -0
  46. data/readme-metrics.gemspec +0 -1
  47. metadata +38 -20
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: edf64efc0c1f3a7ba72f9f6d30aaebbd1caf64774258fe7dc69e343751358adb
4
- data.tar.gz: 36dd67292da34691382b5e3d9f7234275c9d14d4b133f8067ed22c2c0c861a02
3
+ metadata.gz: 7e56a6d3e2f6345dcc6b17a00b3de12223b5982bbf2ed1d88c78e7bc6155a4a1
4
+ data.tar.gz: 40223680001e31af74173f227cc0b56cd74ef5c0c81437328d2506a303482d2b
5
5
  SHA512:
6
- metadata.gz: 20c0d88a3e19f49a742ad52555b22f4cfa1d6fc34eeea60dbeb3410f97050d546ed9caa4d00ba5c518822296d9660a6e24c84c7232165724251cafd68dadab53
7
- data.tar.gz: c29cb1edddfd487996d345be984f402353a1940c4626aad107b4df33537800de0cab8ba41cf294d9a7bfaae5f221cf266012bea8d925ac8794e717b7059c3238
6
+ metadata.gz: afd8efd488128281a9d3e5c952b17a678e499e145aa6a448fdbe05a8b748bdcd36e2d01ff83195362931fd8158d884a8804b72e8f9d863237a729e632acab611
7
+ data.tar.gz: ebd3eb9482710916a7d969d6315147ab36526d53de86f12abc49892325d7405de2074d2744a89cb3160ea9b37050117335b1fc834900d74470d2301273865fda
data/.rubocop.yml CHANGED
@@ -9,6 +9,8 @@ AllCops:
9
9
  # https://docs.rubocop.org/rubocop/cops_layout.html
10
10
  Layout/LineLength:
11
11
  Max: 150
12
+ Exclude:
13
+ - examples/metrics-rails/bin/*
12
14
 
13
15
  # https://docs.rubocop.org/rubocop/cops_metrics.html
14
16
  Metrics/AbcSize:
@@ -65,3 +67,6 @@ Style/RescueStandardError:
65
67
  # and by only catching `StandardError` we'll miss out on something else and potentially take down
66
68
  # someones integration.
67
69
  Enabled: false
70
+
71
+ Gemspec/RequireMFA:
72
+ Enabled: false
data/Gemfile CHANGED
@@ -12,5 +12,4 @@ gem 'rspec', '~> 3.0'
12
12
  gem 'rubocop', require: false
13
13
  gem 'rubocop-performance', require: false
14
14
  gem 'rubocop-rspec', require: false
15
- gem 'uuid'
16
15
  gem 'webmock'
data/Gemfile.lock CHANGED
@@ -1,16 +1,15 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- readme-metrics (2.0.1)
4
+ readme-metrics (2.1.0)
5
5
  httparty (~> 0.18)
6
- uuid (~> 2.3.8)
7
6
 
8
7
  GEM
9
8
  remote: https://rubygems.org/
10
9
  specs:
11
10
  addressable (2.8.0)
12
11
  public_suffix (>= 2.0.2, < 5.0)
13
- ast (2.4.1)
12
+ ast (2.4.2)
14
13
  crack (0.4.3)
15
14
  safe_yaml (~> 1.0.0)
16
15
  diff-lcs (1.4.4)
@@ -18,25 +17,24 @@ GEM
18
17
  httparty (0.20.0)
19
18
  mime-types (~> 3.0)
20
19
  multi_xml (>= 0.5.2)
20
+ json (2.6.2)
21
21
  json-schema (2.8.1)
22
22
  addressable (>= 2.4)
23
- macaddr (1.7.2)
24
- systemu (~> 2.6.5)
25
23
  mime-types (3.4.1)
26
24
  mime-types-data (~> 3.2015)
27
25
  mime-types-data (3.2022.0105)
28
26
  multi_xml (0.6.0)
29
- parallel (1.19.2)
30
- parser (2.7.1.4)
27
+ parallel (1.22.1)
28
+ parser (3.1.2.1)
31
29
  ast (~> 2.4.1)
32
30
  public_suffix (4.0.6)
33
31
  rack (2.2.3.1)
34
32
  rack-test (1.1.0)
35
33
  rack (>= 1.0, < 3)
36
- rainbow (3.0.0)
34
+ rainbow (3.1.1)
37
35
  rake (12.3.3)
38
- regexp_parser (1.7.1)
39
- rexml (3.2.4)
36
+ regexp_parser (2.5.0)
37
+ rexml (3.2.5)
40
38
  rspec (3.9.0)
41
39
  rspec-core (~> 3.9.0)
42
40
  rspec-expectations (~> 3.9.0)
@@ -50,27 +48,26 @@ GEM
50
48
  diff-lcs (>= 1.2.0, < 2.0)
51
49
  rspec-support (~> 3.9.0)
52
50
  rspec-support (3.9.3)
53
- rubocop (0.85.1)
51
+ rubocop (1.36.0)
52
+ json (~> 2.3)
54
53
  parallel (~> 1.10)
55
- parser (>= 2.7.0.1)
54
+ parser (>= 3.1.2.1)
56
55
  rainbow (>= 2.2.2, < 4.0)
57
- regexp_parser (>= 1.7)
58
- rexml
59
- rubocop-ast (>= 0.0.3)
56
+ regexp_parser (>= 1.8, < 3.0)
57
+ rexml (>= 3.2.5, < 4.0)
58
+ rubocop-ast (>= 1.20.1, < 2.0)
60
59
  ruby-progressbar (~> 1.7)
61
- unicode-display_width (>= 1.4.0, < 2.0)
62
- rubocop-ast (0.3.0)
63
- parser (>= 2.7.1.4)
64
- rubocop-performance (1.7.1)
65
- rubocop (>= 0.82.0)
66
- rubocop-rspec (1.41.0)
67
- rubocop (>= 0.68.1)
68
- ruby-progressbar (1.10.1)
60
+ unicode-display_width (>= 1.4.0, < 3.0)
61
+ rubocop-ast (1.21.0)
62
+ parser (>= 3.1.1.0)
63
+ rubocop-performance (1.14.3)
64
+ rubocop (>= 1.7.0, < 2.0)
65
+ rubocop-ast (>= 0.4.0)
66
+ rubocop-rspec (2.12.1)
67
+ rubocop (~> 1.31)
68
+ ruby-progressbar (1.11.0)
69
69
  safe_yaml (1.0.5)
70
- systemu (2.6.5)
71
- unicode-display_width (1.7.0)
72
- uuid (2.3.9)
73
- macaddr (~> 1.0)
70
+ unicode-display_width (2.2.0)
74
71
  webmock (3.8.3)
75
72
  addressable (>= 2.3.6)
76
73
  crack (>= 0.3.2)
@@ -88,7 +85,6 @@ DEPENDENCIES
88
85
  rubocop
89
86
  rubocop-performance
90
87
  rubocop-rspec
91
- uuid
92
88
  webmock
93
89
 
94
90
  BUNDLED WITH
data/Makefile CHANGED
@@ -1,3 +1,6 @@
1
+ .PHONY: help test
2
+ API_KEY ?= $(shell bash -c 'read -p "ReadMe API Key: " api_key; echo $$api_key')
3
+
1
4
  install: ## Install all dependencies
2
5
  bundle
3
6
 
@@ -5,10 +8,13 @@ lint: ## Run code standard checks
5
8
  bundle exec rubocop
6
9
 
7
10
  lint-fix: ## Attempt to automatically fix any code standard violations
8
- bundle exec rubocop --auto-correct
11
+ bundle exec rubocop --autocorrect
12
+
13
+ serve-metrics-rails: ## Start the local Express server to test Metrics
14
+ README_API_KEY=$(API_KEY) ./examples/metrics-rails/bin/rails server
9
15
 
10
16
  test: ## Run unit tests
11
17
  rake spec
12
18
 
13
- help: ## Show this help
19
+ help: ## Display this help screen
14
20
  @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
@@ -0,0 +1,7 @@
1
+ # See https://git-scm.com/docs/gitattributes for more about git attribute files.
2
+
3
+ # Mark the database schema as having been generated.
4
+ db/schema.rb linguist-generated
5
+
6
+ # Mark any vendored files as having been vendored.
7
+ vendor/* linguist-vendored
@@ -0,0 +1,20 @@
1
+ # See https://help.github.com/articles/ignoring-files for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile '~/.gitignore_global'
6
+
7
+ # Ignore bundler config.
8
+ /.bundle
9
+
10
+ # Ignore the default SQLite database.
11
+ /db/*.sqlite3
12
+ /db/*.sqlite3-*
13
+
14
+ # Ignore all logfiles and tempfiles.
15
+ /log/*
16
+ /tmp/*
17
+
18
+
19
+ # Ignore master key for decrypting credentials and more.
20
+ /config/master.key
@@ -0,0 +1 @@
1
+ ruby-3.1.2
@@ -0,0 +1,31 @@
1
+ source 'https://rubygems.org'
2
+ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
3
+
4
+ ruby '3.1.2'
5
+
6
+ # Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
7
+ gem 'rails', '~> 7.0.3', '>= 7.0.3.1'
8
+
9
+ # Use sqlite3 as the database for Active Record
10
+ gem 'sqlite3', '~> 1.4'
11
+
12
+ # Use the Puma web server [https://github.com/puma/puma]
13
+ gem 'puma', '~> 5.0'
14
+
15
+ # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
16
+ gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]
17
+
18
+ # Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible
19
+ # gem "rack-cors"
20
+
21
+ group :development, :test do
22
+ # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
23
+ gem 'debug', platforms: %i[mri mingw x64_mingw]
24
+ end
25
+
26
+ group :development do
27
+ # Speed up commands on slow machines / big apps [https://github.com/rails/spring]
28
+ # gem "spring"
29
+ end
30
+
31
+ gem 'readme-metrics', path: '../../'
@@ -0,0 +1,189 @@
1
+ PATH
2
+ remote: ../..
3
+ specs:
4
+ readme-metrics (2.1.0)
5
+ httparty (~> 0.18)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actioncable (7.0.3.1)
11
+ actionpack (= 7.0.3.1)
12
+ activesupport (= 7.0.3.1)
13
+ nio4r (~> 2.0)
14
+ websocket-driver (>= 0.6.1)
15
+ actionmailbox (7.0.3.1)
16
+ actionpack (= 7.0.3.1)
17
+ activejob (= 7.0.3.1)
18
+ activerecord (= 7.0.3.1)
19
+ activestorage (= 7.0.3.1)
20
+ activesupport (= 7.0.3.1)
21
+ mail (>= 2.7.1)
22
+ net-imap
23
+ net-pop
24
+ net-smtp
25
+ actionmailer (7.0.3.1)
26
+ actionpack (= 7.0.3.1)
27
+ actionview (= 7.0.3.1)
28
+ activejob (= 7.0.3.1)
29
+ activesupport (= 7.0.3.1)
30
+ mail (~> 2.5, >= 2.5.4)
31
+ net-imap
32
+ net-pop
33
+ net-smtp
34
+ rails-dom-testing (~> 2.0)
35
+ actionpack (7.0.3.1)
36
+ actionview (= 7.0.3.1)
37
+ activesupport (= 7.0.3.1)
38
+ rack (~> 2.0, >= 2.2.0)
39
+ rack-test (>= 0.6.3)
40
+ rails-dom-testing (~> 2.0)
41
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
42
+ actiontext (7.0.3.1)
43
+ actionpack (= 7.0.3.1)
44
+ activerecord (= 7.0.3.1)
45
+ activestorage (= 7.0.3.1)
46
+ activesupport (= 7.0.3.1)
47
+ globalid (>= 0.6.0)
48
+ nokogiri (>= 1.8.5)
49
+ actionview (7.0.3.1)
50
+ activesupport (= 7.0.3.1)
51
+ builder (~> 3.1)
52
+ erubi (~> 1.4)
53
+ rails-dom-testing (~> 2.0)
54
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
55
+ activejob (7.0.3.1)
56
+ activesupport (= 7.0.3.1)
57
+ globalid (>= 0.3.6)
58
+ activemodel (7.0.3.1)
59
+ activesupport (= 7.0.3.1)
60
+ activerecord (7.0.3.1)
61
+ activemodel (= 7.0.3.1)
62
+ activesupport (= 7.0.3.1)
63
+ activestorage (7.0.3.1)
64
+ actionpack (= 7.0.3.1)
65
+ activejob (= 7.0.3.1)
66
+ activerecord (= 7.0.3.1)
67
+ activesupport (= 7.0.3.1)
68
+ marcel (~> 1.0)
69
+ mini_mime (>= 1.1.0)
70
+ activesupport (7.0.3.1)
71
+ concurrent-ruby (~> 1.0, >= 1.0.2)
72
+ i18n (>= 1.6, < 2)
73
+ minitest (>= 5.1)
74
+ tzinfo (~> 2.0)
75
+ builder (3.2.4)
76
+ concurrent-ruby (1.1.10)
77
+ crass (1.0.6)
78
+ debug (1.6.2)
79
+ irb (>= 1.3.6)
80
+ reline (>= 0.3.1)
81
+ digest (3.1.0)
82
+ erubi (1.11.0)
83
+ globalid (1.0.0)
84
+ activesupport (>= 5.0)
85
+ httparty (0.20.0)
86
+ mime-types (~> 3.0)
87
+ multi_xml (>= 0.5.2)
88
+ i18n (1.12.0)
89
+ concurrent-ruby (~> 1.0)
90
+ io-console (0.5.11)
91
+ irb (1.4.1)
92
+ reline (>= 0.3.0)
93
+ loofah (2.18.0)
94
+ crass (~> 1.0.2)
95
+ nokogiri (>= 1.5.9)
96
+ mail (2.7.1)
97
+ mini_mime (>= 0.1.1)
98
+ marcel (1.0.2)
99
+ method_source (1.0.0)
100
+ mime-types (3.4.1)
101
+ mime-types-data (~> 3.2015)
102
+ mime-types-data (3.2022.0105)
103
+ mini_mime (1.1.2)
104
+ mini_portile2 (2.8.0)
105
+ minitest (5.16.3)
106
+ multi_xml (0.6.0)
107
+ net-imap (0.2.3)
108
+ digest
109
+ net-protocol
110
+ strscan
111
+ net-pop (0.1.1)
112
+ digest
113
+ net-protocol
114
+ timeout
115
+ net-protocol (0.1.3)
116
+ timeout
117
+ net-smtp (0.3.1)
118
+ digest
119
+ net-protocol
120
+ timeout
121
+ nio4r (2.5.8)
122
+ nokogiri (1.13.8)
123
+ mini_portile2 (~> 2.8.0)
124
+ racc (~> 1.4)
125
+ nokogiri (1.13.8-arm64-darwin)
126
+ racc (~> 1.4)
127
+ puma (5.6.5)
128
+ nio4r (~> 2.0)
129
+ racc (1.6.0)
130
+ rack (2.2.4)
131
+ rack-test (2.0.2)
132
+ rack (>= 1.3)
133
+ rails (7.0.3.1)
134
+ actioncable (= 7.0.3.1)
135
+ actionmailbox (= 7.0.3.1)
136
+ actionmailer (= 7.0.3.1)
137
+ actionpack (= 7.0.3.1)
138
+ actiontext (= 7.0.3.1)
139
+ actionview (= 7.0.3.1)
140
+ activejob (= 7.0.3.1)
141
+ activemodel (= 7.0.3.1)
142
+ activerecord (= 7.0.3.1)
143
+ activestorage (= 7.0.3.1)
144
+ activesupport (= 7.0.3.1)
145
+ bundler (>= 1.15.0)
146
+ railties (= 7.0.3.1)
147
+ rails-dom-testing (2.0.3)
148
+ activesupport (>= 4.2.0)
149
+ nokogiri (>= 1.6)
150
+ rails-html-sanitizer (1.4.3)
151
+ loofah (~> 2.3)
152
+ railties (7.0.3.1)
153
+ actionpack (= 7.0.3.1)
154
+ activesupport (= 7.0.3.1)
155
+ method_source
156
+ rake (>= 12.2)
157
+ thor (~> 1.0)
158
+ zeitwerk (~> 2.5)
159
+ rake (13.0.6)
160
+ reline (0.3.1)
161
+ io-console (~> 0.5)
162
+ sqlite3 (1.4.4)
163
+ strscan (3.0.4)
164
+ thor (1.2.1)
165
+ timeout (0.3.0)
166
+ tzinfo (2.0.5)
167
+ concurrent-ruby (~> 1.0)
168
+ websocket-driver (0.7.5)
169
+ websocket-extensions (>= 0.1.0)
170
+ websocket-extensions (0.1.5)
171
+ zeitwerk (2.6.0)
172
+
173
+ PLATFORMS
174
+ arm64-darwin-21
175
+ ruby
176
+
177
+ DEPENDENCIES
178
+ debug
179
+ puma (~> 5.0)
180
+ rails (~> 7.0.3, >= 7.0.3.1)
181
+ readme-metrics!
182
+ sqlite3 (~> 1.4)
183
+ tzinfo-data
184
+
185
+ RUBY VERSION
186
+ ruby 3.1.2p20
187
+
188
+ BUNDLED WITH
189
+ 2.3.11
@@ -0,0 +1,38 @@
1
+ # ReadMe Metrics/Webhooks Rails Demo
2
+
3
+ ```sh
4
+ make install
5
+ ```
6
+
7
+ ## 📊 Metrics
8
+
9
+ ```sh
10
+ make serve-metrics-rails
11
+ ```
12
+
13
+ Access your test server to demo Metrics by making a cURL request:
14
+
15
+ ```sh
16
+ curl http://localhost:8000
17
+ ```
18
+
19
+ ## 📞 Webhooks
20
+
21
+ ```sh
22
+ make serve-metrics-rails
23
+ ```
24
+
25
+ We have to generate a valid HMAC to send through to the webhook, you can do that with the following shell commands:
26
+
27
+ ```sh
28
+ README_API_KEY=<Your ReadMe API Key here>
29
+ TIME=$(date +%s000)
30
+ UNSIGNED=$TIME.{\"email\":\"test@example.com\"}
31
+ HMAC=$(echo -n $UNSIGNED | openssl dgst -sha256 -hmac $README_API_KEY -hex)
32
+ SIGNATURE="t=$TIME,v0=$HMAC"
33
+
34
+ curl http://localhost:8000/webhook \
35
+ -H "readme-signature: $SIGNATURE" \
36
+ -H "content-type: application/json" \
37
+ -d '{"email":"test@example.com"}'
38
+ ```
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require_relative 'config/application'
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,2 @@
1
+ class ApplicationController < ActionController::API
2
+ end
@@ -0,0 +1,34 @@
1
+ require 'readme/webhook'
2
+
3
+ class MetricsController < ApplicationController
4
+ def index
5
+ render json: { message: 'hello world' }
6
+ end
7
+
8
+ def post
9
+ head :ok
10
+ end
11
+
12
+ def webhook
13
+ # Your ReadMe secret
14
+ secret = ENV.fetch('README_API_KEY', nil)
15
+ # Verify the request is legitimate and came from ReadMe
16
+ signature = request.headers['readme-signature']
17
+
18
+ begin
19
+ Readme::Webhook.verify(request.raw_post, signature, secret)
20
+ rescue Readme::MissingSignatureError, Readme::ExpiredSignatureError, Readme::InvalidSignatureError => e
21
+ # Handle invalid requests
22
+ render json: { error: e.message }, status: 401
23
+ return
24
+ end
25
+
26
+ # Fetch the user from the database and return their data for use with OpenAPI variables.
27
+ # current_user ||= User.find(session[:user_id]) if session[:user_id]
28
+ render json: {
29
+ # OAS Security variables
30
+ petstore_auth: 'default-key',
31
+ basic_auth: { user: 'user', pass: 'pass' }
32
+ }
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ class ApplicationRecord < ActiveRecord::Base
2
+ primary_abstract_class
3
+ end
@@ -0,0 +1,116 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'bundle' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require 'rubygems'
12
+
13
+ m = Module.new do
14
+ module_function
15
+
16
+ def invoked_as_script?
17
+ File.expand_path($PROGRAM_NAME) == File.expand_path(__FILE__)
18
+ end
19
+
20
+ def env_var_version
21
+ ENV.fetch('BUNDLER_VERSION', nil)
22
+ end
23
+
24
+ def cli_arg_version
25
+ return unless invoked_as_script? # don't want to hijack other binstubs
26
+ return unless 'update'.start_with?(ARGV.first || ' ') # must be running `bundle update`
27
+
28
+ bundler_version = nil
29
+ update_index = nil
30
+ ARGV.each_with_index do |a, i|
31
+ bundler_version = a if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
32
+ next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/o
33
+
34
+ bundler_version = Regexp.last_match(1)
35
+ update_index = i
36
+ end
37
+ bundler_version
38
+ end
39
+
40
+ def gemfile
41
+ gemfile = ENV.fetch('BUNDLE_GEMFILE', nil)
42
+ return gemfile if gemfile && !gemfile.empty?
43
+
44
+ File.expand_path('../Gemfile', __dir__)
45
+ end
46
+
47
+ def lockfile
48
+ lockfile =
49
+ case File.basename(gemfile)
50
+ when 'gems.rb' then gemfile.sub(/\.rb$/, gemfile)
51
+ else "#{gemfile}.lock"
52
+ end
53
+ File.expand_path(lockfile)
54
+ end
55
+
56
+ def lockfile_version
57
+ return unless File.file?(lockfile)
58
+
59
+ lockfile_contents = File.read(lockfile)
60
+ return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/o
61
+
62
+ Regexp.last_match(1)
63
+ end
64
+
65
+ def bundler_requirement
66
+ @bundler_requirement ||=
67
+ env_var_version || cli_arg_version ||
68
+ bundler_requirement_for(lockfile_version)
69
+ end
70
+
71
+ def bundler_requirement_for(version)
72
+ return "#{Gem::Requirement.default}.a" unless version
73
+
74
+ bundler_gem_version = Gem::Version.new(version)
75
+
76
+ requirement = bundler_gem_version.approximate_recommendation
77
+
78
+ return requirement unless Gem.rubygems_version < Gem::Version.new('2.7.0')
79
+
80
+ requirement += '.a' if bundler_gem_version.prerelease?
81
+
82
+ requirement
83
+ end
84
+
85
+ def load_bundler!
86
+ ENV['BUNDLE_GEMFILE'] ||= gemfile
87
+
88
+ activate_bundler
89
+ end
90
+
91
+ def activate_bundler
92
+ gem_error = activation_error_handling do
93
+ gem 'bundler', bundler_requirement
94
+ end
95
+ return if gem_error.nil?
96
+
97
+ require_error = activation_error_handling do
98
+ require 'bundler/version'
99
+ end
100
+ return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION))
101
+
102
+ warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`"
103
+ exit 42
104
+ end
105
+
106
+ def activation_error_handling
107
+ yield
108
+ nil
109
+ rescue StandardError, LoadError => e
110
+ e
111
+ end
112
+ end
113
+
114
+ m.load_bundler!
115
+
116
+ load Gem.bin_path('bundler', 'bundle') if m.invoked_as_script?
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../config/application', __dir__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+ require 'fileutils'
3
+
4
+ # path to your application root.
5
+ APP_ROOT = File.expand_path('..', __dir__)
6
+
7
+ def system!(*args)
8
+ system(*args) || abort("\n== Command #{args} failed ==")
9
+ end
10
+
11
+ FileUtils.chdir APP_ROOT do
12
+ # This script is a way to set up or update your development environment automatically.
13
+ # This script is idempotent, so that you can run it at any time and get an expectable outcome.
14
+ # Add necessary setup steps to this file.
15
+
16
+ puts '== Installing dependencies =='
17
+ system! 'gem install bundler --conservative'
18
+ system('bundle check') || system!('bundle install')
19
+
20
+ # puts "\n== Copying sample files =="
21
+ # unless File.exist?("config/database.yml")
22
+ # FileUtils.cp "config/database.yml.sample", "config/database.yml"
23
+ # end
24
+
25
+ puts "\n== Preparing database =="
26
+ system! 'bin/rails db:prepare'
27
+
28
+ puts "\n== Removing old logs and tempfiles =="
29
+ system! 'bin/rails log:clear tmp:clear'
30
+
31
+ puts "\n== Restarting application server =="
32
+ system! 'bin/rails restart'
33
+ end