Sha256: d02f788078d10b387dccef39e8edd502731ae248d009b6d30ce98c251be2a76c

Contents?: true

Size: 1.41 KB

Versions: 7

Compression:

Stored size: 1.41 KB

Contents

module FeatureGate
  class GatedFeaturesController < ApplicationController
    before_filter :ensure_feature_gate_control_allowed
    layout 'feature_gate/application'

    def index
      @closed_gates = FeatureGate::GatedFeature.closed
      @opened_gates = FeatureGate::GatedFeature.opened
      @stale_gates = FeatureGate::GatedFeature.stale.order(:updated_at)
    end

    def update
      gate = FeatureGate::GatedFeature.find(params[:id])
      if params[:gated] == 'true'
        gate.gate_feature!
        flash[:notice] = "#{gate.name} has been gated"
      else
        gate.deploy_feature!
        flash[:success] = "#{gate.name} is live!"
      end

      redirect_to gated_features_path
    end

    def destroy
      gate = FeatureGate::GatedFeature.find(params[:id])
      if gate.destroyable?
        gate.destroy!
        flash[:success] = "#{gate.name} has been deleted"
      else
        flash[:error] = "#{gate.name} is currently being used in the codebase, execute `feature_gate_cleaner #{gate.name}` in the terminal to remove all references to #{gate.name}"
      end

      redirect_to gated_features_path
    end

    private

    define_method(:feature_gate_control_allowed?) do
      true
    end unless method_defined? :feature_gate_control_allowed?

    def ensure_feature_gate_control_allowed
      return if feature_gate_control_allowed?
      raise ActionController::RoutingError.new('Not Found')
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
feature_gate-0.2.6 app/controllers/feature_gate/gated_features_controller.rb
feature_gate-0.2.5 app/controllers/feature_gate/gated_features_controller.rb
feature_gate-0.2.4 app/controllers/feature_gate/gated_features_controller.rb
feature_gate-0.2.3 app/controllers/feature_gate/gated_features_controller.rb
feature_gate-0.2.2 app/controllers/feature_gate/gated_features_controller.rb
feature_gate-0.2.1 app/controllers/feature_gate/gated_features_controller.rb
feature_gate-0.2.0 app/controllers/feature_gate/gated_features_controller.rb