Module: Cel::Extensions::Network::IP
- Defined in:
- lib/cel/extensions/network.rb
Constant Summary collapse
- CAST_ALLOWED_TYPES =
{ string: %i[ip cidr].freeze, }.freeze
Class Method Summary collapse
- .__check(funcall, checker:) ⇒ Object
- .__cidr(value) ⇒ Object
- .__ip(value) ⇒ Object
- .cidr(str, program:) ⇒ Object
- .implicit? ⇒ Boolean
- .ip(str, program:) ⇒ Object
-
.isCanonical(str, program:) ⇒ Object
rubocop:disable Naming/MethodName.
-
.isIP(str, program:) ⇒ Object
rubocop:disable Naming/MethodName.
Class Method Details
.__check(funcall, checker:) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/cel/extensions/network.rb', line 46 def __check(funcall, checker:) funcall.var func = funcall.func args = funcall.args case func when :ip, :cidr checker.check_arity(func, args, 1) arg = checker.call(args.first) TYPES[func] if checker.find_match_all_types(%i[string], arg) when :isIP, :isCanonical checker.check_arity(func, args, 1) arg = checker.call(args.first) TYPES[:bool] if checker.find_match_all_types(%i[string], arg) end end |
.__cidr(value) ⇒ Object
69 70 71 72 73 |
# File 'lib/cel/extensions/network.rb', line 69 def __cidr(value) Cel::CIDR.new(value) rescue IPAddr::InvalidAddressError raise EvaluateError, "IP Address '#{value}' parse error during conversion from string" end |
.__ip(value) ⇒ Object
63 64 65 66 67 |
# File 'lib/cel/extensions/network.rb', line 63 def __ip(value) Cel::IP.new(value) rescue IPAddr::InvalidAddressError raise EvaluateError, "IP Address '#{value}' parse error during conversion from string" end |
.cidr(str, program:) ⇒ Object
81 82 83 84 85 |
# File 'lib/cel/extensions/network.rb', line 81 def cidr(str, program:) value = program.call(str).value __cidr(value) end |
.implicit? ⇒ Boolean
42 43 44 |
# File 'lib/cel/extensions/network.rb', line 42 def implicit? true end |
.ip(str, program:) ⇒ Object
75 76 77 78 79 |
# File 'lib/cel/extensions/network.rb', line 75 def ip(str, program:) value = program.call(str).value __ip(value) end |
.isCanonical(str, program:) ⇒ Object
rubocop:disable Naming/MethodName
98 99 100 101 102 |
# File 'lib/cel/extensions/network.rb', line 98 def isCanonical(str, program:) # rubocop:disable Naming/MethodName value = program.call(str).value Bool.new(value == __ip(value).to_s) end |
.isIP(str, program:) ⇒ Object
rubocop:disable Naming/MethodName
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/cel/extensions/network.rb', line 87 def isIP(str, program:) # rubocop:disable Naming/MethodName value = program.call(str).value begin __ip(value) Bool.new(true) rescue EvaluateError Bool.new(false) end end |