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"