Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
yasuhito committed Jul 13, 2016
1 parent 3575305 commit 9905ad0
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion features/icmp_reply.feature
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ Feature: Icmp::Reply
"""
Then the result of eval should be:
"""
Icmp::Reply(destination_mac: mac_address, source_mac: mac_address, ether_type: uint16, vlan_pcp: bit3, vlan_cfi: bit1, vlan_vid: bit12, ip_version: bit4, ip_header_length: bit4, ip_type_of_service: uint8, ip_total_length: uint16, ip_identifier: uint16, ip_flag: bit3, ip_fragment: bit13, ip_ttl: uint8, ip_protocol: uint8, ip_header_checksum: uint16, source_ip_address: ip_address, destination_ip_address: ip_address, ip_option: string, icmp_type: uint8, icmp_code: uint8, icmp_checksum: uint16, icmp_identifier: uint16, icmp_sequence_number: uint16, echo_data: string)
Pio::Icmp::Reply(destination_mac: mac_address, source_mac: mac_address, ether_type: ether_type, vlan_pcp: bit3, vlan_cfi: bit1, vlan_vid: bit12, ether_type_vlan: uint16, ip_version: bit4, ip_header_length: bit4, ip_type_of_service: uint8, ip_total_length: uint16, ip_identifier: uint16, ip_flag: bit3, ip_fragment: bit13, ip_ttl: uint8, ip_protocol: uint8, ip_header_checksum: uint16, source_ip_address: ip_address, destination_ip_address: ip_address, ip_option: string, icmp_type: uint8, icmp_code: uint8, icmp_checksum: uint16, icmp_identifier: uint16, icmp_sequence_number: uint16, echo_data: string)
"""
2 changes: 1 addition & 1 deletion features/icmp_request.feature
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,5 @@ Feature: Icmp::Request
"""
Then the result of eval should be:
"""
Icmp::Request(destination_mac: mac_address, source_mac: mac_address, ether_type: uint16, vlan_pcp: bit3, vlan_cfi: bit1, vlan_vid: bit12, ip_version: bit4, ip_header_length: bit4, ip_type_of_service: uint8, ip_total_length: uint16, ip_identifier: uint16, ip_flag: bit3, ip_fragment: bit13, ip_ttl: uint8, ip_protocol: uint8, ip_header_checksum: uint16, source_ip_address: ip_address, destination_ip_address: ip_address, ip_option: string, icmp_type: uint8, icmp_code: uint8, icmp_checksum: uint16, icmp_identifier: uint16, icmp_sequence_number: uint16, echo_data: string)
Pio::Icmp::Request(destination_mac: mac_address, source_mac: mac_address, ether_type: ether_type, vlan_pcp: bit3, vlan_cfi: bit1, vlan_vid: bit12, ether_type_vlan: uint16, ip_version: bit4, ip_header_length: bit4, ip_type_of_service: uint8, ip_total_length: uint16, ip_identifier: uint16, ip_flag: bit3, ip_fragment: bit13, ip_ttl: uint8, ip_protocol: uint8, ip_header_checksum: uint16, source_ip_address: ip_address, destination_ip_address: ip_address, ip_option: string, icmp_type: uint8, icmp_code: uint8, icmp_checksum: uint16, icmp_identifier: uint16, icmp_sequence_number: uint16, echo_data: string)
"""
1 change: 1 addition & 0 deletions lib/pio/class_inspector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module ClassInspector
# rubocop:disable LineLength
def inspect
field_and_type = fields.each_with_object([]) do |each, result|
next if each.name == :padding
result << [each.name,
each.prototype.instance_variable_get(:@obj_class).name.demodulize.sub(/be$/, '').underscore]
end
Expand Down
7 changes: 7 additions & 0 deletions lib/pio/icmp/message.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'pio/class_inspector'
require 'pio/icmp/format'
require 'pio/message'
require 'pio/ruby_dumper'
Expand All @@ -6,6 +7,12 @@ module Pio
class Icmp
# Base class of Icmp::Request and Icmp::Reply.
class Message < Pio::Message
extend ClassInspector

def self.fields
Icmp::Format.fields
end

def self.create(format)
allocate.tap do |message|
message.instance_variable_set :@format, format
Expand Down
6 changes: 0 additions & 6 deletions lib/pio/icmp/reply.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ class Icmp
class Reply < Message
include InstanceInspector

# rubocop:disable LineLength
def self.inspect
'Icmp::Reply(destination_mac: mac_address, source_mac: mac_address, ether_type: uint16, vlan_pcp: bit3, vlan_cfi: bit1, vlan_vid: bit12, ip_version: bit4, ip_header_length: bit4, ip_type_of_service: uint8, ip_total_length: uint16, ip_identifier: uint16, ip_flag: bit3, ip_fragment: bit13, ip_ttl: uint8, ip_protocol: uint8, ip_header_checksum: uint16, source_ip_address: ip_address, destination_ip_address: ip_address, ip_option: string, icmp_type: uint8, icmp_code: uint8, icmp_checksum: uint16, icmp_identifier: uint16, icmp_sequence_number: uint16, echo_data: string)'
end
# rubocop:enable LineLength

option :icmp_type, value: 0
option :source_mac
option :destination_mac
Expand Down
6 changes: 0 additions & 6 deletions lib/pio/icmp/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ class Icmp
class Request < Message
include InstanceInspector

# rubocop:disable LineLength
def self.inspect
'Icmp::Request(destination_mac: mac_address, source_mac: mac_address, ether_type: uint16, vlan_pcp: bit3, vlan_cfi: bit1, vlan_vid: bit12, ip_version: bit4, ip_header_length: bit4, ip_type_of_service: uint8, ip_total_length: uint16, ip_identifier: uint16, ip_flag: bit3, ip_fragment: bit13, ip_ttl: uint8, ip_protocol: uint8, ip_header_checksum: uint16, source_ip_address: ip_address, destination_ip_address: ip_address, ip_option: string, icmp_type: uint8, icmp_code: uint8, icmp_checksum: uint16, icmp_identifier: uint16, icmp_sequence_number: uint16, echo_data: string)'
end
# rubocop:enable LineLength

option :icmp_type, value: 8
option :source_mac
option :destination_mac
Expand Down

0 comments on commit 9905ad0

Please sign in to comment.