Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixes "superclass mismatch for class Name" error in edge Rails

  • Loading branch information...
commit ecf23df1e1a801bb606279ec9d7f2e4a01591297 1 parent bc1a839
@andreychernih andreychernih authored
View
30 lib/gettext_i18n_rails/active_model.rb
@@ -1,28 +1,2 @@
-module ActiveModel
- class Name < String
- def human(options={})
- _(@klass.humanize_class_name)
- end
- end
-
- module Translation
- # CarDealer.sales_count -> s_('CarDealer|Sales count') -> 'Sales count' if no translation was found
- def human_attribute_name(attribute, *args)
- s_(gettext_translation_for_attribute_name(attribute))
- end
-
- def gettext_translation_for_attribute_name(attribute)
- attribute = attribute.to_s
- if attribute.ends_with?('_id')
- humanize_class_name(attribute)
- else
- "#{self}|#{attribute.split('.').map! {|a| a.humanize }.join('|')}"
- end
- end
-
- def humanize_class_name(name=nil)
- name ||= self.to_s
- name.underscore.humanize
- end
- end
-end
+require 'gettext_i18n_rails/active_model/name'
+require 'gettext_i18n_rails/active_model/translation'
View
7 lib/gettext_i18n_rails/active_model/name.rb
@@ -0,0 +1,7 @@
+module ActiveModel
+ Name.class_eval do
+ def human(options={})
+ _(@klass.humanize_class_name)
+ end
+ end
+end
View
22 lib/gettext_i18n_rails/active_model/translation.rb
@@ -0,0 +1,22 @@
+module ActiveModel
+ module Translation
+ # CarDealer.sales_count -> s_('CarDealer|Sales count') -> 'Sales count' if no translation was found
+ def human_attribute_name(attribute, *args)
+ s_(gettext_translation_for_attribute_name(attribute))
+ end
+
+ def gettext_translation_for_attribute_name(attribute)
+ attribute = attribute.to_s
+ if attribute.ends_with?('_id')
+ humanize_class_name(attribute)
+ else
+ "#{self}|#{attribute.split('.').map! {|a| a.humanize }.join('|')}"
+ end
+ end
+
+ def humanize_class_name(name=nil)
+ name ||= self.to_s
+ name.underscore.humanize
+ end
+ end
+end
View
2  lib/gettext_i18n_rails/active_record.rb
@@ -1,4 +1,4 @@
-require 'gettext_i18n_rails/active_model'
+require 'gettext_i18n_rails/active_model/translation'
class ActiveRecord::Base
extend ActiveModel::Translation
View
20 spec/gettext_i18n_rails/active_model/name_spec.rb
@@ -0,0 +1,20 @@
+# encoding: utf-8
+require "spec_helper"
+
+if ActiveRecord::VERSION::MAJOR >= 3
+ require "gettext_i18n_rails/active_model/name"
+
+ describe ActiveModel::Name do
+ before do
+ FastGettext.current_cache = {}
+ end
+
+ describe 'human' do
+ it "is translated through FastGettext" do
+ name = ActiveModel::Name.new(CarSeat)
+ name.should_receive(:_).with('Car seat').and_return('Autositz')
+ name.human.should == 'Autositz'
+ end
+ end
+ end
+end
View
16 spec/gettext_i18n_rails/active_model_spec.rb
@@ -1,16 +0,0 @@
-# encoding: utf-8
-require "spec_helper"
-
-describe ActiveModel::Name do
- before do
- FastGettext.current_cache = {}
- end
-
- describe 'human' do
- it "is translated through FastGettext" do
- name = ActiveModel::Name.new(CarSeat)
- name.should_receive(:_).with('Car seat').and_return('Autositz')
- name.human.should == 'Autositz'
- end
- end
-end if ActiveRecord::VERSION::MAJOR >= 3
Please sign in to comment.
Something went wrong with that request. Please try again.