Class: KafoWizards::Entries::NetmaskEntry
- Inherits:
-
IPAddressEntry
- Object
- AbstractEntry
- StringEntry
- IPAddressEntry
- KafoWizards::Entries::NetmaskEntry
- Defined in:
- lib/kafo_wizards/entries/netmask.rb
Instance Attribute Summary
Attributes inherited from AbstractEntry
#default_value, #description, #label, #name, #parent, #post_hook, #pre_hook, #validators, #value
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from StringEntry
Methods inherited from AbstractEntry
#call_post_hook, #call_pre_hook, descendants, #display_type, inherited, #initialize, #required?, #update
Constructor Details
This class inherits a constructor from KafoWizards::Entries::StringEntry
Class Method Details
.entry_type ⇒ Object
20 21 22 |
# File 'lib/kafo_wizards/entries/netmask.rb', line 20 def self.entry_type :netmask end |
Instance Method Details
#validate(value) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/kafo_wizards/entries/netmask.rb', line 5 def validate(value) if value.to_s.include?('/') begin mask_len = value.split('/').last.to_i value = IPAddr.new('255.255.255.255').mask(mask_len).to_s rescue IPAddr::InvalidPrefixError => e raise KafoWizards::ValidationError.new("#{value} is not valid netmask (#{e.})") end end if !(value =~ Resolv::IPv4::Regex) raise KafoWizards::ValidationError.new("#{value} is not valid netmask") end value end |