Sha256: 296fda5e4fa8716670ed0bda824cfa5488dadee6b1e4962f0c7f54141bea1f81

Contents?: true

Size: 1.23 KB

Versions: 2

Compression:

Stored size: 1.23 KB

Contents

require 'i_am_i_can/permission/helpers'
require 'i_am_i_can/permission/p_array'

module IAmICan
  module Permission
    module Definition
      include Helpers::Cls

      def have_permission *preds, obj: nil, desc: nil, save: i_am_i_can.default_save
        failed_items = [ ]

        preds.each do |pred|
          pms_name = pms_naming(pred, obj)
          description = desc || pms_name.to_s.tr('_', ' ')
          if save
            failed_items << pms_name unless _to_store_permission(pred, obj, desc: description)
          else
            failed_items << pms_name if pms_name.in?(defined_local_permissions.keys)
            defined_local_permissions[pms_name] ||= { desc: description }
          end
        end

        _pms_definition_result(preds, obj, failed_items)
      end

      alias have_permissions have_permission
      alias has_permission   have_permission
      alias has_permissions  have_permission

      def declare_permission *preds, **options
        have_permission *preds, **options, save: false
      end

      alias declare_permissions declare_permission

      def self.extended(kls)
        kls.delegate :defined_permissions, :pms_naming, :deconstruct_obj, :pms_of_defined_local_role, to: kls
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
i_am_i_can-3.0.1 lib/i_am_i_can/permission/definition.rb
i_am_i_can-3.0.0 lib/i_am_i_can/permission/definition.rb