Sha256: a91a1c853ba379ed89474f409c0f77c3859406fda4d288729885499043890e02

Contents?: true

Size: 766 Bytes

Versions: 10

Compression:

Stored size: 766 Bytes

Contents

require "delegate"

module Ddr
  module Auth
    module Roles
      class Query < SimpleDelegator

        def initialize(role_set)
          super(role_set.to_a)
        end

        def where(criteria)
          matching = select do |role|
            criteria.all? do |key, value|
              send("any_#{key}?", value, role)
            end
          end
          __setobj__(matching)
          self
        end

        private

        def any_scope?(scopes, role)
          Array(scopes).include? role.scope.first
        end

        def any_type?(types, role)
          Array(types).include? role.role_type.first
        end

        def any_agent?(agents, role)
          Array(agents).include? role.agent.first
        end

      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

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