We were very inconsistent regarding these rules. Personally I prefer no empty lines around blocks, clases, etc... as recommended by the Ruby style guide [1], and they're the default values in rubocop, so those are the settings I'm applying. The exception is the `private` access modifier, since we were leaving empty lines around it most of the time. That's the default rubocop rule as well. Personally I don't have a strong preference about this one. [1] https://rubystyle.guide/#empty-lines-around-bodies
28 lines
795 B
Ruby
28 lines
795 B
Ruby
module RemotelyTranslatable
|
|
private
|
|
|
|
def detect_remote_translations(*args)
|
|
return [] unless Setting["feature.remote_translations"].present?
|
|
|
|
resources_groups(*args).flatten.select { |resource| translation_empty?(resource) }.map do |resource|
|
|
remote_translation_for(resource)
|
|
end
|
|
end
|
|
|
|
def remote_translation_for(resource)
|
|
{ "remote_translatable_id" => resource.id.to_s,
|
|
"remote_translatable_type" => resource.class.to_s,
|
|
"locale" => I18n.locale }
|
|
end
|
|
|
|
def translation_empty?(resource)
|
|
resource.translations.where(locale: I18n.locale).empty?
|
|
end
|
|
|
|
def resources_groups(*args)
|
|
feeds = args.detect { |arg| arg&.first.class == Widget::Feed } || []
|
|
|
|
args.compact - [feeds] + feeds.map(&:items)
|
|
end
|
|
end
|