-
Notifications
You must be signed in to change notification settings - Fork 41
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
Modules not isolated, rely on foreknowledge of includer #371
Comments
This is a common pattern in Rails: https://github.com/rails/rails/blob/master/activerecord/lib/active_record/callbacks.rb#L292 And it was my impression that those programmers knew more than I did, so I copied them. I agree it's not the best, but I don't have the inclination or time to refactor it. Patches welcome! |
@jcoyne, that isn't comparable. module ClassMethods # :nodoc:
include ActiveModel::Callbacks
end
included do
include ActiveModel::Validations::Callbacks
define_model_callbacks :initialize, :find, :touch, only: :after
define_model_callbacks :save, :create, :update, :destroy
end Now that is obfuscated and heavy on meta-programming, but isn't unmodular. But by the time it calls define_model_callbacks :initialize, :find, :touch Given the context, we can tell that ends up here: It does not rely on the includer having already defined |
@jcoyne Have I described it clearly enough? Do you agree this is not just a "nice to have", but actually a flaw in design? |
See also: projectblacklight/blacklight#1588 |
How does a module with no ancestors call
super
in a method? (Multiple methods.)Example:
https://github.com/projecthydra/hydra-head/blob/master/hydra-access-controls/lib/hydra/policy_aware_access_controls_enforcement.rb#L9
I know this recurs generally in the Hydra stack but it is bad design. The module doesn't check at include time whether its needs are met and the includer shouldn't be forced to debug runtime errors or monkey-patch the module to inject its dependencies (in this case blacklight access controls enforcement).
This is not the composition pattern that was intended.
The text was updated successfully, but these errors were encountered: