Sha256: 3bd63e2c65741ea141ecb09cbb0144cbb867716fb2c3ad43c10052d3dbb5c242
Contents?: true
Size: 1.16 KB
Versions: 3
Compression:
Stored size: 1.16 KB
Contents
# frozen_string_literal: true require "singleton" require "yaml" module Miau class PolicyRun include Singleton # return method[s] # klass and action are symbols # Priority: # - method of <klass>Policy # - method of <klass>Policy specified by "miau action, method" # - method of ApplicationPolicy (independent of klass) # - method of ApplicationPolicy specified by "miau action, method" # - nil # returns method_name[s] def find_methods(policy, klass, action) return action if policy.respond_to?(action) hsh = PolicyStorage.instance.policies[klass] return nil unless hsh hsh[action] end def runs(policy, actions) [actions].flatten.each { |action| raise_undef(policy, action) unless policy&.respond_to?(action) return false unless policy.send(action) } true end def raise_undef(policy, action) msg = "policy <#{policy}> action <#{action}>" raise NotDefinedError, msg end def raise_authorize(controller, action) msg = "controller <#{controller}> action <#{action}>" raise NotAuthorizedError, msg end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
miau-1.1.10 | lib/miau/run.rb |
miau-1.1.8 | lib/miau/run.rb |
miau-1.1.7 | lib/miau/run.rb |