Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
cdb9d7f4
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,发现更多精彩内容 >>
提交
cdb9d7f4
编写于
12月 19, 2016
作者:
A
Akira Matsuda
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Privatize unneededly protected methods in Active Model
上级
53f537d1
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
23 addition
and
27 deletion
+23
-27
activemodel/lib/active_model/attribute_methods.rb
activemodel/lib/active_model/attribute_methods.rb
+4
-6
activemodel/lib/active_model/forbidden_attributes_protection.rb
...model/lib/active_model/forbidden_attributes_protection.rb
+1
-1
activemodel/lib/active_model/validations.rb
activemodel/lib/active_model/validations.rb
+3
-3
activemodel/lib/active_model/validations/callbacks.rb
activemodel/lib/active_model/validations/callbacks.rb
+2
-2
activemodel/lib/active_model/validations/numericality.rb
activemodel/lib/active_model/validations/numericality.rb
+10
-12
activemodel/lib/active_model/validations/validates.rb
activemodel/lib/active_model/validations/validates.rb
+3
-3
未找到文件。
activemodel/lib/active_model/attribute_methods.rb
浏览文件 @
cdb9d7f4
...
...
@@ -334,12 +334,11 @@ def generated_attribute_methods #:nodoc:
}.
tap
{
|
mod
|
include
mod
}
end
pr
otected
def
instance_method_already_implemented?
(
method_name
)
#:nodoc:
pr
ivate
def
instance_method_already_implemented?
(
method_name
)
generated_attribute_methods
.
method_defined?
(
method_name
)
end
private
# The methods +method_missing+ and +respond_to?+ of this module are
# invoked often in a typical rails, both of which invoke the method
# +matched_attribute_method+. The latter method iterates through an
...
...
@@ -458,12 +457,11 @@ def respond_to?(method, include_private_methods = false)
end
end
pr
otected
def
attribute_method?
(
attr_name
)
#:nodoc:
pr
ivate
def
attribute_method?
(
attr_name
)
respond_to_without_attributes?
(
:attributes
)
&&
attributes
.
include?
(
attr_name
)
end
private
# Returns a struct representing the matching attribute method.
# The struct's attributes are prefix, base and suffix.
def
matched_attribute_method
(
method_name
)
...
...
activemodel/lib/active_model/forbidden_attributes_protection.rb
浏览文件 @
cdb9d7f4
...
...
@@ -15,7 +15,7 @@ class ForbiddenAttributesError < StandardError
end
module
ForbiddenAttributesProtection
# :nodoc:
pr
otected
pr
ivate
def
sanitize_for_mass_assignment
(
attributes
)
if
attributes
.
respond_to?
(
:permitted?
)
raise
ActiveModel
::
ForbiddenAttributesError
if
!
attributes
.
permitted?
...
...
activemodel/lib/active_model/validations.rb
浏览文件 @
cdb9d7f4
...
...
@@ -399,14 +399,14 @@ def validate!(context = nil)
# end
alias
:read_attribute_for_validation
:send
pr
otected
pr
ivate
def
run_validations!
#:nodoc:
def
run_validations!
_run_validate_callbacks
errors
.
empty?
end
def
raise_validation_error
def
raise_validation_error
# :doc:
raise
(
ValidationError
.
new
(
self
))
end
end
...
...
activemodel/lib/active_model/validations/callbacks.rb
浏览文件 @
cdb9d7f4
...
...
@@ -104,10 +104,10 @@ def after_validation(*args, &block)
end
end
pr
otected
pr
ivate
# Overwrite run validations to include callbacks.
def
run_validations!
#:nodoc:
def
run_validations!
_run_validation_callbacks
{
super
}
end
end
...
...
activemodel/lib/active_model/validations/numericality.rb
浏览文件 @
cdb9d7f4
...
...
@@ -61,29 +61,29 @@ def validate_each(record, attr_name, value)
end
end
pr
otected
pr
ivate
def
is_number?
(
raw_value
)
def
is_number?
(
raw_value
)
# :doc:
!
parse_raw_value_as_a_number
(
raw_value
).
nil?
rescue
ArgumentError
,
TypeError
false
end
def
parse_raw_value_as_a_number
(
raw_value
)
def
parse_raw_value_as_a_number
(
raw_value
)
# :doc:
Kernel
.
Float
(
raw_value
)
if
raw_value
!~
/\A0[xX]/
end
def
is_integer?
(
raw_value
)
def
is_integer?
(
raw_value
)
# :doc:
/\A[+-]?\d+\z/
===
raw_value
.
to_s
end
def
filtered_options
(
value
)
def
filtered_options
(
value
)
# :doc:
filtered
=
options
.
except
(
*
RESERVED_OPTIONS
)
filtered
[
:value
]
=
value
filtered
end
def
allow_only_integer?
(
record
)
def
allow_only_integer?
(
record
)
# :doc:
case
options
[
:only_integer
]
when
Symbol
record
.
send
(
options
[
:only_integer
])
...
...
@@ -94,12 +94,10 @@ def allow_only_integer?(record)
end
end
private
def
record_attribute_changed_in_place?
(
record
,
attr_name
)
record
.
respond_to?
(
:attribute_changed_in_place?
)
&&
record
.
attribute_changed_in_place?
(
attr_name
.
to_s
)
end
def
record_attribute_changed_in_place?
(
record
,
attr_name
)
record
.
respond_to?
(
:attribute_changed_in_place?
)
&&
record
.
attribute_changed_in_place?
(
attr_name
.
to_s
)
end
end
module
HelperMethods
...
...
activemodel/lib/active_model/validations/validates.rb
浏览文件 @
cdb9d7f4
...
...
@@ -148,15 +148,15 @@ def validates!(*attributes)
validates
(
*
(
attributes
<<
options
))
end
pr
otected
pr
ivate
# When creating custom validators, it might be useful to be able to specify
# additional default keys. This can be done by overwriting this method.
def
_validates_default_keys
# :nodoc:
def
_validates_default_keys
[
:if
,
:unless
,
:on
,
:allow_blank
,
:allow_nil
,
:strict
]
end
def
_parse_validates_options
(
options
)
# :nodoc:
def
_parse_validates_options
(
options
)
case
options
when
TrueClass
{}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录