Added Inflector.humanize to turn attribute names like employee_salary into "Employee salary". Used by automated error reporting in AR.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@449 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
ecfe77f38d
commit
1b38c5523e
|
@ -1,3 +1,5 @@
|
||||||
|
* Added Inflector.humanize to turn attribute names like employee_salary into "Employee salary". Used by automated error reporting in AR.
|
||||||
|
|
||||||
* Added availability of class inheritable attributes to the masses #477 [bitsweat]
|
* Added availability of class inheritable attributes to the masses #477 [bitsweat]
|
||||||
|
|
||||||
class Foo
|
class Foo
|
||||||
|
|
|
@ -27,6 +27,10 @@ module Inflector
|
||||||
camel_cased_word.to_s.gsub(/([A-Z]+)([A-Z])/,'\1_\2').gsub(/([a-z])([A-Z])/,'\1_\2').downcase
|
camel_cased_word.to_s.gsub(/([A-Z]+)([A-Z])/,'\1_\2').gsub(/([a-z])([A-Z])/,'\1_\2').downcase
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def humanize(lower_case_and_underscored_word)
|
||||||
|
lower_case_and_underscored_word.to_s.gsub(/_/, " ").capitalize
|
||||||
|
end
|
||||||
|
|
||||||
def demodulize(class_name_in_module)
|
def demodulize(class_name_in_module)
|
||||||
class_name_in_module.to_s.gsub(/^.*::/, '')
|
class_name_in_module.to_s.gsub(/^.*::/, '')
|
||||||
end
|
end
|
||||||
|
|
|
@ -65,6 +65,11 @@ class InflectorTest < Test::Unit::TestCase
|
||||||
"PrimarySpokesman" => "primary_spokesmen",
|
"PrimarySpokesman" => "primary_spokesmen",
|
||||||
"NodeChild" => "node_children"
|
"NodeChild" => "node_children"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UnderscoreToHuman = {
|
||||||
|
"employee_salary" => "Employee salary",
|
||||||
|
"underground" => "Underground"
|
||||||
|
}
|
||||||
|
|
||||||
def test_pluralize
|
def test_pluralize
|
||||||
SingularToPlural.each do |singular, plural|
|
SingularToPlural.each do |singular, plural|
|
||||||
|
@ -120,4 +125,10 @@ class InflectorTest < Test::Unit::TestCase
|
||||||
assert_equal(class_name, Inflector.classify(table_name))
|
assert_equal(class_name, Inflector.classify(table_name))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_humanize
|
||||||
|
UnderscoreToHuman.each do |underscore, human|
|
||||||
|
assert_equal(human, Inflector.humanize(underscore))
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
Loading…
Reference in New Issue