Skip to content

Commit

Permalink
Refactor methods
Browse files Browse the repository at this point in the history
Improves commit eb35a37.
  • Loading branch information
akadusei committed Jun 2, 2024
1 parent 6bf07e4 commit bd095a2
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/envy.cr
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ module Envy
load do
set_perms files, perm

if found = files.find { |file| File.readable?(file) }
next from_file(found, force: false)
files.find { |file| File.readable?(file) }.try do |file|
return from_file(file, force: false)
end

raise Error.new("Env file(s) not found or not readable")
Expand All @@ -22,8 +22,8 @@ module Envy
load do
set_perms files, perm

if found = files.find { |file| File.readable?(file) }
next from_file(found, force: true)
files.find { |file| File.readable?(file) }.try do |file|
return from_file(file, force: true)
end

raise Error.new("Env file(s) not found or not readable")
Expand Down Expand Up @@ -65,9 +65,11 @@ module Envy

private def load
var = "ENVY_LOADED"
return if ENV[var]? == "yes"

unless ENV[var]? == "yes"
begin
yield
ensure
ENV[var] = "yes"
end
end
Expand Down

0 comments on commit bd095a2

Please sign in to comment.