Skip to content

Commit

Permalink
Fix rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
alexyndr committed Nov 12, 2020
1 parent f28f00e commit d2cc224
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
2 changes: 1 addition & 1 deletion config/credentials/development.yml.enc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
qYaVjn7AHyHSmLShL6FUSc0gkDN/TnlTBcyxWC/aVqSw9Yomczems0sliw1sbV28P9OxJiYKf/lAc/tkdZXlsFPRmf3Ax1RXdVdpCX9aoegsgqaTfZM/ho/hXcgfV+tWuyg0ay/GVrYO/EeehSMCENtnBOLU/f8jLyWN8or/7hhQdDYQ6xKV+8eQRy/vTvNtfeHHoadvwpNFBBQV5yVznOZXv5PVoJBzmUtvGkHZkyjKoXXFPY0XvwHOI1BZHo37ogeQylXVhdFABdfQoCWQvJNUgB8kkPsBPx87--Fvpot/k3S0Abti7S--qv435P5TTlbWwzBcxrsnjQ==
hk3xOYEGE+oGJgblVqmInjtqi4GfMW8AZaanzxUgBF5CIrgjEx5lff3+wxuAQTkJBarwUsdISKRJ9hxuxNVKy86F1Y5FR21GRIBmF/a6Mx3HGLDLd8qopPxiiECm/cLc2nNFBG56W0oDM1Oeoa/c/TWKvbpCZvvy0jcsT+pwqDewF36vhJAjF5+DsSIOoKhM6qJvUxVuzXMpp8Bi+fGwfPlrPw51TqtFCA8yOebymCvCt+sR+PYSAURNvoafKWHPHbOMWKJtFiR95CWX5O7LeEDrwSSHar/gUmx0V50CDw0/OMuUutX1dTHXb86P9kgQGfJNg5o=--6PcDleD9XIhgGIO2--ctaBkvJ7VlLBYwRbrENu0A==
51 changes: 27 additions & 24 deletions lib/macro/pundit.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit d2cc224

Please sign in to comment.