Sha256: 9192a2ed7a89885bd06cda665f3948fa9df4baaf03084992eef05e8f83c146bc

Contents?: true

Size: 1.16 KB

Versions: 15

Compression:

Stored size: 1.16 KB

Contents

require 'flipper/api/action'
require 'flipper/api/v1/decorators/feature'

module Flipper
  module Api
    module V1
      module Actions
        class PercentageOfTimeGate < Api::Action
          include FeatureNameFromRoute

          route %r{\A/features/(?<feature_name>.*)/percentage_of_time/?\Z}

          def post
            if percentage < 0 || percentage > 100
              json_error_response(:percentage_invalid)
            end

            feature = flipper[feature_name]
            feature.enable_percentage_of_time(percentage)
            decorated_feature = Decorators::Feature.new(feature)
            json_response(decorated_feature.as_json, 200)
          end

          def delete
            feature = flipper[feature_name]
            feature.disable_percentage_of_time

            decorated_feature = Decorators::Feature.new(feature)
            json_response(decorated_feature.as_json, 200)
          end

          private

          def percentage
            @percentage ||= begin
              Integer(params['percentage'])
            rescue ArgumentError, TypeError
              -1
            end
          end
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
flipper-api-0.20.3 lib/flipper/api/v1/actions/percentage_of_time_gate.rb
flipper-api-0.20.2 lib/flipper/api/v1/actions/percentage_of_time_gate.rb
flipper-api-0.20.1 lib/flipper/api/v1/actions/percentage_of_time_gate.rb
flipper-api-0.20.0 lib/flipper/api/v1/actions/percentage_of_time_gate.rb
flipper-api-0.20.0.beta3 lib/flipper/api/v1/actions/percentage_of_time_gate.rb
flipper-api-0.20.0.beta2 lib/flipper/api/v1/actions/percentage_of_time_gate.rb
flipper-api-0.20.0.beta1 lib/flipper/api/v1/actions/percentage_of_time_gate.rb
flipper-api-0.19.1 lib/flipper/api/v1/actions/percentage_of_time_gate.rb
flipper-api-0.19.0 lib/flipper/api/v1/actions/percentage_of_time_gate.rb
flipper-api-0.18.0 lib/flipper/api/v1/actions/percentage_of_time_gate.rb
flipper-api-0.17.2 lib/flipper/api/v1/actions/percentage_of_time_gate.rb
flipper-api-0.17.1 lib/flipper/api/v1/actions/percentage_of_time_gate.rb
flipper-api-0.16.2 lib/flipper/api/v1/actions/percentage_of_time_gate.rb
flipper-api-0.16.1 lib/flipper/api/v1/actions/percentage_of_time_gate.rb
flipper-api-0.16.0 lib/flipper/api/v1/actions/percentage_of_time_gate.rb