class AzaharaSchema::AttributeName
Attributes
attribute[R]
Public Class Methods
new(attribute)
click to toggle source
# File lib/azahara_schema/attribute_name.rb, line 6 def initialize(attribute) @attribute = attribute end
Public Instance Methods
human(**options)
click to toggle source
# File lib/azahara_schema/attribute_name.rb, line 10 def human(**options) I18n.t(i18n_scoped_key, options.merge(default: i18n_fallback_keys)) end
human_list_value(value, **options)
click to toggle source
translates values to list_values TODO: not needed to do it for every value - for example districts are not translatable
# File lib/azahara_schema/attribute_name.rb, line 16 def human_list_value(value, **options) return '' unless value.present? I18n.t(i18n_scoped_list_key(value.to_s), options.merge(default: i18n_list_fallback_keys(value)+[value.to_s])) end
i18n_fallback_keys()
click to toggle source
# File lib/azahara_schema/attribute_name.rb, line 45 def i18n_fallback_keys if attribute.respond_to?(:attribute) parent_attr_name = attribute.attribute.attribute_name keys = [ parent_attr_name.i18n_scoped_key.to_sym ] keys.concat( parent_attr_name.i18n_fallback_keys ) keys else [] end end
i18n_key()
click to toggle source
# File lib/azahara_schema/attribute_name.rb, line 25 def i18n_key attribute.name end
i18n_list_fallback_keys(value)
click to toggle source
# File lib/azahara_schema/attribute_name.rb, line 67 def i18n_list_fallback_keys(value) i18n_list_fallback_prefixes.collect{|pref| i18n_scoped_list_key(value, pref) } end
i18n_list_fallback_prefixes()
click to toggle source
# File lib/azahara_schema/attribute_name.rb, line 56 def i18n_list_fallback_prefixes if attribute.respond_to?(:attribute) parent_attr_name = attribute.attribute.attribute_name prefixes = [ parent_attr_name.i18n_scoped_list_prefix ] prefixes.concat( parent_attr_name.i18n_list_fallback_prefixes ) prefixes else [] end end
i18n_scope()
click to toggle source
# File lib/azahara_schema/attribute_name.rb, line 29 def i18n_scope 'activerecord.attributes.' + model_i18n_key.to_s end
i18n_scoped_key()
click to toggle source
# File lib/azahara_schema/attribute_name.rb, line 33 def i18n_scoped_key (i18n_scope + '.' + i18n_key.to_s).to_sym end
i18n_scoped_list_key(value, prefix=self.i18n_scoped_list_prefix)
click to toggle source
# File lib/azahara_schema/attribute_name.rb, line 41 def i18n_scoped_list_key(value, prefix=self.i18n_scoped_list_prefix) (prefix + '.' + value.to_s).to_sym end
i18n_scoped_list_prefix()
click to toggle source
# File lib/azahara_schema/attribute_name.rb, line 37 def i18n_scoped_list_prefix i18n_scope + '.' + i18n_key.to_s.pluralize end
model_i18n_key()
click to toggle source
# File lib/azahara_schema/attribute_name.rb, line 21 def model_i18n_key attribute.model.model_name.i18n_key end