Skip to content

Commit

Permalink
Handle Crystal 1.13 deprecation (#423)
Browse files Browse the repository at this point in the history
  • Loading branch information
Blacksmoke16 authored Jun 16, 2024
1 parent d3a173f commit 214cc46
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 14 deletions.
15 changes: 12 additions & 3 deletions src/components/dotenv/src/athena-dotenv.cr
Original file line number Diff line number Diff line change
Expand Up @@ -506,9 +506,18 @@ class Athena::Dotenv

private def load(override_existing_vars : Bool, paths : Enumerable(String | ::Path)) : Nil
paths.each do |path|
if !File.readable?(path) || File.directory?(path)
raise Athena::Dotenv::Exceptions::Path.new path
end
# TODO: Inline this again once 1.13.0 is the new min version
{% begin %}
{% if compare_versions(Crystal::VERSION, "1.13.0-dev") >= 0 %}
is_file_readable = File::Info.readable? path
{% else %}
is_file_readable = File.readable? path
{% end %}

if !is_file_readable || File.directory?(path)
raise Athena::Dotenv::Exceptions::Path.new path
end
{% end %}

self.populate(self.parse(File.read(path), path), override_existing_vars)
end
Expand Down
11 changes: 10 additions & 1 deletion src/components/framework/src/binary_file_response.cr
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,16 @@ class Athena::Framework::BinaryFileResponse < Athena::Framework::Response
)
super nil, status, headers

raise File::Error.new("File '#{file_path}' must be readable.", file: file_path) unless File.readable? file_path
# TODO: Inline this again once 1.13.0 is the new min version
{% begin %}
{% if compare_versions(Crystal::VERSION, "1.13.0-dev") >= 0 %}
is_file_readable = File::Info.readable? file_path
{% else %}
is_file_readable = File.readable? file_path
{% end %}

raise File::Error.new("File '#{file_path}' must be readable.", file: file_path) unless is_file_readable
{% end %}

@file_path = Path.new(file_path).expand

Expand Down
28 changes: 18 additions & 10 deletions src/components/validator/src/constraints/file.cr
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ class Athena::Validator::Constraints::File < Athena::Validator::Constraint

class Validator < Athena::Validator::ConstraintValidator
# :inherit:
# ameba:disable Metrics/CyclomaticComplexity
def validate(value : _, constraint : AVD::Constraints::File) : Nil
return if value.nil? || value == ""

Expand All @@ -242,15 +241,24 @@ class Athena::Validator::Constraints::File < Athena::Validator::Constraint
return
end

unless ::File.readable? path
self
.context
.build_violation(constraint.not_readable_message, NOT_READABLE_ERROR)
.add_parameter("{{ file }}", path)
.add

return
end
# TODO: Inline this again once 1.13.0 is the new min version
{% begin %}
{% if compare_versions(Crystal::VERSION, "1.13.0-dev") >= 0 %}
is_file_readable = ::File::Info.readable? path
{% else %}
is_file_readable = ::File.readable? path
{% end %}

unless is_file_readable
self
.context
.build_violation(constraint.not_readable_message, NOT_READABLE_ERROR)
.add_parameter("\{{ file }}", path)
.add

return
end
{% end %}

size_in_bytes = ::File.size path
base_name = ::File.basename path
Expand Down

0 comments on commit 214cc46

Please sign in to comment.