Given the flexibility of Ruby, you have many options available here. The most obvious ones:
Use a module constant/method, or multiple ones, to store the desired settings/mappings as Hashed, and then just pass them to Tire methods.
Define the shared settings/mappings/behaviour in a module, which you can then include in your models. The approach is well described in the tire/issues/481.
A relevant snippet:
module Searchable
def self.included(base)
p "Included in #{base}"
base.class_eval do
include Tire::Model::Search
tire do
mapping do
indexes :title, type: 'string', analyzer: 'snowball'
end
end
end
end
end
class Article < ActiveRecord::Base
include Searchable
end
class Person < ActiveRecord::Base
include Searchable
end
This really doesn't have to be in an initializer -- you can put it in any place loadable from the Rails application.