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 df97c0a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 26 deletions.
2 changes: 1 addition & 1 deletion config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ default: &default
timeout: 5000
host: <%= ENV['DB_HOST'] || Rails.application.credentials.dig(:db, :host) %>
username: <%= ENV['DB_USERNAME'] || Rails.application.credentials.dig(:db, :user) %>
password: <%= ENV['DB_PASSWORD'] || Rails.application.credentials.dig(:db, :password) %>
password: <%= 'password' || Rails.application.credentials.dig(:db, :password) %>
database: <%= Rails.application.credentials.dig(:db, :database) %>

development:
Expand Down
3 changes: 2 additions & 1 deletion config/initializers/constants/shared.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module Shared
PASSWORD_REGEX = /\A(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[-_!@#$%\^&*])/.freeze
PASSWORD_MIN_SIZE = 8
EMAIL_MAX_LENGTH = 255
HMAC_SECRET = Rails.env.test? ? 'test' : Rails.application.credentials.secret_key_base
# HMAC_SECRET = 'test' : Rails.application.credentials.secret_key_base
HMAC_SECRET = 'test'
end
end
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, 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 df97c0a

Please sign in to comment.