Sha256: 1dee230f22610aef5e8f6950b8a47b15deee71907415ecf47f259fa58526041c

Contents?: true

Size: 711 Bytes

Versions: 1

Compression:

Stored size: 711 Bytes

Contents

module Ddr
  AdminSet = Struct.new(:code, :title, keyword_init: true) do

    def self.config
      @config ||= YAML.load_file(::File.expand_path('../../../config/aux/admin_set.yml', __dir__))
    end

    def self.keystore
      @keystore ||= Hash[config.map { |entry| [entry['code'], new(entry).freeze] }].freeze
    end

    def self.all
      keystore
    end

    def self.call(obj)
      find_by_code(obj.admin_set)
    end

    def self.find_by_code(code)
      return unless code

      keystore.fetch(code)

    rescue KeyError => _
      raise Ddr::NotFoundError, "AdminSet code '#{code}' not found."
    end

    def self.keys
      keystore.keys
    end

    def to_s
      title
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ddr-core-1.13.1 app/models/ddr/admin_set.rb