Sha256: b49f261f31e34cb8454a602581d725da912205d91ff124254dc18912c73339aa

Contents?: true

Size: 852 Bytes

Versions: 26

Compression:

Stored size: 852 Bytes

Contents

class Dorsale::ApplicationPolicy
  attr_reader :user, :subject

  def initialize(user, subject)
    @user    = user
    @subject = subject
  end

  def record
    subject
  end

  def policy(subject)
    Pundit.policy(user, subject)
  end

  def policy_scope(subject)
    Pundit.policy_scope(user, subject)
  end

  def self.inherited(klass)
    klass.define_subject_accessor!
  end

  def self.define_subject_accessor!
    # Dorsale::BillingMachine::InvoicePolicy -> :invoice
    object_type = self.to_s.demodulize.gsub("Policy", "").underscore.to_sym

    # Avoid user/subject conflict
    object_type = :other_user if object_type == :user

    self.send(:define_method, object_type) { subject }
  end

  private

  class Scope
    attr_reader :user, :scope

    def initialize(user, scope)
      @user  = user
      @scope = scope
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
dorsale-3.8.1 app/policies/dorsale/application_policy.rb
dorsale-3.8.0 app/policies/dorsale/application_policy.rb
dorsale-3.7.8 app/policies/dorsale/application_policy.rb
dorsale-3.7.7 app/policies/dorsale/application_policy.rb
dorsale-3.7.6 app/policies/dorsale/application_policy.rb
dorsale-3.7.5 app/policies/dorsale/application_policy.rb
dorsale-3.7.4 app/policies/dorsale/application_policy.rb
dorsale-3.7.2 app/policies/dorsale/application_policy.rb
dorsale-3.7.1 app/policies/dorsale/application_policy.rb
dorsale-3.7.0 app/policies/dorsale/application_policy.rb
dorsale-3.6.1 app/policies/dorsale/application_policy.rb
dorsale-3.6.0 app/policies/dorsale/application_policy.rb
dorsale-3.5.2 app/policies/dorsale/application_policy.rb
dorsale-3.5.1 app/policies/dorsale/application_policy.rb
dorsale-3.5.0 app/policies/dorsale/application_policy.rb
dorsale-3.4.0 app/policies/dorsale/application_policy.rb
dorsale-3.3.0 app/policies/dorsale/application_policy.rb
dorsale-3.2.0 app/policies/dorsale/application_policy.rb
dorsale-3.1.7 app/policies/dorsale/application_policy.rb
dorsale-3.1.6 app/policies/dorsale/application_policy.rb