diff --git a/.github/workflows/rspec.yml b/.github/workflows/rspec.yml index ef60cc7..325c5d1 100755 --- a/.github/workflows/rspec.yml +++ b/.github/workflows/rspec.yml @@ -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 diff --git a/lib/sniffer/adapters/ethon_adapter.rb b/lib/sniffer/adapters/ethon_adapter.rb index 2a93d88..7c1bef5 100644 --- a/lib/sniffer/adapters/ethon_adapter.rb +++ b/lib/sniffer/adapters/ethon_adapter.rb @@ -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 diff --git a/lib/sniffer/data_item.rb b/lib/sniffer/data_item.rb index c5d7d5b..059456a 100644 --- a/lib/sniffer/data_item.rb +++ b/lib/sniffer/data_item.rb @@ -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 @@ -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 @@ -62,7 +52,14 @@ 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 { @@ -70,14 +67,7 @@ def to_h 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 @@ -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 diff --git a/sniffer.gemspec b/sniffer.gemspec index cb9b372..f273e5d 100644 --- a/sniffer.gemspec +++ b/sniffer.gemspec @@ -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"