2020-02-15 01:09:11 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module API
|
|
|
|
module Entities
|
|
|
|
class Feature < Grape::Entity
|
|
|
|
expose :name
|
|
|
|
expose :state
|
|
|
|
expose :gates, using: Entities::FeatureGate do |model|
|
|
|
|
model.gates.map do |gate|
|
|
|
|
value = model.gate_values[gate.key]
|
|
|
|
|
|
|
|
# By default all gate values are populated. Only show relevant ones.
|
2020-08-05 11:09:59 -04:00
|
|
|
if (value.is_a?(Integer) && value == 0) || (value.is_a?(Set) && value.empty?)
|
2020-02-15 01:09:11 -05:00
|
|
|
next
|
|
|
|
end
|
|
|
|
|
|
|
|
{ key: gate.key, value: value }
|
|
|
|
end.compact
|
|
|
|
end
|
2020-11-18 22:08:59 -05:00
|
|
|
|
|
|
|
class Definition < Grape::Entity
|
|
|
|
::Feature::Definition::PARAMS.each do |param|
|
|
|
|
expose param
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :definition, using: Definition do |feature|
|
|
|
|
::Feature::Definition.definitions[feature.name.to_sym]
|
|
|
|
end
|
2020-02-15 01:09:11 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|