Sha256: aa70415c083155c01a569e6bea53a25ee94d57619850391970e8ef7885d4efbf

Contents?: true

Size: 1.1 KB

Versions: 4

Compression:

Stored size: 1.1 KB

Contents

require 'flipper/ui/action'
require 'flipper/ui/actor'
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{ |value| Rack::Utils.unescape value }
          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

4 entries across 4 versions & 1 rubygems

Version Path
flipper-ui-0.7.0.beta4 lib/flipper/ui/actions/gate.rb
flipper-ui-0.2.0.beta5 lib/flipper/ui/actions/gate.rb
flipper-ui-0.2.0.beta4 lib/flipper/ui/actions/gate.rb
flipper-ui-0.2.0.beta3 lib/flipper/ui/actions/gate.rb