ipaddr-ext 0.2.1 → 0.3.1

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: efb2c1d3849cb842a7fd508f3bdfddd4ab1bbfcc45075b74f074adf918bc82f8
4
+ data.tar.gz: b7a81fc6cb1d480f569d2a6c9aa397a1b32d3666c0c10afd14bec1e954fce2fa
5
5
  SHA512:
6
- metadata.gz: 4619358ca982d7d672f875b3c1dd590283056459fd6e13aa6b505587dfc42f0df4b757597c1ab17dc10cb70b184eebf93f8c98e9d22abcb6dc1c3e6eb562ef63
7
- data.tar.gz: d10d7ac3cb147c017f3b31aecb1563b3b6a4cf9482037d93a0e6990258375cebb04b3bb126c35d877d5acbc2902f7bc8ba5b313fd6d18a4330dee01fe8e8857b
6
+ metadata.gz: dc28d0d3d2e2b1cb8b18c1294eccd764279e8594252a3a8927d44db992f7f91cd9a2ff4a19a3d3dccdb7c042c3a74f5b33cf70c2ffdad59df5ecfc0a544167a6
7
+ data.tar.gz: d333f5b64e6a3a6688b38dea8dc1d8eb6adcfc91f31863162534eeb23e2cb4b77d03ef3230bb29500f30086291ae686e63e981a56dc8209a99ee8ff8e8ba8098
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']}.0"
15
+ end
16
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'action_view'
4
+ if (ActionView.gem_version >= Gem::Version.new('7.2.2') && ActionView.gem_version < Gem::Version.new('8.0')) ||
5
+ (ActionView.gem_version >= Gem::Version.new('7.1.5') && ActionView.gem_version < Gem::Version.new('7.2'))
6
+ require 'uri'
7
+ end
8
+
9
+ module ActionView
10
+ module Helpers
11
+ module TagHelper
12
+ class TagBuilder
13
+ # Overwrite to fix FormHelper#text_field build value attribute of IPAddr without prefix
14
+ # https://github.com/rails/rails/pull/52365
15
+ def tag_option(key, value, escape)
16
+ key = ERB::Util.xml_name_escape(key) if escape
17
+
18
+ case value
19
+ when Array, Hash
20
+ value = TagHelper.build_tag_values(value) if key.to_s == "class"
21
+ value = escape ? safe_join(value, " ") : value.join(" ")
22
+ when Regexp
23
+ value = escape ? ERB::Util.unwrapped_html_escape(value.source) : value.source
24
+ when IPAddr
25
+ addr = value.to_s
26
+ unless (value.ipv4? && value.prefix == 32) || (value.ipv6? && value.prefix == 128)
27
+ addr = format("%s/%s", value.to_s, value.prefix)
28
+ end
29
+
30
+ value = escape ? ERB::Util.unwrapped_html_escape(addr) : addr
31
+ else
32
+ value = escape ? ERB::Util.unwrapped_html_escape(value) : value.to_s
33
+ end
34
+ value = value.gsub('"', "&quot;") if value.include?('"')
35
+
36
+ %(#{key}="#{value}")
37
+ end
38
+ end
39
+ end
40
+ end
41
+ 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.1"
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.1
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-11-08 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