rack_middleware_metrics 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +60 -0
- data/.rspec +1 -0
- data/.rubocop-performance.yml +3 -0
- data/.rubocop-rspec.yml +72 -0
- data/.rubocop.yml +53 -0
- data/.solargraph.yml +15 -0
- data/.travis.yml +19 -0
- data/.~lock.GIST_API.odt# +1 -0
- data/Cargo.lock +47 -0
- data/Cargo.toml +14 -0
- data/Gemfile +11 -0
- data/LICENSE.txt +21 -0
- data/README.md +54 -0
- data/Rakefile +14 -0
- data/bin/bundle +105 -0
- data/bin/console +14 -0
- data/bin/helix +29 -0
- data/bin/htmldiff +29 -0
- data/bin/ldiff +29 -0
- data/bin/maruku +29 -0
- data/bin/marutex +29 -0
- data/bin/nokogiri +29 -0
- data/bin/rackup +29 -0
- data/bin/rake +29 -0
- data/bin/reverse_markdown +29 -0
- data/bin/rspec +29 -0
- data/bin/rubocop +29 -0
- data/bin/ruby-parse +29 -0
- data/bin/ruby-rewrite +29 -0
- data/bin/setup +8 -0
- data/bin/solargraph +29 -0
- data/bin/thin +29 -0
- data/bin/thor +29 -0
- data/bin/tilt +29 -0
- data/bin/yard +29 -0
- data/bin/yardoc +29 -0
- data/bin/yri +29 -0
- data/example/.keep +0 -0
- data/example/thin_rack_app.rb +23 -0
- data/lib/md5_gen.rb +25 -0
- data/lib/md5_ruby_ext.rb +10 -0
- data/lib/rack_middleware_metrics.rb +11 -0
- data/lib/rack_middleware_metrics/railtie.rb +14 -0
- data/lib/rack_middleware_metrics/reporter.rb +54 -0
- data/lib/rack_middleware_metrics/version.rb +3 -0
- data/lib/tasks/helix_runtime.rake +6 -0
- data/rack_middleware_metrics.gemspec +32 -0
- data/src/lib.rs +14 -0
- metadata +136 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 98990077c946511fb1f4b12324b71802b2b7d0a5541c598e1f4396698f545fa3
|
4
|
+
data.tar.gz: 9f209425500a239563c966cf4ceaaf29d5d831d6c5df2e6f4dfcc559ef189b56
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e00125579f4516e61a798ff8f69b04446ea0e2803a3953ea5bdf83fb90638c87f6edc7095e416a39e7ccc79272007d2b019422cecef1653865ac2e14b1916632
|
7
|
+
data.tar.gz: a7c14ed40b52f708e33ea7538c1a01c40e86b096d4c3dbd2dbb1968ce5182fc561c6bfb5cc0295984e254c0f3e1148dfbf5e2fd637ffc973ab8d28dd94289588
|
data/.gitignore
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
# Ignore Byebug command history file.
|
17
|
+
.byebug_history
|
18
|
+
|
19
|
+
## Specific to RubyMotion:
|
20
|
+
.dat*
|
21
|
+
.repl_history
|
22
|
+
build/
|
23
|
+
*.bridgesupport
|
24
|
+
build-iPhoneOS/
|
25
|
+
build-iPhoneSimulator/
|
26
|
+
|
27
|
+
## Specific to RubyMotion (use of CocoaPods):
|
28
|
+
#
|
29
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
30
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
31
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
32
|
+
#
|
33
|
+
# vendor/Pods/
|
34
|
+
|
35
|
+
## Documentation cache and generated files:
|
36
|
+
/.yardoc/
|
37
|
+
/_yardoc/
|
38
|
+
/doc/
|
39
|
+
/rdoc/
|
40
|
+
|
41
|
+
## Environment normalization:
|
42
|
+
.bundle/
|
43
|
+
vendor
|
44
|
+
lib/bundler/man/
|
45
|
+
|
46
|
+
# for a library or gem, you might want to ignore these files since the code is
|
47
|
+
# intended to run in multiple environments; otherwise, check them in:
|
48
|
+
Gemfile.lock
|
49
|
+
.ruby-version
|
50
|
+
.ruby-gemset
|
51
|
+
|
52
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
53
|
+
.rvmrc
|
54
|
+
|
55
|
+
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
|
56
|
+
# .rubocop-https?--*
|
57
|
+
|
58
|
+
*.csv
|
59
|
+
target
|
60
|
+
lib/md5_ruby_ext
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/.rubocop-rspec.yml
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
#--------1---------2---------3---------4---------5---------6---------7---------8---------9---------0
|
2
|
+
require:
|
3
|
+
- rubocop-rspec
|
4
|
+
# The idea is to bring this file in line with the default configuration:
|
5
|
+
# https://github.com/rubocop-hq/rubocop-rspec/blob/master/config/default.yml.
|
6
|
+
# We're not quite at a point to do that yet.
|
7
|
+
AllCops:
|
8
|
+
TargetRubyVersion: 2.5
|
9
|
+
RSpec/AnyInstance:
|
10
|
+
Enabled: false
|
11
|
+
RSpec/ContextWording:
|
12
|
+
Prefixes:
|
13
|
+
- and
|
14
|
+
- before
|
15
|
+
- but
|
16
|
+
- can
|
17
|
+
- for
|
18
|
+
- in
|
19
|
+
- is
|
20
|
+
- such
|
21
|
+
- that
|
22
|
+
- when # default
|
23
|
+
- which
|
24
|
+
- while
|
25
|
+
- will
|
26
|
+
- with # default
|
27
|
+
- without # default
|
28
|
+
RSpec/DescribeClass:
|
29
|
+
Exclude:
|
30
|
+
- spec/contrast/core_extensions/assess/rules/*_spec.rb # assess rules don't have concrete classes
|
31
|
+
- spec/contrast/rails_extensions/**/*_spec.rb
|
32
|
+
- spec/contrast/sinatra_extensions/**/*_spec.rb
|
33
|
+
RSpec/ExampleLength:
|
34
|
+
Enabled: false
|
35
|
+
RSpec/FilePath:
|
36
|
+
CustomTransform:
|
37
|
+
Activity: inventory_activity
|
38
|
+
AppContext: app_context
|
39
|
+
ApplicationSettings: application_settings
|
40
|
+
CmdInjection: cmd_injection
|
41
|
+
ContrastService: contrast_service
|
42
|
+
EntityWrapper: entity_wrapper
|
43
|
+
PreShift: preshift
|
44
|
+
TraceEvent: trace_event
|
45
|
+
Exclude:
|
46
|
+
- spec/contrast/core_extensions/assess/freeze_spec.rb
|
47
|
+
- spec/contrast/core_extensions/postgresql_spec.rb
|
48
|
+
- spec/contrast/core_extensions/protect/sqlite3_spec.rb
|
49
|
+
- spec/contrast/rack_extensions/*.rb
|
50
|
+
- spec/contrast/sinatra_extensions/sinatra_base_spec.rb
|
51
|
+
RSpec/MessageSpies:
|
52
|
+
Enabled: false
|
53
|
+
RSpec/MultipleExpectations:
|
54
|
+
Max: 22
|
55
|
+
RSpec/NestedGroups:
|
56
|
+
Max: 5 # Target around 3 or 4. Drop as we have more spec helpers. -ajm
|
57
|
+
RSpec/VerifiedDoubles:
|
58
|
+
Enabled: false
|
59
|
+
#
|
60
|
+
# ...
|
61
|
+
#
|
62
|
+
# And to then enable the default disabled cops.
|
63
|
+
# These cops are off by default, but should be audited to see if they're worth
|
64
|
+
# enabling as they're recommended, but hard to implement or controversial.
|
65
|
+
RSpec/DescribedClassModuleWrapping:
|
66
|
+
Enabled: false
|
67
|
+
RSpec/Dialect:
|
68
|
+
Enabled: false
|
69
|
+
RSpec/MessageExpectation:
|
70
|
+
Enabled: false
|
71
|
+
RSpec/Pending:
|
72
|
+
Enabled: false
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
#--------1---------2---------3---------4---------5---------6---------7---------8---------9---------0
|
2
|
+
# The idea is to bring this file in line with the default configuration:
|
3
|
+
# https://github.com/rubocop-hq/rubocop/blob/master/config/default.yml
|
4
|
+
# We're not quite at a point to do that yet.
|
5
|
+
AllCops:
|
6
|
+
EnabledByDefault: true
|
7
|
+
NewCops: enable
|
8
|
+
TargetRubyVersion: 2.5
|
9
|
+
Bundler/DuplicatedGem:
|
10
|
+
Enabled: false
|
11
|
+
Bundler/GemComment:
|
12
|
+
Enabled: false
|
13
|
+
Layout/DotPosition:
|
14
|
+
EnforcedStyle: trailing
|
15
|
+
Layout/FirstArgumentIndentation:
|
16
|
+
IndentationWidth: 4
|
17
|
+
Layout/FirstHashElementIndentation:
|
18
|
+
IndentationWidth: 4
|
19
|
+
Layout/FirstParameterIndentation:
|
20
|
+
IndentationWidth: 4
|
21
|
+
Layout/LineLength:
|
22
|
+
IgnoredPatterns:
|
23
|
+
- '^\s*# http' # allow URLs, standalone, in comments
|
24
|
+
Layout/MultilineMethodCallBraceLayout:
|
25
|
+
EnforcedStyle: same_line
|
26
|
+
Layout/MultilineMethodCallIndentation:
|
27
|
+
EnforcedStyle: indented
|
28
|
+
IndentationWidth: 4
|
29
|
+
Layout/MultilineMethodDefinitionBraceLayout:
|
30
|
+
EnforcedStyle: same_line
|
31
|
+
Layout/MultilineOperationIndentation:
|
32
|
+
EnforcedStyle: indented
|
33
|
+
IndentationWidth: 4
|
34
|
+
Layout/SpaceInsideStringInterpolation:
|
35
|
+
EnforcedStyle: space
|
36
|
+
Lint/ConstantResolution:
|
37
|
+
Enabled: false
|
38
|
+
Naming/MemoizedInstanceVariableName:
|
39
|
+
EnforcedStyleForLeadingUnderscores: required
|
40
|
+
Style/Alias:
|
41
|
+
EnforcedStyle: prefer_alias_method
|
42
|
+
Style/DisableCopsWithinSourceCodeDirective:
|
43
|
+
Enabled: false
|
44
|
+
Style/DoubleNegation: # team prefers !!var over !var.nil? syntax, so we are leaving this cop off
|
45
|
+
Enabled: false
|
46
|
+
Style/MethodDefParentheses:
|
47
|
+
EnforcedStyle: require_no_parentheses_except_multiline
|
48
|
+
Style/Copyright:
|
49
|
+
Enabled: false
|
50
|
+
Style/DocumentationMethod:
|
51
|
+
Enabled: false
|
52
|
+
Style/MissingElse:
|
53
|
+
Enabled: false
|
data/.solargraph.yml
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
language: ruby
|
2
|
+
cache: bundler
|
3
|
+
rvm:
|
4
|
+
- 2.5
|
5
|
+
- 2.6
|
6
|
+
- 2.7
|
7
|
+
before_install:
|
8
|
+
- curl https://sh.rustup.rs -sSf | sh -s -- -y
|
9
|
+
- source $HOME/.cargo/env
|
10
|
+
deploy:
|
11
|
+
provider: rubygems
|
12
|
+
api_key:
|
13
|
+
secure: cJgoY38KR4cqoVCbNsQaXbqKMbXCSh/JOxHXpKIodP0IzdqBwO2+JyuUnIKW9oq4CMlj7V8bNUMmY3Bce0NZoSFDc+A1SbogWFDn7BHcHjU5zgC0XiPcY04u3/oK2iI6zmZN+ANg3JWqTKcF1pBN/y5u8S8Q5S1ZWsnwg7/VzDZseDRLJVR7r8g83Bnus7oD+nGU8Cibi7I4rJNjfp3k9flKSzysm9EMs+GBuw52ESUyfUpqoMWVlz4KljWWUjgV3dX4OV6bH/UlVHg7I0hcNUkQepweNydiT6J3eQmDLN2msYZs/os8ivZPrsMY4V1SZYtn8iXPzeaW7keCJNtcjh4I9WFf00NE/R0/IWBl6fPOqTfddxgBd7lst+3N47R/pGJBVayRhskYTUPmIBymo065oGoVQiPUKQ3F5cz6OCjuW40GSyxmW5AL+hKQWPqBJossv5RgXP/pYPWW1pluwdCYRbROYfH+JrxWuU5VQJZ49Q7otK+/KEamJwbFg5R115aJS3rrQ4cTmH5uTwvDkQfCJ2VDVvGy5zzLGl96ewY+uOd7HoykjyBUkEe52V01B+MublXrzgXmd5VFcpFPXF6aQ9jxrb6SD5YOXjYneZd20omeOzzKAbFPvuFyYL5dktf75pFqis13z5CleLs7/MupgT8BFuC7cxuZk+tglLQ=
|
14
|
+
gem: rack_middleware_metrics
|
15
|
+
on:
|
16
|
+
tags: true
|
17
|
+
repo: reedjosh/RackMiddlewareMetrics
|
18
|
+
branch: main
|
19
|
+
skip_cleanup: 'true'
|
@@ -0,0 +1 @@
|
|
1
|
+
,jreed,jayr.localdomain,14.07.2017 13:50,file:///home/jreed/.config/libreoffice/4;
|
data/Cargo.lock
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# This file is automatically @generated by Cargo.
|
2
|
+
# It is not intended for manual editing.
|
3
|
+
[[package]]
|
4
|
+
name = "cstr-macro"
|
5
|
+
version = "0.1.0"
|
6
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
7
|
+
checksum = "db53fddba18cdd35477a7213a3ef6acfbfa333c31b42ce019e544c4a1420a06f"
|
8
|
+
|
9
|
+
[[package]]
|
10
|
+
name = "helix"
|
11
|
+
version = "0.7.5"
|
12
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
13
|
+
checksum = "49a017e3e798ad9386e0a0584e66fd6c04a80ccc1242eb8f689c62ce6f408240"
|
14
|
+
dependencies = [
|
15
|
+
"cstr-macro",
|
16
|
+
"libc",
|
17
|
+
"libcruby-sys",
|
18
|
+
]
|
19
|
+
|
20
|
+
[[package]]
|
21
|
+
name = "libc"
|
22
|
+
version = "0.2.79"
|
23
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
24
|
+
checksum = "2448f6066e80e3bfc792e9c98bf705b4b0fc6e8ef5b43e5889aff0eaa9c58743"
|
25
|
+
|
26
|
+
[[package]]
|
27
|
+
name = "libcruby-sys"
|
28
|
+
version = "0.7.5"
|
29
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
30
|
+
checksum = "fef6028cdce0c8d55676fd1d66bb810facef8cade0dd71d28511d375e84da4c0"
|
31
|
+
dependencies = [
|
32
|
+
"libc",
|
33
|
+
]
|
34
|
+
|
35
|
+
[[package]]
|
36
|
+
name = "md5"
|
37
|
+
version = "0.7.0"
|
38
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
39
|
+
checksum = "490cc448043f947bae3cbee9c203358d62dbee0db12107a74be5c30ccfd09771"
|
40
|
+
|
41
|
+
[[package]]
|
42
|
+
name = "md5_ruby_ext"
|
43
|
+
version = "0.1.0"
|
44
|
+
dependencies = [
|
45
|
+
"helix",
|
46
|
+
"md5",
|
47
|
+
]
|
data/Cargo.toml
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
[package]
|
2
|
+
name = "md5_ruby_ext"
|
3
|
+
version = "0.1.0"
|
4
|
+
authors = ["Reed, Joshua <joshua.reed@intel.com>"]
|
5
|
+
edition = "2018"
|
6
|
+
|
7
|
+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
8
|
+
[lib]
|
9
|
+
crate-type = ["cdylib"]
|
10
|
+
|
11
|
+
|
12
|
+
[dependencies]
|
13
|
+
md5 = "0.7.0"
|
14
|
+
helix = "*"
|
data/Gemfile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in RackMiddlewareMetrics.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
group :development, :test do
|
7
|
+
gem "rspec", "~> 3.9"
|
8
|
+
gem 'solargraph', '~> 0.39.12'
|
9
|
+
gem "rubocop", "~> 0.93.1"
|
10
|
+
gem "thin", "~> 1.7"
|
11
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 reedjosh
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# Metrics Reporter
|
2
|
+
A minimalist Application Performance Monitoring (APM) library for Ruby on Rails.
|
3
|
+
|
4
|
+
[![Build Status](https://travis-ci.com/reedjosh/RackMiddlewareMetrics.svg?branch=main)](https://travis-ci.com/reedjosh/RackMiddlewareMetrics)
|
5
|
+
|
6
|
+
Reports:
|
7
|
+
- The time that the request enters the middleware.
|
8
|
+
- The time that it leaves the middleware.
|
9
|
+
- Request path
|
10
|
+
- The request's parameter list.
|
11
|
+
- MD5 hash value of the rendered output.
|
12
|
+
- Current thread and process ids.
|
13
|
+
|
14
|
+
Appends to a CSV file.
|
15
|
+
|
16
|
+
The location and name of the file are configurable by the user.
|
17
|
+
|
18
|
+
Adds itself to the hosting Ruby on Rails application using Railties AND the agent
|
19
|
+
|
20
|
+
Does MD5 calculation in Rust.
|
21
|
+
|
22
|
+
Getting Started
|
23
|
+
|
24
|
+
|
25
|
+
## Etc... Notes
|
26
|
+
TODO: Add the Gem to an open source Ruby on Rails project (RedMine, Discourse, etc) and generate
|
27
|
+
a performance metrics CSV file.
|
28
|
+
|
29
|
+
TODO: The Rack middleware should be implemented as a Railtie
|
30
|
+
|
31
|
+
The middleware should generate a CSV file with the following fields:
|
32
|
+
- Request Time: the timestamp when the request enters the middleware
|
33
|
+
- Response Time: the timestamp when the request leaves the middleware
|
34
|
+
- Elapsed Time: the time betwen request and response
|
35
|
+
- Path: the URI of the request
|
36
|
+
- Params: a semi-colon delimited list of GET parameters
|
37
|
+
- MD5: the hashed value of the response body
|
38
|
+
- Process ID: the process ID of the current request
|
39
|
+
- Thread ID: the thread ID of the current request
|
40
|
+
|
41
|
+
Done: The filename and path of the generated CSV file should be configurable by the user of the Gem
|
42
|
+
Almost Done: generate the MD5 hash in Rust using Helix
|
43
|
+
Flesh out further: Write unit tests in RSpec.
|
44
|
+
Done: Add Travis CI.
|
45
|
+
Partially: Write a README that explains what you built and how to use it.
|
46
|
+
|
47
|
+
Goals:
|
48
|
+
- Write idiomatic and well-tested ruby code in a gem.
|
49
|
+
- Make sharable among many Ruby on Rails projects even with MD5 generation in rust.
|
50
|
+
- Use rvm/Travis to test many ruby versions.
|
51
|
+
|
52
|
+
### Build Gem via:
|
53
|
+
`gem build metrics_reporter.gemspec`
|
54
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Rakefile
|
4
|
+
require 'rake'
|
5
|
+
require 'rspec/core/rake_task'
|
6
|
+
import 'lib/tasks/helix_runtime.rake'
|
7
|
+
|
8
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
9
|
+
t.pattern = Dir.glob('spec/**/*_spec.rb')
|
10
|
+
t.rspec_opts = '--format documentation'
|
11
|
+
end
|
12
|
+
|
13
|
+
task :spec => :build
|
14
|
+
task default: :spec
|
data/bin/bundle
ADDED
@@ -0,0 +1,105 @@
|
|
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($0) == File.expand_path(__FILE__)
|
18
|
+
end
|
19
|
+
|
20
|
+
def env_var_version
|
21
|
+
ENV["BUNDLER_VERSION"]
|
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
|
+
bundler_version = nil
|
28
|
+
update_index = nil
|
29
|
+
ARGV.each_with_index do |a, i|
|
30
|
+
if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
|
31
|
+
bundler_version = a
|
32
|
+
end
|
33
|
+
next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
|
34
|
+
bundler_version = $1 || ">= 0.a"
|
35
|
+
update_index = i
|
36
|
+
end
|
37
|
+
bundler_version
|
38
|
+
end
|
39
|
+
|
40
|
+
def gemfile
|
41
|
+
gemfile = ENV["BUNDLE_GEMFILE"]
|
42
|
+
return gemfile if gemfile && !gemfile.empty?
|
43
|
+
|
44
|
+
File.expand_path("../../Gemfile", __FILE__)
|
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
|
+
lockfile_contents = File.read(lockfile)
|
59
|
+
return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
|
60
|
+
Regexp.last_match(1)
|
61
|
+
end
|
62
|
+
|
63
|
+
def bundler_version
|
64
|
+
@bundler_version ||= begin
|
65
|
+
env_var_version || cli_arg_version ||
|
66
|
+
lockfile_version || "#{Gem::Requirement.default}.a"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def load_bundler!
|
71
|
+
ENV["BUNDLE_GEMFILE"] ||= gemfile
|
72
|
+
|
73
|
+
# must dup string for RG < 1.8 compatibility
|
74
|
+
activate_bundler(bundler_version.dup)
|
75
|
+
end
|
76
|
+
|
77
|
+
def activate_bundler(bundler_version)
|
78
|
+
if Gem::Version.correct?(bundler_version) && Gem::Version.new(bundler_version).release < Gem::Version.new("2.0")
|
79
|
+
bundler_version = "< 2"
|
80
|
+
end
|
81
|
+
gem_error = activation_error_handling do
|
82
|
+
gem "bundler", bundler_version
|
83
|
+
end
|
84
|
+
return if gem_error.nil?
|
85
|
+
require_error = activation_error_handling do
|
86
|
+
require "bundler/version"
|
87
|
+
end
|
88
|
+
return if require_error.nil? && Gem::Requirement.new(bundler_version).satisfied_by?(Gem::Version.new(Bundler::VERSION))
|
89
|
+
warn "Activating bundler (#{bundler_version}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_version}'`"
|
90
|
+
exit 42
|
91
|
+
end
|
92
|
+
|
93
|
+
def activation_error_handling
|
94
|
+
yield
|
95
|
+
nil
|
96
|
+
rescue StandardError, LoadError => e
|
97
|
+
e
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
m.load_bundler!
|
102
|
+
|
103
|
+
if m.invoked_as_script?
|
104
|
+
load Gem.bin_path("bundler", "bundle")
|
105
|
+
end
|