Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
566d717d
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,体验更适合开发者的 AI 搜索 >>
提交
566d717d
编写于
6月 06, 2008
作者:
J
Jeremy Kemper
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move Class::ModelName to Active Support module core_ext
上级
c1a98209
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
48 addition
and
18 deletion
+48
-18
actionpack/lib/action_controller/record_identifier.rb
actionpack/lib/action_controller/record_identifier.rb
+2
-18
activesupport/lib/active_support/core_ext/module.rb
activesupport/lib/active_support/core_ext/module.rb
+5
-0
activesupport/lib/active_support/core_ext/module/model_naming.rb
...upport/lib/active_support/core_ext/module/model_naming.rb
+22
-0
activesupport/test/core_ext/module/model_naming_test.rb
activesupport/test/core_ext/module/model_naming_test.rb
+19
-0
未找到文件。
actionpack/lib/action_controller/record_identifier.rb
浏览文件 @
566d717d
class
Class
def
model_name
@model_name
||=
ModelName
.
new
(
name
)
end
class
ModelName
attr_reader
:singular
,
:plural
,
:path
def
initialize
(
name
)
@singular
=
name
.
underscore
.
tr
(
'/'
,
'_'
).
freeze
@plural
=
@singular
.
pluralize
.
freeze
@path
=
"
#{
name
.
tableize
}
/
#{
name
.
demodulize
.
underscore
}
"
.
freeze
end
end
end
module
ActionController
# The record identifier encapsulates a number of naming conventions for dealing with records, like Active Records or
# Active Resources or pretty much any other model type that has an id. These patterns are then used to try elevate
...
...
@@ -59,9 +43,9 @@ def partial_path(record_or_class, controller_path = nil)
name
=
model_name_from_record_or_class
(
record_or_class
)
if
controller_path
&&
controller_path
.
include?
(
"/"
)
"
#{
File
.
dirname
(
controller_path
)
}
/
#{
name
.
path
}
"
"
#{
File
.
dirname
(
controller_path
)
}
/
#{
name
.
pa
rtial_pa
th
}
"
else
name
.
path
name
.
pa
rtial_pa
th
end
end
...
...
activesupport/lib/active_support/core_ext/module.rb
浏览文件 @
566d717d
...
...
@@ -6,3 +6,8 @@
require
'active_support/core_ext/module/introspection'
require
'active_support/core_ext/module/loading'
require
'active_support/core_ext/module/aliasing'
require
'active_support/core_ext/module/model_naming'
class
Module
include
ActiveSupport
::
CoreExt
::
Module
::
ModelNaming
end
activesupport/lib/active_support/core_ext/module/model_naming.rb
0 → 100644
浏览文件 @
566d717d
module
ActiveSupport
class
ModelName
<
String
attr_reader
:singular
,
:plural
,
:partial_path
def
initialize
(
name
)
super
@singular
=
underscore
.
tr
(
'/'
,
'_'
).
freeze
@plural
=
@singular
.
pluralize
.
freeze
@partial_path
=
"
#{
tableize
}
/
#{
demodulize
.
underscore
}
"
.
freeze
end
end
module
CoreExt
module
Module
module
ModelNaming
def
model_name
@model_name
||=
ModelName
.
new
(
name
)
end
end
end
end
end
activesupport/test/core_ext/module/model_naming_test.rb
0 → 100644
浏览文件 @
566d717d
require
'abstract_unit'
class
ModelNamingTest
<
Test
::
Unit
::
TestCase
def
setup
@name
=
ActiveSupport
::
ModelName
.
new
(
'Post::TrackBack'
)
end
def
test_singular
assert_equal
'post_track_back'
,
@name
.
singular
end
def
test_plural
assert_equal
'post_track_backs'
,
@name
.
plural
end
def
test_partial_path
assert_equal
'post/track_backs/track_back'
,
@name
.
partial_path
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录