Sha256: d982320b04349b6ebd9f0b51abdb07ae0cc93bdd5e323c26b1a6e4cccc51c0b0

Contents?: true

Size: 1.78 KB

Versions: 1

Compression:

Stored size: 1.78 KB

Contents

module IAmICan
  module Permission
    module Helpers
      module Cls
        def _pms_definition_result(preds, obj, failed_items)
          prefix = 'Permission Definition Done'
          fail_msg = prefix + ", but #{failed_items} have been defined" if failed_items.present?
          raise Error, fail_msg if  config.strict_mode && fail_msg
          puts fail_msg || prefix unless ENV['ITEST']
          prefix.present?
        end

        def _to_store_permission(pred, obj, **options)
          return false if config.permission_model.exists?(pred, obj)
          config.permission_model.create!(pred: pred, **deconstruct_obj(obj), **options)
        end

        def pms_naming(pred, obj)
          config.permission_model.naming(pred, obj)
        end

        def deconstruct_obj(obj)
          config.permission_model.deconstruct_obj(obj)
        end

        def pms_of_defined_local_role(role_name)
          config.subject_model.defined_local_roles[role_name.to_sym]&.[](:permissions) || []
        end
      end

      module Ins
        def _pms_assignment_result(preds, obj, not_defined_items, covered_items = nil, strict_mode = false)
          prefix = 'Permission Assignment Done'
          msg1 = "#{not_defined_items} have not been defined or have been repeatedly assigned" if not_defined_items.present?
          msg2 = "#{covered_items} have been covered" if covered_items.present?
          fail_msg = prefix + ', but ' + [msg1, msg2].compact.join(', ') if msg1 || msg2
          raise Error, fail_msg if (strict_mode || config.strict_mode) && fail_msg
          puts fail_msg || prefix unless ENV['ITEST']
          prefix.present?
        end

        def pms_matched?(pms_name, plist)
          config.permission_model.matched?(pms_name, in: plist[:in])
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
i_am_i_can-3.0.0pre lib/i_am_i_can/permission/helpers.rb