aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib
diff options
context:
space:
mode:
authorSantiago Pastorino <santiago@wyeworks.com>2010-05-12 14:29:39 -0300
committerJosé Valim <jose.valim@gmail.com>2010-05-12 21:02:16 +0200
commit6334006b815eadd83575fe6d00e9010838530ee7 (patch)
tree2634aafd2705b09fd07f1a262e845ba1bc741e28 /activemodel/lib
parentbea3c26833ad3e1e94f7331e0553a4e2164e7de5 (diff)
downloadrails-6334006b815eadd83575fe6d00e9010838530ee7.tar.gz
rails-6334006b815eadd83575fe6d00e9010838530ee7.tar.bz2
rails-6334006b815eadd83575fe6d00e9010838530ee7.zip
Revert "Refactor of active_model/naming.rb and allow collection and element to be writable"
This reverts commit f7862b2c34b5b298bf7b937c55f0637ebfe43a25. Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activemodel/lib')
-rw-r--r--activemodel/lib/active_model/naming.rb34
1 files changed, 5 insertions, 29 deletions
diff --git a/activemodel/lib/active_model/naming.rb b/activemodel/lib/active_model/naming.rb
index a860388bae..8cdd3d2fe8 100644
--- a/activemodel/lib/active_model/naming.rb
+++ b/activemodel/lib/active_model/naming.rb
@@ -3,36 +3,18 @@ require 'active_support/inflector'
module ActiveModel
class Name < String
- attr_reader :singular, :plural, :element
+ attr_reader :singular, :plural, :element, :collection, :partial_path
+ alias_method :cache_key, :collection
def initialize(klass)
super(klass.name)
@klass = klass
@singular = ActiveSupport::Inflector.underscore(self).tr('/', '_').freeze
@plural = ActiveSupport::Inflector.pluralize(@singular).freeze
- @collection = nil
- self.element = ActiveSupport::Inflector.underscore(ActiveSupport::Inflector.demodulize(self)).freeze
- end
-
- def element=(element)
- @element = element
+ @element = ActiveSupport::Inflector.underscore(ActiveSupport::Inflector.demodulize(self)).freeze
@human = ActiveSupport::Inflector.humanize(@element).freeze
- @default_collection = nil
- @partial_path = nil
- end
-
- def collection
- @collection || default_collection
- end
- alias_method :cache_key, :collection
-
- def collection=(collection)
- @collection = collection
- @partial_path = nil
- end
-
- def partial_path
- @partial_path ||= "#{collection}/#{@element}"
+ @collection = ActiveSupport::Inflector.tableize(self).freeze
+ @partial_path = "#{@collection}/#{@element}".freeze
end
# Transform the model name into a more humane format, using I18n. By default,
@@ -52,12 +34,6 @@ module ActiveModel
options.reverse_merge! :scope => [@klass.i18n_scope, :models], :count => 1, :default => defaults
I18n.translate(defaults.shift, options)
end
-
- private
-
- def default_collection
- @default_collection ||= ActiveSupport::Inflector.tableize(self.sub(/[^:]*$/, @element)).freeze
- end
end
# ActiveModel::Naming is a module that creates a +model_name+ method on your