lib/flipper/adapters/sequel.rb in flipper-sequel-0.10.1 vs lib/flipper/adapters/sequel.rb in flipper-sequel-0.10.2
- old
+ new
@@ -70,26 +70,21 @@
#
# Returns a Hash of Flipper::Gate#key => value.
def get(feature)
db_gates = @gate_class.where(feature_key: feature.key.to_s).all
- 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
- 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
+ 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 }
+ result = {}
+ features.each do |feature|
+ result[feature.key] = result_for_feature(feature, grouped_db_gates[feature.key])
end
+ result
end
# Public: Enables a gate for a given thing.
#
# feature - The Flipper::Feature for the gate.
@@ -159,9 +154,29 @@
{
feature_key: feature.key.to_s,
key: gate.key.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
+ 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