Sha256: b3f7ad9d501a0ec82e83814446fa643f9462b883c4b8ccbebc7ee94593a2793a

Contents?: true

Size: 1.65 KB

Versions: 5

Compression:

Stored size: 1.65 KB

Contents

# frozen_string_literal: true

module Signum
  module Options
    module ClassMethods
      def option(name, default: nil)
        attr_accessor(name)

        schema[name] = default
      end

      def schema
        @schema ||= {}
      end
    end

    def set_defaults!
      self.class.schema.each do |name, default|
        instance_variable_set("@#{name}", default)
      end
    end

    def self.included(cls)
      cls.extend(ClassMethods)
    end
  end

  class Configuration
    include Options

    option :logger, default: Rails.logger
    option :user_model_name, default: 'User'
    option :hide_after, default: 3000
    option :base_controller, default: '::ApplicationController'
    option :base_service, default: '::ApplicationService'
    option :base_service_context, default: '::ApplicationContext'
    option :current_user, default: -> {}
    option :drawer_notifications_container_id, default: -> {}
    option :balloon_notifications_container_id, default: -> {}
    option :icons,
           default: { info: 'fa-solid fa-circle-info fa-lg',
                      error: 'fa-solid fa-square-xmark fa-lg',
                      success: 'fa-solid fa-circle-check fa-lg',
                      warning: 'fa-solid fa-triangle-exclamation fa-lg',
                      unread_main: 'fa-solid fa-bell-ring',
                      read_main: 'fa-solid fa-bell' }

    def initialize
      set_defaults!
    end
  end

  module Configurable
    attr_writer :config

    def config
      @config ||= Configuration.new
    end

    def configure
      yield(config)
    end
    alias setup configure

    def reset_config!
      @config = Configuration.new
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
signum-0.4.13 lib/signum/configuration.rb
signum-0.4.12 lib/signum/configuration.rb
signum-0.4.11 lib/signum/configuration.rb
signum-0.4.10 lib/signum/configuration.rb
signum-0.4.8 lib/signum/configuration.rb