Sha256: 978839ca13db432d1af0bb70c688370e1d4d9181f40bf038a0b78f5546ea99aa

Contents?: true

Size: 1.44 KB

Versions: 5

Compression:

Stored size: 1.44 KB

Contents

module ConfigManager
	class TogglesController < ConfigManager::ApplicationController
  	# GET /toggles
  	def index
  		@toggles = Toggle.toggles
  		@toggle = Toggles::Definition.new(params[:toggle_name])
  	end

		# POST /toggles
  	def create
  		@toggle = Toggle.create(params[:toggle])	
			if @toggle.valid?	
				flash[:notice] = "Toggle successfully created/updated"
			else
				flash[:error] = "Failed to create/update toggle: #{@toggle.message}"
			end
  		redirect_to toggles_url

  	rescue 
  		Rails.logger.error "Error raised trying to create/update toggle. #{$!}. #{$!.backtrace.take(3)}"
  		flash[:error] = "Error raised trying to create/update toggle: #{$!}"
  		redirect_to toggles_url
  	end

  	# DELETE /toggles/:id
  	def destroy
  		Toggle.delete(params[:id])
  		flash[:notice] = "#{params[:id]} has been deleted!"

  		redirect_to toggles_url
  	end

  	# POST /toggles/load
  	def load
			if params[:file]
				loads, failures = Toggle.from_yaml(params[:file].tempfile)
				flash[:notice] = "#{loads} toggles have been loaded from the yaml file." if loads > 0
				flash[:error] = "#{failures} toggles failed to be loaded from the yaml file" if failures > 0
			else
				flash[:error] = "You must choose a file"
			end
		rescue 
  		flash[:error] = "Couldn't load toggles. Did you choose a valid file?"
  	ensure
  		redirect_to toggles_url
  	end

  	# POST /toggles/dump
  	def dump
  		send_data Toggle.to_yaml, :filename => 'toggles.yml'
		end
	end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
config_manager-1.0.4 app/controllers/config_manager/toggles_controller.rb
config_manager-1.0.3 app/controllers/config_manager/toggles_controller.rb
config_manager-1.0.2 app/controllers/config_manager/toggles_controller.rb
config_manager-1.0.0 app/controllers/config_manager/toggles_controller.rb
config_manager-0.0.10 app/controllers/config_manager/toggles_controller.rb