Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ServicePattern pollutes the top-level namespace #136

Open
ollietreend opened this issue Apr 25, 2024 · 0 comments
Open

ServicePattern pollutes the top-level namespace #136

ollietreend opened this issue Apr 25, 2024 · 0 comments

Comments

@ollietreend
Copy link

The ServicePattern module is defined as a top-level module, rather than being namespaced within the DfE::Analytics module. It therefore pollutes the top-level namespace of any Ruby app which uses the dfe-analytics gem.

# a template for creating service objects
module ServicePattern
def self.included(base)
base.extend(ClassMethods)
base.class_eval do
private_class_method(:new)
end
end

For example, this caused some strange behaviour over in DFE-Digital/itt-mentor-services#521 (comment) where we had to manually require our own ServicePattern module directly in a spec file to override the one provided by dfe-analytics.

I think ideally this module should be namespaced inside DfE::Analytics to avoid this from happening – plus to be consistent with the other classes in this gem, which all seem to be namespaced according to their file path.

In other words, I think lib/dfe/analytics/shared/service_pattern.rb should be changed to:

# a template for creating service objects
module DfE
  module Analytics
    module Shared
      module ServicePattern
        # ...
      end
    end
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant