Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
0421fb7a
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0421fb7a
编写于
6月 21, 2010
作者:
J
José Valim
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor previous commit a bit [#4057 state:resolved]
上级
26392c4a
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
16 addition
and
16 deletion
+16
-16
activemodel/lib/active_model/errors.rb
activemodel/lib/active_model/errors.rb
+7
-4
activemodel/lib/active_model/validations/exclusion.rb
activemodel/lib/active_model/validations/exclusion.rb
+1
-1
activemodel/lib/active_model/validations/format.rb
activemodel/lib/active_model/validations/format.rb
+2
-2
activemodel/lib/active_model/validations/inclusion.rb
activemodel/lib/active_model/validations/inclusion.rb
+1
-1
activemodel/lib/active_model/validations/length.rb
activemodel/lib/active_model/validations/length.rb
+2
-2
activemodel/lib/active_model/validations/numericality.rb
activemodel/lib/active_model/validations/numericality.rb
+3
-3
activemodel/lib/active_model/validations/with.rb
activemodel/lib/active_model/validations/with.rb
+0
-3
未找到文件。
activemodel/lib/active_model/errors.rb
浏览文件 @
0421fb7a
...
...
@@ -61,6 +61,8 @@ module ActiveModel
class
Errors
<
ActiveSupport
::
OrderedHash
include
DeprecatedErrorMethods
CALLBACKS_OPTIONS
=
[
:if
,
:unless
,
:on
,
:allow_nil
,
:allow_blank
]
# Pass in the instance of the object that is using the errors object.
#
# class Person
...
...
@@ -183,11 +185,12 @@ def to_xml(options={})
def
add
(
attribute
,
message
=
nil
,
options
=
{})
message
||=
:invalid
validation_conditionals
=
[
:if
,
:unless
,
:on
]
message
=
generate_message
(
attribute
,
message
,
options
.
except
(
*
validation_conditionals
))
if
message
.
is_a?
(
Symbol
)
if
message
.
is_a?
(
Symbol
)
message
=
generate_message
(
attribute
,
message
,
options
.
except
(
*
CALLBACKS_OPTIONS
))
elsif
message
.
is_a?
(
Proc
)
message
=
message
.
call
end
message
=
message
.
call
if
message
.
is_a?
(
Proc
)
self
[
attribute
]
<<
message
end
...
...
activemodel/lib/active_model/validations/exclusion.rb
浏览文件 @
0421fb7a
...
...
@@ -10,7 +10,7 @@ def check_validity!
def
validate_each
(
record
,
attribute
,
value
)
if
options
[
:in
].
include?
(
value
)
record
.
errors
.
add
(
attribute
,
:exclusion
,
options
.
except
(
:in
).
merge
(
:value
=>
value
))
record
.
errors
.
add
(
attribute
,
:exclusion
,
options
.
except
(
:in
).
merge
!
(
:value
=>
value
))
end
end
end
...
...
activemodel/lib/active_model/validations/format.rb
浏览文件 @
0421fb7a
...
...
@@ -5,9 +5,9 @@ module Validations
class
FormatValidator
<
EachValidator
def
validate_each
(
record
,
attribute
,
value
)
if
options
[
:with
]
&&
value
.
to_s
!~
options
[
:with
]
record
.
errors
.
add
(
attribute
,
:invalid
,
options
.
except
(
:with
).
merge
(
:value
=>
value
))
record
.
errors
.
add
(
attribute
,
:invalid
,
options
.
except
(
:with
).
merge
!
(
:value
=>
value
))
elsif
options
[
:without
]
&&
value
.
to_s
=~
options
[
:without
]
record
.
errors
.
add
(
attribute
,
:invalid
,
options
.
except
(
:with
).
merge
(
:value
=>
value
))
record
.
errors
.
add
(
attribute
,
:invalid
,
options
.
except
(
:with
out
).
merge!
(
:value
=>
value
))
end
end
...
...
activemodel/lib/active_model/validations/inclusion.rb
浏览文件 @
0421fb7a
...
...
@@ -10,7 +10,7 @@ def check_validity!
def
validate_each
(
record
,
attribute
,
value
)
unless
options
[
:in
].
include?
(
value
)
record
.
errors
.
add
(
attribute
,
:inclusion
,
options
.
except
(
:in
).
merge
(
:value
=>
value
))
record
.
errors
.
add
(
attribute
,
:inclusion
,
options
.
except
(
:in
).
merge
!
(
:value
=>
value
))
end
end
end
...
...
activemodel/lib/active_model/validations/length.rb
浏览文件 @
0421fb7a
...
...
@@ -7,6 +7,7 @@ class LengthValidator < EachValidator
CHECKS
=
{
:is
=>
:==
,
:minimum
=>
:
>=
,
:maximum
=>
:<=
}.
freeze
DEFAULT_TOKENIZER
=
lambda
{
|
value
|
value
.
split
(
//
)
}
RESERVED_OPTIONS
=
[
:minimum
,
:maximum
,
:within
,
:is
,
:tokenizer
,
:too_short
,
:too_long
]
def
initialize
(
options
)
if
range
=
(
options
.
delete
(
:in
)
||
options
.
delete
(
:within
))
...
...
@@ -50,9 +51,8 @@ def validate_each(record, attribute, value)
next
if
valid_value
reserved_options
=
[
:minimum
,
:maximum
,
:within
,
:is
,
:tokenizer
,
:too_short
,
:too_long
]
record
.
errors
.
add
(
attribute
,
MESSAGES
[
key
],
options
.
except
(
*
reserved_options
).
merge
(
:count
=>
check_value
))
options
.
except
(
*
RESERVED_OPTIONS
).
merge!
(
:count
=>
check_value
))
end
end
end
...
...
activemodel/lib/active_model/validations/numericality.rb
浏览文件 @
0421fb7a
...
...
@@ -7,6 +7,8 @@ class NumericalityValidator < EachValidator
:equal_to
=>
:==
,
:less_than
=>
:<
,
:less_than_or_equal_to
=>
:<=
,
:odd
=>
:odd?
,
:even
=>
:even?
}.
freeze
RESERVED_OPTIONS
=
CHECKS
.
keys
+
[
:only_integer
]
def
initialize
(
options
)
super
(
options
.
reverse_merge
(
:only_integer
=>
false
,
:allow_nil
=>
false
))
end
...
...
@@ -76,10 +78,8 @@ def parse_raw_value_as_an_integer(raw_value)
end
def
filtered_options
(
value
)
reserved_options
=
[
:allow_nil
,
:odd
,
:even
,
:not_an_integer
,
:only_integer
,
:allow_nil
,
:less_than
]
options
.
except
(
*
reserved_options
).
merge
(
:value
=>
value
)
options
.
except
(
*
RESERVED_OPTIONS
).
merge!
(
:value
=>
value
)
end
end
module
HelperMethods
...
...
activemodel/lib/active_model/validations/with.rb
浏览文件 @
0421fb7a
module
ActiveModel
# == Active Model validates_with method
module
Validations
module
HelperMethods
private
...
...
@@ -11,7 +9,6 @@ def _merge_attributes(attr_names)
end
module
ClassMethods
# Passes the record off to the class or classes specified and allows them
# to add errors based on more complex conditions.
#
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录