The problem with what you've done is that you've bound your gem's functionality to ActionView. It would be better to make it more generic.
To fix this you should package your code in its own module and then inject that module into your view environment. For example, put your helper into its own module (and file):
# lib/semantic_id/helper.rb
module SemanticId
module Helper
def semantic_id
...
end
end
end
Then add it to ActionView using a Railtie:
# lib/semantic_id.rb
require 'semantic_id/helper'
ActiveSupport.on_load(:action_view) do
include SemanticId::Helper
end
You want to separate the functional part of the helper from the part that inserts it into the framework. Your method contains some Rails-specific code, but if it didn't this technique would allow you to use it with Sinatra and other frameworks as well.
In general, the guts of your project should be in lib//*.rb
, and lib/.rb
should just make the functionality accessible.