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) ⇒ Object



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

def translatable_attribute(name)
  attribute(name, Types::Map(Types::Strict::Symbol.constructor(&:to_sym), Types::Strict::String))
  override_translatable_attribute_getter(name)
end

#translatable_attributes(*names) ⇒ Object



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

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