lib-bootp 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 35f8b8b8e9cfea345c8c405e4557e6e8a8232c78968d913b6c7c926ba456dbe0
4
- data.tar.gz: 5c4344e2a22b5543a2a0a870febd49f4da4d03c33f454a79eaa04718b0ecddd9
3
+ metadata.gz: bed60f10af914d6832cb7d6b35edecdf91b7216410f912bdc6fbf6b28326e937
4
+ data.tar.gz: 6e185e3ac0c45d43beaff60ddee746e475ccbcff507499409330dcfa9cfb0a0a
5
5
  SHA512:
6
- metadata.gz: 55720d5ce4bb5e82d9c9d27adbcb86dcbf0d217679857f6aaf7a607727bc8568dcfdde44a5cfd02738d2f4b270543aced68985830b27a273e0f3f678a72b1780
7
- data.tar.gz: de807d6fd9da0245e22c7d952e9d949b08471226618a6c473e883328276e23ac48479561d5477b8b125bddcfc98773053d6e48a9bc250900c78c392c5ccbedd4
6
+ metadata.gz: 463b1ef322b4aed9ee14cb81a6cb6297d28a6b35e6c7d289a131965a8b24040bf5371b5be51f82fd46dc470ed24a9ac7241eb9e94db8483c548ba36879194edb
7
+ data.tar.gz: 3516025c3729975d85563278db1611746b5cdd3fedda7f914337c23d3603079ee11af8327f983f568cd817994e4e668cb7e2eecf7a86f9501ccc3fa0a7dda7dd
@@ -18,8 +18,8 @@ module Lib
18
18
  def initialize(flags=0)
19
19
  @flags = {}
20
20
  @flag = 0
21
- if flags.is_a? Integer
22
- case flags
21
+ if flags.is_a? Integer or flags.is_a? String
22
+ case flags.to_i
23
23
  when 0x8000
24
24
  @flags[:b] = 1
25
25
  @flag = 0x8000
@@ -16,8 +16,8 @@ module Lib
16
16
  def_delegator :@htype, :to_i
17
17
 
18
18
  def initialize(htype=1)
19
- raise ArgumentError, "Hardware address type out of range : #{htype}" unless (0..12).include? htype
20
- @htype = htype
19
+ @htype = htype.is_a?(Hash) ? htype.transform_keys(&:to_sym)[:code].to_i : htype
20
+ raise ArgumentError, "Hardware address type out of range : #{@htype}" unless (0..12).include? @htype
21
21
  end
22
22
 
23
23
  def to_s
@@ -16,8 +16,8 @@ module Lib
16
16
  def_delegators :@hops, :to_s, :to_i
17
17
 
18
18
  def initialize(hops=0)
19
- raise ArgumentError, "Hop Count out of range: #{hops}" if hops > 255
20
- @hops = hops
19
+ @hops = hops.to_i #.is_a?(Hash) ? hops.transform_keys(&:to_sym)[:code].to_i : hops.to_i
20
+ raise ArgumentError, "Hop Count out of range: #{@hops}" if @hops > 255
21
21
  end
22
22
 
23
23
  def <=>(other)
@@ -17,8 +17,8 @@ module Lib
17
17
  def_delegator :@op, :to_i
18
18
 
19
19
  def initialize(op=1)
20
- raise ArgumentError, "OP Code out of range : #{op}" unless [1,2].include? op.to_i
21
- @op = op
20
+ @op = op.is_a?(Hash) ? op.transform_keys(&:to_sym)[:code].to_i : op
21
+ raise ArgumentError, "OP Code out of range : #{@op}" unless [1,2].include? @op.to_i
22
22
  end
23
23
 
24
24
  def to_s
@@ -17,10 +17,10 @@ module Lib
17
17
 
18
18
  def initialize(xid = nil)
19
19
  xid = generate if xid.nil?
20
- unless xid >= 0 && xid <= 0xFFFFFFFF
21
- raise ArgumentError, "Not valid XID - #{xid} - should by 4 octet length"
20
+ @xid = xid.to_i
21
+ unless @xid >= 0 && @xid <= 0xFFFFFFFF
22
+ raise ArgumentError, "Not valid XID - #{@xid} - should by 4 octet length"
22
23
  end
