Module: Globalize::ActiveRecord::ClassMethods
- Defined in:
- lib/globalize/active_record.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
115
116
117
118
119
120
121
|
# File 'lib/globalize/active_record.rb', line 115
def method_missing(method, *args)
if method.to_s =~ /^find_by_(\w+)$/ && translated_attribute_names.include?($1.to_sym)
find_first_by_translated_attr_and_locales($1, args.first)
else
super
end
end
|
Instance Method Details
#quoted_translation_table_name ⇒ Object
101
102
103
|
# File 'lib/globalize/active_record.rb', line 101
def quoted_translation_table_name
translation_class.quoted_table_name
end
|
#required_attributes ⇒ Object
105
106
107
108
109
|
# File 'lib/globalize/active_record.rb', line 105
def required_attributes
@required_attributes ||= reflect_on_all_validations.select do |validation|
validation.macro == :validates_presence_of && translated_attribute_names.include?(validation.name)
end.map(&:name)
end
|
#respond_to?(method, *args, &block) ⇒ Boolean
111
112
113
|
# File 'lib/globalize/active_record.rb', line 111
def respond_to?(method, *args, &block)
method.to_s =~ /^find_by_(\w+)$/ && translated_attribute_names.include?($1.to_sym) || super
end
|
#translation_table_name ⇒ Object
97
98
99
|
# File 'lib/globalize/active_record.rb', line 97
def translation_table_name
translation_class.table_name
end
|
#with_locale(locale) ⇒ Object
90
91
92
93
94
95
|
# File 'lib/globalize/active_record.rb', line 90
def with_locale(locale)
previous_locale, self.locale = self.locale, locale
result = yield
self.locale = previous_locale
result
end
|