Sha256: 1e7505081e329ebe728cf62c552873633247544ec1e684aa2b2347bb380a1934

Contents?: true

Size: 1.17 KB

Versions: 10

Compression:

Stored size: 1.17 KB

Contents

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

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

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

          def post
            feature = flipper[feature_name]

            begin
              expression = Flipper::Expression.build(expression_hash)
              feature.enable_expression expression
              decorated_feature = Decorators::Feature.new(feature)
              json_response(decorated_feature.as_json, 200)
            rescue NameError, ArgumentError => exception
              json_error_response(:expression_invalid)
            end
          end

          def delete
            feature = flipper[feature_name]
            feature.disable_expression

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

          private

          def expression_hash
            @expression_hash ||= request.env["parsed_request_body".freeze] || {}.freeze
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
flipper-api-1.3.2 lib/flipper/api/v1/actions/expression_gate.rb
flipper-api-1.3.1 lib/flipper/api/v1/actions/expression_gate.rb
flipper-api-1.3.0 lib/flipper/api/v1/actions/expression_gate.rb
flipper-api-1.3.0.pre lib/flipper/api/v1/actions/expression_gate.rb
flipper-api-1.2.2 lib/flipper/api/v1/actions/expression_gate.rb
flipper-api-1.2.1 lib/flipper/api/v1/actions/expression_gate.rb
flipper-api-1.2.0 lib/flipper/api/v1/actions/expression_gate.rb
flipper-api-1.1.2 lib/flipper/api/v1/actions/expression_gate.rb
flipper-api-1.1.1 lib/flipper/api/v1/actions/expression_gate.rb
flipper-api-1.1.0 lib/flipper/api/v1/actions/expression_gate.rb