Sha256: 9e87ec453c72a54baceb7d09472031ab140d063735255b61ec305c2408b9b521

Contents?: true

Size: 590 Bytes

Versions: 9

Compression:

Stored size: 590 Bytes

Contents

require "delegate"

module Ddr
  module Auth
    # Wraps a String
    class Group < SimpleDelegator

      attr_reader :label

      def initialize(name, opts={})
        super(name)
        @label = opts.fetch(:label, name)
        freeze
      end

      # The inverse of `Ddr::Auth::User#member_of?(group)`
      def has_member?(user)
        user.groups.include?(self)
      end

      def to_agent
        to_s
      end
      alias_method :agent, :to_agent

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

    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

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