Sha256: 871818ef1b587f35dc3ea2929776936bd96b3954b6563d581f9253ea66591ef1

Contents?: true

Size: 1.13 KB

Versions: 17

Compression:

Stored size: 1.13 KB

Contents

require 'flipper/ui/action'
require 'flipper/ui/decorators/feature'

module Flipper
  module UI
    module Actions
      class Gate < UI::Action
        route %r{features/[^/]*/[^/]*/?\Z}

        def post
          feature_name, gate_name = request.path.split('/').pop(2)
                                           .map(&Rack::Utils.method(:unescape))
          update_gate_method_name = "update_#{gate_name}"

          feature = flipper[feature_name.to_sym]
          @feature = Decorators::Feature.new(feature)

          if respond_to?(update_gate_method_name, true)
            send(update_gate_method_name, feature)
          else
            update_gate_method_undefined(gate_name)
          end

          redirect_to "/features/#{@feature.key}"
        end

        private

        # Private: Returns error response that gate update method is not defined.
        def update_gate_method_undefined(gate_name)
          error = Rack::Utils.escape(
            "#{gate_name.inspect} gate does not exist therefore it cannot be updated."
          )
          redirect_to("/features/#{@feature.key}?error=#{error}")
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
flipper-ui-0.15.0 lib/flipper/ui/actions/gate.rb
flipper-ui-0.14.0 lib/flipper/ui/actions/gate.rb
flipper-ui-0.13.0 lib/flipper/ui/actions/gate.rb
flipper-ui-0.13.0.beta1 lib/flipper/ui/actions/gate.rb
flipper-ui-0.12.2 lib/flipper/ui/actions/gate.rb
flipper-ui-0.12.1 lib/flipper/ui/actions/gate.rb
flipper-ui-0.12.0 lib/flipper/ui/actions/gate.rb
flipper-ui-0.11.0 lib/flipper/ui/actions/gate.rb
flipper-ui-0.11.0.rc1 lib/flipper/ui/actions/gate.rb
flipper-ui-0.11.0.beta9 lib/flipper/ui/actions/gate.rb
flipper-ui-0.11.0.beta8 lib/flipper/ui/actions/gate.rb
flipper-ui-0.11.0.beta7 lib/flipper/ui/actions/gate.rb
flipper-ui-0.11.0.beta6 lib/flipper/ui/actions/gate.rb
flipper-ui-0.11.0.beta5 lib/flipper/ui/actions/gate.rb
flipper-ui-0.11.0.beta4 lib/flipper/ui/actions/gate.rb
flipper-ui-0.11.0.beta3 lib/flipper/ui/actions/gate.rb
flipper-ui-0.11.0.beta1 lib/flipper/ui/actions/gate.rb