ipaddr-ext 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cf80589f0fb436a83b743951bda416d1797bcfed488cad15b26f40378f95df7b
4
- data.tar.gz: 6159ab041b42951c635bafc9b7feab379071d5044f9a03133ccd533a2b166e55
3
+ metadata.gz: 3aa51bb31b861615ca35b891193aadd6ef6bae73cf52ca3793a83778acb9029c
4
+ data.tar.gz: 599314c4ea8c6bb731ee8336b7e2f90533b3ce04ab5195e1753432d9b2cfbb2c
5
5
  SHA512:
6
- metadata.gz: 6e8bcd61f275230ae3ec8937e11d4ef511e188b3487956c3058d50a30552c26afd5a84a4b6f08265b05c1a43d98aebeb8dcc0f70b54dc4cf8f5b6ad843c058db
7
- data.tar.gz: ee6b3b25223c78ac7823c13f7fa56c34a443f5d83170a6c0b5a2d52a1f872a72e9277681f80a6f6fcc3f5be7d873ebc5b986fcde427a22443c981ab713ba1ba9
6
+ metadata.gz: b6da8fcb2121fc1fc847d9c6819f8c6d12993f1282c620da21ab8170448dedb92e9ae4f2b8cc3accbdffe83e9779cc504c29529021d225be4cc75ff1929c776b
7
+ data.tar.gz: e0ce190b061be6832d12d226d786e7268c0a3ded3b13f9b86c96c4b65db20d2f4531774c5c485ad22f9f510df07d7bbcaf60d5f08a311f6031b345c3cfbe707b
data/Gemfile CHANGED
@@ -3,3 +3,14 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gemspec
6
+
7
+ if ENV['CI'].nil?
8
+ # for development
9
+ gem "actionview"
10
+
11
+ else
12
+ # for CI
13
+ unless ENV['RAILS_VERSION'].nil? || ENV['RAILS_VERSION'] == ''
14
+ gem "actionview", "~> #{ENV['RAILS_VERSION']}"
15
+ end
16
+ end
data/README.md CHANGED
@@ -58,6 +58,12 @@ ipaddr5.to_host.succ.to_s_with_prefix
58
58
  # to_json: export with prefix string
59
59
  IPAddr.new("3ffe:505:2::/64").to_json
60
60
  => "\"3ffe:505:2::/64\""
61
+
62
+ # ==: Fix to compare with address prefix
63
+ IPAddr.new("192.168.1.0/24") == IPAddr.new("192.168.1.0/24")
64
+ => true
65
+ IPAddr.new("192.168.1.0/24") == IPAddr.new("192.168.1.0/25")
66
+ => false # different behavior with pure IPAddr class
61
67
  ```
62
68
 
63
69
  ## Development
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'action_view'
4
+
5
+ module ActionView
6
+ module Helpers
7
+ module TagHelper
8
+ class TagBuilder
9
+ # Overwrite to fix FormHelper#text_field build value attribute of IPAddr without prefix
10
+ # https://github.com/rails/rails/pull/52365
11
+ def tag_option(key, value, escape)
12
+ key = ERB::Util.xml_name_escape(key) if escape
13
+
14
+ case value
15
+ when Array, Hash
16
+ value = TagHelper.build_tag_values(value) if key.to_s == "class"
17
+ value = escape ? safe_join(value, " ") : value.join(" ")
18
+ when Regexp
19
+ value = escape ? ERB::Util.unwrapped_html_escape(value.source) : value.source
20
+ when IPAddr
21
+ addr = value.to_s
22
+ unless (value.ipv4? && value.prefix == 32) || (value.ipv6? && value.prefix == 128)
23
+ addr = format("%s/%s", value.to_s, value.prefix)
24
+ end
25
+
26
+ value = escape ? ERB::Util.unwrapped_html_escape(addr) : addr
27
+ else
28
+ value = escape ? ERB::Util.unwrapped_html_escape(value) : value.to_s
29
+ end
30
+ value = value.gsub('"', """) if value.include?('"')
31
+
32
+ %(#{key}="#{value}")
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -21,19 +21,30 @@ module IPAddrExt
21
21
  end
22
22
  end
23
23
 
24
- # Returns the wildcard mask in string format e.g. 0.0.255.255
25
- # ref: https://github.com/ruby/ipaddr/pull/44
26
- def wildcard_mask
27
- case @family
28
- when Socket::AF_INET
29
- mask = IPAddr::IN4MASK ^ @mask_addr
30
- when Socket::AF_INET6
31
- mask = IPAddr::IN6MASK ^ @mask_addr
32
- else
33
- raise AddressFamilyError, "unsupported address family"
24
+ unless defined?(IPAddr::VERSION) && Gem::Version.new(IPAddr::VERSION) >= Gem::Version.new("1.2.7") # Ruby 3.4+ default gem
25
+ # Returns the wildcard mask in string format e.g. 0.0.255.255
26
+ def wildcard_mask
27
+ case @family
28
+ when Socket::AF_INET
29
+ mask = IPAddr::IN4MASK ^ @mask_addr
30
+ when Socket::AF_INET6
31
+ mask = IPAddr::IN6MASK ^ @mask_addr
32
+ else
33
+ raise AddressFamilyError, "unsupported address family"
34
+ end
35
+
36
+ _to_string(mask)
34
37
  end
38
+ end
35
39
 
36
- _to_string(mask)
40
+ # Returns true if two ipaddrs are equal.
41
+ # Overwrite original == method, fixing to compare address with prefix
42
+ def ==(other)
43
+ other = coerce_other(other)
44
+ rescue
45
+ false
46
+ else
47
+ @family == other.family && @addr == other.to_i && prefix == other.prefix
37
48
  end
38
49
 
39
50
  # Returns a address greater than the original address by offset
@@ -62,7 +73,11 @@ module IPAddrExt
62
73
 
63
74
  # Returns the address with prefix
64
75
  def to_s_with_prefix
65
- "#{self.to_s}/#{prefix}"
76
+ if defined?(IPAddr::VERSION) && Gem::Version.new(IPAddr::VERSION) >= Gem::Version.new("1.2.7") # Ruby 3.4+ default gem
77
+ cidr
78
+ else
79
+ "#{self.to_s}/#{prefix}"
80
+ end
66
81
  end
67
82
  end
68
83
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IPAddrExt
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
data/lib/ipaddr-ext.rb CHANGED
@@ -1,11 +1,14 @@
1
1
  require "ipaddr"
2
- require 'json'
3
2
 
4
3
  require "ipaddr-ext/version"
5
4
  require "ipaddr-ext/extensions"
6
5
  require "ipaddr-ext/json"
7
6
 
8
- IPAddr.send(:include, IPAddrExt::Extensions)
7
+ IPAddr.send(:prepend, IPAddrExt::Extensions)
9
8
 
10
9
  IPAddrExt::JSON.remove_as_json
11
10
  IPAddr.send(:include, IPAddrExt::JSON)
11
+
12
+ if defined?(::ActionView) && ActionView.version >= Gem::Version.new("6.1.0")
13
+ require "ipaddr-ext/actionview/tag_helper"
14
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ipaddr-ext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taketo Takashima
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-11-16 00:00:00.000000000 Z
11
+ date: 2024-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -52,6 +52,7 @@ files:
52
52
  - Rakefile
53
53
  - ipaddr-ext.gemspec
54
54
  - lib/ipaddr-ext.rb
55
+ - lib/ipaddr-ext/actionview/tag_helper.rb
55
56
  - lib/ipaddr-ext/extensions.rb
56
57
  - lib/ipaddr-ext/json.rb
57
58
  - lib/ipaddr-ext/version.rb
@@ -78,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
78
79
  - !ruby/object:Gem::Version
79
80
  version: '0'
80
81
  requirements: []
81
- rubygems_version: 3.3.26
82
+ rubygems_version: 3.5.16
82
83
  signing_key:
83
84
  specification_version: 4
84
85
  summary: Extensions for IPAddr Class