lib/flipper/adapters/sequel.rb in flipper-sequel-0.10.2 vs lib/flipper/adapters/sequel.rb in flipper-sequel-0.11.0.beta1

- old
+ new

@@ -7,15 +7,19 @@ class Sequel include ::Flipper::Adapter # Private: Do not use outside of this adapter. class Feature < ::Sequel::Model(:flipper_features) + unrestrict_primary_key + plugin :timestamps, update_on_create: true end # Private: Do not use outside of this adapter. class Gate < ::Sequel::Model(:flipper_gates) + unrestrict_primary_key + plugin :timestamps, update_on_create: true end # Public: The name of the adapter. attr_reader :name @@ -75,11 +79,11 @@ result_for_feature(feature, db_gates) end def get_multi(features) db_gates = @gate_class.where(feature_key: features.map(&:key)).to_a - grouped_db_gates = db_gates.group_by { |gate| gate.feature_key } + grouped_db_gates = db_gates.group_by(&:feature_key) result = {} features.each do |feature| result[feature.key] = result_for_feature(feature, grouped_db_gates[feature.key]) end result @@ -96,11 +100,11 @@ case gate.data_type when :boolean, :integer @gate_class.db.transaction do args = { feature_key: feature.key, - key: gate.key.to_s + key: gate.key.to_s, } @gate_class.where(args).delete @gate_class.create(gate_attrs(feature, gate, thing)) end @@ -126,11 +130,11 @@ clear(feature) when :integer @gate_class.db.transaction do args = { feature_key: feature.key.to_s, - key: gate.key.to_s + key: gate.key.to_s, } @gate_class.where(args).delete @gate_class.create(gate_attrs(feature, gate, thing)) end @@ -152,30 +156,31 @@ def gate_attrs(feature, gate, thing) { feature_key: feature.key.to_s, key: gate.key.to_s, - value: thing.value.to_s + value: thing.value.to_s, } end def result_for_feature(feature, db_gates) db_gates ||= [] feature.gates.each_with_object({}) do |gate, result| - result[gate.key] = case gate.data_type - when :boolean - if db_gate = db_gates.detect { |db_gate| db_gate.key == gate.key.to_s } - db_gate.value + result[gate.key] = + case gate.data_type + when :boolean + if db_gate = db_gates.detect { |db_gate| db_gate.key == gate.key.to_s } + db_gate.value + end + when :integer + if db_gate = db_gates.detect { |db_gate| db_gate.key == gate.key.to_s } + db_gate.value + end + when :set + db_gates.select { |db_gate| db_gate.key == gate.key.to_s }.map(&:value).to_set + else + unsupported_data_type gate.data_type end - when :integer - if db_gate = db_gates.detect { |db_gate| db_gate.key == gate.key.to_s } - db_gate.value - end - when :set - db_gates.select { |db_gate| db_gate.key == gate.key.to_s }.map(&:value).to_set - else - unsupported_data_type gate.data_type - end end end end end end