Sha256: faacfb6f9a2d9f08871d60b79201cd7e7a997cb9b15aaa0644762f6369ddf778
Contents?: true
Size: 742 Bytes
Versions: 2
Compression:
Stored size: 742 Bytes
Contents
# frozen_string_literal: true module IIPolicy module Core extend ActiveSupport::Concern included do attr_reader :context, :user, :item, :_result end def initialize(context = {}) @context = if context.is_a?(IIPolicy::Context) context else IIPolicy::Context.new(context) end @item = @context.item @user = @context.user end def call(action) if respond_to?(action) && !send(action) @_result = false else @_result = true end end def allowed(action) call(action) end def policy(item) context = @context.dup context.item = item self.class.lookup(item).new(context) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
ii_policy-2.0.0 | lib/ii_policy/core.rb |
ii_policy-1.1.0 | lib/ii_policy/core.rb |