Module: Statics::Translatable::ClassMethods

Defined in:
lib/statics/translatable.rb

Instance Method Summary collapse

Instance Method Details

#override_translatable_attribute_getter(name) ⇒ Object



19
20
21
22
23
# File 'lib/statics/translatable.rb', line 19

def override_translatable_attribute_getter(name)
  define_method(name) do |locale: I18n.locale|
    attributes.dig(name, locale.to_sym)
  end
end

#translatable_attribute(name, options = {}) ⇒ Object



14
15
16
17
# File 'lib/statics/translatable.rb', line 14

def translatable_attribute(name, options = {})
  attribute(name, Types::Translations.meta(omittable: options.fetch(:optional, false)))
  override_translatable_attribute_getter(name)
end

#translatable_attributes(*names, **options) ⇒ Object



10
11
12
# File 'lib/statics/translatable.rb', line 10

def translatable_attributes(*names, **options)
  names.each { |name| translatable_attribute(name, options) }
end