Class: IpaddrValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- IpaddrValidator
- Defined in:
- lib/ipaddr_validator.rb,
lib/ipaddr_validator/engine.rb,
lib/ipaddr_validator/version.rb
Defined Under Namespace
Classes: Engine
Constant Summary collapse
- VERSION =
'0.0.2'
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.default_options ⇒ Object
19 20 21 |
# File 'lib/ipaddr_validator.rb', line 19 def { ipv4: true, ipv6: false, array: false } end |
.valid?(value, options = {}) ⇒ Boolean
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/ipaddr_validator.rb', line 5 def valid?(value, = {}) = .merge() array = if [:array] return false unless value.is_a?(Array) value else [value] end array.all? do |value| validate_single_ipaddr(value, ) end end |
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
45 46 47 48 49 |
# File 'lib/ipaddr_validator.rb', line 45 def validate_each(record, attribute, value) unless self.class.valid?(value, ) record.errors.add(attribute, [:message] || :invalid_ipaddr) end end |