Features aren't declared until Feature model has been required.
Opened this issue · 4 comments
Only tested in development, but until the Feature model has been loaded, any call to a Flip.on? :blarg
will raise No feature declared with key :blarg
.
If you simply place require 'feature'
before a call, then the problem will go away (even for subsequent requests AFTER removing the require 'feature'
line).
Is it easy enough to include a load method in Flip, which checks for initialization and requires 'feature' if it's not available?
I've run into this problem too, since renaming the accessor class to Flip but leaving the model class as Feature.
It makes me think that declaring the features inside the Feature < ActiveRecord::Base
class is totally wrong.. especially as DatabaseStrategy
is just one optional strategy.
I'm thinking of moving the declarations into an initializer, or a config file loaded by an initializer. I guess in the mean time it's possible to create a config/initializers/flip.rb
which loads app/models/feature.rb
, but it doesn't feel like an ideal solution.
That's what I was thinking but then you'd need to reload the server on new features correct? That's not that big an issue.
There wouldn't be an issue with getting the current declaration back with an initializer would there, it could still be changed and the strategy could be changed on the fly right?
Do you reckon this is a real pain point or have you guys found reasonable workarounds? I'm just trolling your project while I figure out how much work it would be to have it support other ORMs and send a PR.
O/T but do you think this could also be used to facilitate A/B testing (like a strategy that gives users a 50% chance of seeing a feature; maybe even based on something like the last octet of the IP address being odd or even).
The Feature
model could be loaded in a Railtie.