ipaddr-ext 0.2.1 → 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: 4fb5976cf49eb88720a9e1eb813f40f8ad390130f7095b5c9729368117ca37ad
4
- data.tar.gz: 673d199fa8a14c42138accc2d9c39d3fc558f36781f38d311ad627f2618af8a4
3
+ metadata.gz: 3aa51bb31b861615ca35b891193aadd6ef6bae73cf52ca3793a83778acb9029c
4
+ data.tar.gz: 599314c4ea8c6bb731ee8336b7e2f90533b3ce04ab5195e1753432d9b2cfbb2c
5
5
  SHA512:
6
- metadata.gz: 4619358ca982d7d672f875b3c1dd590283056459fd6e13aa6b505587dfc42f0df4b757597c1ab17dc10cb70b184eebf93f8c98e9d22abcb6dc1c3e6eb562ef63
7
- data.tar.gz: d10d7ac3cb147c017f3b31aecb1563b3b6a4cf9482037d93a0e6990258375cebb04b3bb126c35d877d5acbc2902f7bc8ba5b313fd6d18a4330dee01fe8e8857b
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
@@ -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,20 @@ 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"
34
- end
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
35
 
36
- _to_string(mask)
36
+ _to_string(mask)
37
+ end
37
38
  end
38
39
 
39
40
  # Returns true if two ipaddrs are equal.
@@ -72,7 +73,11 @@ module IPAddrExt
72
73
 
73
74
  # Returns the address with prefix
74
75
  def to_s_with_prefix
75
- "#{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
76
81
  end
77
82
  end
78
83
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IPAddrExt
4
- VERSION = "0.2.1"
4
+ VERSION = "0.3.0"
5
5
  end
data/lib/ipaddr-ext.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require "ipaddr"
2
- require 'json'
3
2
 
4
3
  require "ipaddr-ext/version"
5
4
  require "ipaddr-ext/extensions"
@@ -9,3 +8,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.1
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: 2024-05-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.5.9
82
+ rubygems_version: 3.5.16
82
83
  signing_key:
83
84
  specification_version: 4
84
85
  summary: Extensions for IPAddr Class