diff --git a/config/credentials/development.yml.enc b/config/credentials/development.yml.enc index 5ba4c45a..7a2eddaf 100644 --- a/config/credentials/development.yml.enc +++ b/config/credentials/development.yml.enc @@ -1 +1 @@ -qYaVjn7AHyHSmLShL6FUSc0gkDN/TnlTBcyxWC/aVqSw9Yomczems0sliw1sbV28P9OxJiYKf/lAc/tkdZXlsFPRmf3Ax1RXdVdpCX9aoegsgqaTfZM/ho/hXcgfV+tWuyg0ay/GVrYO/EeehSMCENtnBOLU/f8jLyWN8or/7hhQdDYQ6xKV+8eQRy/vTvNtfeHHoadvwpNFBBQV5yVznOZXv5PVoJBzmUtvGkHZkyjKoXXFPY0XvwHOI1BZHo37ogeQylXVhdFABdfQoCWQvJNUgB8kkPsBPx87--Fvpot/k3S0Abti7S--qv435P5TTlbWwzBcxrsnjQ== \ No newline at end of file +hk3xOYEGE+oGJgblVqmInjtqi4GfMW8AZaanzxUgBF5CIrgjEx5lff3+wxuAQTkJBarwUsdISKRJ9hxuxNVKy86F1Y5FR21GRIBmF/a6Mx3HGLDLd8qopPxiiECm/cLc2nNFBG56W0oDM1Oeoa/c/TWKvbpCZvvy0jcsT+pwqDewF36vhJAjF5+DsSIOoKhM6qJvUxVuzXMpp8Bi+fGwfPlrPw51TqtFCA8yOebymCvCt+sR+PYSAURNvoafKWHPHbOMWKJtFiR95CWX5O7LeEDrwSSHar/gUmx0V50CDw0/OMuUutX1dTHXb86P9kgQGfJNg5o=--6PcDleD9XIhgGIO2--ctaBkvJ7VlLBYwRbrENu0A== \ No newline at end of file diff --git a/lib/macro/pundit.rb b/lib/macro/pundit.rb index 4780f434..cef39922 100644 --- a/lib/macro/pundit.rb +++ b/lib/macro/pundit.rb @@ -1,36 +1,39 @@ # frozen_string_literal: true -module Policy - def self.Pundit(policy_class, user: nil, model: nil, action, name: :default) - Policy.step(Pundit.build(policy_class, user, model, action), name: name) - end - - module Pundit - def self.build(*args, &block) - Condition.new(*args, &block) +module Macro + module Policy + def self.Pundit(policy_class, action, user: nil, model: nil, name: :default) + Policy.step(Pundit.build(policy_class, action, user: user, model: model), name: name) end - class Condition - def initialize(policy_class, user, model, action) - @policy_class, @user, @model, @action = policy_class, user, model, action + module Pundit + def self.build(*args, &block) + Condition.new(*args, &block) end - def call((options), *) - policy = build_policy - result!(policy.send(@action), policy) - end + class Condition + def initialize(policy_class, action, user, model) + @policy_class, @user, @model, @action = policy_class, user, model, action + end - private - def build_policy - @policy_class.new(@user, @model) if @user && @model - @policy_class.new(options[:current_user], options[:model]) unless @user && @model - end + def call((options), *) + policy = build_policy(options) + result!(policy.send(@action), policy) + end + + private + + def build_policy(options) + @policy_class.new(@user, @model) if @user && @model + @policy_class.new(options[:current_user], options[:model]) unless @user && @model + end - def result!(success, policy) - data = { policy: policy } - data[:message] = "Breach" if !success + def result!(success, policy) + data = { policy: policy } + data[:message] = 'Breach' unless success - Trailblazer::Operation::Result.new(success, data) + Trailblazer::Operation::Result.new(success, data) + end end end end