rails_request 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ea92c0e89c072a3121f9b80007186a7dcfe5a376f958d836b73f989b6b4bae94
4
+ data.tar.gz: 64437012808d57ec7d1d52d1cd2fa26afa643b9bf7ca2a6ce965c3bcf5c31c77
5
+ SHA512:
6
+ metadata.gz: 58e5ae0422fb57d8b4d2d2eaf093dc5afd3d81185b59f353834bb8a69f6561b60268b12d5e63518ccd29ef316e9085d844e99fef15a3418bb02a41e5c15c97d8
7
+ data.tar.gz: 168cb5b94f6c981572f8623f0e52e914d9bc7276216ee590426c854cf4bce8535bbcf93f4aa235e26240d3843e0af640d0ef245e2288bc469c66b87444093b62
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,29 @@
1
+ Style/Documentation:
2
+ Enabled: false
3
+
4
+ Layout/EmptyLinesAroundAttributeAccessor:
5
+ Enabled: true
6
+ Layout/SpaceAroundMethodCallOperator:
7
+ Enabled: true
8
+ Lint/DeprecatedOpenSSLConstant:
9
+ Enabled: true
10
+ Lint/MixedRegexpCaptureTypes:
11
+ Enabled: true
12
+ Lint/RaiseException:
13
+ Enabled: true
14
+ Lint/StructNewOverride:
15
+ Enabled: true
16
+ Style/ExponentialNotation:
17
+ Enabled: true
18
+ Style/HashEachMethods:
19
+ Enabled: true
20
+ Style/HashTransformKeys:
21
+ Enabled: true
22
+ Style/HashTransformValues:
23
+ Enabled: true
24
+ Style/RedundantRegexpCharacterClass:
25
+ Enabled: true
26
+ Style/RedundantRegexpEscape:
27
+ Enabled: true
28
+ Style/SlicingWithRange:
29
+ Enabled: true
@@ -0,0 +1 @@
1
+ 2.7.1
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in rails_request.gemspec
6
+ gemspec
7
+
8
+ gem 'rake', '~> 12.0'
9
+ gem 'rspec', '~> 3.0'
@@ -0,0 +1,184 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rails_request (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ actioncable (6.0.3.2)
10
+ actionpack (= 6.0.3.2)
11
+ nio4r (~> 2.0)
12
+ websocket-driver (>= 0.6.1)
13
+ actionmailbox (6.0.3.2)
14
+ actionpack (= 6.0.3.2)
15
+ activejob (= 6.0.3.2)
16
+ activerecord (= 6.0.3.2)
17
+ activestorage (= 6.0.3.2)
18
+ activesupport (= 6.0.3.2)
19
+ mail (>= 2.7.1)
20
+ actionmailer (6.0.3.2)
21
+ actionpack (= 6.0.3.2)
22
+ actionview (= 6.0.3.2)
23
+ activejob (= 6.0.3.2)
24
+ mail (~> 2.5, >= 2.5.4)
25
+ rails-dom-testing (~> 2.0)
26
+ actionpack (6.0.3.2)
27
+ actionview (= 6.0.3.2)
28
+ activesupport (= 6.0.3.2)
29
+ rack (~> 2.0, >= 2.0.8)
30
+ rack-test (>= 0.6.3)
31
+ rails-dom-testing (~> 2.0)
32
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
33
+ actiontext (6.0.3.2)
34
+ actionpack (= 6.0.3.2)
35
+ activerecord (= 6.0.3.2)
36
+ activestorage (= 6.0.3.2)
37
+ activesupport (= 6.0.3.2)
38
+ nokogiri (>= 1.8.5)
39
+ actionview (6.0.3.2)
40
+ activesupport (= 6.0.3.2)
41
+ builder (~> 3.1)
42
+ erubi (~> 1.4)
43
+ rails-dom-testing (~> 2.0)
44
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
45
+ activejob (6.0.3.2)
46
+ activesupport (= 6.0.3.2)
47
+ globalid (>= 0.3.6)
48
+ activemodel (6.0.3.2)
49
+ activesupport (= 6.0.3.2)
50
+ activerecord (6.0.3.2)
51
+ activemodel (= 6.0.3.2)
52
+ activesupport (= 6.0.3.2)
53
+ activestorage (6.0.3.2)
54
+ actionpack (= 6.0.3.2)
55
+ activejob (= 6.0.3.2)
56
+ activerecord (= 6.0.3.2)
57
+ marcel (~> 0.3.1)
58
+ activesupport (6.0.3.2)
59
+ concurrent-ruby (~> 1.0, >= 1.0.2)
60
+ i18n (>= 0.7, < 2)
61
+ minitest (~> 5.1)
62
+ tzinfo (~> 1.1)
63
+ zeitwerk (~> 2.2, >= 2.2.2)
64
+ ast (2.4.1)
65
+ builder (3.2.4)
66
+ concurrent-ruby (1.1.6)
67
+ crass (1.0.6)
68
+ diff-lcs (1.3)
69
+ erubi (1.9.0)
70
+ globalid (0.4.2)
71
+ activesupport (>= 4.2.0)
72
+ i18n (1.8.3)
73
+ concurrent-ruby (~> 1.0)
74
+ loofah (2.6.0)
75
+ crass (~> 1.0.2)
76
+ nokogiri (>= 1.5.9)
77
+ mail (2.7.1)
78
+ mini_mime (>= 0.1.1)
79
+ marcel (0.3.3)
80
+ mimemagic (~> 0.3.2)
81
+ method_source (1.0.0)
82
+ mimemagic (0.3.5)
83
+ mini_mime (1.0.2)
84
+ mini_portile2 (2.4.0)
85
+ minitest (5.14.1)
86
+ nio4r (2.5.2)
87
+ nokogiri (1.10.9)
88
+ mini_portile2 (~> 2.4.0)
89
+ paint (2.2.0)
90
+ parallel (1.19.2)
91
+ parser (2.7.1.4)
92
+ ast (~> 2.4.1)
93
+ rack (2.2.3)
94
+ rack-test (1.1.0)
95
+ rack (>= 1.0, < 3)
96
+ rails (6.0.3.2)
97
+ actioncable (= 6.0.3.2)
98
+ actionmailbox (= 6.0.3.2)
99
+ actionmailer (= 6.0.3.2)
100
+ actionpack (= 6.0.3.2)
101
+ actiontext (= 6.0.3.2)
102
+ actionview (= 6.0.3.2)
103
+ activejob (= 6.0.3.2)
104
+ activemodel (= 6.0.3.2)
105
+ activerecord (= 6.0.3.2)
106
+ activestorage (= 6.0.3.2)
107
+ activesupport (= 6.0.3.2)
108
+ bundler (>= 1.3.0)
109
+ railties (= 6.0.3.2)
110
+ sprockets-rails (>= 2.0.0)
111
+ rails-dom-testing (2.0.3)
112
+ activesupport (>= 4.2.0)
113
+ nokogiri (>= 1.6)
114
+ rails-html-sanitizer (1.3.0)
115
+ loofah (~> 2.3)
116
+ railties (6.0.3.2)
117
+ actionpack (= 6.0.3.2)
118
+ activesupport (= 6.0.3.2)
119
+ method_source
120
+ rake (>= 0.8.7)
121
+ thor (>= 0.20.3, < 2.0)
122
+ rainbow (3.0.0)
123
+ rake (12.3.3)
124
+ regexp_parser (1.7.1)
125
+ rexml (3.2.4)
126
+ rspec (3.9.0)
127
+ rspec-core (~> 3.9.0)
128
+ rspec-expectations (~> 3.9.0)
129
+ rspec-mocks (~> 3.9.0)
130
+ rspec-core (3.9.2)
131
+ rspec-support (~> 3.9.3)
132
+ rspec-expectations (3.9.2)
133
+ diff-lcs (>= 1.2.0, < 2.0)
134
+ rspec-support (~> 3.9.0)
135
+ rspec-mocks (3.9.1)
136
+ diff-lcs (>= 1.2.0, < 2.0)
137
+ rspec-support (~> 3.9.0)
138
+ rspec-support (3.9.3)
139
+ rubocop (0.85.1)
140
+ parallel (~> 1.10)
141
+ parser (>= 2.7.0.1)
142
+ rainbow (>= 2.2.2, < 4.0)
143
+ regexp_parser (>= 1.7)
144
+ rexml
145
+ rubocop-ast (>= 0.0.3)
146
+ ruby-progressbar (~> 1.7)
147
+ unicode-display_width (>= 1.4.0, < 2.0)
148
+ rubocop-ast (0.0.3)
149
+ parser (>= 2.7.0.1)
150
+ ruby-progressbar (1.10.1)
151
+ sprockets (4.0.2)
152
+ concurrent-ruby (~> 1.0)
153
+ rack (> 1, < 3)
154
+ sprockets-rails (3.2.1)
155
+ actionpack (>= 4.0)
156
+ activesupport (>= 4.0)
157
+ sprockets (>= 3.0.0)
158
+ strong_versions (0.4.4)
159
+ i18n (>= 0.5.0)
160
+ paint (~> 2.0)
161
+ thor (1.0.1)
162
+ thread_safe (0.3.6)
163
+ tzinfo (1.2.7)
164
+ thread_safe (~> 0.1)
165
+ unicode-display_width (1.7.0)
166
+ websocket-driver (0.7.2)
167
+ websocket-extensions (>= 0.1.0)
168
+ websocket-extensions (0.1.5)
169
+ zeitwerk (2.3.0)
170
+
171
+ PLATFORMS
172
+ ruby
173
+
174
+ DEPENDENCIES
175
+ bundler (~> 2.1)
176
+ rails (~> 6.0)
177
+ rails_request!
178
+ rake (~> 12.0)
179
+ rspec (~> 3.0)
180
+ rubocop (~> 0.85.1)
181
+ strong_versions (~> 0.4.4)
182
+
183
+ BUNDLED WITH
184
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Bob Farrell
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.
@@ -0,0 +1,5 @@
1
+ .PHONY: test
2
+ test:
3
+ @bundle exec rspec
4
+ @bundle exec strong_versions
5
+ @bundle exec rubocop
@@ -0,0 +1,21 @@
1
+ # RailsRequest
2
+
3
+ _Rails_ toolkit for debugging and inspecting requests.
4
+
5
+ ## Installation
6
+
7
+ Add the gem to your `Gemfile`
8
+
9
+ ```ruby
10
+ gem 'rails_request', '~> 0.1.0'
11
+ ```
12
+
13
+ And rebuild your bundle:
14
+
15
+ ```bash
16
+ $ bundle install
17
+ ```
18
+
19
+ ## License
20
+
21
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'rails_request'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pathname'
4
+ require 'tempfile'
5
+ require 'rails'
6
+
7
+ require 'rails_request/version'
8
+ require 'rails_request/railtie' if Rails.env.development?
9
+ require 'rails_request/application_controller_extension'
10
+ require 'rails_request/payload'
11
+
12
+ module RailsRequest
13
+ class Error < StandardError; end
14
+
15
+ class << self
16
+ attr_accessor :host, :port
17
+ end
18
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsRequest
4
+ module ApplicationControllerExtension
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ before_action :__rails_request_capture_host_and_port
9
+ end
10
+
11
+ def __rails_request_capture_host_and_port
12
+ RailsRequest.host = request.host
13
+ RailsRequest.port = request.port
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsRequest
4
+ class Payload
5
+ def initialize(payload)
6
+ @payload = payload
7
+ end
8
+
9
+ def curl_options
10
+ query = params.present? ? "?#{params.to_query}" : nil
11
+ # host and port set during request by before_action
12
+ host = RailsRequest.host
13
+ port = RailsRequest.port
14
+ [
15
+ 'curl',
16
+ "--request '#{method}'",
17
+ headers.map { |key, value| "--header '#{key}: #{value}'" },
18
+ "http://#{host}:#{port}#{path}#{query}"
19
+ ].flatten.join(" \\\n")
20
+ end
21
+
22
+ def path
23
+ @payload[:path]
24
+ end
25
+
26
+ def method
27
+ @payload[:method]
28
+ end
29
+
30
+ private
31
+
32
+ def headers
33
+ @payload[:headers]
34
+ .select { |key, *_| key.start_with?('HTTP') }
35
+ .map do |key, value|
36
+ segments = key.downcase.split('_')
37
+ segments.shift
38
+ reformatted = segments.map(&:capitalize).join('-')
39
+ [reformatted, value]
40
+ end
41
+ end
42
+
43
+ def params
44
+ Hash[@payload[:params].reject do |key, _|
45
+ %w[action controller path].include?(key)
46
+ end]
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ ActiveSupport.on_load(:action_controller) do
4
+ include RailsRequest::ApplicationControllerExtension
5
+ end
6
+
7
+ module RailsRequest
8
+ class Railtie < Rails::Railtie
9
+ initializer 'rails_request.subscribe' do |_app|
10
+ event = 'process_action.action_controller'
11
+ notifications = ActiveSupport::Notifications
12
+ notifications.subscribe(event) do |_unused, start, _unused, _unused, data|
13
+ payload = Payload.new(data)
14
+ path = Pathname.new(Dir.tmpdir)
15
+ .join(start.strftime('%Y-%m-%d--%H-%M-%S.curl'))
16
+ File.write(path, payload.curl_options)
17
+ output(payload, path)
18
+ end
19
+ end
20
+
21
+ def output(payload, path)
22
+ green = "\033[32m"
23
+ blue = "\033[33m"
24
+ yellow = "\033[34m"
25
+ cyan = "\033[36m"
26
+ reset = "\033[0m"
27
+
28
+ command = %(eval "$(cat '#{path}')")
29
+ prefix = "#{cyan}#{payload.method} #{blue}#{payload.path}"
30
+ puts "#{prefix}#{reset} | #{yellow}replay request:#{reset}"
31
+ puts "#{green}#{command}#{reset}"
32
+ puts
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsRequest
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/rails_request/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'rails_request'
7
+ spec.version = RailsRequest::VERSION
8
+ spec.authors = ['Bob Farrell']
9
+ spec.email = ['git@bob.frl']
10
+
11
+ spec.summary = 'Rails request insight'
12
+ spec.description = 'Toolkit for replaying/analysing Rails requests'
13
+ spec.homepage = 'https://github.com/bobf/rails_request'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
17
+ `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ end
21
+
22
+ spec.bindir = 'bin'
23
+ spec.executables = []
24
+ spec.require_paths = ['lib']
25
+
26
+ spec.add_development_dependency 'bundler', '~> 2.1'
27
+ spec.add_development_dependency 'rails', '~> 6.0'
28
+ spec.add_development_dependency 'rake', '~> 10.0'
29
+ spec.add_development_dependency 'rspec', '~> 3.0'
30
+ spec.add_development_dependency 'rubocop', '~> 0.85.1'
31
+ spec.add_development_dependency 'strong_versions', '~> 0.4.4'
32
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_request
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Bob Farrell
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-06-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.1'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '6.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '6.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.85.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.85.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: strong_versions
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.4.4
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.4.4
97
+ description: Toolkit for replaying/analysing Rails requests
98
+ email:
99
+ - git@bob.frl
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".rubocop.yml"
107
+ - ".ruby-version"
108
+ - Gemfile
109
+ - Gemfile.lock
110
+ - LICENSE.txt
111
+ - Makefile
112
+ - README.md
113
+ - Rakefile
114
+ - bin/console
115
+ - bin/setup
116
+ - lib/rails_request.rb
117
+ - lib/rails_request/application_controller_extension.rb
118
+ - lib/rails_request/payload.rb
119
+ - lib/rails_request/railtie.rb
120
+ - lib/rails_request/version.rb
121
+ - rails_request.gemspec
122
+ homepage: https://github.com/bobf/rails_request
123
+ licenses:
124
+ - MIT
125
+ metadata: {}
126
+ post_install_message:
127
+ rdoc_options: []
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ requirements: []
141
+ rubygems_version: 3.1.2
142
+ signing_key:
143
+ specification_version: 4
144
+ summary: Rails request insight
145
+ test_files: []