Skip to content

Commit

Permalink
Replace active_attr to dry-initializer
Browse files Browse the repository at this point in the history
  • Loading branch information
aderyabin committed May 6, 2022
1 parent aca8adb commit ad20df2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 39 deletions.
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 ad20df2

Please sign in to comment.