Sha256: 2619b95992a6eaba72336d16722f1b65a994fbfd0fc15067b352e855b53ae371

Contents?: true

Size: 1.3 KB

Versions: 10

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

require "singleton"

module Glossarist
  class Config
    include Singleton

    DEFAULT_CLASSES = {
      localized_concept: Glossarist::LocalizedConcept,
      managed_concept: Glossarist::ManagedConcept,
    }.freeze

    attr_reader :registered_classes

    def initialize
      if File.exist?("glossarist.yaml")
        @config = YAML.load_file("glossarist.yaml")
      end

      @config ||= {}

      @registered_classes = DEFAULT_CLASSES.dup
      @extension_attributes = @config["extension_attributes"] || []
    end

    def class_for(name)
      @registered_classes[name.to_sym]
    end

    def register_class(class_name, klass)
      @registered_classes[class_name.to_sym] = klass
    end

    def extension_attributes
      @extension_attributes
    end

    def register_extension_attributes(attributes)
      @extension_attributes = attributes
    end

    class << self
      def class_for(name)
        self.instance.class_for(name)
      end

      def extension_attributes
        self.instance.extension_attributes
      end

      def register_class(class_name, klass)
        self.instance.register_class(class_name, klass)
      end

      def register_extension_attributes(attributes)
        self.instance.register_extension_attributes(attributes)
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
glossarist-2.3.0 lib/glossarist/config.rb
glossarist-2.2.1 lib/glossarist/config.rb
glossarist-2.2.0 lib/glossarist/config.rb
glossarist-2.1.0 lib/glossarist/config.rb
glossarist-2.0.10 lib/glossarist/config.rb
glossarist-2.0.9 lib/glossarist/config.rb
glossarist-2.0.8 lib/glossarist/config.rb
glossarist-2.0.7 lib/glossarist/config.rb
glossarist-2.0.6 lib/glossarist/config.rb
glossarist-2.0.5 lib/glossarist/config.rb