Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
92160219
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,发现更多精彩内容 >>
提交
92160219
编写于
5月 11, 2010
作者:
J
Josh Kalderimis
提交者:
Carl Lerche
5月 13, 2010
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
minor changes to instance level validations implementation based on feedback from José Valim
上级
9131a88b
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
17 addition
and
38 deletion
+17
-38
activemodel/lib/active_model/validations.rb
activemodel/lib/active_model/validations.rb
+2
-1
activemodel/lib/active_model/validations/helper_methods.rb
activemodel/lib/active_model/validations/helper_methods.rb
+0
-12
activemodel/lib/active_model/validations/with.rb
activemodel/lib/active_model/validations/with.rb
+12
-25
activemodel/lib/active_model/validator.rb
activemodel/lib/active_model/validator.rb
+3
-0
未找到文件。
activemodel/lib/active_model/validations.rb
浏览文件 @
92160219
...
...
@@ -47,7 +47,8 @@ module Validations
included
do
extend
ActiveModel
::
Translation
extend
HelperMethods
;
include
HelperMethods
extend
HelperMethods
include
HelperMethods
define_callbacks
:validate
,
:scope
=>
:name
...
...
activemodel/lib/active_model/validations/helper_methods.rb
已删除
100644 → 0
浏览文件 @
9131a88b
module
ActiveModel
module
Validations
module
HelperMethods
private
def
_merge_attributes
(
attr_names
)
options
=
attr_names
.
extract_options!
options
.
merge
(
:attributes
=>
attr_names
.
flatten
)
end
end
end
end
\ No newline at end of file
activemodel/lib/active_model/validations/with.rb
浏览文件 @
92160219
module
ActiveModel
module
Validations
module
HelperMethods
private
def
_merge_attributes
(
attr_names
)
options
=
attr_names
.
extract_options!
options
.
merge
(
:attributes
=>
attr_names
.
flatten
)
end
end
module
ClassMethods
# Passes the record off to the class or classes specified and allows them
...
...
@@ -89,18 +97,8 @@ def validates_with(*args, &block)
# end
# end
#
# class MyValidator < ActiveModel::Validator
# def validate(record)
# if some_complex_logic
# record.errors[:base] << "This record is invalid"
# end
# end
#
# private
# def some_complex_logic
# # ...
# end
# end
# Please consult the class method documentation for more information on
# creating your own validator.
#
# You may also pass it multiple classes, like so:
#
...
...
@@ -120,24 +118,13 @@ def validates_with(*args, &block)
# in the callback
#
# If you pass any additional configuration options, they will be passed
# to the class and available as <tt>options</tt>:
#
# class Person
# include ActiveModel::Validations
# validates_with MyValidator, :my_custom_key => "my custom value"
# end
#
# class MyValidator < ActiveModel::Validator
# def validate(record)
# options[:my_custom_key] # => "my custom value"
# end
# end
# to the class and available as <tt>options</tt>, please refer to the
# class version of this method for more information
#
def
validates_with
(
*
args
,
&
block
)
options
=
args
.
extract_options!
args
.
each
do
|
klass
|
validator
=
klass
.
new
(
options
,
&
block
)
validator
.
setup
(
self
)
if
validator
.
respond_to?
(
:setup
)
validator
.
validate
(
self
)
end
end
...
...
activemodel/lib/active_model/validator.rb
浏览文件 @
92160219
...
...
@@ -88,6 +88,9 @@ module ActiveModel #:nodoc:
# klass.send :attr_accessor, :custom_attribute
# end
# end
#
# This setup method is only called when used with validation macros or the
# class level <tt>validates_with</tt> method.
#
class
Validator
attr_reader
:options
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录