How to override an Ubiquo::Connector

Suppose you want to change the way some uhooks work for one of your models. You need to override this hook so it will do something different. The way to do it is extending the default I18n connector from, say, UbiquoMedia (overriding other plugin’s connectors its done in the same way) and provide a custom method. Here’s how to do it:

Place an extension somewhere in lib/. In this case we will use lib/ubiquo_media/connectors/my_i18n.rb.

Inside you copy the affected method’s object hierarchy so our method overrides the original one. You must use its full class hierarchy while extending from I18n cause extending with “class MyI18n < I18n" alone clashes with rails I18n module raising an "Uncaught exception: superclass must be a Class (Module given)" error.

module UbiquoMedia
  module Connectors
    class MyI18n < UbiquoMedia::Connectors::I18n
      # Custom implementation
      
      def uhook_after_update
      # do stuff…
    end
  end
end

Then you require it, usually from a ubiquo_connectors.rb in lib/ like this:

require 'ubiquo_media/connectors/my_i18n'

Finally you tell Ubiquo::Config to use your connector instead of the original one, updating the ubiquo connector configuration (in config/initializers/ubiquo_config.rb), from this:

Ubiquo::Config.context(:ubiquo_media).set(:connector, :i18n)

to this:

Ubiquo::Config.context(:ubiquo_media).set(:connector, :my_i18n)

From now on, your method will be the one running in place of the original one.