Module: Traco::ClassMethods
- Defined in:
- lib/traco/class_methods.rb
Instance Method Summary collapse
- #human_attribute_name(attribute, options = {}) ⇒ Object
- #locale_columns(*attributes) ⇒ Object
- #locales_for_attribute(attribute) ⇒ Object
Instance Method Details
#human_attribute_name(attribute, options = {}) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/traco/class_methods.rb', line 19 def human_attribute_name(attribute, = {}) default = super(attribute, .merge(:default => "")) if default.blank? && attribute.to_s.match(/\A(\w+)_([a-z]{2})\z/) column, locale = $1, $2.to_sym if translates?(column) return "#{super(column, options)} (#{locale_name(locale)})" end end super end |
#locale_columns(*attributes) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/traco/class_methods.rb', line 11 def locale_columns(*attributes) attributes.inject([]) { |memo, attribute| memo += locales_for_attribute(attribute).map { |locale| :"#{attribute}_#{locale}" } } end |
#locales_for_attribute(attribute) ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/traco/class_methods.rb', line 3 def locales_for_attribute(attribute) re = /\A#{attribute}_([a-z]{2})\z/ column_names. grep(re) { $1.to_sym }. sort_by(&locale_sort_value) end |