-
Notifications
You must be signed in to change notification settings - Fork 87
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
Disable setting default_options hash directly #92
Comments
An alternative approach would be to configure the default behavior within the plugin itself, instead of having a default default_options. For instance, module Presence
def self.apply(attributes, option)
attributes.backend_class.include(self) if option != false
end
end In the previous example, if the user didn't specify anything, The only downside to this approach is that given the current implementation, there is no way to tell if the user specified Mobility.plugins.each do |name|
plugin = get_plugin_class(name)
plugin.apply(self, !options.has_key?(name), options[name])
end and change the method signature of apply to def self.apply(attributes, default, option) One advantage of this approach is it keeps the default behaviour of a plugin contained within the plugin itself. |
Yes I thought about that as one way to do it. The issue I have is that checking for
In a way, yes, but on the other hand it means looking at the So personally I prefer having a set of defaults in That said, the plugins are not consistent in the sense of true/false above. I think actually |
I see your point. Raising visibility to what options are enabled by default is important. One other approach you probably also considered was having Mobility.configure do |config|
config.default_options = {
cache: true,
dirty: false,
fallbacks: nil,
presence: true,
default: nil
}
end That way, it would be quite obvious how to configure mobility. The main downside to that approach is maintainability, as it makes it harder to change defaults per version, or guarantee that keys are set. |
Yes, that would be another way to do it. I'm worried like you said about maintainability though. If we use this approach, and in future release we have another plugin that should be on by default, we'll have the same problem again. |
Actually, looking at the plugins again, I remember now why The tricky thing is that with a plugin like fallbacks, you really have three different things you may want:
You could argue that the first case (disable the plugin altogether) can also be achieved by removing Mobility.plugins.each do |name|
plugin = get_plugin_class(name)
plugin.apply(self, options[name])
end However, this applies universally and you may just want to remove the fallbacks plugin from a particular model (say for debugging). So here The So this whole options thing is slightly more complicated than I'd like it to be, but after thinking about this quite a lot (and simplifying things quite a lot from 0.1 to 0.2) this is the most straightforward setup I've managed to come up with. At least, the application of plugins is very simple (the four lines of code pasted above). Sorry a bit of a digression... but if you have thoughts, interested to hear 😄 |
Context
Since 0.2.0, it has become possible to set
Mobility.default_options
which are merged into the options set whenevertranslates
is called on a Mobility model. However, the problem with this is that the "default" default_options is overridden if the user sets these options withMobility.default_options =
, which will typically disable "low-profile" plugins like presence and cache.Expected Behavior
Setting
Mobility.default_options =
raises an error and instructs the user to set options by their key, e.g.:Actual Behavior
Mobility allows default options to be overridden entirely, implicitly disabling any options which were previously
true
but now arenil
.Possible Fix
Add a deprecation warning on the setter in 0.3.0, and remove thereafter.
The text was updated successfully, but these errors were encountered: