Page Menu
Home
GRNET
Search
Configure Global Search
Log In
Files
F448934
prio_validator.rb
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Thu, Apr 24, 11:58 AM
Size
757 B
Mime Type
text/x-ruby
Expires
Sat, Apr 26, 11:58 AM (1 d, 13 h)
Engine
blob
Format
Raw Data
Handle
212304
Attached To
rWEBDNS WebDNS (edet4)
prio_validator.rb
View Options
# Validates DNS priorities [0, 65535]
class
PrioValidator
<
ActiveModel
::
EachValidator
# Adds an attribute error if value is not a valid DNS priority.
def
validate_each
(
record
,
attribute
,
value
)
# Rails autocasts integer fields to 0 if a non-numerical value is passed
# we override that by using th *_before_type_cast helper method
before_cast
=
:"
#{
attribute
}
_before_type_cast"
raw_value
=
record
.
send
(
before_cast
)
if
record
.
respond_to?
(
before_cast
)
raw_value
||=
value
val
=
Integer
(
raw_value
)
if
val
<
0
||
val
>
65_535
record
.
errors
[
attribute
]
<<
'is not a valid DNS priority [0, 65535]'
end
rescue
ArgumentError
,
TypeError
record
.
errors
[
attribute
]
<<
'is not a valid DNS priority [0, 65535]'
end
end
Event Timeline
Log In to Comment