Skip to content

Commit

Permalink
Merge pull request #66 from aderyabin/more_rubies
Browse files Browse the repository at this point in the history
Add last rubies support
  • Loading branch information
aderyabin authored May 6, 2022
2 parents 41e4a2c + ad20df2 commit 7afc2a1
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 49 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/rspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: ["2.5.x", "2.6.x"]
ruby-version: ['3.1', '3.0', '2.7', '2.6', '2.5']
steps:
- uses: actions/checkout@v1
- name: Set up Ruby
uses: actions/setup-ruby@v1
- uses: actions/checkout@v2
- name: Set up Ruby ${{ matrix.ruby-version }}
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
ruby-version: ${{ matrix.ruby-version }}
- name: Install Bundler
run: |
gem install bundler
Expand Down
8 changes: 3 additions & 5 deletions lib/sniffer/adapters/ethon_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,14 @@ def perform

if defined?(::Ethon::Easy)
if defined?(Sniffer::Adapters::EthonAdapter::PREPEND)
Ethon::Easy::Http.prepend Sniffer::Adapters::EthonAdapter::Http::Prepend
Ethon::Easy::Operations.prepend Sniffer::Adapters::EthonAdapter::Operations::Prepend
Ethon::Easy.prepend Sniffer::Adapters::EthonAdapter::Http::Prepend
Ethon::Easy.prepend Sniffer::Adapters::EthonAdapter::Operations::Prepend
else
Ethon::Easy::Http.class_eval do
Ethon::Easy.class_eval do
include Sniffer::Adapters::EthonAdapter::Http
alias_method :http_request_without_sniffer, :http_request
alias_method :http_request, :http_request_with_sniffer
end

Ethon::Easy::Operations.class_eval do
include Sniffer::Adapters::EthonAdapter::Operations
alias_method :perform_without_sniffer, :perform
alias_method :perform, :perform_with_sniffer
Expand Down
64 changes: 26 additions & 38 deletions lib/sniffer/data_item.rb
Original file line number Diff line number Diff line change
@@ -1,33 +1,23 @@
# frozen_string_literal: true

require 'active_attr'
require 'dry-initializer'
require 'json'
require_relative 'request_policy'

module Sniffer
# Sniffer data item stores a request info
class DataItem
include ActiveAttr::MassAssignment
attr_accessor :request, :response
extend Dry::Initializer

attr_writer :request, :response

option :request, optional: true
option :response, optional: true

def to_h
{
request: # frozen_string_literal: true
# Sniffer data item stores a request info
# Basic object for request and response objects
# Stores http request data
# rubocop:enable
# Stores http response data

request&.to_h,
response: # frozen_string_literal: true
# Sniffer data item stores a request info
# Basic object for request and response objects
# Stores http request data
# rubocop:enable
# Stores http response data

response&.to_h
request: request&.to_h,
response: response&.to_h
}
end

Expand All @@ -49,7 +39,7 @@ def allowed_to_sniff?

# Basic object for request and response objects
class HttpObject
include ActiveAttr::MassAssignment
extend Dry::Initializer

def log_message
raise NotImplementedError
Expand All @@ -62,22 +52,22 @@ def log_settings

# Stores http request data
class Request < HttpObject
attr_accessor :host, :port, :query, :method, :headers, :body
option :host, optional: true
option :port, optional: true
option :query, optional: true
option :method, optional: true
option :headers, optional: true
option :body, optional: true

attr_writer :host, :port, :query, :method, :headers, :body

def to_h
{
host: host,
query: query,
port: port,
headers: headers,
body: # frozen_string_literal: true
# Sniffer data item stores a request info
# Basic object for request and response objects
# Stores http request data
# rubocop:enable
# Stores http response data

body&.to_s,
body: body&.to_s,
method: method
}
end
Expand Down Expand Up @@ -106,20 +96,18 @@ def to_log

# Stores http response data
class Response < HttpObject
attr_accessor :status, :headers, :body, :timing
attr_writer :status, :headers, :body, :timing

option :status, optional: true
option :headers, optional: true
option :body, optional: true
option :timing, optional: true

def to_h
{
status: status,
headers: headers,
body: # frozen_string_literal: true
# Sniffer data item stores a request info
# Basic object for request and response objects
# Stores http request data
# rubocop:enable
# Stores http response data

body&.to_s,
body: body&.to_s,
timing: timing
}
end
Expand Down
2 changes: 1 addition & 1 deletion sniffer.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]

spec.add_dependency "anyway_config", ">= 1.0"
spec.add_dependency "active_attr", ">= 0.10.2"
spec.add_dependency "dry-initializer", "~> 3"

spec.add_development_dependency "bundler", "~> 2"
spec.add_development_dependency "rake", ">= 12.3.3"
Expand Down

0 comments on commit 7afc2a1

Please sign in to comment.