Skip to content

Commit 622099a

Browse files
committed
Do not load ActiveRecord at require time
The last version removed the on_load wrapper, making flipper load ActiveRecord immediately whenever flipper is required. This causes some issues with other gems that setup their own behavior using `on_load`. This reintroduces the on_load wrapper around the database models, which by inheriting from ActiveRecord::Base were causing ActiveRecord to be loaded at require time.
1 parent fcb554c commit 622099a

1 file changed

Lines changed: 24 additions & 22 deletions

File tree

lib/flipper/adapters/active_record.rb

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,35 @@ module Adapters
88
class ActiveRecord
99
include ::Flipper::Adapter
1010

11-
class Model < ::ActiveRecord::Base
12-
self.abstract_class = true
13-
end
11+
ActiveSupport.on_load(:active_record) do
12+
class Model < ::ActiveRecord::Base
13+
self.abstract_class = true
14+
end
1415

15-
# Private: Do not use outside of this adapter.
16-
class Feature < Model
17-
self.table_name = [
18-
Model.table_name_prefix,
19-
"flipper_features",
20-
Model.table_name_suffix,
21-
].join
16+
# Private: Do not use outside of this adapter.
17+
class Feature < Model
18+
self.table_name = [
19+
Model.table_name_prefix,
20+
"flipper_features",
21+
Model.table_name_suffix,
22+
].join
2223

23-
has_many :gates, foreign_key: "feature_key", primary_key: "key"
24+
has_many :gates, foreign_key: "feature_key", primary_key: "key"
2425

25-
validates :key, presence: true
26-
end
26+
validates :key, presence: true
27+
end
2728

28-
# Private: Do not use outside of this adapter.
29-
class Gate < Model
30-
self.table_name = [
31-
Model.table_name_prefix,
32-
"flipper_gates",
33-
Model.table_name_suffix,
34-
].join
29+
# Private: Do not use outside of this adapter.
30+
class Gate < Model
31+
self.table_name = [
32+
Model.table_name_prefix,
33+
"flipper_gates",
34+
Model.table_name_suffix,
35+
].join
3536

36-
validates :feature_key, presence: true
37-
validates :key, presence: true
37+
validates :feature_key, presence: true
38+
validates :key, presence: true
39+
end
3840
end
3941

4042
VALUE_TO_TEXT_WARNING = <<-EOS

0 commit comments

Comments
 (0)