aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/module/model_naming.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2008-06-12 17:48:30 -0500
committerDavid Heinemeier Hansson <david@loudthinking.com>2008-06-12 17:48:30 -0500
commitea3a7e1bb1efc8b3ca10c4163bc116f3d5e23af1 (patch)
treea3cce25be0c613a8e1444e1d0ff53aaed3497057 /activesupport/lib/active_support/core_ext/module/model_naming.rb
parent556204abaf95f7c995576cb1358f13de406682ab (diff)
parentdd4181f47dc0f166eb5d3e47a4a0dc1594cc5669 (diff)
downloadrails-ea3a7e1bb1efc8b3ca10c4163bc116f3d5e23af1.tar.gz
rails-ea3a7e1bb1efc8b3ca10c4163bc116f3d5e23af1.tar.bz2
rails-ea3a7e1bb1efc8b3ca10c4163bc116f3d5e23af1.zip
Merge branch 'master' of git@github.com:rails/rails
Diffstat (limited to 'activesupport/lib/active_support/core_ext/module/model_naming.rb')
-rw-r--r--activesupport/lib/active_support/core_ext/module/model_naming.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/module/model_naming.rb b/activesupport/lib/active_support/core_ext/module/model_naming.rb
new file mode 100644
index 0000000000..26e76ab556
--- /dev/null
+++ b/activesupport/lib/active_support/core_ext/module/model_naming.rb
@@ -0,0 +1,22 @@
+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