23
- @xid = xid
24
24
  end
25
25
 
26
26
  def <=>(other)
@@ -1,5 +1,5 @@
1
1
  module Lib
2
2
  module BOOTP
3
- VERSION = '0.2.3'
3
+ VERSION = '0.2.4'
4
4
  end
5
5
  end
data/lib/lib/bootp.rb CHANGED
@@ -37,20 +37,24 @@ module Lib
37
37
 
38
38
  def initialize(op: 1, htype: 1, hlen: 6, hops: 0, xid: nil, secs: 0, flags: 0, ciaddr: 0, yiaddr: 0, siaddr: 0, giaddr: 0, chaddr: nil, sname: '.', file: '.')
39
39
  @packets = {}
40
- @packets[:op] = (op.is_a? Lib::BOOTP::Packet::OpCode) ? op : Lib::BOOTP::Packet::OpCode.new(op)
41
- @packets[:htype] = (htype.is_a? Lib::BOOTP::Packet::HardwareAddressType) ? htype : Lib::BOOTP::Packet::HardwareAddressType.new(htype)
42
- @packets[:hlen] = (hlen.is_a? Lib::BOOTP::Packet::HardwareAddressLength) ? hlen : Lib::BOOTP::Packet::HardwareAddressLength.new(hlen)
43
- @packets[:hops] = (hops.is_a? Lib::BOOTP::Packet::HopCount) ? hops : Lib::BOOTP::Packet::HopCount.new(hops)
44
- @packets[:xid] = (xid.is_a? Lib::BOOTP::Packet::TransactionID) ? xid : Lib::BOOTP::Packet::TransactionID.new(xid)
45
- @packets[:secs] = (secs.is_a? Lib::BOOTP::Packet::Seconds) ? secs : Lib::BOOTP::Packet::Seconds.new(secs)
46
- @packets[:flags] = (flags.is_a? Lib::BOOTP::Packet::Flags) ? flags : Lib::BOOTP::Packet::Flags.new(flags)
47
- @packets[:ciaddr] = (ciaddr.is_a? Lib::BOOTP::Packet::IPAddress) ? ciaddr : Lib::BOOTP::Packet::IPAddress.new(ciaddr)
48
- @packets[:yiaddr] = (yiaddr.is_a? Lib::BOOTP::Packet::IPAddress) ? yiaddr : Lib::BOOTP::Packet::IPAddress.new(yiaddr)
49
- @packets[:siaddr] = (siaddr.is_a? Lib::BOOTP::Packet::IPAddress) ? siaddr : Lib::BOOTP::Packet::IPAddress.new(siaddr)
50
- @packets[:giaddr] = (giaddr.is_a? Lib::BOOTP::Packet::IPAddress) ? giaddr : Lib::BOOTP::Packet::IPAddress.new(giaddr)
51
- @packets[:chaddr] = (chaddr.is_a? Lib::BOOTP::Packet::ClientHardwareAddress) ? chaddr : Lib::BOOTP::Packet::ClientHardwareAddress.new(chaddr)
52
- @packets[:sname] = (sname.is_a? Lib::BOOTP::Packet::ServerHostName) ? sname : Lib::BOOTP::Packet::ServerHostName.new(sname)
53
- @packets[:file] = (file.is_a? Lib::BOOTP::Packet::BootFile) ? file : Lib::BOOTP::Packet::BootFile.new(file)
40
+ if block_given?
41
+ yield self
42
+ else
43
+ @packets[:op] = (op.is_a? Lib::BOOTP::Packet::OpCode) ? op : Lib::BOOTP::Packet::OpCode.new(op)
44
+ @packets[:htype] = (htype.is_a? Lib::BOOTP::Packet::HardwareAddressType) ? htype : Lib::BOOTP::Packet::HardwareAddressType.new(htype)
45
+ @packets[:hlen] = (hlen.is_a? Lib::BOOTP::Packet::HardwareAddressLength) ? hlen : Lib::BOOTP::Packet::HardwareAddressLength.new(hlen)
46
+ @packets[:hops] = (hops.is_a? Lib::BOOTP::Packet::HopCount) ? hops : Lib::BOOTP::Packet::HopCount.new(hops)
47
+ @packets[:xid] = (xid.is_a? Lib::BOOTP::Packet::TransactionID) ? xid : Lib::BOOTP::Packet::TransactionID.new(xid)
48
+ @packets[:secs] = (secs.is_a? Lib::BOOTP::Packet::Seconds) ? secs : Lib::BOOTP::Packet::Seconds.new(secs)
49
+ @packets[:flags] = (flags.is_a? Lib::BOOTP::Packet::Flags) ? flags : Lib::BOOTP::Packet::Flags.new(flags)
50
+ @packets[:ciaddr] = (ciaddr.is_a? Lib::BOOTP::Packet::IPAddress) ? ciaddr : Lib::BOOTP::Packet::IPAddress.new(ciaddr)
51
+ @packets[:yiaddr] = (yiaddr.is_a? Lib::BOOTP::Packet::IPAddress) ? yiaddr : Lib::BOOTP::Packet::IPAddress.new(yiaddr)
52
+ @packets[:siaddr] = (siaddr.is_a? Lib::BOOTP::Packet::IPAddress) ? siaddr : Lib::BOOTP::Packet::IPAddress.new(siaddr)
53
+ @packets[:giaddr] = (giaddr.is_a? Lib::BOOTP::Packet::IPAddress) ? giaddr : Lib::BOOTP::Packet::IPAddress.new(giaddr)
54
+ @packets[:chaddr] = (chaddr.is_a? Lib::BOOTP::Packet::ClientHardwareAddress) ? chaddr : Lib::BOOTP::Packet::ClientHardwareAddress.new(chaddr)
55
+ @packets[:sname] = (sname.is_a? Lib::BOOTP::Packet::ServerHostName) ? sname : Lib::BOOTP::Packet::ServerHostName.new(sname)
56
+ @packets[:file] = (file.is_a? Lib::BOOTP::Packet::BootFile) ? file : Lib::BOOTP::Packet::BootFile.new(file)
57
+ end
54
58
  end
