Sha256: 29040bd11687eb9eb8726d44c92ac2bfbc58d42e96e60c9624d88bef611457be

Contents?: true

Size: 844 Bytes

Versions: 23

Compression:

Stored size: 844 Bytes

Contents

require "delegate"

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

      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
        warn "[DEPRECATION] `#{self.class.name}#to_agent` is deprecated. Use `#{self.class.name}#agent instead."
        agent
      end

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

    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
ddr-models-2.3.2 lib/ddr/auth/group.rb
ddr-models-2.3.1 lib/ddr/auth/group.rb
ddr-models-2.3.0 lib/ddr/auth/group.rb
ddr-models-2.2.0 lib/ddr/auth/group.rb
ddr-models-2.1.3 lib/ddr/auth/group.rb
ddr-models-2.1.2 lib/ddr/auth/group.rb
ddr-models-2.1.1 lib/ddr/auth/group.rb
ddr-models-2.1.0 lib/ddr/auth/group.rb
ddr-models-2.1.0.rc2 lib/ddr/auth/group.rb
ddr-models-2.1.0.rc1 lib/ddr/auth/group.rb
ddr-models-2.0.1 lib/ddr/auth/group.rb
ddr-models-2.0.0 lib/ddr/auth/group.rb
ddr-models-2.0.0.rc6 lib/ddr/auth/group.rb
ddr-models-2.0.0.rc5 lib/ddr/auth/group.rb
ddr-models-2.0.0.rc4 lib/ddr/auth/group.rb
ddr-models-2.0.0.rc3 lib/ddr/auth/group.rb
ddr-models-2.0.0.rc2 lib/ddr/auth/group.rb
ddr-models-2.0.0.rc1 lib/ddr/auth/group.rb
ddr-models-2.0.0.pre.5 lib/ddr/auth/group.rb
ddr-models-2.0.0.pre.4 lib/ddr/auth/group.rb