Sha256: ae3056525b30e3226aa52e9197fab8b25584bdd9f93f6801a07781a727cfc07b

Contents?: true

Size: 1.13 KB

Versions: 10

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

module RedisWebManager
  class ApplicationController < ActionController::Base
    protect_from_forgery with: :exception

    before_action :authenticated?, if: :authenticate
    before_action :valid_instance?
    helper_method :redises
    helper_method :instance

    private

    def authenticated?
      instance_exec(&authenticate)
    end

    def authenticate
      RedisWebManager.authenticate
    end

    def info
      @info ||= RedisWebManager::Info.new(instance)
    end

    def connection
      @connection ||= RedisWebManager::Connection.new(instance)
    end

    def action
      @action ||= RedisWebManager::Action.new(instance)
    end

    def data
      @data ||= RedisWebManager::Data.new(instance)
    end

    def default_url_options(options = {})
      options.merge(instance: instance)
    end

    def valid_instance?
      default_instance = redises.keys[0]
      redirect_to dashboard_url(instance: default_instance) if instance.nil?
    end

    def instance
      @instance ||= params[:instance].presence
    end

    def redises
      @redises ||= RedisWebManager.redises
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
redis_web_manager-0.4.0 app/controllers/redis_web_manager/application_controller.rb
redis_web_manager-0.3.9 app/controllers/redis_web_manager/application_controller.rb
redis_web_manager-0.3.8 app/controllers/redis_web_manager/application_controller.rb
redis_web_manager-0.3.6 app/controllers/redis_web_manager/application_controller.rb
redis_web_manager-0.3.5 app/controllers/redis_web_manager/application_controller.rb
redis_web_manager-0.3.4 app/controllers/redis_web_manager/application_controller.rb
redis_web_manager-0.3.3 app/controllers/redis_web_manager/application_controller.rb
redis_web_manager-0.3.2 app/controllers/redis_web_manager/application_controller.rb
redis_web_manager-0.3.1 app/controllers/redis_web_manager/application_controller.rb
redis_web_manager-0.3.0 app/controllers/redis_web_manager/application_controller.rb