Sha256: 3f2b049679ec0c4c505b2e6103d8ca2e069d1d2c3b3d45c474a79548aeafad62

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

module Insales::Controller
  module BaseHelpers
    extend ActiveSupport::Concern

    included do
      class_attribute :insales_config
      self.insales_config = {
        account_class: '::Account',
        insales_app_class: '::InsalesApi::App',
        login_path: 'login_path',
        success_login_path: 'account_path',
      }

      def account_class
        @account_class ||= insales_config[:account_class].constantize
      end

      def insales_app_class
        @insales_app_class ||= insales_config[:insales_app_class].constantize
      end

      def insales_login_path
        send(insales_config[:login_path])
      end

      def insales_success_login_path
        send(insales_config[:success_login_path])
      end
    end

    protected

    delegate :insales_app_class, :account_class,
             :insales_login_path, :insales_success_login_path,
             to: :class

    def store_location(path = request.url)
      session[:return_to] = path
    end

    def stored_location
      session.delete(:return_to)
    end

    def find_account_by_request
      if params[:insales_id]
        account_class.find_by_insales_id(params[:insales_id])
      elsif params[:domain]
        account_class.find_by_insales_domain(params[:domain])
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
insales_api-0.2.0 lib/insales/controller/base_helpers.rb