class LinkedRails::Translate
Public Class Methods
call(type, key, object, fallback = true)
click to toggle source
# File lib/linked_rails/translate.rb, line 21 def call(type, key, object, fallback = true) strategy_for(type, key).call(object, fallback) end
key_for_iri(iri, key)
click to toggle source
# File lib/linked_rails/translate.rb, line 43 def key_for_iri(iri, key) [ Vocab.for!(iri).__prefix__, tag_for_iri(iri), key ].join('.') end
tag_for_iri(iri)
click to toggle source
# File lib/linked_rails/translate.rb, line 51 def tag_for_iri(iri) iri.to_s.split(Vocab.for(iri).to_s).last end
translation_key(resource)
click to toggle source
# File lib/linked_rails/translate.rb, line 25 def translation_key(resource) klass = case resource when Collection resource.association_class when Class resource else resource&.class end klass&.name&.demodulize&.tableize end
translations_for(type, key) { |object, fallback| ... }
click to toggle source
# File lib/linked_rails/translate.rb, line 38 def translations_for(type, key) strategies[type] ||= {} strategies[type][key] = ->(object, fallback) { yield(object, fallback) } end
Private Class Methods
strategy_for(type, key)
click to toggle source
# File lib/linked_rails/translate.rb, line 57 def strategy_for(type, key) strategies[type] ||= {} strategies[type][key] end