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 +4 -4
- data/Gemfile +11 -0
- data/lib/ipaddr-ext/actionview/tag_helper.rb +37 -0
- data/lib/ipaddr-ext/extensions.rb +18 -13
- data/lib/ipaddr-ext/version.rb +1 -1
- data/lib/ipaddr-ext.rb +4 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3aa51bb31b861615ca35b891193aadd6ef6bae73cf52ca3793a83778acb9029c
|
4
|
+
data.tar.gz: 599314c4ea8c6bb731ee8336b7e2f90533b3ce04ab5195e1753432d9b2cfbb2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
-
|
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
|
-
"#
|
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
|
data/lib/ipaddr-ext/version.rb
CHANGED
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.
|
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-
|
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.
|
82
|
+
rubygems_version: 3.5.16
|
82
83
|
signing_key:
|
83
84
|
specification_version: 4
|
84
85
|
summary: Extensions for IPAddr Class
|