0.0
No commit activity in last 3 years
No release in over 3 years
At times we would want to block certain requests. SafetyCone allows this to be controlled from an interface. It also provides a feature flipper for the views.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

<= 5.1.4
>= 3.3.3, ~> 3.3
 Project Readme

safety cone logo

SafetyCone Gem Version

Safety Cone is a Rails gem that allows you to temporarily add warnings or block requests to specific pages through a simple interface. It also provides a feature flipper.

Installation

Add this line to your application's Gemfile:

gem 'safety_cone'

And then execute:

$ bundle

Usage

Create a safety_cone.rb file in config/initializers. The routes that needs to be managed can be added to this config file.

$redis = Redis::Namespace.new("app_name", :redis => Redis.new)

SafetyCone.configure do |config|
  # Redis connection for safety_cone
  config.redis = $redis

  # Http auth username and password for Safety Cone admin page
  config.auth = { username: 'admin', password: 'admin-password' }

  # To allow Safety Cone to manage a single controller action
  config.add(
    controller: :registrations,
    action: :new,
    name: 'User Registration'
  )

  # To allow Safety Cone to manage all POST requests
  config.add(
    method: 'POST',
    name: 'All POST requests'
  )

  # Feature flipper
  config.add(
    feature: :record_search,
    name: 'Search'
  )

  # This config will provide a view helper record_search?
  # Which can be used in the view to display a div or not
end

In routes add

  mount SafetyCone::Engine, :as => '/safety_cone'

In ApplicationController

class ApplicationController < ActionController::Base
  protect_from_forgery

  # Add this line
  include SafetyCone::Filter
end

In View

<div class="container">
  <% if safetycone_notice %>
    <div class="notice"><%= safetycone_notice %></div>
  <% end %>
 
   <% if safetycone_alert %>
    <div class="alert"><%= safetycone_alert %></div>
  <% end %>

  <!-- Feature Flipper -->
  <% if record_search? %>
    <div>Search Records</div>
  <% end %>
</div>

Now you should be able to go to http://localhost:3000/safety_cone and manage your routes.

For version 0.1.0 users

This earlier version is not a mountable engine and it does not provide an admin interface. The configuration is as follows:

SafetyCone.configure do |config|
  # disables Safety Cone. By default this value is true
  config.enabled = false

  # This config will block all POST requests and display this message.
  config.add(
    method: :POST,
    message: 'We are unable to write any data to database now.',
    type: :block
  )

  # This is a controller action specific warning. But with no types to prevent this action
  config.add(
    controller: :users,
    action: :new,
    message: 'We are unable to register any user now. Please try after sometime.'
    type: :notice
  )

  # This is a controller action specific block. This config will let the application
  # to raise an alert message and block the request from hitting the controller action.
  config.add(
    controller: 'users',
    action: 'create',
    message: 'We are unable to register any user now. Please try after sometime.',
    type: :block
  )

  # This is a controller action specific block with a redirect configured.
  config.add(
    controller: 'users',
    action: 'create',
    message: 'We are unable to register any user now. Please try after sometime.',
    type: :block,
    redirect: '/page/more_info'
  )

  # For :block flash message is an alert
  # For :notice flash message is a notice
end

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

License

The gem is available as open source under the terms of the MIT License.