55
59
 
56
60
  def op=(op)
@@ -174,22 +178,11 @@ module Lib
174
178
 
175
179
  def self.from_json(json)
176
180
  json = json.is_a?(Hash) ? json: JSON.parse(json)
177
- self.new(
178
- op: json['op']['code'].to_i,
179
- htype: json['htype']['code'].to_i,
180
- hlen: json['hlen'].to_i,
181
- hops: json['hops'].to_i,
182
- xid: json['xid'].to_i,
183
- secs: json['secs'].to_i,
184
- flags: json['flags'].to_i,
185
- ciaddr: json['ciaddr']['address'].to_s,
186
- yiaddr: json['yiaddr']['address'].to_s,
187
- siaddr: json['siaddr']['address'].to_s,
188
- giaddr: json['giaddr']['address'].to_s,
189
- chaddr: json['chaddr'].to_s,
190
- sname: json['sname'].to_s,
191
- file: json['file'].to_s
192
- )
181
+ self.new do |p|
182
+ json.each_pair do |k,v|
183
+ p.send("#{k}=".to_sym, v) rescue NoMethodError
184
+ end
185
+ end
193
186
  end
194
187
 
195
188
  end
data/lib-bootp.gemspec CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "rake"
25
25
  spec.add_development_dependency "rspec"
26
26
 
27
- spec.add_dependency 'net-address', '~> 0.2.1'
27
+ spec.add_dependency 'net-address', '~> 0.2.2'
28
28
 
29
29
  spec.required_ruby_version = '>= 3.0.0'
30
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lib-bootp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Wojcieszonek
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.2.1
61
+ version: 0.2.2
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.2.1
68
+ version: 0.2.2
69
69
  description: Set of classes to low level handle the BOOTP protocol
70
70
  email:
71
71
  - piotr@wojcieszonek.pl