Sha256: 1eeb2c1421a97c7a9e65c025a6b5255d91aaae3d1cb0969950c99500287eecd8

Contents?: true

Size: 917 Bytes

Versions: 9

Compression:

Stored size: 917 Bytes

Contents

module Ddr
  module Auth
    # @abstract
    class Affiliation < SimpleDelegator

      private_class_method :new

      VALUES = %w( faculty staff student emeritus affiliate alumni ).freeze

      VALUES.each do |value|
        const_set(value.capitalize, new(value).freeze)
      end

      def group
        Group.new(group_name, label: label)
      end

      def label
        "Duke #{capitalize}"
      end

      def group_name
        "duke.#{self}"
      end

      def inspect
        "#<#{self.class.name}(#{__getobj__.inspect})>"
      end

      class << self
        def all
          @all ||= VALUES.map { |value| get(value) }
        end

        def get(affiliation)
          const_get(affiliation.capitalize)
        end

        def group(affiliation)
          get(affiliation).group
        end

        def groups
          @groups ||= all.map(&:group)
        end
      end

    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
ddr-models-1.17.1 lib/ddr/auth/affiliation.rb
ddr-models-1.17.0 lib/ddr/auth/affiliation.rb
ddr-models-1.16.2 lib/ddr/auth/affiliation.rb
ddr-models-1.16.1 lib/ddr/auth/affiliation.rb
ddr-models-1.16.0 lib/ddr/auth/affiliation.rb
ddr-models-1.15.0 lib/ddr/auth/affiliation.rb
ddr-models-1.14.2 lib/ddr/auth/affiliation.rb
ddr-models-1.14.1 lib/ddr/auth/affiliation.rb
ddr-models-1.14.0 lib/ddr/auth/affiliation.rb