diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2008-06-06 03:38:05 -0700 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2008-06-06 03:38:05 -0700 |
commit | 566d717d783f56563cd602198be2177c972c9a81 (patch) | |
tree | ff384a6a8c8c83054ff9db6335e6a28d6433aafe /activesupport/lib/active_support/core_ext | |
parent | c1a98209da7422965f5dd4f475603b8a3cc887e4 (diff) | |
download | rails-566d717d783f56563cd602198be2177c972c9a81.tar.gz rails-566d717d783f56563cd602198be2177c972c9a81.tar.bz2 rails-566d717d783f56563cd602198be2177c972c9a81.zip |
Move Class::ModelName to Active Support module core_ext
Diffstat (limited to 'activesupport/lib/active_support/core_ext')
-rw-r--r-- | activesupport/lib/active_support/core_ext/module.rb | 5 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/module/model_naming.rb | 22 |
2 files changed, 27 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/module.rb b/activesupport/lib/active_support/core_ext/module.rb index da8d5b3762..34fcbd124b 100644 --- a/activesupport/lib/active_support/core_ext/module.rb +++ b/activesupport/lib/active_support/core_ext/module.rb @@ -6,3 +6,8 @@ require 'active_support/core_ext/module/delegation' 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 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 |