Sha256: bc2319b01684345d7646cc8f2255203721bbde98d6dd1779bc24506d3418af5f

Contents?: true

Size: 843 Bytes

Versions: 55

Compression:

Stored size: 843 Bytes

Contents

require "delegate"

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

      attr_reader :rule

      def initialize(id, opts={}, &rule)
        super(id)
        @label = opts[:label]
        @rule = rule
        freeze
      end

      # @param user [Ddr::Auth::AuthContext]
      def has_member?(auth_context)
        rule ? instance_exec(auth_context, &rule) : auth_context.member_of?(self)
      end

      def id
        __getobj__
      end

      def label
        @label || id
      end

      def agent
        to_s
      end

      def to_agent
        Deprecation.warn(self.class, "`to_agent` is deprecated. Use `agent` instead.")
        agent
      end

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

    end
  end
end

Version data entries

55 entries across 55 versions & 1 rubygems

Version Path
ddr-models-2.11.0 lib/ddr/auth/group.rb
ddr-models-2.10.2 lib/ddr/auth/group.rb
ddr-models-2.10.1 lib/ddr/auth/group.rb
ddr-models-2.10.0 lib/ddr/auth/group.rb
ddr-models-2.10.0.rc2 lib/ddr/auth/group.rb
ddr-models-2.10.0.rc1 lib/ddr/auth/group.rb
ddr-models-2.9.2 lib/ddr/auth/group.rb
ddr-models-2.9.1 lib/ddr/auth/group.rb
ddr-models-2.9.0 lib/ddr/auth/group.rb
ddr-models-2.9.0.rc1 lib/ddr/auth/group.rb
ddr-models-2.8.0 lib/ddr/auth/group.rb
ddr-models-2.8.0.rc1 lib/ddr/auth/group.rb
ddr-models-2.7.6 lib/ddr/auth/group.rb
ddr-models-2.7.5 lib/ddr/auth/group.rb
ddr-models-2.7.4 lib/ddr/auth/group.rb
ddr-models-2.7.3 lib/ddr/auth/group.rb
ddr-models-2.7.2 lib/ddr/auth/group.rb
ddr-models-2.7.1 lib/ddr/auth/group.rb
ddr-models-2.7.0 lib/ddr/auth/group.rb
ddr-models-2.7.0.rc1 lib/ddr/auth/group.rb